15 #define _CRTDBG_MAP_ALLOC
29 #include "HdfEosDef.h"
35 #include "HDFEOS2EnumType.h"
39 #pragma warning(disable:4290)
67 class Exception:
public std::exception
71 explicit Exception (
const std::string & msg)
72 : message (msg), isHDFEOS2 (true)
77 virtual ~ Exception () throw ()
82 virtual const char *what ()
const throw ()
84 return this->message.c_str ();
89 virtual bool getFileType ()
91 return this->isHDFEOS2;
95 virtual void setFileType (
bool isHDFEOS2_flag)
97 this->isHDFEOS2 = isHDFEOS2_flag;
101 virtual void setException (std::string exception_message)
103 this->message = exception_message;
119 template <
typename T >
class LightVector {
122 : data (0), length (0), capacity (0) {
125 LightVector (
const LightVector < T > &that)
127 this->data =
new T[that.length];
128 for (
unsigned int i = 0; i < that.length; ++i)
129 this->data[i] = that[i];
130 this->length = that.length;
131 this->capacity = that.length;
139 void push_back (
const T & d)
141 this->reserve (this->length + 1);
142 this->data[this->length] = d;
146 void reserve (
unsigned int len)
148 if (this->capacity >= len)
151 this->capacity = len;
154 this->data =
new T[len];
156 for (
unsigned int i = 0; i < this->length; ++i)
157 this->data[i] = old[i];
162 void resize (
unsigned int len)
165 if (this->length == len)
167 else if (this->length < len) {
168 if (this->capacity < len) {
169 this->capacity = len;
172 this->data =
new T[len];
174 for (
unsigned int i = 0; i < this->length; ++i)
175 this->data[i] = old[i];
181 this->capacity = len;
184 this->data =
new T[len];
185 for (
unsigned int i = 0; i < len; ++i)
186 this->data[i] = old[i];
193 unsigned int size ()
const
198 T & operator[] (
unsigned int i)
200 return this->data[i];
202 const T & operator[] (
unsigned int i)
const
204 return this->data[i];
207 LightVector < T > &operator= (
const LightVector < T > &that)
210 this->data =
new T[that.length];
211 for (
unsigned int i = 0; i < that.length; ++i)
212 this->data[i] = that[i];
213 this->length = that.length;
214 this->capacity = that.length;
222 unsigned int capacity;
225 class SwathDimensionAdjustment;
233 const std::string & getName ()
const
237 int32 getSize ()
const
239 return this->dimsize;
243 Dimension (
const std::string & eos_dname, int32 eos_dimsize)
244 : name (eos_dname), dimsize (eos_dimsize)
253 friend class Dataset;
254 friend class SwathDimensionAdjustment;
263 :fieldtype (0), condenseddim (false), iscoard (false), ydimmajor (true), speciallon (false), specialformat (0), haveaddedfv (false), addedfv (-9999.0), dmap (false)
278 const std::string & getName ()
const
284 const std::string & getNewName ()
const
286 return this->newname;
290 int32 getRank ()
const
296 int32 getType ()
const
302 const std::vector < Dimension * >&getCorrectedDimensions ()
const
304 return this->correcteddims;
308 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
310 return &(this->correcteddims);
314 void setCorrectedDimensions (std::vector < Dimension * >eos_dims)
316 correcteddims = eos_dims;
320 const std::string getCoordinate ()
const
322 return this->coordinates;
326 void setCoordinates (std::string coor)
332 const std::string getUnits ()
const
338 void setUnits (std::string uni)
344 float getAddedFillValue ()
const
346 return this->addedfv;
354 void addFillValue (
float fv)
360 bool haveAddedFillValue ()
const
362 return this->haveaddedfv;
366 void setAddedFillValue (
bool havefv)
368 haveaddedfv = havefv;
381 int getFieldType ()
const
383 return this->fieldtype;
387 const std::vector < Dimension * >&getDimensions ()
const
393 const std::vector < char >&getFillValue ()
const
399 bool getYDimMajor ()
const
401 return this->ydimmajor;
405 bool getSpecialLon ()
const
407 return this->speciallon;
411 int getSpecialLLFormat ()
const
413 return this->specialformat;
417 bool getCondensedDim ()
const
419 return this->condenseddim;
423 bool UseDimMap ()
const
436 const short UseFieldCache ()
const
438 return this->field_cache;
452 std::vector < Dimension * >dims;
455 std::vector < Dimension * >correcteddims;
462 std::vector < char >filler;
465 std::string coordinates;
522 friend class Dataset;
523 friend class SwathDimensionAdjustment;
524 friend class GridDataset;
525 friend class SwathDataset;
531 class GeoField:
public Field
548 const std::string & getName ()
const
554 const std::string & getNewName ()
const
556 return this->newname;
560 int32 getType ()
const
566 int32 getCount ()
const
572 const std::vector < char >&getValue ()
const
592 std::vector < char >value;
594 friend class Dataset;
604 const std::string & getName ()
const
609 const std::vector < Dimension * >&getDimensions ()
const
614 const std::vector < Field * >&getDataFields ()
const
616 return this->datafields;
620 const std::vector < Attribute * >&getAttributes ()
const
626 SOType getScaleType ()
const
628 return this->scaletype;
633 explicit Dataset (
const std::string & n)
634 : datasetid (-1), addfvalueattr(false),name (n),scaletype(DEFAULT_CF_EQU)
639 virtual ~ Dataset ();
643 void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
644 int32 (*inq) (int32,
char *, int32 *),
645 std::vector < Dimension * >&dims)
throw (Exception);
650 void ReadFields (int32 (*entries) (int32, int32, int32 *),
651 int32 (*inq) (int32,
char *, int32 *, int32 *),
652 intn (*fldinfo) (int32,
char *, int32 *, int32 *,
654 intn (*readfld) (int32,
char *, int32 *, int32 *,
656 intn (*getfill) (int32,
char *, VOIDP),
657 bool geofield, std::vector < Field * >&fields)
662 void ReadAttributes (int32 (*inq) (int32,
char *, int32 *),
663 intn (*attrinfo) (int32,
char *, int32 *, int32 *),
664 intn (*readattr) (int32,
char *, VOIDP),
665 std::vector < Attribute * >&attrs)
674 void SetScaleType(
const std::string EOS2ObjName)
throw(Exception);
689 std::vector < Dimension * >dims;
692 std::vector < Field * >datafields;
695 std::vector < Attribute * >attrs;
699 std::map < std::string, std::string > dimcvarlist;
702 std::map < std::string, std::string > ncvarnamelist;
705 std::map < std::string, std::string > ndimnamelist;
726 class GridDataset:
public Dataset
750 const float64 *getUpLeft ()
const
760 const float64 *getLowRight ()
const
762 return this->lowright;
776 friend class GridDataset;
787 int32 getCode ()
const
793 int32 getZone ()
const
799 int32 getSphere ()
const
805 const float64 *getParam ()
const
811 int32 getPix ()
const
817 int32 getOrigin ()
const
839 friend class GridDataset;
850 bool isYDimMajor () throw (Exception);
857 explicit Calculated (const GridDataset * eos_grid)
858 : grid (eos_grid), ydimmajor (false)
862 Calculated & operator= (
const Calculated & victim)
864 if (
this != &victim) {
865 this->grid = victim.grid;
866 this->ydimmajor = victim.ydimmajor;
873 void DetectMajorDimension () throw (Exception);
876 int DetectFieldMajorDimension () throw (Exception);
880 const GridDataset *grid;
883 friend class GridDataset;
889 static GridDataset *Read (int32 fd, const std::
string & gridname) throw (Exception);
891 virtual ~ GridDataset ();
894 const Info & getInfo ()
const
900 const Projection & getProjection ()
const
906 Calculated & getCalculated ()
const;
909 void setDimxName (std::string dxname)
914 void setDimyName (std::string dyname)
920 bool getLatLonFlag ()
const
922 return this->ownllflag;
926 explicit GridDataset (
const std::string & g_name)
927 : Dataset (g_name), calculated (0), ownllflag (false), iscoard (false)
943 mutable Calculated calculated;
956 std::string dimxname;
957 std::string dimyname;
969 class SwathDataset:
public Dataset
991 const std::string & getGeoDimension ()
const
995 const std::string & getDataDimension ()
const
997 return this->datadim;
999 int32 getOffset ()
const
1001 return this->offset;
1003 int32 getIncrement ()
const
1005 return this->increment;
1009 DimensionMap (
const std::string & eos_geodim,
const std::string & eos_datadim, int32 eos_offset, int32 dimmap_increment)
1010 : geodim (eos_geodim), datadim (eos_datadim), offset (eos_offset), increment (dimmap_increment)
1017 std::string datadim;
1021 friend class SwathDataset;
1022 friend class SwathDimensionAdjustment;
1032 const std::string & getGeoDimension ()
const
1036 const std::string & getDataDimension ()
const
1040 const LightVector < int32 > &getIndices ()
const
1042 return this->indices;
1048 LightVector < int32 > indices;
1050 friend class SwathDataset;
1055 static SwathDataset *Read (int32 fd,
const std::string & swathname)
throw (Exception);
1057 virtual ~ SwathDataset ();
1060 const std::vector < DimensionMap * >&getDimensionMaps ()
const
1062 return this->dimmaps;
1064 const std::vector < IndexMap * >&getIndexMaps ()
const
1066 return this->indexmaps;
1070 const std::vector < Field * >&getGeoFields ()
const
1072 return this->geofields;
1077 void set_num_map (
int this_num_map)
1079 num_map = this_num_map;
1081 int get_num_map ()
const
1087 explicit SwathDataset (
const std::string & swath_name)
1088 : Dataset (swath_name),num_map(0) {
1094 int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps)
throw (Exception);
1097 void ReadIndexMaps (std::vector < IndexMap * >&indexmaps)
throw (Exception);
1101 std::vector < DimensionMap * >dimmaps;
1104 std::vector < IndexMap * >indexmaps;
1107 std::set < std::string > nonmisscvdimlist;
1110 std::vector < Field * >geofields;
1122 class PointDataset:
public Dataset
1125 static PointDataset *Read (int32 fd,
const std::string & point_name)
throw (Exception);
1126 virtual ~ PointDataset ();
1129 explicit PointDataset (
const std::string & point_name)
1130 : Dataset (point_name)
1143 static File *Read (
const char *path,int32 gridfd,int32 swathfd)
throw (Exception);
1149 void Prepare(
const char *path)
throw(Exception);
1152 bool check_special_1d_grid() throw(Exception);
1157 bool getOneLatLon ()
1159 return this->onelatlon;
1165 const std::string & getPath ()
const
1170 const std::vector < GridDataset * >&getGrids ()
const
1175 const std::vector < SwathDataset * >&getSwaths ()
const
1177 return this->swaths;
1180 const std::vector < PointDataset * >&getPoints ()
const
1182 return this->points;
1185 const std::string get_first_grid_name()
const
1186 {
return this->grids[0]->getName();}
1199 explicit File (
const char *eos2_file_path)
1200 : path (eos2_file_path), onelatlon (false), iscoard (false), gridfd (-1), swathfd (-1)
1210 std::vector < GridDataset * >grids;
1213 std::vector < SwathDataset * >swaths;
1216 std::vector < PointDataset * >points;
1237 std::string get_geodim_x_name ();
1238 std::string get_geodim_y_name ();
1244 void _find_geodim_names ();
1246 std::string _geodim_x_name;
1247 std::string _geodim_y_name;
1248 static const char *_geodim_x_names[];
1249 static const char *_geodim_y_names[];
1260 std::string get_latfield_name ();
1261 std::string get_lonfield_name ();
1267 void _find_latlonfield_names ();
1269 std::string _latfield_name;
1270 std::string _lonfield_name;
1271 static const char *_latfield_names[];
1272 static const char *_lonfield_names[];
1279 std::string get_geogrid_name ();
1284 void _find_geogrid_name ();
1286 std::string _geogrid_name;
1287 static const char *_geogrid_names[];
1293 void check_onelatlon_grids();
1296 void handle_one_grid_zdim(GridDataset*);
1299 void handle_one_grid_latlon(GridDataset*)
throw(Exception);
1303 void handle_onelatlon_grids() throw (Exception);
1306 void handle_grid_dim_cvar_maps() throw(Exception);
1309 void handle_grid_coards() throw(Exception);
1312 void update_grid_field_corrected_dims() throw(Exception);
1316 void handle_grid_cf_attrs() throw(Exception);
1319 void handle_grid_SOM_projection() throw(Exception);
1322 int obtain_dimmap_num(
int numswath) throw(Exception);
1326 void create_swath_latlon_dim_cvar_map(
int numdm) throw(Exception);
1329 void create_swath_nonll_dim_cvar_map() throw(Exception);
1333 void handle_swath_dim_cvar_maps(
int numdm) throw(Exception);
1337 void handle_swath_cf_attrs() throw(Exception);
1370 static bool ReadNamelist (
const char *path,
1371 int32 (*inq) (
char *,
char *, int32 *),
1372 std::vector < std::string > &names);