-
Notifications
You must be signed in to change notification settings - Fork 3
/
HDF5GMCF.cc
7125 lines (6014 loc) · 294 KB
/
HDF5GMCF.cc
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 hdf5_handler implementing for the CF-compliant
// Copyright (c) 2011-2016 The HDF Group, Inc. and OPeNDAP, Inc.
//
// This is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your
// option) any later version.
//
// This software is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
// You can contact The HDF Group, Inc. at 1800 South Oak Street,
// Suite 203, Champaign, IL 61820
/////////////////////////////////////////////////////////////////////////////
/// \file HDF5GMCF.cc
/// \brief Implementation of the mapping of NASA generic HDF5 products to DAP by following CF
///
/// It includes functions to
/// 1) retrieve HDF5 metadata info.
/// 2) translate HDF5 objects into DAP DDS and DAS by following CF conventions.
///
///
/// \author Muqun Yang <myang6@hdfgroup.org>
///
/// Copyright (C) 2011-2016 The HDF Group
///
/// All rights reserved.
#include "HDF5CF.h"
#include "HDF5RequestHandler.h"
#include "h5apicompatible.h"
#include <BESDebug.h>
#include <algorithm>
using namespace std;
using namespace libdap;
using namespace HDF5CF;
// Copier function.
GMCVar::GMCVar(Var*var) {
BESDEBUG("h5", "Coming to GMCVar()"<<endl);
newname = var->newname;
name = var->name;
fullpath = var->fullpath;
rank = var->rank;
total_elems = var->total_elems;
zero_storage_size = var->zero_storage_size;
dtype = var->dtype;
unsupported_attr_dtype = var->unsupported_attr_dtype;
unsupported_dspace = var->unsupported_dspace;
coord_attr_add_path = false;
for (vector<Attribute*>::iterator ira = var->attrs.begin();
ira!=var->attrs.end(); ++ira) {
Attribute* attr= new Attribute();
attr->name = (*ira)->name;
attr->newname = (*ira)->newname;
attr->dtype =(*ira)->dtype;
attr->count =(*ira)->count;
attr->strsize = (*ira)->strsize;
attr->fstrsize = (*ira)->fstrsize;
attr->value =(*ira)->value;
attrs.push_back(attr);
} //for (vector<Attribute*>::iterator ira = var->attrs.begin()
for (vector<Dimension*>::iterator ird = var->dims.begin();
ird!=var->dims.end(); ++ird) {
Dimension *dim = new Dimension((*ird)->size);
dim->name = (*ird)->name;
dim->newname = (*ird)->newname;
dim->unlimited_dim = (*ird)->unlimited_dim;
dims.push_back(dim);
} // for (vector<Dimension*>::iterator ird = var->dims.begin()
product_type = General_Product;
}
#if 0
GMCVar::GMCVar(GMCVar*cvar) {
newname = cvar->newname;
name = cvar->name;
fullpath = cvar->fullpath;
rank = cvar->rank;
dtype = cvar->dtype;
unsupported_attr_dtype = cvar->unsupported_attr_dtype;
unsupported_dspace = cvar->unsupported_dspace;
for (vector<Attribute*>::iterator ira = cvar->attrs.begin();
ira!=cvar->attrs.end(); ++ira) {
Attribute* attr= new Attribute();
attr->name = (*ira)->name;
attr->newname = (*ira)->newname;
attr->dtype =(*ira)->dtype;
attr->count =(*ira)->count;
attr->strsize = (*ira)->strsize;
attr->fstrsize = (*ira)->fstrsize;
attr->value =(*ira)->value;
attrs.push_back(attr);
}
for (vector<Dimension*>::iterator ird = cvar->dims.begin();
ird!=cvar->dims.end(); ++ird) {
Dimension *dim = new Dimension((*ird)->size);
//"h5","dim->name "<< (*ird)->name <<endl;
//"h5","dim->newname "<< (*ird)->newname <<endl;
dim->name = (*ird)->name;
dim->newname = (*ird)->newname;
dims.push_back(dim);
}
GMcvar->cfdimname = latdim0;
GMcvar->cvartype = CV_EXIST;
GMcvar->product_type = product_type;
}
#endif
//Copier function of a special variable.
GMSPVar::GMSPVar(Var*var) {
BESDEBUG("h5", "Coming to GMSPVar()"<<endl);
fullpath = var->fullpath;
rank = var->rank;
total_elems = var->total_elems;
zero_storage_size = var->zero_storage_size;
unsupported_attr_dtype = var->unsupported_attr_dtype;
unsupported_dspace = var->unsupported_dspace;
coord_attr_add_path = var->coord_attr_add_path;
// The caller of this function should change the following fields.
// This is just to make data coverity happy.
otype = H5UNSUPTYPE;
sdbit = -1;
numofdbits = -1;
for (vector<Attribute*>::iterator ira = var->attrs.begin();
ira!=var->attrs.end(); ++ira) {
Attribute* attr= new Attribute();
attr->name = (*ira)->name;
attr->newname = (*ira)->newname;
attr->dtype =(*ira)->dtype;
attr->count =(*ira)->count;
attr->strsize = (*ira)->strsize;
attr->fstrsize = (*ira)->fstrsize;
attr->value =(*ira)->value;
attrs.push_back(attr);
} // "for (vector<Attribute*>::iterator ira = var->attrs.begin()"
for (vector<Dimension*>::iterator ird = var->dims.begin();
ird!=var->dims.end(); ++ird) {
Dimension *dim = new Dimension((*ird)->size);
dim->name = (*ird)->name;
dim->newname = (*ird)->newname;
dim->unlimited_dim = (*ird)->unlimited_dim;
dims.push_back(dim);
}
}
GMFile::GMFile(const char*file_fullpath, hid_t file_id, H5GCFProduct product_type, GMPattern gproduct_pattern):
File(file_fullpath,file_id), product_type(product_type),gproduct_pattern(gproduct_pattern),iscoard(false),have_nc4_non_coord(false)
{
}
// destructor
GMFile::~GMFile()
{
if (!this->cvars.empty()){
for (vector<GMCVar *>:: const_iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i) {
delete *i;
}
}
if (!this->spvars.empty()){
for (vector<GMSPVar *>:: const_iterator i= this->spvars.begin(); i!=this->spvars.end(); ++i) {
delete *i;
}
}
}
// Get CF string
string GMFile::get_CF_string(string s) {
// HDF5 group or variable path always starts with '/'. When CF naming rule is applied,
// the first '/' is always changes to "_", this is not necessary. However,
// to keep the backward compatiablity, I use a BES key for people to go back with the original name.
if(s[0] !='/')
return File::get_CF_string(s);
else if (General_Product == product_type && OTHERGMS == gproduct_pattern) {
if(true == HDF5RequestHandler::get_keep_var_leading_underscore())
return File::get_CF_string(s);
else {
s.erase(0,1);
return File::get_CF_string(s);
}
}
else {
// The leading underscore should be removed from all supported products
s.erase(0,1);
return File::get_CF_string(s);
}
}
// Retrieve all the HDF5 information.
void GMFile::Retrieve_H5_Info(const char *file_fullpath,
hid_t file_id, bool include_attr) {
BESDEBUG("h5", "Coming to Retrieve_H5_Info()"<<endl);
// GPM needs the attribute info. to obtain the lat/lon.
// So set the include_attr to be true for these products.
if (product_type == Mea_SeaWiFS_L2 || product_type == Mea_SeaWiFS_L3
|| GPMS_L3 == product_type || GPMM_L3 == product_type || GPM_L1 == product_type || OBPG_L3 == product_type
|| Mea_Ozone == product_type || General_Product == product_type)
File::Retrieve_H5_Info(file_fullpath,file_id,true);
else
File::Retrieve_H5_Info(file_fullpath,file_id,include_attr);
}
// Update the product type. This is because the file structure may change across different versions of products
// I need to handle them differently and still support different versions. The goal is to support two versions in a row.
// Currently GPM level 3 is changed.
// This routine should be called right after Retrieve_H5_Info.
void GMFile::Update_Product_Type() {
BESDEBUG("h5", "Coming to Update_Product_Type()"<<endl);
if(GPMS_L3 == this->product_type || GPMM_L3 == this->product_type) {
// Check Dimscale attributes
//Check_General_Product_Pattern();
Check_Dimscale_General_Product_Pattern();
if(GENERAL_DIMSCALE == this->gproduct_pattern){
if(GPMS_L3 == this->product_type) {
for (vector<Var *>::iterator irv = this->vars.begin();
irv != this->vars.end(); ++irv)
(*irv)->newname = (*irv)->name;
}
this->product_type = General_Product;
}
}
//#if 0
else if(General_Product == this->product_type)
Check_General_Product_Pattern();
//#endif
}
void GMFile::Remove_Unneeded_Objects() {
BESDEBUG("h5", "Coming to Remove_Unneeded_Objects()"<<endl);
if(General_Product == this->product_type) {
string file_path = this->path;
if(HDF5CFUtil::obtain_string_after_lastslash(file_path).find("OMPS-NPP")==0)
Remove_OMPSNPP_InputPointers();
}
if((General_Product == this->product_type) && (GENERAL_DIMSCALE == this->gproduct_pattern)) {
set<string> nc4_non_coord_set;
string nc4_non_coord="_nc4_non_coord_";
size_t nc4_non_coord_size= nc4_non_coord.size();
for (vector<Var *>::iterator irv = this->vars.begin();
irv != this->vars.end(); ++irv) {
if((*irv)->name.find(nc4_non_coord)==0)
nc4_non_coord_set.insert((*irv)->name.substr(nc4_non_coord_size,(*irv)->name.size()-nc4_non_coord_size));
}
for (vector<Var *>::iterator irv = this->vars.begin();
irv != this->vars.end();) {
if(nc4_non_coord_set.find((*irv)->name)!=nc4_non_coord_set.end()){
delete(*irv);
irv=this->vars.erase(irv);
}
else
++irv;
}
if(nc4_non_coord_set.size()!=0)
this->have_nc4_non_coord = true;
}
else if(GPM_L3_New == this->product_type) {
for (vector<Group *>::iterator irg = this->groups.begin();
irg != this->groups.end(); ) {
if((*irg)->attrs.empty()) {
delete(*irg);
irg = this->groups.erase(irg);
}
else
++irg;
}
}
}
void GMFile::Remove_OMPSNPP_InputPointers() {
// Here I don't check whether this is a netCDF file by
// using Check_Dimscale_General_Product_Pattern() to see if it returns true.
// We will see if we need this.
for (vector<Group *>::iterator irg = this->groups.begin();
irg != this->groups.end(); ) {
if((*irg)->path.find("/InputPointers")==0) {
delete(*irg);
irg = this->groups.erase(irg);
}
else
++irg;
}
for (vector<Var *>::iterator irv = this->vars.begin();
irv != this->vars.end(); ) {
if((*irv)->fullpath.find("/InputPointers")==0) {
delete(*irv);
irv = this->vars.erase(irv);
}
else
++irv;
}
}
void GMFile::Retrieve_H5_CVar_Supported_Attr_Values() {
for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
ircv != this->cvars.end(); ++ircv) {
if ((*ircv)->cvartype != CV_NONLATLON_MISS){
for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
ira != (*ircv)->attrs.end(); ++ira) {
Retrieve_H5_Attr_Value(*ira,(*ircv)->fullpath);
}
}
}
}
// Retrieve HDF5 supported attribute values.
void GMFile::Retrieve_H5_Supported_Attr_Values() {
BESDEBUG("h5", "Coming to Retrieve_H5_Supported_Attr_Values()"<<endl);
// General attributes
File::Retrieve_H5_Supported_Attr_Values();
//Coordinate variable attributes
for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
ircv != this->cvars.end(); ++ircv) {
if ((*ircv)->cvartype != CV_NONLATLON_MISS){
for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
ira != (*ircv)->attrs.end(); ++ira) {
Retrieve_H5_Attr_Value(*ira,(*ircv)->fullpath);
}
}
}
// Special variable attributes
for (vector<GMSPVar *>::iterator irspv = this->spvars.begin();
irspv != this->spvars.end(); ++irspv) {
for (vector<Attribute *>::iterator ira = (*irspv)->attrs.begin();
ira != (*irspv)->attrs.end(); ++ira) {
Retrieve_H5_Attr_Value(*ira,(*irspv)->fullpath);
Adjust_H5_Attr_Value(*ira);
}
}
}
// Adjust attribute values. Currently this is only for ACOS and OCO2.
// Reason: DAP2 doesn't support 64-bit integer and they have 64-bit integer data
// in these files. Chop them to two 32-bit integers following the data producer's information.
void GMFile::Adjust_H5_Attr_Value(Attribute *attr) {
BESDEBUG("h5", "Coming to Adjust_H5_Attr_Value()"<<endl);
if (product_type == ACOS_L2S_OR_OCO2_L1B) {
if (("Type" == attr->name) && (H5VSTRING == attr->dtype)) {
string orig_attrvalues(attr->value.begin(),attr->value.end());
if (orig_attrvalues != "Signed64") return;
string new_attrvalues = "Signed32";
// Since the new_attrvalues size is the same as the orig_attrvalues size
// No need to adjust the strsize and fstrsize. KY 2011-2-1
attr->value.clear();
attr->value.resize(new_attrvalues.size());
copy(new_attrvalues.begin(),new_attrvalues.end(),attr->value.begin());
}
} // "end if (product_type == ACOS_L2S_OR_OCO2_L1B)"
}
// Unsupported datatype
void GMFile:: Handle_Unsupported_Dtype(bool include_attr) {
BESDEBUG("h5", "Coming to Handle_Unsupported_Dtype()"<<endl);
if(true == check_ignored) {
Gen_Unsupported_Dtype_Info(include_attr);
}
File::Handle_Unsupported_Dtype(include_attr);
Handle_GM_Unsupported_Dtype(include_attr);
}
// Unsupported datatype for general data products.
void GMFile:: Handle_GM_Unsupported_Dtype(bool include_attr) {
BESDEBUG("h5", "Coming to Handle_GM_Unsupported_Dtype()"<<endl);
for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
ircv != this->cvars.end(); ) {
if (true == include_attr) {
for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
ira != (*ircv)->attrs.end(); ) {
H5DataType temp_dtype = (*ira)->getType();
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
delete (*ira);
ira = (*ircv)->attrs.erase(ira);
}
else {
++ira;
}
}
}
H5DataType temp_dtype = (*ircv)->getType();
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
// This may need to be checked carefully in the future,
// My current understanding is that the coordinate variable can
// be ignored if the corresponding variable is ignored.
// Currently we don't find any NASA files in this category.
// KY 2012-5-21
delete (*ircv);
ircv = this->cvars.erase(ircv);
}
else {
++ircv;
}
} // for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
ircv != this->spvars.end(); ) {
if (true == include_attr) {
for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
ira != (*ircv)->attrs.end(); ) {
H5DataType temp_dtype = (*ira)->getType();
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
delete (*ira);
ira = (*ircv)->attrs.erase(ira);
}
else {
++ira;
}
}
}
H5DataType temp_dtype = (*ircv)->getType();
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
delete (*ircv);
ircv = this->spvars.erase(ircv);
}
else {
++ircv;
}
}// "end for (vector<GMSPVar *>::iterator ircv = this->spvars.begin()"
}
// Datatype ignore information.
void GMFile:: Gen_Unsupported_Dtype_Info(bool include_attr) {
BESDEBUG("h5", "GMFile::Coming to Gen_Unsupported_Dtype_Info()"<<endl);
if(true == include_attr) {
File::Gen_Group_Unsupported_Dtype_Info();
File::Gen_Var_Unsupported_Dtype_Info();
Gen_VarAttr_Unsupported_Dtype_Info();
}
}
// Datatype ignored information for variable ttributes
void GMFile:: Gen_VarAttr_Unsupported_Dtype_Info() {
BESDEBUG("h5", "GMFile::Coming to Gen_Unsupported_Dtype_Info()"<<endl);
// First general variables(non-CV and non-special variable) that use dimension scales.
if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
|| (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type) || (Mea_SeaWiFS_L3 == this->product_type)
|| (OBPG_L3 == this->product_type)) {
Gen_DimScale_VarAttr_Unsupported_Dtype_Info();
}
else
File::Gen_VarAttr_Unsupported_Dtype_Info();
// CV and special variables
Gen_GM_VarAttr_Unsupported_Dtype_Info();
}
// Generate ignored object,attribute information for the CVs and special variables of general supported products.
void GMFile:: Gen_GM_VarAttr_Unsupported_Dtype_Info(){
BESDEBUG("h5", "GMFile::Coming to Gen_GM_VarAttr_Unsupported_Dtype_Info()"<<endl);
if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
|| (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type) || (Mea_SeaWiFS_L3 == this->product_type)
|| (OBPG_L3 == this->product_type)) {
for (vector<GMCVar *>::iterator irv = this->cvars.begin();
irv != this->cvars.end(); ++irv) {
// If the attribute REFERENCE_LIST comes with the attribut CLASS, the
// attribute REFERENCE_LIST is okay to ignore. No need to report.
bool is_ignored = ignored_dimscale_ref_list((*irv));
if (false == (*irv)->attrs.empty()) {
for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end(); ++ira) {
H5DataType temp_dtype = (*ira)->getType();
// TODO: check why 64-bit integer is included here.
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
// "DIMENSION_LIST" is okay to ignore and "REFERENCE_LIST"
// is okay to ignore if the variable has another attribute
// CLASS="DIMENSION_SCALE"
if (("DIMENSION_LIST" !=(*ira)->name) &&
("REFERENCE_LIST" != (*ira)->name || true == is_ignored))
this->add_ignored_info_attrs(false,(*irv)->fullpath,(*ira)->name);
}
}
} // end "if (false == (*irv)->attrs.empty())"
}// end "for(vector<GMCVar*>"
for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
irv != this->spvars.end(); ++irv) {
// If the attribute REFERENCE_LIST comes with the attribut CLASS, the
// attribute REFERENCE_LIST is okay to ignore. No need to report.
bool is_ignored = ignored_dimscale_ref_list((*irv));
if (false == (*irv)->attrs.empty()) {
//if (true == (*irv)->unsupported_attr_dtype) {
for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end(); ++ira) {
H5DataType temp_dtype = (*ira)->getType();
//TODO; check why 64-bit integer is included here.
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
// "DIMENSION_LIST" is okay to ignore and "REFERENCE_LIST"
// is okay to ignore if the variable has another attribute
// CLASS="DIMENSION_SCALE"
if (("DIMENSION_LIST" !=(*ira)->name) &&
("REFERENCE_LIST" != (*ira)->name || true == is_ignored))
this->add_ignored_info_attrs(false,(*irv)->fullpath,(*ira)->name);
}
}
} // "if (false == (*irv)->attrs.empty())"
}// "for(vector<GMSPVar*>"
}// "if((General_Product == ......)"
else {
for (vector<GMCVar *>::iterator irv = this->cvars.begin();
irv != this->cvars.end(); ++irv) {
if (false == (*irv)->attrs.empty()) {
//if (true == (*irv)->unsupported_attr_dtype) {
for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end(); ++ira) {
H5DataType temp_dtype = (*ira)->getType();
// TODO: check why 64-bit integer is included here.
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
this->add_ignored_info_attrs(false,(*irv)->fullpath,(*ira)->name);
}
}
//}
}
}// for (vector<GMCVar *>::iterator irv = this->cvars.begin() STOP adding end logic comments
for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
irv != this->spvars.end(); ++irv) {
if (false == (*irv)->attrs.empty()) {
//if (true == (*irv)->unsupported_attr_dtype) {
for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end(); ++ira) {
H5DataType temp_dtype = (*ira)->getType();
//TODO: check why 64-bit integer is included here.
if (false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
this->add_ignored_info_attrs(false,(*irv)->fullpath,(*ira)->name);
}
}
//}
}
}// for(vector<GMSPVar *>
}// else
}
// Unsupported data space
void GMFile:: Handle_Unsupported_Dspace(bool include_attr) {
BESDEBUG("h5", "Coming to GMFile:Handle_Unsupported_Dspace()"<<endl);
if(true == check_ignored)
Gen_Unsupported_Dspace_Info();
File::Handle_Unsupported_Dspace(include_attr);
Handle_GM_Unsupported_Dspace(include_attr);
}
// Unsupported data space for coordinate variables and special variables of general products
void GMFile:: Handle_GM_Unsupported_Dspace(bool include_attr) {
BESDEBUG("h5", "Coming to GMFile:Handle_GM_Unsupported_Dspace()"<<endl);
if(true == this->unsupported_var_dspace) {
for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
ircv != this->cvars.end(); ) {
if (true == (*ircv)->unsupported_dspace ) {
// This may need to be checked carefully in the future,
// My current understanding is that the coordinate variable can
// be ignored if the corresponding variable is ignored.
// Currently we don't find any NASA files in this category.
// KY 2012-5-21
delete (*ircv);
ircv = this->cvars.erase(ircv);
}
else {
++ircv;
}
} // "for (vector<GMCVar *>::iterator ircv = this->cvars.begin();"
for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
ircv != this->spvars.end(); ) {
if (true == (*ircv)->unsupported_dspace) {
delete (*ircv);
ircv = this->spvars.erase(ircv);
}
else {
++ircv;
}
}// for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
}// if(true == this->unsupported_dspace)
if(true == include_attr) {
if(true == this->unsupported_var_attr_dspace) {
for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
ircv != this->cvars.end(); ++ircv) {
if (false == (*ircv)->attrs.empty()) {
if (true == (*ircv)->unsupported_attr_dspace) {
for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
ira != (*ircv)->attrs.end(); ) {
if (0 == (*ira)->count) {
delete (*ira);
ira = (*ircv)->attrs.erase(ira);
}
else {
++ira;
}
}
}
}
}
for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
ircv != this->spvars.end(); ++ircv) {
if (false == (*ircv)->attrs.empty()) {
if (true == (*ircv)->unsupported_attr_dspace) {
for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
ira != (*ircv)->attrs.end(); ) {
if (0 == (*ira)->count) {
delete (*ira);
ira = (*ircv)->attrs.erase(ira);
}
else {
++ira;
}
}
}
}
}
}// if(true == this->unsupported_var_attr_dspace)
}// if(true == include_attr)
}
// Generate unsupported data space information
void GMFile:: Gen_Unsupported_Dspace_Info() {
File::Gen_Unsupported_Dspace_Info();
}
// Handle other unsupported objects
void GMFile:: Handle_Unsupported_Others(bool include_attr) {
BESDEBUG("h5", "Coming to GMFile:Handle_Unsupported_Others()"<<endl);
File::Handle_Unsupported_Others(include_attr);
// Add the removal of CLASS=DIM_SCALE attribute if this is a netCDF-4-like attribute.
//
if(General_Product != this->product_type
|| (General_Product == this->product_type && OTHERGMS != this->gproduct_pattern)){
//
#if 0
if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
|| (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type)
|| (Mea_SeaWiFS_L3 == this->product_type)
|| (OBPG_L3 == this->product_type))
#endif
remove_netCDF_internal_attributes(include_attr);
if(include_attr == true) {
// We also need to remove the _nc3_strict from the root attributes
for (vector<Attribute *>::iterator ira = this->root_attrs.begin(); ira != this->root_attrs.end();) {
if((*ira)->name == "_nc3_strict") {
delete(*ira);
ira =this->root_attrs.erase(ira);
//If we have other root attributes to remove, remove the break statement.
}
else if((*ira)->name == "_NCProperties") {
delete(*ira);
ira =this->root_attrs.erase(ira);
}
else if((*ira)->name == "_Netcdf4Coordinates") {
delete(*ira);
ira =this->root_attrs.erase(ira);
}
else {
++ira;
}
}
for (vector<GMCVar *>::iterator irv = this->cvars.begin();
irv != this->cvars.end(); ++irv) {
for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end();) {
if((*ira)->name == "CLASS") {
string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
// Compare the attribute "CLASS" value with "DIMENSION_SCALE". We only compare the string with the size of
// "DIMENSION_SCALE", which is 15.
if (0 == class_value.compare(0,15,"DIMENSION_SCALE")) {
delete(*ira);
ira = (*irv)->attrs.erase(ira);
// Add another block to set a key
}
else {
++ira;
}
}
else if((*ira)->name == "NAME") {// Add a BES Key later
delete(*ira);
ira =(*irv)->attrs.erase(ira);
//"NAME" attribute causes the file netCDF-4 failed.
#if 0
string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
delete(*ira);
ira =(*irv)->attrs.erase(ira);
}
else {
string netcdf_dim_mark= "This is a netCDF dimension but not a netCDF variable";
if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
delete((*ira));
ira =(*irv)->attrs.erase(ira);
}
else {
++ira;
}
}
#endif
}
else if((*ira)->name == "_Netcdf4Dimid") {
delete(*ira);
ira =(*irv)->attrs.erase(ira);
}
else if((*ira)->name == "_Netcdf4Coordinates") {
delete(*ira);
ira =(*irv)->attrs.erase(ira);
}
#if 0
else if((*ira)->name == "_nc3_strict") {
delete((*ira));
ira =(*irv)->attrs.erase(ira);
}
#endif
else {
++ira;
}
}
}
}
}
// netCDF Java lifts the string size limitation. All the string attributes can be
// represented by netCDF Java. So comment out the code. KY 2018/08/10
#if 0
if(true == this->check_ignored && true == include_attr) {
if(true == HDF5RequestHandler::get_drop_long_string()){
for (vector<GMCVar *>::iterator irv = this->cvars.begin();
irv != this->cvars.end(); ++irv) {
for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end();++ira) {
if(true == Check_DropLongStr((*irv),(*ira))) {
this->add_ignored_droplongstr_hdr();
this->add_ignored_var_longstr_info((*irv),(*ira));
}
}
}
for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
irv != this->spvars.end(); ++irv) {
for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
ira != (*irv)->attrs.end();++ira) {
if(true == Check_DropLongStr((*irv),(*ira))) {
this->add_ignored_droplongstr_hdr();
this->add_ignored_var_longstr_info((*irv),(*ira));
}
}
}
}
}
#endif
if(false == this->have_ignored)
this->add_no_ignored_info();
}
// Add dimension names
void GMFile::Add_Dim_Name() {
BESDEBUG("h5", "Coming to GMFile:Add_Dim_Name()"<<endl);
switch(product_type) {
case Mea_SeaWiFS_L2:
case Mea_SeaWiFS_L3:
Add_Dim_Name_Mea_SeaWiFS();
break;
case Aqu_L3:
Add_Dim_Name_Aqu_L3();
break;
case OSMAPL2S:
Add_Dim_Name_OSMAPL2S();
break;
case ACOS_L2S_OR_OCO2_L1B:
Add_Dim_Name_ACOS_L2S_OCO2_L1B();
break;
case Mea_Ozone:
Add_Dim_Name_Mea_Ozonel3z();
break;
case GPMS_L3:
case GPMM_L3:
case GPM_L1:
case GPM_L3_New:
Add_Dim_Name_GPM();
break;
case OBPG_L3:
Add_Dim_Name_OBPG_L3();
break;
case General_Product:
Add_Dim_Name_General_Product();
break;
default:
throw1("Cannot generate dim. names for unsupported datatype");
} // switch(product_type)
// Just for debugging
#if 0
for (vector<Var*>::iterator irv2 = this->vars.begin();
irv2 != this->vars.end(); irv2++) {
for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
ird !=(*irv2)->dims.end(); ird++) {
cerr<<"Dimension name afet Add_Dim_Name "<<(*ird)->newname <<endl;
}
}
#endif
}
//Add Dim. Names for OBPG level 3 product
void GMFile::Add_Dim_Name_OBPG_L3() {
BESDEBUG("h5", "Coming to Add_Dim_Name_OBPG_L3()"<<endl);
// netCDF-4 like structure
// Note: We need to change the product type to netCDF-4 like product type and pattern.
Check_General_Product_Pattern();
Add_Dim_Name_General_Product();
}
//Add Dim. Names for MeaSures SeaWiFS. Future: May combine with the handling of netCDF-4 products
void GMFile::Add_Dim_Name_Mea_SeaWiFS() {
BESDEBUG("h5", "Coming to Add_Dim_Name_Mea_SeaWiFS()"<<endl);
pair<set<string>::iterator,bool> setret;
if (Mea_SeaWiFS_L3 == product_type)
iscoard = true;
for (vector<Var *>::iterator irv = this->vars.begin();
irv != this->vars.end(); ++irv) {
Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
ird !=(*irv)->dims.end();++ird) {
setret = dimnamelist.insert((*ird)->name);
if (true == setret.second)
Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
}
} // for (vector<Var *>::iterator irv = this->vars.begin();
if (true == dimnamelist.empty())
throw1("This product should have the dimension names, but no dimension names are found");
}
// Handle Dimension scales for MEasUREs SeaWiFS and OZone.
void GMFile::Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(Var* var)
{
BESDEBUG("h5", "Coming to Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
Attribute* dimlistattr = NULL;
bool has_dimlist = false;
bool has_class = false;
bool has_reflist = false;
for(vector<Attribute *>::iterator ira = var->attrs.begin();
ira != var->attrs.end();ira++) {
if ("DIMENSION_LIST" == (*ira)->name) {
dimlistattr = *ira;
has_dimlist = true;
}
if ("CLASS" == (*ira)->name)
has_class = true;
if ("REFERENCE_LIST" == (*ira)->name)
has_reflist = true;
if (true == has_dimlist)
break;
if (true == has_class && true == has_reflist)
break;
} // for(vector<Attribute *>::iterator ira = var->attrs.begin(); ...
if (true == has_dimlist)
Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(var,dimlistattr);
// Dim name is the same as the variable name for dimscale variable
else if(true == has_class && true == has_reflist) {
if (var->dims.size() !=1)
throw2("dimension scale dataset must be 1 dimension, this is not true for variable ",
var->name);
// The var name is the object name, however, we would like the dimension name to be full path.
// so that the dim name can be served as the key for future handling.
(var->dims)[0]->name = var->fullpath;
(var->dims)[0]->newname = var->fullpath;
pair<set<string>::iterator,bool> setret;
setret = dimnamelist.insert((var->dims)[0]->name);
if (true == setret.second)
Insert_One_NameSizeMap_Element((var->dims)[0]->name,(var->dims)[0]->size,(var->dims)[0]->unlimited_dim);
}
// No dimension, add fake dim names, this may never happen for MeaSure
// but just for coherence and completeness.
// For Fake dimesnion
else {
set<hsize_t> fakedimsize;
pair<set<hsize_t>::iterator,bool> setsizeret;
for (vector<Dimension *>::iterator ird= var->dims.begin();
ird != var->dims.end(); ++ird) {
Add_One_FakeDim_Name(*ird);
setsizeret = fakedimsize.insert((*ird)->size);
if (false == setsizeret.second)
Adjust_Duplicate_FakeDim_Name(*ird);
}
// Just for debugging
#if 0
for (int i = 0; i < var->dims.size(); ++i) {
Add_One_FakeDim_Name((var->dims)[i]);
bool gotoMainLoop = false;
for (int j =i-1; j>=0 && !gotoMainLoop; --j) {
if (((var->dims)[i])->size == ((var->dims)[j])->size){
Adjust_Duplicate_FakeDim_Name((var->dims)[i]);
gotoMainLoop = true;
}
}
}
#endif
}//end of else
}
// Helper function to support dimensions of MeaSUrES SeaWiFS and OZone products
void GMFile::Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(Var *var,Attribute*dimlistattr)
{
BESDEBUG("h5", "Coming to Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
ssize_t objnamelen = -1;
hobj_ref_t rbuf;
vector<hvl_t> vlbuf;