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)
77 ~ Exception () throw () override = default;
80 const
char *what () const throw ()
override
82 return this->message.c_str ();
87 virtual bool getFileType ()
89 return this->isHDFEOS2;
93 virtual void setFileType (
bool isHDFEOS2_flag)
95 this->isHDFEOS2 = isHDFEOS2_flag;
99 virtual void setException (
const std::string & exception_message)
101 this->message = exception_message;
106 bool isHDFEOS2 =
true;
117 template <
typename T >
class LightVector {
119 LightVector () =
default;
121 LightVector (
const LightVector < T > &that)
123 this->data =
new T[that.length];
124 for (
unsigned int i = 0; i < that.length; ++i)
125 this->data[i] = that[i];
126 this->length = that.length;
127 this->capacity = that.length;
135 void push_back (
const T & d)
137 this->reserve (this->length + 1);
138 this->data[this->length] = d;
142 void reserve (
unsigned int len)
144 if (this->capacity >= len)
147 this->capacity = len;
150 this->data =
new T[len];
152 for (
unsigned int i = 0; i < this->length; ++i)
153 this->data[i] = old[i];
158 void resize (
unsigned int len)
161 if (this->length == len)
163 else if (this->length < len) {
164 if (this->capacity < len) {
165 this->capacity = len;
168 this->data =
new T[len];
170 for (
unsigned int i = 0; i < this->length; ++i)
171 this->data[i] = old[i];
177 this->capacity = len;
180 this->data =
new T[len];
181 for (
unsigned int i = 0; i < len; ++i)
182 this->data[i] = old[i];
189 unsigned int size ()
const
194 T & operator[] (
unsigned int i)
196 return this->data[i];
198 const T & operator[] (
unsigned int i)
const
200 return this->data[i];
203 LightVector < T > &operator= (
const LightVector < T > &that)
206 this->data =
new T[that.length];
207 for (
unsigned int i = 0; i < that.length; ++i)
208 this->data[i] = that[i];
209 this->length = that.length;
210 this->capacity = that.length;
217 unsigned int length = 0;
218 unsigned int capacity = 0;
221 class SwathDimensionAdjustment;
229 const std::string & getName ()
const
233 int32 getSize ()
const
235 return this->dimsize;
239 Dimension (
const std::string & eos_dname, int32 eos_dimsize)
240 : name (eos_dname), dimsize (eos_dimsize)
249 friend class Dataset;
250 friend class SwathDimensionAdjustment;
274 const std::string & getName ()
const
280 const std::string & getNewName ()
const
282 return this->newname;
286 int32 getRank ()
const
292 int32 getType ()
const
298 const std::vector < Dimension * >&getCorrectedDimensions ()
const
300 return this->correcteddims;
304 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
306 return &(this->correcteddims);
310 void setCorrectedDimensions (std::vector < Dimension * >eos_dims)
312 correcteddims = eos_dims;
316 const std::string getCoordinate ()
const
318 return this->coordinates;
322 void setCoordinates (
const std::string& coor)
328 std::string getUnits ()
const
334 void setUnits (
const std::string& uni)
340 float getAddedFillValue ()
const
342 return this->addedfv;
350 void addFillValue (
float fv)
356 bool haveAddedFillValue ()
const
358 return this->haveaddedfv;
362 void setAddedFillValue (
bool havefv)
364 haveaddedfv = havefv;
377 int getFieldType ()
const
379 return this->fieldtype;
383 const std::vector < Dimension * >&getDimensions ()
const
389 const std::vector < char >&getFillValue ()
const
397 int getLLDim0Offset ()
const
399 return this->ll_dim0_offset;
401 int getLLDim0Inc ()
const
403 return this->ll_dim0_inc;
405 int getLLDim1Offset ()
const
407 return this->ll_dim1_offset;
409 int getLLDim1Inc ()
const
411 return this->ll_dim1_inc;
416 bool getYDimMajor ()
const
418 return this->ydimmajor;
422 bool getSpecialLon ()
const
424 return this->speciallon;
428 int getSpecialLLFormat ()
const
430 return this->specialformat;
434 bool getCondensedDim ()
const
436 return this->condenseddim;
440 bool UseDimMap ()
const
453 const short UseFieldCache ()
const
455 return this->field_cache;
469 std::vector < Dimension * >dims;
472 std::vector < Dimension * >correcteddims;
479 std::vector < char >filler;
482 std::string coordinates;
505 bool condenseddim =
false;
508 bool iscoard =
false;
512 bool ydimmajor =
true;
515 bool speciallon =
false;
525 int specialformat = 0;
533 bool haveaddedfv =
false;
539 float addedfv = -9999.0;
544 friend class Dataset;
545 friend class SwathDimensionAdjustment;
546 friend class GridDataset;
547 friend class SwathDataset;
553 class GeoField:
public Field
570 const std::string & getName ()
const
576 const std::string & getNewName ()
const
578 return this->newname;
582 int32 getType ()
const
588 int32 getCount ()
const
594 const std::vector < char >&getValue ()
const
614 std::vector < char >value;
616 friend class Dataset;
626 const std::string & getName ()
const
631 const std::vector < Dimension * >&getDimensions ()
const
636 const std::vector < Field * >&getDataFields ()
const
638 return this->datafields;
642 const std::vector < Attribute * >&getAttributes ()
const
648 SOType getScaleType ()
const
650 return this->scaletype;
655 explicit Dataset (
const std::string & n)
656 : datasetid (-1), addfvalueattr(false),name (n),scaletype(DEFAULT_CF_EQU)
661 virtual ~ Dataset ();
665 void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
666 int32 (*inq) (int32,
char *, int32 *),
667 std::vector < Dimension * >&dims)
throw (Exception);
672 void ReadFields (int32 (*entries) (int32, int32, int32 *),
673 int32 (*inq) (int32,
char *, int32 *, int32 *),
674 intn (*fldinfo) (int32,
char *, int32 *, int32 *,
676 intn (*readfld) (int32,
char *, int32 *, int32 *,
678 intn (*getfill) (int32,
char *, VOIDP),
679 bool geofield, std::vector < Field * >&fields)
684 void ReadAttributes (int32 (*inq) (int32,
char *, int32 *),
685 intn (*attrinfo) (int32,
char *, int32 *, int32 *),
686 intn (*readattr) (int32,
char *, VOIDP),
687 std::vector < Attribute * >&attrs)
696 void SetScaleType(
const std::string & EOS2ObjName)
throw(Exception);
698 int obtain_dimsize_with_dimname(
const std::string& dimname);
712 std::vector < Dimension * >dims;
715 std::vector < Field * >datafields;
718 std::vector < Attribute * >attrs;
722 std::map < std::string, std::string > dimcvarlist;
725 std::map < std::string, std::string > ncvarnamelist;
728 std::map < std::string, std::string > ndimnamelist;
749 class GridDataset:
public Dataset
773 const float64 *getUpLeft ()
const
783 const float64 *getLowRight ()
const
785 return this->lowright;
796 friend class GridDataset;
807 int32 getCode ()
const
813 int32 getZone ()
const
819 int32 getSphere ()
const
825 const float64 *getParam ()
const
831 int32 getPix ()
const
837 int32 getOrigin ()
const
843 Projection() =
default;
853 friend class GridDataset;
864 bool isYDimMajor () throw (Exception);
873 explicit Calculated (
const GridDataset * eos_grid)
878 Calculated & operator= (
const Calculated & victim)
880 if (
this != &victim) {
881 this->grid = victim.grid;
882 this->ydimmajor = victim.ydimmajor;
889 void DetectMajorDimension () throw (Exception);
892 int DetectFieldMajorDimension () throw (Exception);
896 const GridDataset *grid;
897 bool ydimmajor = false;
899 friend class GridDataset;
905 static GridDataset *Read (int32 fd, const std::
string & gridname) throw (Exception);
907 ~ GridDataset () override;
910 const Info & getInfo ()
const
916 const Projection & getProjection ()
const
922 Calculated & getCalculated ()
const;
925 void setDimxName (
const std::string &dxname)
930 void setDimyName (
const std::string &dyname)
936 bool getLatLonFlag ()
const
938 return this->ownllflag;
942 explicit GridDataset (
const std::string & g_name)
943 : Dataset (g_name), calculated(0)
957 mutable Calculated calculated;
960 bool ownllflag =
false;
963 bool iscoard =
false;
966 Field *latfield =
nullptr;
967 Field *lonfield =
nullptr;
970 std::string dimxname;
971 std::string dimyname;
983 class SwathDataset:
public Dataset
1006 const std::string & getGeoDimension ()
const
1008 return this->geodim;
1010 const std::string & getDataDimension ()
const
1012 return this->datadim;
1014 int32 getOffset ()
const
1016 return this->offset;
1018 int32 getIncrement ()
const
1020 return this->increment;
1024 DimensionMap (
const std::string & eos_geodim,
const std::string & eos_datadim, int32 eos_offset, int32 dimmap_increment)
1025 : geodim (eos_geodim), datadim (eos_datadim), offset (eos_offset), increment (dimmap_increment)
1032 std::string datadim;
1036 friend class SwathDataset;
1037 friend class SwathDimensionAdjustment;
1047 const std::string & getGeoDimension ()
const
1051 const std::string & getDataDimension ()
const
1055 const LightVector < int32 > &getIndices ()
const
1057 return this->indices;
1063 LightVector < int32 > indices;
1065 friend class SwathDataset;
1070 static SwathDataset *Read (int32 fd,
const std::string & swathname)
throw (Exception);
1072 ~ SwathDataset ()
override;
1075 const std::vector < DimensionMap * >&getDimensionMaps ()
const
1077 return this->dimmaps;
1079 const std::vector < IndexMap * >&getIndexMaps ()
const
1081 return this->indexmaps;
1085 const std::vector < Field * >&getGeoFields ()
const
1087 return this->geofields;
1092 void set_num_map (
int this_num_map)
1094 num_map = this_num_map;
1096 int get_num_map ()
const
1102 explicit SwathDataset (
const std::string & swath_name)
1103 : Dataset (swath_name) {
1109 int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps)
throw (Exception);
1111 bool obtain_dmap_offset_inc(
const std::string& o_dimname,
const std::string& n_dimmname,
int&,
int&) ;
1114 void ReadIndexMaps (std::vector < IndexMap * >&indexmaps)
throw (Exception);
1121 std::vector < DimensionMap * >dimmaps;
1124 std::vector < IndexMap * >indexmaps;
1127 std::set < std::string > nonmisscvdimlist;
1130 std::vector < Field * >geofields;
1136 bool GeoDim_in_vars =
false;
1144 class PointDataset:
public Dataset
1147 static PointDataset *Read (int32 fd,
const std::string & point_name)
throw (Exception);
1148 ~ PointDataset ()
override;
1151 explicit PointDataset (
const std::string & point_name)
1152 : Dataset (point_name)
1165 static File *Read (
const char *path,int32 gridfd,int32 swathfd)
throw (Exception);
1171 void Prepare(
const char *path)
throw(Exception);
1174 bool check_special_1d_grid() throw(Exception);
1179 bool getOneLatLon ()
const
1181 return this->onelatlon;
1187 const std::string & getPath ()
const
1192 const std::vector < GridDataset * >&getGrids ()
const
1197 const std::vector < SwathDataset * >&getSwaths ()
const
1199 return this->swaths;
1202 bool getMultiDimMaps()
const
1204 return this->multi_dimmap;
1206 const std::vector < PointDataset * >&getPoints ()
const
1208 return this->points;
1211 std::string get_first_grid_name()
const
1213 return this->grids[0]->getName();
1228 explicit File (
const char *eos2_file_path)
1229 : path (eos2_file_path)
1239 std::vector < GridDataset * >grids;
1242 std::vector < SwathDataset * >swaths;
1245 std::vector < PointDataset * >points;
1253 bool onelatlon =
false;
1256 bool iscoard =
false;
1264 bool handle_swath_dimmap =
false;
1269 bool backward_handle_swath_dimmap =
false;
1272 bool multi_dimmap =
false;
1282 std::string get_geodim_x_name ();
1283 std::string get_geodim_y_name ();
1289 void _find_geodim_names ();
1291 std::string _geodim_x_name;
1292 std::string _geodim_y_name;
1293 static const char *_geodim_x_names[];
1294 static const char *_geodim_y_names[];
1305 std::string get_latfield_name ();
1306 std::string get_lonfield_name ();
1312 void _find_latlonfield_names ();
1314 std::string _latfield_name;
1315 std::string _lonfield_name;
1316 static const char *_latfield_names[];
1317 static const char *_lonfield_names[];
1324 std::string get_geogrid_name ();
1329 void _find_geogrid_name ();
1331 std::string _geogrid_name;
1332 static const char *_geogrid_names[];
1338 void check_onelatlon_grids();
1341 void handle_one_grid_zdim(GridDataset*);
1344 void handle_one_grid_latlon(GridDataset*)
throw(Exception);
1348 void handle_onelatlon_grids() throw (Exception);
1351 void handle_grid_dim_cvar_maps() throw(Exception);
1354 void handle_grid_coards() throw(Exception);
1357 void update_grid_field_corrected_dims() throw(Exception);
1361 void handle_grid_cf_attrs() throw(Exception);
1364 void handle_grid_SOM_projection() throw(Exception);
1366 bool find_dim_in_dims(const std::vector<Dimension*>&dims,const std::
string &dim_name) const;
1370 void check_swath_dimmap(
int numswath) throw(Exception);
1372 void check_swath_dimmap_bk_compat(
int numswath);
1376 void create_swath_latlon_dim_cvar_map() throw(Exception);
1379 void create_swath_nonll_dim_cvar_map() throw(Exception);
1383 void handle_swath_dim_cvar_maps() throw(Exception);
1387 void handle_swath_cf_attrs() throw(Exception);
1389 bool check_ll_in_coords(const std::
string& vname) throw(Exception);
1396 void check_dm_geo_dims_in_vars();
1399 void create_swath_latlon_dim_cvar_map_for_dimmap(SwathDataset*,Field*,Field*) throw(Exception);
1401 void create_geo_varnames_list(std::vector<std::
string> &,const std::
string &,
1402 const std::
string &,
int,
bool);
1404 void create_geo_dim_var_maps(SwathDataset*, Field*, const std::vector<std::
string>&,
1405 const std::vector<std::
string>&,
1406 std::vector<Dimension*>&, std::vector<Dimension*>&);
1407 void create_geo_vars(SwathDataset*,Field*,Field*,const std::vector<std::
string>&,const std::vector<std::
string>&,
1408 std::vector<Dimension*>&, std::vector<Dimension*>&) throw(Exception);
1410 void update_swath_dims_for_dimmap(SwathDataset*,
1411 const std::vector<Dimension*>&, const std::vector<Dimension*>&);
1446 static bool ReadNamelist (
const char *path,
1447 int32 (*inq) (
char *,
char *, int32 *),
1448 std::vector < std::string > &names);