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;
262 const std::string & getName ()
const
268 const std::string & getNewName ()
const
270 return this->newname;
274 int32 getRank ()
const
280 int32 getType ()
const
286 const std::vector < Dimension * >&getCorrectedDimensions ()
const
288 return this->correcteddims;
292 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
294 return &(this->correcteddims);
298 void setCorrectedDimensions (
const std::vector < Dimension * >& eos_dims)
300 correcteddims = eos_dims;
304 std::string getCoordinate ()
const
306 return this->coordinates;
310 void setCoordinates (
const std::string& coor)
316 std::string getUnits ()
const
322 void setUnits (
const std::string& uni)
328 float getAddedFillValue ()
const
330 return this->addedfv;
338 void addFillValue (
float fv)
344 bool haveAddedFillValue ()
const
346 return this->haveaddedfv;
350 void setAddedFillValue (
bool havefv)
352 haveaddedfv = havefv;
365 int getFieldType ()
const
367 return this->fieldtype;
371 const std::vector < Dimension * >&getDimensions ()
const
377 const std::vector < char >&getFillValue ()
const
385 int getLLDim0Offset ()
const
387 return this->ll_dim0_offset;
389 int getLLDim0Inc ()
const
391 return this->ll_dim0_inc;
393 int getLLDim1Offset ()
const
395 return this->ll_dim1_offset;
397 int getLLDim1Inc ()
const
399 return this->ll_dim1_inc;
404 bool getYDimMajor ()
const
406 return this->ydimmajor;
410 bool getSpecialLon ()
const
412 return this->speciallon;
416 int getSpecialLLFormat ()
const
418 return this->specialformat;
422 bool getCondensedDim ()
const
424 return this->condenseddim;
428 bool UseDimMap ()
const
444 std::vector < Dimension * >dims;
447 std::vector < Dimension * >correcteddims;
454 std::vector < char >filler;
457 std::string coordinates;
480 bool condenseddim =
false;
483 bool iscoard =
false;
487 bool ydimmajor =
true;
490 bool speciallon =
false;
500 int specialformat = 0;
508 bool haveaddedfv =
false;
509 int ll_dim0_offset = 0;
511 int ll_dim1_offset = 0;
514 float addedfv = -9999.0;
519 friend class Dataset;
520 friend class SwathDimensionAdjustment;
521 friend class GridDataset;
522 friend class SwathDataset;
533 const std::string & getName ()
const
539 const std::string & getNewName ()
const
541 return this->newname;
545 int32 getType ()
const
551 int32 getCount ()
const
557 const std::vector < char >&getValue ()
const
577 std::vector < char >value;
579 friend class Dataset;
589 const std::string & getName ()
const
594 const std::vector < Dimension * >&getDimensions ()
const
599 const std::vector < Field * >&getDataFields ()
const
601 return this->datafields;
605 const std::vector < Attribute * >&getAttributes ()
const
611 SOType getScaleType ()
const
613 return this->scaletype;
618 explicit Dataset (
const std::string & n)
620 virtual ~ Dataset ();
624 void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
625 int32 (*inq) (int32,
char *, int32 *),
626 std::vector < Dimension * >&dims) ;
631 void ReadFields (int32 (*entries) (int32, int32, int32 *),
632 int32 (*inq) (int32,
char *, int32 *, int32 *),
633 intn (*fldinfo) (int32,
char *, int32 *, int32 *,
635 intn (*getfill) (int32,
char *, VOIDP),
636 bool geofield, std::vector < Field * >&fields)
641 void ReadAttributes (int32 (*inq) (int32,
char *, int32 *),
642 intn (*attrinfo) (int32,
char *, int32 *, int32 *),
643 intn (*readattr) (int32,
char *, VOIDP),
644 std::vector < Attribute * >&attrs)
653 void SetScaleType(
const std::string & EOS2ObjName);
655 int obtain_dimsize_with_dimname(
const std::string& dimname)
const;
658 int32 datasetid = -1;
663 bool addfvalueattr =
false;
669 std::vector < Dimension * >dims;
672 std::vector < Field * >datafields;
675 std::vector < Attribute * >attrs;
679 std::map < std::string, std::string > dimcvarlist;
682 std::map < std::string, std::string > ncvarnamelist;
685 std::map < std::string, std::string > ndimnamelist;
699 SOType scaletype = SOType::DEFAULT_CF_EQU;
706 class GridDataset:
public Dataset
730 const float64 *getUpLeft ()
const
740 const float64 *getLowRight ()
const
742 return this->lowright;
753 friend class GridDataset;
764 int32 getCode ()
const
770 int32 getZone ()
const
776 int32 getSphere ()
const
782 const float64 *getParam ()
const
788 int32 getPix ()
const
794 int32 getOrigin ()
const
800 Projection() =
default;
810 friend class GridDataset;
821 bool isYDimMajor () ;
825 explicit Calculated (
const GridDataset * eos_grid)
830 Calculated & operator= (
const Calculated & victim)
832 if (
this != &victim) {
833 this->grid = victim.grid;
834 this->ydimmajor = victim.ydimmajor;
841 void DetectMajorDimension () ;
844 int DetectFieldMajorDimension ()
const;
848 const GridDataset *grid;
849 bool ydimmajor =
false;
851 friend class GridDataset;
857 static GridDataset *Read (int32 fd,
const std::string & gridname) ;
859 ~ GridDataset ()
override;
862 const Info & getInfo ()
const
868 const Projection & getProjection ()
const
874 Calculated & getCalculated ()
const;
877 void setDimxName (
const std::string &dxname)
882 void setDimyName (
const std::string &dyname)
888 bool getLatLonFlag ()
const
890 return this->ownllflag;
894 explicit GridDataset (
const std::string & g_name)
895 : Dataset (g_name),calculated(0)
909 mutable Calculated calculated;
912 bool ownllflag =
false;
915 bool iscoard =
false;
918 Field *latfield =
nullptr;
919 Field *lonfield =
nullptr;
922 std::string dimxname;
923 std::string dimyname;
935 class SwathDataset:
public Dataset
958 const std::string & getGeoDimension ()
const
962 const std::string & getDataDimension ()
const
964 return this->datadim;
966 int32 getOffset ()
const
970 int32 getIncrement ()
const
972 return this->increment;
976 DimensionMap (
const std::string & eos_geodim,
const std::string & eos_datadim, int32 eos_offset, int32 dimmap_increment)
977 : geodim (eos_geodim), datadim (eos_datadim), offset (eos_offset), increment (dimmap_increment)
988 friend class SwathDataset;
989 friend class SwathDimensionAdjustment;
999 const std::string & getGeoDimension ()
const
1003 const std::string & getDataDimension ()
const
1007 const LightVector < int32 > &getIndices ()
const
1009 return this->indices;
1015 LightVector < int32 > indices;
1017 friend class SwathDataset;
1022 static SwathDataset *Read (int32 fd,
const std::string & swathname) ;
1024 ~ SwathDataset ()
override;
1027 const std::vector < DimensionMap * >&getDimensionMaps ()
const
1029 return this->dimmaps;
1031 const std::vector < IndexMap * >&getIndexMaps ()
const
1033 return this->indexmaps;
1037 const std::vector < Field * >&getGeoFields ()
const
1039 return this->geofields;
1044 void set_num_map (
int this_num_map)
1046 num_map = this_num_map;
1048 int get_num_map ()
const
1054 explicit SwathDataset (
const std::string & swath_name)
1055 : Dataset (swath_name) {
1061 int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps) ;
1063 bool obtain_dmap_offset_inc(
const std::string& o_dimname,
const std::string& n_dimmname,
int&,
int&)
const;
1066 void ReadIndexMaps (std::vector < IndexMap * >&indexmaps) ;
1070 std::vector < DimensionMap * >dimmaps;
1073 std::vector < IndexMap * >indexmaps;
1076 std::set < std::string > nonmisscvdimlist;
1079 std::vector < Field * >geofields;
1085 bool GeoDim_in_vars =
false;
1093 class PointDataset:
public Dataset
1096 static PointDataset *Read (int32 fd,
const std::string & point_name) ;
1097 ~ PointDataset ()
override;
1100 explicit PointDataset (
const std::string & point_name)
1101 : Dataset (point_name)
1114 static File *Read (
const char *path,int32 gridfd,int32 swathfd) ;
1120 void Prepare(
const char *path);
1123 bool check_special_1d_grid();
1128 bool getOneLatLon ()
const
1130 return this->onelatlon;
1136 const std::string & getPath ()
const
1141 const std::vector < GridDataset * >&getGrids ()
const
1146 const std::vector < SwathDataset * >&getSwaths ()
const
1148 return this->swaths;
1151 bool getMultiDimMaps()
const
1153 return this->multi_dimmap;
1155 const std::vector < PointDataset * >&getPoints ()
const
1157 return this->points;
1160 std::string get_first_grid_name()
const
1162 return this->grids[0]->getName();
1167 explicit File (
const char *eos2_file_path)
1168 : path (eos2_file_path)
1178 std::vector < GridDataset * >grids;
1181 std::vector < SwathDataset * >swaths;
1184 std::vector < PointDataset * >points;
1192 bool onelatlon =
false;
1195 bool iscoard =
false;
1203 bool handle_swath_dimmap =
false;
1208 bool backward_handle_swath_dimmap =
false;
1211 bool multi_dimmap =
false;
1221 std::string get_geodim_x_name ();
1222 std::string get_geodim_y_name ();
1228 void _find_geodim_names ();
1230 std::string _geodim_x_name;
1231 std::string _geodim_y_name;
1232 static const char *_geodim_x_names[];
1233 static const char *_geodim_y_names[];
1244 std::string get_latfield_name ();
1245 std::string get_lonfield_name ();
1251 void _find_latlonfield_names ();
1253 std::string _latfield_name;
1254 std::string _lonfield_name;
1255 static const char *_latfield_names[];
1256 static const char *_lonfield_names[];
1263 std::string get_geogrid_name ();
1268 void _find_geogrid_name ();
1270 std::string _geogrid_name;
1271 static const char *_geogrid_names[];
1277 void check_onelatlon_grids();
1280 void handle_one_grid_zdim(GridDataset*);
1283 void handle_one_grid_latlon(GridDataset*);
1287 void handle_onelatlon_grids() ;
1290 void handle_grid_dim_cvar_maps() ;
1293 void handle_grid_coards();
1296 void update_grid_field_corrected_dims();
1300 void handle_grid_cf_attrs();
1303 void handle_grid_SOM_projection();
1305 bool find_dim_in_dims(
const std::vector<Dimension*>&dims,
const std::string &dim_name)
const;
1309 void check_swath_dimmap(
int numswath);
1311 void check_swath_dimmap_bk_compat(
int numswath);
1315 void create_swath_latlon_dim_cvar_map();
1318 void create_swath_nonll_dim_cvar_map();
1322 void handle_swath_dim_cvar_maps();
1326 void handle_swath_cf_attrs();
1328 bool check_ll_in_coords(
const std::string& vname);
1335 void check_dm_geo_dims_in_vars()
const;
1338 void create_swath_latlon_dim_cvar_map_for_dimmap(SwathDataset*,Field*,Field*);
1340 void create_geo_varnames_list(std::vector<std::string> &,
const std::string &,
1341 const std::string &,
int,
bool)
const;
1343 void create_geo_dim_var_maps(SwathDataset*, Field*,
const std::vector<std::string>&,
1344 const std::vector<std::string>&,
1345 std::vector<Dimension*>&, std::vector<Dimension*>&)
const;
1346 void create_geo_vars(SwathDataset*,Field*,Field*,
const std::vector<std::string>&,
const std::vector<std::string>&,
1347 std::vector<Dimension*>&, std::vector<Dimension*>&);
1349 void update_swath_dims_for_dimmap(
const SwathDataset*,
1350 const std::vector<Dimension*>&,
const std::vector<Dimension*>&)
const;
1387 static bool ReadNamelist (
const char *path,
1388 int32 (*inq) (
char *,
char *, int32 *),
1389 std::vector < std::string > &names);