h5import.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  *
00018  * Data and structure definitions for h5import
00019  *
00020  */
00021 
00022 #ifndef H5IMPORT_H__
00023 #define H5IMPORT_H__
00024 
00025 /*
00026  * state table tokens
00027  */
00028 #define FILNAME 0
00029 /* filename */
00030 #define OPT_o   1
00031 /* output filename */
00032 #define OPT_c   2   /* configuration filename */
00033 #define OPT_h   3   /* request for explanation */
00034 #define OPT_d   4   /* dimensions */
00035 #define OPT_p   5   /* pathname */
00036 #define OPT_t   6   /* data type */
00037 #define OPT_s   7   /* data size */
00038 #define ERR    20  /* invalid token */
00039 
00040 #define MAX_GROUPS_IN_PATH  20
00041 #define MAX_PATH_NAME_LENGTH 255
00042 #define NUM_KEYS 14
00043 #define MIN_NUM_DIMENSION  1
00044 #define MAX_NUM_DIMENSION  32
00045 #define BASE_10 10
00046 
00047 #define CHUNK            0
00048 #define COMPRESS         1
00049 #define EXTEND           2
00050 #define EXTERNAL         3
00051 #define DIM              4
00052 #define RANK             5
00053 #define PATH             6
00054 #define INPUT_CLASS      7
00055 #define INPUT_SIZE       8
00056 #define OUTPUT_CLASS     9
00057 #define OUTPUT_SIZE     10
00058 #define OUTPUT_ARCH     11
00059 #define OUTPUT_B_ORDER  12
00060 #define COMPRESS_PARAM  13
00061 
00062 /* data types */
00063 #define H5DT_INT8      signed char
00064 #define H5DT_INT16     short
00065 #define H5DT_INT32     int
00066 #define H5DT_FLOAT32   float
00067 #define H5DT_FLOAT64   double
00068 #define VOIDP          void*
00069 #define H5DT_UINT8     unsigned char
00070 #define H5DT_UINT16    unsigned short
00071 #define H5DT_UINT32    unsigned int
00072 #define H5DT_INT64     long long
00073 #define H5DT_UINT64    unsigned H5DT_INT64
00074 
00075 struct path_info
00076 {
00077   char group[MAX_GROUPS_IN_PATH][MAX_PATH_NAME_LENGTH];
00078   int count;
00079 };
00080 
00081 struct Input
00082 {
00083   struct path_info path;
00084   int inputClass;
00085   int inputSize;
00086   int rank;
00087   hsize_t* sizeOfDimension;
00088   int outputClass;
00089   int outputSize;
00090   int outputArchitecture;
00091   int outputByteOrder;
00092   hsize_t* sizeOfChunk;
00093   hsize_t* maxsizeOfDimension;
00094   int compressionType;
00095   int compressionParam;
00096   char *externFilename;
00097   VOIDP data;
00098   int configOptionVector[NUM_KEYS];
00099 };
00100 
00101 struct infilesformat
00102 {
00103   char datafile[255];
00104   char configfile[255];
00105   struct Input in;
00106   int config; /* Configfile present? No - 0. Yes - 1 */
00107 };
00108 
00109 struct Options
00110 {
00111   struct infilesformat  infiles[30];  /* structure to hold the list of input file names. Limited to 30*/
00112   char   outfile[256];  /* output file name */
00113   int    fcount;       /* number of input files */
00114 };
00115 
00116 char keytable[NUM_KEYS][30] = {
00117   "PATH",
00118   "INPUT-CLASS",
00119   "INPUT-SIZE",
00120   "RANK",
00121   "DIMENSION-SIZES",
00122   "OUTPUT-CLASS",
00123   "OUTPUT-SIZE",
00124   "OUTPUT-ARCHITECTURE",
00125   "OUTPUT-BYTE-ORDER",
00126   "CHUNKED-DIMENSION-SIZES",
00127   "COMPRESSION-TYPE",
00128   "COMPRESSION-PARAM",
00129   "EXTERNAL-STORAGE",
00130   "MAXIMUM-DIMENSIONS"
00131 };
00132 
00133 static int  state_table[15][8] =
00134 {
00135   /* token ordering:
00136      FILNAME      OPT_o   OPT_c  OPT_h  OPT_d  OPT_p  OPT_t  OPT_s   */
00137 
00138   /* state 0: start */
00139   {1, ERR, ERR, 6, ERR, ERR, ERR, ERR},
00140 
00141   /* state 1: input files */
00142   {ERR, ERR, 2, ERR, 7, ERR, ERR, ERR},
00143 
00144   /* state 2: -c[onfigfile] */
00145   {3, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00146 
00147   /* state 3: configfile */
00148   {1, 4, ERR, ERR, ERR, ERR, ERR, ERR},
00149 
00150   /* state 4: -o[utfile] */
00151   {5, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00152 
00153   /* state 5: outfile */
00154   {ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00155 
00156   /* state 6: -h[elp] */
00157   {ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00158 
00159   /* state 7: -d[ims] */
00160   {8, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00161 
00162   /* state 8: dimensions */
00163   {1, 4, ERR, ERR, ERR, 9, 11, 13},
00164 
00165   /* state 9: -p[ath] */
00166   {10, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00167 
00168   /* state 10: path name */
00169   {1, 4, ERR, ERR, ERR, ERR, 11, 13},
00170 
00171   /* state 11: -t[ype] */
00172   {12, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00173 
00174   /* state 12: data type */
00175   {1, 4, ERR, ERR, ERR, ERR, ERR, 13},
00176 
00177   /* state 13: -s[ize] */
00178   {14, ERR, ERR, ERR, ERR, ERR, ERR, ERR},
00179 
00180   /* state 14: data size */
00181   {1, 4, ERR, ERR, ERR, ERR, ERR, ERR}
00182 
00183 };
00184 
00185 /*
00186  *
00187  *  Function declarations for h5import
00188  *
00189  */
00190 void  usage(char *);
00191 void  setDefaultValues(struct Input *in, int count);
00192 void  help(char *);
00193 
00194 static int  gtoken(char *s);
00195 static int  process(struct Options *opt);
00196 static int  processConfigurationFile(char *infile, struct Input *in, FILE **strm);
00197 static int  mapKeywordToIndex(char *key);
00198 static int  parsePathInfo(struct path_info *path, char *strm);
00199 static int  parseDimensions(struct Input *in, char *strm);
00200 static int  getInputSize(struct Input *in, int ival);
00201 static int  getInputClass(struct Input *in, char * strm);
00202 static int  InputClassStrToInt(char *temp);
00203 static int  getRank(struct Input *in, FILE** strm);
00204 static int  getDimensionSizes(struct Input *in, FILE** strm);
00205 static int  getOutputSize(struct Input *in, FILE** strm);
00206 static int  getOutputClass(struct Input *in, FILE** strm);
00207 static int  OutputClassStrToInt(char *temp);
00208 static int  getOutputArchitecture(struct Input *in, FILE** strm);
00209 static int  OutputArchStrToInt(char *temp);
00210 static int  getOutputByteOrder(struct Input *in, FILE** strm);
00211 static int  OutputByteOrderStrToInt(char *temp);
00212 static int  getChunkedDimensionSizes(struct Input *in, FILE **strm);
00213 static int  getCompressionType(struct Input *in, FILE** strm);
00214 static int  CompressionTypeStrToInt(char *temp);
00215 static int  getCompressionParameter(struct Input *in, FILE** strm);
00216 static int  getExternalFilename(struct Input *in, FILE** strm);
00217 static int  getMaximumDimensionSizes(struct Input *in, FILE **strm);
00218 static int  processDataFile(char *infile, struct Input *in, FILE **strm, hid_t file_id);
00219 static int  readIntegerData(FILE **strm, struct Input *in);
00220 static int  readFloatData(FILE **strm, struct Input *in);
00221 static int  allocateIntegerStorage(struct Input *in);
00222 static int  allocateFloatStorage(struct Input *in);
00223 hid_t       createOutputDataType(struct Input *in);
00224 hid_t       createInputDataType(struct Input *in);
00225 static int  readUIntegerData(FILE **strm, struct Input *in);
00226 static int  allocateUIntegerStorage(struct Input *in);
00227 static int  validateConfigurationParameters(struct Input * in);
00228 static int  processStrData(FILE **strm, struct Input *in, hid_t file_id);
00229 
00230 #endif  /* H5IMPORT_H__ */
00231