Article View: comp.graphics.explorer
Article #239Need help with my module
From: Howard Wai-Chun Yeung
Date: Mon, 25 Jan 1993 19:58
Date: Mon, 25 Jan 1993 19:58
105 lines
2924 bytes
2924 bytes
I write the following simple program using module muilder functions.
The problem is that it cannot send the lattice data to other modules.
I make a connection to WriteLat(), but no data is written. It seems
like the lattice is empty. But I retrive the data pointer from the
lattice. It does have data!
The problem has bug me for a few days. I wish it will just be a small
mistake I am not aware of.
#include <stdio.h>
#include "cx/PortAccess.h"
#include "cx/DataTypes.h"
#include "cx/DataAccess.h"
#include "cx/UserFuncs.h"
#define MAX_DIM 250
#define SLICE_DIM 2
translate_u3l(file_name, x_dim, y_dim, z_dim, slice_no)
char *file_name;
long x_dim, y_dim, z_dim;
long slice_no;
{
char *var;
int *int_ptr;
int i, j, k, size = 1;
FILE *in_file;
char *lat_file;
long slice_dim[2];
cxPrimType prim_type = cx_prim_long;
cxLattice *lattice_2d;
/*check any parameter error*/
if (x_dim > 250 || y_dim >250 || z_dim >250)
{
printf("Dimension of the volume is too large.\n");
return 0;;
}
/*set the maximum number of slice available*/
cxInWdgtLongMinMaxSet("slice_no", 0, z_dim-1);
/* open the input file */
if((in_file=fopen(file_name, "r")) == NULL)
{
char str[128];
sprintf(str,"cannot open input file %s", lat_file);
cxModAlert( str );
fclose(in_file);
return 0;
}
if((var = (char *)malloc(size)) == NULL)
{
printf("Memory allocation failed\n");
exit(1);;
}
slice_dim[0] = x_dim;
slice_dim[1] = y_dim;
lattice_2d = cxLatNew(SLICE_DIM,slice_dim,NO_VARIABLE,prim_type,
SLICE_DIM,cx_coord_uniform);
/*no error in share memory allocation*/
if (!cxDataAllocErrorGet())
{
cxLatPtrGet(lattice_2d, NULL, &int_ptr, NULL, NULL);
}
else
{
printf("Lattice allocation error.\n");
return 0;
}
/*in_file then is the pointer to the opened file read only
the portion of file which is the slice*/
fseek(in_file, 0L, 0);
fseek(in_file, x_dim*y_dim*slice_no, 1);
/*x_dim is number of colums while y_dim is number of row*/
for (i=0; i<y_dim; i++){
for (j=0; j<x_dim; j++){
fread(var, size, 1, in_file);
int_ptr[i*x_dim + j] = (long) (*var);
}
}
/*x_dim is number of colums while y_dim is number of row*/
cxOutputDataSet(cxOutputPortOpen("slice_lattice"), lattice_2d);
free(var);
fclose(in_file);
return;
}
With thousand thanks!
Technical Details
Message-ID:
<1993Jan25.195823.12754@alw.nih.gov>Path:
arc1-ca.pugleaf.net!sparky!uunet!nih-csl!freud.nia.nih.gov!howardyShow Full Headers
Complete Article Headers
Newsgroups: comp.graphics.explorer Path: arc1-ca.pugleaf.net!sparky!uunet!nih-csl!freud.nia.nih.gov!howardy From: howardy@freud.nia.nih.gov (Howard Wai-Chun Yeung) Subject: Need help with my module Message-ID: <1993Jan25.195823.12754@alw.nih.gov> Sender: postman@alw.nih.gov (AMDS Postmaster) Organization: (Natl. Institutes of Health, Bethesda, MD) Date: Mon, 25 Jan 1993 19:58:23 GMT Lines: 112