17 #include "InternalErr.h"
33 #define SIGNED_BYTE_TO_INT32 1
38 int inv_init(
int insys,
int inzone,
double *inparm,
int indatum,
char *fn27,
char *fn83,
int *iflg,
int (*inv_trans[])(
double,
double,
double*,
double*));
39 int sominv(
double y,
double x,
double *lon,
double *lat);
43 HDFEOS2ArrayGridGeoField::read ()
46 BESDEBUG(
"h4",
"Coming to HDFEOS2ArrayGridGeoField read "<<endl);
48 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
49 bool check_pass_fileid_key =
false;
55 if (rank < 1 || rank > 2) {
56 throw InternalErr (__FILE__, __LINE__,
"The rank of geo field is greater than 2, currently we don't support 3-D lat/lon cases.");
62 if (
true == condenseddim)
64 else if(4 == specialformat)
70 offset.resize(final_rank);
72 count.resize(final_rank);
74 step.resize(final_rank);
79 nelms = format_constraint (&offset[0], &step[0], &count[0]);
84 int32 (*openfunc) (
char *, intn);
85 int32 (*attachfunc) (int32,
char *);
86 intn (*detachfunc) (int32);
87 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
88 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
92 attachfunc = GDattach;
93 detachfunc = GDdetach;
94 fieldinfofunc = GDfieldinfo;
95 readfieldfunc = GDreadfield;
96 datasetname = gridname;
113 string cache_fpath=
"";
114 bool use_cache =
false;
117 if(
true == check_pass_fileid_key)
120 gfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
123 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
124 throw InternalErr (__FILE__, __LINE__, eherr.str ());
129 gridid = attachfunc (gfid, const_cast < char *>(datasetname.c_str ()));
133 eherr <<
"Grid " << datasetname.c_str () <<
" cannot be attached.";
134 throw InternalErr (__FILE__, __LINE__, eherr.str ());
137 if(
false == llflag) {
142 string check_eos_geo_cache_key =
"H4.EnableEOSGeoCacheFile";
143 bool enable_eos_geo_cache_key =
false;
146 if(
true == enable_eos_geo_cache_key) {
158 if((
"" == bescachedir)||(
""==bescacheprefix)||(cachesize <=0)){
160 throw InternalErr (__FILE__, __LINE__,
"Either the cached dir is empty or the prefix is NULL or the cache size is not set.");
164 if(stat(bescachedir.c_str(),&sb) !=0) {
166 string err_mesg=
"The cached directory " + bescachedir;
167 err_mesg = err_mesg +
" doesn't exist. ";
168 throw InternalErr(__FILE__,__LINE__,err_mesg);
172 if(
true == S_ISDIR(sb.st_mode)) {
173 if(access(bescachedir.c_str(),R_OK|W_OK|X_OK) == -1) {
176 string err_mesg=
"The cached directory " + bescachedir;
177 err_mesg = err_mesg +
" can NOT be read,written or executable.";
178 throw InternalErr(__FILE__,__LINE__,err_mesg);
184 string err_mesg=
"The cached directory " + bescachedir;
185 err_mesg = err_mesg +
" is not a directory.";
186 throw InternalErr(__FILE__,__LINE__,err_mesg);
195 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
199 throw InternalErr (__FILE__, __LINE__,
"GDprojinfo failed");
203 if (GDgridinfo(gridid, &xdim, &ydim, upleft,
207 throw InternalErr (__FILE__, __LINE__,
"GDgridinfo failed");
212 r = GDpixreginfo (gridid, &pixreg);
217 eherr <<
"cannot obtain grid pixel registration info.";
218 throw InternalErr (__FILE__, __LINE__, eherr.str ());
223 r = GDorigininfo (gridid, &origin);
228 eherr <<
"cannot obtain grid origin info.";
229 throw InternalErr (__FILE__, __LINE__, eherr.str ());
261 for(
int ipar = 0; ipar<13;ipar++) {
266 cache_fpath = bescachedir +
"/"+ cache_fname;
268 cerr<<
"cache file path is "<<cache_fpath <<endl;
269 cerr<<
"obtain file path from BESMCache "<<endl;
270 cerr<<
"Name is "<<llcache->get_cache_file_name_h4(cache_fpath,
false) <<endl;
273 cerr<<
"after testing get_read_lock"<<endl;
278 int expected_file_size = 0;
279 if(GCTP_CEA == projcode || GCTP_GEO == projcode)
280 expected_file_size = (xdim+ydim)*
sizeof(
double);
281 else if(GCTP_SOM == projcode)
282 expected_file_size = xdim*ydim*
NBLOCK*2*
sizeof(double);
284 expected_file_size = xdim*ydim*2*
sizeof(double);
289 if(
true == latlon_from_cache)
290 cerr<<
"the cached file exists: "<<endl;
292 cerr<<
"the cached file doesn't exist "<< endl;
294 if(
false == latlon_from_cache)
300 size_t offset_1d = 0;
307 if(GCTP_CEA == projcode|| GCTP_GEO== projcode) {
311 offset_1d = (fieldtype == 1) ?offset[0] :(ydim+offset[0]);
313 if(
true == ydimmajor) {
314 offset_1d = (fieldtype == 1) ?offset[0] :(ydim*
sizeof(
double)+offset[0]);
317 offset_1d = (fieldtype == 1) ?offset[0] :(xdim*
sizeof(
double)+offset[0]);
320 count_1d = 1+(count[0]-1)*step[0];
322 else if (GCTP_SOM == projcode) {
324 if(
true == ydimmajor) {
325 offset_1d = (fieldtype == 1)?(offset[0]*xdim*ydim+offset[1]*xdim+offset[2])
326 :(offset[0]*xdim*ydim+offset[1]*xdim+offset[2]+expected_file_size/2/
sizeof(double));
329 offset_1d = (fieldtype == 1)?(offset[0]*xdim*ydim+offset[1]*ydim+offset[2])
330 :(offset[0]*xdim*ydim+offset[1]*ydim+offset[2]+expected_file_size/2/
sizeof(double));
333 int total_count_dim0 = (count[0]-1)*step[0];
334 int total_count_dim1 = (count[1]-1)*step[1];
335 int total_count_dim2 = (count[2]-1)*step[2];
336 int total_dim1 = (
true ==ydimmajor)?ydim:xdim;
337 int total_dim2 = (
true ==ydimmajor)?xdim:ydim;
342 count_1d = 1 + total_count_dim0*total_dim1*total_dim2 + total_count_dim1*total_dim2 + total_count_dim2;
346 if (
true == ydimmajor)
347 offset_1d = (fieldtype == 1) ?(offset[0] * xdim + offset[1]):(expected_file_size/2/
sizeof(double)+offset[0]*xdim+offset[1]);
349 offset_1d = (fieldtype == 1) ?(offset[0] * ydim + offset[1]):(expected_file_size/2/
sizeof(double)+offset[0]*ydim+offset[1]);
352 int total_count_dim0 = (count[0]-1)*step[0];
353 int total_count_dim1 = (count[1]-1)*step[1];
354 int total_dim1 = (
true ==ydimmajor)?xdim:ydim;
356 count_1d = 1 + total_count_dim0*total_dim1 + total_count_dim1;
360 vector<double> latlon_1d;
361 latlon_1d.resize(count_1d);
367 off_t fpos = lseek(fd,
sizeof(
double)*offset_1d,SEEK_SET);
375 if((-1 == read_size) || ((
size_t)read_size != count_1d*
sizeof(
double))) {
384 pFile = fopen(cache_fpath.c_str(),
"rb");
388 int ret_value = fseek(pFile,
sizeof(
double)*offset_1d,SEEK_SET);
394 cerr<<
"field name is "<<fieldname <<endl;
395 cerr<<
"fread is checked "<<endl;
396 cerr<<
"offset_1d is "<<offset_1d <<endl;
397 cerr<<
"count_1d is "<<count_1d <<endl;
400 ret_value = fread(&latlon_1d[0],
sizeof(
double),count_1d,pFile);
403 cerr<<
"fread fails "<<endl;
409 for(
int i =0;i<count_1d;i++)
410 cerr<<
"latlon_1d["<<i<<
"]"<<latlon_1d[i]<<endl;
414 for (
int i_rank = 0; i_rank<final_rank;i_rank++)
415 total_count = total_count*count[i_rank];
421 if(total_count == count_1d) {
422 set_value((dods_float64*)&latlon_1d[0],nelms);
428 vector<double>latlon;
429 latlon.resize(total_count);
432 if(GCTP_CEA == projcode|| GCTP_GEO== projcode) {
433 for (
int i = 0; i <total_count;i++)
434 latlon[i] = latlon_1d[i*step[0]];
437 else if (GCTP_SOM == projcode) {
439 for (
int i =0; i<count[0];i++)
440 for(
int j =0;j<count[1];j++)
441 for(
int k=0;k<count[2];k++)
442 latlon[i*count[1]*count[2]+j*count[2]+k]=(
true == ydimmajor)
443 ?latlon_1d[i*ydim*xdim*step[0]+j*xdim*step[1]+k*step[2]]
444 :latlon_1d[i*ydim*xdim*step[0]+j*ydim*step[1]+k*step[2]];
447 for (
int i =0; i<count[0];i++)
448 for(
int j =0;j<count[1];j++)
449 latlon[i*count[1]+j]=(
true == ydimmajor)
450 ?latlon_1d[i*xdim*step[0]+j*step[1]]
451 :latlon_1d[i*ydim*step[0]+j*step[1]];
455 set_value((dods_float64*)&latlon[0],nelms);
477 if(specialformat == 4) {
479 CalculateSOMLatLon(gridid, &offset[0], &count[0], &step[0], nelms,cache_fpath,use_cache);
492 vector<int32>offset32;
493 offset32.resize(rank);
495 vector<int32>count32;
496 count32.resize(rank);
505 getCorrectSubset (&offset[0], &count[0], &step[0], &offset32[0], &count32[0], &step32[0], condenseddim, ydimmajor, fieldtype, rank);
514 if (llflag ==
false) {
516 vector<float64>latlon;
517 latlon.resize(nelms);
521 if(projcode == -1 && specialformat !=3) {
525 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
529 throw InternalErr (__FILE__, __LINE__,
"GDprojinfo failed");
533 if (GDgridinfo(gridid, &xdim, &ydim, upleft,
537 throw InternalErr (__FILE__, __LINE__,
"GDgridinfo failed");
543 if (GCTP_LAMAZ == projcode) {
545 vector<double>latlon_all;
546 latlon_all.resize(xdim*ydim*2);
548 CalculateLAMAZLatLon(gridid, fieldtype, &latlon[0], &latlon_all[0],&offset[0], &count[0], &step[0], nelms,use_cache);
549 if(
true == use_cache) {
561 set_value ((dods_float64 *) &latlon[0], nelms);
568 if (specialformat == 1) {
571 vector<double>latlon_all;
572 latlon_all.resize(xdim+ydim);
574 CalculateLargeGeoLatLon(gridid, fieldtype,&latlon[0], &latlon_all[0],&offset[0], &count[0], &step[0], nelms,use_cache);
575 if(
true == use_cache) {
582 if(HDFCFUtil::write_vector_to_file2(cache_fpath,latlon_all,
sizeof(
double)) != ((xdim+ydim)*
sizeof(
double))) {
583 if(
remove(cache_fpath.c_str()) !=0) {
584 throw InternalErr(__FILE__,__LINE__,
"Cannot remove the cached file.");
596 set_value((dods_float64 *)&latlon[0],nelms);
604 else if (specialformat == 3) {
606 CalculateSpeLatLon (gridid, fieldtype, &latlon[0], &offset32[0], &count32[0], &step32[0], nelms);
620 vector<double>latlon_all;
622 if(GCTP_GEO == projcode || GCTP_CEA == projcode)
623 latlon_all.resize(xdim+ydim);
625 latlon_all.resize(xdim*ydim*2);
627 CalculateLatLon (gridid, fieldtype, specialformat, &latlon[0],&latlon_all[0],
628 &offset32[0], &count32[0], &step32[0], nelms,use_cache);
629 if(
true == use_cache) {
632 size_t num_item_expected = 0;
633 if(GCTP_GEO == projcode || GCTP_CEA == projcode)
634 num_item_expected = xdim + ydim;
636 num_item_expected = xdim*ydim*2;
639 llcache->
write_cached_data(cache_fpath,num_item_expected*
sizeof(
double),latlon_all);
647 if (speciallon && fieldtype == 2) {
648 CorSpeLon (&latlon[0], nelms);
651 set_value ((dods_float64 *) &latlon[0], nelms);
659 int32 tmp_dims[rank];
660 char tmp_dimlist[1024];
665 r = fieldinfofunc (gridid, const_cast < char *>(fieldname.c_str ()),
666 &tmp_rank, tmp_dims, &type, tmp_dimlist);
672 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
673 throw InternalErr (__FILE__, __LINE__, eherr.str ());
683 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
688 eherr <<
"Grid " << datasetname.c_str () <<
" information cannot be obtained.";
689 throw InternalErr (__FILE__, __LINE__, eherr.str ());
698 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
703 eherr <<
"Grid " << datasetname.c_str () <<
" projection info. cannot be obtained.";
704 throw InternalErr (__FILE__, __LINE__, eherr.str ());
707 if (projcode != GCTP_GEO) {
714 r = readfieldfunc (gridid,
715 const_cast < char *>(fieldname.c_str ()),
716 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
721 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
722 throw InternalErr (__FILE__, __LINE__, eherr.str ());
727 #ifndef SIGNED_BYTE_TO_INT32
728 set_value ((dods_byte *) &val[0], nelms);
731 newval.resize(nelms);
733 for (
int counter = 0; counter < nelms; counter++)
734 newval[counter] = (int32) (val[counter]);
736 set_value ((dods_int32 *) &newval[0], nelms);
747 r = readfieldfunc (gridid,
748 const_cast < char *>(fieldname.c_str ()),
749 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
754 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
755 throw InternalErr (__FILE__, __LINE__, eherr.str ());
757 set_value ((dods_byte *) &val[0], nelms);
768 r = readfieldfunc (gridid,
769 const_cast < char *>(fieldname.c_str ()),
770 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
775 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
776 throw InternalErr (__FILE__, __LINE__, eherr.str ());
779 set_value ((dods_int16 *) &val[0], nelms);
789 r = readfieldfunc (gridid,
790 const_cast < char *>(fieldname.c_str ()),
791 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
796 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
797 throw InternalErr (__FILE__, __LINE__, eherr.str ());
800 set_value ((dods_uint16 *) &val[0], nelms);
809 r = readfieldfunc (gridid,
810 const_cast < char *>(fieldname.c_str ()),
811 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
816 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
817 throw InternalErr (__FILE__, __LINE__, eherr.str ());
820 set_value ((dods_int32 *) &val[0], nelms);
829 r = readfieldfunc (gridid,
830 const_cast < char *>(fieldname.c_str ()),
831 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
836 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
837 throw InternalErr (__FILE__, __LINE__, eherr.str ());
839 set_value ((dods_uint32 *) &val[0], nelms);
848 r = readfieldfunc (gridid,
849 const_cast < char *>(fieldname.c_str ()),
850 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
855 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
856 throw InternalErr (__FILE__, __LINE__, eherr.str ());
859 set_value ((dods_float32 *) &val[0], nelms);
868 r = readfieldfunc (gridid,
869 const_cast < char *>(fieldname.c_str ()),
870 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
875 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
876 throw InternalErr (__FILE__, __LINE__, eherr.str ());
879 set_value ((dods_float64 *) &val[0], nelms);
886 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
905 r = GDgetfillvalue (gridid,
906 const_cast < char *>(fieldname.c_str ()),
909 int ifillvalue = fillvalue;
911 vector <int8> temp_total_val;
913 temp_total_val.resize(xdim*ydim);
916 r = readfieldfunc(gridid,
917 const_cast < char *>(fieldname.c_str ()),
924 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
925 throw InternalErr (__FILE__, __LINE__, eherr.str ());
930 HandleFillLatLon(temp_total_val, (int8*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
942 r = readfieldfunc (gridid,
943 const_cast < char *>(fieldname.c_str ()),
944 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
949 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
950 throw InternalErr (__FILE__, __LINE__, eherr.str ());
954 if (speciallon && fieldtype == 2)
955 CorSpeLon ((int8 *) &val[0], nelms);
958 #ifndef SIGNED_BYTE_TO_INT32
959 set_value ((dods_byte *) &val[0], nelms);
962 newval.resize(nelms);
964 for (
int counter = 0; counter < nelms; counter++)
965 newval[counter] = (int32) (val[counter]);
967 set_value ((dods_int32 *) &newval[0], nelms);
982 r = GDgetfillvalue (gridid,
983 const_cast < char *>(fieldname.c_str ()),
988 int ifillvalue = fillvalue;
989 vector <uint8> temp_total_val;
990 temp_total_val.resize(xdim*ydim);
992 r = readfieldfunc(gridid,
993 const_cast < char *>(fieldname.c_str ()),
1000 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1001 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1005 HandleFillLatLon(temp_total_val, (uint8*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1017 r = readfieldfunc (gridid,
1018 const_cast < char *>(fieldname.c_str ()),
1019 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1023 ostringstream eherr;
1024 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1025 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1029 if (speciallon && fieldtype == 2)
1030 CorSpeLon ((uint8 *) &val[0], nelms);
1031 set_value ((dods_byte *) &val[0], nelms);
1041 int16 fillvalue = 0;
1043 r = GDgetfillvalue (gridid,
1044 const_cast < char *>(fieldname.c_str ()),
1048 int ifillvalue = fillvalue;
1049 vector <int16> temp_total_val;
1050 temp_total_val.resize(xdim*ydim);
1052 r = readfieldfunc(gridid,
1053 const_cast < char *>(fieldname.c_str ()),
1059 ostringstream eherr;
1060 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1061 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1065 HandleFillLatLon(temp_total_val, (int16*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1077 r = readfieldfunc (gridid,
1078 const_cast < char *>(fieldname.c_str ()),
1079 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1083 ostringstream eherr;
1084 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1085 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1090 if (speciallon && fieldtype == 2)
1091 CorSpeLon ((int16 *) &val[0], nelms);
1093 set_value ((dods_int16 *) &val[0], nelms);
1098 uint16 fillvalue = 0;
1102 r = GDgetfillvalue (gridid,
1103 const_cast < char *>(fieldname.c_str ()),
1108 int ifillvalue = fillvalue;
1110 vector <uint16> temp_total_val;
1111 temp_total_val.resize(xdim*ydim);
1113 r = readfieldfunc(gridid,
1114 const_cast < char *>(fieldname.c_str ()),
1120 ostringstream eherr;
1121 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1122 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1126 HandleFillLatLon(temp_total_val, (uint16*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1137 r = readfieldfunc (gridid,
1138 const_cast < char *>(fieldname.c_str ()),
1139 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1143 ostringstream eherr;
1144 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1145 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1149 if (speciallon && fieldtype == 2)
1150 CorSpeLon ((uint16 *) &val[0], nelms);
1152 set_value ((dods_uint16 *) &val[0], nelms);
1162 int32 fillvalue = 0;
1164 r = GDgetfillvalue (gridid,
1165 const_cast < char *>(fieldname.c_str ()),
1169 int ifillvalue = fillvalue;
1171 vector <int32> temp_total_val;
1172 temp_total_val.resize(xdim*ydim);
1174 r = readfieldfunc(gridid,
1175 const_cast < char *>(fieldname.c_str ()),
1179 ostringstream eherr;
1182 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1183 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1187 HandleFillLatLon(temp_total_val, (int32*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1199 r = readfieldfunc (gridid,
1200 const_cast < char *>(fieldname.c_str ()),
1201 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1205 ostringstream eherr;
1206 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1207 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1211 if (speciallon && fieldtype == 2)
1212 CorSpeLon ((int32 *) &val[0], nelms);
1214 set_value ((dods_int32 *) &val[0], nelms);
1224 uint32 fillvalue = 0;
1226 r = GDgetfillvalue (gridid,
1227 const_cast < char *>(fieldname.c_str ()),
1232 int ifillvalue = (int)fillvalue;
1233 vector <uint32> temp_total_val;
1234 temp_total_val.resize(xdim*ydim);
1235 r = readfieldfunc(gridid,
1236 const_cast < char *>(fieldname.c_str ()),
1242 ostringstream eherr;
1243 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1244 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1248 HandleFillLatLon(temp_total_val, (uint32*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1260 r = readfieldfunc (gridid,
1261 const_cast < char *>(fieldname.c_str ()),
1262 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1266 ostringstream eherr;
1267 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1268 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1272 if (speciallon && fieldtype == 2)
1273 CorSpeLon ((uint32 *) &val[0], nelms);
1275 set_value ((dods_uint32 *) &val[0], nelms);
1282 vector<float32> val;
1285 float32 fillvalue =0;
1286 r = GDgetfillvalue (gridid,
1287 const_cast < char *>(fieldname.c_str ()),
1294 int ifillvalue =(int)fillvalue;
1296 vector <float32> temp_total_val;
1297 temp_total_val.resize(xdim*ydim);
1300 r = readfieldfunc(gridid,
1301 const_cast < char *>(fieldname.c_str ()),
1307 ostringstream eherr;
1308 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1309 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1313 HandleFillLatLon(temp_total_val, (float32*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1324 r = readfieldfunc (gridid,
1325 const_cast < char *>(fieldname.c_str ()),
1326 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1330 ostringstream eherr;
1331 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1332 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1336 if (speciallon && fieldtype == 2)
1337 CorSpeLon ((float32 *) &val[0], nelms);
1339 set_value ((dods_float32 *) &val[0], nelms);
1346 vector<float64> val;
1349 float64 fillvalue = 0;
1350 r = GDgetfillvalue (gridid,
1351 const_cast < char *>(fieldname.c_str ()),
1358 int ifillvalue = (int)fillvalue;
1359 vector <float64> temp_total_val;
1360 temp_total_val.resize(xdim*ydim);
1361 r = readfieldfunc(gridid,
1362 const_cast < char *>(fieldname.c_str ()),
1368 ostringstream eherr;
1369 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1370 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1374 HandleFillLatLon(temp_total_val, (float64*)&val[0],ydimmajor,fieldtype,xdim,ydim,&offset32[0],&count32[0],&step32[0],ifillvalue);
1386 r = readfieldfunc (gridid,
1387 const_cast < char *>(fieldname.c_str ()),
1388 &offset32[0], &step32[0], &count32[0], (
void*)(&val[0]));
1392 ostringstream eherr;
1393 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1394 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1398 if (speciallon && fieldtype == 2)
1399 CorSpeLon ((float64 *) &val[0], nelms);
1401 set_value ((dods_float64 *) &val[0], nelms);
1408 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1413 r = detachfunc (gridid);
1415 ostringstream eherr;
1416 eherr <<
"Grid " << datasetname.c_str () <<
" cannot be detached.";
1417 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1423 r = closefunc (gfid);
1425 ostringstream eherr;
1427 eherr <<
"Grid " << filename.c_str () <<
" cannot be closed.";
1428 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1439 HDFEOS2ArrayGridGeoField::format_constraint (
int *offset,
int *step,
1445 Dim_iter p = dim_begin ();
1447 while (p != dim_end ()) {
1449 int start = dimension_start (p,
true);
1450 int stride = dimension_stride (p,
true);
1451 int stop = dimension_stop (p,
true);
1455 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
1458 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
1459 ":" << stride <<
":" << stop <<
"]";
1460 throw Error (malformed_expr, oss.str ());
1464 if (start == 0 && stop == 0 && stride == 0) {
1465 start = dimension_start (p,
false);
1466 stride = dimension_stride (p,
false);
1467 stop = dimension_stop (p,
false);
1472 count[id] = ((stop - start) / stride) + 1;
1476 "=format_constraint():"
1477 <<
"id=" <<
id <<
" offset=" << offset[
id]
1478 <<
" step=" << step[
id]
1479 <<
" count=" << count[
id]
1491 HDFEOS2ArrayGridGeoField::CalculateLatLon (int32 gridid,
int fieldtype,
1493 float64 * outlatlon,float64* latlon_all,
1494 int32 * offset, int32 * count,
1495 int32 * step,
int nelms,
bool write_latlon_cache)
1503 float64 lowright[2];
1505 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
1507 ostringstream eherr;
1508 eherr <<
"cannot obtain grid information.";
1509 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1515 if (specialformat == 1) {
1516 upleft[0] = upleft[0] * 1000000;
1517 upleft[1] = upleft[1] * 1000000;
1518 lowright[0] = lowright[0] * 1000000;
1519 lowright[1] = lowright[1] * 1000000;
1526 if (specialformat == 2) {
1528 upleft[1] = 90000000.0;
1529 lowright[0] = 360000000.0;
1530 lowright[1] = -90000000.0;
1539 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
1541 ostringstream eherr;
1542 eherr <<
"cannot obtain grid projection information";
1543 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1549 r = GDpixreginfo (gridid, &pixreg);
1551 ostringstream eherr;
1552 eherr <<
"cannot obtain grid pixel registration info.";
1553 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1560 r = GDorigininfo (gridid, &origin);
1562 ostringstream eherr;
1563 eherr <<
"cannot obtain grid origin info.";
1564 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1571 rows.resize(xdim*ydim);
1572 cols.resize(xdim*ydim);
1573 lon.resize(xdim*ydim);
1574 lat.resize(xdim*ydim);
1577 int i = 0, j = 0, k = 0;
1588 for (k = j = 0; j < ydim; ++j) {
1589 for (i = 0; i < xdim; ++i) {
1604 for (k = j = 0; j < xdim; ++j) {
1605 for (i = 0; i < ydim; ++i) {
1614 r = GDij2ll (projcode, zone, params, sphere, xdim, ydim, upleft, lowright,
1615 xdim * ydim, &rows[0], &cols[0], &lon[0], &lat[0], pixreg, origin);
1618 ostringstream eherr;
1619 eherr <<
"cannot calculate grid latitude and longitude";
1620 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1625 if(
true == write_latlon_cache) {
1626 if(GCTP_CEA == projcode || GCTP_GEO == projcode) {
1628 vector<double>temp_lat;
1629 vector<double>temp_lon;
1630 int32 temp_offset[2];
1631 int32 temp_count[2];
1639 temp_count[0] = ydim;
1641 temp_lat.resize(ydim);
1642 LatLon2DSubset(&temp_lat[0],ydim,xdim,&lat[0],temp_offset,temp_count,temp_step);
1646 temp_count[1] = xdim;
1647 temp_lon.resize(xdim);
1648 LatLon2DSubset(&temp_lon[0],ydim,xdim,&lon[0],temp_offset,temp_count,temp_step);
1650 for(
int i = 0; i<ydim;i++)
1651 latlon_all[i] = temp_lat[i];
1653 for(
int i = 0; i<xdim;i++)
1654 latlon_all[i+ydim] = temp_lon[i];
1659 temp_count[1] = ydim;
1661 temp_lat.resize(ydim);
1662 LatLon2DSubset(&temp_lat[0],xdim,ydim,&lat[0],temp_offset,temp_count,temp_step);
1666 temp_count[0] = xdim;
1667 temp_lon.resize(xdim);
1668 LatLon2DSubset(&temp_lon[0],xdim,ydim,&lon[0],temp_offset,temp_count,temp_step);
1670 for(
int i = 0; i<ydim;i++)
1671 latlon_all[i] = temp_lat[i];
1673 for(
int i = 0; i<xdim;i++)
1674 latlon_all[i+ydim] = temp_lon[i];
1680 memcpy((
char*)(&latlon_all[0]),&lat[0],xdim*ydim*
sizeof(
double));
1681 memcpy((
char*)(&latlon_all[0])+xdim*ydim*
sizeof(
double),&lon[0],xdim*ydim*
sizeof(
double));
1688 if (nelms == (xdim * ydim)) {
1690 memcpy (outlatlon, &lat[0], xdim * ydim *
sizeof (
double));
1692 memcpy (outlatlon, &lon[0], xdim * ydim *
sizeof (
double));
1697 LatLon2DSubset (outlatlon, ydim, xdim, &lat[0], offset, count,
1700 LatLon2DSubset (outlatlon, ydim, xdim, &lon[0], offset, count,
1705 LatLon2DSubset (outlatlon, xdim, ydim, &lat[0], offset, count,
1708 LatLon2DSubset (outlatlon, xdim, ydim, &lon[0], offset, count,
1716 template<
class T>
void
1717 HDFEOS2ArrayGridGeoField::LatLon2DSubset (T * outlatlon,
int majordim,
1718 int minordim, T * latlon,
1719 int32 * offset, int32 * count,
1723 T (*templatlonptr)[majordim][minordim] =
1724 (typeof templatlonptr) latlon;
1729 int dim0count = count[0];
1730 int dim1count = count[1];
1731 int dim0index[dim0count], dim1index[dim1count];
1733 for (i = 0; i < count[0]; i++)
1734 dim0index[i] = offset[0] + i * step[0];
1737 for (j = 0; j < count[1]; j++)
1738 dim1index[j] = offset[1] + j * step[1];
1743 for (i = 0; i < count[0]; i++) {
1744 for (j = 0; j < count[1]; j++) {
1745 outlatlon[k] = (*templatlonptr)[dim0index[i]][dim1index[j]];
1755 template <
class T >
bool HDFEOS2ArrayGridGeoField::CorLatLon (T * latlon,
1769 for (
int i = 0; i < elms; i++)
1770 if ((
int) (latlon[i]) == fv)
1777 for (
int i = 0; i < 3; i++)
1778 if ((
int) (latlon[i]) == fv)
1781 if ((
int) (latlon[elms - 1]) != fv)
1784 T increment = latlon[2] - latlon[1];
1789 index = findfirstfv (latlon, 0, elms - 1, fv);
1791 ostringstream eherr;
1792 eherr <<
"cannot calculate the fill value. ";
1793 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1796 for (
int i = index; i < elms; i++) {
1798 latlon[i] = latlon[i - 1] + increment;
1801 if (i != (elms - 1) && (fieldtype == 1) &&
1802 ((
float) (latlon[i]) < -90.0 || (
float) (latlon[i]) > 90.0))
1809 if (i != (elms - 1) && (fieldtype == 2) &&
1810 ((
float) (latlon[i]) < -180.0 || (
float) (latlon[i]) > 360.0))
1813 if (fieldtype == 1) {
1814 if ((
float) (latlon[elms - 1]) < -90.0)
1815 latlon[elms - 1] = (T)-90;
1816 if ((
float) (latlon[elms - 1]) > 90.0)
1817 latlon[elms - 1] = (T)90;
1820 if (fieldtype == 2) {
1821 if ((
float) (latlon[elms - 1]) < -180.0)
1822 latlon[elms - 1] = (T)-180.0;
1823 if ((
float) (latlon[elms - 1]) > 360.0)
1824 latlon[elms - 1] = (T)360.0;
1830 template <
class T >
void
1831 HDFEOS2ArrayGridGeoField::CorSpeLon (T * lon,
int xdim)
1834 float64 accuracy = 1e-3;
1840 for (i = 0; i < xdim; i++) {
1841 if ((
double) lon[i] < 180.0)
1842 temp = 180.0 - (double) lon[i];
1843 if ((
double) lon[i] > 180.0)
1844 temp = (double) lon[i] - 180.0;
1846 if (temp < accuracy) {
1850 else if ((static_cast < double >(lon[i]) < 180.0)
1851 &&(
static_cast<double>(lon[i + 1]) > 180.0)) {
1859 if (speindex != -1) {
1860 for (i = speindex + 1; i < xdim; i++) {
1862 static_cast < T > (static_cast <
double >(lon[i]) - 360.0);
1870 HDFEOS2ArrayGridGeoField::getCorrectSubset (
int *offset,
int *count,
1871 int *step, int32 * offset32,
1872 int32 * count32, int32 * step32,
1873 bool condenseddim,
bool ydimmajor,
1874 int fieldtype,
int rank)
1878 offset32[0] = (int32) offset[0];
1879 count32[0] = (int32) count[0];
1880 step32[0] = (int32) step[0];
1882 else if (condenseddim) {
1886 for (
int i = 0; i < rank; i++) {
1892 if (ydimmajor && fieldtype == 1) {
1893 offset32[0] = (int32) offset[0];
1894 count32[0] = (int32) count[0];
1895 step32[0] = (int32) step[0];
1897 else if (ydimmajor && fieldtype == 2) {
1898 offset32[1] = (int32) offset[0];
1899 count32[1] = (int32) count[0];
1900 step32[1] = (int32) step[0];
1902 else if (!ydimmajor && fieldtype == 1) {
1903 offset32[1] = (int32) offset[0];
1904 count32[1] = (int32) count[0];
1905 step32[1] = (int32) step[0];
1907 else if (!ydimmajor && fieldtype == 2) {
1908 offset32[0] = (int32) offset[0];
1909 count32[0] = (int32) count[0];
1910 step32[0] = (int32) step[0];
1914 InternalErr (__FILE__, __LINE__,
1915 "Lat/lon subset is wrong for condensed lat/lon");
1919 for (
int i = 0; i < rank; i++) {
1920 offset32[i] = (int32) offset[i];
1921 count32[i] = (int32) count[i];
1922 step32[i] = (int32) step[i];
1930 template <
class T>
void
1931 HDFEOS2ArrayGridGeoField::HandleFillLatLon(vector<T> total_latlon, T* latlon,
bool ydimmajor,
int fieldtype, int32 xdim , int32 ydim, int32* offset, int32* count, int32* step,
int fv) {
1933 class vector <T> temp_lat;
1934 class vector <T> temp_lon;
1936 if (
true == ydimmajor) {
1938 if (1 == fieldtype) {
1939 temp_lat.resize(ydim);
1940 for (
int i = 0; i <(int)ydim; i++)
1941 temp_lat[i] = total_latlon[i*xdim];
1943 if (
false == CorLatLon(&temp_lat[0],fieldtype,ydim,fv))
1944 InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1946 for (
int i = 0; i <(int)(count[0]); i++)
1947 latlon[i] = temp_lat[offset[0] + i* step[0]];
1951 temp_lon.resize(xdim);
1952 for (
int i = 0; i <(int)xdim; i++)
1953 temp_lon[i] = total_latlon[i];
1956 if (
false == CorLatLon(&temp_lon[0],fieldtype,xdim,fv))
1957 InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1959 for (
int i = 0; i <(int)(count[1]); i++)
1960 latlon[i] = temp_lon[offset[1] + i* step[1]];
1966 if (1 == fieldtype) {
1967 temp_lat.resize(xdim);
1968 for (
int i = 0; i <(int)xdim; i++)
1969 temp_lat[i] = total_latlon[i];
1971 if (
false == CorLatLon(&temp_lat[0],fieldtype,ydim,fv))
1972 InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1974 for (
int i = 0; i <(int)(count[1]); i++)
1975 latlon[i] = temp_lat[offset[1] + i* step[1]];
1979 temp_lon.resize(ydim);
1980 for (
int i = 0; i <(int)ydim; i++)
1981 temp_lon[i] = total_latlon[i*xdim];
1984 if (
false == CorLatLon(&temp_lon[0],fieldtype,xdim,fv))
1985 InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1987 for (
int i = 0; i <(int)(count[0]); i++)
1988 latlon[i] = temp_lon[offset[0] + i* step[0]];
1995 template <
class T >
int
1996 HDFEOS2ArrayGridGeoField::findfirstfv (T * array,
int start,
int end,
2000 if (start == end || start == (end - 1)) {
2001 if (static_cast < int >(array[start]) == fillvalue)
2007 int current = (start + end) / 2;
2009 if (static_cast < int >(array[current]) == fillvalue)
2010 return findfirstfv (array, start, current, fillvalue);
2012 return findfirstfv (array, current, end, fillvalue);
2024 HDFEOS2ArrayGridGeoField::CalculateSpeLatLon (int32 gridid,
int fieldtype,
2025 float64 * outlatlon,
2027 int32 * count32, int32 * step32,
2036 float64 lowright[2];
2038 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
2040 ostringstream eherr;
2041 eherr <<
"cannot obtain grid information.";
2042 throw InternalErr (__FILE__, __LINE__, eherr.str ());
2052 if(0 == xdim || 0 == ydim)
2053 throw InternalErr(__FILE__,__LINE__,
"xdim or ydim cannot be zero");
2055 if (fieldtype == 1) {
2056 double latstep = 180.0 / ydim;
2058 for (
int i = 0; i < (int) (count32[0]); i++)
2059 outlatlon[i] = 90.0 -latstep/2 - latstep * (offset32[0] + i * step32[0]);
2062 double lonstep = 360.0 / xdim;
2064 for (
int i = 0; i < (int) (count32[1]); i++)
2065 outlatlon[i] = -180.0 + lonstep/2 + lonstep * (offset32[1] + i * step32[1]);
2075 HDFEOS2ArrayGridGeoField::CalculateSOMLatLon(int32 gridid,
int *start,
int *count,
int *step,
int nelms,
const string & cache_fpath,
bool write_latlon_cache)
2077 int32 projcode = -1;
2080 float64 params[
NPROJ];
2083 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
2085 throw InternalErr (__FILE__, __LINE__,
"GDprojinfo doesn't return the correct values");
2090 r = GDinqdims(gridid, dimlist, dim);
2094 throw InternalErr (__FILE__, __LINE__,
"GDinqdims doesn't return the correct values");
2096 bool is_block_180 =
false;
2097 for(
int i=0; i<MAXNDIM; i++)
2101 is_block_180 =
true;
2105 if(
false == is_block_180) {
2106 ostringstream eherr;
2107 eherr <<
"Number of Block is not " <<
NBLOCK ;
2108 throw InternalErr(__FILE__,__LINE__,eherr.str());
2116 r = GDgridinfo (gridid, &xdim, &ydim, ulc, lrc);
2118 throw InternalErr(__FILE__,__LINE__,
"GDgridinfo doesn't return the correct values");
2122 char som_rw_code[]=
"r";
2123 r = GDblkSOMoffset(gridid, offset,
NOFFSET, som_rw_code);
2125 throw InternalErr(__FILE__,__LINE__,
"GDblkSOMoffset doesn't return the correct values");
2127 int status =
misr_init(NBLOCK, xdim, ydim, offset, ulc, lrc);
2129 throw InternalErr(__FILE__,__LINE__,
"misr_init doesn't return the correct values");
2132 int (*inv_trans[MAXPROJ+1])(double, double,
double*,
double*);
2133 inv_init((
long)projcode, (
long)zone, (
double*)params, (
long)sphere,
NULL,
NULL, (
int*)&iflg, inv_trans);
2135 throw InternalErr(__FILE__,__LINE__,
"inv_init doesn't return correct values");
2156 if(
true == write_latlon_cache) {
2157 vector<double>latlon_all;
2158 latlon_all.resize(xdim*ydim*NBLOCK*2);
2159 for(
int i =1; i <NBLOCK+1;i++)
2160 for(
int j=0;j<xdim;j++)
2161 for(
int k=0;k<ydim;k++)
2166 misrinv(b, l, s, &somx, &somy);
2167 sominv(somx, somy, &lon_r, &lat_r);
2168 latlon_all[npts] = lat_r*
R2D;
2169 latlon_all[xdim*ydim*NBLOCK+npts] = lon_r*
R2D;
2177 if(HDFCFUtil::write_vector_to_file2(cache_fpath,latlon_all,
sizeof(
double)) != (xdim*ydim*NBLOCK*2)*
sizeof(
double)) {
2178 if(
remove(cache_fpath.c_str()) !=0) {
2179 throw InternalErr(__FILE__,__LINE__,
"Cannot remove the cached file.");
2184 llcache->
write_cached_data(cache_fpath,xdim*ydim*NBLOCK*2*
sizeof(
double),latlon_all);
2187 vector<double>latlon;
2188 latlon.resize(nelms);
2198 for(
int i=0; i<count[0]; i++)
2199 for(
int j=0; j<count[1]; j++)
2200 for(
int k=0; k<count[2]; k++)
2202 if(fieldtype == 1) {
2203 latlon[npts] = latlon_all[start[0]*ydim*xdim+start[1]*ydim+start[2]+
2204 i*ydim*xdim*step[0]+j*ydim*step[1]+k*step[2]];
2207 latlon[npts] = latlon_all[xdim*ydim*NBLOCK+start[0]*ydim*xdim+start[1]*ydim+start[2]+
2208 i*ydim*xdim*step[0]+j*ydim*step[1]+k*step[2]];
2214 set_value ((dods_float64 *) &latlon[0], nelms);
2217 vector<double>latlon;
2218 latlon.resize(nelms);
2219 int s1=start[0]+1, e1=s1+count[0]*step[0];
2220 int s2=start[1], e2=s2+count[1]*step[1];
2221 int s3=start[2], e3=s3+count[2]*step[2];
2222 for(i=s1; i<e1; i+=step[0])
2223 for(j=s2; j<e2; j+=step[1])
2224 for(k=s3; k<e3; k+=step[2])
2229 misrinv(b, l, s, &somx, &somy);
2230 sominv(somx, somy, &lon_r, &lat_r);
2232 latlon[npts] = lat_r*
R2D;
2234 latlon[npts] = lon_r*
R2D;
2237 set_value ((dods_float64 *) &latlon[0], nelms);
2250 HDFEOS2ArrayGridGeoField::CalculateLargeGeoLatLon(int32 gridid,
int fieldtype, float64* latlon, float64* latlon_all,
int *start,
int *count,
int *step,
int nelms,
bool write_latlon_cache)
2256 float64 lowright[2];
2258 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
2260 throw InternalErr(__FILE__,__LINE__,
"GDgridinfo failed");
2263 if (0 == xdim || 0 == ydim) {
2264 throw InternalErr(__FILE__,__LINE__,
"xdim or ydim should not be zero. ");
2267 if (upleft[0]>180.0 || upleft[0] <-180.0 ||
2268 upleft[1]>90.0 || upleft[1] <-90.0 ||
2269 lowright[0] >180.0 || lowright[0] <-180.0 ||
2270 lowright[1] >90.0 || lowright[1] <-90.0) {
2272 throw InternalErr(__FILE__,__LINE__,
"lat/lon corner points are out of range. ");
2275 if (count[0] != nelms) {
2276 throw InternalErr(__FILE__,__LINE__,
"rank is not 1 ");
2278 float lat_step = (lowright[1] - upleft[1])/ydim;
2279 float lon_step = (lowright[0] - upleft[0])/xdim;
2281 if(
true == write_latlon_cache) {
2283 for(
int i = 0;i<ydim;i++)
2284 latlon_all[i] = upleft[1] + i*lat_step + lat_step/2;
2286 for(
int i = 0;i<xdim;i++)
2287 latlon_all[i+ydim] = upleft[0] + i*lon_step + lon_step/2;
2293 if (1 == fieldtype) {
2294 float start_lat = upleft[1] + start[0] *lat_step + lat_step/2;
2295 float step_lat = lat_step *step[0];
2296 for (
int i = 0; i < count[0]; i++)
2297 latlon[i] = start_lat +i *step_lat;
2300 float start_lon = upleft[0] + start[0] *lon_step + lon_step/2;
2301 float step_lon = lon_step *step[0];
2302 for (
int i = 0; i < count[0]; i++)
2303 latlon[i] = start_lon +i *step_lon;
2312 HDFEOS2ArrayGridGeoField::CalculateLAMAZLatLon(int32 gridid,
int fieldtype, float64* latlon, float64* latlon_all,
int *start,
int *count,
int *step,
int nelms,
bool write_latlon_cache)
2318 float64 lowright[2];
2320 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
2322 throw InternalErr(__FILE__,__LINE__,
"GDgridinfo failed");
2324 vector<float64> tmp1;
2325 tmp1.resize(xdim*ydim);
2326 int32 tmp2[] = {0, 0};
2327 int32 tmp3[] = {xdim, ydim};
2328 int32 tmp4[] = {1, 1};
2330 CalculateLatLon (gridid, fieldtype, specialformat, &tmp1[0], latlon_all, tmp2, tmp3, tmp4, xdim*ydim,write_latlon_cache);
2332 if(write_latlon_cache ==
true) {
2334 vector<float64> temp_lat_all,lat_all;
2335 temp_lat_all.resize(xdim*ydim);
2336 lat_all.resize(xdim*ydim);
2338 vector<float64> temp_lon_all,lon_all;
2339 temp_lon_all.resize(xdim*ydim);
2340 lon_all.resize(xdim*ydim);
2342 for(
int w=0; w < xdim*ydim; w++){
2343 temp_lat_all[w] = latlon_all[w];
2344 lat_all[w] = latlon_all[w];
2345 temp_lon_all[w] = latlon_all[w+xdim*ydim];
2346 lon_all[w] = latlon_all[w+xdim*ydim];
2351 for(
int i=0; i<ydim; i++)
2352 for(
int j=0; j<xdim; j++)
2353 if(isundef_lat(lat_all[i*xdim+j]))
2354 lat_all[i*xdim+j]=nearestNeighborLatVal(&temp_lat_all[0], i, j, ydim, xdim);
2355 for(
int i=0; i<ydim; i++)
2356 for(
int j=0; j<xdim; j++)
2357 if(isundef_lon(lon_all[i*xdim+j]))
2358 lon_all[i*xdim+j]=nearestNeighborLonVal(&temp_lon_all[0], i, j, ydim, xdim);
2361 for(
int i=0; i<xdim; i++)
2362 for(
int j=0; j<ydim; j++)
2363 if(isundef_lat(lat_all[i*ydim+j]))
2364 lat_all[i*ydim+j]=nearestNeighborLatVal(&temp_lat_all[0], i, j, xdim, ydim);
2366 for(
int i=0; i<xdim; i++)
2367 for(
int j=0; j<ydim; j++)
2368 if(isundef_lon(lon_all[i*ydim+j]))
2369 lon_all[i*ydim+j]=nearestNeighborLonVal(&temp_lon_all[0], i, j, xdim, ydim);
2373 for(
int i = 0; i<xdim*ydim;i++) {
2374 latlon_all[i] = lat_all[i];
2375 latlon_all[i+xdim*ydim] = lon_all[i];
2381 vector<float64> tmp5;
2382 tmp5.resize(xdim*ydim);
2384 for(
int w=0; w < xdim*ydim; w++)
2390 for(
int i=0; i<ydim; i++)
2391 for(
int j=0; j<xdim; j++)
2392 if(isundef_lat(tmp1[i*xdim+j]))
2393 tmp1[i*xdim+j]=nearestNeighborLatVal(&tmp5[0], i, j, ydim, xdim);
2394 }
else if(fieldtype==2){
2395 for(
int i=0; i<ydim; i++)
2396 for(
int j=0; j<xdim; j++)
2397 if(isundef_lon(tmp1[i*xdim+j]))
2398 tmp1[i*xdim+j]=nearestNeighborLonVal(&tmp5[0], i, j, ydim, xdim);
2402 for(
int i=0; i<xdim; i++)
2403 for(
int j=0; j<ydim; j++)
2404 if(isundef_lat(tmp1[i*ydim+j]))
2405 tmp1[i*ydim+j]=nearestNeighborLatVal(&tmp5[0], i, j, xdim, ydim);
2406 }
else if(fieldtype==2) {
2407 for(
int i=0; i<xdim; i++)
2408 for(
int j=0; j<ydim; j++)
2409 if(isundef_lon(tmp1[i*ydim+j]))
2410 tmp1[i*ydim+j]=nearestNeighborLonVal(&tmp5[0], i, j, xdim, ydim);
2414 for(
int i=start[0], k=0; i<start[0]+count[0]*step[0]; i+=step[0])
2415 for(
int j=start[1]; j<start[1]+count[1]*step[1]; j+= step[1])
2416 latlon[k++] = tmp1[i*ydim+j];
bool get_data_from_cache(const string &cache_file_name, const int expected_file_size, int &fd)
static void close_fileid(int32 sdfd, int32 file_id, int32 gridfd, int32 swathfd, bool pass_fileid_key)
Close HDF4 and HDF-EOS2 file IDs. For performance reasons, we want to keep HDF-EOS2/HDF4 IDs open for...
static string getCachePrefixFromConfig()
static unsigned long getCacheSizeFromConfig()
static std::string get_int_str(int)
int misrinv(const int block, const float line, const float sample, double *x, double *y)
bool write_cached_data(const string &cache_file_name, const int expected_file_size, const std::vector< double > &val)
static std::string get_double_str(double, int, int)
virtual void purge_file(const string &file)
Purge a single file from the cache.
static BESH4Cache * get_instance()
Get the default instance of the BESH4Cache object.
virtual bool get_read_lock(const string &target, int &fd)
Get a read-only lock on the file if it exists.
int misr_init(const int nblock, const int nline, const int nsample, const float relOff[NOFFSET], const double ulc_coord[], const double lrc_coord[])
static ssize_t read_vector_from_file(int fd, vector< double > &, size_t)
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
static string getCacheDirFromConfig()
virtual void unlock_and_close(const string &target)
Unlock the named file.