16 #ifdef USE_HDFEOS2_LIB
22 #include "InternalErr.h"
25 #include "HDFEOS2ArraySwathDimMapField.h"
26 #include "HDF4RequestHandler.h"
27 #define SIGNED_BYTE_TO_INT32 1
31 HDFEOS2ArraySwathDimMapField::read ()
34 BESDEBUG(
"h4",
"Coming to HDFEOS2ArraySwathDimMapField read "<<endl);
39 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
40 bool check_pass_fileid_key =
false;
41 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
44 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
57 int nelms = format_constraint(&offset[0],&step[0],&count[0]);
60 vector<int32>offset32;
61 offset32.resize(rank);
70 for (
int i = 0; i < rank; i++) {
71 offset32[i] = (int32) offset[i];
72 count32[i] = (int32) count[i];
73 step32[i] = (int32) step[i];
77 int32 (*openfunc) (
char *, intn);
78 intn (*closefunc) (int32);
79 int32 (*attachfunc) (int32,
char *);
80 intn (*detachfunc) (int32);
84 if (swathname ==
"") {
85 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
87 else if (gridname ==
"") {
90 attachfunc = SWattach;
91 detachfunc = SWdetach;
92 datasetname = swathname;
95 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
102 if (
true == isgeofile ||
false == check_pass_fileid_key) {
105 sfid = 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 ());
116 swathid = attachfunc (sfid,
const_cast < char *
>(datasetname.c_str ()));
120 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be attached.";
121 throw InternalErr (__FILE__, __LINE__, eherr.str ());
130 if(
true == dimmaps.empty()) {
136 if ((nummaps = SWnentries(swathid, HDFE_NENTMAP, &bufsize)) == -1){
139 throw InternalErr (__FILE__, __LINE__,
"cannot obtain the number of dimmaps");
145 throw InternalErr (__FILE__,__LINE__,
146 "Number of dimension maps should be greater than 0");
149 vector<char> namelist;
150 vector<int32> map_offset;
151 vector<int32> increment;
153 namelist.resize(bufsize + 1);
154 map_offset.resize(nummaps);
155 increment.resize(nummaps);
156 if (SWinqmaps(swathid, &namelist[0], &map_offset[0], &increment[0])
160 throw InternalErr (__FILE__,__LINE__,
"fail to inquiry dimension maps");
163 vector<string> mapnames;
166 for (vector<string>::const_iterator i = mapnames.begin();
167 i != mapnames.end(); ++i) {
168 vector<string> parts;
170 if (parts.size() != 2){
173 throw InternalErr (__FILE__,__LINE__,
"the dimmaps should only include two parts");
177 tempdimmap.geodim = parts[0];
178 tempdimmap.datadim = parts[1];
179 tempdimmap.offset = map_offset[map_count];
180 tempdimmap.inc = increment[map_count];
182 dimmaps.push_back(tempdimmap);
187 if (sotype!=DEFAULT_CF_EQU) {
189 if(
"MODIS_SWATH_Type_L1B" == swathname) {
191 string emissive_str =
"Emissive";
192 string RefSB_str =
"RefSB";
193 bool is_emissive_field =
false;
194 bool is_refsb_field =
false;
196 if(fieldname.find(emissive_str)!=string::npos) {
197 if(0 == fieldname.compare(fieldname.size()-emissive_str.size(),
198 emissive_str.size(),emissive_str))
199 is_emissive_field =
true;
202 if(fieldname.find(RefSB_str)!=string::npos) {
203 if(0 == fieldname.compare(fieldname.size()-RefSB_str.size(),
204 RefSB_str.size(),RefSB_str))
205 is_refsb_field =
true;
208 if ((
true == is_emissive_field) || (
true == is_refsb_field)) {
211 throw InternalErr (__FILE__, __LINE__,
212 "Currently don't support MODIS Level 1B swath dim. map for data ");
217 bool is_modis1b =
false;
218 if(
"MODIS_SWATH_Type_L1B" == swathname)
221 string check_disable_scale_comp_key =
"H4.DisableScaleOffsetComp";
222 bool turn_on_disable_scale_comp_key=
false;
223 turn_on_disable_scale_comp_key = HDFCFUtil::check_beskeys(check_disable_scale_comp_key);
228 if(
true == HDF4RequestHandler::get_disable_scaleoffset_comp() &&
false== is_modis1b)
229 write_dap_data_disable_scale_comp(swathid,nelms,offset32,count32,step32);
231 write_dap_data_scale_comp(swathid,nelms,offset32,count32,step32);
240 r = detachfunc (swathid);
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 (sfid);
254 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
255 throw InternalErr (__FILE__, __LINE__, eherr.str ());
266 HDFEOS2ArraySwathDimMapField::format_constraint (
int *offset,
int *step,
int *count)
271 Dim_iter p = dim_begin ();
272 while (p != dim_end ()) {
274 int start = dimension_start (p,
true);
275 int stride = dimension_stride (p,
true);
276 int stop = dimension_stop (p,
true);
281 oss <<
"Array/Grid hyperslab start point "<< start <<
282 " is greater than stop point " << stop <<
".";
283 throw Error(malformed_expr, oss.str());
288 count[id] = ((stop - start) / stride) + 1;
292 "=format_constraint():"
293 <<
"id=" <<
id <<
" offset=" << offset[
id]
294 <<
" step=" << step[
id]
295 <<
" count=" << count[
id]
307 template <
class T >
int
308 HDFEOS2ArraySwathDimMapField::
309 GetFieldValue (int32 swathid,
const string & geofieldname,
310 vector < struct dimmap_entry >&sw_dimmaps,
311 vector < T > &vals, vector<int32>&newdims)
323 ret = SWfieldinfo (swathid,
const_cast < char *
>(geofieldname.c_str ()),
324 &sw_rank, dims, &type, dimlist);
329 for (
int i = 0; i <sw_rank; i++)
334 ret = SWreadfield (swathid,
const_cast < char *
>(geofieldname.c_str ()),
335 NULL, NULL, NULL, (
void *) &vals[0]);
339 vector < string > dimname;
342 for (
int i = 0; i < sw_rank; i++) {
343 vector < struct dimmap_entry >::iterator it;
345 for (it = sw_dimmaps.begin (); it != sw_dimmaps.end (); it++) {
346 if (it->geodim == dimname[i]) {
347 int32 ddimsize = SWdiminfo (swathid, (
char *) it->datadim.c_str ());
352 r = _expand_dimmap_field (&vals, sw_rank, dims, i, ddimsize, it->offset, it->inc);
360 for (
int i = 0; i < sw_rank; i++) {
364 newdims[i] = dims[i];
371 template <
class T >
int
372 HDFEOS2ArraySwathDimMapField::_expand_dimmap_field (vector < T >
373 *pvals, int32 sw_rank,
380 vector < T > orig = *pvals;
381 vector < int32 > pos;
382 vector < int32 > dims;
383 vector < int32 > newdims;
384 pos.resize (sw_rank);
385 dims.resize (sw_rank);
387 for (
int i = 0; i < sw_rank; i++) {
392 newdims[dimindex] = ddimsize;
393 dimsa[dimindex] = ddimsize;
397 for (
int i = 0; i < sw_rank; i++) {
398 newsize *= newdims[i];
401 pvals->resize (newsize);
405 if (pos[0] == dims[0]) {
409 else if (pos[dimindex] == 0) {
412 for (
int i = 0; i < dims[dimindex]; i++) {
414 v.push_back (orig[INDEX_nD_TO_1D (dims, pos)]);
419 for (int32 j = 0; j < ddimsize; j++) {
420 int32 i = (j - offset) / inc;
423 if (i * inc + offset == j)
429 int32 i2 = (i<=0)?1:0;
439 if ((
unsigned int) i + 1 >= v.size ()) {
447 j1 = i1 * inc + offset;
448 j2 = i2 * inc + offset;
449 f = (((j - j1) * v[i2] + (j2 - j) * v[i1]) / (j2 - j1));
453 (*pvals)[INDEX_nD_TO_1D (newdims, pos)] = f;
459 for (
int i = sw_rank - 1; i > 0; i--) {
460 if (pos[i] == dims[i]) {
471 bool HDFEOS2ArraySwathDimMapField::FieldSubset (T * outlatlon,
472 const vector<int32>&newdims,
479 if (newdims.size() == 1)
480 Field1DSubset(outlatlon,newdims[0],latlon,offset,count,step);
481 else if (newdims.size() == 2)
482 Field2DSubset(outlatlon,newdims[0],newdims[1],latlon,offset,count,step);
483 else if (newdims.size() == 3)
484 Field3DSubset(outlatlon,newdims,latlon,offset,count,step);
486 throw InternalErr(__FILE__, __LINE__,
487 "Currently doesn't support rank >3 when interpolating with dimension map");
494 bool HDFEOS2ArraySwathDimMapField::Field1DSubset (T * outlatlon,
501 if (majordim < count[0])
502 throw InternalErr(__FILE__, __LINE__,
503 "The number of elements is greater than the total dimensional size");
505 for (
int i = 0; i < count[0]; i++)
506 outlatlon[i] = latlon[offset[0]+i*step[0]];
513 bool HDFEOS2ArraySwathDimMapField::Field2DSubset (T * outlatlon,
522 T (*templatlonptr)[majordim][minordim] = (T *[][]) latlon;
529 int dim0count = count[0];
530 int dim1count = count[1];
532 int dim0index[dim0count];
533 int dim1index[dim1count];
535 for (i = 0; i < count[0]; i++)
536 dim0index[i] = offset[0] + i * step[0];
539 for (j = 0; j < count[1]; j++)
540 dim1index[j] = offset[1] + j * step[1];
545 for (i = 0; i < count[0]; i++) {
546 for (j = 0; j < count[1]; j++) {
548 outlatlon[k] = (*templatlonptr)[dim0index[i]][dim1index[j]];
550 outlatlon[k] = *(latlon + (dim0index[i] * minordim) + dim1index[j]);
559 bool HDFEOS2ArraySwathDimMapField::Field3DSubset (T * outlatlon,
560 const vector<int32>& newdims,
566 if (newdims.size() !=3)
567 throw InternalErr(__FILE__, __LINE__,
568 "the rank must be 3 to call this function");
570 T (*templatlonptr)[newdims[0]][newdims[1]][newdims[2]] = (T *[][][]) latlon;
578 int dim0count = count[0];
579 int dim1count = count[1];
580 int dim2count = count[2];
582 int dim0index[dim0count], dim1index[dim1count],dim2index[dim2count];
584 for (i = 0; i < count[0]; i++)
585 dim0index[i] = offset[0] + i * step[0];
588 for (j = 0; j < count[1]; j++)
589 dim1index[j] = offset[1] + j * step[1];
591 for (k = 0; k < count[2]; k++)
592 dim2index[k] = offset[2] + k * step[2];
597 for (i = 0; i < count[0]; i++) {
598 for (j = 0; j < count[1]; j++) {
599 for (k =0; k < count[2]; k++) {
601 outlatlon[l] = (*templatlonptr)[dim0index[i]][dim1index[j]][dim2index[k]];
603 outlatlon[l] = *(latlon + (dim0index[i] * newdims[1] * newdims[2]) + (dim1index[j] * newdims[2])+ dim2index[k]);
612 HDFEOS2ArraySwathDimMapField::write_dap_data_scale_comp(int32 swathid,
614 vector<int32>& offset32,
615 vector<int32>& count32,
616 vector<int32>& step32) {
619 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
620 bool check_pass_fileid_key =
false;
621 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
624 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
627 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
630 fieldinfofunc = SWfieldinfo;
633 int32 attrcount = -1;
634 int32 attrindex = -1;
636 int32 scale_factor_attr_index = -1;
637 int32 add_offset_attr_index =-1;
641 float fillvalue = 0.;
643 if (sotype!=DEFAULT_CF_EQU) {
648 if (
true == isgeofile ||
false == check_pass_fileid_key) {
649 sdfileid = SDstart(
const_cast < char *
>(filename.c_str ()), DFACC_READ);
650 if (FAIL == sdfileid) {
652 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
653 throw InternalErr (__FILE__, __LINE__, eherr.str ());
662 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
663 if (FAIL == sdsindex) {
664 if(
true == isgeofile ||
false == check_pass_fileid_key)
667 eherr <<
"Cannot obtain the index of " << fieldname;
668 throw InternalErr (__FILE__, __LINE__, eherr.str ());
671 sdsid = SDselect(sdfileid, sdsindex);
673 if(
true == isgeofile ||
false == check_pass_fileid_key)
676 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
677 throw InternalErr (__FILE__, __LINE__, eherr.str ());
680 char attrname[H4_MAX_NC_NAME + 1];
681 vector<char> attrbuf;
682 vector<char> attrbuf2;
684 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
685 if(scale_factor_attr_index!=FAIL)
688 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname, &attrtype, &attrcount);
692 if(
true == isgeofile ||
false == check_pass_fileid_key)
695 eherr <<
"Attribute 'scale_factor' in "
696 << fieldname.c_str () <<
" cannot be obtained.";
697 throw InternalErr (__FILE__, __LINE__, eherr.str ());
701 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
702 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)&attrbuf[0]);
706 if(
true == isgeofile ||
false == check_pass_fileid_key)
709 eherr <<
"Attribute 'scale_factor' in "
710 << fieldname.c_str () <<
" cannot be obtained.";
711 throw InternalErr (__FILE__, __LINE__, eherr.str ());
721 #define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
724 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
725 scale = (float)tmpvalue; \
728 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float);
729 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double);
731 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
735 #undef GET_SCALE_FACTOR_ATTR_VALUE
738 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
739 if(add_offset_attr_index!=FAIL)
742 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname, &attrtype, &attrcount);
746 if(
true == isgeofile ||
false == check_pass_fileid_key)
749 eherr <<
"Attribute 'add_offset' in "
750 << fieldname.c_str () <<
" cannot be obtained.";
751 throw InternalErr (__FILE__, __LINE__, eherr.str ());
754 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
755 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)&attrbuf[0]);
759 if(
true == isgeofile ||
false == check_pass_fileid_key)
762 eherr <<
"Attribute 'add_offset' in "
763 << fieldname.c_str () <<
" cannot be obtained.";
764 throw InternalErr (__FILE__, __LINE__, eherr.str ());
768 #define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
771 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
772 offset2 = (float)tmpvalue; \
775 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float);
776 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double);
778 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
780 #undef GET_ADD_OFFSET_ATTR_VALUE
783 attrindex = SDfindattr(sdsid,
"_FillValue");
784 if(sotype!=DEFAULT_CF_EQU && attrindex!=FAIL)
787 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
791 if(
true == isgeofile ||
false == check_pass_fileid_key)
794 eherr <<
"Attribute '_FillValue' in "
795 << fieldname.c_str () <<
" cannot be obtained.";
796 throw InternalErr (__FILE__, __LINE__, eherr.str ());
799 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
800 ret = SDreadattr(sdsid, attrindex, (VOIDP)&attrbuf[0]);
804 if(
true == isgeofile ||
false == check_pass_fileid_key)
807 eherr <<
"Attribute '_FillValue' in "
808 << fieldname.c_str () <<
" cannot be obtained.";
809 throw InternalErr (__FILE__, __LINE__, eherr.str ());
814 #define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
817 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
818 fillvalue = (float)tmpvalue; \
821 GET_FILLVALUE_ATTR_VALUE(INT8, int8);
822 GET_FILLVALUE_ATTR_VALUE(INT16, int16);
823 GET_FILLVALUE_ATTR_VALUE(INT32, int32);
824 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8);
825 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16);
826 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32);
833 #undef GET_FILLVALUE_ATTR_VALUE
840 float orig_valid_min = 0.;
841 float orig_valid_max = 0.;
847 attrindex = SDfindattr(sdsid,
"valid_range");
851 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
859 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
860 throw InternalErr (__FILE__, __LINE__, eherr.str ());
863 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
864 ret = SDreadattr(sdsid, attrindex, (VOIDP)&attrbuf[0]);
872 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
873 throw InternalErr (__FILE__, __LINE__, eherr.str ());
876 string attrbuf_str(attrbuf.begin(),attrbuf.end());
884 size_t found = attrbuf_str.find_first_of(
",");
885 size_t found_from_end = attrbuf_str.find_last_of(
",");
887 if (string::npos == found)
888 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
889 if (found != found_from_end)
890 throw InternalErr(__FILE__,__LINE__,
"Only one separator , should be available.");
895 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
896 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
903 if (2 == temp_attrcount) {
904 orig_valid_min = (float)attrbuf[0];
905 orig_valid_max = (float)attrbuf[1];
908 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be greater than 1.");
916 if (temp_attrcount != 2)
917 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT8 type.");
919 unsigned char* temp_valid_range = (
unsigned char *)&attrbuf[0];
920 orig_valid_min = (float)(temp_valid_range[0]);
921 orig_valid_max = (float)(temp_valid_range[1]);
927 if (temp_attrcount != 2)
928 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_INT16 type.");
930 short* temp_valid_range = (
short *)&attrbuf[0];
931 orig_valid_min = (float)(temp_valid_range[0]);
932 orig_valid_max = (float)(temp_valid_range[1]);
938 if (temp_attrcount != 2)
939 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT16 type.");
941 unsigned short* temp_valid_range = (
unsigned short *)&attrbuf[0];
942 orig_valid_min = (float)(temp_valid_range[0]);
943 orig_valid_max = (float)(temp_valid_range[1]);
949 if (temp_attrcount != 2)
950 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_INT32 type.");
952 int* temp_valid_range = (
int *)&attrbuf[0];
953 orig_valid_min = (float)(temp_valid_range[0]);
954 orig_valid_max = (float)(temp_valid_range[1]);
960 if (temp_attrcount != 2)
961 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT32 type.");
963 unsigned int* temp_valid_range = (
unsigned int *)&attrbuf[0];
964 orig_valid_min = (float)(temp_valid_range[0]);
965 orig_valid_max = (float)(temp_valid_range[1]);
971 if (temp_attrcount != 2)
972 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
974 float* temp_valid_range = (
float *)&attrbuf[0];
975 orig_valid_min = temp_valid_range[0];
976 orig_valid_max = temp_valid_range[1];
982 if (temp_attrcount != 2)
983 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
984 double* temp_valid_range = (
double *)&attrbuf[0];
989 orig_valid_min = temp_valid_range[0];
990 orig_valid_max = temp_valid_range[1];
994 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
1009 if(
true == isgeofile ||
false == check_pass_fileid_key)
1041 if (MODIS_EQ_SCALE == sotype || MODIS_MUL_SCALE == sotype) {
1043 sotype = MODIS_DIV_SCALE;
1044 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1046 <<
" But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1048 <<
" Now change it to MODIS_DIV_SCALE. "<<endl;
1052 if (MODIS_DIV_SCALE == sotype) {
1054 sotype = MODIS_MUL_SCALE;
1055 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1057 <<
" But the original scale factor type is MODIS_DIV_SCALE. "
1059 <<
" Now change it to MODIS_MUL_SCALE. "<<endl;
1074 #define RECALCULATE(CAST, DODS_CAST, VAL) \
1076 bool change_data_value = false; \
1077 if(sotype!=DEFAULT_CF_EQU) \
1079 if(scale_factor_attr_index!=FAIL && !(scale==1 && offset2==0)) \
1081 vector<float>tmpval; \
1082 tmpval.resize(nelms); \
1083 CAST tmptr = (CAST)VAL; \
1084 for(int l=0; l<nelms; l++) \
1085 tmpval[l] = (float)tmptr[l]; \
1086 float temp_scale = scale; \
1087 float temp_offset = offset2; \
1088 if(sotype==MODIS_MUL_SCALE) \
1089 temp_offset = -1. *offset2*temp_scale;\
1090 else if (sotype==MODIS_DIV_SCALE) \
1092 temp_scale = 1/scale; \
1093 temp_offset = -1. *temp_scale *offset2;\
1095 for(int l=0; l<nelms; l++) \
1096 if(attrindex!=FAIL && ((float)tmptr[l])!=fillvalue) \
1097 tmpval[l] = tmptr[l]*temp_scale + temp_offset; \
1098 change_data_value = true; \
1099 set_value((dods_float32 *)&tmpval[0], nelms); \
1102 if(!change_data_value) \
1104 set_value ((DODS_CAST)VAL, nelms); \
1111 char tmp_dimlist[1024];
1114 int32 tmp_dims[rank];
1117 int32 field_dtype = 0;
1124 r = fieldinfofunc (swathid,
const_cast < char *
>(fieldname.c_str ()),
1125 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1127 ostringstream eherr;
1128 eherr <<
"Field " << fieldname.c_str ()
1129 <<
" information cannot be obtained.";
1130 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1135 vector<int32> newdims;
1136 newdims.resize(rank);
1139 switch (field_dtype) {
1145 vector < int8 > total_val8;
1146 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1148 ostringstream eherr;
1149 eherr <<
"field " << fieldname.c_str ()
1150 <<
"cannot be read.";
1151 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1154 check_num_elems_constraint(nelms,newdims);
1159 FieldSubset (&val8[0], newdims, &total_val8[0],
1160 &offset32[0], &count32[0], &step32[0]);
1162 #ifndef SIGNED_BYTE_TO_INT32
1163 RECALCULATE(int8*, dods_byte*, &val8[0]);
1165 vector<int32>newval;
1166 newval.resize(nelms);
1168 for (
int counter = 0; counter < nelms; counter++)
1169 newval[counter] = (int32) (val8[counter]);
1171 RECALCULATE(int32*, dods_int32*, &newval[0]);
1180 vector < uint8 > total_val_u8;
1181 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1183 ostringstream eherr;
1184 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1185 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1188 check_num_elems_constraint(nelms,newdims);
1189 vector<uint8>val_u8;
1190 val_u8.resize(nelms);
1192 FieldSubset (&val_u8[0], newdims, &total_val_u8[0],
1193 &offset32[0], &count32[0], &step32[0]);
1194 RECALCULATE(uint8*, dods_byte*, &val_u8[0]);
1201 vector < int16 > total_val16;
1202 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1204 ostringstream eherr;
1205 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1206 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1209 check_num_elems_constraint(nelms,newdims);
1211 val16.resize(nelms);
1213 FieldSubset (&val16[0], newdims, &total_val16[0],
1214 &offset32[0], &count32[0], &step32[0]);
1216 RECALCULATE(int16*, dods_int16*, &val16[0]);
1223 vector < uint16 > total_val_u16;
1224 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1226 ostringstream eherr;
1228 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1229 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1232 check_num_elems_constraint(nelms,newdims);
1233 vector<uint16>val_u16;
1234 val_u16.resize(nelms);
1236 FieldSubset (&val_u16[0], newdims, &total_val_u16[0],
1237 &offset32[0], &count32[0], &step32[0]);
1238 RECALCULATE(uint16*, dods_uint16*, &val_u16[0]);
1246 vector < int32 > total_val32;
1247 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1249 ostringstream eherr;
1251 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1252 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1255 check_num_elems_constraint(nelms,newdims);
1256 vector<int32> val32;
1257 val32.resize(nelms);
1259 FieldSubset (&val32[0], newdims, &total_val32[0],
1260 &offset32[0], &count32[0], &step32[0]);
1262 RECALCULATE(int32*, dods_int32*, &val32[0]);
1270 vector < uint32 > total_val_u32;
1271 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, newdims);
1273 ostringstream eherr;
1274 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1275 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1278 check_num_elems_constraint(nelms,newdims);
1279 vector<uint32>val_u32;
1280 val_u32.resize(nelms);
1282 FieldSubset (&val_u32[0], newdims, &total_val_u32[0],
1283 &offset32[0], &count32[0], &step32[0]);
1284 RECALCULATE(uint32*, dods_uint32*, &val_u32[0]);
1292 vector < float32 > total_val_f32;
1293 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1295 ostringstream eherr;
1296 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1297 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1300 check_num_elems_constraint(nelms,newdims);
1301 vector<float32>val_f32;
1302 val_f32.resize(nelms);
1304 FieldSubset (&val_f32[0], newdims, &total_val_f32[0],
1305 &offset32[0], &count32[0], &step32[0]);
1306 RECALCULATE(float32*, dods_float32*, &val_f32[0]);
1312 vector < float64 > total_val_f64;
1313 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1315 ostringstream eherr;
1316 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1317 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1320 check_num_elems_constraint(nelms,newdims);
1321 vector<float64>val_f64;
1322 val_f64.resize(nelms);
1323 FieldSubset (&val_f64[0], newdims, &total_val_f64[0],
1324 &offset32[0], &count32[0], &step32[0]);
1325 RECALCULATE(float64*, dods_float64*, &val_f64[0]);
1331 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1339 HDFEOS2ArraySwathDimMapField::write_dap_data_disable_scale_comp(int32 swathid,
1341 vector<int32>& offset32,
1342 vector<int32>& count32,
1343 vector<int32>& step32) {
1346 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1348 fieldinfofunc = SWfieldinfo;
1354 char tmp_dimlist[1024];
1357 int32 tmp_dims[rank];
1360 int32 field_dtype = 0;
1367 r = fieldinfofunc (swathid,
const_cast < char *
>(fieldname.c_str ()),
1368 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1370 ostringstream eherr;
1371 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1372 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1377 vector<int32> newdims;
1378 newdims.resize(rank);
1381 switch (field_dtype) {
1386 vector < int8 > total_val8;
1387 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1389 ostringstream eherr;
1390 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1391 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1394 check_num_elems_constraint(nelms,newdims);
1398 FieldSubset (&val8[0], newdims, &total_val8[0],
1399 &offset32[0], &count32[0], &step32[0]);
1402 #ifndef SIGNED_BYTE_TO_INT32
1403 set_value((dods_byte*)&val8[0],nelms);
1405 vector<int32>newval;
1406 newval.resize(nelms);
1408 for (
int counter = 0; counter < nelms; counter++)
1409 newval[counter] = (int32) (val8[counter]);
1411 set_value ((dods_int32 *) &newval[0], nelms);
1419 vector < uint8 > total_val_u8;
1420 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1422 ostringstream eherr;
1423 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1424 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1427 check_num_elems_constraint(nelms,newdims);
1428 vector<uint8>val_u8;
1429 val_u8.resize(nelms);
1431 FieldSubset (&val_u8[0], newdims, &total_val_u8[0],
1432 &offset32[0], &count32[0], &step32[0]);
1433 set_value ((dods_byte *) &val_u8[0], nelms);
1439 vector < int16 > total_val16;
1440 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1442 ostringstream eherr;
1443 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1444 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1447 check_num_elems_constraint(nelms,newdims);
1449 val16.resize(nelms);
1451 FieldSubset (&val16[0], newdims, &total_val16[0],
1452 &offset32[0], &count32[0], &step32[0]);
1454 set_value ((dods_int16 *) &val16[0], nelms);
1460 vector < uint16 > total_val_u16;
1461 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1463 ostringstream eherr;
1464 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1465 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1468 check_num_elems_constraint(nelms,newdims);
1469 vector<uint16>val_u16;
1470 val_u16.resize(nelms);
1472 FieldSubset (&val_u16[0], newdims, &total_val_u16[0],
1473 &offset32[0], &count32[0], &step32[0]);
1474 set_value ((dods_uint16 *) &val_u16[0], nelms);
1481 vector < int32 > total_val32;
1482 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1484 ostringstream eherr;
1486 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1487 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1490 check_num_elems_constraint(nelms,newdims);
1491 vector<int32> val32;
1492 val32.resize(nelms);
1494 FieldSubset (&val32[0], newdims, &total_val32[0],
1495 &offset32[0], &count32[0], &step32[0]);
1496 set_value ((dods_int32 *) &val32[0], nelms);
1503 vector < uint32 > total_val_u32;
1504 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, newdims);
1506 ostringstream eherr;
1508 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1509 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1512 check_num_elems_constraint(nelms,newdims);
1513 vector<uint32>val_u32;
1514 val_u32.resize(nelms);
1516 FieldSubset (&val_u32[0], newdims, &total_val_u32[0],
1517 &offset32[0], &count32[0], &step32[0]);
1518 set_value ((dods_uint32 *) &val_u32[0], nelms);
1525 vector < float32 > total_val_f32;
1526 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1528 ostringstream eherr;
1530 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1531 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1534 check_num_elems_constraint(nelms,newdims);
1535 vector<float32>val_f32;
1536 val_f32.resize(nelms);
1538 FieldSubset (&val_f32[0], newdims, &total_val_f32[0],
1539 &offset32[0], &count32[0], &step32[0]);
1541 set_value ((dods_float32 *) &val_f32[0], nelms);
1547 vector < float64 > total_val_f64;
1548 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1550 ostringstream eherr;
1552 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1553 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1556 check_num_elems_constraint(nelms,newdims);
1557 vector<float64>val_f64;
1558 val_f64.resize(nelms);
1559 FieldSubset (&val_f64[0], newdims, &total_val_f64[0],
1560 &offset32[0], &count32[0], &step32[0]);
1561 set_value ((dods_float64 *) &val_f64[0], nelms);
1567 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1579 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
1580 bool check_pass_fileid_key =
false;
1581 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
1585 if(
true == isgeofile ||
false == HDF4RequestHandler::get_pass_fileid()) {
1597 bool HDFEOS2ArraySwathDimMapField::check_num_elems_constraint(
const int num_elems,
1598 const vector<int32>&newdims) {
1600 int total_dim_size = 1;
1601 for (
int i =0;i<rank;i++)
1602 total_dim_size*=newdims[i];
1604 if(total_dim_size < num_elems) {
1605 ostringstream eherr;
1606 eherr <<
"The total number of elements for the array " << total_dim_size
1607 <<
"is less than the user-requested number of elements " << num_elems;
1608 throw InternalErr (__FILE__, __LINE__, eherr.str ());