/* * attempts to move to ncData Class from struct * ** warnings removed from g++ compile ** time functions removed ** */ /* * Libraries. **************/ #include #include #include #include #include #include #include #include /* this added to avoid compiler error of isalpha, isdigit, isgraph */ #include /* removed if system Unix to avoid Fedora 8 error */ #include /* * Headers. ************/ //#include "/opt/cxx/netcdf.h" DLL definitions for Windows removed #include "/usr/local/include/netcdf.h" #include #include "/opt/cern/root/include/TObject.h" #include "/opt/cern/root/include/TROOT.h" #include "/opt/cern/root/include/TFile.h" #include "/opt/cern/root/include/TTree.h" #include "/opt/cern/root/include/TVersionCheck.h" /* * Macros. **************/ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef CALLOC #define CALLOC(n, t) (t *)calloc(n, sizeof(t)) #endif #ifndef MALLOC #define MALLOC(n, t) (t *)malloc(n * sizeof(t)) #endif #ifndef REALLOC #define REALLOC(p, n, t) (t*) realloc(p, (n) * sizeof(t)) #endif #ifndef ncx_DataCALLOC #define ncx_DataCALLOC(DATA) \ if( ( DATA = MALLOC(1, ncDataS)) \ == (ncDataP)NULL ) \ memory_fail(__FILE__,__LINE__); \ init_ncdata(DATA) #endif /* * Struct to hold the dimensions of the netcdf file. *****************************************************/ typedef struct _Dimensions { public: /* Dimension id. */ int dimid; /* Dimension name. */ char *dimname; /* Dimension length. */ size_t dimlength; /* Flag to keep this dimension. */ int keep; /* Dimension id for writing. */ int wdimid; /* Variable to hold start position to print. */ int start; } DimensionsS, *DimensionsP; /* * Struct to hold the global/field-level attributes of the netcdf file. ************************************************************************/ typedef struct _Attributes { public: /* Attribute id. */ int attid; /* Attribute type. */ nc_type atttype; /* Attribute name. */ char *attname; /* Attribute length. */ size_t attlength; /* Attribute value. */ long *long_val; char *char_val; double *double_val; float *float_val; short *short_val; unsigned char *uchar_val; /* Flag to keep this attribute. */ int keep; /* Attribute id for writing. */ int wattid; } AttributesS, *AttributesP; /* * Struct to hold the variables of the netcdf file. ****************************************************/ typedef struct _Variables { public: /* Variable id. */ int varid; /* Variable name. */ char *varname; /* Variable type. */ nc_type vartype; /* Number of dimensions. */ int varndims; /* Dimension ids. */ int *vardimids; /* Number of attributes. */ int varnatts; /* Attributes. */ AttributesP *attributes; /* Number of samples. */ size_t nsamples; /* Variable data. */ long *long_data; char *char_data; double *double_data; float *float_data; short *short_data; unsigned char *uchar_data; /* Flag to keep this variable. */ int keep; /* Variable id for writing. */ int wvarid; } VariablesS, *VariablesP; /* * Struct (now class) to hold the contents of the netcdf file. ***************************************************/ typedef class ncData : public TObject { public: /* Stats. */ int fid, ndims, nvars, ngatts, unlimited; //! apparently references via & /* Dimensions. */ DimensionsP *dimensions; //! /* Global attributes. */ AttributesP *globals; //! /* Variables. */ VariablesP *variables; //! /* File names. */ char *infile, *outfile; //! /* Flags for reading. */ int isopen, getattvalues, getvardata; //! /* Flags for writing. */ int mode; //! /* Flag to sort data. */ int sort; /* Time flag. */ int time_flag; // ncData(); //default constructor // ncData(int fid, int ndims, int nvars, int ngatts, int unlimited, // DimensionsP dimensions, AttributesP globals, VariablesP variables, // char infile, char outfile, int isopen, int getattvalues ,int getvardata, // int mode, int sort, int time_flag); //real constructor // virtual ~ncData(); //destructor // ClassDef(ncData, 1); } ncDataS, *ncDataP ; /* * Prototypes. ***************/ /* Read. */ int ncx_read(ncDataP data); int ncx_getdimensions(ncDataP data); int ncx_getdimension(ncDataP data, DimensionsP dim); int ncx_getglobals(ncDataP data); int ncx_getattributes(ncDataP data ,VariablesP var); int ncx_getattribute(ncDataP data ,AttributesP att,VariablesP var); int ncx_getattributevalue(ncDataP data, AttributesP ,VariablesP var); int ncx_getvariables(ncDataP data); int ncx_getvariable(ncDataP data,VariablesP var); int ncx_getvariabledata(ncDataP data, VariablesP var, unsigned int* spts, unsigned int* elens); int ncx_getatt(ncDataP, int, char *); int ncx_getdimid(ncDataP, char *); int ncx_getvarid(ncDataP, char *); int ncx_getvarsize(ncDataP, int); int ncx_setFilename(ncDataP data, char *filename, int flag); /* Initialize. */ void init_dimension(DimensionsP dim); void init_attribute(AttributesP att); void init_variable(VariablesP var); void init_ncdata(ncDataP data); /* Print. */ void print_dimension(DimensionsP dim); void print_attribute(AttributesP att); void print_variable(VariablesP var); void print_ncdata(ncDataP data); /* Free memory. */ int free_dimensions(ncDataP data); int free_dimension(DimensionsP dim); int free_attributes(AttributesP* att, int natts); int free_attribute(AttributesP att); int free_variables(ncDataP data); int free_variable(VariablesP var); int free_ncdata(ncDataP data); /* Memory allocation failure. */ void memory_fail(char*,int);