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):
field | type | size | comment |
dummy | int(4B) | 1 | for FORTRAN compatibility |
tag | char(1B) | 16 | identifies the file type. Value : "NDFIELD" |
dummy | int(4B) | 1 | |
dummy | int(4B) | 1 | |
ndims | int(4B) | 1 | number of dimensions of the embedding space |
dims | int(4B) | 20 | size of the grid in pixels along each dimension, or [ndims,nparticles] if data represents particle coordinates (i.e. fdims_index=1) |
fdims_index | int(4B) | 1 | 0 if data represents a regular grid, 1 if it represents coordinates of tracer particles |
datatype | int(4B) | 1 | type of data stored (see below) |
x0 | double(8B) | 20 | origin of bounding box (first ndims val. are meaningfull) |
delta | double(8B) | 20 | size of bounding box (first ndims val. are meaningfull) |
dummy_ext | char(1B) | 160 | dummy data reserved for future extensions |
dummy | int(4B) | 1 | |
dummy | int(4B) | 1 | |
data | size of datatype | N | data itself (N may be the number of pixels or ndism times the number of particles) |
dummy | int(4B) | 1 |
name | size (Bytes) | type | value |
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) |