bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDFEOS2.h
1
2// 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) The HDF Group
7
8//#include <libdap/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
63namespace HDFEOS2
64{
67 class Exception:public std::exception
68 {
69 public:
71 explicit Exception (const std::string & msg)
72 : message (msg)
73 {
74 }
75
77 ~ Exception () throw () override = default;
78
80 const char *what () const throw () override
81 {
82 return this->message.c_str ();
83 }
84
87 virtual bool getFileType ()
88 {
89 return this->isHDFEOS2;
90 }
91
93 virtual void setFileType (bool isHDFEOS2_flag)
94 {
95 this->isHDFEOS2 = isHDFEOS2_flag;
96 }
97
99 virtual void setException (const std::string & exception_message)
100 {
101 this->message = exception_message;
102 }
103
104 private:
105 std::string message;
106 bool isHDFEOS2 = true;
107 };
108
117 template < typename T > class LightVector {
118 public:
119 LightVector () = default;
120
121 LightVector (const LightVector < T > &that)
122 {
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;
128 }
129
130 ~LightVector () {
131 if (this->data)
132 delete[]data;
133 }
134
135 void push_back (const T & d)
136 {
137 this->reserve (this->length + 1);
138 this->data[this->length] = d;
139 ++this->length;
140 }
141
142 void reserve (unsigned int len)
143 {
144 if (this->capacity >= len)
145 return;
146
147 this->capacity = len;
148 T *old = this->data;
149
150 this->data = new T[len];
151 if (old) {
152 for (unsigned int i = 0; i < this->length; ++i)
153 this->data[i] = old[i];
154 delete[]old;
155 }
156 }
157
158 void resize (unsigned int len)
159 {
161 if (this->length == len)
162 return;
163 else if (this->length < len) {
164 if (this->capacity < len) {
165 this->capacity = len;
166 T *old = this->data;
167
168 this->data = new T[len];
169 if (old) {
170 for (unsigned int i = 0; i < this->length; ++i)
171 this->data[i] = old[i];
172 delete[]old;
173 }
174 }
175 }
176 else {
177 this->capacity = len;
178 T *old = this->data;
179
180 this->data = new T[len];
181 for (unsigned int i = 0; i < len; ++i)
182 this->data[i] = old[i];
183 if (old)
184 delete[]old;
185 }
186 this->length = len;
187 }
188
189 unsigned int size () const
190 {
191 return this->length;
192 }
193
194 T & operator[] (unsigned int i)
195 {
196 return this->data[i];
197 }
198 const T & operator[] (unsigned int i) const
199 {
200 return this->data[i];
201 }
202
203 LightVector < T > &operator= (const LightVector < T > &that)
204 {
205 if (this != &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;
211 }
212 return *this;
213 }
214
215 private:
216 T * data = nullptr;
217 unsigned int length = 0;
218 unsigned int capacity = 0;
219 };
220
221 class SwathDimensionAdjustment;
222
226 class Dimension
227 {
228 public:
229 const std::string & getName () const
230 {
231 return this->name;
232 }
233 int32 getSize () const
234 {
235 return this->dimsize;
236 }
237
238 protected:
239 Dimension (const std::string & eos_dname, int32 eos_dimsize)
240 : name (eos_dname), dimsize (eos_dimsize)
241 {
242 }
243
244 private:
245 std::string name;
246 int32 dimsize;
247
248 friend class File;
249 friend class Dataset;
250 friend class SwathDimensionAdjustment;
251 };
252
255 class Field
256 {
257 public:
258 Field () = default;
259 virtual ~ Field ();
260
262 const std::string & getName () const
263 {
264 return this->name;
265 }
266
268 const std::string & getNewName () const
269 {
270 return this->newname;
271 }
272
274 int32 getRank () const
275 {
276 return this->rank;
277 }
278
280 int32 getType () const
281 {
282 return this->type;
283 }
284
286 const std::vector < Dimension * >&getCorrectedDimensions () const
287 {
288 return this->correcteddims;
289 }
290
292 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
293 {
294 return &(this->correcteddims);
295 }
296
298 void setCorrectedDimensions (const std::vector < Dimension * >& eos_dims)
299 {
300 correcteddims = eos_dims;
301 }
302
304 std::string getCoordinate () const
305 {
306 return this->coordinates;
307 }
308
310 void setCoordinates (const std::string& coor)
311 {
312 coordinates = coor;
313 }
314
316 std::string getUnits () const
317 {
318 return this->units;
319 }
320
322 void setUnits (const std::string& uni)
323 {
324 units = uni;
325 }
326
328 float getAddedFillValue () const
329 {
330 return this->addedfv;
331 }
332
333 // Add the "_FillValue" attribute
334 // This is for supporting the old versions of HDF-EOS2 data(AIRS) because
335 // some data products have fillvalue(-9999.0) but don't specify the fillvalue.
336 // We add the fillvalue to ensure the netCDF client can successfully display the data.
337 // KY 2013-06-30
338 void addFillValue (float fv)
339 {
340 addedfv = fv;
341 }
342
344 bool haveAddedFillValue () const
345 {
346 return this->haveaddedfv;
347 }
348
350 void setAddedFillValue (bool havefv)
351 {
352 haveaddedfv = havefv;
353 }
354
355
356 // Obtain fieldtype values
357 // For fieldtype values:
358 // 0 is general fields
359 // 1 is latitude.
360 // 2 is longtitude.
361 // 3 is defined level.
362 // 4 is an inserted natural number.
363 // 5 is time.
364
365 int getFieldType () const
366 {
367 return this->fieldtype;
368 }
369
371 const std::vector < Dimension * >&getDimensions () const
372 {
373 return this->dims;
374 }
375
377 const std::vector < char >&getFillValue () const
378 {
379 return this->filler;
380 }
381
385 int getLLDim0Offset () const
386 {
387 return this->ll_dim0_offset;
388 }
389 int getLLDim0Inc () const
390 {
391 return this->ll_dim0_inc;
392 }
393 int getLLDim1Offset () const
394 {
395 return this->ll_dim1_offset;
396 }
397 int getLLDim1Inc () const
398 {
399 return this->ll_dim1_inc;
400 }
401
402
404 bool getYDimMajor () const
405 {
406 return this->ydimmajor;
407 }
408
410 bool getSpecialLon () const
411 {
412 return this->speciallon;
413 }
414
416 int getSpecialLLFormat () const
417 {
418 return this->specialformat;
419 }
420
422 bool getCondensedDim () const
423 {
424 return this->condenseddim;
425 }
426
428 bool UseDimMap () const
429 {
430 return this->dmap;
431 }
432
433 private:
434 // field name
435 std::string name;
436
437 // field dimension rank
438 int32 rank = -1;
439
440 // field datatype
441 int32 type = -1;
442
443 // field dimensions with original dimension names
444 std::vector < Dimension * >dims;
445
446 // field dimensions with the corrected(CF) dimension names
447 std::vector < Dimension * >correcteddims;
448
449 // This is for reading the fillvalue.
450 // HDF-EOS2 provides a special routine to read fillvalue.
451 // Up to HDF-EOS2 version 2.18, this is the only field attribute
452 // that HDF-EOS2 APIs provide. KY 2013-07-01
453
454 std::vector < char >filler;
455
456 // Coordinate attributes that includes coordinate variable list.
457 std::string coordinates;
458
459 // newname is to record CF Grid/Swath name + "_"+ CF field name(special characters replaced by underscores).
460 std::string newname;
461
462
463 // This flag will specify the fieldtype.
464 // 0 means this field is general field.
465 // 1 means this field is lat.
466 // 2 means this field is lon.
467 // 3 means this field is other dimension variable.
468 // 4 means this field is added other dimension variable with nature number.
469 // 5 means time, but currently the units is not correct.
470 int fieldtype = 0;
471
472 // Latitude and longitude retrieved by HDF-EOS2 are always
473 // 2-D arrays(XDim * YDim). However, for some projections
474 // (geographic etc.), latiude and longitude can be condensed to
475 // 1-D arrays. The handler will track such projections and condense
476 // the latitude and longitude to 1-D arrays. This can reduce
477 // the disk storage and can greatly improve the performance for
478 // the visualization tool to access the latitude and longitde.
479 // condenseddim is the flag internally used by the handler to track this.
480 bool condenseddim = false;
481
482 // This flag is to mark if the data should follow COARDS.
483 bool iscoard = false;
484
485 // This flag is to check if the field is YDim major(temp(YDim,XDim). This
486 // flag is necessary when calling GDij2ll to retrieve latitude and longitude.
487 bool ydimmajor = true;
488
489 // SOme special longitude is from 0 to 360.We need to check this case with this flag.
490 bool speciallon = false;
491
492 // This flag specifies the special latitude/longitude coordinate format
493 // The latiude and longitude should represent as DDDMMMSSS format
494 // However, we found some files simply represent lat/lon as -180.0000000 or -90.000000.
495 // Some other files use default. So we this flag to record this and correctly retrieve
496 // the latitude and longitude values in the DAP output.
497 // 0 means normal
498 // 1 means the coordinate is -180 to 180
499 // 2 means the coordinate is default(0)
500 int specialformat = 0;
501
502 // CF units attribute(mostly to add latitude and longitude CF units).
503 std::string units;
504
505 // Some data products have fillvalue(-9999.0) but don't specify the fillvalue.
506 // We add the fillvalue to ensure the netCDF client can successfully display the data.
507 // haveaddedfv and addedfv are to check if having added fillvalues.
508 bool haveaddedfv = false;
509 int ll_dim0_offset = 0;
510 int ll_dim0_inc = 0;
511 int ll_dim1_offset = 0;
512 int ll_dim1_inc = 0;
513
514 float addedfv = -9999.0;
515
516 // Check if this swath uses the dimension map.
517 bool dmap = false;
518
519 friend class Dataset;
520 friend class SwathDimensionAdjustment;
521 friend class GridDataset;
522 friend class SwathDataset;
523 friend class File;
524 };
525
526
528 class Attribute
529 {
530 public:
531
533 const std::string & getName () const
534 {
535 return this->name;
536 }
537
539 const std::string & getNewName () const
540 {
541 return this->newname;
542 }
543
545 int32 getType () const
546 {
547 return this->type;
548 }
549
551 int32 getCount () const
552 {
553 return this->count;
554 }
555
557 const std::vector < char >&getValue () const
558 {
559 return this->value;
560 }
561
562 private:
563
565 std::string name;
566
568 std::string newname;
569
571 int32 type;
572
574 int32 count;
575
577 std::vector < char >value;
578
579 friend class Dataset;
580 };
581
585 class Dataset
586 {
587 public:
589 const std::string & getName () const
590 {
591 return this->name;
592 }
594 const std::vector < Dimension * >&getDimensions () const
595 {
596 return this->dims;
597 }
599 const std::vector < Field * >&getDataFields () const
600 {
601 return this->datafields;
602 }
603
605 const std::vector < Attribute * >&getAttributes () const
606 {
607 return this->attrs;
608 }
609
611 SOType getScaleType () const
612 {
613 return this->scaletype;
614 }
615
616
617 protected:
618 explicit Dataset (const std::string & n)
619 : name (n){}
620 virtual ~ Dataset ();
621
624 void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
625 int32 (*inq) (int32, char *, int32 *),
626 std::vector < Dimension * >&dims) ;
627
631 void ReadFields (int32 (*entries) (int32, int32, int32 *),
632 int32 (*inq) (int32, char *, int32 *, int32 *),
633 intn (*fldinfo) (int32, char *, int32 *, int32 *,
634 int32 *, char *),
635 intn (*getfill) (int32, char *, VOIDP),
636 bool geofield, std::vector < Field * >&fields)
637 ;
638
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)
645 ;
646
653 void SetScaleType(const std::string & EOS2ObjName);
654
655 int obtain_dimsize_with_dimname(const std::string& dimname) const;
656 protected:
658 int32 datasetid = -1;
659
663 bool addfvalueattr = false;
664
666 std::string name;
667
669 std::vector < Dimension * >dims;
670
672 std::vector < Field * >datafields;
673
675 std::vector < Attribute * >attrs;
676
679 std::map < std::string, std::string > dimcvarlist;
680
682 std::map < std::string, std::string > ncvarnamelist;
683
685 std::map < std::string, std::string > ndimnamelist;
686
687 // Some MODIS files don't use the CF linear equation y = scale * x + offset,
688 // The scaletype distinguishs products following different scale and offset rules.
689 // Note the assumption here: we assume that all fields will
690 // use one scale and offset function in a file. If
691 // multiple scale and offset equations are used in one file, our
692 // function will fail. So far only one scale and offset equation is
693 // applied for NASA HDF-EOS2 files we observed. KY 2012-6-13
694 // Since I found one MODIS product(MOD09GA) uses different scale offset
695 // equations for different grids. I had to move the scaletype to the
696 // group level. Hopefully this is the final fix. Truly hope that
697 // this will not happen at the field level since it will be too messy to
698 // check. KY 2012-11-21
699 SOType scaletype = SOType::DEFAULT_CF_EQU;
700
701 friend class File;
702 };
703
706 class GridDataset:public Dataset
707 {
708 public:
709 class Info
710 {
711 public:
712
714 int32 getX ()const
715 {
716 return this->xdim;
717 }
718
720 int32 getY () const
721 {
722 return this->ydim;
723 }
724
730 const float64 *getUpLeft () const
731 {
732 return this->upleft;
733 }
734
740 const float64 *getLowRight () const
741 {
742 return this->lowright;
743 }
744 protected:
745 Info() = default;
746
747 private:
748 int32 xdim = -1;
749 int32 ydim = -1;
750 float64 upleft[2];
751 float64 lowright[2];
752
753 friend class GridDataset;
754 };
755
756 class Projection
757 {
758 public:
761
764 int32 getCode () const
765 {
766 return this->code;
767 }
768
770 int32 getZone () const
771 {
772 return this->zone;
773 }
774
776 int32 getSphere () const
777 {
778 return this->sphere;
779 }
780
782 const float64 *getParam () const
783 {
784 return this->param;
785 }
786
788 int32 getPix () const
789 {
790 return this->pix;
791 }
792
794 int32 getOrigin () const
795 {
796 return this->origin;
797 }
798
799 protected:
800 Projection() = default;
801
802 private:
803 int32 code = -1;
804 int32 zone = -1;
805 int32 sphere = -1;
806 float64 param[16];
807 int32 pix = -1;
808 int32 origin =-1;
809
810 friend class GridDataset;
811 };
812
815 class Calculated
816 {
817 public:
818
821 bool isYDimMajor () ;
822
823 protected:
824
825 explicit Calculated (const GridDataset * eos_grid)
826 : grid (eos_grid)
827 {
828 }
829
830 Calculated & operator= (const Calculated & victim)
831 {
832 if (this != &victim) {
833 this->grid = victim.grid;
834 this->ydimmajor = victim.ydimmajor;
835 }
836 return *this;
837 }
838
841 void DetectMajorDimension () ;
842
844 int DetectFieldMajorDimension () const;
845
846
847 private:
848 const GridDataset *grid;
849 bool ydimmajor = false;
850
851 friend class GridDataset;
852 friend class File;
853 };
854
855 public:
857 static GridDataset *Read (int32 fd, const std::string & gridname) ;
858
859 ~ GridDataset () override;
860
862 const Info & getInfo () const
863 {
864 return this->info;
865 }
866
868 const Projection & getProjection () const
869 {
870 return this->proj;
871 }
872
874 Calculated & getCalculated () const;
875
877 void setDimxName (const std::string &dxname)
878 {
879 dimxname = dxname;
880 }
882 void setDimyName (const std::string &dyname)
883 {
884 dimyname = dyname;
885 }
886
888 bool getLatLonFlag () const
889 {
890 return this->ownllflag;
891 }
892
893 private:
894 explicit GridDataset (const std::string & g_name)
895 : Dataset (g_name),calculated(0)
896 {
897 }
898
899 private:
900
902 Info info;
903
905 Projection proj;
906
909 mutable Calculated calculated;
910
912 bool ownllflag = false;
913
915 bool iscoard = false;
916
918 Field *latfield = nullptr;
919 Field *lonfield = nullptr;
920
922 std::string dimxname;
923 std::string dimyname;
924
925 friend class File;
926
927 };
928
929 class File;
930
934
935 class SwathDataset:public Dataset
936 {
937
938 public:
953
954 class DimensionMap
955 {
956
957 public:
958 const std::string & getGeoDimension () const
959 {
960 return this->geodim;
961 }
962 const std::string & getDataDimension () const
963 {
964 return this->datadim;
965 }
966 int32 getOffset () const
967 {
968 return this->offset;
969 }
970 int32 getIncrement () const
971 {
972 return this->increment;
973 }
974
975 protected:
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)
978 {
979 }
980
981 private:
982
983 std::string geodim;
984 std::string datadim;
985 int32 offset;
986 int32 increment;
987
988 friend class SwathDataset;
989 friend class SwathDimensionAdjustment;
990 friend class File;
991 };
992
996 class IndexMap
997 {
998 public:
999 const std::string & getGeoDimension () const
1000 {
1001 return this->geo;
1002 }
1003 const std::string & getDataDimension () const
1004 {
1005 return this->data;
1006 }
1007 const LightVector < int32 > &getIndices () const
1008 {
1009 return this->indices;
1010 }
1011
1012 private:
1013 std::string geo;
1014 std::string data;
1015 LightVector < int32 > indices;
1016
1017 friend class SwathDataset;
1018 };
1019
1020 public:
1022 static SwathDataset *Read (int32 fd, const std::string & swathname) ;
1023
1024 ~ SwathDataset () override;
1025
1027 const std::vector < DimensionMap * >&getDimensionMaps () const
1028 {
1029 return this->dimmaps;
1030 }
1031 const std::vector < IndexMap * >&getIndexMaps () const
1032 {
1033 return this->indexmaps;
1034 }
1035
1037 const std::vector < Field * >&getGeoFields () const
1038 {
1039 return this->geofields;
1040 }
1041
1042
1044 void set_num_map (int this_num_map)
1045 {
1046 num_map = this_num_map;
1047 }
1048 int get_num_map () const
1049 {
1050 return num_map;
1051 };
1052
1053 private:
1054 explicit SwathDataset (const std::string & swath_name)
1055 : Dataset (swath_name) {
1056 }
1057
1058
1061 int ReadDimensionMaps (std::vector < DimensionMap * >&dimmaps) ;
1062
1063 bool obtain_dmap_offset_inc(const std::string& o_dimname,const std::string& n_dimmname,int&,int&) const;
1064
1066 void ReadIndexMaps (std::vector < IndexMap * >&indexmaps) ;
1067
1068
1070 std::vector < DimensionMap * >dimmaps;
1071
1073 std::vector < IndexMap * >indexmaps;
1074
1076 std::set < std::string > nonmisscvdimlist;
1077
1079 std::vector < Field * >geofields;
1080
1083 int num_map = 0;
1084
1085 bool GeoDim_in_vars = false;
1086
1087 friend class File;
1088 };
1089
1093 class PointDataset:public Dataset
1094 {
1095 public:
1096 static PointDataset *Read (int32 fd, const std::string & point_name) ;
1097 ~ PointDataset () override;
1098
1099 private:
1100 explicit PointDataset (const std::string & point_name)
1101 : Dataset (point_name)
1102 {
1103 }
1104 };
1105
1106
1109 class File
1110 {
1111 public:
1112
1114 static File *Read (const char *path,int32 gridfd,int32 swathfd) ;
1115
1116
1120 void Prepare(const char *path);
1121
1123 bool check_special_1d_grid();
1124
1125
1128 bool getOneLatLon () const
1129 {
1130 return this->onelatlon;
1131 }
1132
1134 ~File ();
1135
1136 const std::string & getPath () const
1137 {
1138 return this->path;
1139 }
1140
1141 const std::vector < GridDataset * >&getGrids () const
1142 {
1143 return this->grids;
1144 }
1145
1146 const std::vector < SwathDataset * >&getSwaths () const
1147 {
1148 return this->swaths;
1149 }
1150
1151 bool getMultiDimMaps() const
1152 {
1153 return this->multi_dimmap;
1154 }
1155 const std::vector < PointDataset * >&getPoints () const
1156 {
1157 return this->points;
1158 }
1159
1160 std::string get_first_grid_name() const
1161 {
1162 return this->grids[0]->getName();
1163 }
1164
1165
1166 protected:
1167 explicit File (const char *eos2_file_path)
1168 : path (eos2_file_path)
1169 {
1170 }
1171
1172 private:
1173
1175 std::string path;
1176
1178 std::vector < GridDataset * >grids;
1179
1181 std::vector < SwathDataset * >swaths;
1182
1184 std::vector < PointDataset * >points;
1185
1186 // This is for the case that only one lat/lon
1187 // set is provided for multiple grid cases.
1188 // The current case is that the user provides
1189 // the latitude and longitude under a special grid.
1190 // By default, the grid name is "location". This will
1191 // cover the AIRS grid case.
1192 bool onelatlon = false;
1193
1195 bool iscoard = false;
1196
1203 bool handle_swath_dimmap = false;
1204
1208 bool backward_handle_swath_dimmap = false;
1209
1211 bool multi_dimmap = false;
1212
1213 protected:
1214 /*
1215 A grid's X-dimension can have different names: XDim, LatDim, etc.
1216 * Y-dimension also has YDim, LonDim, etc.
1217 * This function returns the name of X-dimension which is used in
1218 * the given file.
1219 * For better performance, we check the first grid or swath only.
1220 */
1221 std::string get_geodim_x_name ();
1222 std::string get_geodim_y_name ();
1223
1224 // Internal function used by
1225 // get_geodim_x_name and get_geodim_y_name functions.
1226 // This function is not intended to be used outside the
1227 // get_geodim_x_name and get_geodim_y_name functions.
1228 void _find_geodim_names ();
1229
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[];
1234
1244 std::string get_latfield_name ();
1245 std::string get_lonfield_name ();
1246
1247 // Internal function used by
1248 // get_latfield_name and get_lonfield_name functions.
1249 // This function is not intended to be used outside
1250 // the get_latfield_name and get_lonfield_name functions.
1251 void _find_latlonfield_names ();
1252
1253 std::string _latfield_name;
1254 std::string _lonfield_name;
1255 static const char *_latfield_names[];
1256 static const char *_lonfield_names[];
1257
1263 std::string get_geogrid_name ();
1264
1265 // Internal function used by
1266 // the get_geogrid_name function.
1267 // This function is not intended to be used outside the get_geogrid_name function.
1268 void _find_geogrid_name ();
1269
1270 std::string _geogrid_name;
1271 static const char *_geogrid_names[];
1272
1273
1274 // All the following functions are called by the Prepare() function.
1275
1276 // Check if we have the dedicated lat/lon grid.
1277 void check_onelatlon_grids();
1278
1279 // For one grid, need to handle the third-dimension(both existing and missing) coordinate variables
1280 void handle_one_grid_zdim(GridDataset*);
1281
1282 // For one grid, need to handle lat/lon(both existing lat/lon and calculated lat/lon from EOS2 APIs)
1283 void handle_one_grid_latlon(GridDataset*);
1284
1285 // For the case of which all grids have one dedicated lat/lon grid,
1286 // this function shows how to handle lat/lon fields.
1287 void handle_onelatlon_grids() ;
1288
1289 // Handle the dimension name to coordinate variable map for grid.
1290 void handle_grid_dim_cvar_maps() ;
1291
1292 // Follow COARDS for grids.
1293 void handle_grid_coards();
1294
1295 // Create the corrected dimension vector for each field when COARDS is not followed.
1296 void update_grid_field_corrected_dims();
1297
1298 // Handle CF attributes for grids.
1299 // The CF attributes include "coordinates", "units" for coordinate variables and "_FillValue".
1300 void handle_grid_cf_attrs();
1301
1302 // Special handling SOM(Space Oblique Mercator) projection files
1303 void handle_grid_SOM_projection();
1304
1305 bool find_dim_in_dims(const std::vector<Dimension*>&dims,const std::string &dim_name) const;
1306
1307 // Check if we need to handle dim. map and set handle_swath_dimmap if necessary.
1308 // The input parameter is the number of swath.
1309 void check_swath_dimmap(int numswath);
1310
1311 void check_swath_dimmap_bk_compat(int numswath);
1312
1313 // Create the dimension name to coordinate variable name map for lat/lon.
1314 // The input parameter is the number of dimension maps in this file.
1315 void create_swath_latlon_dim_cvar_map();
1316
1317 // Create the dimension name to coordinate variable name map for non lat/lon coordinate variables.
1318 void create_swath_nonll_dim_cvar_map();
1319
1320 // Handle swath dimension name to coordinate variable name maps.
1321 // The input parameter is the number of dimension maps in this file.
1322 void handle_swath_dim_cvar_maps();
1323
1324 // Handle CF attributes for swaths.
1325 // The CF attributes include "coordinates", "units" for coordinate variables and "_FillValue".
1326 void handle_swath_cf_attrs();
1327
1328 bool check_ll_in_coords(const std::string& vname);
1329
1333 // is not to keep original latitude/longitude. Now some MODIS files
1334 // have the variables that still use the low resolution. See HFRHANDLER-332.
1335 void check_dm_geo_dims_in_vars() const;
1336
1338 void create_swath_latlon_dim_cvar_map_for_dimmap(SwathDataset*,Field*,Field*);
1339
1340 void create_geo_varnames_list(std::vector<std::string> &,const std::string &,
1341 const std::string &,int,bool) const;
1342
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*>&);
1348
1349 void update_swath_dims_for_dimmap(const SwathDataset*,
1350 const std::vector<Dimension*>&, const std::vector<Dimension*>&) const;
1351
1352
1353
1354 private:
1355
1356 // HDF-EOS2 Grid File ID. Notice this ID is not an individual grid ID but the grid file ID returned by
1357 // calling the HDF-EOS2 API GDopen.
1358 int32 gridfd = -1;
1359
1360 // HDF-EOS2 Swath File ID. Notice this ID is not an individual swath ID but the swath file ID returned by
1361 // calling the HDF-EOS2 API SWopen.
1362 int32 swathfd = -1;
1363
1376
1377#if 0
1379#endif
1380 };
1381
1382
1383 struct Utility
1384 {
1385
1387 static bool ReadNamelist (const char *path,
1388 int32 (*inq) (char *, char *, int32 *),
1389 std::vector < std::string > &names);
1390
1391
1392 };
1393
1394}
1395#endif
1396
1397#endif