13 #include "InternalErr.h"
17 #include "HDFCFUtil.h"
18 #include "HDFEOS2Array_RealField.h"
20 #include "HDF4RequestHandler.h"
25 #define SIGNED_BYTE_TO_INT32 1
28 HDFEOS2Array_RealField::read ()
31 BESDEBUG(
"h4",
"Coming to HDFEOS2_Array_RealField read "<<endl);
36 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
37 bool check_pass_fileid_key =
false;
38 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
41 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
53 nelms = format_constraint (&offset[0], &step[0], &count[0]);
56 vector<int32>offset32;
57 offset32.resize(rank);
64 for (
int i = 0; i < rank; i++) {
65 offset32[i] = (int32) offset[i];
66 count32[i] = (int32) count[i];
67 step32[i] = (int32) step[i];
71 int32 (*openfunc) (
char *, intn);
72 intn (*closefunc) (int32);
73 int32 (*attachfunc) (int32,
char *);
74 intn (*detachfunc) (int32);
75 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
78 if (swathname ==
"") {
81 attachfunc = GDattach;
82 detachfunc = GDdetach;
83 fieldinfofunc = GDfieldinfo;
84 datasetname = gridname;
86 else if (gridname ==
"") {
89 attachfunc = SWattach;
90 detachfunc = SWdetach;
91 fieldinfofunc = SWfieldinfo;
92 datasetname = swathname;
95 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
101 if (
true == isgeofile ||
false == check_pass_fileid_key) {
104 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
107 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
108 throw InternalErr (__FILE__, __LINE__, eherr.str ());
115 gridid = attachfunc (gfid,
const_cast < char *
>(datasetname.c_str ()));
119 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be attached.";
120 throw InternalErr (__FILE__, __LINE__, eherr.str ());
124 string check_disable_scale_comp_key =
"H4.DisableScaleOffsetComp";
125 bool turn_on_disable_scale_comp_key=
false;
126 turn_on_disable_scale_comp_key = HDFCFUtil::check_beskeys(check_disable_scale_comp_key);
130 bool is_modis_l1b =
false;
131 if(
"MODIS_SWATH_Type_L1B" == swathname)
134 bool is_modis_vip =
false;
135 if (
"VIP_CMG_GRID" == gridname)
138 bool field_is_vdata =
false;
149 char tmp_dimlist[1024];
150 int32 tmp_dims[rank];
151 int32 field_dtype = 0;
154 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
155 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
161 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
162 throw InternalErr (__FILE__, __LINE__, eherr.str ());
166 field_is_vdata =
true;
170 bool has_Key_attr =
false;
172 if (
false == field_is_vdata) {
177 if (
true == isgeofile ||
false == check_pass_fileid_key) {
179 sdfileid = SDstart(
const_cast < char *
>(filename.c_str ()), DFACC_READ);
181 if (FAIL == sdfileid) {
185 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
193 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
194 if (FAIL == sdsindex) {
198 eherr <<
"Cannot obtain the index of " << fieldname;
199 throw InternalErr (__FILE__, __LINE__, eherr.str ());
202 sdsid = SDselect(sdfileid, sdsindex);
207 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
208 throw InternalErr (__FILE__, __LINE__, eherr.str ());
217 if(SDfindattr(sdsid,
"Key")!=FAIL)
222 if (
true == isgeofile ||
false == check_pass_fileid_key)
228 if((
false == is_modis_l1b) && (
false == is_modis_vip)
229 &&(
false == has_Key_attr) && (
true == HDF4RequestHandler::get_disable_scaleoffset_comp()))
230 write_dap_data_disable_scale_comp(gridid,nelms,&offset32[0],&count32[0],&step32[0]);
232 write_dap_data_scale_comp(gridid,nelms,offset32,count32,step32);
241 r = detachfunc (gridid);
245 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
246 throw InternalErr (__FILE__, __LINE__, eherr.str ());
250 if(
true == isgeofile ||
false == check_pass_fileid_key) {
251 r = closefunc (gfid);
254 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
255 throw InternalErr (__FILE__, __LINE__, eherr.str ());
263 HDFEOS2Array_RealField::write_dap_data_scale_comp(int32 gridid,
265 vector<int32>& offset32,
266 vector<int32>& count32,
267 vector<int32>& step32) {
271 "coming to HDFEOS2Array_RealField write_dap_data_scale_comp "
275 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
276 bool check_pass_fileid_key =
false;
277 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
279 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
282 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
283 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
286 if (swathname ==
"") {
287 fieldinfofunc = GDfieldinfo;
288 readfieldfunc = GDreadfield;
290 else if (gridname ==
"") {
291 fieldinfofunc = SWfieldinfo;
292 readfieldfunc = SWreadfield;
295 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
299 char tmp_dimlist[1024];
302 int32 tmp_dims[rank];
305 int32 field_dtype = 0;
312 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
313 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
317 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
318 throw InternalErr (__FILE__, __LINE__, eherr.str ());
328 float *reflectance_offsets =NULL;
329 float *reflectance_scales =NULL;
330 float *radiance_offsets =NULL;
331 float *radiance_scales =NULL;
334 int32 attr_dtype = 0;
337 int32 temp_attrcount = 0;
340 int32 num_eles_of_an_attr = 0;
343 int32 cf_modl1b_rr_attrindex = 0;
346 int32 cf_modl1b_rr_attrindex2 = 0;
349 int32 cf_vr_attrindex = 0;
352 int32 cf_fv_attrindex = 0;
355 int32 scale_factor_attr_index = 0;
358 int32 add_offset_attr_index = 0;
364 float field_offset = 0;
370 float orig_valid_min = 0;
373 float orig_valid_max = 0;
380 bool has_Key_attr =
false;
383 if(sotype!=DEFAULT_CF_EQU) {
385 bool field_is_vdata =
false;
398 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
399 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
402 eherr <<
"Field " << fieldname.c_str ()
403 <<
" information cannot be obtained.";
404 throw InternalErr (__FILE__, __LINE__, eherr.str ());
408 field_is_vdata =
true;
412 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
413 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
417 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
418 throw InternalErr (__FILE__, __LINE__, eherr.str ());
421 cerr<<
"tmp_rank is "<<tmp_rank <<endl;
432 if(
false == field_is_vdata) {
434 char attrname[H4_MAX_NC_NAME + 1];
435 vector<char> attrbuf;
438 if(
false == isgeofile ||
false == check_pass_fileid_key)
441 sdfileid = SDstart(
const_cast < char *
>(filename.c_str ()), DFACC_READ);
442 if (FAIL == sdfileid) {
444 eherr <<
"Cannot Start the SD interface for the file "
446 throw InternalErr (__FILE__, __LINE__, eherr.str ());
452 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
453 if (FAIL == sdsindex) {
454 if(
true == isgeofile ||
false == check_pass_fileid_key)
457 eherr <<
"Cannot obtain the index of " << fieldname;
458 throw InternalErr (__FILE__, __LINE__, eherr.str ());
461 sdsid = SDselect(sdfileid, sdsindex);
463 if (
true == isgeofile ||
false == check_pass_fileid_key)
466 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
467 throw InternalErr (__FILE__, __LINE__, eherr.str ());
471 char attrname[H4_MAX_NC_NAME + 1];
472 vector<char> attrbuf, attrbuf2;
479 cf_general_attrindex = SDfindattr(sdsid,
"radiance_scales");
480 cf_general_attrindex2 = SDfindattr(sdsid,
"radiance_offsets");
483 if(cf_general_attrindex!=FAIL && cf_general_attrindex2!=FAIL)
486 ret = SDattrinfo(sdsid, cf_general_attrindex, attrname, &attr_dtype, &temp_attrcount);
490 if(
true == isgeofile)
493 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
494 throw InternalErr (__FILE__, __LINE__, eherr.str ());
497 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
498 ret = SDreadattr(sdsid, cf_general_attrindex, (VOIDP)&attrbuf[0]);
501 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
503 if (
true == isgeofile)
506 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
507 throw InternalErr (__FILE__, __LINE__, eherr.str ());
509 ret = SDattrinfo(sdsid, cf_general_attrindex2, attrname, &attr_dtype, &temp_attrcount);
512 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
514 if(
true == isgeofile)
517 eherr <<
"Attribute 'radiance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
518 throw InternalErr (__FILE__, __LINE__, eherr.str ());
521 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
522 ret = SDreadattr(sdsid, cf_general_attrindex2, (VOIDP)&attrbuf2[0]);
525 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
527 if(
true == isgeofile)
530 eherr <<
"Attribute 'radiance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
531 throw InternalErr (__FILE__, __LINE__, eherr.str ());
538 #define GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
541 CAST *ptr = (CAST*)&attrbuf[0]; \
542 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
543 radiance_scales = new float[temp_attrcount]; \
544 radiance_offsets = new float[temp_attrcount]; \
545 for(int l=0; l<temp_attrcount; l++) \
547 radiance_scales[l] = ptr[l]; \
548 radiance_offsets[l] = ptr2[l]; \
552 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
553 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
555 #undef GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES
556 num_eles_of_an_attr = temp_attrcount;
560 cf_general_attrindex = SDfindattr(sdsid,
"reflectance_scales");
561 cf_general_attrindex2 = SDfindattr(sdsid,
"reflectance_offsets");
562 if(cf_general_attrindex!=FAIL && cf_general_attrindex2!=FAIL)
565 ret = SDattrinfo(sdsid, cf_general_attrindex, attrname, &attr_dtype, &temp_attrcount);
568 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
570 if(
true == isgeofile)
573 eherr <<
"Attribute 'reflectance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
574 throw InternalErr (__FILE__, __LINE__, eherr.str ());
577 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
578 ret = SDreadattr(sdsid, cf_general_attrindex, (VOIDP)&attrbuf[0]);
581 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
583 if(
true == isgeofile)
586 eherr <<
"Attribute 'reflectance_scales' in " << fieldname.c_str () <<
" cannot be obtained.";
587 throw InternalErr (__FILE__, __LINE__, eherr.str ());
590 ret = SDattrinfo(sdsid, cf_general_attrindex2, attrname, &attr_dtype, &temp_attrcount);
593 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
595 if(
true == isgeofile)
598 eherr <<
"Attribute 'reflectance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
599 throw InternalErr (__FILE__, __LINE__, eherr.str ());
602 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
603 ret = SDreadattr(sdsid, cf_general_attrindex2, (VOIDP)&attrbuf2[0]);
606 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
608 if(
true == isgeofile)
611 eherr <<
"Attribute 'reflectance_offsets' in " << fieldname.c_str () <<
" cannot be obtained.";
612 throw InternalErr (__FILE__, __LINE__, eherr.str ());
616 #define GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
619 CAST *ptr = (CAST*)&attrbuf[0]; \
620 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
621 reflectance_scales = new float[temp_attrcount]; \
622 reflectance_offsets = new float[temp_attrcount]; \
623 for(int l=0; l<temp_attrcount; l++) \
625 reflectance_scales[l] = ptr[l]; \
626 reflectance_offsets[l] = ptr2[l]; \
630 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
631 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
633 #undef GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES
634 num_eles_of_an_attr = temp_attrcount;
639 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
640 if(scale_factor_attr_index!=FAIL)
643 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname,
644 &attr_dtype, &temp_attrcount);
648 if(
true == isgeofile ||
false == check_pass_fileid_key)
651 eherr <<
"Attribute 'scale_factor' in "
652 << fieldname.c_str () <<
" cannot be obtained.";
653 throw InternalErr (__FILE__, __LINE__, eherr.str ());
656 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
657 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)&attrbuf[0]);
661 if(
true == isgeofile ||
false == check_pass_fileid_key)
665 eherr <<
"Attribute 'scale_factor' in "
666 << fieldname.c_str () <<
" cannot be obtained.";
667 throw InternalErr (__FILE__, __LINE__, eherr.str ());
672 #define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
675 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
676 scale = (float)tmpvalue; \
679 GET_SCALE_FACTOR_ATTR_VALUE(INT8, int8);
680 GET_SCALE_FACTOR_ATTR_VALUE(CHAR,int8);
681 GET_SCALE_FACTOR_ATTR_VALUE(UINT8, uint8);
682 GET_SCALE_FACTOR_ATTR_VALUE(UCHAR,uint8);
683 GET_SCALE_FACTOR_ATTR_VALUE(INT16, int16);
684 GET_SCALE_FACTOR_ATTR_VALUE(UINT16, uint16);
685 GET_SCALE_FACTOR_ATTR_VALUE(INT32, int32);
686 GET_SCALE_FACTOR_ATTR_VALUE(UINT32, uint32);
687 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float);
688 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double);
690 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
694 #undef GET_SCALE_FACTOR_ATTR_VALUE
698 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
699 if(add_offset_attr_index!=FAIL)
702 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname,
703 &attr_dtype, &temp_attrcount);
707 if(
true == isgeofile ||
false == check_pass_fileid_key)
711 eherr <<
"Attribute 'add_offset' in " << fieldname.c_str ()
712 <<
" cannot be obtained.";
713 throw InternalErr (__FILE__, __LINE__, eherr.str ());
716 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
717 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)&attrbuf[0]);
721 if(
true == isgeofile ||
false == check_pass_fileid_key)
725 eherr <<
"Attribute 'add_offset' in " << fieldname.c_str ()
726 <<
" cannot be obtained.";
727 throw InternalErr (__FILE__, __LINE__, eherr.str ());
732 #define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
735 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
736 field_offset = (float)tmpvalue; \
739 GET_ADD_OFFSET_ATTR_VALUE(INT8, int8);
740 GET_ADD_OFFSET_ATTR_VALUE(CHAR,int8);
741 GET_ADD_OFFSET_ATTR_VALUE(UINT8, uint8);
742 GET_ADD_OFFSET_ATTR_VALUE(UCHAR,uint8);
743 GET_ADD_OFFSET_ATTR_VALUE(INT16, int16);
744 GET_ADD_OFFSET_ATTR_VALUE(UINT16, uint16);
745 GET_ADD_OFFSET_ATTR_VALUE(INT32, int32);
746 GET_ADD_OFFSET_ATTR_VALUE(UINT32, uint32);
747 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float);
748 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double);
750 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
753 #undef GET_ADD_OFFSET_ATTR_VALUE
757 cf_fv_attrindex = SDfindattr(sdsid,
"_FillValue");
758 if(cf_fv_attrindex!=FAIL)
761 ret = SDattrinfo(sdsid, cf_fv_attrindex, attrname, &attr_dtype, &temp_attrcount);
765 if(
true == isgeofile ||
false == check_pass_fileid_key)
769 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
770 <<
" cannot be obtained.";
771 throw InternalErr (__FILE__, __LINE__, eherr.str ());
774 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
775 ret = SDreadattr(sdsid, cf_fv_attrindex, (VOIDP)&attrbuf[0]);
779 if(
true == isgeofile ||
false == check_pass_fileid_key)
783 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
784 <<
" cannot be obtained.";
785 throw InternalErr (__FILE__, __LINE__, eherr.str ());
790 #define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
793 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
794 fillvalue = (float)tmpvalue; \
797 GET_FILLVALUE_ATTR_VALUE(INT8, int8);
798 GET_FILLVALUE_ATTR_VALUE(CHAR, int8);
799 GET_FILLVALUE_ATTR_VALUE(INT16, int16);
800 GET_FILLVALUE_ATTR_VALUE(INT32, int32);
801 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8);
802 GET_FILLVALUE_ATTR_VALUE(UCHAR, uint8);
803 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16);
804 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32);
806 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
809 #undef GET_FILLVALUE_ATTR_VALUE
815 cf_vr_attrindex = SDfindattr(sdsid,
"valid_range");
816 if(cf_vr_attrindex!=FAIL)
819 ret = SDattrinfo(sdsid, cf_vr_attrindex, attrname, &attr_dtype, &temp_attrcount);
823 if(
true == isgeofile ||
false == check_pass_fileid_key)
827 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
828 <<
" cannot be obtained.";
829 throw InternalErr (__FILE__, __LINE__, eherr.str ());
832 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
833 ret = SDreadattr(sdsid, cf_vr_attrindex, (VOIDP)&attrbuf[0]);
837 if(
true == isgeofile ||
false == check_pass_fileid_key)
841 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str ()
842 <<
" cannot be obtained.";
843 throw InternalErr (__FILE__, __LINE__, eherr.str ());
847 string attrbuf_str(attrbuf.begin(),attrbuf.end());
855 size_t found = attrbuf_str.find_first_of(
",");
856 size_t found_from_end = attrbuf_str.find_last_of(
",");
858 if (string::npos == found){
860 if(
true == isgeofile ||
false == check_pass_fileid_key)
862 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
864 if (found != found_from_end){
866 if(
true == isgeofile ||
false == check_pass_fileid_key)
868 throw InternalErr(__FILE__,__LINE__,
869 "Only one separator , should be available.");
877 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
878 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
892 if (temp_attrcount >2) {
894 size_t found = attrbuf_str.find_first_of(
",");
895 size_t found_from_end = attrbuf_str.find_last_of(
",");
897 if (string::npos == found){
899 if(
true == isgeofile ||
false == check_pass_fileid_key)
901 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
903 if (found != found_from_end){
905 if(
true == isgeofile ||
false == check_pass_fileid_key)
907 throw InternalErr(__FILE__,__LINE__,
908 "Only one separator , should be available.");
914 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
915 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
918 else if (2 == temp_attrcount) {
919 orig_valid_min = (float)attrbuf[0];
920 orig_valid_max = (float)attrbuf[1];
924 if(
true == isgeofile ||
false == check_pass_fileid_key)
926 throw InternalErr(__FILE__,__LINE__,
927 "The number of attribute count should be greater than 1.");
936 if (temp_attrcount != 2) {
938 if(
true == isgeofile ||
false == check_pass_fileid_key)
941 throw InternalErr(__FILE__,__LINE__,
942 "The number of attribute count should be 2 for the DFNT_UINT8 type.");
945 unsigned char* temp_valid_range = (
unsigned char *)&attrbuf[0];
946 orig_valid_min = (float)(temp_valid_range[0]);
947 orig_valid_max = (float)(temp_valid_range[1]);
953 if (temp_attrcount != 2) {
955 if(
true == isgeofile ||
false == check_pass_fileid_key)
958 throw InternalErr(__FILE__,__LINE__,
959 "The number of attribute count should be 2 for the DFNT_INT16 type.");
962 short* temp_valid_range = (
short *)&attrbuf[0];
963 orig_valid_min = (float)(temp_valid_range[0]);
964 orig_valid_max = (float)(temp_valid_range[1]);
970 if (temp_attrcount != 2) {
972 if(
true == isgeofile ||
false == check_pass_fileid_key)
975 throw InternalErr(__FILE__,__LINE__,
976 "The number of attribute count should be 2 for the DFNT_UINT16 type.");
979 unsigned short* temp_valid_range = (
unsigned short *)&attrbuf[0];
980 orig_valid_min = (float)(temp_valid_range[0]);
981 orig_valid_max = (float)(temp_valid_range[1]);
987 if (temp_attrcount != 2) {
989 if(
true == isgeofile ||
false == check_pass_fileid_key)
992 throw InternalErr(__FILE__,__LINE__,
993 "The number of attribute count should be 2 for the DFNT_INT32 type.");
996 int* temp_valid_range = (
int *)&attrbuf[0];
997 orig_valid_min = (float)(temp_valid_range[0]);
998 orig_valid_max = (float)(temp_valid_range[1]);
1004 if (temp_attrcount != 2) {
1006 if(
true == isgeofile ||
false == check_pass_fileid_key)
1009 throw InternalErr(__FILE__,__LINE__,
1010 "The number of attribute count should be 2 for the DFNT_UINT32 type.");
1013 unsigned int* temp_valid_range = (
unsigned int *)&attrbuf[0];
1014 orig_valid_min = (float)(temp_valid_range[0]);
1015 orig_valid_max = (float)(temp_valid_range[1]);
1021 if (temp_attrcount != 2) {
1023 if(
true == isgeofile ||
false == check_pass_fileid_key)
1026 throw InternalErr(__FILE__,__LINE__,
1027 "The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
1030 float* temp_valid_range = (
float *)&attrbuf[0];
1031 orig_valid_min = temp_valid_range[0];
1032 orig_valid_max = temp_valid_range[1];
1038 if (temp_attrcount != 2){
1040 if(
true == isgeofile ||
false == check_pass_fileid_key)
1043 throw InternalErr(__FILE__,__LINE__,
1044 "The number of attribute count should be 2 for the DFNT_FLOAT64 type.");
1046 double* temp_valid_range = (
double *)&attrbuf[0];
1053 orig_valid_min = temp_valid_range[0];
1054 orig_valid_max = temp_valid_range[1];
1059 if(
true == isgeofile ||
false == check_pass_fileid_key)
1061 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
1071 int32 cf_mod_key_attrindex = SUCCEED;
1072 cf_mod_key_attrindex = SDfindattr(sdsid,
"Key");
1073 if(cf_mod_key_attrindex !=FAIL) {
1074 has_Key_attr =
true;
1078 vector<char> attrbuf2;
1086 cf_modl1b_rr_attrindex = SDfindattr(sdsid,
"radiance_scales");
1087 cf_modl1b_rr_attrindex2 = SDfindattr(sdsid,
"radiance_offsets");
1090 if(cf_modl1b_rr_attrindex!=FAIL && cf_modl1b_rr_attrindex2!=FAIL)
1093 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex, attrname,
1094 &attr_dtype, &temp_attrcount);
1098 if(
true == isgeofile ||
false == check_pass_fileid_key)
1100 ostringstream eherr;
1101 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str ()
1102 <<
" cannot be obtained.";
1103 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1106 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1107 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex, (VOIDP)&attrbuf[0]);
1111 if (
true == isgeofile ||
false == check_pass_fileid_key)
1113 ostringstream eherr;
1114 eherr <<
"Attribute 'radiance_scales' in " << fieldname.c_str ()
1115 <<
" cannot be obtained.";
1116 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1118 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex2, attrname,
1119 &attr_dtype, &temp_attrcount);
1123 if(
true == isgeofile ||
false == check_pass_fileid_key)
1125 ostringstream eherr;
1126 eherr <<
"Attribute 'radiance_offsets' in "
1127 << fieldname.c_str () <<
" cannot be obtained.";
1128 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1131 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1132 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex2, (VOIDP)&attrbuf2[0]);
1136 if(
true == isgeofile ||
false == check_pass_fileid_key)
1138 ostringstream eherr;
1139 eherr <<
"Attribute 'radiance_offsets' in "
1140 << fieldname.c_str () <<
" cannot be obtained.";
1141 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1149 #define GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
1152 CAST *ptr = (CAST*)&attrbuf[0]; \
1153 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
1154 radiance_scales = new float[temp_attrcount]; \
1155 radiance_offsets = new float[temp_attrcount]; \
1156 for(int l=0; l<temp_attrcount; l++) \
1158 radiance_scales[l] = ptr[l]; \
1159 radiance_offsets[l] = ptr2[l]; \
1163 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
1164 GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
1166 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1169 #undef GET_RADIANCE_SCALES_OFFSETS_ATTR_VALUES
1171 num_eles_of_an_attr = temp_attrcount;
1176 cf_modl1b_rr_attrindex = SDfindattr(sdsid,
"reflectance_scales");
1177 cf_modl1b_rr_attrindex2 = SDfindattr(sdsid,
"reflectance_offsets");
1178 if(cf_modl1b_rr_attrindex!=FAIL && cf_modl1b_rr_attrindex2!=FAIL)
1181 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex, attrname,
1182 &attr_dtype, &temp_attrcount);
1185 release_mod1b_res(reflectance_scales,reflectance_offsets,
1186 radiance_scales,radiance_offsets);
1188 if(
true == isgeofile ||
false == check_pass_fileid_key)
1190 ostringstream eherr;
1191 eherr <<
"Attribute 'reflectance_scales' in "
1192 << fieldname.c_str () <<
" cannot be obtained.";
1193 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1196 attrbuf.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1197 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex, (VOIDP)&attrbuf[0]);
1200 release_mod1b_res(reflectance_scales,reflectance_offsets,
1201 radiance_scales,radiance_offsets);
1203 if(
true == isgeofile ||
false == check_pass_fileid_key)
1205 ostringstream eherr;
1206 eherr <<
"Attribute 'reflectance_scales' in "
1207 << fieldname.c_str () <<
" cannot be obtained.";
1208 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1211 ret = SDattrinfo(sdsid, cf_modl1b_rr_attrindex2, attrname,
1212 &attr_dtype, &temp_attrcount);
1215 release_mod1b_res(reflectance_scales,reflectance_offsets,
1216 radiance_scales,radiance_offsets);
1218 if(
true == isgeofile ||
false == check_pass_fileid_key)
1220 ostringstream eherr;
1221 eherr <<
"Attribute 'reflectance_offsets' in "
1222 << fieldname.c_str () <<
" cannot be obtained.";
1223 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1226 attrbuf2.resize(DFKNTsize(attr_dtype)*temp_attrcount);
1227 ret = SDreadattr(sdsid, cf_modl1b_rr_attrindex2, (VOIDP)&attrbuf2[0]);
1230 release_mod1b_res(reflectance_scales,reflectance_offsets,
1231 radiance_scales,radiance_offsets);
1233 if(
true == isgeofile ||
false == check_pass_fileid_key)
1235 ostringstream eherr;
1236 eherr <<
"Attribute 'reflectance_offsets' in "
1237 << fieldname.c_str () <<
" cannot be obtained.";
1238 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1242 #define GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(TYPE, CAST) \
1245 CAST *ptr = (CAST*)&attrbuf[0]; \
1246 CAST *ptr2 = (CAST*)&attrbuf2[0]; \
1247 reflectance_scales = new float[temp_attrcount]; \
1248 reflectance_offsets = new float[temp_attrcount]; \
1249 for(int l=0; l<temp_attrcount; l++) \
1251 reflectance_scales[l] = ptr[l]; \
1252 reflectance_offsets[l] = ptr2[l]; \
1256 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT32,
float);
1257 GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES(FLOAT64,
double);
1259 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1262 #undef GET_REFLECTANCE_SCALES_OFFSETS_ATTR_VALUES
1263 num_eles_of_an_attr = temp_attrcount;
1269 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1270 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1272 ostringstream eherr;
1274 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1275 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1278 cerr<<
"tmp_rank 3 is "<<tmp_rank <<endl;
1284 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1285 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1287 ostringstream eherr;
1289 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1290 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1293 cerr<<
"tmp_rank 4 is "<<tmp_rank <<endl;
1296 BESDEBUG(
"h4",
"scale is "<<scale <<endl);
1297 BESDEBUG(
"h4",
"offset is "<<field_offset <<endl);
1298 BESDEBUG(
"h4",
"fillvalue is "<<fillvalue <<endl);
1327 if (MODIS_EQ_SCALE == sotype || MODIS_MUL_SCALE == sotype) {
1329 bool need_change_scale =
true;
1332 string temp_filename;
1333 if (filename.find(
"#") != string::npos)
1334 temp_filename =filename.substr(filename.find_last_of(
"#") + 1);
1336 temp_filename = filename.substr(filename.find_last_of(
"/") +1);
1338 if ((temp_filename.size() >5) && ((temp_filename.compare(0,5,
"MOD09") == 0)
1339 ||(temp_filename.compare(0,5,
"MYD09") == 0))) {
1340 if ((fieldname.size() >5) && fieldname.compare(0,5,
"Range") == 0)
1341 need_change_scale =
false;
1344 else if((temp_filename.size() >7)&&
1345 ((temp_filename.compare(0,7,
"MOD16A2") == 0)|| (temp_filename.compare(0,7,
"MYD16A2")==0)||
1346 (temp_filename.compare(0,7,
"MOD16A3") == 0)|| (temp_filename.compare(0,7,
"MYD16A3")==0)))
1347 need_change_scale =
false;
1351 if(
true == need_change_scale) {
1352 sotype = MODIS_DIV_SCALE;
1354 <<
"The field " << fieldname <<
" scale factor is "
1355 << scale <<
" ."<<endl
1356 <<
" But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1358 <<
" Now change it to MODIS_DIV_SCALE. "<<endl;
1363 if (MODIS_DIV_SCALE == sotype) {
1365 sotype = MODIS_MUL_SCALE;
1366 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1367 << scale <<
" ."<<endl
1368 <<
" But the original scale factor type is MODIS_DIV_SCALE. "
1370 <<
" Now change it to MODIS_MUL_SCALE. "<<endl;
1374 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1376 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1378 ostringstream eherr;
1380 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1381 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1384 cerr<<
"tmp_rank 2 is "<<tmp_rank <<endl;
1623 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1625 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1627 ostringstream eherr;
1629 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1630 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1633 cerr<<
"tmp_rank again is "<<tmp_rank <<endl;
1635 switch (field_dtype) {
1641 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1642 &offset32[0], &step32[0], &count32[0], &val[0]);
1644 release_mod1b_res(reflectance_scales,reflectance_offsets,
1645 radiance_scales,radiance_offsets);
1646 ostringstream eherr;
1647 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1648 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1651 #ifndef SIGNED_BYTE_TO_INT32
1652 RECALCULATE(int8*, dods_byte*, &val[0]);
1655 vector<int32>newval;
1656 newval.resize(nelms);
1658 for (
int counter = 0; counter < nelms; counter++)
1659 newval[counter] = (int32) (val[counter]);
1661 RECALCULATE(int32*, dods_int32*, &newval[0]);
1671 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1672 &offset32[0], &step32[0], &count32[0], &val[0]);
1674 release_mod1b_res(reflectance_scales,reflectance_offsets,
1675 radiance_scales,radiance_offsets);
1676 ostringstream eherr;
1678 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1679 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1682 RECALCULATE(uint8*, dods_byte*, &val[0]);
1690 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1691 &offset32[0], &step32[0], &count32[0], &val[0]);
1695 release_mod1b_res(reflectance_scales,reflectance_offsets,
1696 radiance_scales,radiance_offsets);
1697 ostringstream eherr;
1699 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1700 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1702 RECALCULATE(int16*, dods_int16*, &val[0]);
1710 cerr<<
"gridid is "<<gridid <<endl;
1712 char tmp_dimlist[1024];
1713 int32 tmp_dims[rank];
1714 int32 field_dtype = 0;
1717 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1718 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1720 ostringstream eherr;
1722 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1723 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1727 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1728 &offset32[0], &step32[0], &count32[0], &val[0]);
1730 release_mod1b_res(reflectance_scales,reflectance_offsets,
1731 radiance_scales,radiance_offsets);
1732 ostringstream eherr;
1734 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1735 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1738 RECALCULATE(uint16*, dods_uint16*, &val[0]);
1745 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1746 &offset32[0], &step32[0], &count32[0], &val[0]);
1749 release_mod1b_res(reflectance_scales,reflectance_offsets,
1750 radiance_scales,radiance_offsets);
1751 ostringstream eherr;
1753 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1754 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1757 RECALCULATE(int32*, dods_int32*, &val[0]);
1764 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1765 &offset32[0], &step32[0], &count32[0], &val[0]);
1768 release_mod1b_res(reflectance_scales,reflectance_offsets,
1769 radiance_scales,radiance_offsets);
1770 ostringstream eherr;
1772 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1773 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1776 RECALCULATE(uint32*, dods_uint32*, &val[0]);
1783 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1784 &offset32[0], &step32[0], &count32[0], &val[0]);
1787 release_mod1b_res(reflectance_scales,reflectance_offsets,
1788 radiance_scales,radiance_offsets);
1789 ostringstream eherr;
1791 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1792 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1796 RECALCULATE(float32*, dods_float32*, &val[0]);
1804 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1805 &offset32[0], &step32[0], &count32[0], &val[0]);
1808 release_mod1b_res(reflectance_scales,reflectance_offsets,
1809 radiance_scales,radiance_offsets);
1810 ostringstream eherr;
1812 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1813 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1815 set_value ((dods_float64 *) &val[0], nelms);
1819 release_mod1b_res(reflectance_scales,reflectance_offsets,
1820 radiance_scales,radiance_offsets);
1821 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1824 release_mod1b_res(reflectance_scales,reflectance_offsets,radiance_scales,radiance_offsets);
1826 if(reflectance_scales!=NULL)
1828 delete[] reflectance_offsets;
1829 delete[] reflectance_scales;
1832 if(radiance_scales!=NULL)
1834 delete[] radiance_offsets;
1835 delete[] radiance_scales;
1841 if (
true == isgeofile ||
false == check_pass_fileid_key)
1850 HDFEOS2Array_RealField::write_dap_data_disable_scale_comp(int32 gridid,
1858 "Coming to HDFEOS2_Array_RealField: write_dap_data_disable_scale_comp"
1862 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1863 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
1866 if (swathname ==
"") {
1867 fieldinfofunc = GDfieldinfo;
1868 readfieldfunc = GDreadfield;
1871 else if (gridname ==
"") {
1872 fieldinfofunc = SWfieldinfo;
1873 readfieldfunc = SWreadfield;
1877 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
1883 char tmp_dimlist[1024];
1886 int32 tmp_dims[rank];
1889 int32 field_dtype = 0;
1896 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1897 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1899 ostringstream eherr;
1900 eherr <<
"Field " << fieldname.c_str ()
1901 <<
" information cannot be obtained.";
1902 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1906 switch (field_dtype) {
1911 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1912 offset32, step32, count32, &val[0]);
1914 ostringstream eherr;
1915 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1916 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1919 #ifndef SIGNED_BYTE_TO_INT32
1920 set_value((dods_byte*)&val[0],nelms);
1923 vector<int32>newval;
1924 newval.resize(nelms);
1926 for (
int counter = 0; counter < nelms; counter++)
1927 newval[counter] = (int32) (val[counter]);
1929 set_value((dods_int32*)&newval[0],nelms);
1939 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1940 offset32, step32, count32, &val[0]);
1943 ostringstream eherr;
1944 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1945 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1948 set_value((dods_byte*)&val[0],nelms);
1956 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1957 offset32, step32, count32, &val[0]);
1960 ostringstream eherr;
1961 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1962 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1964 set_value((dods_int16*)&val[0],nelms);
1971 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1972 offset32, step32, count32, &val[0]);
1974 ostringstream eherr;
1975 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1976 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1979 set_value((dods_uint16*)&val[0],nelms);
1986 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
1987 offset32, step32, count32, &val[0]);
1989 ostringstream eherr;
1990 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1991 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1994 set_value((dods_int32*)&val[0],nelms);
2001 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
2002 offset32, step32, count32, &val[0]);
2004 ostringstream eherr;
2005 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
2006 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2009 set_value((dods_uint32*)&val[0],nelms);
2016 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
2017 offset32, step32, count32, &val[0]);
2019 ostringstream eherr;
2020 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
2021 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2025 set_value((dods_float32*)&val[0],nelms);
2032 r = readfieldfunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
2033 offset32, step32, count32, &val[0]);
2035 ostringstream eherr;
2036 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
2037 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2039 set_value ((dods_float64 *) &val[0], nelms);
2043 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
2048 r = detachfunc (gridid);
2051 ostringstream eherr;
2053 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
2054 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2058 r = closefunc (gfid);
2060 ostringstream eherr;
2062 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
2063 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2073 HDFEOS2Array_RealField::format_constraint (
int *offset,
int *step,
int *count)
2078 Dim_iter p = dim_begin ();
2079 while (p != dim_end ()) {
2081 int start = dimension_start (p,
true);
2082 int stride = dimension_stride (p,
true);
2083 int stop = dimension_stop (p,
true);
2088 oss <<
"Array/Grid hyperslab start point "<< start <<
2089 " is greater than stop point " << stop <<
".";
2090 throw Error(malformed_expr, oss.str());
2095 count[id] = ((stop - start) / stride) + 1;
2099 "=format_constraint():"
2100 <<
"id=" <<
id <<
" offset=" << offset[
id]
2101 <<
" step=" << step[
id]
2102 <<
" count=" << count[
id]
2116 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
2117 bool check_pass_fileid_key =
false;
2118 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
2123 if(
true == isgeofile ||
false == HDF4RequestHandler::get_pass_fileid()) {
2139 void HDFEOS2Array_RealField::release_mod1b_res(
float*ref_scale,
2144 if(ref_scale != NULL)
2146 if(ref_offset != NULL)
2147 delete[] ref_offset;
2148 if(rad_scale != NULL)
2150 if(rad_offset != NULL)
2151 delete[] rad_offset;