This is the native binary format of DisPerSE. Functions for reading and writing NDfield format in C can be found within the file ${DISPERSE_SRC}/src/C/NDfield.c (see functions Load_NDfield and Save_NDfield).

When using the C functions from Disperse, data is loaded into the following C structure which is close to the actual structure of the file (see file ${DISPERSE_SRC}/src/C/NDfield.h):

#define ND_CHAR   (1<<0)
#define ND_UCHAR  (1<<1)
#define ND_SHORT  (1<<2)
#define ND_USHORT (1<<3)
#define ND_INT    (1<<4)
#define ND_UINT   (1<<5)
#define ND_LONG   (1<<6)
#define ND_ULONG  (1<<7)
#define ND_FLOAT  (1<<8)
#define ND_DOUBLE (1<<9)
typedef struct NDfield_str
{
 char comment[80];  // a comment on the data
 int dims[NDFIELD_MAX_DIMS];  // dimensions of the grid, must be [ndims,nparticles] when data represents sample particles coordinates (i.e. when fdims_index!=0)
 int ndims;  // number of dimensions of the space
 int n_dims;  // number of meaningfull values in dims array
 int fdims_index; // if 0, the field is a regular grid of dimensions dims, else the file contains the dims[0] coordinates of dims[1] particles.
 int datatype;  // type of the data (one of the ND_... defined above)
 double x0[NDFIELD_MAX_DIMS];  // origin of the bounding box
 double delta[NDFIELD_MAX_DIMS];  // extent of the bounding box
 char dummy[160];  // dummy data, for future extensions or for storing anything you want.

 void *val;  // pointer to data

 long nval;  // total number of particles (fdims_index==1) or pixels (fdims_index==0)
 int datasize;  // size in bytes of datatype type.
} NDfield;



The NDfield binary format is organized as follows (blocks are delimited by dummy variables indicating the size of the blocks for FORTRAN compatibility, but they are ignored in C):

NDnet binary format
fieldtypesizecomment
dummyint(4B) 1 for FORTRAN compatibility
tagchar(1B)16identifies the file type. Value : "NDFIELD"
dummyint(4B) 1
dummyint(4B) 1
ndimsint(4B)1number of dimensions of the embedding space
dimsint(4B)20size of the grid in pixels along each dimension, or [ndims,nparticles] if data represents particle coordinates (i.e. fdims_index=1)
fdims_indexint(4B)1 0 if data represents a regular grid, 1 if it represents coordinates of tracer particles
datatypeint(4B)1type of data stored (see below)
x0double(8B)20origin of bounding box (first ndims val. are meaningfull)
deltadouble(8B)20size of bounding box (first ndims val. are meaningfull)
dummy_extchar(1B)160dummy data reserved for future extensions
dummyint(4B) 1
dummyint(4B) 1
datasize of datatypeNdata itself (N may be the number of pixels or ndism times the number of particles)
dummyint(4B) 1



Possible data types
namesize (Bytes)typevalue
ND_CHAR 1 integer 1 (=1<<0)
ND_UCHAR 1 integer 2 (=1<<1)
ND_SHORT 2 integer 4 (=1<<2)
ND_USHORT 2 integer 8 (=1<<3)
ND_INT 4 integer 16 (=1<<4)
ND_UINT 4 integer 32 (=1<<5)
ND_LONG 8 integer 64 (=1<<6)
ND_ULONG 8 integer 128 (=1<<7)
ND_FLOAT 4 float 256 (=1<<8)
ND_DOUBLE 8 float 512 (=1<<9)