#include /* necessary for hdf library routines */ /* IMPORTANT NOTE: Data Explorer does not provide HDF libraries. This example program is for illustrative purposes only. Because we do not provide hdf libraries, it will not be possible for you to compile and link this module unless you have the HDF libraries yourself */ #include #define MAXRANK 3 Error m_SimpleImport(Object *in, Object *out) { Array a=NULL; Field f=NULL; char *filename; int dims, counts[MAXRANK], numelements, i, j; float deltas[MAXRANK*MAXRANK], origins[MAXRANK], *data; /* extract the file name from in[0] */ if (!in[0]) { DXSetError(ERROR_BAD_PARAMETER,"missing filename"); goto error; } else if (!DXExtractString(in[0], &filename)) { DXSetError(ERROR_BAD_PARAMETER, "filename must be a string"); goto error; } /* check to see that the file is accessible, and is an hdf file */ /* DFishdf is an hdf library routine */ if (DFishdf(filename) != 0) { DXSetError(ERROR_BAD_PARAMETER, "file \"%s\" is either not accessible, or is not an hdf file", filename); goto error; } /* initialize */ /* DFSDrestart is an HDF library routine */ DFSDrestart(); /* this returns the dimensionality of the grid (1D, 2D, etc) in dims. The number of positions in each dimension is returned in the array counts */ /* DFSDgetdims is an HDF library routine */ DFSDgetdims(filename, &dims, counts, MAXRANK); /* 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