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
34HDFEOS2ArraySwathDimMapField::read ()
37 BESDEBUG(
"h4",
"Coming to HDFEOS2ArraySwathDimMapField read "<<endl);
41 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
54 int nelms = format_constraint(offset.data(),step.data(),count.data());
58 offset32.resize(rank);
67 for (
int i = 0; i < rank; i++) {
68 offset32[i] = (int32) offset[i];
69 count32[i] = (int32) count[i];
70 step32[i] = (int32) step[i];
74 int32 (*openfunc) (
char *, intn);
75 intn (*closefunc) (int32);
76 int32 (*attachfunc) (int32,
char *);
77 intn (*detachfunc) (int32);
81 if (swathname ==
"") {
82 throw InternalErr (__FILE__, __LINE__,
"It should be either grid or swath.");
84 else if (gridname ==
"") {
87 attachfunc = SWattach;
88 detachfunc = SWdetach;
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 ()));
115 close_fileid (sfid,-1);
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){
135 close_fileid(sfid,-1);
136 throw InternalErr (__FILE__, __LINE__,
"cannot obtain the number of dimmaps");
141 close_fileid(sfid,-1);
142 throw InternalErr (__FILE__,__LINE__,
143 "Number of dimension maps should be greater than 0");
150 namelist.resize(bufsize + 1);
151 map_offset.resize(nummaps);
152 increment.resize(nummaps);
153 if (SWinqmaps(swathid, namelist.data(), map_offset.data(), increment.data())
156 close_fileid(sfid,-1);
157 throw InternalErr (__FILE__,__LINE__,
"fail to inquiry dimension maps");
163 for (
auto const &mapname:mapnames) {
166 if (parts.size() != 2){
168 close_fileid(sfid,-1);
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 = map_offset[map_count];
176 tempdimmap.inc = increment[map_count];
177 dimmaps.push_back(tempdimmap);
182 if (sotype!=SOType::DEFAULT_CF_EQU) {
184 if (
"MODIS_SWATH_Type_L1B" == swathname) {
186 string emissive_str =
"Emissive";
187 string RefSB_str =
"RefSB";
188 bool is_emissive_field =
false;
189 bool is_refsb_field =
false;
191 if (fieldname.find(emissive_str)!=string::npos) {
192 if (0 == fieldname.compare(fieldname.size()-emissive_str.size(),
193 emissive_str.size(),emissive_str))
194 is_emissive_field =
true;
197 if (fieldname.find(RefSB_str)!=string::npos) {
198 if (0 == fieldname.compare(fieldname.size()-RefSB_str.size(),
199 RefSB_str.size(),RefSB_str))
200 is_refsb_field =
true;
203 if ((
true == is_emissive_field) || (
true == is_refsb_field)) {
205 close_fileid(sfid,-1);
206 throw InternalErr (__FILE__, __LINE__,
207 "Currently don't support MODIS Level 1B swath dim. map for data ");
212 bool is_modis1b =
false;
213 if (
"MODIS_SWATH_Type_L1B" == swathname)
217 if (
true == HDF4RequestHandler::get_disable_scaleoffset_comp() &&
false== is_modis1b)
218 write_dap_data_disable_scale_comp(swathid,nelms,offset32,count32,step32);
220 write_dap_data_scale_comp(swathid,nelms,offset32,count32,step32);
224 close_fileid(sfid,-1);
229 r = detachfunc (swathid);
231 close_fileid(sfid,-1);
234 eherr <<
"Grid/Swath " << datasetname.c_str () <<
" cannot be detached.";
235 throw InternalErr (__FILE__, __LINE__, eherr.str ());
239 if (
true == isgeofile ||
false == check_pass_fileid_key) {
240 r = closefunc (sfid);
243 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
244 throw InternalErr (__FILE__, __LINE__, eherr.str ());
255HDFEOS2ArraySwathDimMapField::format_constraint (
int *offset,
int *step,
int *count)
260 Dim_iter p = dim_begin ();
261 while (p != dim_end ()) {
263 int start = dimension_start (p,
true);
264 int stride = dimension_stride (p,
true);
265 int stop = dimension_stop (p,
true);
270 oss <<
"Array/Grid hyperslab start point "<< start <<
271 " is greater than stop point " << stop <<
".";
272 throw Error(malformed_expr, oss.str());
277 count[id] = ((stop - start) / stride) + 1;
281 "=format_constraint():"
282 <<
"id=" <<
id <<
" offset=" << offset[
id]
283 <<
" step=" << step[
id]
284 <<
" count=" << count[
id]
296template <
class T >
int
297HDFEOS2ArraySwathDimMapField::
298GetFieldValue (int32 swathid,
const string & geofieldname,
299 const vector < struct dimmap_entry >&sw_dimmaps,
312 ret = SWfieldinfo (swathid,
const_cast < char *
>(geofieldname.c_str ()),
313 &sw_rank, dims, &type, dimlist);
318 for (
int i = 0; i <sw_rank; i++)
323 ret = SWreadfield (swathid,
const_cast < char *
>(geofieldname.c_str ()),
324 nullptr,
nullptr,
nullptr, (
void *) vals.data());
328 vector < string > dimname;
331 for (
int i = 0; i < sw_rank; i++) {
333 for (
const auto & dmap:sw_dimmaps) {
334 if (dmap.geodim == dimname[i]) {
335 int32 ddimsize = SWdiminfo (swathid, (
char *) dmap.datadim.c_str ());
340 r = _expand_dimmap_field (&vals, sw_rank, dims, i, ddimsize, dmap.offset, dmap.inc);
348 for (
int i = 0; i < sw_rank; i++) {
351 newdims[i] = dims[i];
358template <
class T >
int
359HDFEOS2ArraySwathDimMapField::_expand_dimmap_field (vector < T >
360 *pvals, int32 sw_rank,
367 vector < T > orig = *pvals;
368 vector < int32 > pos;
369 vector < int32 > dims;
370 vector < int32 > newdims;
371 pos.resize (sw_rank);
372 dims.resize (sw_rank);
374 for (
int i = 0; i < sw_rank; i++) {
379 newdims[dimindex] = ddimsize;
380 dimsa[dimindex] = ddimsize;
384 for (
int i = 0; i < sw_rank; i++) {
385 newsize *= newdims[i];
388 pvals->resize (newsize);
392 if (pos[0] == dims[0]) {
396 else if (pos[dimindex] == 0) {
399 for (
int i = 0; i < dims[dimindex]; i++) {
401 v.push_back (orig[INDEX_nD_TO_1D (dims, pos)]);
406 for (int32 j = 0; j < ddimsize; j++) {
407 int32 i = (j - offset) / inc;
410 if (i * inc + offset == j)
416 int32 i2 = (i<=0)?1:0;
420 if ((
unsigned int) i + 1 >= v.size ()) {
428 j1 = i1 * inc + offset;
429 j2 = i2 * inc + offset;
430 f = (((j - j1) * v[i2] + (j2 - j) * v[i1]) / (j2 - j1));
434 (*pvals)[INDEX_nD_TO_1D (newdims, pos)] = f;
440 for (
int i = sw_rank - 1; i > 0; i--) {
441 if (pos[i] == dims[i]) {
452bool HDFEOS2ArraySwathDimMapField::FieldSubset (T * outlatlon,
455 const int32 * offset,
460 if (newdims.size() == 1)
461 Field1DSubset(outlatlon,newdims[0],latlon,offset,count,step);
462 else if (newdims.size() == 2)
463 Field2DSubset(outlatlon,newdims[0],newdims[1],latlon,offset,count,step);
464 else if (newdims.size() == 3)
465 Field3DSubset(outlatlon,newdims,latlon,offset,count,step);
467 throw InternalErr(__FILE__, __LINE__,
468 "Currently doesn't support rank >3 when interpolating with dimension map");
475bool HDFEOS2ArraySwathDimMapField::Field1DSubset (T * outlatlon,
478 const int32 * offset,
482 if (majordim < count[0])
483 throw InternalErr(__FILE__, __LINE__,
484 "The number of elements is greater than the total dimensional size");
486 for (
int i = 0; i < count[0]; i++)
487 outlatlon[i] = latlon[offset[0]+i*step[0]];
494bool HDFEOS2ArraySwathDimMapField::Field2DSubset (T * outlatlon,
498 const int32 * offset,
507 int dim0count = count[0];
508 int dim1count = count[1];
513 for (i = 0; i < count[0]; i++)
514 dim0index[i] = offset[0] + i * step[0];
517 for (j = 0; j < count[1]; j++)
518 dim1index[j] = offset[1] + j * step[1];
523 for (i = 0; i < count[0]; i++) {
524 for (j = 0; j < count[1]; j++) {
525 outlatlon[k] = *(latlon + (dim0index[i] * minordim) + dim1index[j]);
534bool HDFEOS2ArraySwathDimMapField::Field3DSubset (T * outlatlon,
537 const int32 * offset,
541 if (newdims.size() !=3)
542 throw InternalErr(__FILE__, __LINE__,
543 "the rank must be 3 to call this function");
550 int dim0count = count[0];
551 int dim1count = count[1];
552 int dim2count = count[2];
558 for (i = 0; i < count[0]; i++)
559 dim0index[i] = offset[0] + i * step[0];
562 for (j = 0; j < count[1]; j++)
563 dim1index[j] = offset[1] + j * step[1];
565 for (k = 0; k < count[2]; k++)
566 dim2index[k] = offset[2] + k * step[2];
571 for (i = 0; i < count[0]; i++) {
572 for (j = 0; j < count[1]; j++) {
573 for (k =0; k < count[2]; k++) {
574 outlatlon[l] = *(latlon + (dim0index[i] * newdims[1] * newdims[2]) + (dim1index[j] * newdims[2])+ dim2index[k]);
583HDFEOS2ArraySwathDimMapField::write_dap_data_scale_comp(int32 swathid,
590 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
593 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
596 fieldinfofunc = SWfieldinfo;
599 int32 attrcount = -1;
600 int32 attrindex = -1;
602 int32 scale_factor_attr_index = -1;
603 int32 add_offset_attr_index =-1;
607 float fillvalue = 0.;
609 if (sotype!=SOType::DEFAULT_CF_EQU) {
614 if (
true == isgeofile ||
false == check_pass_fileid_key) {
615 sdfileid = SDstart(filename.c_str (), DFACC_READ);
616 if (FAIL == sdfileid) {
618 eherr <<
"Cannot Start the SD interface for the file " << filename <<endl;
619 throw InternalErr (__FILE__, __LINE__, eherr.str ());
628 sdsindex = SDnametoindex(sdfileid, fieldname.c_str());
629 if (FAIL == sdsindex) {
630 if (
true == isgeofile ||
false == check_pass_fileid_key)
633 eherr <<
"Cannot obtain the index of " << fieldname;
634 throw InternalErr (__FILE__, __LINE__, eherr.str ());
637 sdsid = SDselect(sdfileid, sdsindex);
639 if (
true == isgeofile ||
false == check_pass_fileid_key)
642 eherr <<
"Cannot obtain the SDS ID of " << fieldname;
643 throw InternalErr (__FILE__, __LINE__, eherr.str ());
646 char attrname[H4_MAX_NC_NAME + 1];
650 scale_factor_attr_index = SDfindattr(sdsid,
"scale_factor");
651 if (scale_factor_attr_index!=FAIL)
654 ret = SDattrinfo(sdsid, scale_factor_attr_index, attrname, &attrtype, &attrcount);
658 if (
true == isgeofile ||
false == check_pass_fileid_key)
661 eherr <<
"Attribute 'scale_factor' in "
662 << fieldname.c_str () <<
" cannot be obtained.";
663 throw InternalErr (__FILE__, __LINE__, eherr.str ());
667 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
668 ret = SDreadattr(sdsid, scale_factor_attr_index, (VOIDP)attrbuf.data());
672 if (
true == isgeofile ||
false == check_pass_fileid_key)
675 eherr <<
"Attribute 'scale_factor' in "
676 << fieldname.c_str () <<
" cannot be obtained.";
677 throw InternalErr (__FILE__, __LINE__, eherr.str ());
687#define GET_SCALE_FACTOR_ATTR_VALUE(TYPE, CAST) \
690 CAST tmpvalue = *(CAST*)attrbuf.data(); \
691 scale = (float)tmpvalue; \
694 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT32,
float)
695 GET_SCALE_FACTOR_ATTR_VALUE(FLOAT64,
double)
697 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
701#undef GET_SCALE_FACTOR_ATTR_VALUE
704 add_offset_attr_index = SDfindattr(sdsid,
"add_offset");
705 if (add_offset_attr_index!=FAIL)
708 ret = SDattrinfo(sdsid, add_offset_attr_index, attrname, &attrtype, &attrcount);
712 if (
true == isgeofile ||
false == check_pass_fileid_key)
715 eherr <<
"Attribute 'add_offset' in "
716 << fieldname.c_str () <<
" cannot be obtained.";
717 throw InternalErr (__FILE__, __LINE__, eherr.str ());
720 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
721 ret = SDreadattr(sdsid, add_offset_attr_index, (VOIDP)attrbuf.data());
725 if (
true == isgeofile ||
false == check_pass_fileid_key)
728 eherr <<
"Attribute 'add_offset' in "
729 << fieldname.c_str () <<
" cannot be obtained.";
730 throw InternalErr (__FILE__, __LINE__, eherr.str ());
734#define GET_ADD_OFFSET_ATTR_VALUE(TYPE, CAST) \
737 CAST tmpvalue = *(CAST*)attrbuf.data(); \
738 offset2 = (float)tmpvalue; \
741 GET_ADD_OFFSET_ATTR_VALUE(FLOAT32,
float)
742 GET_ADD_OFFSET_ATTR_VALUE(FLOAT64,
double)
744 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
746#undef GET_ADD_OFFSET_ATTR_VALUE
749 attrindex = SDfindattr(sdsid,
"_FillValue");
750 if (sotype!=SOType::DEFAULT_CF_EQU && attrindex!=FAIL)
753 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
757 if (
true == isgeofile ||
false == check_pass_fileid_key)
760 eherr <<
"Attribute '_FillValue' in "
761 << fieldname.c_str () <<
" cannot be obtained.";
762 throw InternalErr (__FILE__, __LINE__, eherr.str ());
765 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
766 ret = SDreadattr(sdsid, attrindex, (VOIDP)attrbuf.data());
770 if (
true == isgeofile ||
false == check_pass_fileid_key)
773 eherr <<
"Attribute '_FillValue' in "
774 << fieldname.c_str () <<
" cannot be obtained.";
775 throw InternalErr (__FILE__, __LINE__, eherr.str ());
780#define GET_FILLVALUE_ATTR_VALUE(TYPE, CAST) \
783 CAST tmpvalue = *(CAST*)attrbuf.data(); \
784 fillvalue = (float)tmpvalue; \
787 GET_FILLVALUE_ATTR_VALUE(INT8, int8)
788 GET_FILLVALUE_ATTR_VALUE(INT16, int16)
789 GET_FILLVALUE_ATTR_VALUE(INT32, int32)
790 GET_FILLVALUE_ATTR_VALUE(UINT8, uint8)
791 GET_FILLVALUE_ATTR_VALUE(UINT16, uint16)
792 GET_FILLVALUE_ATTR_VALUE(UINT32, uint32)
798#undef GET_FILLVALUE_ATTR_VALUE
806 float orig_valid_min = 0.;
807 float orig_valid_max = 0.;
813 attrindex = SDfindattr(sdsid,
"valid_range");
817 ret = SDattrinfo(sdsid, attrindex, attrname, &attrtype, &attrcount);
825 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
826 throw InternalErr (__FILE__, __LINE__, eherr.str ());
829 attrbuf.resize(DFKNTsize(attrtype)*attrcount);
830 ret = SDreadattr(sdsid, attrindex, (VOIDP)attrbuf.data());
838 eherr <<
"Attribute '_FillValue' in " << fieldname.c_str () <<
" cannot be obtained.";
839 throw InternalErr (__FILE__, __LINE__, eherr.str ());
842 string attrbuf_str(attrbuf.begin(),attrbuf.end());
850 size_t found = attrbuf_str.find_first_of(
",");
851 size_t found_from_end = attrbuf_str.find_last_of(
",");
853 if (string::npos == found)
854 throw InternalErr(__FILE__,__LINE__,
"should find the separator ,");
855 if (found != found_from_end)
856 throw InternalErr(__FILE__,__LINE__,
"Only one separator , should be available.");
861 orig_valid_min = atof((attrbuf_str.substr(0,found)).c_str());
862 orig_valid_max = atof((attrbuf_str.substr(found+1)).c_str());
869 if (2 == temp_attrcount) {
870 orig_valid_min = (float)attrbuf[0];
871 orig_valid_max = (float)attrbuf[1];
874 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be greater than 1.");
882 if (temp_attrcount != 2)
883 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT8 type.");
885 unsigned char* temp_valid_range = (
unsigned char *)attrbuf.data();
886 orig_valid_min = (float)(temp_valid_range[0]);
887 orig_valid_max = (float)(temp_valid_range[1]);
893 if (temp_attrcount != 2)
894 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_INT16 type.");
896 short* temp_valid_range = (
short *)attrbuf.data();
897 orig_valid_min = (float)(temp_valid_range[0]);
898 orig_valid_max = (float)(temp_valid_range[1]);
904 if (temp_attrcount != 2)
905 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT16 type.");
907 unsigned short* temp_valid_range = (
unsigned short *)attrbuf.data();
908 orig_valid_min = (float)(temp_valid_range[0]);
909 orig_valid_max = (float)(temp_valid_range[1]);
915 if (temp_attrcount != 2)
916 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_INT32 type.");
918 int* temp_valid_range = (
int *)attrbuf.data();
919 orig_valid_min = (float)(temp_valid_range[0]);
920 orig_valid_max = (float)(temp_valid_range[1]);
926 if (temp_attrcount != 2)
927 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_UINT32 type.");
929 unsigned int* temp_valid_range = (
unsigned int *)attrbuf.data();
930 orig_valid_min = (float)(temp_valid_range[0]);
931 orig_valid_max = (float)(temp_valid_range[1]);
937 if (temp_attrcount != 2)
938 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
940 float* temp_valid_range = (
float *)attrbuf.data();
941 orig_valid_min = temp_valid_range[0];
942 orig_valid_max = temp_valid_range[1];
948 if (temp_attrcount != 2)
949 throw InternalErr(__FILE__,__LINE__,
"The number of attribute count should be 2 for the DFNT_FLOAT32 type.");
950 double* temp_valid_range = (
double *)attrbuf.data();
955 orig_valid_min = temp_valid_range[0];
956 orig_valid_max = temp_valid_range[1];
960 throw InternalErr(__FILE__,__LINE__,
"Unsupported data type.");
969 if (
true == isgeofile ||
false == check_pass_fileid_key)
1001 if (SOType::MODIS_EQ_SCALE == sotype || SOType::MODIS_MUL_SCALE == sotype) {
1003 sotype = SOType::MODIS_DIV_SCALE;
1004 INFO_LOG(
"The field " + fieldname +
" scale factor is "
1005 + std::to_string(scale) +
". But the original scale factor type is MODIS_MUL_SCALE or MODIS_EQ_SCALE. "
1006 +
" Now change it to MODIS_DIV_SCALE. ");
1010 if (SOType::MODIS_DIV_SCALE == sotype) {
1012 sotype = SOType::MODIS_MUL_SCALE;
1013 INFO_LOG(
"The field " + fieldname +
" scale factor is " + std::to_string(scale) +
1014 +
" But the original scale factor type is MODIS_DIV_SCALE. "
1015 +
" Now change it to MODIS_MUL_SCALE.");
1020#define RECALCULATE(CAST, DODS_CAST, VAL) \
1022 bool change_data_value = false; \
1023 if (sotype!=SOType::DEFAULT_CF_EQU) \
1025 if (scale_factor_attr_index!=FAIL && !(scale==1 && offset2==0)) \
1027 vector<float>tmpval; \
1028 tmpval.resize(nelms); \
1029 CAST tmptr = (CAST)VAL; \
1030 for(int l=0; l<nelms; l++) \
1031 tmpval[l] = (float)tmptr[l]; \
1032 float temp_scale = scale; \
1033 float temp_offset = offset2; \
1034 if (sotype==SOType::MODIS_MUL_SCALE) \
1035 temp_offset = -1. *offset2*temp_scale;\
1036 else if (sotype==SOType::MODIS_DIV_SCALE) \
1038 temp_scale = 1/scale; \
1039 temp_offset = -1. *temp_scale *offset2;\
1041 for(int l=0; l<nelms; l++) \
1042 if (attrindex!=FAIL && ((float)tmptr[l])!=fillvalue) \
1043 tmpval[l] = tmptr[l]*temp_scale + temp_offset; \
1044 change_data_value = true; \
1045 set_value((dods_float32 *)tmpval.data(), nelms); \
1048 if (!change_data_value) \
1050 set_value ((DODS_CAST)VAL, nelms); \
1057 char tmp_dimlist[1024];
1060 int32 tmp_dims[rank];
1063 int32 field_dtype = 0;
1070 r = fieldinfofunc (swathid,
const_cast < char *
>(fieldname.c_str ()),
1071 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1074 eherr <<
"Field " << fieldname.c_str ()
1075 <<
" information cannot be obtained.";
1076 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1081 newdims.resize(rank);
1084 switch (field_dtype) {
1090 vector < int8 > total_val8;
1091 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1094 eherr <<
"field " << fieldname.c_str ()
1095 <<
"cannot be read.";
1096 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1099 check_num_elems_constraint(nelms,newdims);
1104 FieldSubset (val8.data(), newdims, total_val8.data(),
1105 offset32.data(), count32.data(), step32.data());
1107#ifndef SIGNED_BYTE_TO_INT32
1108 RECALCULATE(int8*, dods_byte*, val8.data());
1111 newval.resize(nelms);
1113 for (
int counter = 0; counter < nelms; counter++)
1114 newval[counter] = (int32) (val8[counter]);
1116 RECALCULATE(int32*, dods_int32*, newval.data())
1125 vector < uint8 > total_val_u8;
1126 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1129 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1130 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1133 check_num_elems_constraint(nelms,newdims);
1135 val_u8.resize(nelms);
1137 FieldSubset (val_u8.data(), newdims, total_val_u8.data(),
1138 offset32.data(), count32.data(), step32.data());
1139 RECALCULATE(uint8*, dods_byte*, val_u8.data())
1146 vector < int16 > total_val16;
1147 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1150 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1151 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1154 check_num_elems_constraint(nelms,newdims);
1156 val16.resize(nelms);
1158 FieldSubset (val16.data(), newdims, total_val16.data(),
1159 offset32.data(), count32.data(), step32.data());
1161 RECALCULATE(int16*, dods_int16*, val16.data())
1168 vector < uint16 > total_val_u16;
1169 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1173 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1174 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1177 check_num_elems_constraint(nelms,newdims);
1179 val_u16.resize(nelms);
1181 FieldSubset (val_u16.data(), newdims, total_val_u16.data(),
1182 offset32.data(), count32.data(), step32.data());
1183 RECALCULATE(uint16*, dods_uint16*, val_u16.data())
1191 vector < int32 > total_val32;
1192 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1196 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1197 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1200 check_num_elems_constraint(nelms,newdims);
1202 val32.resize(nelms);
1204 FieldSubset (val32.data(), newdims, total_val32.data(),
1205 offset32.data(), count32.data(), step32.data());
1207 RECALCULATE(int32*, dods_int32*, val32.data())
1215 vector < uint32 > total_val_u32;
1216 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, newdims);
1219 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1220 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1223 check_num_elems_constraint(nelms,newdims);
1225 val_u32.resize(nelms);
1227 FieldSubset (val_u32.data(), newdims, total_val_u32.data(),
1228 offset32.data(), count32.data(), step32.data());
1229 RECALCULATE(uint32*, dods_uint32*, val_u32.data())
1237 vector < float32 > total_val_f32;
1238 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1241 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1242 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1245 check_num_elems_constraint(nelms,newdims);
1247 val_f32.resize(nelms);
1249 FieldSubset (val_f32.data(), newdims, total_val_f32.data(),
1250 offset32.data(), count32.data(), step32.data());
1251 RECALCULATE(float32*, dods_float32*, val_f32.data())
1257 vector < float64 > total_val_f64;
1258 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1261 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1262 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1265 check_num_elems_constraint(nelms,newdims);
1267 val_f64.resize(nelms);
1268 FieldSubset (val_f64.data(), newdims, total_val_f64.data(),
1269 offset32.data(), count32.data(), step32.data());
1270 RECALCULATE(float64*, dods_float64*, val_f64.data())
1276 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1284HDFEOS2ArraySwathDimMapField::write_dap_data_disable_scale_comp(int32 swathid,
1291 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
1293 fieldinfofunc = SWfieldinfo;
1299 char tmp_dimlist[1024];
1302 int32 tmp_dims[rank];
1305 int32 field_dtype = 0;
1312 r = fieldinfofunc (swathid,
const_cast < char *
>(fieldname.c_str ()),
1313 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
1316 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
1317 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1323 newdims.resize(rank);
1326 switch (field_dtype) {
1331 vector < int8 > total_val8;
1332 r = GetFieldValue (swathid, fieldname, dimmaps, total_val8, newdims);
1335 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1336 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1339 check_num_elems_constraint(nelms,newdims);
1343 FieldSubset (val8.data(), newdims, total_val8.data(),
1344 offset32.data(), count32.data(), step32.data());
1347#ifndef SIGNED_BYTE_TO_INT32
1348 set_value((dods_byte*)val8.data(),nelms);
1351 newval.resize(nelms);
1353 for (
int counter = 0; counter < nelms; counter++)
1354 newval[counter] = (int32) (val8[counter]);
1356 set_value ((dods_int32 *) newval.data(), nelms);
1364 vector < uint8 > total_val_u8;
1365 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u8, newdims);
1368 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1369 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1372 check_num_elems_constraint(nelms,newdims);
1374 val_u8.resize(nelms);
1376 FieldSubset (val_u8.data(), newdims, total_val_u8.data(),
1377 offset32.data(), count32.data(), step32.data());
1378 set_value ((dods_byte *) val_u8.data(), nelms);
1384 vector < int16 > total_val16;
1385 r = GetFieldValue (swathid, fieldname, dimmaps, total_val16, newdims);
1388 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1389 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1392 check_num_elems_constraint(nelms,newdims);
1394 val16.resize(nelms);
1396 FieldSubset (val16.data(), newdims, total_val16.data(),
1397 offset32.data(), count32.data(), step32.data());
1399 set_value ((dods_int16 *) val16.data(), nelms);
1405 vector < uint16 > total_val_u16;
1406 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u16, newdims);
1409 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1410 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1413 check_num_elems_constraint(nelms,newdims);
1415 val_u16.resize(nelms);
1417 FieldSubset (val_u16.data(), newdims, total_val_u16.data(),
1418 offset32.data(), count32.data(), step32.data());
1419 set_value ((dods_uint16 *) val_u16.data(), nelms);
1426 vector < int32 > total_val32;
1427 r = GetFieldValue (swathid, fieldname, dimmaps, total_val32, newdims);
1431 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1432 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1435 check_num_elems_constraint(nelms,newdims);
1437 val32.resize(nelms);
1439 FieldSubset (val32.data(), newdims, total_val32.data(),
1440 offset32.data(), count32.data(), step32.data());
1441 set_value ((dods_int32 *) val32.data(), nelms);
1448 vector < uint32 > total_val_u32;
1449 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_u32, newdims);
1453 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1454 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1457 check_num_elems_constraint(nelms,newdims);
1459 val_u32.resize(nelms);
1461 FieldSubset (val_u32.data(), newdims, total_val_u32.data(),
1462 offset32.data(), count32.data(), step32.data());
1463 set_value ((dods_uint32 *) val_u32.data(), nelms);
1470 vector < float32 > total_val_f32;
1471 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f32, newdims);
1475 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1476 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1479 check_num_elems_constraint(nelms,newdims);
1481 val_f32.resize(nelms);
1483 FieldSubset (val_f32.data(), newdims, total_val_f32.data(),
1484 offset32.data(), count32.data(), step32.data());
1486 set_value ((dods_float32 *) val_f32.data(), nelms);
1492 vector < float64 > total_val_f64;
1493 r = GetFieldValue (swathid, fieldname, dimmaps, total_val_f64, newdims);
1497 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1498 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1501 check_num_elems_constraint(nelms,newdims);
1503 val_f64.resize(nelms);
1504 FieldSubset (val_f64.data(), newdims, total_val_f64.data(),
1505 offset32.data(), count32.data(), step32.data());
1506 set_value ((dods_float64 *) val_f64.data(), nelms);
1512 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1519void HDFEOS2ArraySwathDimMapField::close_fileid(
const int32 swfileid,
const int32 sdfileid) {
1522 if (
true == isgeofile ||
false == HDF4RequestHandler::get_pass_fileid()) {
1534bool HDFEOS2ArraySwathDimMapField::check_num_elems_constraint(
const int num_elems,
1537 int total_dim_size = 1;
1538 for (
int i =0;i<rank;i++)
1539 total_dim_size*=newdims[i];
1541 if (total_dim_size < num_elems) {
1543 eherr <<
"The total number of elements for the array " << total_dim_size
1544 <<
"is less than the user-requested number of elements " << num_elems;
1545 throw InternalErr (__FILE__, __LINE__, eherr.str ());
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)