bes  Updated for version 3.20.6
HDFEOS2.h
1 // This file is part of the hdf4 data handler for the OPeNDAP data server.
3 //
4 // Author: Kent Yang,Choonghwan Lee <myang6@hdfgroup.org>
5 // Copyright (c) 2010-2012 The HDF Group
7 
8 //#include "InternalErr.h"
9 #ifdef USE_HDFEOS2_LIB
10 
11 #ifndef _HDFEOS2_H
12 #define _HDFEOS2_H
13 #ifdef _WIN32
14 #ifdef _DEBUG
15 #define _CRTDBG_MAP_ALLOC
16 #include <stdlib.h>
17 #include <crtdbg.h>
18 #endif
19 #endif
20 
21 
22 #include <iostream>
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <set>
27 #include "mfhdf.h"
28 #include "hdf.h"
29 #include "HdfEosDef.h"
30 
31 
32 // Add MISR SOM projection header
33 #include "misrproj.h"
34 
35 #include "HDFEOS2EnumType.h"
36 
37 #ifdef _WIN32
38 #ifdef _MSC_VER
39 #pragma warning(disable:4290)
40 #endif
41 #endif
42 
63 namespace HDFEOS2
64 {
67  class Exception:public std::exception
68  {
69  public:
71  explicit Exception (const std::string & msg)
72  : message (msg), isHDFEOS2 (true)
73  {
74  }
75 
77  virtual ~ Exception () throw ()
78  {
79  }
80 
82  virtual const char *what () const throw ()
83  {
84  return this->message.c_str ();
85  }
86 
89  virtual bool getFileType ()
90  {
91  return this->isHDFEOS2;
92  }
93 
95  virtual void setFileType (bool isHDFEOS2_flag)
96  {
97  this->isHDFEOS2 = isHDFEOS2_flag;
98  }
99 
101  virtual void setException (std::string exception_message)
102  {
103  this->message = exception_message;
104  }
105 
106  private:
107  std::string message;
108  bool isHDFEOS2;
109  };
110 
119  template < typename T > class LightVector {
120  public:
121  LightVector ()
122  : data (0), length (0), capacity (0) {
123  }
124 
125  LightVector (const LightVector < T > &that)
126  {
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;
132  }
133 
134  ~LightVector () {
135  if (this->data)
136  delete[]data;
137  }
138 
139  void push_back (const T & d)
140  {
141  this->reserve (this->length + 1);
142  this->data[this->length] = d;
143  ++this->length;
144  }
145 
146  void reserve (unsigned int len)
147  {
148  if (this->capacity >= len)
149  return;
150 
151  this->capacity = len;
152  T *old = this->data;
153 
154  this->data = new T[len];
155  if (old) {
156  for (unsigned int i = 0; i < this->length; ++i)
157  this->data[i] = old[i];
158  delete[]old;
159  }
160  }
161 
162  void resize (unsigned int len)
163  {
165  if (this->length == len)
166  return;
167  else if (this->length < len) {
168  if (this->capacity < len) {
169  this->capacity = len;
170  T *old = this->data;
171 
172  this->data = new T[len];
173  if (old) {
174  for (unsigned int i = 0; i < this->length; ++i)
175  this->data[i] = old[i];
176  delete[]old;
177  }
178  }
179  }
180  else {
181  this->capacity = len;
182  T *old = this->data;
183 
184  this->data = new T[len];
185  for (unsigned int i = 0; i < len; ++i)
186  this->data[i] = old[i];
187  if (old)
188  delete[]old;
189  }
190  this->length = len;
191  }
192 
193  unsigned int size () const
194  {
195  return this->length;
196  }
197 
198  T & operator[] (unsigned int i)
199  {
200  return this->data[i];
201  }
202  const T & operator[] (unsigned int i) const
203  {
204  return this->data[i];
205  }
206 
207  LightVector < T > &operator= (const LightVector < T > &that)
208  {
209  if (this != &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;
215  }
216  return *this;
217  }
218 
219  private:
220  T * data;
221  unsigned int length;
222  unsigned int capacity;
223  };
224 
225  class SwathDimensionAdjustment;
226 
230  class Dimension
231  {
232  public:
233  const std::string & getName () const
234  {
235  return this->name;
236  }
237  int32 getSize () const
238  {
239  return this->dimsize;
240  }
241 
242  protected:
243  Dimension (const std::string & eos_dname, int32 eos_dimsize)
244  : name (eos_dname), dimsize (eos_dimsize)
245  {
246  }
247 
248  private:
249  std::string name;
250  int32 dimsize;
251 
252  friend class File;
253  friend class Dataset;
254  friend class SwathDimensionAdjustment;
255  };
256 
259  class Field
260  {
261  public:
262  Field ()
263  :fieldtype (0), condenseddim (false), iscoard (false), ydimmajor (true), speciallon (false), specialformat (0), haveaddedfv (false), addedfv (-9999.0), dmap (false)/*, field_cache(0)*/
264 
265  {
266  name ="";
267  rank =-1;
268  type =-1;
269  coordinates="";
270  newname = "";
271  units="";
272  }
273  virtual ~ Field ();
274 
275  public:
276 
278  const std::string & getName () const
279  {
280  return this->name;
281  }
282 
284  const std::string & getNewName () const
285  {
286  return this->newname;
287  }
288 
290  int32 getRank () const
291  {
292  return this->rank;
293  }
294 
296  int32 getType () const
297  {
298  return this->type;
299  }
300 
302  const std::vector < Dimension * >&getCorrectedDimensions () const
303  {
304  return this->correcteddims;
305  }
306 
308  std::vector < Dimension * >*getCorrectedDimensionsPtr ()
309  {
310  return &(this->correcteddims);
311  }
312 
314  void setCorrectedDimensions (std::vector < Dimension * >eos_dims)
315  {
316  correcteddims = eos_dims;
317  }
318 
320  const std::string getCoordinate () const
321  {
322  return this->coordinates;
323  }
324 
326  void setCoordinates (std::string coor)
327  {
328  coordinates = coor;
329  }
330 
332  const std::string getUnits () const
333  {
334  return this->units;
335  }
336 
338  void setUnits (std::string uni)
339  {
340  units = uni;
341  }
342 
344  float getAddedFillValue () const
345  {
346  return this->addedfv;
347  }
348 
349  // Add the "_FillValue" attribute
350  // This is for supporting the old versions of HDF-EOS2 data(AIRS) because
351  // some data products have fillvalue(-9999.0) but don't specify the fillvalue.
352  // We add the fillvalue to ensure the netCDF client can successfully display the data.
353  // KY 2013-06-30
354  void addFillValue (float fv)
355  {
356  addedfv = fv;
357  }
358 
360  bool haveAddedFillValue () const
361  {
362  return this->haveaddedfv;
363  }
364 
366  void setAddedFillValue (bool havefv)
367  {
368  haveaddedfv = havefv;
369  }
370 
371 
372  // Obtain fieldtype values
373  // For fieldtype values:
374  // 0 is general fields
375  // 1 is latitude.
376  // 2 is longtitude.
377  // 3 is defined level.
378  // 4 is an inserted natural number.
379  // 5 is time.
380 
381  int getFieldType () const
382  {
383  return this->fieldtype;
384  }
385 
387  const std::vector < Dimension * >&getDimensions () const
388  {
389  return this->dims;
390  }
391 
393  const std::vector < char >&getFillValue () const
394  {
395  return this->filler;
396  }
397 
399  bool getYDimMajor () const
400  {
401  return this->ydimmajor;
402  }
403 
405  bool getSpecialLon () const
406  {
407  return this->speciallon;
408  }
409 
411  int getSpecialLLFormat () const
412  {
413  return this->specialformat;
414  }
415 
417  bool getCondensedDim () const
418  {
419  return this->condenseddim;
420  }
421 
423  bool UseDimMap () const
424  {
425  return this->dmap;
426  }
427 
428 //No need to check field_cache in the DDS level.
429 //May remove the debugging info. totally in the next release.
430 //KY 2014-10-23
431 #if 0
432  // 2 exactly cached
434  // 1 maybe cached, need to check the
435  // file size when accessing the data
436  const short UseFieldCache () const
437  {
438  return this->field_cache;
439  }
440 #endif
441  protected:
442  // field name
443  std::string name;
444 
445  // field dimension rank
446  int32 rank;
447 
448  // field datatype
449  int32 type;
450 
451  // field dimensions with original dimension names
452  std::vector < Dimension * >dims;
453 
454  // field dimensions with the corrected(CF) dimension names
455  std::vector < Dimension * >correcteddims;
456 
457  // This is for reading the fillvalue.
458  // HDF-EOS2 provides a special routine to read fillvalue.
459  // Up to HDF-EOS2 version 2.18, this is the only field attribute
460  // that HDF-EOS2 APIs provide. KY 2013-07-01
461 
462  std::vector < char >filler;
463 
464  // Coordinate attributes that includes coordinate variable list.
465  std::string coordinates;
466 
467  // newname is to record CF Grid/Swath name + "_"+ CF field name(special characters replaced by underscores).
468  std::string newname;
469 
470 
471  // This flag will specify the fieldtype.
472  // 0 means this field is general field.
473  // 1 means this field is lat.
474  // 2 means this field is lon.
475  // 3 means this field is other dimension variable.
476  // 4 means this field is added other dimension variable with nature number.
477  // 5 means time, but currently the units is not correct.
478  int fieldtype;
479 
480  // Latitude and longitude retrieved by HDF-EOS2 are always
481  // 2-D arrays(XDim * YDim). However, for some projections
482  // (geographic etc.), latiude and longitude can be condensed to
483  // 1-D arrays. The handler will track such projections and condense
484  // the latitude and longitude to 1-D arrays. This can reduce
485  // the disk storage and can greatly improve the performance for
486  // the visualization tool to access the latitude and longitde.
487  // condenseddim is the flag internally used by the handler to track this.
488  bool condenseddim;
489 
490  // This flag is to mark if the data should follow COARDS.
491  bool iscoard;
492 
493  // This flag is to check if the field is YDim major(temp(YDim,XDim). This
494  // flag is necessary when calling GDij2ll to retrieve latitude and longitude.
495  bool ydimmajor;
496 
497  // SOme special longitude is from 0 to 360.We need to check this case with this flag.
498  bool speciallon;
499 
500  // This flag specifies the special latitude/longitude coordinate format
501  // The latiude and longitude should represent as DDDMMMSSS format
502  // However, we found some files simply represent lat/lon as -180.0000000 or -90.000000.
503  // Some other files use default. So we this flag to record this and correctly retrieve
504  // the latitude and longitude values in the DAP output.
505  // 0 means normal
506  // 1 means the coordinate is -180 to 180
507  // 2 means the coordinate is default(0)
508  int specialformat;
509 
510  // CF units attribute(mostly to add latitude and longitude CF units).
511  std::string units;
512 
513  // Some data products have fillvalue(-9999.0) but don't specify the fillvalue.
514  // We add the fillvalue to ensure the netCDF client can successfully display the data.
515  // haveaddedfv and addedfv are to check if having added fillvalues.
516  bool haveaddedfv;
517  float addedfv;
518 
519  // Check if this swath uses the dimension map.
520  bool dmap;
521 
522  friend class Dataset;
523  friend class SwathDimensionAdjustment;
524  friend class GridDataset;
525  friend class SwathDataset;
526  friend class File;
527  };
528 
529 #if 0
530  // For future improvement of the modulization
531  class GeoField:public Field
532  {
533 
534  protected:
535  bool condenseddim;
536  bool ydimmajor;
537  bool speciallon;
538 
539  };
540 #endif
541 
543  class Attribute
544  {
545  public:
546 
548  const std::string & getName () const
549  {
550  return this->name;
551  }
552 
554  const std::string & getNewName () const
555  {
556  return this->newname;
557  }
558 
560  int32 getType () const
561  {
562  return this->type;
563  }
564 
566  int32 getCount () const
567  {
568  return this->count;
569  }
570 
572  const std::vector < char >&getValue () const
573  {
574  return this->value;
575  }
576 
577  private:
578 
580  std::string name;
581 
583  std::string newname;
584 
586  int32 type;
587 
589  int32 count;
590 
592  std::vector < char >value;
593 
594  friend class Dataset;
595  };
596 
600  class Dataset
601  {
602  public:
604  const std::string & getName () const
605  {
606  return this->name;
607  }
609  const std::vector < Dimension * >&getDimensions () const
610  {
611  return this->dims;
612  }
614  const std::vector < Field * >&getDataFields () const
615  {
616  return this->datafields;
617  }
618 
620  const std::vector < Attribute * >&getAttributes () const
621  {
622  return this->attrs;
623  }
624 
626  SOType getScaleType () const
627  {
628  return this->scaletype;
629  }
630 
631 
632  protected:
633  explicit Dataset (const std::string & n)
634  : datasetid (-1), addfvalueattr(false),name (n),scaletype(DEFAULT_CF_EQU)
635  {
636 
637  }
638 
639  virtual ~ Dataset ();
640 
643  void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
644  int32 (*inq) (int32, char *, int32 *),
645  std::vector < Dimension * >&dims) throw (Exception);
646 
650  void ReadFields (int32 (*entries) (int32, int32, int32 *),
651  int32 (*inq) (int32, char *, int32 *, int32 *),
652  intn (*fldinfo) (int32, char *, int32 *, int32 *,
653  int32 *, char *),
654  intn (*readfld) (int32, char *, int32 *, int32 *,
655  int32 *, VOIDP),
656  intn (*getfill) (int32, char *, VOIDP),
657  bool geofield, std::vector < Field * >&fields)
658  throw (Exception);
659 
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)
666  throw (Exception);
667 
674  void SetScaleType(const std::string EOS2ObjName) throw(Exception);
675 
676  protected:
678  int32 datasetid;
679 
683  bool addfvalueattr;
684 
686  std::string name;
687 
689  std::vector < Dimension * >dims;
690 
692  std::vector < Field * >datafields;
693 
695  std::vector < Attribute * >attrs;
696 
699  std::map < std::string, std::string > dimcvarlist;
700 
702  std::map < std::string, std::string > ncvarnamelist;
703 
705  std::map < std::string, std::string > ndimnamelist;
706 
707  // Some MODIS files don't use the CF linear equation y = scale * x + offset,
708  // The scaletype distinguishs products following different scale and offset rules.
709  // Note the assumption here: we assume that all fields will
710  // use one scale and offset function in a file. If
711  // multiple scale and offset equations are used in one file, our
712  // function will fail. So far only one scale and offset equation is
713  // applied for NASA HDF-EOS2 files we observed. KY 2012-6-13
714  // Since I found one MODIS product(MOD09GA) uses different scale offset
715  // equations for different grids. I had to move the scaletype to the
716  // group level. Hopefully this is the final fix. Truly hope that
717  // this will not happen at the field level since it will be too messy to
718  // check. KY 2012-11-21
719  SOType scaletype;
720 
721  friend class File;
722  };
723 
726  class GridDataset:public Dataset
727  {
728  public:
729  class Info
730  {
731  public:
732 
734  int32 getX ()const
735  {
736  return this->xdim;
737  }
738 
740  int32 getY () const
741  {
742  return this->ydim;
743  }
744 
750  const float64 *getUpLeft () const
751  {
752  return this->upleft;
753  }
754 
760  const float64 *getLowRight () const
761  {
762  return this->lowright;
763  }
764  protected:
765  Info() {
766  xdim = -1;
767  ydim = -1;
768  }
769 
770  private:
771  int32 xdim;
772  int32 ydim;
773  float64 upleft[2];
774  float64 lowright[2];
775 
776  friend class GridDataset;
777  };
778 
779  class Projection
780  {
781  public:
784 
787  int32 getCode () const
788  {
789  return this->code;
790  }
791 
793  int32 getZone () const
794  {
795  return this->zone;
796  }
797 
799  int32 getSphere () const
800  {
801  return this->sphere;
802  }
803 
805  const float64 *getParam () const
806  {
807  return this->param;
808  }
809 
811  int32 getPix () const
812  {
813  return this->pix;
814  }
815 
817  int32 getOrigin () const
818  {
819  return this->origin;
820  }
821 
822  protected:
823  Projection() {
824  code = -1;
825  zone = -1;
826  sphere = -1;
827  pix = -1;
828  origin = -1;
829 
830  }
831  private:
832  int32 code;
833  int32 zone;
834  int32 sphere;
835  float64 param[16];
836  int32 pix;
837  int32 origin;
838 
839  friend class GridDataset;
840  };
841 
844  class Calculated
845  {
846  public:
847 
850  bool isYDimMajor () throw (Exception);
854 
855  protected:
856 
857  explicit Calculated (const GridDataset * eos_grid)
858  : grid (eos_grid), ydimmajor (false)
859  {
860  }
861 
862  Calculated & operator= (const Calculated & victim)
863  {
864  if (this != &victim) {
865  this->grid = victim.grid;
866  this->ydimmajor = victim.ydimmajor;
867  }
868  return *this;
869  }
870 
873  void DetectMajorDimension () throw (Exception);
874 
876  int DetectFieldMajorDimension () throw (Exception);
877 
878 
879  private:
880  const GridDataset *grid;
881  bool ydimmajor;
882 
883  friend class GridDataset;
884  friend class File;
885  };
886 
887  public:
889  static GridDataset *Read (int32 fd, const std::string & gridname) throw (Exception);
890 
891  virtual ~ GridDataset ();
892 
894  const Info & getInfo () const
895  {
896  return this->info;
897  }
898 
900  const Projection & getProjection () const
901  {
902  return this->proj;
903  }
904 
906  Calculated & getCalculated () const;
907 
909  void setDimxName (std::string dxname)
910  {
911  dimxname = dxname;
912  }
914  void setDimyName (std::string dyname)
915  {
916  dimyname = dyname;
917  }
918 
920  bool getLatLonFlag () const
921  {
922  return this->ownllflag;
923  }
924 
925  private:
926  explicit GridDataset (const std::string & g_name)
927  : Dataset (g_name), calculated (0), ownllflag (false), iscoard (false)
928  {
929  latfield = NULL;
930  lonfield = NULL;
931  }
932 
933  private:
934 
936  Info info;
937 
939  Projection proj;
940 
943  mutable Calculated calculated;
944 
946  bool ownllflag;
947 
949  bool iscoard;
950 
952  Field *latfield;
953  Field *lonfield;
954 
956  std::string dimxname;
957  std::string dimyname;
958 
959  friend class File;
960 
961  };
962 
963  class File;
964 
968 
969  class SwathDataset:public Dataset
970  {
971 
972  public:
987 
988  class DimensionMap
989  {
990  public:
991  const std::string & getGeoDimension () const
992  {
993  return this->geodim;
994  }
995  const std::string & getDataDimension () const
996  {
997  return this->datadim;
998  }
999  int32 getOffset () const
1000  {
1001  return this->offset;
1002  }
1003  int32 getIncrement () const
1004  {
1005  return this->increment;
1006  }
1007 
1008  protected:
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)
1011  {
1012  }
1013 
1014  private:
1015 
1016  std::string geodim;
1017  std::string datadim;
1018  int32 offset;
1019  int32 increment;
1020 
1021  friend class SwathDataset;
1022  friend class SwathDimensionAdjustment;
1023  friend class File;
1024  };
1025 
1029  class IndexMap
1030  {
1031  public:
1032  const std::string & getGeoDimension () const
1033  {
1034  return this->geo;
1035  }
1036  const std::string & getDataDimension () const
1037  {
1038  return this->data;
1039  }
1040  const LightVector < int32 > &getIndices () const
1041  {
1042  return this->indices;
1043  }
1044 
1045  private:
1046  std::string geo;
1047  std::string data;
1048  LightVector < int32 > indices;
1049 
1050  friend class SwathDataset;
1051  };
1052 
1053  public:
1055  static SwathDataset *Read (int32 fd, const std::string & swathname) throw (Exception);
1056 
1057  virtual ~ SwathDataset ();
1058 
1060  const std::vector < DimensionMap * >&getDimensionMaps () const
1061  {
1062  return this->dimmaps;
1063  }
1064  const std::vector < IndexMap * >&getIndexMaps () const
1065  {
1066  return this->indexmaps;
1067  }
1068 
1070  const std::vector < Field * >&getGeoFields () const
1071  {
1072  return this->geofields;
1073  }
1074 
1075 
1077  void set_num_map (int this_num_map)
1078  {
1079  num_map = this_num_map;
1080  }
1081  int get_num_map () const
1082  {
1083  return num_map;
1084  };
1085 
1086  private:
1087  explicit SwathDataset (const std::string & swath_name)
1088  : Dataset (swath_name),num_map(0) {
1089  }
1090 
1091 
1094  int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps) throw (Exception);
1095 
1097  void ReadIndexMaps (std::vector < IndexMap * >&indexmaps) throw (Exception);
1098 
1099 
1101  std::vector < DimensionMap * >dimmaps;
1102 
1104  std::vector < IndexMap * >indexmaps;
1105 
1107  std::set < std::string > nonmisscvdimlist;
1108 
1110  std::vector < Field * >geofields;
1111 
1114  int num_map;
1115 
1116  friend class File;
1117  };
1118 
1122  class PointDataset:public Dataset
1123  {
1124  public:
1125  static PointDataset *Read (int32 fd, const std::string & point_name) throw (Exception);
1126  virtual ~ PointDataset ();
1127 
1128  private:
1129  explicit PointDataset (const std::string & point_name)
1130  : Dataset (point_name)
1131  {
1132  }
1133  };
1134 
1135 
1138  class File
1139  {
1140  public:
1141 
1143  static File *Read (const char *path,int32 gridfd,int32 swathfd) throw (Exception);
1144 
1145 
1149  void Prepare(const char *path) throw(Exception);
1150 
1152  bool check_special_1d_grid() throw(Exception);
1153 
1154 
1157  bool getOneLatLon ()
1158  {
1159  return this->onelatlon;
1160  }
1161 
1163  ~File ();
1164 
1165  const std::string & getPath () const
1166  {
1167  return this->path;
1168  }
1169 
1170  const std::vector < GridDataset * >&getGrids () const
1171  {
1172  return this->grids;
1173  }
1174 
1175  const std::vector < SwathDataset * >&getSwaths () const
1176  {
1177  return this->swaths;
1178  }
1179 
1180  const std::vector < PointDataset * >&getPoints () const
1181  {
1182  return this->points;
1183  }
1184 
1185  const std::string get_first_grid_name() const
1186  { return this->grids[0]->getName();}
1187 #if 0
1188 #endif
1196 
1197 
1198  protected:
1199  explicit File (const char *eos2_file_path)
1200  : path (eos2_file_path), onelatlon (false), iscoard (false), gridfd (-1), swathfd (-1)
1201  {
1202  }
1203 
1204  private:
1205 
1207  std::string path;
1208 
1210  std::vector < GridDataset * >grids;
1211 
1213  std::vector < SwathDataset * >swaths;
1214 
1216  std::vector < PointDataset * >points;
1217 
1218  // This is for the case that only one lat/lon
1219  // set is provided for multiple grid cases.
1220  // The current case is that the user provides
1221  // the latitude and longitude under a special grid.
1222  // By default, the grid name is "location". This will
1223  // cover the AIRS grid case.
1224  bool onelatlon;
1225 
1227  bool iscoard;
1228 
1229  protected:
1230  /*
1231  A grid's X-dimension can have different names: XDim, LatDim, etc.
1232  * Y-dimension also has YDim, LonDim, etc.
1233  * This function returns the name of X-dimension which is used in
1234  * the given file.
1235  * For better performance, we check the first grid or swath only.
1236  */
1237  std::string get_geodim_x_name ();
1238  std::string get_geodim_y_name ();
1239 
1240  // Internal function used by
1241  // get_geodim_x_name and get_geodim_y_name functions.
1242  // This function is not intended to be used outside the
1243  // get_geodim_x_name and get_geodim_y_name functions.
1244  void _find_geodim_names ();
1245 
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[];
1250 
1260  std::string get_latfield_name ();
1261  std::string get_lonfield_name ();
1262 
1263  // Internal function used by
1264  // get_latfield_name and get_lonfield_name functions.
1265  // This function is not intended to be used outside
1266  // the get_latfield_name and get_lonfield_name functions.
1267  void _find_latlonfield_names ();
1268 
1269  std::string _latfield_name;
1270  std::string _lonfield_name;
1271  static const char *_latfield_names[];
1272  static const char *_lonfield_names[];
1273 
1279  std::string get_geogrid_name ();
1280 
1281  // Internal function used by
1282  // the get_geogrid_name function.
1283  // This function is not intended to be used outside the get_geogrid_name function.
1284  void _find_geogrid_name ();
1285 
1286  std::string _geogrid_name;
1287  static const char *_geogrid_names[];
1288 
1289 
1290  // All the following functions are called by the Prepare() function.
1291 
1292  // Check if we have the dedicated lat/lon grid.
1293  void check_onelatlon_grids();
1294 
1295  // For one grid, need to handle the third-dimension(both existing and missing) coordinate variables
1296  void handle_one_grid_zdim(GridDataset*);
1297 
1298  // For one grid, need to handle lat/lon(both existing lat/lon and calculated lat/lon from EOS2 APIs)
1299  void handle_one_grid_latlon(GridDataset*) throw(Exception);
1300 
1301  // For the case of which all grids have one dedicated lat/lon grid,
1302  // this function shows how to handle lat/lon fields.
1303  void handle_onelatlon_grids() throw (Exception);
1304 
1305  // Handle the dimension name to coordinate variable map for grid.
1306  void handle_grid_dim_cvar_maps() throw(Exception);
1307 
1308  // Follow COARDS for grids.
1309  void handle_grid_coards() throw(Exception);
1310 
1311  // Create the corrected dimension vector for each field when COARDS is not followed.
1312  void update_grid_field_corrected_dims() throw(Exception);
1313 
1314  // Handle CF attributes for grids.
1315  // The CF attributes include "coordinates", "units" for coordinate variables and "_FillValue".
1316  void handle_grid_cf_attrs() throw(Exception);
1317 
1318  // Special handling SOM(Space Oblique Mercator) projection files
1319  void handle_grid_SOM_projection() throw(Exception);
1320 
1321  // Obtain the number of dimension maps in this file. The input parameter is the number of swath.
1322  int obtain_dimmap_num(int numswath) throw(Exception);
1323 
1324  // Create the dimension name to coordinate variable name map for lat/lon.
1325  // The input parameter is the number of dimension maps in this file.
1326  void create_swath_latlon_dim_cvar_map(int numdm) throw(Exception);
1327 
1328  // Create the dimension name to coordinate variable name map for non lat/lon coordinate variables.
1329  void create_swath_nonll_dim_cvar_map() throw(Exception);
1330 
1331  // Handle swath dimension name to coordinate variable name maps.
1332  // The input parameter is the number of dimension maps in this file.
1333  void handle_swath_dim_cvar_maps(int numdm) throw(Exception);
1334 
1335  // Handle CF attributes for swaths.
1336  // The CF attributes include "coordinates", "units" for coordinate variables and "_FillValue".
1337  void handle_swath_cf_attrs() throw(Exception);
1338 
1339  private:
1340 
1341  // HDF-EOS2 Grid File ID. Notice this ID is not an individual grid ID but the grid file ID returned by
1342  // calling the HDF-EOS2 API GDopen.
1343  int32 gridfd;
1344 
1345  // HDF-EOS2 Swath File ID. Notice this ID is not an individual swath ID but the swath file ID returned by
1346  // calling the HDF-EOS2 API SWopen.
1347  int32 swathfd;
1348 
1361 
1363  };
1364 
1365 
1366  struct Utility
1367  {
1368 
1370  static bool ReadNamelist (const char *path,
1371  int32 (*inq) (char *, char *, int32 *),
1372  std::vector < std::string > &names);
1373 
1374 
1375  };
1376 
1377 }
1378 #endif
1379 
1380 #endif