18#include "config_hdf.h"
23#include <libdap/debug.h>
24#include <libdap/InternalErr.h>
27#include "HDFEOS2ArraySwathDimMapField.h"
28#include "HDF4RequestHandler.h"
29#define SIGNED_BYTE_TO_INT32 1
33HDFEOS2ArraySwathDimMapField::read ()
36 BESDEBUG(
"h4",
"Coming to HDFEOS2ArraySwathDimMapField read "<<endl);
41 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
42 bool check_pass_fileid_key =
false;
43 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
46 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
59 int nelms = format_constraint(&offset[0],&step[0],&count[0]);
62 vector<int32>offset32;
63 offset32.resize(rank);
72 for (
int i = 0; i < rank; i++) {
73 offset32[i] = (int32) offset[i];
74 count32[i] = (int32) count[i];
75 step32[i] = (int32) step[i];
79 int32 (*openfunc) (
char *, intn);
80 intn (*closefunc) (int32);
81 int32 (*attachfunc) (int32,
char *);
82 intn (*detachfunc) (int32);
86 if (swathname ==
"") {
87 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
89 else if (gridname ==
"") {
92 attachfunc = SWattach;
93 detachfunc = SWdetach;
94 datasetname = swathname;
97 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
104 if (
true == isgeofile ||
false == check_pass_fileid_key) {
107 sfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
111 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
112 throw InternalErr (__FILE__, __LINE__, eherr.str ());
118 swathid = attachfunc (sfid,
const_cast < char *
>(datasetname.c_str ()));
122 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be attached.";
123 throw InternalErr (__FILE__, __LINE__, eherr.str ());
132 if(
true == dimmaps.empty()) {
138 if ((nummaps = SWnentries(swathid, HDFE_NENTMAP, &bufsize)) == -1){
141 throw InternalErr (__FILE__, __LINE__,
"cannot obtain the number of dimmaps");
147 throw InternalErr (__FILE__,__LINE__,
148 "Number of dimension maps should be greater than 0");
151 vector<char> namelist;
152 vector<int32> map_offset;
153 vector<int32> increment;
155 namelist.resize(bufsize + 1);
156 map_offset.resize(nummaps);
157 increment.resize(nummaps);
158 if (SWinqmaps(swathid, &namelist[0], &map_offset[0], &increment[0])
162 throw InternalErr (__FILE__,__LINE__,
"fail to inquiry dimension maps");
165 vector<string> mapnames;
168 for (vector<string>::const_iterator i = mapnames.begin();
169 i != mapnames.end(); ++i) {
170 vector<string> parts;
172 if (parts.size() != 2){
175 throw InternalErr (__FILE__,__LINE__,
"the dimmaps should only include two parts");
179 tempdimmap.geodim = parts[0];
180 tempdimmap.datadim = parts[1];
181 tempdimmap.offset = map_offset[map_count];
182 tempdimmap.inc = increment[map_count];
188 dimmaps.push_back(tempdimmap);
194for(
int i = 0; i <dimmaps.size();i++) {
195cerr<<
"dimmap geodim is: "<<dimmaps[i].geodim <<endl;
196cerr<<
"dimmap datadim is: "<<dimmaps[i].datadim <<endl;
197cerr<<
"offset is: "<<dimmaps[i].offset <<endl;
198cerr<<
"inc is: "<<dimmaps[i].inc <<endl;
206 if (sotype!=DEFAULT_CF_EQU) {
208 if(
"MODIS_SWATH_Type_L1B" == swathname) {
210 string emissive_str =
"Emissive";
211 string RefSB_str =
"RefSB";
212 bool is_emissive_field =
false;
213 bool is_refsb_field =
false;
215 if(fieldname.find(emissive_str)!=string::npos) {
216 if(0 == fieldname.compare(fieldname.size()-emissive_str.size(),
217 emissive_str.size(),emissive_str))
218 is_emissive_field =
true;
221 if(fieldname.find(RefSB_str)!=string::npos) {
222 if(0 == fieldname.compare(fieldname.size()-RefSB_str.size(),
223 RefSB_str.size(),RefSB_str))
224 is_refsb_field =
true;
227 if ((
true == is_emissive_field) || (
true == is_refsb_field)) {
230 throw InternalErr (__FILE__, __LINE__,
231 "Currently don't support MODIS Level 1B swath dim. map for data ");
236 bool is_modis1b =
false;
237 if(
"MODIS_SWATH_Type_L1B" == swathname)
240 string check_disable_scale_comp_key =
"H4.DisableScaleOffsetComp";
241 bool turn_on_disable_scale_comp_key=
false;
242 turn_on_disable_scale_comp_key = HDFCFUtil::check_beskeys(check_disable_scale_comp_key);
247 if(
true == HDF4RequestHandler::get_disable_scaleoffset_comp() &&
false== is_modis1b)
248 write_dap_data_disable_scale_comp(swathid,nelms,offset32,count32,step32);
250 write_dap_data_scale_comp(swathid,nelms,offset32,count32,step32);
259 r = detachfunc (swathid);
264 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
265 throw InternalErr (__FILE__, __LINE__, eherr.str ());
269 if(
true == isgeofile ||
false == check_pass_fileid_key) {
270 r = closefunc (sfid);
273 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
274 throw InternalErr (__FILE__, __LINE__, eherr.str ());
285HDFEOS2ArraySwathDimMapField::format_constraint (
int *offset,
int *step,
int *count)
290 Dim_iter p = dim_begin ();
291 while (p != dim_end ()) {
293 int start = dimension_start (p,
true);
294 int stride = dimension_stride (p,
true);
295 int stop = dimension_stop (p,
true);
300 oss <<
"Array/Grid hyperslab start point "<< start <<
301 " is greater than stop point " << stop <<
".";
302 throw Error(malformed_expr, oss.str());
307 count[id] = ((stop - start) / stride) + 1;
311 "=format_constraint():"
312 <<
"id=" <<
id <<
" offset=" << offset[
id]
313 <<
" step=" << step[
id]
314 <<
" count=" << count[
id]
326template <
class T >
int
327HDFEOS2ArraySwathDimMapField::
328GetFieldValue (int32 swathid,
const string & geofieldname,
329 vector < struct dimmap_entry >&sw_dimmaps,
330 vector < T > &vals, vector<int32>&newdims)
342 ret = SWfieldinfo (swathid,
const_cast < char *
>(geofieldname.c_str ()),
343 &sw_rank, dims, &type, dimlist);
348 for (
int i = 0; i <sw_rank; i++)
353 ret = SWreadfield (swathid,
const_cast < char *
>(geofieldname.c_str ()),
354 NULL, NULL, NULL, (
void *) &vals[0]);
358 vector < string > dimname;
361 for (
int i = 0; i < sw_rank; i++) {
362 vector < struct dimmap_entry >::iterator it;
364 for (it = sw_dimmaps.begin (); it != sw_dimmaps.end (); it++) {
365 if (it->geodim == dimname[i]) {
369 int32 ddimsize = SWdiminfo (swathid, (
char *) it->datadim.c_str ());
374 r = _expand_dimmap_field (&vals, sw_rank, dims, i, ddimsize, it->offset, it->inc);
382 for (
int i = 0; i < sw_rank; i++) {
386 newdims[i] = dims[i];
393template <
class T >
int
394HDFEOS2ArraySwathDimMapField::_expand_dimmap_field (vector < T >
395 *pvals, int32 sw_rank,
402 vector < T > orig = *pvals;
403 vector < int32 > pos;
404 vector < int32 > dims;
405 vector < int32 > newdims;
406 pos.resize (sw_rank);
407 dims.resize (sw_rank);
409 for (
int i = 0; i < sw_rank; i++) {
414 newdims[dimindex] = ddimsize;
415 dimsa[dimindex] = ddimsize;
419 for (
int i = 0; i < sw_rank; i++) {
420 newsize *= newdims[i];
423 pvals->resize (newsize);
427 if (pos[0] == dims[0]) {
431 else if (pos[dimindex] == 0) {
434 for (
int i = 0; i < dims[dimindex]; i++) {
436 v.push_back (orig[INDEX_nD_TO_1D (dims, pos)]);
441 for (int32 j = 0; j < ddimsize; j++) {
442 int32 i = (j - offset) / inc;
445 if (i * inc + offset == j)
451 int32 i2 = (i<=0)?1:0;
461 if ((
unsigned int) i + 1 >= v.size ()) {
469 j1 = i1 * inc + offset;
470 j2 = i2 * inc + offset;
471 f = (((j - j1) * v[i2] + (j2 - j) * v[i1]) / (j2 - j1));
475 (*pvals)[INDEX_nD_TO_1D (newdims, pos)] = f;
481 for (
int i = sw_rank - 1; i > 0; i--) {
482 if (pos[i] == dims[i]) {
493bool HDFEOS2ArraySwathDimMapField::FieldSubset (T * outlatlon,
494 const vector<int32>&newdims,
501 if (newdims.size() == 1)
502 Field1DSubset(outlatlon,newdims[0],latlon,offset,count,step);
503 else if (newdims.size() == 2)
504 Field2DSubset(outlatlon,newdims[0],newdims[1],latlon,offset,count,step);
505 else if (newdims.size() == 3)
506 Field3DSubset(outlatlon,newdims,latlon,offset,count,step);
508 throw InternalErr(__FILE__, __LINE__,
509 "Currently doesn't support rank >3 when interpolating with dimension map");
516bool HDFEOS2ArraySwathDimMapField::Field1DSubset (T * outlatlon,
523 if (majordim < count[0])
524 throw InternalErr(__FILE__, __LINE__,
525 "The number of elements is greater than the total dimensional size");
527 for (
int i = 0; i < count[0]; i++)
528 outlatlon[i] = latlon[offset[0]+i*step[0]];
535bool HDFEOS2ArraySwathDimMapField::Field2DSubset (T * outlatlon,
544 T (*templatlonptr)[majordim][minordim] = (T *[][]) latlon;
551 int dim0count = count[0];
552 int dim1count = count[1];
554 int dim0index[dim0count];
555 int dim1index[dim1count];
557 for (i = 0; i < count[0]; i++)
558 dim0index[i] = offset[0] + i * step[0];
561 for (j = 0; j < count[1]; j++)
562 dim1index[j] = offset[1] + j * step[1];
567 for (i = 0; i < count[0]; i++) {
568 for (j = 0; j < count[1]; j++) {
570 outlatlon[k] = (*templatlonptr)[dim0index[i]][dim1index[j]];
572 outlatlon[k] = *(latlon + (dim0index[i] * minordim) + dim1index[j]);
581bool HDFEOS2ArraySwathDimMapField::Field3DSubset (T * outlatlon,
582 const vector<int32>& newdims,
588 if (newdims.size() !=3)
589 throw InternalErr(__FILE__, __LINE__,
590 "the rank must be 3 to call this function");
592 T (*templatlonptr)[newdims[0]][newdims[1]][newdims[2]] = (T *[][][]) latlon;
600 int dim0count = count[0];
601 int dim1count = count[1];
602 int dim2count = count[2];
604 int dim0index[dim0count], dim1index[dim1count],dim2index[dim2count];
606 for (i = 0; i < count[0]; i++)
607 dim0index[i] = offset[0] + i * step[0];
610 for (j = 0; j < count[1]; j++)
611 dim1index[j] = offset[1] + j * step[1];
613 for (k = 0; k < count[2]; k++)
614 dim2index[k] = offset[2] + k * step[2];
619 for (i = 0; i < count[0]; i++) {
620 for (j = 0; j < count[1]; j++) {
621 for (k =0; k < count[2]; k++) {
623 outlatlon[l] = (*templatlonptr)[dim0index[i]][dim1index[j]][dim2index[k]];
625 outlatlon[l] = *(latlon + (dim0index[i] * newdims[1] * newdims[2]) + (dim1index[j] * newdims[2])+ dim2index[k]);
634HDFEOS2ArraySwathDimMapField::write_dap_data_scale_comp(int32 swathid,
636 vector<int32>& offset32,
637 vector<int32>& count32,
638 vector<int32>& step32) {
641 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
642 bool check_pass_fileid_key =
false;
643 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
646 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
649 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
652 fieldinfofunc = SWfieldinfo;
655 int32 attrcount = -1;
656 int32 attrindex = -1;
658 int32 scale_factor_attr_index = -1;
659 int32 add_offset_attr_index =-1;
663 float fillvalue = 0.;
665 if (sotype!=DEFAULT_CF_EQU) {
670 if (
true == isgeofile ||
false == check_pass_fileid_key) {
671 sdfileid = SDstart(
const_cast < char *
>(filename.c_str ()), DFACC_READ);
672 if (FAIL == sdfileid) {
674 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
675 throw InternalErr (__FILE__, __LINE__, eherr.str ());
684 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
685 if (FAIL == sdsindex) {
686 if(
true == isgeofile ||
false == check_pass_fileid_key)
689 eherr <<
"Cannot obtain the index of " << fieldname;
690 throw InternalErr (__FILE__, __LINE__, eherr.str ());
693 sdsid = SDselect(sdfileid, sdsindex);
695 if(
true == isgeofile ||
false == check_pass_fileid_key)
698 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
699 throw InternalErr (__FILE__, __LINE__, eherr.str ());
702 char attrname[H4_MAX_NC_NAME + 1];
703 vector<char> attrbuf;
704 vector<char> attrbuf2;
706 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
707 if(scale_factor_attr_index!=FAIL)
710 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname, &attrtype, &attrcount);
714 if(
true == isgeofile ||
false == check_pass_fileid_key)
717 eherr <<
"Attribute 'scale_factor' in "
718 << fieldname.c_str () <<
" cannot be obtained.";
719 throw InternalErr (__FILE__, __LINE__, eherr.str ());
723 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
724 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)&attrbuf[0]);
728 if(
true == isgeofile ||
false == check_pass_fileid_key)
731 eherr <<
"Attribute 'scale_factor' in "
732 << fieldname.c_str () <<
" cannot be obtained.";
733 throw InternalErr (__FILE__, __LINE__, eherr.str ());
743#define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
746 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
747 scale = (float)tmpvalue; \
750 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float);
751 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double);
753 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
757#undef GET_SCALE_FACTOR_ATTR_VALUE
760 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
761 if(add_offset_attr_index!=FAIL)
764 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname, &attrtype, &attrcount);
768 if(
true == isgeofile ||
false == check_pass_fileid_key)
771 eherr <<
"Attribute 'add_offset' in "
772 << fieldname.c_str () <<
" cannot be obtained.";
773 throw InternalErr (__FILE__, __LINE__, eherr.str ());
776 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
777 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)&attrbuf[0]);
781 if(
true == isgeofile ||
false == check_pass_fileid_key)
784 eherr <<
"Attribute 'add_offset' in "
785 << fieldname.c_str () <<
" cannot be obtained.";
786 throw InternalErr (__FILE__, __LINE__, eherr.str ());
790#define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
793 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
794 offset2 = (float)tmpvalue; \
797 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float);
798 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double);
800 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
802#undef GET_ADD_OFFSET_ATTR_VALUE
805 attrindex = SDfindattr(sdsid,
"_FillValue");
806 if(sotype!=DEFAULT_CF_EQU && attrindex!=FAIL)
809 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
813 if(
true == isgeofile ||
false == check_pass_fileid_key)
816 eherr <<
"Attribute '_FillValue' in "
817 << fieldname.c_str () <<
" cannot be obtained.";
818 throw InternalErr (__FILE__, __LINE__, eherr.str ());
821 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
822 ret = SDreadattr(sdsid, attrindex, (VOIDP)&attrbuf[0]);
826 if(
true == isgeofile ||
false == check_pass_fileid_key)
829 eherr <<
"Attribute '_FillValue' in "
830 << fieldname.c_str () <<
" cannot be obtained.";
831 throw InternalErr (__FILE__, __LINE__, eherr.str ());
836#define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
839 CAST tmpvalue = *(CAST*)&attrbuf[0]; \
840 fillvalue = (float)tmpvalue; \
843 GET_FILLVALUE_ATTR_VALUE(INT8, int8);
844 GET_FILLVALUE_ATTR_VALUE(INT16, int16);
845 GET_FILLVALUE_ATTR_VALUE(INT32, int32);
846 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8);
847 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16);
848 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32);
855#undef GET_FILLVALUE_ATTR_VALUE
862 float orig_valid_min = 0.;
863 float orig_valid_max = 0.;
869 attrindex = SDfindattr(sdsid,
"valid_range");
873 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
881 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
882 throw InternalErr (__FILE__, __LINE__, eherr.str ());
885 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
886 ret = SDreadattr(sdsid, attrindex, (VOIDP)&attrbuf[0]);
894 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
895 throw InternalErr (__FILE__, __LINE__, eherr.str ());
898 string attrbuf_str(attrbuf.begin(),attrbuf.end());
906 size_t found = attrbuf_str.find_first_of(
",");
907 size_t found_from_end = attrbuf_str.find_last_of(
",");
909 if (string::npos == found)
910 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
911 if (found != found_from_end)
912 throw InternalErr(__FILE__,__LINE__,
"Only one separator , should be available.");
917 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
918 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
925 if (2 == temp_attrcount) {
926 orig_valid_min = (float)attrbuf[0];
927 orig_valid_max = (float)attrbuf[1];
930 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be greater than 1.");
938 if (temp_attrcount != 2)
939 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT8 type.");
941 unsigned char* temp_valid_range = (
unsigned char *)&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_INT16 type.");
952 short* temp_valid_range = (
short *)&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_UINT16 type.");
963 unsigned short* temp_valid_range = (
unsigned short *)&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_INT32 type.");
974 int* temp_valid_range = (
int *)&attrbuf[0];
975 orig_valid_min = (float)(temp_valid_range[0]);
976 orig_valid_max = (float)(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_UINT32 type.");
985 unsigned int* temp_valid_range = (
unsigned int *)&attrbuf[0];
986 orig_valid_min = (float)(temp_valid_range[0]);
987 orig_valid_max = (float)(temp_valid_range[1]);
993 if (temp_attrcount != 2)
994 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
996 float* temp_valid_range = (
float *)&attrbuf[0];
997 orig_valid_min = temp_valid_range[0];
998 orig_valid_max = temp_valid_range[1];
1004 if (temp_attrcount != 2)
1005 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
1006 double* temp_valid_range = (
double *)&attrbuf[0];
1011 orig_valid_min = temp_valid_range[0];
1012 orig_valid_max = temp_valid_range[1];
1016 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
1031 if(
true == isgeofile ||
false == check_pass_fileid_key)
1063 if (MODIS_EQ_SCALE == sotype || MODIS_MUL_SCALE == sotype) {
1065 sotype = MODIS_DIV_SCALE;
1066 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1068 <<
" But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1070 <<
" Now change it to MODIS_DIV_SCALE. "<<endl;
1074 if (MODIS_DIV_SCALE == sotype) {
1076 sotype = MODIS_MUL_SCALE;
1077 (*BESLog::TheLog())<<
"The field " << fieldname <<
" scale factor is "
1079 <<
" But the original scale factor type is MODIS_DIV_SCALE. "
1081 <<
" Now change it to MODIS_MUL_SCALE. "<<endl;
1096#define RECALCULATE(CAST, DODS_CAST, VAL) \
1098 bool change_data_value = false; \
1099 if(sotype!=DEFAULT_CF_EQU) \
1101 if(scale_factor_attr_index!=FAIL && !(scale==1 && offset2==0)) \
1103 vector<float>tmpval; \
1104 tmpval.resize(nelms); \
1105 CAST tmptr = (CAST)VAL; \
1106 for(int l=0; l<nelms; l++) \
1107 tmpval[l] = (float)tmptr[l]; \
1108 float temp_scale = scale; \
1109 float temp_offset = offset2; \
1110 if(sotype==MODIS_MUL_SCALE) \
1111 temp_offset = -1. *offset2*temp_scale;\
1112 else if (sotype==MODIS_DIV_SCALE) \
1114 temp_scale = 1/scale; \
1115 temp_offset = -1. *temp_scale *offset2;\
1117 for(int l=0; l<nelms; l++) \
1118 if(attrindex!=FAIL && ((float)tmptr[l])!=fillvalue) \
1119 tmpval[l] = tmptr[l]*temp_scale + temp_offset; \
1120 change_data_value = true; \
1121 set_value((dods_float32 *)&tmpval[0], nelms); \
1124 if(!change_data_value) \
1126 set_value ((DODS_CAST)VAL, nelms); \
1133 char tmp_dimlist[1024];
1136 int32 tmp_dims[rank];
1139 int32 field_dtype = 0;
1146 r = fieldinfofunc (swathid,
const_cast < char *
>(fieldname.c_str ()),
1147 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1149 ostringstream eherr;
1150 eherr <<
"Field " << fieldname.c_str ()
1151 <<
" information cannot be obtained.";
1152 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1157 vector<int32> newdims;
1158 newdims.resize(rank);
1161 switch (field_dtype) {
1167 vector < int8 > total_val8;
1168 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1170 ostringstream eherr;
1171 eherr <<
"field " << fieldname.c_str ()
1172 <<
"cannot be read.";
1173 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1176 check_num_elems_constraint(nelms,newdims);
1181 FieldSubset (&val8[0], newdims, &total_val8[0],
1182 &offset32[0], &count32[0], &step32[0]);
1184#ifndef SIGNED_BYTE_TO_INT32
1185 RECALCULATE(int8*, dods_byte*, &val8[0]);
1187 vector<int32>newval;
1188 newval.resize(nelms);
1190 for (
int counter = 0; counter < nelms; counter++)
1191 newval[counter] = (int32) (val8[counter]);
1193 RECALCULATE(int32*, dods_int32*, &newval[0]);
1202 vector < uint8 > total_val_u8;
1203 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1205 ostringstream eherr;
1206 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1207 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1210 check_num_elems_constraint(nelms,newdims);
1211 vector<uint8>val_u8;
1212 val_u8.resize(nelms);
1214 FieldSubset (&val_u8[0], newdims, &total_val_u8[0],
1215 &offset32[0], &count32[0], &step32[0]);
1216 RECALCULATE(uint8*, dods_byte*, &val_u8[0]);
1223 vector < int16 > total_val16;
1224 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1226 ostringstream eherr;
1227 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1228 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1231 check_num_elems_constraint(nelms,newdims);
1233 val16.resize(nelms);
1235 FieldSubset (&val16[0], newdims, &total_val16[0],
1236 &offset32[0], &count32[0], &step32[0]);
1238 RECALCULATE(int16*, dods_int16*, &val16[0]);
1245 vector < uint16 > total_val_u16;
1246 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1248 ostringstream eherr;
1250 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1251 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1254 check_num_elems_constraint(nelms,newdims);
1255 vector<uint16>val_u16;
1256 val_u16.resize(nelms);
1258 FieldSubset (&val_u16[0], newdims, &total_val_u16[0],
1259 &offset32[0], &count32[0], &step32[0]);
1260 RECALCULATE(uint16*, dods_uint16*, &val_u16[0]);
1268 vector < int32 > total_val32;
1269 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1271 ostringstream eherr;
1273 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1274 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1277 check_num_elems_constraint(nelms,newdims);
1278 vector<int32> val32;
1279 val32.resize(nelms);
1281 FieldSubset (&val32[0], newdims, &total_val32[0],
1282 &offset32[0], &count32[0], &step32[0]);
1284 RECALCULATE(int32*, dods_int32*, &val32[0]);
1292 vector < uint32 > total_val_u32;
1293 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, 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<uint32>val_u32;
1302 val_u32.resize(nelms);
1304 FieldSubset (&val_u32[0], newdims, &total_val_u32[0],
1305 &offset32[0], &count32[0], &step32[0]);
1306 RECALCULATE(uint32*, dods_uint32*, &val_u32[0]);
1314 vector < float32 > total_val_f32;
1315 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1317 ostringstream eherr;
1318 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1319 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1322 check_num_elems_constraint(nelms,newdims);
1323 vector<float32>val_f32;
1324 val_f32.resize(nelms);
1326 FieldSubset (&val_f32[0], newdims, &total_val_f32[0],
1327 &offset32[0], &count32[0], &step32[0]);
1328 RECALCULATE(float32*, dods_float32*, &val_f32[0]);
1334 vector < float64 > total_val_f64;
1335 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1337 ostringstream eherr;
1338 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1339 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1342 check_num_elems_constraint(nelms,newdims);
1343 vector<float64>val_f64;
1344 val_f64.resize(nelms);
1345 FieldSubset (&val_f64[0], newdims, &total_val_f64[0],
1346 &offset32[0], &count32[0], &step32[0]);
1347 RECALCULATE(float64*, dods_float64*, &val_f64[0]);
1353 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1361HDFEOS2ArraySwathDimMapField::write_dap_data_disable_scale_comp(int32 swathid,
1363 vector<int32>& offset32,
1364 vector<int32>& count32,
1365 vector<int32>& step32) {
1368 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1370 fieldinfofunc = SWfieldinfo;
1376 char tmp_dimlist[1024];
1379 int32 tmp_dims[rank];
1382 int32 field_dtype = 0;
1389 r = fieldinfofunc (swathid,
const_cast < char *
>(fieldname.c_str ()),
1390 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1392 ostringstream eherr;
1393 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1394 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1399 vector<int32> newdims;
1400 newdims.resize(rank);
1403 switch (field_dtype) {
1408 vector < int8 > total_val8;
1409 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1411 ostringstream eherr;
1412 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1413 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1416 check_num_elems_constraint(nelms,newdims);
1420 FieldSubset (&val8[0], newdims, &total_val8[0],
1421 &offset32[0], &count32[0], &step32[0]);
1424#ifndef SIGNED_BYTE_TO_INT32
1425 set_value((dods_byte*)&val8[0],nelms);
1427 vector<int32>newval;
1428 newval.resize(nelms);
1430 for (
int counter = 0; counter < nelms; counter++)
1431 newval[counter] = (int32) (val8[counter]);
1433 set_value ((dods_int32 *) &newval[0], nelms);
1441 vector < uint8 > total_val_u8;
1442 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, 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<uint8>val_u8;
1451 val_u8.resize(nelms);
1453 FieldSubset (&val_u8[0], newdims, &total_val_u8[0],
1454 &offset32[0], &count32[0], &step32[0]);
1455 set_value ((dods_byte *) &val_u8[0], nelms);
1461 vector < int16 > total_val16;
1462 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1464 ostringstream eherr;
1465 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1466 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1469 check_num_elems_constraint(nelms,newdims);
1471 val16.resize(nelms);
1473 FieldSubset (&val16[0], newdims, &total_val16[0],
1474 &offset32[0], &count32[0], &step32[0]);
1476 set_value ((dods_int16 *) &val16[0], nelms);
1482 vector < uint16 > total_val_u16;
1483 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1485 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<uint16>val_u16;
1492 val_u16.resize(nelms);
1494 FieldSubset (&val_u16[0], newdims, &total_val_u16[0],
1495 &offset32[0], &count32[0], &step32[0]);
1496 set_value ((dods_uint16 *) &val_u16[0], nelms);
1503 vector < int32 > total_val32;
1504 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, 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<int32> val32;
1514 val32.resize(nelms);
1516 FieldSubset (&val32[0], newdims, &total_val32[0],
1517 &offset32[0], &count32[0], &step32[0]);
1518 set_value ((dods_int32 *) &val32[0], nelms);
1525 vector < uint32 > total_val_u32;
1526 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, 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<uint32>val_u32;
1536 val_u32.resize(nelms);
1538 FieldSubset (&val_u32[0], newdims, &total_val_u32[0],
1539 &offset32[0], &count32[0], &step32[0]);
1540 set_value ((dods_uint32 *) &val_u32[0], nelms);
1547 vector < float32 > total_val_f32;
1548 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, 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<float32>val_f32;
1558 val_f32.resize(nelms);
1560 FieldSubset (&val_f32[0], newdims, &total_val_f32[0],
1561 &offset32[0], &count32[0], &step32[0]);
1563 set_value ((dods_float32 *) &val_f32[0], nelms);
1569 vector < float64 > total_val_f64;
1570 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1572 ostringstream eherr;
1574 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1575 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1578 check_num_elems_constraint(nelms,newdims);
1579 vector<float64>val_f64;
1580 val_f64.resize(nelms);
1581 FieldSubset (&val_f64[0], newdims, &total_val_f64[0],
1582 &offset32[0], &count32[0], &step32[0]);
1583 set_value ((dods_float64 *) &val_f64[0], nelms);
1589 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1601 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
1602 bool check_pass_fileid_key =
false;
1603 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
1607 if(
true == isgeofile ||
false == HDF4RequestHandler::get_pass_fileid()) {
1619bool HDFEOS2ArraySwathDimMapField::check_num_elems_constraint(
const int num_elems,
1620 const vector<int32>&newdims) {
1622 int total_dim_size = 1;
1623 for (
int i =0;i<rank;i++)
1624 total_dim_size*=newdims[i];
1626 if(total_dim_size < num_elems) {
1627 ostringstream eherr;
1628 eherr <<
"The total number of elements for the array " << total_dim_size
1629 <<
"is less than the user-requested number of elements " << num_elems;
1630 throw InternalErr (__FILE__, __LINE__, eherr.str ());
void close_fileid(hid_t fid)
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)