I have giving up tring to work with the data formats that dx provides
and I am resorting to figuring out how to program up an import module.
I am having a hard time with how to set up the grid. I keep getting
bad type: bat positions/box type in bounding box
I am using
a = DXNewArrayV(TYPE_FLOAT, CATEGORY_REAL, dims,counts);
if (!DXAddArrayData(a, 0, 2, NULL))
goto error;
/* get a pointer to the data array */
data = (float *)DXGetArrayData(a);
//Fill data
if (!DXSetComponentValue(f, "positions", (Object)a))
to create the positions array
and the rest follows
If someone sees what I am doing wrong and can help educate me that would
be great
Thanks in advance
matt
Error m_SimpleImport(Object *in, Object *out)
{
Array a=NULL;
Field f=NULL;
char *filename;
int dims, counts[MAXRANK], numelements, i, j,shape[8];
float deltas[MAXRANK*MAXRANK], origins[MAXRANK], *data;
float* tempspace;
FILE* fp;
char string[80];
int nt,mt,l,ls,nr,nq,ntyp,ntc,nobmax,nriv;
double degrad=M_PI/180.;
float earth_rad =6374000*2.*M_PI;
// Read file stuff deleted, grid is 2d nt x mt cell centered data
dims = 2;
counts[0] = nt+1;
counts[1] = mt+1;
counts[2] = 0;
// Open and read in the grid data
if (!DXExtractString(in[1], &filename)) {
DXSetError(ERROR_BAD_PARAMETER, "grid filename must be a string");
goto error;
}
fp = fopen(filename,"r");
if ( !fp ) {
DXSetError(ERROR_BAD_PARAMETER,"Cannot open grid file (second
input)");
goto error;
}
// Allocate grid data
/* make a new data array (scalar) */
a = DXNewArray(TYPE_FLOAT, CATEGORY_REAL, 0);
if (!a)
goto error;
/* figure out how many elements there are in the data array */
for (i=0, numelements=1; i<dims; numelements *= counts[i], i++)
;
/* create a new field */
f = DXNewField();
if (!f)
goto error;
/* create the connections array */
/* DXMakeGridConnections will set the element type */
a = DXMakeGridConnectionsV(dims, counts);
if (!a)
goto error;
if (!DXSetComponentValue(f, "connections", (Object)a))
goto error;
a=NULL;
/* allocate space in the data array for positions */
a = DXNewArrayV(TYPE_FLOAT, CATEGORY_REAL, dims,counts);
if (!DXAddArrayData(a, 0, 2, NULL))
goto error;
/* get a pointer to the data array */
data = (float *)DXGetArrayData(a);
if (!data)
goto error;
// Allocate and read positions
tempspace = (float*)malloc(mt*nt*6*sizeof(float));
fread(tempspace,mt*nt*6,sizeof(float),fp);
for (i=0;i<counts[0]-1;i++)
for (j=0;j<counts[1]-1;j++){
// Stuff deleted
data[2*index] = x;
data[2*index+1] = y;
}
free(tempspace);
for (i=0;i<counts[0]-1;i++)
for (j=0;j<counts[1]-1;j++){
int index,index2;
index = i+j*counts[0];
printf("%d %d %f %f\n",i,j,data[2*index],data[2*index+1]);
}
// Set the positions
if (!DXSetComponentValue(f, "positions", (Object)a))
goto error;
a=NULL;
/* EndField sets default attributes (such as setting the connections
attribute to be "ref" positions), and creates the bounding box. */
if (!DXEndField(f))
goto error;
out[0]=f;
return OK;
error:
DXDelete((Object)f);
DXDelete((Object)a);
return ERROR;
}