/* cc -O3 raw2hdf.c -o raw2hdf -I$HDFINC -L$HDFLIB -lmfhdf -ldf -lz -lm -ljpeg */ /** * @file raw2hdf.c * @brief Command line tool that write binary data in the sds of an HDF file * * @author Jacques Descloitres, CGTD ICARE * @version 1.0.0 * * ---------------------------------------------------------------------------- * * History : * * ---------------------------------------------------------------------------- * */ #include #include "mfhdf.h" #define MAXNAMELENGTH 200 /** * @struct SDS represents a sds */ typedef struct { char name[MAXNAMELENGTH]; int32 id, index, num_type, rank, n_attr, Nl, Np, *plane, Nplanes; int32 start[MAX_VAR_DIMS], edges[MAX_VAR_DIMS], dim_sizes[MAX_VAR_DIMS]; void *data, *fillvalue; } SDS; /** * @brief retrieve an HDF type code using a string representatin of it * @param typename the type given in a string ("char8", "float64"...) * @return the corresponding HDF type code (DFNT_CHAR8, DFNT_FLOAT64...) */ int get_num_type( char* typename ) { if ( strcmp(typename,"char8") == 0 ) return DFNT_CHAR8; else if ( strcmp(typename,"uchar8") == 0 ) return DFNT_UCHAR8; else if ( strcmp(typename,"int8") == 0 ) return DFNT_INT8; else if ( strcmp(typename,"uint8") == 0 ) return DFNT_UINT8; else if ( strcmp(typename,"int16") == 0 ) return DFNT_INT16; else if ( strcmp(typename,"uint16") == 0 ) return DFNT_UINT16; else if ( strcmp(typename,"int32") == 0 ) return DFNT_INT32; else if ( strcmp(typename,"uint32") == 0 ) return DFNT_UINT32; else if ( strcmp(typename,"float32") == 0 ) return DFNT_FLOAT32; else if ( strcmp(typename,"float64") == 0 ) return DFNT_FLOAT64; else return FAIL; } /** * @brief command line tool entry point * @param argc as usual * @param argv[] as usual * @return 0 if all works fine, -1 either */ int main(int argc, char *argv[]) { char filename1[MAXNAMELENGTH], filename2[MAXNAMELENGTH], typename[10]; int32 sd_id, num_type; int j, irow, write_mode, width, height; FILE *fd; char verbose=FALSE; SDS sds; void *data; filename1[0] = (char)NULL; filename2[0] = (char)NULL; typename[0] = (char)NULL; write_mode = DFACC_CREATE; width = height = 0; if (argc < 3) { fprintf(stderr, "Usage: %s [-v] [-append] -size=x -type=float64|float32|int32|uint32|int16|uint16|int8|uint8|char8|uchar8 -of= \n", argv[0]); exit(-1); } for (j=1; j