9 #include "config_hdf.h"
14 #include <libdap/debug.h>
15 #include <libdap/InternalErr.h>
19 #include "HDFCFUtil.h"
20 #include "HDFEOS2Array_RealField.h"
22 #include "HDF4RequestHandler.h"
27 #define SIGNED_BYTE_TO_INT32 1
30 HDFEOS2Array_RealField::read ()
33 BESDEBUG(
"h4",
"Coming to HDFEOS2_Array_RealField read "<<endl);
38 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
39 bool check_pass_fileid_key =
false;
40 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
43 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
55 nelms = format_constraint (&offset[0], &step[0], &count[0]);
58 vector<int32>offset32;
59 offset32.resize(rank);
66 for (
int i = 0; i < rank; i++) {
67 offset32[i] = (int32) offset[i];
68 count32[i] = (int32) count[i];
69 step32[i] = (int32) step[i];
73 int32 (*openfunc) (
char *, intn);
74 intn (*closefunc) (int32);
75 int32 (*attachfunc) (int32,
char *);
76 intn (*detachfunc) (int32);
77 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
80 if (swathname ==
"") {
83 attachfunc = GDattach;
84 detachfunc = GDdetach;
85 fieldinfofunc = GDfieldinfo;
86 datasetname = gridname;
88 else if (gridname ==
"") {
91 attachfunc = SWattach;
92 detachfunc = SWdetach;
93 fieldinfofunc = SWfieldinfo;
94 datasetname = swathname;
97 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
103 if (
true == isgeofile ||
false == check_pass_fileid_key) {
106 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
109 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
110 throw InternalErr (__FILE__, __LINE__, eherr.str ());
117 gridid = attachfunc (gfid,
const_cast < char *
>(datasetname.c_str ()));
121 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be attached.";
122 throw InternalErr (__FILE__, __LINE__, eherr.str ());
126 string check_disable_scale_comp_key =
"H4.DisableScaleOffsetComp";
127 bool turn_on_disable_scale_comp_key=
false;
128 turn_on_disable_scale_comp_key = HDFCFUtil::check_beskeys(check_disable_scale_comp_key);
132 bool is_modis_l1b =
false;
133 if(
"MODIS_SWATH_Type_L1B" == swathname)
136 bool is_modis_vip =
false;
137 if (
"VIP_CMG_GRID" == gridname)
140 bool field_is_vdata =
false;
151 char tmp_dimlist[1024];
152 int32 tmp_dims[rank];
153 int32 field_dtype = 0;
156 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
157 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
163 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
164 throw InternalErr (__FILE__, __LINE__, eherr.str ());
168 field_is_vdata =
true;
172 bool has_Key_attr =
false;
174 if (
false == field_is_vdata) {
179 if (
true == isgeofile ||
false == check_pass_fileid_key) {
181 sdfileid = SDstart(
const_cast < char *
>(filename.c_str ()), DFACC_READ);
183 if (FAIL == sdfileid) {
187 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
195 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
196 if (FAIL == sdsindex) {
200 eherr <<
"Cannot obtain the index of " << fieldname;
201 throw InternalErr (__FILE__, __LINE__, eherr.str ());
204 sdsid = SDselect(sdfileid, sdsindex);
209 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
210 throw InternalErr (__FILE__, __LINE__, eherr.str ());
219 if(SDfindattr(sdsid,
"Key")!=FAIL)
224 if (
true == isgeofile ||
false == check_pass_fileid_key)
230 if((
false == is_modis_l1b) && (
false == is_modis_vip)
231 &&(
false == has_Key_attr) && (
true == HDF4RequestHandler::get_disable_scaleoffset_comp()))
232 write_dap_data_disable_scale_comp(gridid,nelms,&offset32[0],&count32[0],&step32[0]);
234 write_dap_data_scale_comp(gridid,nelms,offset32,count32,step32);
243 r = detachfunc (gridid);
247 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
248 throw InternalErr (__FILE__, __LINE__, eherr.str ());
252 if(
true == isgeofile ||
false == check_pass_fileid_key) {
253 r = closefunc (gfid);
256 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
257 throw InternalErr (__FILE__, __LINE__, eherr.str ());
265 HDFEOS2Array_RealField::write_dap_data_scale_comp(int32 gridid,
267 vector<int32>& offset32,
268 vector<int32>& count32,
269 vector<int32>& step32) {
273 "coming to HDFEOS2Array_RealField write_dap_data_scale_comp "
277 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
278 bool check_pass_fileid_key =
false;
279 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
281 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
284 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
285 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
288 if (swathname ==
"") {
289 fieldinfofunc = GDfieldinfo;
290 readfieldfunc = GDreadfield;
292 else if (gridname ==
"") {
293 fieldinfofunc = SWfieldinfo;
294 readfieldfunc = SWreadfield;
297 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
301 char tmp_dimlist[1024];
304 int32 tmp_dims[rank];
307 int32 field_dtype = 0;
314 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
315 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
319 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
320 throw InternalErr (__FILE__, __LINE__, eherr.str ());
330 float *reflectance_offsets =NULL;
331 float *reflectance_scales =NULL;
332 float *radiance_offsets =NULL;
333 float *radiance_scales =NULL;
336 int32 attr_dtype = 0;
339 int32 temp_attrcount = 0;
342 int32 num_eles_of_an_attr = 0;
345 int32 cf_modl1b_rr_attrindex = 0;
348 int32 cf_modl1b_rr_attrindex2 = 0;
351 int32 cf_vr_attrindex = 0;
354 int32 cf_fv_attrindex = 0;
357 int32 scale_factor_attr_index = 0;
360 int32 add_offset_attr_index = 0;
366 float field_offset = 0;
372 float orig_valid_min = 0;
375 float orig_valid_max = 0;
382 bool has_Key_attr =
false;
385 if(sotype!=DEFAULT_CF_EQU) {
387 bool field_is_vdata =
false;
400 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
401 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
404 eherr <<
"Field " << fieldname.c_str ()
405 <<
" information cannot be obtained.";
406 throw InternalErr (__FILE__, __LINE__, eherr.str ());
410 field_is_vdata =
true;
414 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
415 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
419 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
420 throw InternalErr (__FILE__, __LINE__, eherr.str ());
423 cerr<<
"tmp_rank is "<<tmp_rank <<endl;
434 if(
false == field_is_vdata) {
436 char attrname[H4_MAX_NC_NAME + 1];
437 vector<char> attrbuf;
440 if(
false == isgeofile ||
false == check_pass_fileid_key)
443 sdfileid = SDstart(
const_cast < char *
>(filename.c_str ()), DFACC_READ);
444 if (FAIL == sdfileid) {
446 eherr <<
"Cannot Start the SD interface for the file "
448 throw InternalErr (__FILE__, __LINE__, eherr.str ());
454 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
455 if (FAIL == sdsindex) {
456 if(
true == isgeofile ||
false == check_pass_fileid_key)
459 eherr <<
"Cannot obtain the index of " << fieldname;
460 throw InternalErr (__FILE__, __LINE__, eherr.str ());
463 sdsid = SDselect(sdfileid, sdsindex);
465 if (
true == isgeofile ||
false == check_pass_fileid_key)
468 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
469 throw InternalErr (__FILE__, __LINE__, eherr.str ());
473 char attrname[H4_MAX_NC_NAME + 1];
474 vector<char> attrbuf, attrbuf2;
481 cf_general_attrindex = SDfindattr(sdsid,
"radiance_scales");
482 cf_general_attrindex2 = SDfindattr(sdsid,
"radiance_offsets");
485 if(cf_general_attrindex!=FAIL && cf_general_attrindex2!=FAIL)
488 ret = SDattrinfo(sdsid, cf_general_attrindex, attrname, &attr_dtype, &temp_attrcount);
492 if(
true == isgeofile)
495 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
496 throw InternalErr (__FILE__, __LINE__, eherr.str ());
499 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
500 ret = SDreadattr(sdsid, cf_general_attrindex, (VOIDP)&attrbuf[0]);
503 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
505 if (
true == isgeofile)
508 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
509 throw InternalErr (__FILE__, __LINE__, eherr.str ());
511 ret = SDattrinfo(sdsid, cf_general_attrindex2, attrname, &attr_dtype, &temp_attrcount);
514 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
516 if(
true == isgeofile)
519 eherr <<
"Attribute 'radiance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
520 throw InternalErr (__FILE__, __LINE__, eherr.str ());
523 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
524 ret = SDreadattr(sdsid, cf_general_attrindex2, (VOIDP)&attrbuf2[0]);
527 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
529 if(
true == isgeofile)
532 eherr <<
"Attribute 'radiance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
533 throw InternalErr (__FILE__, __LINE__, eherr.str ());
540 #define GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
543 CAST *ptr = (CAST*)&attrbuf[0]; \
544 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
545 radiance_scales = new float[temp_attrcount]; \
546 radiance_offsets = new float[temp_attrcount]; \
547 for(int l=0; l<temp_attrcount; l++) \
549 radiance_scales[l] = ptr[l]; \
550 radiance_offsets[l] = ptr2[l]; \
554 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
555 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
557 #undef GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES
558 num_eles_of_an_attr = temp_attrcount;
562 cf_general_attrindex = SDfindattr(sdsid,
"reflectance_scales");
563 cf_general_attrindex2 = SDfindattr(sdsid,
"reflectance_offsets");
564 if(cf_general_attrindex!=FAIL && cf_general_attrindex2!=FAIL)
567 ret = SDattrinfo(sdsid, cf_general_attrindex, attrname, &attr_dtype, &temp_attrcount);
570 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
572 if(
true == isgeofile)
575 eherr <<
"Attribute 'reflectance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
576 throw InternalErr (__FILE__, __LINE__, eherr.str ());
579 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
580 ret = SDreadattr(sdsid, cf_general_attrindex, (VOIDP)&attrbuf[0]);
583 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
585 if(
true == isgeofile)
588 eherr <<
"Attribute 'reflectance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
589 throw InternalErr (__FILE__, __LINE__, eherr.str ());
592 ret = SDattrinfo(sdsid, cf_general_attrindex2, attrname, &attr_dtype, &temp_attrcount);
595 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
597 if(
true == isgeofile)
600 eherr <<
"Attribute 'reflectance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
601 throw InternalErr (__FILE__, __LINE__, eherr.str ());
604 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
605 ret = SDreadattr(sdsid, cf_general_attrindex2, (VOIDP)&attrbuf2[0]);
608 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
610 if(
true == isgeofile)
613 eherr <<
"Attribute 'reflectance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
614 throw InternalErr (__FILE__, __LINE__, eherr.str ());
618 #define GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
621 CAST *ptr = (CAST*)&attrbuf[0]; \
622 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
623 reflectance_scales = new float[temp_attrcount]; \
624 reflectance_offsets = new float[temp_attrcount]; \
625 for(int l=0; l<temp_attrcount; l++) \
627 reflectance_scales[l] = ptr[l]; \
628 reflectance_offsets[l] = ptr2[l]; \
632 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
633 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
635 #undef GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES
636 num_eles_of_an_attr = temp_attrcount;
641 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
642 if(scale_factor_attr_index!=FAIL)
645 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname,
646 &attr_dtype, &temp_attrcount);
650 if(
true == isgeofile ||
false == check_pass_fileid_key)
653 eherr <<
"Attribute 'scale_factor' in "
654 << fieldname.c_str () <<
" cannot be obtained.";
655 throw InternalErr (__FILE__, __LINE__, eherr.str ());
658 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
659 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)&attrbuf[0]);
663 if(
true == isgeofile ||
false == check_pass_fileid_key)
667 eherr <<
"Attribute 'scale_factor' in "
668 << fieldname.c_str () <<
" cannot be obtained.";
669 throw InternalErr (__FILE__, __LINE__, eherr.str ());
674 #define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
677 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
678 scale = (float)tmpvalue; \
681 GET_SCALE_FACTOR_ATTR_VALUE(INT8, int8);
682 GET_SCALE_FACTOR_ATTR_VALUE(CHAR,int8);
683 GET_SCALE_FACTOR_ATTR_VALUE(UINT8, uint8);
684 GET_SCALE_FACTOR_ATTR_VALUE(UCHAR,uint8);
685 GET_SCALE_FACTOR_ATTR_VALUE(INT16, int16);
686 GET_SCALE_FACTOR_ATTR_VALUE(UINT16, uint16);
687 GET_SCALE_FACTOR_ATTR_VALUE(INT32, int32);
688 GET_SCALE_FACTOR_ATTR_VALUE(UINT32, uint32);
689 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float);
690 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double);
692 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
696 #undef GET_SCALE_FACTOR_ATTR_VALUE
700 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
701 if(add_offset_attr_index!=FAIL)
704 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname,
705 &attr_dtype, &temp_attrcount);
709 if(
true == isgeofile ||
false == check_pass_fileid_key)
713 eherr <<
"Attribute 'add_offset' in " << fieldname.c_str ()
714 <<
" cannot be obtained.";
715 throw InternalErr (__FILE__, __LINE__, eherr.str ());
718 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
719 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)&attrbuf[0]);
723 if(
true == isgeofile ||
false == check_pass_fileid_key)
727 eherr <<
"Attribute 'add_offset' in " << fieldname.c_str ()
728 <<
" cannot be obtained.";
729 throw InternalErr (__FILE__, __LINE__, eherr.str ());
734 #define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
737 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
738 field_offset = (float)tmpvalue; \
741 GET_ADD_OFFSET_ATTR_VALUE(INT8, int8);
742 GET_ADD_OFFSET_ATTR_VALUE(CHAR,int8);
743 GET_ADD_OFFSET_ATTR_VALUE(UINT8, uint8);
744 GET_ADD_OFFSET_ATTR_VALUE(UCHAR,uint8);
745 GET_ADD_OFFSET_ATTR_VALUE(INT16, int16);
746 GET_ADD_OFFSET_ATTR_VALUE(UINT16, uint16);
747 GET_ADD_OFFSET_ATTR_VALUE(INT32, int32);
748 GET_ADD_OFFSET_ATTR_VALUE(UINT32, uint32);
749 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float);
750 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double);
752 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
755 #undef GET_ADD_OFFSET_ATTR_VALUE
759 cf_fv_attrindex = SDfindattr(sdsid,
"_FillValue");
760 if(cf_fv_attrindex!=FAIL)
763 ret = SDattrinfo(sdsid, cf_fv_attrindex, attrname, &attr_dtype, &temp_attrcount);
767 if(
true == isgeofile ||
false == check_pass_fileid_key)
771 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
772 <<
" cannot be obtained.";
773 throw InternalErr (__FILE__, __LINE__, eherr.str ());
776 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
777 ret = SDreadattr(sdsid, cf_fv_attrindex, (VOIDP)&attrbuf[0]);
781 if(
true == isgeofile ||
false == check_pass_fileid_key)
785 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
786 <<
" cannot be obtained.";
787 throw InternalErr (__FILE__, __LINE__, eherr.str ());
792 #define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
795 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
796 fillvalue = (float)tmpvalue; \
799 GET_FILLVALUE_ATTR_VALUE(INT8, int8);
800 GET_FILLVALUE_ATTR_VALUE(CHAR, int8);
801 GET_FILLVALUE_ATTR_VALUE(INT16, int16);
802 GET_FILLVALUE_ATTR_VALUE(INT32, int32);
803 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8);
804 GET_FILLVALUE_ATTR_VALUE(UCHAR, uint8);
805 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16);
806 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32);
808 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
811 #undef GET_FILLVALUE_ATTR_VALUE
817 cf_vr_attrindex = SDfindattr(sdsid,
"valid_range");
818 if(cf_vr_attrindex!=FAIL)
821 ret = SDattrinfo(sdsid, cf_vr_attrindex, attrname, &attr_dtype, &temp_attrcount);
825 if(
true == isgeofile ||
false == check_pass_fileid_key)
829 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
830 <<
" cannot be obtained.";
831 throw InternalErr (__FILE__, __LINE__, eherr.str ());
834 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
835 ret = SDreadattr(sdsid, cf_vr_attrindex, (VOIDP)&attrbuf[0]);
839 if(
true == isgeofile ||
false == check_pass_fileid_key)
843 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
844 <<
" cannot be obtained.";
845 throw InternalErr (__FILE__, __LINE__, eherr.str ());
849 string attrbuf_str(attrbuf.begin(),attrbuf.end());
857 size_t found = attrbuf_str.find_first_of(
",");
858 size_t found_from_end = attrbuf_str.find_last_of(
",");
860 if (string::npos == found){
862 if(
true == isgeofile ||
false == check_pass_fileid_key)
864 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
866 if (found != found_from_end){
868 if(
true == isgeofile ||
false == check_pass_fileid_key)
870 throw InternalErr(__FILE__,__LINE__,
871 "Only one separator , should be available.");
879 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
880 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
894 if (temp_attrcount >2) {
896 size_t found = attrbuf_str.find_first_of(
",");
897 size_t found_from_end = attrbuf_str.find_last_of(
",");
899 if (string::npos == found){
901 if(
true == isgeofile ||
false == check_pass_fileid_key)
903 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
905 if (found != found_from_end){
907 if(
true == isgeofile ||
false == check_pass_fileid_key)
909 throw InternalErr(__FILE__,__LINE__,
910 "Only one separator , should be available.");
916 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
917 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
920 else if (2 == temp_attrcount) {
921 orig_valid_min = (float)attrbuf[0];
922 orig_valid_max = (float)attrbuf[1];
926 if(
true == isgeofile ||
false == check_pass_fileid_key)
928 throw InternalErr(__FILE__,__LINE__,
929 "The number of attribute count should be greater than 1.");
938 if (temp_attrcount != 2) {
940 if(
true == isgeofile ||
false == check_pass_fileid_key)
943 throw InternalErr(__FILE__,__LINE__,
944 "The number of attribute count should be 2 for the DFNT_UINT8 type.");
947 unsigned char* temp_valid_range = (
unsigned char *)&attrbuf[0];
948 orig_valid_min = (float)(temp_valid_range[0]);
949 orig_valid_max = (float)(temp_valid_range[1]);
955 if (temp_attrcount != 2) {
957 if(
true == isgeofile ||
false == check_pass_fileid_key)
960 throw InternalErr(__FILE__,__LINE__,
961 "The number of attribute count should be 2 for the DFNT_INT16 type.");
964 short* temp_valid_range = (
short *)&attrbuf[0];
965 orig_valid_min = (float)(temp_valid_range[0]);
966 orig_valid_max = (float)(temp_valid_range[1]);
972 if (temp_attrcount != 2) {
974 if(
true == isgeofile ||
false == check_pass_fileid_key)
977 throw InternalErr(__FILE__,__LINE__,
978 "The number of attribute count should be 2 for the DFNT_UINT16 type.");
981 unsigned short* temp_valid_range = (
unsigned short *)&attrbuf[0];
982 orig_valid_min = (float)(temp_valid_range[0]);
983 orig_valid_max = (float)(temp_valid_range[1]);
989 if (temp_attrcount != 2) {
991 if(
true == isgeofile ||
false == check_pass_fileid_key)
994 throw InternalErr(__FILE__,__LINE__,
995 "The number of attribute count should be 2 for the DFNT_INT32 type.");
998 int* temp_valid_range = (
int *)&attrbuf[0];
999 orig_valid_min = (float)(temp_valid_range[0]);
1000 orig_valid_max = (float)(temp_valid_range[1]);
1006 if (temp_attrcount != 2) {
1008 if(
true == isgeofile ||
false == check_pass_fileid_key)
1011 throw InternalErr(__FILE__,__LINE__,
1012 "The number of attribute count should be 2 for the DFNT_UINT32 type.");
1015 unsigned int* temp_valid_range = (
unsigned int *)&attrbuf[0];
1016 orig_valid_min = (float)(temp_valid_range[0]);
1017 orig_valid_max = (float)(temp_valid_range[1]);
1023 if (temp_attrcount != 2) {
1025 if(
true == isgeofile ||
false == check_pass_fileid_key)
1028 throw InternalErr(__FILE__,__LINE__,
1029 "The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
1032 float* temp_valid_range = (
float *)&attrbuf[0];
1033 orig_valid_min = temp_valid_range[0];
1034 orig_valid_max = temp_valid_range[1];
1040 if (temp_attrcount != 2){
1042 if(
true == isgeofile ||
false == check_pass_fileid_key)
1045 throw InternalErr(__FILE__,__LINE__,
1046 "The number of attribute count should be 2 for the DFNT_FLOAT64 type.");
1048 double* temp_valid_range = (
double *)&attrbuf[0];
1055 orig_valid_min = temp_valid_range[0];
1056 orig_valid_max = temp_valid_range[1];
1061 if(
true == isgeofile ||
false == check_pass_fileid_key)
1063 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
1073 int32 cf_mod_key_attrindex = SUCCEED;
1074 cf_mod_key_attrindex = SDfindattr(sdsid,
"Key");
1075 if(cf_mod_key_attrindex !=FAIL) {
1076 has_Key_attr =
true;
1080 vector<char> attrbuf2;
1088 cf_modl1b_rr_attrindex = SDfindattr(sdsid,
"radiance_scales");
1089 cf_modl1b_rr_attrindex2 = SDfindattr(sdsid,
"radiance_offsets");
1092 if(cf_modl1b_rr_attrindex!=FAIL && cf_modl1b_rr_attrindex2!=FAIL)
1095 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex, attrname,
1096 &attr_dtype, &temp_attrcount);
1100 if(
true == isgeofile ||
false == check_pass_fileid_key)
1102 ostringstream eherr;
1103 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str ()
1104 <<
" cannot be obtained.";
1105 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1108 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1109 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex, (VOIDP)&attrbuf[0]);
1113 if (
true == isgeofile ||
false == check_pass_fileid_key)
1115 ostringstream eherr;
1116 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str ()
1117 <<
" cannot be obtained.";
1118 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1120 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex2, attrname,
1121 &attr_dtype, &temp_attrcount);
1125 if(
true == isgeofile ||
false == check_pass_fileid_key)
1127 ostringstream eherr;
1128 eherr <<
"Attribute 'radiance_offsets' in "
1129 << fieldname.c_str () <<
" cannot be obtained.";
1130 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1133 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1134 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex2, (VOIDP)&attrbuf2[0]);
1138 if(
true == isgeofile ||
false == check_pass_fileid_key)
1140 ostringstream eherr;
1141 eherr <<
"Attribute 'radiance_offsets' in "
1142 << fieldname.c_str () <<
" cannot be obtained.";
1143 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1151 #define GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
1154 CAST *ptr = (CAST*)&attrbuf[0]; \
1155 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
1156 radiance_scales = new float[temp_attrcount]; \
1157 radiance_offsets = new float[temp_attrcount]; \
1158 for(int l=0; l<temp_attrcount; l++) \
1160 radiance_scales[l] = ptr[l]; \
1161 radiance_offsets[l] = ptr2[l]; \
1165 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
1166 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
1168 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1171 #undef GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES
1173 num_eles_of_an_attr = temp_attrcount;
1178 cf_modl1b_rr_attrindex = SDfindattr(sdsid,
"reflectance_scales");
1179 cf_modl1b_rr_attrindex2 = SDfindattr(sdsid,
"reflectance_offsets");
1180 if(cf_modl1b_rr_attrindex!=FAIL && cf_modl1b_rr_attrindex2!=FAIL)
1183 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex, attrname,
1184 &attr_dtype, &temp_attrcount);
1187 release_mod1b_res(reflectance_scales,reflectance_offsets,
1188 radiance_scales,radiance_offsets);
1190 if(
true == isgeofile ||
false == check_pass_fileid_key)
1192 ostringstream eherr;
1193 eherr <<
"Attribute 'reflectance_scales' in "
1194 << fieldname.c_str () <<
" cannot be obtained.";
1195 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1198 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1199 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex, (VOIDP)&attrbuf[0]);
1202 release_mod1b_res(reflectance_scales,reflectance_offsets,
1203 radiance_scales,radiance_offsets);
1205 if(
true == isgeofile ||
false == check_pass_fileid_key)
1207 ostringstream eherr;
1208 eherr <<
"Attribute 'reflectance_scales' in "
1209 << fieldname.c_str () <<
" cannot be obtained.";
1210 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1213 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex2, attrname,
1214 &attr_dtype, &temp_attrcount);
1217 release_mod1b_res(reflectance_scales,reflectance_offsets,
1218 radiance_scales,radiance_offsets);
1220 if(
true == isgeofile ||
false == check_pass_fileid_key)
1222 ostringstream eherr;
1223 eherr <<
"Attribute 'reflectance_offsets' in "
1224 << fieldname.c_str () <<
" cannot be obtained.";
1225 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1228 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1229 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex2, (VOIDP)&attrbuf2[0]);
1232 release_mod1b_res(reflectance_scales,reflectance_offsets,
1233 radiance_scales,radiance_offsets);
1235 if(
true == isgeofile ||
false == check_pass_fileid_key)
1237 ostringstream eherr;
1238 eherr <<
"Attribute 'reflectance_offsets' in "
1239 << fieldname.c_str () <<
" cannot be obtained.";
1240 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1244 #define GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
1247 CAST *ptr = (CAST*)&attrbuf[0]; \
1248 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
1249 reflectance_scales = new float[temp_attrcount]; \
1250 reflectance_offsets = new float[temp_attrcount]; \
1251 for(int l=0; l<temp_attrcount; l++) \
1253 reflectance_scales[l] = ptr[l]; \
1254 reflectance_offsets[l] = ptr2[l]; \
1258 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
1259 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
1261 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1264 #undef GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES
1265 num_eles_of_an_attr = temp_attrcount;
1271 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1272 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1274 ostringstream eherr;
1276 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1277 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1280 cerr<<
"tmp_rank 3 is "<<tmp_rank <<endl;
1286 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1287 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1289 ostringstream eherr;
1291 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1292 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1295 cerr<<
"tmp_rank 4 is "<<tmp_rank <<endl;
1298 BESDEBUG(
"h4",
"scale is "<<scale <<endl);
1299 BESDEBUG(
"h4",
"offset is "<<field_offset <<endl);
1300 BESDEBUG(
"h4",
"fillvalue is "<<fillvalue <<endl);
1329 if (MODIS_EQ_SCALE == sotype || MODIS_MUL_SCALE == sotype) {
1331 bool need_change_scale =
true;
1334 string temp_filename;
1335 if (filename.find(
"#") != string::npos)
1336 temp_filename =filename.substr(filename.find_last_of(
"#") + 1);
1338 temp_filename = filename.substr(filename.find_last_of(
"/") +1);
1340 if ((temp_filename.size() >5) && ((temp_filename.compare(0,5,
"MOD09") == 0)
1341 ||(temp_filename.compare(0,5,
"MYD09") == 0))) {
1342 if ((fieldname.size() >5) && fieldname.compare(0,5,
"Range") == 0)
1343 need_change_scale =
false;
1346 else if((temp_filename.size() >7)&&
1347 ((temp_filename.compare(0,7,
"MOD16A2") == 0)|| (temp_filename.compare(0,7,
"MYD16A2")==0)||
1348 (temp_filename.compare(0,7,
"MOD16A3") == 0)|| (temp_filename.compare(0,7,
"MYD16A3")==0)))
1349 need_change_scale =
false;
1353 if(
true == need_change_scale) {
1354 sotype = MODIS_DIV_SCALE;
1356 <<
"The field " << fieldname <<
" scale factor is "
1357 << scale <<
" ."<<endl
1358 <<
" But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1360 <<
" Now change it to MODIS_DIV_SCALE. "<<endl;
1365 if (MODIS_DIV_SCALE == sotype) {
1367 sotype = MODIS_MUL_SCALE;
1368 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1369 << scale <<
" ."<<endl
1370 <<
" But the original scale factor type is MODIS_DIV_SCALE. "
1372 <<
" Now change it to MODIS_MUL_SCALE. "<<endl;
1377 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1378 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1380 ostringstream eherr;
1382 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1383 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1386 cerr<<
"tmp_rank 2 is "<<tmp_rank <<endl;
1409 #define RECALCULATE(CAST, DODS_CAST, VAL) \
1411 bool change_data_value = false; \
1412 if(sotype!=DEFAULT_CF_EQU) \
1414 vector<float>tmpval; \
1415 tmpval.resize(nelms); \
1416 CAST tmptr = (CAST)VAL; \
1417 for(int l=0; l<nelms; l++) \
1418 tmpval[l] = (float)tmptr[l]; \
1419 bool special_case = false; \
1420 if(scale_factor_attr_index==FAIL) \
1421 if(num_eles_of_an_attr==1) \
1422 if(radiance_scales!=NULL && radiance_offsets!=NULL) \
1424 scale = radiance_scales[0]; \
1425 field_offset = radiance_offsets[0];\
1426 special_case = true; \
1428 if((scale_factor_attr_index!=FAIL && !(scale==1 && field_offset==0)) || special_case) \
1430 for(int l=0; l<nelms; l++) \
1432 if(cf_vr_attrindex!=FAIL) \
1434 if((float)tmptr[l] != fillvalue ) \
1436 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[l]))\
1438 if ((orig_valid_min<=tmpval[l] && orig_valid_max>=tmpval[l]) || (true==has_Key_attr))\
1440 if(sotype==MODIS_MUL_SCALE) \
1441 tmpval[l] = (tmptr[l]-field_offset)*scale; \
1442 else if(sotype==MODIS_EQ_SCALE) \
1443 tmpval[l] = tmptr[l]*scale + field_offset; \
1444 else if(sotype==MODIS_DIV_SCALE) \
1445 tmpval[l] = (tmptr[l]-field_offset)/scale;\
1451 change_data_value = true; \
1452 set_value((dods_float32 *)&tmpval[0], nelms); \
1453 } else if(num_eles_of_an_attr>1 && (radiance_scales!=NULL && radiance_offsets!=NULL) || (reflectance_scales!=NULL && reflectance_offsets!=NULL)) \
1455 size_t dimindex=0; \
1456 if( num_eles_of_an_attr!=tmp_dims[dimindex]) \
1458 ostringstream eherr; \
1459 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."; \
1460 throw InternalErr (__FILE__, __LINE__, eherr.str ()); \
1462 size_t start_index, end_index; \
1463 size_t nr_elems = nelms/count32[dimindex]; \
1464 start_index = offset32[dimindex]; \
1465 end_index = start_index+step32[dimindex]*(count32[dimindex]-1); \
1467 for(size_t k=start_index; k<=end_index; k+=step32[dimindex]) \
1469 float tmpscale = (fieldname.find("Emissive")!=string::npos)? radiance_scales[k]: reflectance_scales[k]; \
1470 float tmpoffset = (fieldname.find("Emissive")!=string::npos)? radiance_offsets[k]: reflectance_offsets[k]; \
1471 for(size_t l=0; l<nr_elems; l++) \
1473 if(cf_vr_attrindex!=FAIL) \
1475 if(((float)tmptr[index])!=fillvalue) \
1477 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[index]))\
1479 if(sotype==MODIS_MUL_SCALE) \
1480 tmpval[index] = (tmptr[index]-tmpoffset)*tmpscale; \
1481 else if(sotype==MODIS_EQ_SCALE) \
1482 tmpval[index] = tmptr[index]*tmpscale+tmpoffset; \
1483 else if(sotype==MODIS_DIV_SCALE) \
1484 tmpval[index] = (tmptr[index]-tmpoffset)/tmpscale; \
1491 change_data_value = true; \
1492 set_value((dods_float32 *)&tmpval[0], nelms); \
1495 if(!change_data_value) \
1497 set_value ((DODS_CAST)VAL, nelms); \
1528 #define RECALCULATE(CAST, DODS_CAST, VAL) \
1530 bool change_data_value = false; \
1531 if(sotype!=DEFAULT_CF_EQU) \
1533 vector<float>tmpval; \
1534 tmpval.resize(nelms); \
1535 CAST tmptr = (CAST)VAL; \
1536 for(int l=0; l<nelms; l++) \
1537 tmpval[l] = (float)tmptr[l]; \
1538 bool special_case = false; \
1539 if(scale_factor_attr_index==FAIL) \
1540 if(num_eles_of_an_attr==1) \
1541 if((radiance_scales!=NULL) && (radiance_offsets!=NULL)) \
1543 scale = radiance_scales[0]; \
1544 field_offset = radiance_offsets[0];\
1545 special_case = true; \
1547 if(((scale_factor_attr_index!=FAIL) && !((scale==1) && (field_offset==0))) || special_case) \
1549 float temp_scale = scale; \
1550 float temp_offset = field_offset; \
1551 if(sotype==MODIS_MUL_SCALE) \
1552 temp_offset = -1. *field_offset*temp_scale;\
1553 else if (sotype==MODIS_DIV_SCALE) \
1555 temp_scale = 1/scale; \
1556 temp_offset = -1. *field_offset*temp_scale;\
1558 for(int l=0; l<nelms; l++) \
1560 if(cf_vr_attrindex!=FAIL) \
1562 if((float)tmptr[l] != fillvalue ) \
1564 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[l]))\
1566 if (((orig_valid_min<=tmpval[l]) && (orig_valid_max>=tmpval[l])) || (true==has_Key_attr))\
1568 tmpval[l] = tmptr[l]*temp_scale + temp_offset; \
1574 change_data_value = true; \
1575 set_value((dods_float32 *)&tmpval[0], nelms); \
1576 } else if((num_eles_of_an_attr>1) && (((radiance_scales!=NULL) && (radiance_offsets!=NULL)) || ((reflectance_scales!=NULL) && (reflectance_offsets!=NULL)))) \
1578 size_t dimindex=0; \
1579 if( num_eles_of_an_attr!=tmp_dims[dimindex]) \
1581 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets); \
1582 ostringstream eherr; \
1583 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."; \
1584 throw InternalErr (__FILE__, __LINE__, eherr.str ()); \
1586 size_t start_index, end_index; \
1587 size_t nr_elems = nelms/count32[dimindex]; \
1588 start_index = offset32[dimindex]; \
1589 end_index = start_index+step32[dimindex]*(count32[dimindex]-1); \
1591 for(size_t k=start_index; k<=end_index; k+=step32[dimindex]) \
1593 float tmpscale = (fieldname.find("Emissive")!=string::npos)? radiance_scales[k]: reflectance_scales[k]; \
1594 float tmpoffset = (fieldname.find("Emissive")!=string::npos)? radiance_offsets[k]: reflectance_offsets[k]; \
1595 for(size_t l=0; l<nr_elems; l++) \
1597 if(cf_vr_attrindex!=FAIL) \
1599 if(((float)tmptr[index])!=fillvalue) \
1601 if(false == HDFCFUtil::is_special_value(field_dtype,fillvalue,tmptr[index]))\
1603 if(sotype==MODIS_MUL_SCALE) \
1604 tmpval[index] = (tmptr[index]-tmpoffset)*tmpscale; \
1605 else if(sotype==MODIS_EQ_SCALE) \
1606 tmpval[index] = tmptr[index]*tmpscale+tmpoffset; \
1607 else if(sotype==MODIS_DIV_SCALE) \
1608 tmpval[index] = (tmptr[index]-tmpoffset)/tmpscale; \
1615 change_data_value = true; \
1616 set_value((dods_float32 *)&tmpval[0], nelms); \
1619 if(!change_data_value) \
1621 set_value ((DODS_CAST)VAL, nelms); \
1626 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1627 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1629 ostringstream eherr;
1631 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1632 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1635 cerr<<
"tmp_rank again is "<<tmp_rank <<endl;
1637 switch (field_dtype) {
1643 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1644 &offset32[0], &step32[0], &count32[0], &val[0]);
1646 release_mod1b_res(reflectance_scales,reflectance_offsets,
1647 radiance_scales,radiance_offsets);
1648 ostringstream eherr;
1649 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1650 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1653 #ifndef SIGNED_BYTE_TO_INT32
1654 RECALCULATE(int8*, dods_byte*, &val[0]);
1657 vector<int32>newval;
1658 newval.resize(nelms);
1660 for (
int counter = 0; counter < nelms; counter++)
1661 newval[counter] = (int32) (val[counter]);
1663 RECALCULATE(int32*, dods_int32*, &newval[0]);
1673 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1674 &offset32[0], &step32[0], &count32[0], &val[0]);
1676 release_mod1b_res(reflectance_scales,reflectance_offsets,
1677 radiance_scales,radiance_offsets);
1678 ostringstream eherr;
1680 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1681 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1684 RECALCULATE(uint8*, dods_byte*, &val[0]);
1692 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1693 &offset32[0], &step32[0], &count32[0], &val[0]);
1697 release_mod1b_res(reflectance_scales,reflectance_offsets,
1698 radiance_scales,radiance_offsets);
1699 ostringstream eherr;
1701 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1702 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1704 RECALCULATE(int16*, dods_int16*, &val[0]);
1712 cerr<<
"gridid is "<<gridid <<endl;
1714 char tmp_dimlist[1024];
1715 int32 tmp_dims[rank];
1716 int32 field_dtype = 0;
1719 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1720 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1722 ostringstream eherr;
1724 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1725 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1729 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1730 &offset32[0], &step32[0], &count32[0], &val[0]);
1732 release_mod1b_res(reflectance_scales,reflectance_offsets,
1733 radiance_scales,radiance_offsets);
1734 ostringstream eherr;
1736 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1737 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1740 RECALCULATE(uint16*, dods_uint16*, &val[0]);
1747 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1748 &offset32[0], &step32[0], &count32[0], &val[0]);
1751 release_mod1b_res(reflectance_scales,reflectance_offsets,
1752 radiance_scales,radiance_offsets);
1753 ostringstream eherr;
1755 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1756 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1759 RECALCULATE(int32*, dods_int32*, &val[0]);
1766 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1767 &offset32[0], &step32[0], &count32[0], &val[0]);
1770 release_mod1b_res(reflectance_scales,reflectance_offsets,
1771 radiance_scales,radiance_offsets);
1772 ostringstream eherr;
1774 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1775 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1778 RECALCULATE(uint32*, dods_uint32*, &val[0]);
1785 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1786 &offset32[0], &step32[0], &count32[0], &val[0]);
1789 release_mod1b_res(reflectance_scales,reflectance_offsets,
1790 radiance_scales,radiance_offsets);
1791 ostringstream eherr;
1793 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1794 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1798 RECALCULATE(float32*, dods_float32*, &val[0]);
1806 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1807 &offset32[0], &step32[0], &count32[0], &val[0]);
1810 release_mod1b_res(reflectance_scales,reflectance_offsets,
1811 radiance_scales,radiance_offsets);
1812 ostringstream eherr;
1814 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1815 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1817 set_value ((dods_float64 *) &val[0], nelms);
1821 release_mod1b_res(reflectance_scales,reflectance_offsets,
1822 radiance_scales,radiance_offsets);
1823 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1826 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
1828 if(reflectance_scales!=NULL)
1830 delete[] reflectance_offsets;
1831 delete[] reflectance_scales;
1834 if(radiance_scales!=NULL)
1836 delete[] radiance_offsets;
1837 delete[] radiance_scales;
1843 if (
true == isgeofile ||
false == check_pass_fileid_key)
1852 HDFEOS2Array_RealField::write_dap_data_disable_scale_comp(int32 gridid,
1860 "Coming to HDFEOS2_Array_RealField: write_dap_data_disable_scale_comp"
1864 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1865 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
1868 if (swathname ==
"") {
1869 fieldinfofunc = GDfieldinfo;
1870 readfieldfunc = GDreadfield;
1873 else if (gridname ==
"") {
1874 fieldinfofunc = SWfieldinfo;
1875 readfieldfunc = SWreadfield;
1879 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
1885 char tmp_dimlist[1024];
1888 int32 tmp_dims[rank];
1891 int32 field_dtype = 0;
1898 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1899 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1901 ostringstream eherr;
1902 eherr <<
"Field " << fieldname.c_str ()
1903 <<
" information cannot be obtained.";
1904 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1908 switch (field_dtype) {
1913 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1914 offset32, step32, count32, &val[0]);
1916 ostringstream eherr;
1917 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1918 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1921 #ifndef SIGNED_BYTE_TO_INT32
1922 set_value((dods_byte*)&val[0],nelms);
1925 vector<int32>newval;
1926 newval.resize(nelms);
1928 for (
int counter = 0; counter < nelms; counter++)
1929 newval[counter] = (int32) (val[counter]);
1931 set_value((dods_int32*)&newval[0],nelms);
1941 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1942 offset32, step32, count32, &val[0]);
1945 ostringstream eherr;
1946 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1947 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1950 set_value((dods_byte*)&val[0],nelms);
1958 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1959 offset32, step32, count32, &val[0]);
1962 ostringstream eherr;
1963 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1964 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1966 set_value((dods_int16*)&val[0],nelms);
1973 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1974 offset32, step32, count32, &val[0]);
1976 ostringstream eherr;
1977 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1978 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1981 set_value((dods_uint16*)&val[0],nelms);
1988 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1989 offset32, step32, count32, &val[0]);
1991 ostringstream eherr;
1992 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1993 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1996 set_value((dods_int32*)&val[0],nelms);
2003 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
2004 offset32, step32, count32, &val[0]);
2006 ostringstream eherr;
2007 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
2008 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2011 set_value((dods_uint32*)&val[0],nelms);
2018 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
2019 offset32, step32, count32, &val[0]);
2021 ostringstream eherr;
2022 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
2023 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2027 set_value((dods_float32*)&val[0],nelms);
2034 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
2035 offset32, step32, count32, &val[0]);
2037 ostringstream eherr;
2038 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
2039 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2041 set_value ((dods_float64 *) &val[0], nelms);
2045 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
2050 r = detachfunc (gridid);
2053 ostringstream eherr;
2055 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
2056 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2060 r = closefunc (gfid);
2062 ostringstream eherr;
2064 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
2065 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2075 HDFEOS2Array_RealField::format_constraint (
int *offset,
int *step,
int *count)
2080 Dim_iter p = dim_begin ();
2081 while (p != dim_end ()) {
2083 int start = dimension_start (p,
true);
2084 int stride = dimension_stride (p,
true);
2085 int stop = dimension_stop (p,
true);
2090 oss <<
"Array/Grid hyperslab start point "<< start <<
2091 " is greater than stop point " << stop <<
".";
2092 throw Error(malformed_expr, oss.str());
2097 count[id] = ((stop - start) / stride) + 1;
2101 "=format_constraint():"
2102 <<
"id=" <<
id <<
" offset=" << offset[
id]
2103 <<
" step=" << step[
id]
2104 <<
" count=" << count[
id]
2118 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
2119 bool check_pass_fileid_key =
false;
2120 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
2125 if(
true == isgeofile ||
false == HDF4RequestHandler::get_pass_fileid()) {
2141 void HDFEOS2Array_RealField::release_mod1b_res(
float*ref_scale,
2146 if(ref_scale != NULL)
2148 if(ref_offset != NULL)
2149 delete[] ref_offset;
2150 if(rad_scale != NULL)
2152 if(rad_offset != NULL)
2153 delete[] rad_offset;
void close_fileid(hid_t fid)