15 #define _CRTDBG_MAP_ALLOC
29 #include "HdfEosDef.h"
39 #pragma warning(disable:4290)
67 class Exception:
public std::exception
71 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)
97 this->isHDFEOS2 = isHDFEOS2;
101 virtual void setException (std::string message)
103 this->message = 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 & name, int32 dimsize)
244 : name (name), dimsize (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)
272 const std::string & getName ()
const
278 const std::string & getNewName ()
const
280 return this->newname;
284 int32 getRank ()
const
290 int32 getType ()
const
296 const std::vector < Dimension * >&getCorrectedDimensions ()
const
298 return this->correcteddims;
302 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
304 return &(this->correcteddims);
308 void setCorrectedDimensions (std::vector < Dimension * >dims)
310 correcteddims = dims;
314 const std::string getCoordinate ()
const
316 return this->coordinates;
320 void setCoordinates (std::string coor)
326 const std::string getUnits ()
const
332 void setUnits (std::string uni)
338 const float getAddedFillValue ()
const
340 return this->addedfv;
348 void addFillValue (
float fv)
354 const bool haveAddedFillValue ()
const
356 return this->haveaddedfv;
360 void setAddedFillValue (
bool havefv)
362 haveaddedfv = havefv;
375 const int getFieldType ()
const
377 return this->fieldtype;
381 const std::vector < Dimension * >&getDimensions ()
const
387 const std::vector < char >&getFillValue ()
const
393 const bool getYDimMajor ()
const
395 return this->ydimmajor;
399 const bool getSpecialLon ()
const
401 return this->speciallon;
405 const int getSpecialLLFormat ()
const
407 return this->specialformat;
411 const bool getCondensedDim ()
const
413 return this->condenseddim;
417 const bool UseDimMap ()
const
430 const short UseFieldCache ()
const
432 return this->field_cache;
447 std::vector < Dimension * >dims;
450 std::vector < Dimension * >correcteddims;
457 std::vector < char >filler;
460 std::string coordinates;
525 friend class Dataset;
526 friend class SwathDimensionAdjustment;
527 friend class GridDataset;
528 friend class SwathDataset;
534 class GeoField:
public Field
551 const std::string & getName ()
const
557 const std::string & getNewName ()
const
559 return this->newname;
563 int32 getType ()
const
569 int32 getCount ()
const
575 const std::vector < char >&getValue ()
const
595 std::vector < char >value;
597 friend class Dataset;
607 const std::string & getName ()
const
612 const std::vector < Dimension * >&getDimensions ()
const
617 const std::vector < Field * >&getDataFields ()
const
619 return this->datafields;
623 const std::vector < Attribute * >&getAttributes ()
const
629 const SOType getScaleType ()
const
631 return this->scaletype;
636 Dataset (
const std::string & n)
637 : datasetid (-1), addfvalueattr(false),name (n),scaletype(
DEFAULT_CF_EQU)
641 virtual ~ Dataset ();
645 void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
646 int32 (*inq) (int32,
char *, int32 *),
647 std::vector < Dimension * >&dims)
throw (Exception);
652 void ReadFields (int32 (*entries) (int32, int32, int32 *),
653 int32 (*inq) (int32,
char *, int32 *, int32 *),
654 intn (*fldinfo) (int32,
char *, int32 *, int32 *,
656 intn (*readfld) (int32,
char *, int32 *, int32 *,
658 intn (*getfill) (int32,
char *, VOIDP),
659 bool geofield, std::vector < Field * >&fields)
664 void ReadAttributes (int32 (*inq) (int32,
char *, int32 *),
665 intn (*attrinfo) (int32,
char *, int32 *, int32 *),
666 intn (*readattr) (int32,
char *, VOIDP),
667 std::vector < Attribute * >&attrs)
676 void SetScaleType(
const std::string EOS2ObjName)
throw(Exception);
691 std::vector < Dimension * >dims;
694 std::vector < Field * >datafields;
697 std::vector < Attribute * >attrs;
701 std::map < std::string, std::string > dimcvarlist;
704 std::map < std::string, std::string > ncvarnamelist;
707 std::map < std::string, std::string > ndimnamelist;
728 class GridDataset:
public Dataset
752 const float64 *getUpLeft ()
const
762 const float64 *getLowRight ()
const
764 return this->lowright;
773 friend class GridDataset;
784 int32 getCode ()
const
790 int32 getZone ()
const
796 int32 getSphere ()
const
802 const float64 *getParam ()
const
808 int32 getPix ()
const
814 int32 getOrigin ()
const
827 friend class GridDataset;
838 bool isYDimMajor () throw (Exception);
845 Calculated (const GridDataset * grid)
846 : grid (grid), ydimmajor (false)
850 Calculated & operator= (
const Calculated & victim)
852 if (
this != &victim) {
853 this->grid = victim.grid;
854 this->ydimmajor = victim.ydimmajor;
861 void DetectMajorDimension () throw (Exception);
864 int DetectFieldMajorDimension () throw (Exception);
868 const GridDataset *grid;
871 friend class GridDataset;
877 static GridDataset *Read (int32 fd, const
std::
string & gridname) throw (Exception);
879 virtual ~ GridDataset ();
882 const Info & getInfo ()
const
888 const Projection & getProjection ()
const
894 Calculated & getCalculated ()
const;
897 void setDimxName (std::string dxname)
902 void setDimyName (std::string dyname)
908 const bool getLatLonFlag ()
const
910 return this->ownllflag;
914 GridDataset (
const std::string & name)
915 : Dataset (name), calculated (0), ownllflag (false), iscoard (false)
929 mutable Calculated calculated;
942 std::string dimxname;
943 std::string dimyname;
955 class SwathDataset:
public Dataset
977 const std::string & getGeoDimension ()
const
981 const std::string & getDataDimension ()
const
983 return this->datadim;
985 int32 getOffset ()
const
989 int32 getIncrement ()
const
991 return this->increment;
995 DimensionMap (
const std::string & geodim,
const std::string & datadim, int32 offset, int32 increment)
996 : geodim (geodim), datadim (datadim), offset (offset), increment (increment)
1003 std::string datadim;
1007 friend class SwathDataset;
1008 friend class SwathDimensionAdjustment;
1018 const std::string & getGeoDimension ()
const
1022 const std::string & getDataDimension ()
const
1026 const LightVector < int32 > &getIndices ()
const
1028 return this->indices;
1034 LightVector < int32 > indices;
1036 friend class SwathDataset;
1041 static SwathDataset *Read (int32 fd,
const std::string & swathname)
throw (Exception);
1043 virtual ~ SwathDataset ();
1046 const std::vector < DimensionMap * >&getDimensionMaps ()
const
1048 return this->dimmaps;
1050 const std::vector < IndexMap * >&getIndexMaps ()
const
1052 return this->indexmaps;
1056 const std::vector < Field * >&getGeoFields ()
const
1058 return this->geofields;
1063 void set_num_map (
int this_num_map)
1065 num_map = this_num_map;
1067 int get_num_map ()
const
1073 SwathDataset (
const std::string & name)
1080 int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps)
throw (Exception);
1083 void ReadIndexMaps (std::vector < IndexMap * >&indexmaps)
throw (Exception);
1088 std::vector < DimensionMap * >dimmaps;
1091 std::vector < IndexMap * >indexmaps;
1094 std::set < std::string > nonmisscvdimlist;
1097 std::vector < Field * >geofields;
1109 class PointDataset:
public Dataset
1112 static PointDataset *Read (int32 fd,
const std::string & pointname)
throw (Exception);
1113 virtual ~ PointDataset ();
1116 PointDataset (
const std::string & name)
1130 static File *Read (
const char *path,int32 gridfd,int32 swathfd)
throw (Exception);
1136 void Prepare(
const char *path)
throw(Exception);
1139 bool check_special_1d_grid() throw(Exception);
1144 bool getOneLatLon ()
1146 return this->onelatlon;
1152 const std::string & getPath ()
const
1157 const std::vector < GridDataset * >&
getGrids ()
const
1162 const std::vector < SwathDataset * >&getSwaths ()
const
1164 return this->swaths;
1167 const std::vector < PointDataset * >&getPoints ()
const
1169 return this->points;
1172 const std::string get_first_grid_name()
const
1173 {
return this->grids[0]->getName();}
1184 File (
const char *path)
1185 : path (path), onelatlon (false), iscoard (false), gridfd (-1), swathfd (-1)
1195 std::vector < GridDataset * >grids;
1198 std::vector < SwathDataset * >swaths;
1201 std::vector < PointDataset * >points;
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*) throw(Exception);
1287 void handle_onelatlon_grids() throw (Exception);
1290 void handle_grid_dim_cvar_maps() throw(Exception);
1293 void handle_grid_coards() throw(Exception);
1296 void update_grid_field_corrected_dims() throw(Exception);
1300 void handle_grid_cf_attrs() throw(Exception);
1303 void handle_grid_SOM_projection() throw(Exception);
1306 int obtain_dimmap_num(
int numswath) throw(Exception);
1310 void create_swath_latlon_dim_cvar_map(
int numdm) throw(Exception);
1313 void create_swath_nonll_dim_cvar_map() throw(Exception);
1317 void handle_swath_dim_cvar_maps(
int numdm) throw(Exception);
1321 void handle_swath_cf_attrs() throw(Exception);
1354 static bool ReadNamelist (
const char *path,
1355 int32 (*inq) (
char *,
char *, int32 *),
1356 std::vector < std::string > &names);
void getGrids(BaseType *bt, vector< Grid * > *grids)
Recursively traverses the BaseType bt (if its a constructor type) and collects pointers to all of the...