14#include <libdap/debug.h>
15#include <libdap/InternalErr.h>
20#include "HDFEOS2Array_RealField.h"
22#include "HDF4RequestHandler.h"
27#define SIGNED_BYTE_TO_INT32 1
30HDFEOS2Array_RealField::read ()
33 BESDEBUG(
"h4",
"Coming to HDFEOS2_Array_RealField read "<<endl);
37 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
49 nelms = format_constraint (offset.data(), step.data(), count.data());
52 vector<int32>offset32;
53 offset32.resize(rank);
60 for (
int i = 0; i < rank; i++) {
61 offset32[i] = offset[i];
62 count32[i] = count[i];
67 int32 (*openfunc) (
char *, intn);
68 intn (*closefunc) (int32);
69 int32 (*attachfunc) (int32,
char *);
70 intn (*detachfunc) (int32);
71 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
74 if (swathname ==
"") {
77 attachfunc = GDattach;
78 detachfunc = GDdetach;
79 fieldinfofunc = GDfieldinfo;
80 datasetname = gridname;
82 else if (gridname ==
"") {
85 attachfunc = SWattach;
86 detachfunc = SWdetach;
87 fieldinfofunc = SWfieldinfo;
88 datasetname = swathname;
91 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
97 if (
true == isgeofile ||
false == check_pass_fileid_key) {
100 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
103 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
104 throw InternalErr (__FILE__, __LINE__, eherr.str ());
111 gridid = attachfunc (gfid,
const_cast < char *
>(datasetname.c_str ()));
115 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be attached.";
116 throw InternalErr (__FILE__, __LINE__, eherr.str ());
119 bool is_modis_l1b =
false;
120 if(
"MODIS_SWATH_Type_L1B" == swathname)
123 bool is_modis_vip =
false;
124 if (
"VIP_CMG_GRID" == gridname)
127 bool field_is_vdata =
false;
138 char tmp_dimlist[1024];
139 int32 tmp_dims[rank];
140 int32 field_dtype = 0;
143 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
144 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
150 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
151 throw InternalErr (__FILE__, __LINE__, eherr.str ());
155 field_is_vdata =
true;
159 bool has_Key_attr =
false;
161 if (
false == field_is_vdata) {
166 if (
true == isgeofile ||
false == check_pass_fileid_key) {
168 sdfileid = SDstart(filename.c_str (), DFACC_READ);
170 if (FAIL == sdfileid) {
174 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
182 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
183 if (FAIL == sdsindex) {
187 eherr <<
"Cannot obtain the index of " << fieldname;
188 throw InternalErr (__FILE__, __LINE__, eherr.str ());
191 sdsid = SDselect(sdfileid, sdsindex);
196 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
197 throw InternalErr (__FILE__, __LINE__, eherr.str ());
206 if(SDfindattr(sdsid,
"Key")!=FAIL)
211 if (
true == isgeofile ||
false == check_pass_fileid_key)
217 if((
false == is_modis_l1b) && (
false == is_modis_vip)
218 &&(
false == has_Key_attr) && (
true == HDF4RequestHandler::get_disable_scaleoffset_comp()))
219 write_dap_data_disable_scale_comp(gridid,nelms,offset32.data(),count32.data(),step32.data());
221 write_dap_data_scale_comp(gridid,nelms,offset32,count32,step32);
230 r = detachfunc (gridid);
234 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
235 throw InternalErr (__FILE__, __LINE__, eherr.str ());
239 if(
true == isgeofile ||
false == check_pass_fileid_key) {
240 r = closefunc (gfid);
243 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
244 throw InternalErr (__FILE__, __LINE__, eherr.str ());
252HDFEOS2Array_RealField::write_dap_data_scale_comp(int32 gridid,
254 vector<int32>& offset32,
255 vector<int32>& count32,
256 vector<int32>& step32) {
260 "coming to HDFEOS2Array_RealField write_dap_data_scale_comp "
263 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
266 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
267 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
270 if (swathname ==
"") {
271 fieldinfofunc = GDfieldinfo;
272 readfieldfunc = GDreadfield;
274 else if (gridname ==
"") {
275 fieldinfofunc = SWfieldinfo;
276 readfieldfunc = SWreadfield;
279 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
283 char tmp_dimlist[1024];
286 int32 tmp_dims[rank];
289 int32 field_dtype = 0;
296 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
297 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
301 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
302 throw InternalErr (__FILE__, __LINE__, eherr.str ());
312 float *reflectance_offsets =
nullptr;
313 float *reflectance_scales =
nullptr;
314 float *radiance_offsets =
nullptr;
315 float *radiance_scales =
nullptr;
318 int32 attr_dtype = 0;
321 int32 temp_attrcount = 0;
324 int32 num_eles_of_an_attr = 0;
327 int32 cf_modl1b_rr_attrindex = 0;
330 int32 cf_modl1b_rr_attrindex2 = 0;
333 int32 cf_vr_attrindex = 0;
336 int32 cf_fv_attrindex = 0;
339 int32 scale_factor_attr_index = 0;
342 int32 add_offset_attr_index = 0;
348 float field_offset = 0;
354 float orig_valid_min = 0;
357 float orig_valid_max = 0;
364 bool has_Key_attr =
false;
367 if(sotype!=DEFAULT_CF_EQU) {
369 bool field_is_vdata =
false;
382 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
383 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
386 eherr <<
"Field " << fieldname.c_str ()
387 <<
" information cannot be obtained.";
388 throw InternalErr (__FILE__, __LINE__, eherr.str ());
392 field_is_vdata =
true;
396r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
397 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
401 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
402 throw InternalErr (__FILE__, __LINE__, eherr.str ());
405cerr<<
"tmp_rank is "<<tmp_rank <<endl;
416 if(
false == field_is_vdata) {
418 char attrname[H4_MAX_NC_NAME + 1];
419 vector<char> attrbuf;
422 if(
false == isgeofile ||
false == check_pass_fileid_key)
425 sdfileid = SDstart(filename.c_str (), DFACC_READ);
426 if (FAIL == sdfileid) {
428 eherr <<
"Cannot Start the SD interface for the file "
430 throw InternalErr (__FILE__, __LINE__, eherr.str ());
436 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
437 if (FAIL == sdsindex) {
438 if(
true == isgeofile ||
false == check_pass_fileid_key)
441 eherr <<
"Cannot obtain the index of " << fieldname;
442 throw InternalErr (__FILE__, __LINE__, eherr.str ());
445 sdsid = SDselect(sdfileid, sdsindex);
447 if (
true == isgeofile ||
false == check_pass_fileid_key)
450 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
451 throw InternalErr (__FILE__, __LINE__, eherr.str ());
455 char attrname[H4_MAX_NC_NAME + 1];
456 vector<char> attrbuf, attrbuf2;
463 cf_general_attrindex = SDfindattr(sdsid,
"radiance_scales");
464 cf_general_attrindex2 = SDfindattr(sdsid,
"radiance_offsets");
467 if(cf_general_attrindex!=FAIL && cf_general_attrindex2!=FAIL)
470 ret = SDattrinfo(sdsid, cf_general_attrindex, attrname, &attr_dtype, &temp_attrcount);
474 if(
true == isgeofile)
477 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
478 throw InternalErr (__FILE__, __LINE__, eherr.str ());
481 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
482 ret = SDreadattr(sdsid, cf_general_attrindex, (VOIDP)attrbuf.data());
485 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
487 if (
true == isgeofile)
490 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
491 throw InternalErr (__FILE__, __LINE__, eherr.str ());
493 ret = SDattrinfo(sdsid, cf_general_attrindex2, attrname, &attr_dtype, &temp_attrcount);
496 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
498 if(
true == isgeofile)
501 eherr <<
"Attribute 'radiance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
502 throw InternalErr (__FILE__, __LINE__, eherr.str ());
505 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
506 ret = SDreadattr(sdsid, cf_general_attrindex2, (VOIDP)attrbuf2.data());
509 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
511 if(
true == isgeofile)
514 eherr <<
"Attribute 'radiance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
515 throw InternalErr (__FILE__, __LINE__, eherr.str ());
522#define GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
525 CAST *ptr = (CAST*)attrbuf.data(); \
526 CAST *ptr2 = (CAST*)attrbuf2.data(); \
527 radiance_scales = new float[temp_attrcount]; \
528 radiance_offsets = new float[temp_attrcount]; \
529 for(int l=0; l<temp_attrcount; l++) \
531 radiance_scales[l] = ptr[l]; \
532 radiance_offsets[l] = ptr2[l]; \
536 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
537 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
539#undef GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES
540 num_eles_of_an_attr = temp_attrcount;
544 cf_general_attrindex = SDfindattr(sdsid,
"reflectance_scales");
545 cf_general_attrindex2 = SDfindattr(sdsid,
"reflectance_offsets");
546 if(cf_general_attrindex!=FAIL && cf_general_attrindex2!=FAIL)
549 ret = SDattrinfo(sdsid, cf_general_attrindex, attrname, &attr_dtype, &temp_attrcount);
552 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
554 if(
true == isgeofile)
557 eherr <<
"Attribute 'reflectance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
558 throw InternalErr (__FILE__, __LINE__, eherr.str ());
561 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
562 ret = SDreadattr(sdsid, cf_general_attrindex, (VOIDP)attrbuf.data());
565 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
567 if(
true == isgeofile)
570 eherr <<
"Attribute 'reflectance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
571 throw InternalErr (__FILE__, __LINE__, eherr.str ());
574 ret = SDattrinfo(sdsid, cf_general_attrindex2, attrname, &attr_dtype, &temp_attrcount);
577 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
579 if(
true == isgeofile)
582 eherr <<
"Attribute 'reflectance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
583 throw InternalErr (__FILE__, __LINE__, eherr.str ());
586 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
587 ret = SDreadattr(sdsid, cf_general_attrindex2, (VOIDP)attrbuf2.data());
590 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
592 if(
true == isgeofile)
595 eherr <<
"Attribute 'reflectance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
596 throw InternalErr (__FILE__, __LINE__, eherr.str ());
600#define GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
603 CAST *ptr = (CAST*)attrbuf.data(); \
604 CAST *ptr2 = (CAST*)attrbuf2.data(); \
605 reflectance_scales = new float[temp_attrcount]; \
606 reflectance_offsets = new float[temp_attrcount]; \
607 for(int l=0; l<temp_attrcount; l++) \
609 reflectance_scales[l] = ptr[l]; \
610 reflectance_offsets[l] = ptr2[l]; \
614 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
615 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
617#undef GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES
618 num_eles_of_an_attr = temp_attrcount;
623 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
624 if(scale_factor_attr_index!=FAIL)
627 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname,
628 &attr_dtype, &temp_attrcount);
632 if(
true == isgeofile ||
false == check_pass_fileid_key)
635 eherr <<
"Attribute 'scale_factor' in "
636 << fieldname.c_str () <<
" cannot be obtained.";
637 throw InternalErr (__FILE__, __LINE__, eherr.str ());
640 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
641 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)attrbuf.data());
645 if(
true == isgeofile ||
false == check_pass_fileid_key)
649 eherr <<
"Attribute 'scale_factor' in "
650 << fieldname.c_str () <<
" cannot be obtained.";
651 throw InternalErr (__FILE__, __LINE__, eherr.str ());
656#define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
659 CAST tmpvalue = *(CAST*)attrbuf.data(); \
660 scale = (float)tmpvalue; \
663 GET_SCALE_FACTOR_ATTR_VALUE(INT8, int8)
664 GET_SCALE_FACTOR_ATTR_VALUE(CHAR,int8)
665 GET_SCALE_FACTOR_ATTR_VALUE(UINT8, uint8)
666 GET_SCALE_FACTOR_ATTR_VALUE(UCHAR,uint8)
667 GET_SCALE_FACTOR_ATTR_VALUE(INT16, int16)
668 GET_SCALE_FACTOR_ATTR_VALUE(UINT16, uint16)
669 GET_SCALE_FACTOR_ATTR_VALUE(INT32, int32)
670 GET_SCALE_FACTOR_ATTR_VALUE(UINT32, uint32)
671 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float)
672 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double)
674 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
678#undef GET_SCALE_FACTOR_ATTR_VALUE
682 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
683 if(add_offset_attr_index!=FAIL)
686 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname,
687 &attr_dtype, &temp_attrcount);
691 if(
true == isgeofile ||
false == check_pass_fileid_key)
695 eherr <<
"Attribute 'add_offset' in " << fieldname.c_str ()
696 <<
" cannot be obtained.";
697 throw InternalErr (__FILE__, __LINE__, eherr.str ());
700 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
701 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)attrbuf.data());
705 if(
true == isgeofile ||
false == check_pass_fileid_key)
709 eherr <<
"Attribute 'add_offset' in " << fieldname.c_str ()
710 <<
" cannot be obtained.";
711 throw InternalErr (__FILE__, __LINE__, eherr.str ());
716#define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
719 CAST tmpvalue = *(CAST*)attrbuf.data(); \
720 field_offset = (float)tmpvalue; \
723 GET_ADD_OFFSET_ATTR_VALUE(INT8, int8)
724 GET_ADD_OFFSET_ATTR_VALUE(CHAR,int8)
725 GET_ADD_OFFSET_ATTR_VALUE(UINT8, uint8)
726 GET_ADD_OFFSET_ATTR_VALUE(UCHAR,uint8)
727 GET_ADD_OFFSET_ATTR_VALUE(INT16, int16)
728 GET_ADD_OFFSET_ATTR_VALUE(UINT16, uint16)
729 GET_ADD_OFFSET_ATTR_VALUE(INT32, int32)
730 GET_ADD_OFFSET_ATTR_VALUE(UINT32, uint32)
731 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float)
732 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double)
734 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
737#undef GET_ADD_OFFSET_ATTR_VALUE
741 cf_fv_attrindex = SDfindattr(sdsid,
"_FillValue");
742 if(cf_fv_attrindex!=FAIL)
745 ret = SDattrinfo(sdsid, cf_fv_attrindex, attrname, &attr_dtype, &temp_attrcount);
749 if(
true == isgeofile ||
false == check_pass_fileid_key)
753 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
754 <<
" cannot be obtained.";
755 throw InternalErr (__FILE__, __LINE__, eherr.str ());
758 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
759 ret = SDreadattr(sdsid, cf_fv_attrindex, (VOIDP)attrbuf.data());
763 if(
true == isgeofile ||
false == check_pass_fileid_key)
767 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
768 <<
" cannot be obtained.";
769 throw InternalErr (__FILE__, __LINE__, eherr.str ());
774#define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
777 CAST tmpvalue = *(CAST*)attrbuf.data(); \
778 fillvalue = (float)tmpvalue; \
781 GET_FILLVALUE_ATTR_VALUE(INT8, int8)
782 GET_FILLVALUE_ATTR_VALUE(CHAR, int8)
783 GET_FILLVALUE_ATTR_VALUE(INT16, int16)
784 GET_FILLVALUE_ATTR_VALUE(INT32, int32)
785 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8)
786 GET_FILLVALUE_ATTR_VALUE(UCHAR, uint8)
787 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16)
788 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32)
790 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
793#undef GET_FILLVALUE_ATTR_VALUE
799 cf_vr_attrindex = SDfindattr(sdsid,
"valid_range");
800 if(cf_vr_attrindex!=FAIL)
803 ret = SDattrinfo(sdsid, cf_vr_attrindex, attrname, &attr_dtype, &temp_attrcount);
807 if(
true == isgeofile ||
false == check_pass_fileid_key)
811 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
812 <<
" cannot be obtained.";
813 throw InternalErr (__FILE__, __LINE__, eherr.str ());
816 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
817 ret = SDreadattr(sdsid, cf_vr_attrindex, (VOIDP)attrbuf.data());
821 if(
true == isgeofile ||
false == check_pass_fileid_key)
825 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
826 <<
" cannot be obtained.";
827 throw InternalErr (__FILE__, __LINE__, eherr.str ());
831 string attrbuf_str(attrbuf.begin(),attrbuf.end());
839 size_t found = attrbuf_str.find_first_of(
",");
840 size_t found_from_end = attrbuf_str.find_last_of(
",");
842 if (string::npos == found){
844 if(
true == isgeofile ||
false == check_pass_fileid_key)
846 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
848 if (found != found_from_end){
850 if(
true == isgeofile ||
false == check_pass_fileid_key)
852 throw InternalErr(__FILE__,__LINE__,
853 "Only one separator , should be available.");
861 orig_valid_min = (float)(atof((attrbuf_str.substr(0,found)).c_str()));
862 orig_valid_max = (float)(atof((attrbuf_str.substr(found+1)).c_str()));
876 if (temp_attrcount >2) {
878 size_t found = attrbuf_str.find_first_of(
",");
879 size_t found_from_end = attrbuf_str.find_last_of(
",");
881 if (string::npos == found){
883 if(
true == isgeofile ||
false == check_pass_fileid_key)
885 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
887 if (found != found_from_end){
889 if(
true == isgeofile ||
false == check_pass_fileid_key)
891 throw InternalErr(__FILE__,__LINE__,
892 "Only one separator , should be available.");
900 orig_valid_min = (float)(atof((attrbuf_str.substr(0,found)).c_str()));
901 orig_valid_max = (float)(atof((attrbuf_str.substr(found+1)).c_str()));
904 else if (2 == temp_attrcount) {
905 orig_valid_min = (float)attrbuf[0];
906 orig_valid_max = (float)attrbuf[1];
910 if(
true == isgeofile ||
false == check_pass_fileid_key)
912 throw InternalErr(__FILE__,__LINE__,
913 "The number of attribute count should be greater than 1.");
922 if (temp_attrcount != 2) {
924 if(
true == isgeofile ||
false == check_pass_fileid_key)
927 throw InternalErr(__FILE__,__LINE__,
928 "The number of attribute count should be 2 for the DFNT_UINT8 type.");
931 auto temp_valid_range = (
unsigned char *)attrbuf.data();
932 orig_valid_min = (float)(temp_valid_range[0]);
933 orig_valid_max = (float)(temp_valid_range[1]);
939 if (temp_attrcount != 2) {
941 if(
true == isgeofile ||
false == check_pass_fileid_key)
944 throw InternalErr(__FILE__,__LINE__,
945 "The number of attribute count should be 2 for the DFNT_INT16 type.");
948 auto temp_valid_range = (
short *)attrbuf.data();
949 orig_valid_min = (float)(temp_valid_range[0]);
950 orig_valid_max = (float)(temp_valid_range[1]);
956 if (temp_attrcount != 2) {
958 if(
true == isgeofile ||
false == check_pass_fileid_key)
961 throw InternalErr(__FILE__,__LINE__,
962 "The number of attribute count should be 2 for the DFNT_UINT16 type.");
965 auto temp_valid_range = (
unsigned short *)attrbuf.data();
966 orig_valid_min = (float)(temp_valid_range[0]);
967 orig_valid_max = (float)(temp_valid_range[1]);
973 if (temp_attrcount != 2) {
975 if(
true == isgeofile ||
false == check_pass_fileid_key)
978 throw InternalErr(__FILE__,__LINE__,
979 "The number of attribute count should be 2 for the DFNT_INT32 type.");
982 auto temp_valid_range = (
int *)attrbuf.data();
983 orig_valid_min = (float)(temp_valid_range[0]);
984 orig_valid_max = (float)(temp_valid_range[1]);
990 if (temp_attrcount != 2) {
992 if(
true == isgeofile ||
false == check_pass_fileid_key)
995 throw InternalErr(__FILE__,__LINE__,
996 "The number of attribute count should be 2 for the DFNT_UINT32 type.");
999 auto temp_valid_range = (
unsigned int *)attrbuf.data();
1000 orig_valid_min = (float)(temp_valid_range[0]);
1001 orig_valid_max = (float)(temp_valid_range[1]);
1007 if (temp_attrcount != 2) {
1009 if(
true == isgeofile ||
false == check_pass_fileid_key)
1012 throw InternalErr(__FILE__,__LINE__,
1013 "The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
1016 auto temp_valid_range = (
float *)attrbuf.data();
1017 orig_valid_min = temp_valid_range[0];
1018 orig_valid_max = temp_valid_range[1];
1024 if (temp_attrcount != 2){
1026 if(
true == isgeofile ||
false == check_pass_fileid_key)
1029 throw InternalErr(__FILE__,__LINE__,
1030 "The number of attribute count should be 2 for the DFNT_FLOAT64 type.");
1032 auto temp_valid_range = (
double *)attrbuf.data();
1039 orig_valid_min = temp_valid_range[0];
1040 orig_valid_max = temp_valid_range[1];
1045 if(
true == isgeofile ||
false == check_pass_fileid_key)
1047 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
1057 int32 cf_mod_key_attrindex = SUCCEED;
1058 cf_mod_key_attrindex = SDfindattr(sdsid,
"Key");
1059 if(cf_mod_key_attrindex !=FAIL) {
1060 has_Key_attr =
true;
1064 vector<char> attrbuf2;
1072 cf_modl1b_rr_attrindex = SDfindattr(sdsid,
"radiance_scales");
1073 cf_modl1b_rr_attrindex2 = SDfindattr(sdsid,
"radiance_offsets");
1076 if(cf_modl1b_rr_attrindex!=FAIL && cf_modl1b_rr_attrindex2!=FAIL)
1079 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex, attrname,
1080 &attr_dtype, &temp_attrcount);
1084 if(
true == isgeofile ||
false == check_pass_fileid_key)
1086 ostringstream eherr;
1087 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str ()
1088 <<
" cannot be obtained.";
1089 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1092 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1093 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex, (VOIDP)attrbuf.data());
1097 if (
true == isgeofile ||
false == check_pass_fileid_key)
1099 ostringstream eherr;
1100 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str ()
1101 <<
" cannot be obtained.";
1102 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1104 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex2, attrname,
1105 &attr_dtype, &temp_attrcount);
1109 if(
true == isgeofile ||
false == check_pass_fileid_key)
1111 ostringstream eherr;
1112 eherr <<
"Attribute 'radiance_offsets' in "
1113 << fieldname.c_str () <<
" cannot be obtained.";
1114 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1117 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1118 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex2, (VOIDP)attrbuf2.data());
1122 if(
true == isgeofile ||
false == check_pass_fileid_key)
1124 ostringstream eherr;
1125 eherr <<
"Attribute 'radiance_offsets' in "
1126 << fieldname.c_str () <<
" cannot be obtained.";
1127 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1135#define GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
1138 CAST *ptr = (CAST*)attrbuf.data(); \
1139 CAST *ptr2 = (CAST*)attrbuf2.data(); \
1140 radiance_scales = new float[temp_attrcount]; \
1141 radiance_offsets = new float[temp_attrcount]; \
1142 for(int l=0; l<temp_attrcount; l++) \
1144 radiance_scales[l] = ptr[l]; \
1145 radiance_offsets[l] = ptr2[l]; \
1149 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float)
1150 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double)
1152 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1155#undef GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES
1157 num_eles_of_an_attr = temp_attrcount;
1162 cf_modl1b_rr_attrindex = SDfindattr(sdsid,
"reflectance_scales");
1163 cf_modl1b_rr_attrindex2 = SDfindattr(sdsid,
"reflectance_offsets");
1164 if(cf_modl1b_rr_attrindex!=FAIL && cf_modl1b_rr_attrindex2!=FAIL)
1167 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex, attrname,
1168 &attr_dtype, &temp_attrcount);
1171 release_mod1b_res(reflectance_scales,reflectance_offsets,
1172 radiance_scales,radiance_offsets);
1174 if(
true == isgeofile ||
false == check_pass_fileid_key)
1176 ostringstream eherr;
1177 eherr <<
"Attribute 'reflectance_scales' in "
1178 << fieldname.c_str () <<
" cannot be obtained.";
1179 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1182 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1183 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex, (VOIDP)attrbuf.data());
1186 release_mod1b_res(reflectance_scales,reflectance_offsets,
1187 radiance_scales,radiance_offsets);
1189 if(
true == isgeofile ||
false == check_pass_fileid_key)
1191 ostringstream eherr;
1192 eherr <<
"Attribute 'reflectance_scales' in "
1193 << fieldname.c_str () <<
" cannot be obtained.";
1194 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1197 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex2, attrname,
1198 &attr_dtype, &temp_attrcount);
1201 release_mod1b_res(reflectance_scales,reflectance_offsets,
1202 radiance_scales,radiance_offsets);
1204 if(
true == isgeofile ||
false == check_pass_fileid_key)
1206 ostringstream eherr;
1207 eherr <<
"Attribute 'reflectance_offsets' in "
1208 << fieldname.c_str () <<
" cannot be obtained.";
1209 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1212 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1213 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex2, (VOIDP)attrbuf2.data());
1216 release_mod1b_res(reflectance_scales,reflectance_offsets,
1217 radiance_scales,radiance_offsets);
1219 if(
true == isgeofile ||
false == check_pass_fileid_key)
1221 ostringstream eherr;
1222 eherr <<
"Attribute 'reflectance_offsets' in "
1223 << fieldname.c_str () <<
" cannot be obtained.";
1224 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1228#define GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
1231 CAST *ptr = (CAST*)attrbuf.data(); \
1232 CAST *ptr2 = (CAST*)attrbuf2.data(); \
1233 reflectance_scales = new float[temp_attrcount]; \
1234 reflectance_offsets = new float[temp_attrcount]; \
1235 for(int l=0; l<temp_attrcount; l++) \
1237 reflectance_scales[l] = ptr[l]; \
1238 reflectance_offsets[l] = ptr2[l]; \
1242 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float)
1243 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double)
1245 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1248#undef GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES
1249 num_eles_of_an_attr = temp_attrcount;
1254 BESDEBUG(
"h4",
"scale is "<<scale <<endl);
1255 BESDEBUG(
"h4",
"offset is "<<field_offset <<endl);
1256 BESDEBUG(
"h4",
"fillvalue is "<<fillvalue <<endl);
1285 if (MODIS_EQ_SCALE == sotype || MODIS_MUL_SCALE == sotype) {
1287 bool need_change_scale =
true;
1290 string temp_filename;
1291 if (filename.find(
"#") != string::npos)
1292 temp_filename =filename.substr(filename.find_last_of(
"#") + 1);
1294 temp_filename = filename.substr(filename.find_last_of(
"/") +1);
1296 if ((temp_filename.size() >5) && ((temp_filename.compare(0,5,
"MOD09") == 0)
1297 ||(temp_filename.compare(0,5,
"MYD09") == 0))) {
1298 if ((fieldname.size() >5) && fieldname.compare(0,5,
"Range") == 0)
1299 need_change_scale =
false;
1302 else if((temp_filename.size() >7)&&
1303 ((temp_filename.compare(0,7,
"MOD16A2") == 0)|| (temp_filename.compare(0,7,
"MYD16A2")==0)||
1304 (temp_filename.compare(0,7,
"MOD16A3") == 0)|| (temp_filename.compare(0,7,
"MYD16A3")==0)))
1305 need_change_scale =
false;
1309 if(
true == need_change_scale) {
1310 sotype = MODIS_DIV_SCALE;
1312 <<
"The field " << fieldname <<
" scale factor is "
1313 << scale <<
" ."<<endl
1314 <<
" But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1316 <<
" Now change it to MODIS_DIV_SCALE. "<<endl;
1321 if (MODIS_DIV_SCALE == sotype) {
1323 sotype = MODIS_MUL_SCALE;
1324 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1325 << scale <<
" ."<<endl
1326 <<
" But the original scale factor type is MODIS_DIV_SCALE. "
1328 <<
" Now change it to MODIS_MUL_SCALE. "<<endl;
1333r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1334 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1336 ostringstream eherr;
1338 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1339 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1342cerr<<
"tmp_rank 2 is "<<tmp_rank <<endl;
1365#define RECALCULATE(CAST, DODS_CAST, VAL) \
1367 bool change_data_value = false; \
1368 if(sotype!=DEFAULT_CF_EQU) \
1370 vector<float>tmpval; \
1371 tmpval.resize(nelms); \
1372 CAST tmptr = (CAST)VAL; \
1373 for(int l=0; l<nelms; l++) \
1374 tmpval[l] = (float)tmptr[l]; \
1375 bool special_case = false; \
1376 if(scale_factor_attr_index==FAIL) \
1377 if(num_eles_of_an_attr==1) \
1378 if(radiance_scales!=nullptr && radiance_offsets!=nullptr) \
1380 scale = radiance_scales[0]; \
1381 field_offset = radiance_offsets[0];\
1382 special_case = true; \
1384 if((scale_factor_attr_index!=FAIL && !(scale==1 && field_offset==0)) || special_case) \
1386 for(int l=0; l<nelms; l++) \
1388 if(cf_vr_attrindex!=FAIL) \
1390 if((float)tmptr[l] != fillvalue ) \
1392 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[l]))\
1394 if ((orig_valid_min<=tmpval[l] && orig_valid_max>=tmpval[l]) || (true==has_Key_attr))\
1396 if(sotype==MODIS_MUL_SCALE) \
1397 tmpval[l] = (tmptr[l]-field_offset)*scale; \
1398 else if(sotype==MODIS_EQ_SCALE) \
1399 tmpval[l] = tmptr[l]*scale + field_offset; \
1400 else if(sotype==MODIS_DIV_SCALE) \
1401 tmpval[l] = (tmptr[l]-field_offset)/scale;\
1407 change_data_value = true; \
1408 set_value((dods_float32 *)tmpval.data(), nelms); \
1409 } else if(num_eles_of_an_attr>1 && (radiance_scales!=nullptr && radiance_offsets!=nullptr) || (reflectance_scales!=nullptr && reflectance_offsets!=nullptr)) \
1411 size_t dimindex=0; \
1412 if( num_eles_of_an_attr!=tmp_dims[dimindex]) \
1414 ostringstream eherr; \
1415 eherr << "The number of Z-Dimension scale attribute is not equal to the size of the first dimension in " << fieldname.c_str() << ". These two values must be equal."; \
1416 throw InternalErr (__FILE__, __LINE__, eherr.str ()); \
1418 size_t start_index, end_index; \
1419 size_t nr_elems = nelms/count32[dimindex]; \
1420 start_index = offset32[dimindex]; \
1421 end_index = start_index+step32[dimindex]*(count32[dimindex]-1); \
1423 for(size_t k=start_index; k<=end_index; k+=step32[dimindex]) \
1425 float tmpscale = (fieldname.find("Emissive")!=string::npos)? radiance_scales[k]: reflectance_scales[k]; \
1426 float tmpoffset = (fieldname.find("Emissive")!=string::npos)? radiance_offsets[k]: reflectance_offsets[k]; \
1427 for(size_t l=0; l<nr_elems; l++) \
1429 if(cf_vr_attrindex!=FAIL) \
1431 if(((float)tmptr[index])!=fillvalue) \
1433 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[index]))\
1435 if(sotype==MODIS_MUL_SCALE) \
1436 tmpval[index] = (tmptr[index]-tmpoffset)*tmpscale; \
1437 else if(sotype==MODIS_EQ_SCALE) \
1438 tmpval[index] = tmptr[index]*tmpscale+tmpoffset; \
1439 else if(sotype==MODIS_DIV_SCALE) \
1440 tmpval[index] = (tmptr[index]-tmpoffset)/tmpscale; \
1447 change_data_value = true; \
1448 set_value((dods_float32 *)tmpval.data(), nelms); \
1451 if(!change_data_value) \
1453 set_value ((DODS_CAST)VAL, nelms); \
1486#define RECALCULATE(CAST, DODS_CAST, VAL) \
1488 bool change_data_value = false; \
1489 if(sotype!=DEFAULT_CF_EQU) \
1491 vector<float>tmpval; \
1492 tmpval.resize(nelms); \
1493 CAST tmptr = (CAST)VAL; \
1494 for(int l=0; l<nelms; l++) \
1495 tmpval[l] = (float)tmptr[l]; \
1496 bool special_case = false; \
1497 if(scale_factor_attr_index==FAIL) \
1498 if(num_eles_of_an_attr==1) \
1499 if((radiance_scales!=nullptr) && (radiance_offsets!=nullptr)) \
1501 scale = radiance_scales[0]; \
1502 field_offset = radiance_offsets[0];\
1503 special_case = true; \
1505 if(((scale_factor_attr_index!=FAIL) && !((scale==1) && (field_offset==0))) || special_case) \
1507 float temp_scale = scale; \
1508 float temp_offset = field_offset; \
1509 if(sotype==MODIS_MUL_SCALE) \
1510 temp_offset = -1. *field_offset*temp_scale;\
1511 else if (sotype==MODIS_DIV_SCALE) \
1513 temp_scale = 1/scale; \
1514 temp_offset = -1. *field_offset*temp_scale;\
1516 for(int l=0; l<nelms; l++) \
1518 if(cf_vr_attrindex!=FAIL) \
1520 if((float)tmptr[l] != fillvalue ) \
1522 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[l]))\
1524 if (((orig_valid_min<=tmpval[l]) && (orig_valid_max>=tmpval[l])) || (true==has_Key_attr))\
1526 tmpval[l] = tmptr[l]*temp_scale + temp_offset; \
1532 change_data_value = true; \
1533 set_value((dods_float32 *)tmpval.data(), nelms); \
1534 } else if((num_eles_of_an_attr>1) && (((radiance_scales!=nullptr) && (radiance_offsets!=nullptr)) || ((reflectance_scales!=nullptr) && (reflectance_offsets!=nullptr)))) \
1536 size_t dimindex=0; \
1537 if( num_eles_of_an_attr!=tmp_dims[dimindex]) \
1539 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets); \
1540 ostringstream eherr; \
1541 eherr << "The number of Z-Dimension scale attribute is not equal to the size of the first dimension in " << fieldname.c_str() << ". These two values must be equal."; \
1542 throw InternalErr (__FILE__, __LINE__, eherr.str ()); \
1544 size_t start_index, end_index; \
1545 size_t nr_elems = nelms/count32[dimindex]; \
1546 start_index = offset32[dimindex]; \
1547 end_index = start_index+step32[dimindex]*(count32[dimindex]-1); \
1549 for(size_t k=start_index; k<=end_index; k+=step32[dimindex]) \
1551 float tmpscale = (fieldname.find("Emissive")!=string::npos)? radiance_scales[k]: reflectance_scales[k]; \
1552 float tmpoffset = (fieldname.find("Emissive")!=string::npos)? radiance_offsets[k]: reflectance_offsets[k]; \
1553 for(size_t l=0; l<nr_elems; l++) \
1555 if(cf_vr_attrindex!=FAIL) \
1557 if(((float)tmptr[index])!=fillvalue) \
1559 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[index]))\
1561 if(sotype==MODIS_MUL_SCALE) \
1562 tmpval[index] = (tmptr[index]-tmpoffset)*tmpscale; \
1563 else if(sotype==MODIS_EQ_SCALE) \
1564 tmpval[index] = tmptr[index]*tmpscale+tmpoffset; \
1565 else if(sotype==MODIS_DIV_SCALE) \
1566 tmpval[index] = (tmptr[index]-tmpoffset)/tmpscale; \
1573 change_data_value = true; \
1574 set_value((dods_float32 *)tmpval.data(), nelms); \
1577 if(!change_data_value) \
1579 set_value ((DODS_CAST)VAL, nelms); \
1582 switch (field_dtype) {
1588 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1589 offset32.data(), step32.data(), count32.data(), val.data());
1591 release_mod1b_res(reflectance_scales,reflectance_offsets,
1592 radiance_scales,radiance_offsets);
1593 ostringstream eherr;
1594 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1595 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1598#ifndef SIGNED_BYTE_TO_INT32
1599 RECALCULATE(int8*, dods_byte*, val.data());
1602 vector<int32>newval;
1603 newval.resize(nelms);
1605 for (
int counter = 0; counter < nelms; counter++)
1606 newval[counter] = (int32) (val[counter]);
1608 RECALCULATE(int32*, dods_int32*, newval.data());
1618 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1619 offset32.data(), step32.data(), count32.data(), val.data());
1621 release_mod1b_res(reflectance_scales,reflectance_offsets,
1622 radiance_scales,radiance_offsets);
1623 ostringstream eherr;
1625 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1626 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1629 RECALCULATE(uint8*, dods_byte*, val.data());
1637 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1638 offset32.data(), step32.data(), count32.data(), val.data());
1642 release_mod1b_res(reflectance_scales,reflectance_offsets,
1643 radiance_scales,radiance_offsets);
1644 ostringstream eherr;
1646 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1647 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1649 RECALCULATE(int16*, dods_int16*, val.data());
1657cerr<<
"gridid is "<<gridid <<endl;
1659char tmp_dimlist[1024];
1660int32 tmp_dims[rank];
1661int32 field_dtype = 0;
1664r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1665 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1667 ostringstream eherr;
1669 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1670 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1674 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1675 offset32.data(), step32.data(), count32.data(), val.data());
1677 release_mod1b_res(reflectance_scales,reflectance_offsets,
1678 radiance_scales,radiance_offsets);
1679 ostringstream eherr;
1681 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1682 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1685 RECALCULATE(uint16*, dods_uint16*, val.data());
1692 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1693 offset32.data(), step32.data(), count32.data(), val.data());
1696 release_mod1b_res(reflectance_scales,reflectance_offsets,
1697 radiance_scales,radiance_offsets);
1698 ostringstream eherr;
1700 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1701 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1704 RECALCULATE(int32*, dods_int32*, val.data());
1711 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1712 offset32.data(), step32.data(), count32.data(), val.data());
1715 release_mod1b_res(reflectance_scales,reflectance_offsets,
1716 radiance_scales,radiance_offsets);
1717 ostringstream eherr;
1719 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1720 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1723 RECALCULATE(uint32*, dods_uint32*, val.data());
1730 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1731 offset32.data(), step32.data(), count32.data(), val.data());
1734 release_mod1b_res(reflectance_scales,reflectance_offsets,
1735 radiance_scales,radiance_offsets);
1736 ostringstream eherr;
1738 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1739 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1743 RECALCULATE(float32*, dods_float32*, val.data());
1751 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1752 offset32.data(), step32.data(), count32.data(), val.data());
1755 release_mod1b_res(reflectance_scales,reflectance_offsets,
1756 radiance_scales,radiance_offsets);
1757 ostringstream eherr;
1759 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1760 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1762 set_value ((dods_float64 *) val.data(), nelms);
1766 release_mod1b_res(reflectance_scales,reflectance_offsets,
1767 radiance_scales,radiance_offsets);
1768 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1771 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
1773 if(reflectance_scales!=
nullptr)
1775 delete[] reflectance_offsets;
1776 delete[] reflectance_scales;
1779 if(radiance_scales!=
nullptr)
1781 delete[] radiance_offsets;
1782 delete[] radiance_scales;
1788 if (
true == isgeofile ||
false == check_pass_fileid_key)
1797HDFEOS2Array_RealField::write_dap_data_disable_scale_comp(int32 gridid,
1805 "Coming to HDFEOS2_Array_RealField: write_dap_data_disable_scale_comp"
1809 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1810 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
1813 if (swathname ==
"") {
1814 fieldinfofunc = GDfieldinfo;
1815 readfieldfunc = GDreadfield;
1818 else if (gridname ==
"") {
1819 fieldinfofunc = SWfieldinfo;
1820 readfieldfunc = SWreadfield;
1824 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
1830 char tmp_dimlist[1024];
1833 int32 tmp_dims[rank];
1836 int32 field_dtype = 0;
1843 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1844 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1846 ostringstream eherr;
1847 eherr <<
"Field " << fieldname.c_str ()
1848 <<
" information cannot be obtained.";
1849 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1853 switch (field_dtype) {
1858 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1859 offset32, step32, count32, val.data());
1861 ostringstream eherr;
1862 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1863 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1866#ifndef SIGNED_BYTE_TO_INT32
1867 set_value((dods_byte*)val.data(),nelms);
1870 vector<int32>newval;
1871 newval.resize(nelms);
1873 for (
int counter = 0; counter < nelms; counter++)
1874 newval[counter] = (int32) (val[counter]);
1876 set_value((dods_int32*)newval.data(),nelms);
1886 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1887 offset32, step32, count32, val.data());
1890 ostringstream eherr;
1891 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1892 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1895 set_value((dods_byte*)val.data(),nelms);
1903 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1904 offset32, step32, count32, val.data());
1907 ostringstream eherr;
1908 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1909 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1911 set_value((dods_int16*)val.data(),nelms);
1918 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1919 offset32, step32, count32, val.data());
1921 ostringstream eherr;
1922 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1923 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1926 set_value((dods_uint16*)val.data(),nelms);
1933 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1934 offset32, step32, count32, val.data());
1936 ostringstream eherr;
1937 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1938 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1941 set_value((dods_int32*)val.data(),nelms);
1948 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1949 offset32, step32, count32, val.data());
1951 ostringstream eherr;
1952 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1953 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1956 set_value((dods_uint32*)val.data(),nelms);
1963 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1964 offset32, step32, count32, val.data());
1966 ostringstream eherr;
1967 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1968 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1972 set_value((dods_float32*)val.data(),nelms);
1979 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1980 offset32, step32, count32, val.data());
1982 ostringstream eherr;
1983 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1984 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1986 set_value ((dods_float64 *) val.data(), nelms);
1990 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1995 r = detachfunc (gridid);
1998 ostringstream eherr;
2000 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
2001 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2005 r = closefunc (gfid);
2007 ostringstream eherr;
2009 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
2010 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2020HDFEOS2Array_RealField::format_constraint (
int *offset,
int *step,
int *count)
2025 Dim_iter p = dim_begin ();
2026 while (p != dim_end ()) {
2028 int start = dimension_start (p,
true);
2029 int stride = dimension_stride (p,
true);
2030 int stop = dimension_stop (p,
true);
2035 oss <<
"Array/Grid hyperslab start point "<< start <<
2036 " is greater than stop point " << stop <<
".";
2037 throw Error(malformed_expr, oss.str());
2042 count[id] = ((stop - start) / stride) + 1;
2046 "=format_constraint():"
2047 <<
"id=" <<
id <<
" offset=" << offset[
id]
2048 <<
" step=" << step[
id]
2049 <<
" count=" << count[
id]
2060void HDFEOS2Array_RealField::close_fileid(
const int gsfileid,
const int sdfileid) {
2062 if(
true == isgeofile ||
false == HDF4RequestHandler::get_pass_fileid()) {
2078void HDFEOS2Array_RealField::release_mod1b_res(
float*ref_scale,
2083 if(ref_scale !=
nullptr)
2085 if(ref_offset !=
nullptr)
2086 delete[] ref_offset;
2087 if(rad_scale !=
nullptr)
2089 if(rad_offset !=
nullptr)
2090 delete[] rad_offset;
void close_fileid(hid_t fid)