forked from OPENDAP/hdf4_handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHDFEOS2.h
More file actions
1470 lines (1195 loc) · 53.2 KB
/
HDFEOS2.h
File metadata and controls
1470 lines (1195 loc) · 53.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////////////////
// This file is part of the hdf4 data handler for the OPeNDAP data server.
//
// Author: Kent Yang,Choonghwan Lee <myang6@hdfgroup.org>
// Copyright (c) 2010-2012 The HDF Group
/////////////////////////////////////////////////////////////////////////////
//#include "InternalErr.h"
#ifdef USE_HDFEOS2_LIB
#ifndef _HDFEOS2_H
#define _HDFEOS2_H
#ifdef _WIN32
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#endif
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include "mfhdf.h"
#include "hdf.h"
#include "HdfEosDef.h"
// Add MISR SOM projection header
#include "misrproj.h"
#include "HDFEOS2EnumType.h"
#ifdef _WIN32
#ifdef _MSC_VER
#pragma warning(disable:4290)
#endif
#endif
/// HDFEOS2.h and HDFEOS2.cc include the core part of retrieving HDF-EOS2 Grid and Swath
/// metadata info and translate them into DAP DDS and DAS.
///
/// It currently handles EOS Swath and Grid, which covers 99%
/// of all EOS2 files. It not only retrieves the general information of an
/// EOS physical data field but also geo-location fields of the data field.
/// For Grid, latitude and longitude fields will be retrieved for all types
/// of projections supported by EOS2. For Swath, latitude and longitude will
/// also be retrieved when dimension map is involved.
/// The translation of Grid and Swath to DAP DDS and DAS is not a pure syntax
/// translation. It addes sematic meaning by following the CF conventions.
/// The core part of the translation is to create coordinate variable list and dimension
/// list for each field(variable). The variable/attribute/dimension names are
/// also made to follow CF.
///
/// @author Kent Yang, Choonghwan Lee <myang6@hdfgroup.org>
///
/// Copyright (C) 2010-2012 The HDF Group
///
/// All rights reserved.
namespace HDFEOS2
{
/// The Exception class for handling exceptions caused by using this
/// HDFEOS2 library
class Exception:public std::exception
{
public:
/// Constructor
explicit Exception (const std::string & msg)
: message (msg), isHDFEOS2 (true)
{
}
/// Destructor
virtual ~ Exception () throw ()
{
}
/// Exception message
virtual const char *what () const throw ()
{
return this->message.c_str ();
}
/// check if this file is an HDFEOS2 file, this is necessary
/// since the handler also supports non-HDFEOS2 HDF4 products.
virtual bool getFileType ()
{
return this->isHDFEOS2;
}
/// set file type be either HDF-EOS2 or HDF4(non-HDFEOS2)
virtual void setFileType (bool isHDFEOS2_flag)
{
this->isHDFEOS2 = isHDFEOS2_flag;
}
/// set exception message
virtual void setException (std::string exception_message)
{
this->message = exception_message;
}
private:
std::string message;
bool isHDFEOS2;
};
/// This class is similar to a standard vector class but with only limited
/// features.
///
/// The main unique feature of this class is that it doesn't call default
/// constructor to initialize the value of each element when resizing
/// this class. It may reduce some overheads. However, it only provides
/// push_back,reserve and resize functions. FieldData class and its
/// subclasses use this class to hold elements in the field.
template < typename T > class LightVector {
public:
LightVector ()
: data (0), length (0), capacity (0) {
}
LightVector (const LightVector < T > &that)
{
this->data = new T[that.length];
for (unsigned int i = 0; i < that.length; ++i)
this->data[i] = that[i];
this->length = that.length;
this->capacity = that.length;
}
~LightVector () {
if (this->data)
delete[]data;
}
void push_back (const T & d)
{
this->reserve (this->length + 1);
this->data[this->length] = d;
++this->length;
}
void reserve (unsigned int len)
{
if (this->capacity >= len)
return;
this->capacity = len;
T *old = this->data;
this->data = new T[len];
if (old) {
for (unsigned int i = 0; i < this->length; ++i)
this->data[i] = old[i];
delete[]old;
}
}
void resize (unsigned int len)
{
/// do not call constructor for each element
if (this->length == len)
return;
else if (this->length < len) {
if (this->capacity < len) {
this->capacity = len;
T *old = this->data;
this->data = new T[len];
if (old) {
for (unsigned int i = 0; i < this->length; ++i)
this->data[i] = old[i];
delete[]old;
}
}
}
else {
this->capacity = len;
T *old = this->data;
this->data = new T[len];
for (unsigned int i = 0; i < len; ++i)
this->data[i] = old[i];
if (old)
delete[]old;
}
this->length = len;
}
unsigned int size () const
{
return this->length;
}
T & operator[] (unsigned int i)
{
return this->data[i];
}
const T & operator[] (unsigned int i) const
{
return this->data[i];
}
LightVector < T > &operator= (const LightVector < T > &that)
{
if (this != &that) {
this->data = new T[that.length];
for (unsigned int i = 0; i < that.length; ++i)
this->data[i] = that[i];
this->length = that.length;
this->capacity = that.length;
}
return *this;
}
private:
T * data;
unsigned int length;
unsigned int capacity;
};
class SwathDimensionAdjustment;
/// It repersents one dimension of an EOS object including fields,
/// geo-location fields and others.
/// It holds the dimension name and the size of that dimension.
class Dimension
{
public:
const std::string & getName () const
{
return this->name;
}
int32 getSize () const
{
return this->dimsize;
}
protected:
Dimension (const std::string & eos_dname, int32 eos_dimsize)
: name (eos_dname), dimsize (eos_dimsize)
{
}
private:
std::string name;
int32 dimsize;
friend class File;
friend class Dataset;
friend class SwathDimensionAdjustment;
};
/// One instance of this class represents one field or one geo-location
/// field
class Field
{
public:
Field ()
:fieldtype (0), condenseddim (false), iscoard (false), ydimmajor (true), speciallon (false), specialformat (0), haveaddedfv (false), addedfv (-9999.0), dmap (false)/*, field_cache(0)*/
{
name ="";
rank =-1;
type =-1;
ll_dim0_offset = 0;
ll_dim0_inc = 0;
ll_dim1_offset = 0;
ll_dim1_inc = 0;
coordinates="";
newname = "";
units="";
}
virtual ~ Field ();
public:
/// Get the name of this field
const std::string & getName () const
{
return this->name;
}
/// Get the CF name of this field
const std::string & getNewName () const
{
return this->newname;
}
/// Get the dimension rank of this field
int32 getRank () const
{
return this->rank;
}
/// Get the data type of this field
int32 getType () const
{
return this->type;
}
/// Get the list of the corrected dimensions
const std::vector < Dimension * >&getCorrectedDimensions () const
{
return this->correcteddims;
}
/// Get the pointer of the corrected dimensions
std::vector < Dimension * >*getCorrectedDimensionsPtr ()
{
return &(this->correcteddims);
}
/// Set the list of the corrected dimensions
void setCorrectedDimensions (std::vector < Dimension * >eos_dims)
{
correcteddims = eos_dims;
}
/// Get the "coordinates" attribute value
const std::string getCoordinate () const
{
return this->coordinates;
}
/// Set the "coordinates" attribute value
void setCoordinates (std::string coor)
{
coordinates = coor;
}
/// Get the "units" attribute value
const std::string getUnits () const
{
return this->units;
}
/// Set the "units" attribute value
void setUnits (std::string uni)
{
units = uni;
}
/// Get the _Fillvalue" attribute value
float getAddedFillValue () const
{
return this->addedfv;
}
// Add the "_FillValue" attribute
// This is for supporting the old versions of HDF-EOS2 data(AIRS) because
// some data products have fillvalue(-9999.0) but don't specify the fillvalue.
// We add the fillvalue to ensure the netCDF client can successfully display the data.
// KY 2013-06-30
void addFillValue (float fv)
{
addedfv = fv;
}
/// Have the added fillvaue?
bool haveAddedFillValue () const
{
return this->haveaddedfv;
}
/// set the flag for the added FillValue
void setAddedFillValue (bool havefv)
{
haveaddedfv = havefv;
}
// Obtain fieldtype values
// For fieldtype values:
// 0 is general fields
// 1 is latitude.
// 2 is longtitude.
// 3 is defined level.
// 4 is an inserted natural number.
// 5 is time.
int getFieldType () const
{
return this->fieldtype;
}
/// Get the list of dimensions
const std::vector < Dimension * >&getDimensions () const
{
return this->dims;
}
/// Obtain fill value of this field.
const std::vector < char >&getFillValue () const
{
return this->filler;
}
/// Obtain swath the dimension map offset of the first dimenion.
/// Only apply to Latitude/Longitude(fieldtype=1,or 2) when
/// the file contains multiple swath dimension maps(multi_dimmap =true).
const int getLLDim0Offset () const
{
return this->ll_dim0_offset;
}
const int getLLDim0Inc () const
{
return this->ll_dim0_inc;
}
const int getLLDim1Offset () const
{
return this->ll_dim1_offset;
}
const int getLLDim1Inc () const
{
return this->ll_dim1_inc;
}
/// Obtain the ydimmajor info.
bool getYDimMajor () const
{
return this->ydimmajor;
}
/// Obtain the speciallon info.
bool getSpecialLon () const
{
return this->speciallon;
}
/// Obtain the special lat/lon format info.
int getSpecialLLFormat () const
{
return this->specialformat;
}
/// Obtain if the dimension can be condensed.
bool getCondensedDim () const
{
return this->condenseddim;
}
/// Have dimension map or not
bool UseDimMap () const
{
return this->dmap;
}
//No need to check field_cache in the DDS level.
//May remove the debugging info. totally in the next release.
//KY 2014-10-23
#if 0
/// Have field cache or not
// 2 exactly cached
// 1 maybe cached, need to check the
// file size when accessing the data
const short UseFieldCache () const
{
return this->field_cache;
}
#endif
protected:
// field name
std::string name;
// field dimension rank
int32 rank;
// field datatype
int32 type;
// field dimensions with original dimension names
std::vector < Dimension * >dims;
// field dimensions with the corrected(CF) dimension names
std::vector < Dimension * >correcteddims;
// This is for reading the fillvalue.
// HDF-EOS2 provides a special routine to read fillvalue.
// Up to HDF-EOS2 version 2.18, this is the only field attribute
// that HDF-EOS2 APIs provide. KY 2013-07-01
std::vector < char >filler;
// Coordinate attributes that includes coordinate variable list.
std::string coordinates;
// newname is to record CF Grid/Swath name + "_"+ CF field name(special characters replaced by underscores).
std::string newname;
// This flag will specify the fieldtype.
// 0 means this field is general field.
// 1 means this field is lat.
// 2 means this field is lon.
// 3 means this field is other dimension variable.
// 4 means this field is added other dimension variable with nature number.
// 5 means time, but currently the units is not correct.
int fieldtype;
// Latitude and longitude retrieved by HDF-EOS2 are always
// 2-D arrays(XDim * YDim). However, for some projections
// (geographic etc.), latiude and longitude can be condensed to
// 1-D arrays. The handler will track such projections and condense
// the latitude and longitude to 1-D arrays. This can reduce
// the disk storage and can greatly improve the performance for
// the visualization tool to access the latitude and longitde.
// condenseddim is the flag internally used by the handler to track this.
bool condenseddim;
// This flag is to mark if the data should follow COARDS.
bool iscoard;
// This flag is to check if the field is YDim major(temp(YDim,XDim). This
// flag is necessary when calling GDij2ll to retrieve latitude and longitude.
bool ydimmajor;
// SOme special longitude is from 0 to 360.We need to check this case with this flag.
bool speciallon;
// This flag specifies the special latitude/longitude coordinate format
// The latiude and longitude should represent as DDDMMMSSS format
// However, we found some files simply represent lat/lon as -180.0000000 or -90.000000.
// Some other files use default. So we this flag to record this and correctly retrieve
// the latitude and longitude values in the DAP output.
// 0 means normal
// 1 means the coordinate is -180 to 180
// 2 means the coordinate is default(0)
int specialformat;
// CF units attribute(mostly to add latitude and longitude CF units).
std::string units;
// Some data products have fillvalue(-9999.0) but don't specify the fillvalue.
// We add the fillvalue to ensure the netCDF client can successfully display the data.
// haveaddedfv and addedfv are to check if having added fillvalues.
bool haveaddedfv;
int ll_dim0_offset;
int ll_dim0_inc;
int ll_dim1_offset;
int ll_dim1_inc;
float addedfv;
// Check if this swath uses the dimension map.
bool dmap;
friend class Dataset;
friend class SwathDimensionAdjustment;
friend class GridDataset;
friend class SwathDataset;
friend class File;
};
#if 0
// For future improvement of the modulization
class GeoField:public Field
{
protected:
bool condenseddim;
bool ydimmajor;
bool speciallon;
};
#endif
/// Representing one attribute in grid or swath
class Attribute
{
public:
/// Obtain the original attribute name
const std::string & getName () const
{
return this->name;
}
/// Obtain the CF attribute name(special characters are replaced by underscores)
const std::string & getNewName () const
{
return this->newname;
}
/// Obtain the attribute data type
int32 getType () const
{
return this->type;
}
/// Get the number of elements of this attribute
int32 getCount () const
{
return this->count;
}
/// Obtain the attribute values(in vector <char> form)
const std::vector < char >&getValue () const
{
return this->value;
}
private:
/// Attribute name
std::string name;
/// Attribute CF name(special characters are replaced by underscores)
std::string newname;
/// Attribute datatype(in HDF4 representation)
int32 type;
/// Attribute number of elements
int32 count;
/// Attribute value
std::vector < char >value;
friend class Dataset;
};
/// Base class of Grid and Swath Dataset. It provides public methods
/// to obtain name, number of dimensions, number of data fields and
/// attributes.
class Dataset
{
public:
/// Get the Dataset name
const std::string & getName () const
{
return this->name;
}
/// Get the dimension list of this grid or swath
const std::vector < Dimension * >&getDimensions () const
{
return this->dims;
}
/// Get data fields
const std::vector < Field * >&getDataFields () const
{
return this->datafields;
}
/// Get the attributes
const std::vector < Attribute * >&getAttributes () const
{
return this->attrs;
}
/// Get the scale and offset type
SOType getScaleType () const
{
return this->scaletype;
}
protected:
explicit Dataset (const std::string & n)
: datasetid (-1), addfvalueattr(false),name (n),scaletype(DEFAULT_CF_EQU)
{
}
virtual ~ Dataset ();
/// Obtain dimensions from Swath or Grid by calling EOS2 APIs such as
/// GDnentries and GDinqdims.
void ReadDimensions (int32 (*entries) (int32, int32, int32 *),
int32 (*inq) (int32, char *, int32 *),
std::vector < Dimension * >&dims) throw (Exception);
/// Obtain field data information from Swath or Gird by calling EOS2
/// APIs such as GDnentries, GDinqfields, GDfieldinfo, GDreadfield and
/// GDgetfillvalue.
void ReadFields (int32 (*entries) (int32, int32, int32 *),
int32 (*inq) (int32, char *, int32 *, int32 *),
intn (*fldinfo) (int32, char *, int32 *, int32 *,
int32 *, char *),
intn (*readfld) (int32, char *, int32 *, int32 *,
int32 *, VOIDP),
intn (*getfill) (int32, char *, VOIDP),
bool geofield, std::vector < Field * >&fields)
throw (Exception);
/// Obtain Grid or Swath attributes by calling EOS2 APIs such as
/// GDinqattrs, GDattrinfo and GDreadattr.
void ReadAttributes (int32 (*inq) (int32, char *, int32 *),
intn (*attrinfo) (int32, char *, int32 *, int32 *),
intn (*readattr) (int32, char *, VOIDP),
std::vector < Attribute * >&attrs)
throw (Exception);
/// Set scale and offset type
/// MODIS data has three scale and offset rules.
/// They are
/// MODIS_EQ_SCALE: raw_data = scale*data + offset
/// MODIS_MUL_SCALE: raw_data = scale*(data -offset)
/// MODIS_DIV_SCALE: raw_data = (data-offset)/scale
void SetScaleType(const std::string EOS2ObjName) throw(Exception);
int obtain_dimsize_with_dimname(const std::string& dimname);
protected:
/// Grid and Swath ID
int32 datasetid;
/// This flag is for CERES TRMM data that has fillvalues(huge real number) but doesn't
/// have the fillvalue attribute. We need to add a fillvalue.
/// Actually we also need to handle AIRS -9999.0 fillvalue case with this flag.
bool addfvalueattr;
/// Dataset name
std::string name;
/// Dataset dimension list
std::vector < Dimension * >dims;
/// Dataset field list
std::vector < Field * >datafields;
/// Dataset attribute list(This is equivalent to vgroup attributes)
std::vector < Attribute * >attrs;
/// dimension name to coordinate variable name map list
/// this is for building the coordinate variables associated with each variables.
std::map < std::string, std::string > dimcvarlist;
/// original coordinate variable name to corrected(CF) coordinate variable name map list
std::map < std::string, std::string > ncvarnamelist;
/// original dimension name to corrected(CF) dimension name map list
std::map < std::string, std::string > ndimnamelist;
// Some MODIS files don't use the CF linear equation y = scale * x + offset,
// The scaletype distinguishs products following different scale and offset rules.
// Note the assumption here: we assume that all fields will
// use one scale and offset function in a file. If
// multiple scale and offset equations are used in one file, our
// function will fail. So far only one scale and offset equation is
// applied for NASA HDF-EOS2 files we observed. KY 2012-6-13
// Since I found one MODIS product(MOD09GA) uses different scale offset
// equations for different grids. I had to move the scaletype to the
// group level. Hopefully this is the final fix. Truly hope that
// this will not happen at the field level since it will be too messy to
// check. KY 2012-11-21
SOType scaletype;
friend class File;
};
/// This class mainly handles the calculation of longitude and latitude of
/// an EOS Grid.
class GridDataset:public Dataset
{
public:
class Info
{
public:
/// dimension size of XDim.
int32 getX ()const
{
return this->xdim;
}
/// dimension size of YDim.
int32 getY () const
{
return this->ydim;
}
/// Geo-location value(latitude and longtitude for geographic
/// projection) at upper-left corner of the grid.
/// It consists of two values. The information was obtained from
/// EOS2 API GDgridinfo. These values are used by
/// EOS2 GDij2ll function to calculate latitude and longitude.
const float64 *getUpLeft () const
{
return this->upleft;
}
/// Geo-location value(latitude and longtitude for geographic
/// projection) at lower-right corner of the grid.
/// It consists of two values. The information was obtained from
/// EOS2 API GDgridinfo. These values are used by
/// EOS2 GDij2ll function to calculate latitude and longitude.
const float64 *getLowRight () const
{
return this->lowright;
}
protected:
Info() {
xdim = -1;
ydim = -1;
}
private:
int32 xdim;
int32 ydim;
float64 upleft[2];
float64 lowright[2];
friend class GridDataset;
};
class Projection
{
public:
/// These methods are for obtaining projection information from
/// EOS2 APIs.
/// Obtain projection code such as geographic projection or
/// sinusoidal projection.
int32 getCode () const
{
return this->code;
}
/// Obtain GCTP zone code used by UTM projection
int32 getZone () const
{
return this->zone;
}
/// Obtain GCTP spheriod code
int32 getSphere () const
{
return this->sphere;
}
/// Obtain GCTP projection parameter array from EOS API GDprojinfo
const float64 *getParam () const
{
return this->param;
}
/// Obtain pix registration code from EOS API GDpixreginfo
int32 getPix () const
{
return this->pix;
}
/// Obtain origin code from EOS API GDorigininfo
int32 getOrigin () const
{
return this->origin;
}
protected:
Projection() {
code = -1;
zone = -1;
sphere = -1;
pix = -1;
origin = -1;
}
private:
int32 code;
int32 zone;
int32 sphere;
float64 param[16];
int32 pix;
int32 origin;
friend class GridDataset;
};
/// This class holds corresponding calculated latitude and longitude
/// values of a grid field.
class Calculated
{
public:
/// We follow C-major convention. Normally YDim is major.
/// Sometimes it is not. .
bool isYDimMajor () throw (Exception);
/// The projection can be either 1-D or 2-D. For 1-D, the method
/// returns true. Otherwise, return false.
/// bool isOrthogonal () throw (Exception);
protected:
explicit Calculated (const GridDataset * eos_grid)
: grid (eos_grid), ydimmajor (false)
{
}
Calculated & operator= (const Calculated & victim)
{
if (this != &victim) {
this->grid = victim.grid;
this->ydimmajor = victim.ydimmajor;
}
return *this;
}
/// We follow C-major convention. Normally YDim is major. But
/// sometimes it is not. We have to check.
void DetectMajorDimension () throw (Exception);
/// Find a field and check which dimension is major for this field. If Y dimension is major, return 1; if X dimension is major, return 0, otherwise throw exception. (LD -2012/01/16)
int DetectFieldMajorDimension () throw (Exception);
private:
const GridDataset *grid;
bool ydimmajor;
friend class GridDataset;
friend class File;
};
public:
/// Read all information regarding this Grid.
static GridDataset *Read (int32 fd, const std::string & gridname) throw (Exception);
virtual ~ GridDataset ();
/// Return all information of Info class.
const Info & getInfo () const
{
return this->info;
}
/// Return all information of Projection class.
const Projection & getProjection () const
{
return this->proj;
}
/// Return all information of Calculated class.
Calculated & getCalculated () const;
/// set dimxname, "XDim" may be "LonDim" or "nlon"
void setDimxName (std::string dxname)
{
dimxname = dxname;
}
/// set dimyname, "YDim" may be "LatDim" or "nlat"
void setDimyName (std::string dyname)
{
dimyname = dyname;
}
/// Obtain the ownllflag info.
bool getLatLonFlag () const
{
return this->ownllflag;
}
private:
explicit GridDataset (const std::string & g_name)
: Dataset (g_name), calculated (0), ownllflag (false), iscoard (false)
{
latfield = NULL;
lonfield = NULL;
}
private:
/// Info consists of the sizes, lower right and upper left coordinates of the grid.
Info info;
/// Projection info. of the grid.
Projection proj;
/// A class to detect the dimension major etc. temp(YDim,XDim) or temp(XDim,YDim)
/// This is used to calculate the latitude and longitude
mutable Calculated calculated;
/// This flag is for AIRS level 3 data since the lat/lon for this product is under the geolocation grid.
bool ownllflag;
/// If this grid is following COARDS
bool iscoard;
/// Each grid has its own lat and lon. So separate them from the rest fields.
Field *latfield;
Field *lonfield;
/// Each grid has its own dimension names for latitude and longtiude. Also separate them from the rest fields.
std::string dimxname;
std::string dimyname;
friend class File;
};
class File;
/// This class retrieves and holds all information of an EOS swath.
/// The old way is to retrieve dimension map data in this class.
/// Now we put the way to handle the data in HDFEOS2ArraySwathDimMap.cc.
class SwathDataset:public Dataset