15#define _CRTDBG_MAP_ALLOC
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)
282 const std::string & getName ()
const
288 const std::string & getNewName ()
const
290 return this->newname;
294 int32 getRank ()
const
300 int32 getType ()
const
306 const std::vector < Dimension * >&getCorrectedDimensions ()
const
308 return this->correcteddims;
312 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
314 return &(this->correcteddims);
318 void setCorrectedDimensions (std::vector < Dimension * >eos_dims)
320 correcteddims = eos_dims;
324 const std::string getCoordinate ()
const
326 return this->coordinates;
330 void setCoordinates (std::string coor)
336 const std::string getUnits ()
const
342 void setUnits (std::string uni)
348 float getAddedFillValue ()
const
350 return this->addedfv;
358 void addFillValue (
float fv)
364 bool haveAddedFillValue ()
const
366 return this->haveaddedfv;
370 void setAddedFillValue (
bool havefv)
372 haveaddedfv = havefv;
385 int getFieldType ()
const
387 return this->fieldtype;
391 const std::vector < Dimension * >&getDimensions ()
const
397 const std::vector < char >&getFillValue ()
const
405 const int getLLDim0Offset ()
const
407 return this->ll_dim0_offset;
409 const int getLLDim0Inc ()
const
411 return this->ll_dim0_inc;
413 const int getLLDim1Offset ()
const
415 return this->ll_dim1_offset;
417 const int getLLDim1Inc ()
const
419 return this->ll_dim1_inc;
424 bool getYDimMajor ()
const
426 return this->ydimmajor;
430 bool getSpecialLon ()
const
432 return this->speciallon;
436 int getSpecialLLFormat ()
const
438 return this->specialformat;
442 bool getCondensedDim ()
const
444 return this->condenseddim;
448 bool UseDimMap ()
const
461 const short UseFieldCache ()
const
463 return this->field_cache;
477 std::vector < Dimension * >dims;
480 std::vector < Dimension * >correcteddims;
487 std::vector < char >filler;
490 std::string coordinates;
552 friend class Dataset;
553 friend class SwathDimensionAdjustment;
554 friend class GridDataset;
555 friend class SwathDataset;
561 class GeoField:
public Field
578 const std::string & getName ()
const
584 const std::string & getNewName ()
const
586 return this->newname;
590 int32 getType ()
const
596 int32 getCount ()
const
602 const std::vector < char >&getValue ()
const
622 std::vector < char >value;
624 friend class Dataset;
634 const std::string & getName ()
const
639 const std::vector < Dimension * >&getDimensions ()
const
644 const std::vector < Field * >&getDataFields ()
const
646 return this->datafields;
650 const std::vector < Attribute * >&getAttributes ()
const
656 SOType getScaleType ()
const
658 return this->scaletype;
663 explicit Dataset (
const std::string & n)
664 : datasetid (-1), addfvalueattr(false),name (n),scaletype(DEFAULT_CF_EQU)
669 virtual ~ Dataset ();
673 void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
674 int32 (*inq) (int32,
char *, int32 *),
675 std::vector < Dimension * >&dims)
throw (Exception);
680 void ReadFields (int32 (*entries) (int32, int32, int32 *),
681 int32 (*inq) (int32,
char *, int32 *, int32 *),
682 intn (*fldinfo) (int32,
char *, int32 *, int32 *,
684 intn (*readfld) (int32,
char *, int32 *, int32 *,
686 intn (*getfill) (int32,
char *, VOIDP),
687 bool geofield, std::vector < Field * >&fields)
692 void ReadAttributes (int32 (*inq) (int32,
char *, int32 *),
693 intn (*attrinfo) (int32,
char *, int32 *, int32 *),
694 intn (*readattr) (int32,
char *, VOIDP),
695 std::vector < Attribute * >&attrs)
704 void SetScaleType(
const std::string EOS2ObjName)
throw(Exception);
706 int obtain_dimsize_with_dimname(
const std::string& dimname);
720 std::vector < Dimension * >dims;
723 std::vector < Field * >datafields;
726 std::vector < Attribute * >attrs;
730 std::map < std::string, std::string > dimcvarlist;
733 std::map < std::string, std::string > ncvarnamelist;
736 std::map < std::string, std::string > ndimnamelist;
757 class GridDataset:
public Dataset
781 const float64 *getUpLeft ()
const
791 const float64 *getLowRight ()
const
793 return this->lowright;
807 friend class GridDataset;
818 int32 getCode ()
const
824 int32 getZone ()
const
830 int32 getSphere ()
const
836 const float64 *getParam ()
const
842 int32 getPix ()
const
848 int32 getOrigin ()
const
870 friend class GridDataset;
881 bool isYDimMajor () throw (Exception);
888 explicit Calculated (const GridDataset * eos_grid)
889 : grid (eos_grid), ydimmajor (false)
893 Calculated & operator= (
const Calculated & victim)
895 if (
this != &victim) {
896 this->grid = victim.grid;
897 this->ydimmajor = victim.ydimmajor;
904 void DetectMajorDimension () throw (Exception);
907 int DetectFieldMajorDimension () throw (Exception);
911 const GridDataset *grid;
914 friend class GridDataset;
920 static GridDataset *Read (int32 fd, const std::
string & gridname) throw (Exception);
922 virtual ~ GridDataset ();
925 const Info & getInfo ()
const
931 const Projection & getProjection ()
const
937 Calculated & getCalculated ()
const;
940 void setDimxName (std::string dxname)
945 void setDimyName (std::string dyname)
951 bool getLatLonFlag ()
const
953 return this->ownllflag;
957 explicit GridDataset (
const std::string & g_name)
958 : Dataset (g_name), calculated (0), ownllflag (false), iscoard (false)
974 mutable Calculated calculated;
987 std::string dimxname;
988 std::string dimyname;
1000 class SwathDataset:
public Dataset
1023 const std::string & getGeoDimension ()
const
1025 return this->geodim;
1027 const std::string & getDataDimension ()
const
1029 return this->datadim;
1031 int32 getOffset ()
const
1033 return this->offset;
1035 int32 getIncrement ()
const
1037 return this->increment;
1041 DimensionMap (
const std::string & eos_geodim,
const std::string & eos_datadim, int32 eos_offset, int32 dimmap_increment)
1042 : geodim (eos_geodim), datadim (eos_datadim), offset (eos_offset), increment (dimmap_increment)
1049 std::string datadim;
1053 friend class SwathDataset;
1054 friend class SwathDimensionAdjustment;
1064 const std::string & getGeoDimension ()
const
1068 const std::string & getDataDimension ()
const
1072 const LightVector < int32 > &getIndices ()
const
1074 return this->indices;
1080 LightVector < int32 > indices;
1082 friend class SwathDataset;
1087 static SwathDataset *Read (int32 fd,
const std::string & swathname)
throw (Exception);
1089 virtual ~ SwathDataset ();
1092 const std::vector < DimensionMap * >&getDimensionMaps ()
const
1094 return this->dimmaps;
1096 const std::vector < IndexMap * >&getIndexMaps ()
const
1098 return this->indexmaps;
1102 const std::vector < Field * >&getGeoFields ()
const
1104 return this->geofields;
1109 void set_num_map (
int this_num_map)
1111 num_map = this_num_map;
1113 int get_num_map ()
const
1119 explicit SwathDataset (
const std::string & swath_name)
1120 : Dataset (swath_name),num_map(0),GeoDim_in_vars(false) {
1126 int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps)
throw (Exception);
1128 bool obtain_dmap_offset_inc(
const std::string& o_dimname,
const std::string& n_dimmname,
int&,
int&) ;
1131 void ReadIndexMaps (std::vector < IndexMap * >&indexmaps)
throw (Exception);
1138 std::vector < DimensionMap * >dimmaps;
1141 std::vector < IndexMap * >indexmaps;
1144 std::set < std::string > nonmisscvdimlist;
1147 std::vector < Field * >geofields;
1153 bool GeoDim_in_vars;
1161 class PointDataset:
public Dataset
1164 static PointDataset *Read (int32 fd,
const std::string & point_name)
throw (Exception);
1165 virtual ~ PointDataset ();
1168 explicit PointDataset (
const std::string & point_name)
1169 : Dataset (point_name)
1182 static File *Read (
const char *path,int32 gridfd,int32 swathfd)
throw (Exception);
1188 void Prepare(
const char *path)
throw(Exception);
1191 bool check_special_1d_grid() throw(Exception);
1196 bool getOneLatLon ()
1198 return this->onelatlon;
1204 const std::string & getPath ()
const
1209 const std::vector < GridDataset * >&getGrids ()
const
1214 const std::vector < SwathDataset * >&getSwaths ()
const
1216 return this->swaths;
1219 const bool getMultiDimMaps()
const
1221 return this->multi_dimmap;
1223 const std::vector < PointDataset * >&getPoints ()
const
1225 return this->points;
1228 const std::string get_first_grid_name()
const
1229 {
return this->grids[0]->getName();}
1242 explicit File (
const char *eos2_file_path)
1243 : path (eos2_file_path), onelatlon (false), iscoard (false), handle_swath_dimmap(false),backward_handle_swath_dimmap(false),multi_dimmap(false),gridfd (-1), swathfd (-1)
1253 std::vector < GridDataset * >grids;
1256 std::vector < SwathDataset * >swaths;
1259 std::vector < PointDataset * >points;
1278 bool handle_swath_dimmap;
1283 bool backward_handle_swath_dimmap;
1296 std::string get_geodim_x_name ();
1297 std::string get_geodim_y_name ();
1303 void _find_geodim_names ();
1305 std::string _geodim_x_name;
1306 std::string _geodim_y_name;
1307 static const char *_geodim_x_names[];
1308 static const char *_geodim_y_names[];
1319 std::string get_latfield_name ();
1320 std::string get_lonfield_name ();
1326 void _find_latlonfield_names ();
1328 std::string _latfield_name;
1329 std::string _lonfield_name;
1330 static const char *_latfield_names[];
1331 static const char *_lonfield_names[];
1338 std::string get_geogrid_name ();
1343 void _find_geogrid_name ();
1345 std::string _geogrid_name;
1346 static const char *_geogrid_names[];
1352 void check_onelatlon_grids();
1355 void handle_one_grid_zdim(GridDataset*);
1358 void handle_one_grid_latlon(GridDataset*)
throw(Exception);
1362 void handle_onelatlon_grids() throw (Exception);
1365 void handle_grid_dim_cvar_maps() throw(Exception);
1368 void handle_grid_coards() throw(Exception);
1371 void update_grid_field_corrected_dims() throw(Exception);
1375 void handle_grid_cf_attrs() throw(Exception);
1378 void handle_grid_SOM_projection() throw(Exception);
1380 bool find_dim_in_dims(const std::vector<Dimension*>&dims,const std::
string &dim_name);
1384 void check_swath_dimmap(
int numswath) throw(Exception);
1386 void check_swath_dimmap_bk_compat(
int numswath);
1390 void create_swath_latlon_dim_cvar_map() throw(Exception);
1393 void create_swath_nonll_dim_cvar_map() throw(Exception);
1397 void handle_swath_dim_cvar_maps() throw(Exception);
1401 void handle_swath_cf_attrs() throw(Exception);
1403 bool check_ll_in_coords(const std::
string& vname) throw(Exception);
1410 void check_dm_geo_dims_in_vars();
1413 void create_swath_latlon_dim_cvar_map_for_dimmap(SwathDataset*,Field*,Field*) throw(Exception);
1415 void create_geo_varnames_list(std::vector<std::
string> &,const std::
string &,
1416 const std::
string &,
int,
bool);
1418 void create_geo_dim_var_maps(SwathDataset*, Field*, const std::vector<std::
string>&,
1419 const std::vector<std::
string>&,
1420 std::vector<Dimension*>&, std::vector<Dimension*>&);
1421 void create_geo_vars(SwathDataset*,Field*,Field*,const std::vector<std::
string>&,const std::vector<std::
string>&,
1422 std::vector<Dimension*>&, std::vector<Dimension*>&) throw(Exception);
1424 void update_swath_dims_for_dimmap(SwathDataset*,
1425 const std::vector<Dimension*>&, const std::vector<Dimension*>&);
1460 static bool ReadNamelist (
const char *path,
1461 int32 (*inq) (
char *,
char *, int32 *),
1462 std::vector < std::string > &names);