16 #ifdef USE_HDFEOS2_LIB
22 #include "InternalErr.h"
26 #define SIGNED_BYTE_TO_INT32 1
30 HDFEOS2ArraySwathDimMapField::read ()
33 BESDEBUG(
"h4",
"Coming to HDFEOS2ArraySwathDimMapField read "<<endl);
35 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
36 bool check_pass_fileid_key =
false;
50 int nelms = format_constraint(&offset[0],&step[0],&count[0]);
53 vector<int32>offset32;
54 offset32.resize(rank);
63 for (
int i = 0; i < rank; i++) {
64 offset32[i] = (int32) offset[i];
65 count32[i] = (int32) count[i];
66 step32[i] = (int32) step[i];
70 int32 (*openfunc) (
char *, intn);
71 intn (*closefunc) (int32);
72 int32 (*attachfunc) (int32,
char *);
73 intn (*detachfunc) (int32);
74 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
75 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
79 if (swathname ==
"") {
80 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
82 else if (gridname ==
"") {
85 attachfunc = SWattach;
86 detachfunc = SWdetach;
87 fieldinfofunc = SWfieldinfo;
88 readfieldfunc = SWreadfield;
89 datasetname = swathname;
92 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
99 if (
true == isgeofile ||
false == check_pass_fileid_key) {
102 sfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
106 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
107 throw InternalErr (__FILE__, __LINE__, eherr.str ());
113 swathid = attachfunc (sfid, const_cast < char *>(datasetname.c_str ()));
117 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be attached.";
118 throw InternalErr (__FILE__, __LINE__, eherr.str ());
127 if(
true == dimmaps.empty()) {
133 if ((nummaps = SWnentries(swathid, HDFE_NENTMAP, &bufsize)) == -1){
136 throw InternalErr (__FILE__, __LINE__,
"cannot obtain the number of dimmaps");
142 throw InternalErr (__FILE__,__LINE__,
143 "Number of dimension maps should be greater than 0");
146 vector<char> namelist;
147 vector<int32> offset, increment;
149 namelist.resize(bufsize + 1);
150 offset.resize(nummaps);
151 increment.resize(nummaps);
152 if (SWinqmaps(swathid, &namelist[0], &offset[0], &increment[0])
156 throw InternalErr (__FILE__,__LINE__,
"fail to inquiry dimension maps");
159 vector<string> mapnames;
162 for (vector<string>::const_iterator i = mapnames.begin();
163 i != mapnames.end(); ++i) {
164 vector<string> parts;
166 if (parts.size() != 2){
169 throw InternalErr (__FILE__,__LINE__,
"the dimmaps should only include two parts");
173 tempdimmap.
geodim = parts[0];
174 tempdimmap.datadim = parts[1];
175 tempdimmap.offset = offset[count];
176 tempdimmap.inc = increment[count];
178 dimmaps.push_back(tempdimmap);
185 if(
"MODIS_SWATH_Type_L1B" == swathname) {
187 string emissive_str =
"Emissive";
188 string RefSB_str =
"RefSB";
189 bool is_emissive_field =
false;
190 bool is_refsb_field =
false;
192 if(fieldname.find(emissive_str)!=string::npos) {
193 if(0 == fieldname.compare(fieldname.size()-emissive_str.size(),
194 emissive_str.size(),emissive_str))
195 is_emissive_field =
true;
198 if(fieldname.find(RefSB_str)!=string::npos) {
199 if(0 == fieldname.compare(fieldname.size()-RefSB_str.size(),
200 RefSB_str.size(),RefSB_str))
201 is_refsb_field =
true;
204 if ((
true == is_emissive_field) || (
true == is_refsb_field)) {
207 throw InternalErr (__FILE__, __LINE__,
208 "Currently don't support MODIS Level 1B swath dim. map for data ");
213 bool is_modis1b =
false;
214 if(
"MODIS_SWATH_Type_L1B" == swathname)
216 string check_disable_scale_comp_key =
"H4.DisableScaleOffsetComp";
217 bool turn_on_disable_scale_comp_key=
false;
221 if(
true == turn_on_disable_scale_comp_key &&
false== is_modis1b)
222 write_dap_data_disable_scale_comp(swathid,nelms,offset32,count32,step32);
224 write_dap_data_scale_comp(swathid,nelms,offset32,count32,step32);
233 r = detachfunc (swathid);
238 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
239 throw InternalErr (__FILE__, __LINE__, eherr.str ());
243 if(
true == isgeofile ||
false == check_pass_fileid_key) {
244 r = closefunc (sfid);
247 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
248 throw InternalErr (__FILE__, __LINE__, eherr.str ());
259 HDFEOS2ArraySwathDimMapField::format_constraint (
int *offset,
int *step,
int *count)
264 Dim_iter p = dim_begin ();
266 while (p != dim_end ()) {
268 int start = dimension_start (p,
true);
269 int stride = dimension_stride (p,
true);
270 int stop = dimension_stop (p,
true);
274 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
277 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
278 ":" << stride <<
":" << stop <<
"]";
279 throw Error (malformed_expr, oss.str ());
283 if (start == 0 && stop == 0 && stride == 0) {
284 start = dimension_start (p,
false);
285 stride = dimension_stride (p,
false);
286 stop = dimension_stop (p,
false);
291 count[id] = ((stop - start) / stride) + 1;
295 "=format_constraint():"
296 <<
"id=" <<
id <<
" offset=" << offset[
id]
297 <<
" step=" << step[
id]
298 <<
" count=" << count[
id]
310 template <
class T >
int
311 HDFEOS2ArraySwathDimMapField::
312 GetFieldValue (int32 swathid,
const string & geofieldname,
313 vector < struct dimmap_entry >&dimmaps,
314 vector < T > &vals, vector<int32>&newdims)
319 int32 rank = -1, dims[130], type = -1;
324 ret = SWfieldinfo (swathid, const_cast < char *>(geofieldname.c_str ()),
325 &rank, dims, &type, dimlist);
330 for (
int i = 0; i < rank; i++)
335 ret = SWreadfield (swathid, const_cast < char *>(geofieldname.c_str ()),
340 vector < string > dimname;
343 for (
int i = 0; i < rank; i++) {
344 vector < struct dimmap_entry >::iterator it;
346 for (it = dimmaps.begin (); it != dimmaps.end (); it++) {
347 if (it->geodim == dimname[i]) {
348 int32 ddimsize = SWdiminfo (swathid, (
char *) it->datadim.c_str ());
353 r = _expand_dimmap_field (&vals, rank, dims, i, ddimsize, it->offset, it->inc);
361 for (
int i = 0; i < rank; i++) {
365 newdims[i] = dims[i];
372 template <
class T >
int
373 HDFEOS2ArraySwathDimMapField::_expand_dimmap_field (vector < T >
381 vector < T > orig = *pvals;
382 vector < int32 > pos;
383 vector < int32 > dims;
384 vector < int32 > newdims;
388 for (
int i = 0; i < rank; i++) {
393 newdims[dimindex] = ddimsize;
394 dimsa[dimindex] = ddimsize;
398 for (
int i = 0; i < rank; i++) {
399 newsize *= newdims[i];
402 pvals->resize (newsize);
406 if (pos[0] == dims[0]) {
410 else if (pos[dimindex] == 0) {
413 for (
int i = 0; i < dims[dimindex]; i++) {
420 for (int32 j = 0; j < ddimsize; j++) {
421 int32 i = (j -
offset) / inc;
424 if (i * inc + offset == j)
438 if ((
unsigned int) i + 1 >= v.size ()) {
448 f = (((j - j1) * v[i2] + (j2 - j) * v[i1]) / (j2 - j1));
458 for (
int i = rank - 1; i > 0; i--) {
459 if (pos[i] == dims[i]) {
470 bool HDFEOS2ArraySwathDimMapField::FieldSubset (T * outlatlon,
471 const vector<int32>&newdims,
478 if (newdims.size() == 1)
479 Field1DSubset(outlatlon,newdims[0],latlon,offset,count,step);
480 else if (newdims.size() == 2)
481 Field2DSubset(outlatlon,newdims[0],newdims[1],latlon,offset,count,step);
482 else if (newdims.size() == 3)
483 Field3DSubset(outlatlon,newdims,latlon,offset,count,step);
485 throw InternalErr(__FILE__, __LINE__,
486 "Currently doesn't support rank >3 when interpolating with dimension map");
493 bool HDFEOS2ArraySwathDimMapField::Field1DSubset (T * outlatlon,
500 if (majordim < count[0])
501 throw InternalErr(__FILE__, __LINE__,
502 "The number of elements is greater than the total dimensional size");
504 for (
int i = 0; i < count[0]; i++)
505 outlatlon[i] = latlon[offset[0]+i*step[0]];
512 bool HDFEOS2ArraySwathDimMapField::Field2DSubset (T * outlatlon,
523 T (*templatlonptr)[majordim][minordim] = (typeof templatlonptr) latlon;
524 int i = 0, j =0, k = 0;
528 int dim0count = count[0];
529 int dim1count = count[1];
531 int dim0index[dim0count], dim1index[dim1count];
533 for (i = 0; i < count[0]; i++)
534 dim0index[i] = offset[0] + i * step[0];
537 for (j = 0; j < count[1]; j++)
538 dim1index[j] = offset[1] + j * step[1];
543 for (i = 0; i < count[0]; i++) {
544 for (j = 0; j < count[1]; j++) {
545 outlatlon[k] = (*templatlonptr)[dim0index[i]][dim1index[j]];
554 bool HDFEOS2ArraySwathDimMapField::Field3DSubset (T * outlatlon,
555 const vector<int32>& newdims,
564 if (newdims.size() !=3)
565 throw InternalErr(__FILE__, __LINE__,
566 "the rank must be 3 to call this function");
568 T (*templatlonptr)[newdims[0]][newdims[1]][newdims[2]] = (typeof templatlonptr) latlon;
573 int dim0count = count[0];
574 int dim1count = count[1];
575 int dim2count = count[2];
577 int dim0index[dim0count], dim1index[dim1count],dim2index[dim2count];
579 for (i = 0; i < count[0]; i++)
580 dim0index[i] = offset[0] + i * step[0];
583 for (j = 0; j < count[1]; j++)
584 dim1index[j] = offset[1] + j * step[1];
586 for (k = 0; k < count[2]; k++)
587 dim2index[k] = offset[2] + k * step[2];
592 for (i = 0; i < count[0]; i++) {
593 for (j = 0; j < count[1]; j++) {
594 for ( k =0;k<count[2];k++) {
595 outlatlon[l] = (*templatlonptr)[dim0index[i]][dim1index[j]][dim2index[k]];
603 HDFEOS2ArraySwathDimMapField::write_dap_data_scale_comp(int32 swathid,
605 vector<int32>& offset32,
606 vector<int32>& count32,
607 vector<int32>& step32) {
610 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
611 bool check_pass_fileid_key =
false;
615 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
616 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
618 intn (*attrinfofunc) (int32,
char *, int32 *, int32 *);
619 intn (*readattrfunc) (int32,
char *,
void*);
621 fieldinfofunc = SWfieldinfo;
622 readfieldfunc = SWreadfield;
624 attrinfofunc = SWattrinfo;
625 readattrfunc = SWreadattr;
627 int32 attrtype = -1, attrcount = -1;
628 int32 attrindex = -1;
629 int32 scale_factor_attr_index = -1, add_offset_attr_index =-1;
630 float scale=1, offset2=0, fillvalue = 0.;
637 if (
true == isgeofile ||
false == check_pass_fileid_key) {
638 sdfileid = SDstart(const_cast < char *>(filename.c_str ()), DFACC_READ);
639 if (FAIL == sdfileid) {
641 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
642 throw InternalErr (__FILE__, __LINE__, eherr.str ());
648 int32 sdsindex = -1, sdsid = -1;
649 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
650 if (FAIL == sdsindex) {
651 if(
true == isgeofile ||
false == check_pass_fileid_key)
654 eherr <<
"Cannot obtain the index of " << fieldname;
655 throw InternalErr (__FILE__, __LINE__, eherr.str ());
658 sdsid = SDselect(sdfileid, sdsindex);
660 if(
true == isgeofile ||
false == check_pass_fileid_key)
663 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
664 throw InternalErr (__FILE__, __LINE__, eherr.str ());
667 char attrname[H4_MAX_NC_NAME + 1];
668 vector<char> attrbuf, attrbuf2;
670 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
671 if(scale_factor_attr_index!=FAIL)
674 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname, &attrtype, &attrcount);
678 if(
true == isgeofile ||
false == check_pass_fileid_key)
681 eherr <<
"Attribute 'scale_factor' in "
682 << fieldname.c_str () <<
" cannot be obtained.";
683 throw InternalErr (__FILE__, __LINE__, eherr.str ());
687 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
688 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)&attrbuf[0]);
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 ());
707 #define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
710 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
711 scale = (float)tmpvalue; \
714 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float);
715 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double);
717 #undef GET_SCALE_FACTOR_ATTR_VALUE
720 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
721 if(add_offset_attr_index!=FAIL)
724 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname, &attrtype, &attrcount);
728 if(
true == isgeofile ||
false == check_pass_fileid_key)
731 eherr <<
"Attribute 'add_offset' in "
732 << fieldname.c_str () <<
" cannot be obtained.";
733 throw InternalErr (__FILE__, __LINE__, eherr.str ());
736 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
737 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)&attrbuf[0]);
741 if(
true == isgeofile ||
false == check_pass_fileid_key)
744 eherr <<
"Attribute 'add_offset' in "
745 << fieldname.c_str () <<
" cannot be obtained.";
746 throw InternalErr (__FILE__, __LINE__, eherr.str ());
750 #define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
753 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
754 offset2 = (float)tmpvalue; \
757 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float);
758 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double);
760 #undef GET_ADD_OFFSET_ATTR_VALUE
763 attrindex = SDfindattr(sdsid,
"_FillValue");
767 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
771 if(
true == isgeofile ||
false == check_pass_fileid_key)
774 eherr <<
"Attribute '_FillValue' in "
775 << fieldname.c_str () <<
" cannot be obtained.";
776 throw InternalErr (__FILE__, __LINE__, eherr.str ());
779 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
780 ret = SDreadattr(sdsid, attrindex, (VOIDP)&attrbuf[0]);
784 if(
true == isgeofile ||
false == check_pass_fileid_key)
787 eherr <<
"Attribute '_FillValue' in "
788 << fieldname.c_str () <<
" cannot be obtained.";
789 throw InternalErr (__FILE__, __LINE__, eherr.str ());
794 #define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
797 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
798 fillvalue = (float)tmpvalue; \
801 GET_FILLVALUE_ATTR_VALUE(INT8, int8);
802 GET_FILLVALUE_ATTR_VALUE(INT16, int16);
803 GET_FILLVALUE_ATTR_VALUE(INT32, int32);
804 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8);
805 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16);
806 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32);
808 #undef GET_FILLVALUE_ATTR_VALUE
815 float orig_valid_min = 0.;
816 float orig_valid_max = 0.;
822 attrindex = SDfindattr(sdsid,
"valid_range");
826 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
834 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
835 throw InternalErr (__FILE__, __LINE__, eherr.str ());
838 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
839 ret = SDreadattr(sdsid, attrindex, (VOIDP)&attrbuf[0]);
847 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
848 throw InternalErr (__FILE__, __LINE__, eherr.str ());
851 string attrbuf_str(attrbuf.begin(),attrbuf.end());
859 size_t found = attrbuf_str.find_first_of(
",");
860 size_t found_from_end = attrbuf_str.find_last_of(
",");
862 if (string::npos == found)
863 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
864 if (found != found_from_end)
865 throw InternalErr(__FILE__,__LINE__,
"Only one separator , should be available.");
870 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
871 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
878 if (2 == temp_attrcount) {
879 orig_valid_min = (float)attrbuf[0];
880 orig_valid_max = (float)attrbuf[1];
883 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be greater than 1.");
891 if (temp_attrcount != 2)
892 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT8 type.");
894 unsigned char* temp_valid_range = (
unsigned char *)&attrbuf[0];
895 orig_valid_min = (float)(temp_valid_range[0]);
896 orig_valid_max = (float)(temp_valid_range[1]);
902 if (temp_attrcount != 2)
903 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_INT16 type.");
905 short* temp_valid_range = (
short *)&attrbuf[0];
906 orig_valid_min = (float)(temp_valid_range[0]);
907 orig_valid_max = (float)(temp_valid_range[1]);
913 if (temp_attrcount != 2)
914 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT16 type.");
916 unsigned short* temp_valid_range = (
unsigned short *)&attrbuf[0];
917 orig_valid_min = (float)(temp_valid_range[0]);
918 orig_valid_max = (float)(temp_valid_range[1]);
924 if (temp_attrcount != 2)
925 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_INT32 type.");
927 int* temp_valid_range = (
int *)&attrbuf[0];
928 orig_valid_min = (float)(temp_valid_range[0]);
929 orig_valid_max = (float)(temp_valid_range[1]);
935 if (temp_attrcount != 2)
936 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT32 type.");
938 unsigned int* temp_valid_range = (
unsigned int *)&attrbuf[0];
939 orig_valid_min = (float)(temp_valid_range[0]);
940 orig_valid_max = (float)(temp_valid_range[1]);
946 if (temp_attrcount != 2)
947 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
949 float* temp_valid_range = (
float *)&attrbuf[0];
950 orig_valid_min = temp_valid_range[0];
951 orig_valid_max = temp_valid_range[1];
957 if (temp_attrcount != 2)
958 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
959 double* temp_valid_range = (
double *)&attrbuf[0];
964 orig_valid_min = temp_valid_range[0];
965 orig_valid_max = temp_valid_range[1];
969 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
982 if(
true == isgeofile ||
false == check_pass_fileid_key)
1017 (*
BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1019 <<
" But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1021 <<
" Now change it to MODIS_DIV_SCALE. "<<endl;
1028 (*
BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1030 <<
" But the original scale factor type is MODIS_DIV_SCALE. "
1032 <<
" Now change it to MODIS_MUL_SCALE. "<<endl;
1047 #define RECALCULATE(CAST, DODS_CAST, VAL) \
1049 bool change_data_value = false; \
1050 if(sotype!=DEFAULT_CF_EQU) \
1052 if(scale_factor_attr_index!=FAIL && !(scale==1 && offset2==0)) \
1054 vector<float>tmpval; \
1055 tmpval.resize(nelms); \
1056 CAST tmptr = (CAST)VAL; \
1057 for(int l=0; l<nelms; l++) \
1058 tmpval[l] = (float)tmptr[l]; \
1059 float temp_scale = scale; \
1060 float temp_offset = offset2; \
1061 if(sotype==MODIS_MUL_SCALE) \
1062 temp_offset = -1. *offset2*temp_scale;\
1063 else if (sotype==MODIS_DIV_SCALE) \
1065 temp_scale = 1/scale; \
1066 temp_offset = -1. *temp_scale *offset2;\
1068 for(int l=0; l<nelms; l++) \
1069 if(attrindex!=FAIL && ((float)tmptr[l])!=fillvalue) \
1070 tmpval[l] = tmptr[l]*temp_scale + temp_offset; \
1071 change_data_value = true; \
1072 set_value((dods_float32 *)&tmpval[0], nelms); \
1075 if(!change_data_value) \
1077 set_value ((DODS_CAST)VAL, nelms); \
1084 char tmp_dimlist[1024];
1087 int32 tmp_dims[rank];
1090 int32 field_dtype = 0;
1097 r = fieldinfofunc (swathid, const_cast < char *>(fieldname.c_str ()),
1098 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1100 ostringstream eherr;
1101 eherr <<
"Field " << fieldname.c_str ()
1102 <<
" information cannot be obtained.";
1103 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1108 vector<int32> newdims;
1109 newdims.resize(rank);
1112 switch (field_dtype) {
1118 vector < int8 > total_val8;
1119 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1121 ostringstream eherr;
1122 eherr <<
"field " << fieldname.c_str ()
1123 <<
"cannot be read.";
1124 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1127 check_num_elems_constraint(nelms,newdims);
1132 FieldSubset (&val8[0], newdims, &total_val8[0],
1133 &offset32[0], &count32[0], &step32[0]);
1135 #ifndef SIGNED_BYTE_TO_INT32
1136 RECALCULATE(int8*, dods_byte*, &val8[0]);
1138 vector<int32>newval;
1139 newval.resize(nelms);
1141 for (
int counter = 0; counter < nelms; counter++)
1142 newval[counter] = (int32) (val8[counter]);
1144 RECALCULATE(int32*, dods_int32*, &newval[0]);
1153 vector < uint8 > total_val_u8;
1154 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1156 ostringstream eherr;
1157 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1158 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1161 check_num_elems_constraint(nelms,newdims);
1162 vector<uint8>val_u8;
1163 val_u8.resize(nelms);
1165 FieldSubset (&val_u8[0], newdims, &total_val_u8[0],
1166 &offset32[0], &count32[0], &step32[0]);
1167 RECALCULATE(uint8*, dods_byte*, &val_u8[0]);
1174 vector < int16 > total_val16;
1175 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1177 ostringstream eherr;
1178 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1179 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1182 check_num_elems_constraint(nelms,newdims);
1184 val16.resize(nelms);
1186 FieldSubset (&val16[0], newdims, &total_val16[0],
1187 &offset32[0], &count32[0], &step32[0]);
1189 RECALCULATE(int16*, dods_int16*, &val16[0]);
1196 vector < uint16 > total_val_u16;
1197 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1199 ostringstream eherr;
1201 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1202 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1205 check_num_elems_constraint(nelms,newdims);
1206 vector<uint16>val_u16;
1207 val_u16.resize(nelms);
1209 FieldSubset (&val_u16[0], newdims, &total_val_u16[0],
1210 &offset32[0], &count32[0], &step32[0]);
1211 RECALCULATE(uint16*, dods_uint16*, &val_u16[0]);
1219 vector < int32 > total_val32;
1220 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1222 ostringstream eherr;
1224 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1225 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1228 check_num_elems_constraint(nelms,newdims);
1229 vector<int32> val32;
1230 val32.resize(nelms);
1232 FieldSubset (&val32[0], newdims, &total_val32[0],
1233 &offset32[0], &count32[0], &step32[0]);
1235 RECALCULATE(int32*, dods_int32*, &val32[0]);
1243 vector < uint32 > total_val_u32;
1244 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, newdims);
1246 ostringstream eherr;
1247 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1248 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1251 check_num_elems_constraint(nelms,newdims);
1252 vector<uint32>val_u32;
1253 val_u32.resize(nelms);
1255 FieldSubset (&val_u32[0], newdims, &total_val_u32[0],
1256 &offset32[0], &count32[0], &step32[0]);
1257 RECALCULATE(uint32*, dods_uint32*, &val_u32[0]);
1265 vector < float32 > total_val_f32;
1266 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1268 ostringstream eherr;
1269 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1270 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1273 check_num_elems_constraint(nelms,newdims);
1274 vector<float32>val_f32;
1275 val_f32.resize(nelms);
1277 FieldSubset (&val_f32[0], newdims, &total_val_f32[0],
1278 &offset32[0], &count32[0], &step32[0]);
1279 RECALCULATE(float32*, dods_float32*, &val_f32[0]);
1285 vector < float64 > total_val_f64;
1286 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1288 ostringstream eherr;
1289 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1290 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1293 check_num_elems_constraint(nelms,newdims);
1294 vector<float64>val_f64;
1295 val_f64.resize(nelms);
1296 FieldSubset (&val_f64[0], newdims, &total_val_f64[0],
1297 &offset32[0], &count32[0], &step32[0]);
1298 RECALCULATE(float64*, dods_float64*, &val_f64[0]);
1304 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1312 HDFEOS2ArraySwathDimMapField::write_dap_data_disable_scale_comp(int32 swathid,
1314 vector<int32>& offset32,
1315 vector<int32>& count32,
1316 vector<int32>& step32) {
1319 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1320 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
1322 intn (*attrinfofunc) (int32,
char *, int32 *, int32 *);
1323 intn (*readattrfunc) (int32,
char *,
void*);
1325 fieldinfofunc = SWfieldinfo;
1326 readfieldfunc = SWreadfield;
1328 attrinfofunc = SWattrinfo;
1329 readattrfunc = SWreadattr;
1335 char tmp_dimlist[1024];
1338 int32 tmp_dims[rank];
1341 int32 field_dtype = 0;
1348 r = fieldinfofunc (swathid, const_cast < char *>(fieldname.c_str ()),
1349 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1351 ostringstream eherr;
1352 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1353 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1358 vector<int32> newdims;
1359 newdims.resize(rank);
1362 switch (field_dtype) {
1367 vector < int8 > total_val8;
1368 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1370 ostringstream eherr;
1371 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1372 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1375 check_num_elems_constraint(nelms,newdims);
1379 FieldSubset (&val8[0], newdims, &total_val8[0],
1380 &offset32[0], &count32[0], &step32[0]);
1383 #ifndef SIGNED_BYTE_TO_INT32
1384 set_value((dods_byte*)&val8[0],nelms);
1386 vector<int32>newval;
1387 newval.resize(nelms);
1389 for (
int counter = 0; counter < nelms; counter++)
1390 newval[counter] = (int32) (val8[counter]);
1392 set_value ((dods_int32 *) &newval[0], nelms);
1400 vector < uint8 > total_val_u8;
1401 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1403 ostringstream eherr;
1404 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1405 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1408 check_num_elems_constraint(nelms,newdims);
1409 vector<uint8>val_u8;
1410 val_u8.resize(nelms);
1412 FieldSubset (&val_u8[0], newdims, &total_val_u8[0],
1413 &offset32[0], &count32[0], &step32[0]);
1414 set_value ((dods_byte *) &val_u8[0], nelms);
1420 vector < int16 > total_val16;
1421 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1423 ostringstream eherr;
1424 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1425 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1428 check_num_elems_constraint(nelms,newdims);
1430 val16.resize(nelms);
1432 FieldSubset (&val16[0], newdims, &total_val16[0],
1433 &offset32[0], &count32[0], &step32[0]);
1435 set_value ((dods_int16 *) &val16[0], nelms);
1441 vector < uint16 > total_val_u16;
1442 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1444 ostringstream eherr;
1445 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1446 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1449 check_num_elems_constraint(nelms,newdims);
1450 vector<uint16>val_u16;
1451 val_u16.resize(nelms);
1453 FieldSubset (&val_u16[0], newdims, &total_val_u16[0],
1454 &offset32[0], &count32[0], &step32[0]);
1455 set_value ((dods_uint16 *) &val_u16[0], nelms);
1462 vector < int32 > total_val32;
1463 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1465 ostringstream eherr;
1467 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1468 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1471 check_num_elems_constraint(nelms,newdims);
1472 vector<int32> val32;
1473 val32.resize(nelms);
1475 FieldSubset (&val32[0], newdims, &total_val32[0],
1476 &offset32[0], &count32[0], &step32[0]);
1477 set_value ((dods_int32 *) &val32[0], nelms);
1484 vector < uint32 > total_val_u32;
1485 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, newdims);
1487 ostringstream eherr;
1489 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1490 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1493 check_num_elems_constraint(nelms,newdims);
1494 vector<uint32>val_u32;
1495 val_u32.resize(nelms);
1497 FieldSubset (&val_u32[0], newdims, &total_val_u32[0],
1498 &offset32[0], &count32[0], &step32[0]);
1499 set_value ((dods_uint32 *) &val_u32[0], nelms);
1506 vector < float32 > total_val_f32;
1507 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1509 ostringstream eherr;
1511 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1512 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1515 check_num_elems_constraint(nelms,newdims);
1516 vector<float32>val_f32;
1517 val_f32.resize(nelms);
1519 FieldSubset (&val_f32[0], newdims, &total_val_f32[0],
1520 &offset32[0], &count32[0], &step32[0]);
1522 set_value ((dods_float32 *) &val_f32[0], nelms);
1528 vector < float64 > total_val_f64;
1529 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1531 ostringstream eherr;
1533 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1534 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1537 check_num_elems_constraint(nelms,newdims);
1538 vector<float64>val_f64;
1539 val_f64.resize(nelms);
1540 FieldSubset (&val_f64[0], newdims, &total_val_f64[0],
1541 &offset32[0], &count32[0], &step32[0]);
1542 set_value ((dods_float64 *) &val_f64[0], nelms);
1548 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1559 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
1560 bool check_pass_fileid_key =
false;
1563 if(
true == isgeofile ||
false == check_pass_fileid_key) {
1575 bool HDFEOS2ArraySwathDimMapField::check_num_elems_constraint(
const int num_elems,
1576 const vector<int32>&newdims) {
1578 int total_dim_size = 1;
1579 for (
int i =0;i<rank;i++)
1580 total_dim_size*=newdims[i];
1582 if(total_dim_size < num_elems) {
1583 ostringstream eherr;
1584 eherr <<
"The total number of elements for the array " << total_dim_size
1585 <<
"is less than the user-requested number of elements " << num_elems;
1586 throw InternalErr (__FILE__, __LINE__, eherr.str ());
int32 INDEX_nD_TO_1D(const std::vector< int32 > &dims, const std::vector< int32 > &pos)
This inline routine will translate N dimensions into 1 dimension.
void close_fileid(hid_t fid)
closes HDF5 file reffered by fid.
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
From a string separated by a separator to a list of string, for example, split "ab,c" to {"ab","c"}.
static bool check_beskeys(const std::string &key)
Check the BES key. This function will check a BES key specified at the file h4.conf.in. If the key's value is either true or yes. The handler claims to find a key and will do some operations. Otherwise, will do different operations. For example, One may find a line H4.EnableCF=true at h4.conf.in. That means, the HDF4 handler will handle the HDF4 files by following CF conventions.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream