bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HDFSP.h
1
2// This file is part of the hdf4 data handler for the OPeNDAP data server.
12// TRMM version 7 Level2
13// TRMM version 7 Level3
23
32
33
34//#include <libdap/InternalErr.h>
35#ifndef _HDFSP_H
36#define _HDFSP_H
37
38#include <iostream>
39#include <sstream>
40#include <string>
41#include <vector>
42#include <map>
43#include <set>
44#include <list>
45#include "mfhdf.h"
46#include "hdf.h"
47
48#include "HDFSPEnumType.h"
49
50#define MAX_FULL_PATH_LEN 1024
51//#define EOS_DATA_PATH "Data Fields"
52//#define EOS_GEO_PATH "Geolocation Fields"
53
54#define _HDF_CHK_TBL_CLASS "_HDF_CHK_TBL_"
55#define CERE_META_NAME "CERES_metadata"
56#define CERE_META_FIELD_NAME "LOCALGRANULEID"
57#define SENSOR_NAME "Sensor Name"
58#define PRO_NAME "Product Name"
59#define CER_AVG_NAME "CER_AVG"
60#define CER_ES4_NAME "CER_ES4"
61#define CER_CDAY_NAME "CER_ISCCP-D2like-Day"
62#define CER_CGEO_NAME "CER_ISCCP-D2like-GEO"
63#define CER_SRB_NAME "CER_SRBAVG3"
64#define CER_SYN_NAME "CER_SYN"
65#define CER_ZAVG_NAME "CER_ZAVG"
66
67
82
83
84
85namespace HDFSP
86{
89 class File;
90 class SD;
91 class VDATA;
92
93 class Exception:public std::exception
94 {
95 public:
96
98 explicit Exception (const std::string & msg)
99 : message (msg)
100 {
101 }
102
104 ~ Exception () throw () override = default;
105
107 const char *what () const throw () override
108 {
109 return this->message.c_str ();
110 }
111
113 virtual void setException (const std::string &exception_message)
114 {
115 this->message = exception_message;
116 }
117
118
119 private:
121 std::string message;
122 };
123
124
127 class Dimension
128 {
129 public:
130
132 const std::string & getName () const
133 {
134 return this->name;
135 }
136
138 int32 getSize () const
139 {
140 return this->dimsize;
141 }
142
145 int32 getType () const
146 {
147 return this->dimtype;
148 }
149
150 protected:
151 Dimension (const std::string & dim_name, int32 hdf4_dimsize, int32 hdf4_dimtype)
152 : name (dim_name), dimsize (hdf4_dimsize), dimtype (hdf4_dimtype)
153 {
154 }
155
156 private:
157 // dimension name
158 std::string name;
159
160 // dimension size
161 int32 dimsize;
162
164 int32 dimtype;
165
166 friend class SD;
167 friend class File;
168 friend class SDField;
169 };
170
173 {
174 public:
175
177 const std::string & getName () const
178 {
179 return this->name;
180 }
181
183 const std::string & getNewName () const
184 {
185 return this->newname;
186 }
187
189 int32 getType () const
190 {
191 return this->type;
192 }
193
195 int32 getCount () const
196 {
197 return this->count;
198 }
199
201 const std::vector < char >&getValue () const
202 {
203 return this->value;
204 }
205
206 private:
207
209 std::string name;
210
212 std::string newname;
213
215 int32 type;
216
218 int32 count;
219
221 std::vector < char >value;
222
223 friend class SD;
224 friend class VDATA;
225 friend class File;
226 friend class Field;
227 friend class VDField;
228 };
229
234 class AttrContainer {
235
236 public:
237 AttrContainer() = default;
238 ~AttrContainer();
239
240
242 const std::string & getName () const
243 {
244 return this->name;
245 }
246
248
249 const std::vector < Attribute * >&getAttributes () const
250 {
251 return this->attrs;
252 }
253
254 private:
255
256 // The name of this attribute container(an attribute container is a DAP DAS table)
257 std:: string name;
258
259 // The attributes in this attribute container
260 std::vector < Attribute * >attrs;
261 friend class SD;
262 friend class File;
263
264 };
265
266
267 // This field class describes SDS or Vdata fields.
268 class Field
269 {
270 public:
271 Field () = default;
272
273 virtual ~ Field ();
274
276 const std::string & getName () const
277 {
278 return this->name;
279 }
280
282 const std::string & getNewName () const
283 {
284 return this->newname;
285 }
286
288 int32 getRank () const
289 {
290 return this->rank;
291 }
292
294 int32 getType () const
295 {
296 return this->type;
297 }
298
300 const std::vector < Attribute * >&getAttributes () const
301 {
302 return this->attrs;
303 }
304
305
306 protected:
307
309 std::string newname;
310
312 std::string name;
313
315 int32 type = -1;
316
318 int32 rank = -1;
319
321 std::vector < Attribute * >attrs;
322
323 friend class SD;
324 friend class VDATA;
325 friend class File;
326 };
327
329
330 class SDField:public Field
331 {
332 public:
333 SDField () = default;
334 ~SDField () override;
335
336
338 const std::vector < Dimension * >&getCorrectedDimensions () const
339 {
340 return this->correcteddims;
341 }
342
344 std::vector < Dimension * >*getCorrectedDimensionsPtr ()
345 {
346 return &(this->correcteddims);
347 }
348
350 void setCorrectedDimensions (const std::vector < Dimension * > &cor_dims)
351 {
352 correcteddims = cor_dims;
353 }
354
356 std::string getCoordinate () const
357 {
358 return this->coordinates;
359 }
360
362 void setCoordinates (const std::string& coor)
363 {
364 coordinates = coor;
365 }
366
368 std::string getUnits () const
369 {
370 return this->units;
371 }
372
373 // Set the "units" attribute
374 void setUnits (const std::string &uni)
375 {
376 units = uni;
377 }
378
379 // Get the field type
380 int getFieldType () const
381 {
382 return this->fieldtype;
383 }
384
385 // Get the SDS reference number
386 int32 getFieldRef () const
387 {
388 return this->fieldref;
389 }
390
392 const std::vector < Dimension * >&getDimensions () const
393 {
394 return this->dims;
395 }
396
398 const std::vector < AttrContainer * >&getDimInfo () const
399 {
400 return this->dims_info;
401 }
402
403
405 bool IsDimNoScale() const
406 {
407 return is_noscale_dim;
408 }
409
411 bool IsDimScale() const
412 {
413 return is_dim_scale;
414 }
415
417 std::string getSpecFullPath() const
418 {
419 return special_product_fullpath;
420 }
421 private:
422
424 std::vector < Dimension * >dims;
425
429 std::vector < Dimension * >correcteddims;
430
432 std::vector<AttrContainer *>dims_info;
433
434 std::string coordinates;
435
442 int fieldtype = 0;
443
445 std::string units;
446
457 std::string special_product_fullpath;
458
460 int32 fieldref = -1;
461
462
465 bool is_noscale_dim = false;
466
468 bool is_dim_scale = false;
469
472 std::string rootfieldname;
473
474 friend class File;
475 friend class SD;
476 };
477
479 class VDField:public Field
480 {
481 public:
482 VDField () = default;
483 ~VDField () override = default;
484
486 int32 getFieldOrder ()const
487 {
488 return this->order;
489 }
490
492 int32 getFieldsize () const
493 {
494 return this->size;
495 }
496
498 int32 getNumRec () const
499 {
500 return this->numrec;
501 }
502
504 const std::vector < char >&getValue () const
505 {
506 return this->value;
507 }
508
510 void ReadAttributes (int32 vdata_id, int32 fieldindex);
511
512 private:
513
515 int32 order = -1;
516
518 int32 numrec = -1;
519
521 int32 size = -1;
522
524 std::vector < char >value;
525
526 friend class File;
527 friend class VDATA;
528 };
529
531 class SD
532 {
533 public:
534
536 static SD *Read (int32 sdfileid, int32 hfileid) ;
537
539 static SD *Read_Hybrid (int32 sdfileid, int32 hfileid) ;
540
541
543 const std::vector < SDField * >&getFields () const
544 {
545 return this->sdfields;
546 }
547
549 const std::vector < Attribute * >&getAttributes () const
550 {
551 return this->attrs;
552 }
553
555 void obtain_noneos2_sds_path(int32,char*,int32) ;
556
557
559 ~SD ();
560
561 SD() = default;
562
563 private:
565 std::vector < SDField * >sdfields;
566
568 std::vector < Attribute * >attrs;
569
571 std::list <int32> sds_ref_list;
572
574 std::map < int32, int >refindexlist;
575
578 std::map < std::string, int32 > n1dimnamelist;
579
581 std::map < std::string, std::string > n2dimnamelist;
582
584 std::set < std::string > fulldimnamelist;
585
589 std::set < std::string > nonmisscvdimnamelist;
590
592 std::map < std::string, std::string > dimcvarlist;
593
594 friend class File;
595 };
596
598 class VDATA
599 {
600 public:
601
602 ~VDATA ();
603
605 static VDATA *Read (int32 vdata_id, int32 obj_ref) ;
606
608 void ReadAttributes (int32 vdata_id) ;
609
611 const std::string & getNewName () const
612 {
613 return this->newname;
614 }
615
617 const std::string & getName () const
618 {
619 return this->name;
620 }
621
623 const std::vector < VDField * >&getFields () const
624 {
625 return this->vdfields;
626 }
627
629 const std::vector < Attribute * >&getAttributes () const
630 {
631 return this->attrs;
632 }
633
637 bool getTreatAsAttrFlag () const
638 {
639 return TreatAsAttrFlag;
640 }
641
643 int32 getObjRef () const
644 {
645 return vdref;
646 }
647
648 VDATA (int32 obj_ref)
649 :vdref(obj_ref){
650 }
651
652 private:
654 std::string newname;
655
657 std::string name;
658
660 std::vector < VDField * >vdfields;
661
663 std::vector < Attribute * >attrs;
664
666 int32 vdref;
667
669 bool TreatAsAttrFlag = true;
670
671 friend class File;
672 };
673
676 class File
677 {
678 public:
679
681 static File *Read (const char *path, int32 sdid,int32 fileid);
682
685 static File *Read_Hybrid (const char *path, int32 sdid,
686 int32 fileid);
687
691 void Prepare() ;
692
693 bool Check_update_special(const std::string &gridname) const;
694
695 void Handle_AIRS_L23();
696
697
699 SPType getSPType () const
700 {
701 return this->sptype;
702 }
703
705
707 {
708 return this->OTHERHDF_Has_Dim_NoScale_Field;
709 }
710
711 // Destructor
712 ~File ();
713
715 const std::string & getPath () const
716 {
717 return this->path;
718 }
719
721 SD *getSD () const
722 {
723 return this->sd;
724 }
725
727 const std::vector < VDATA * >&getVDATAs () const
728 {
729 return this->vds;
730 }
731
733 const std::vector<AttrContainer *> &getVgattrs () const
734 {
735 return this->vg_attrs;
736 }
737
738
739
740 protected:
741 explicit File (const char *hdf4file_path)
742 : path (hdf4file_path)
743 {
744 }
745
746
750
753
755 void handle_sds_missing_fields() const;
756
759
761 void handle_sds_names(bool & COARDFLAG , std::string & lldimname1, std::string &lldimname2);
762
764 void handle_sds_coords(bool COARDFLAG, const std::string &lldimname1,const std::string &lldimname2);
765
767 void handle_vdata() const;
768
770 void CheckSDType () ;
771
773 void PrepareTRMML2_V6 () ;
774
776 void PrepareTRMML3A_V6 () ;
777
779 void PrepareTRMML3B_V6 () ;
780
782 void PrepareTRMML3C_V6 () ;
783
785 void Obtain_TRMML3S_V7_latlon_size(int &latsize, int&lonsize);
786
787 bool Obtain_TRMM_V7_latlon_name(const SDField* sdfield, const int latsize, const int lonsize, std::string& latname, std::string& lonname);
788
790 void PrepareTRMML2_V7 () ;
791
793 void PrepareTRMML3S_V7 () ;
794
796 void PrepareTRMML3M_V7 () ;
797
798
801 void PrepareCERAVGSYN () ;
802
805 void PrepareCERES4IG () ;
806
810 void PrepareCERSAVGID () ;
811
813 void PrepareCERZAVG () ;
814
816 void PrepareOBPGL2 () ;
817
819 void PrepareOBPGL3 () ;
820
823 void PrepareMODISARNSS () ;
824
826 void PrepareOTHERHDF () ;
827
829 void ReadLoneVdatas(File*) const;
830
833 void ReadHybridNonLoneVdatas(const File*);
834
836 void ReadVgattrs(int32 vgroup_id, const char *fullpath);
837
840
842 void obtain_path (int32 file_id, int32 sd_id, char *full_path, int32 pobj_ref) ;
843
845 void obtain_vdata_path(int32 file_id, char *full_path, int32 pobj_ref) ;
846
847
848 private:
849
851 std::string path;
852
854 SD *sd = nullptr;
855
857 std::vector < VDATA * >vds;
858
860 std::vector<AttrContainer *>vg_attrs;
861
862
864 int32 sdfd = -1;
865
867 int32 fileid = -1;
868
870 SPType sptype = OTHERHDF;
871
873 bool OTHERHDF_Has_Dim_NoScale_Field = false;
874
877 bool EOS2Swathflag = false;
878 };
879
880}
881
882
883#endif
const std::vector< Attribute * > & getAttributes() const
No need to have the newname since we will make the name follow CF conventions.
Definition HDFSP.h:249
const std::string & getName() const
Get the name of this attribute container.
Definition HDFSP.h:242
Representing one attribute in grid or swath.
Definition HDFSP.h:173
const std::string & getName() const
Get the attribute name.
Definition HDFSP.h:177
int32 getType() const
Get the attribute datatype.
Definition HDFSP.h:189
const std::vector< char > & getValue() const
Get the attribute value.
Definition HDFSP.h:201
const std::string & getNewName() const
Get the CF attribute name(special characters are replaced by underscores)
Definition HDFSP.h:183
int32 getCount() const
Get the number of elements of this attribute.
Definition HDFSP.h:195
const std::string & getName() const
Get dimension name.
Definition HDFSP.h:132
int32 getSize() const
Get dimension size.
Definition HDFSP.h:138
int32 getType() const
Definition HDFSP.h:145
const char * what() const override
Return exception message.
Definition HDFSP.h:107
Exception(const std::string &msg)
Constructor.
Definition HDFSP.h:98
virtual void setException(const std::string &exception_message)
Set exception message.
Definition HDFSP.h:113
const std::vector< Attribute * > & getAttributes() const
Get the attributes of this field.
Definition HDFSP.h:300
int32 rank
The rank of this field.
Definition HDFSP.h:318
std::vector< Attribute * > attrs
The attributes of this field.
Definition HDFSP.h:321
std::string newname
The CF full path(special characters replaced by underscores) of this field.
Definition HDFSP.h:309
int32 type
The datatype of this field.
Definition HDFSP.h:315
int32 getType() const
Get the data type of this field.
Definition HDFSP.h:294
const std::string & getNewName() const
Get the CF name(special characters replaced by underscores) of this field.
Definition HDFSP.h:282
std::string name
The original name of this field.
Definition HDFSP.h:312
int32 getRank() const
Get the dimension rank of this field.
Definition HDFSP.h:288
const std::string & getName() const
Get the name of this field.
Definition HDFSP.h:276
static File * Read(const char *path, int32 sdid, int32 fileid)
Retrieve SDS and Vdata information from the HDF4 file.
Definition HDFSP.cc:191
void handle_sds_final_dim_names()
Create the final CF-compliant dimension name list for each field.
Definition HDFSP.cc:3529
void PrepareTRMML3M_V7()
Special method to prepare TRMM multiple grid Level 3 geolocation fields(latitude,longitude,...
Definition HDFSP.cc:4463
void Prepare()
Definition HDFSP.cc:3839
const std::vector< VDATA * > & getVDATAs() const
Public interface to Obtain Vdata.
Definition HDFSP.h:727
const std::vector< AttrContainer * > & getVgattrs() const
Get attributes for all vgroups.
Definition HDFSP.h:733
void PrepareMODISARNSS()
Definition HDFSP.cc:5737
void PrepareTRMML3S_V7()
Special method to prepare TRMM single grid Level 3 geolocation fields(latitude,longitude,...
Definition HDFSP.cc:4169
bool Has_Dim_NoScale_Field() const
This file has a field that is a SDS dimension but no dimension scale.
Definition HDFSP.h:706
void ReadHybridNonLoneVdatas(const File *)
Definition HDFSP.cc:504
void handle_vdata() const
Handle Vdata.
Definition HDFSP.cc:3804
void CheckSDType()
This method will check if the HDF4 file is one of TRMM or OBPG products we supported.
Definition HDFSP.cc:1142
SD * getSD() const
Public interface to Obtain SD.
Definition HDFSP.h:721
void ReadVgattrs(int32 vgroup_id, const char *fullpath)
Obtain vgroup attributes.
Definition HDFSP.cc:2476
void PrepareTRMML2_V7()
Latitude and longitude are stored in different fields. Need to separate.
Definition HDFSP.cc:4040
void PrepareCERAVGSYN()
Definition HDFSP.cc:5352
void Obtain_TRMML3S_V7_latlon_size(int &latsize, int &lonsize)
void Obtain_TRMML3S_V7_latlon_size(int &latsize, int&lonsize) throw(Exception);
Definition HDFSP.cc:3997
void PrepareTRMML3C_V6()
Special method to prepare TRMM Level 3 CSH latitude,longitude and Height information.
Definition HDFSP.cc:5000
static File * Read_Hybrid(const char *path, int32 sdid, int32 fileid)
Definition HDFSP.cc:234
void handle_sds_fakedim_names()
Definition HDFSP.cc:3399
void PrepareOBPGL3()
Special method to prepare OBPG Level 3 latitude and longitude information. The latitude and longitude...
Definition HDFSP.cc:5210
void obtain_vdata_path(int32 file_id, char *full_path, int32 pobj_ref)
The internal function used to obtain the path for hybrid non-lone vdata.
Definition HDFSP.cc:3186
void handle_sds_names(bool &COARDFLAG, std::string &lldimname1, std::string &lldimname2)
Create the final CF-compliant field name list.
Definition HDFSP.cc:3571
SPType getSPType() const
Obtain special HDF4 product type.
Definition HDFSP.h:699
void PrepareCERES4IG()
Definition HDFSP.cc:5426
void handle_sds_missing_fields() const
Add the missing coordinate variables based on the corrected dimension name list.
Definition HDFSP.cc:3491
void ReadLoneVdatas(File *) const
Handle non-attribute lone vdatas.
Definition HDFSP.cc:276
void PrepareOTHERHDF()
We still provide a hook for other HDF data product although no CF compliant is followed.
Definition HDFSP.cc:5783
void handle_sds_coords(bool COARDFLAG, const std::string &lldimname1, const std::string &lldimname2)
Create "coordinates", "units" CF attributes.
Definition HDFSP.cc:3727
void PrepareTRMML3A_V6()
Special method to prepare TRMM Level 3A46 latitude and longitude information.
Definition HDFSP.cc:4863
void PrepareTRMML3B_V6()
Special method to prepare TRMM Level 3B latitude and longitude information.
Definition HDFSP.cc:4760
void InsertOrigFieldPath_ReadVgVdata()
The full path of SDS and Vdata will be obtained.
Definition HDFSP.cc:2529
void PrepareCERSAVGID()
Definition HDFSP.cc:5553
void PrepareOBPGL2()
Special method to prepare OBPG Level 2 latitude and longitude information. The latitude and longitude...
Definition HDFSP.cc:5133
void create_sds_dim_name_list()
Create the new dimension name set and the dimension name to size map.
Definition HDFSP.cc:3471
void obtain_path(int32 file_id, int32 sd_id, char *full_path, int32 pobj_ref)
The internal function used by InsertOrigFieldPath_ReadVgVdata.
Definition HDFSP.cc:2853
void PrepareCERZAVG()
Special method to prepare CERES Zonal Average latitude and longitude information.
Definition HDFSP.cc:5687
void PrepareTRMML2_V6()
Latitude and longitude are stored in one array(geolocation). Need to separate.
Definition HDFSP.cc:4608
const std::string & getPath() const
Obtain the path of the file.
Definition HDFSP.h:715
void setCorrectedDimensions(const std::vector< Dimension * > &cor_dims)
Set the list of the corrected dimensions.
Definition HDFSP.h:350
const std::vector< Dimension * > & getCorrectedDimensions() const
Get the list of the corrected dimensions.
Definition HDFSP.h:338
std::string getSpecFullPath() const
This function returns the full path of some special products that have a very long path.
Definition HDFSP.h:417
bool IsDimScale() const
Is this field a dimension scale field?
Definition HDFSP.h:411
std::vector< Dimension * > * getCorrectedDimensionsPtr()
Get the list of the corrected dimension ptrs.
Definition HDFSP.h:344
const std::vector< AttrContainer * > & getDimInfo() const
Get the list of OHTERHDF dimension attribute container information.
Definition HDFSP.h:398
const std::vector< Dimension * > & getDimensions() const
Get the list of dimensions.
Definition HDFSP.h:392
std::string getCoordinate() const
Get the "coordinates" attribute.
Definition HDFSP.h:356
std::string getUnits() const
Get the "units" attribute.
Definition HDFSP.h:368
bool IsDimNoScale() const
Is this field a dimension without dimension scale(or empty[no data]dimension variable)
Definition HDFSP.h:405
void setCoordinates(const std::string &coor)
Set the coordinate attribute.
Definition HDFSP.h:362
This class retrieves all SDS objects and SD file attributes.
Definition HDFSP.h:532
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain the SD(file) attributes.
Definition HDFSP.h:549
~SD()
Destructor.
Definition HDFSP.cc:144
static SD * Read_Hybrid(int32 sdfileid, int32 hfileid)
Read the information of all hybrid SDS objects from the HDF4 file.
Definition HDFSP.cc:1767
const std::vector< SDField * > & getFields() const
Public interface to obtain information of all SDS vectors(objects).
Definition HDFSP.h:543
static SD * Read(int32 sdfileid, int32 hfileid)
Read the information of all SDS objects from the HDF4 file.
Definition HDFSP.cc:1426
void obtain_noneos2_sds_path(int32, char *, int32)
Obtain SDS path, this is like a clone of obtain_path in File class, except the Vdata and some minor p...
Definition HDFSP.cc:3083
This class retrieves all information of one Vdata.
Definition HDFSP.h:599
bool getTreatAsAttrFlag() const
Definition HDFSP.h:637
int32 getObjRef() const
Obtain Vdata reference number, this is necessary for retrieving Vdata information from HDF4.
Definition HDFSP.h:643
const std::vector< VDField * > & getFields() const
Obtain Vdata fields.
Definition HDFSP.h:623
const std::string & getNewName() const
Obtain new names(with the path and special characters and name clashing handlings)
Definition HDFSP.h:611
void ReadAttributes(int32 vdata_id)
Retrieve all attributes of this Vdata.
Definition HDFSP.cc:2365
const std::string & getName() const
Obtain the original vdata name.
Definition HDFSP.h:617
static VDATA * Read(int32 vdata_id, int32 obj_ref)
Retrieve all information of this Vdata.
Definition HDFSP.cc:2189
const std::vector< Attribute * > & getAttributes() const
Obtain Vdata attributes.
Definition HDFSP.h:629
One instance of this class represents one Vdata field.
Definition HDFSP.h:480
void ReadAttributes(int32 vdata_id, int32 fieldindex)
Read vdata field attributes.
Definition HDFSP.cc:2420
int32 getNumRec() const
Get the number of record.
Definition HDFSP.h:498
const std::vector< char > & getValue() const
Get the vdata field values.
Definition HDFSP.h:504
int32 getFieldOrder() const
Get the order of this field.
Definition HDFSP.h:486
int32 getFieldsize() const
Get the field size.
Definition HDFSP.h:492
Definition HDFSP.h:86