8#include "HDFEOS2ArrayGridGeoField.h"
16#include <libdap/debug.h>
18#include <libdap/InternalErr.h>
23#include "errormacros.h"
29#include "BESH4MCache.h"
30#include "HDF4RequestHandler.h"
35#define SIGNED_BYTE_TO_INT32 1
39 int inv_init(
int insys,
int inzone,
double *inparm,
int indatum,
char *fn27,
char *fn83,
int *iflg,
int (*inv_trans[])(
double,
double,
double*,
double*));
40 int sominv(
double y,
double x,
double *lon,
double *lat);
44HDFEOS2ArrayGridGeoField::read ()
46 BESDEBUG(
"h4",
"Coming to HDFEOS2ArrayGridGeoField read "<<endl);
50 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
54 if (rank < 1 || rank > 2) {
55 throw InternalErr (__FILE__, __LINE__,
"The rank of geo field is greater than 2, currently we don't support 3-D lat/lon cases.");
61 if (
true == condenseddim)
63 else if (4 == specialformat)
69 offset.resize(final_rank);
71 count.resize(final_rank);
73 step.resize(final_rank);
78 nelms = format_constraint (offset.data(), step.data(), count.data());
83 int32 (*openfunc) (
char *, intn);
84 int32 (*attachfunc) (int32,
char *);
85 intn (*detachfunc) (int32);
86 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
87 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
91 attachfunc = GDattach;
92 detachfunc = GDdetach;
93 fieldinfofunc = GDfieldinfo;
94 readfieldfunc = GDreadfield;
95 datasetname = gridname;
112 string cache_fpath=
"";
113 bool use_cache =
false;
116 if (
true == check_pass_fileid_key)
119 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
122 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
123 throw InternalErr (__FILE__, __LINE__, eherr.str ());
128 gridid = attachfunc (gfid,
const_cast < char *
>(datasetname.c_str ()));
132 eherr <<
"Grid " << datasetname.c_str () <<
" cannot be attached.";
133 throw InternalErr (__FILE__, __LINE__, eherr.str ());
136 if (
false == llflag) {
142 if (
true == HDF4RequestHandler::get_enable_eosgeo_cachefile()) {
150 string bescachedir = HDF4RequestHandler::get_cache_latlon_path();
151 string bescacheprefix = HDF4RequestHandler::get_cache_latlon_prefix();
152 long cachesize = HDF4RequestHandler::get_cache_latlon_size();
154 if ((
"" == bescachedir)||(
""==bescacheprefix)||(cachesize <=0)){
156 throw InternalErr (__FILE__, __LINE__,
"Either the cached dir is empty or the prefix is nullptr or the cache size is not set.");
160 if (stat(bescachedir.c_str(),&sb) !=0) {
162 string err_mesg=
"The cached directory " + bescachedir;
163 err_mesg = err_mesg +
" doesn't exist. ";
164 throw InternalErr(__FILE__,__LINE__,err_mesg);
168 if (
true == S_ISDIR(sb.st_mode)) {
169 if (access(bescachedir.c_str(),R_OK|W_OK|X_OK) == -1) {
171 string err_mesg=
"The cached directory " + bescachedir;
172 err_mesg = err_mesg +
" can NOT be read,written or executable.";
173 throw InternalErr(__FILE__,__LINE__,err_mesg);
179 string err_mesg=
"The cached directory " + bescachedir;
180 err_mesg = err_mesg +
" is not a directory.";
181 throw InternalErr(__FILE__,__LINE__,err_mesg);
187 string cache_fname=HDF4RequestHandler::get_cache_latlon_prefix();
190 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
194 throw InternalErr (__FILE__, __LINE__,
"GDprojinfo failed");
198 if (GDgridinfo(gridid, &xdim, &ydim, upleft,
202 throw InternalErr (__FILE__, __LINE__,
"GDgridinfo failed");
207 r = GDpixreginfo (gridid, &pixreg);
212 eherr <<
"cannot obtain grid pixel registration info.";
213 throw InternalErr (__FILE__, __LINE__, eherr.str ());
218 r = GDorigininfo (gridid, &origin);
223 eherr <<
"cannot obtain grid origin info.";
224 throw InternalErr (__FILE__, __LINE__, eherr.str ());
229 cache_fname +=HDFCFUtil::get_int_str(projcode);
230 cache_fname +=HDFCFUtil::get_int_str(zone);
231 cache_fname +=HDFCFUtil::get_int_str(sphere);
232 cache_fname +=HDFCFUtil::get_int_str(pixreg);
233 cache_fname +=HDFCFUtil::get_int_str(origin);
239 cache_fname +=HDFCFUtil::get_int_str(ydim);
240 cache_fname +=HDFCFUtil::get_int_str(xdim);
244 cache_fname +=HDFCFUtil::get_int_str(xdim);
245 cache_fname +=HDFCFUtil::get_int_str(ydim);
250 cache_fname +=HDFCFUtil::get_double_str(upleft[0],17,6);
251 cache_fname +=HDFCFUtil::get_double_str(upleft[1],17,6);
252 cache_fname +=HDFCFUtil::get_double_str(lowright[0],17,6);
253 cache_fname +=HDFCFUtil::get_double_str(lowright[1],17,6);
256 for(
int ipar = 0; ipar<13;ipar++)
257 cache_fname+=HDFCFUtil::get_double_str(params[ipar],17,6);
260 cache_fpath = bescachedir +
"/"+ cache_fname;
264 int expected_file_size = 0;
265 if (GCTP_CEA == projcode || GCTP_GEO == projcode)
266 expected_file_size = (xdim+ydim)*
sizeof(
double);
267 else if (GCTP_SOM == projcode)
268 expected_file_size = xdim*ydim*NBLOCK*2*
sizeof(double);
270 expected_file_size = xdim*ydim*2*
sizeof(double);
273 bool latlon_from_cache = llcache->get_data_from_cache(cache_fpath, expected_file_size,fd);
274 if (
false == latlon_from_cache)
280 size_t offset_1d = 0;
287 if (GCTP_CEA == projcode|| GCTP_GEO== projcode) {
291 offset_1d = (fieldtype == 1) ?offset[0] :(ydim+offset[0]);
292 count_1d = 1+(count[0]-1)*step[0];
294 else if (GCTP_SOM == projcode) {
296 if (
true == ydimmajor) {
297 offset_1d = (fieldtype == 1)?(offset[0]*xdim*ydim+offset[1]*xdim+offset[2])
298 :(offset[0]*xdim*ydim+offset[1]*xdim+offset[2]+expected_file_size/2/
sizeof(double));
301 offset_1d = (fieldtype == 1)?(offset[0]*xdim*ydim+offset[1]*ydim+offset[2])
302 :(offset[0]*xdim*ydim+offset[1]*ydim+offset[2]+expected_file_size/2/
sizeof(double));
305 int total_count_dim0 = (count[0]-1)*step[0];
306 int total_count_dim1 = (count[1]-1)*step[1];
307 int total_count_dim2 = (count[2]-1)*step[2];
308 int total_dim1 = (
true ==ydimmajor)?ydim:xdim;
309 int total_dim2 = (
true ==ydimmajor)?xdim:ydim;
314 count_1d = 1 + total_count_dim0*total_dim1*total_dim2 + total_count_dim1*total_dim2 + total_count_dim2;
318 if (
true == ydimmajor)
319 offset_1d = (fieldtype == 1) ?(offset[0] * xdim + offset[1]):(expected_file_size/2/
sizeof(double)+offset[0]*xdim+offset[1]);
321 offset_1d = (fieldtype == 1) ?(offset[0] * ydim + offset[1]):(expected_file_size/2/
sizeof(double)+offset[0]*ydim+offset[1]);
324 int total_count_dim0 = (count[0]-1)*step[0];
325 int total_count_dim1 = (count[1]-1)*step[1];
326 int total_dim1 = (
true ==ydimmajor)?xdim:ydim;
328 count_1d = 1 + total_count_dim0*total_dim1 + total_count_dim1;
333 latlon_1d.resize(count_1d);
339 off_t fpos = lseek(fd,
sizeof(
double)*offset_1d,SEEK_SET);
345 ssize_t read_size = HDFCFUtil::read_vector_from_file(fd,latlon_1d,
sizeof(
double));
347 if ((-1 == read_size) || ((
size_t)read_size != count_1d*
sizeof(
double))) {
353 for (
int i_rank = 0; i_rank<final_rank;i_rank++)
354 total_count = total_count*count[i_rank];
360 if (total_count == count_1d) {
361 set_value((dods_float64*)latlon_1d.data(),nelms);
368 latlon.resize(total_count);
371 if (GCTP_CEA == projcode|| GCTP_GEO== projcode) {
372 for (
int i = 0; i <total_count;i++)
373 latlon[i] = latlon_1d[i*step[0]];
376 else if (GCTP_SOM == projcode) {
378 for (
int i =0; i<count[0];i++)
379 for(
int j =0;j<count[1];j++)
380 for(
int k=0;k<count[2];k++)
381 latlon[i*count[1]*count[2]+j*count[2]+k]=(
true == ydimmajor)
382 ?latlon_1d[i*ydim*xdim*step[0]+j*xdim*step[1]+k*step[2]]
383 :latlon_1d[i*ydim*xdim*step[0]+j*ydim*step[1]+k*step[2]];
386 for (
int i =0; i<count[0];i++)
387 for(
int j =0;j<count[1];j++)
388 latlon[i*count[1]+j]=(
true == ydimmajor)
389 ?latlon_1d[i*xdim*step[0]+j*step[1]]
390 :latlon_1d[i*ydim*step[0]+j*step[1]];
394 set_value((dods_float64*)latlon.data(),nelms);
413 if (specialformat == 4) {
415 CalculateSOMLatLon(gridid, offset.data(), count.data(), step.data(), nelms,cache_fpath,use_cache);
429 offset32.resize(rank);
432 count32.resize(rank);
441 getCorrectSubset (offset.data(), count.data(), step.data(), offset32.data(), count32.data(), step32.data(), condenseddim, ydimmajor, fieldtype, rank);
450 if (llflag ==
false) {
453 latlon.resize(nelms);
457 if (projcode == -1 && specialformat !=3) {
461 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
465 throw InternalErr (__FILE__, __LINE__,
"GDprojinfo failed");
469 if (GDgridinfo(gridid, &xdim, &ydim, upleft,
473 throw InternalErr (__FILE__, __LINE__,
"GDgridinfo failed");
479 if (GCTP_LAMAZ == projcode) {
482 latlon_all.resize(xdim*ydim*2);
484 CalculateLAMAZLatLon(gridid, fieldtype, latlon.data(), latlon_all.data(),offset.data(), count.data(), step.data(), use_cache);
485 if (
true == use_cache) {
488 llcache->write_cached_data(cache_fpath,xdim*ydim*2*
sizeof(
double),latlon_all);
497 set_value ((dods_float64 *) latlon.data(), nelms);
504 if (specialformat == 1) {
508 latlon_all.resize(xdim+ydim);
510 CalculateLargeGeoLatLon(gridid, fieldtype,latlon.data(), latlon_all.data(),offset.data(), count.data(), step.data(), nelms,use_cache);
511 if (
true == use_cache) {
514 llcache->write_cached_data(cache_fpath,(xdim+ydim)*
sizeof(
double),latlon_all);
524 set_value((dods_float64 *)latlon.data(),nelms);
532 else if (specialformat == 3) {
534 CalculateSpeLatLon (gridid, fieldtype, latlon.data(), offset32.data(), count32.data(), step32.data());
550 if (GCTP_GEO == projcode || GCTP_CEA == projcode)
551 latlon_all.resize(xdim+ydim);
553 latlon_all.resize(xdim*ydim*2);
555 CalculateLatLon (gridid, fieldtype, specialformat, latlon.data(),latlon_all.data(),
556 offset32.data(), count32.data(), step32.data(), nelms,use_cache);
558 if (
true == use_cache) {
559 size_t num_item_expected = 0;
560 if (GCTP_GEO == projcode || GCTP_CEA == projcode)
561 num_item_expected = xdim + ydim;
563 num_item_expected = xdim*ydim*2;
566 llcache->write_cached_data(cache_fpath,num_item_expected*
sizeof(
double),latlon_all);
572 if (speciallon && fieldtype == 2)
573 CorSpeLon(latlon.data(), nelms);
578 set_value ((dods_float64 *) latlon.data(), nelms);
587 tmp_dims.resize(rank);
589 char tmp_dimlist[1024];
594 r = fieldinfofunc (gridid,
const_cast < char *
>(fieldname.c_str ()),
595 &tmp_rank, tmp_dims.data(), &type, tmp_dimlist);
601 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
602 throw InternalErr (__FILE__, __LINE__, eherr.str ());
606 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
611 eherr <<
"Grid " << datasetname.c_str () <<
" information cannot be obtained.";
612 throw InternalErr (__FILE__, __LINE__, eherr.str ());
616 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
621 eherr <<
"Grid " << datasetname.c_str () <<
" projection info. cannot be obtained.";
622 throw InternalErr (__FILE__, __LINE__, eherr.str ());
625 if (projcode != GCTP_GEO) {
632 r = readfieldfunc (gridid,
633 const_cast < char *
>(fieldname.c_str ()),
634 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
639 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
640 throw InternalErr (__FILE__, __LINE__, eherr.str ());
645#ifndef SIGNED_BYTE_TO_INT32
646 set_value ((dods_byte *) val.data(), nelms);
649 newval.resize(nelms);
651 for (
int counter = 0; counter < nelms; counter++)
652 newval[counter] = (int32) (val[counter]);
654 set_value ((dods_int32 *) newval.data(), nelms);
665 r = readfieldfunc (gridid,
666 const_cast < char *
>(fieldname.c_str ()),
667 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
672 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
673 throw InternalErr (__FILE__, __LINE__, eherr.str ());
675 set_value ((dods_byte *) val.data(), nelms);
685 r = readfieldfunc (gridid,
686 const_cast < char *
>(fieldname.c_str ()),
687 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
692 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
693 throw InternalErr (__FILE__, __LINE__, eherr.str ());
696 set_value ((dods_int16 *) val.data(), nelms);
706 r = readfieldfunc (gridid,
707 const_cast < char *
>(fieldname.c_str ()),
708 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
713 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
714 throw InternalErr (__FILE__, __LINE__, eherr.str ());
717 set_value ((dods_uint16 *) val.data(), nelms);
726 r = readfieldfunc (gridid,
727 const_cast < char *
>(fieldname.c_str ()),
728 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
733 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
734 throw InternalErr (__FILE__, __LINE__, eherr.str ());
737 set_value ((dods_int32 *) val.data(), nelms);
746 r = readfieldfunc (gridid,
747 const_cast < char *
>(fieldname.c_str ()),
748 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
753 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
754 throw InternalErr (__FILE__, __LINE__, eherr.str ());
756 set_value ((dods_uint32 *) val.data(), nelms);
765 r = readfieldfunc (gridid,
766 const_cast < char *
>(fieldname.c_str ()),
767 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
772 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
773 throw InternalErr (__FILE__, __LINE__, eherr.str ());
776 set_value ((dods_float32 *) val.data(), nelms);
786 r = readfieldfunc (gridid,
787 const_cast < char *
>(fieldname.c_str ()),
788 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
793 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
794 throw InternalErr (__FILE__, __LINE__, eherr.str ());
797 set_value ((dods_float64 *) val.data(), nelms);
805 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
824 r = GDgetfillvalue (gridid,
825 const_cast < char *
>(fieldname.c_str ()),
828 int ifillvalue = fillvalue;
830 vector <int8> temp_total_val;
831 temp_total_val.resize(xdim*ydim);
833 r = readfieldfunc(gridid,
834 const_cast < char *
>(fieldname.c_str ()),
835 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
841 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
842 throw InternalErr (__FILE__, __LINE__, eherr.str ());
847 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
859 r = readfieldfunc (gridid,
860 const_cast < char *
>(fieldname.c_str ()),
861 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
866 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
867 throw InternalErr (__FILE__, __LINE__, eherr.str ());
871 if (speciallon && fieldtype == 2)
872 CorSpeLon (val.data(), nelms);
875#ifndef SIGNED_BYTE_TO_INT32
876 set_value ((dods_byte *) val.data(), nelms);
879 newval.resize(nelms);
881 for (
int counter = 0; counter < nelms; counter++)
882 newval[counter] = (int32) (val[counter]);
884 set_value ((dods_int32 *) newval.data(), nelms);
899 r = GDgetfillvalue (gridid,
900 const_cast < char *
>(fieldname.c_str ()),
905 int ifillvalue = fillvalue;
906 vector <uint8> temp_total_val;
907 temp_total_val.resize(xdim*ydim);
909 r = readfieldfunc(gridid,
910 const_cast < char *
>(fieldname.c_str ()),
911 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
917 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
918 throw InternalErr (__FILE__, __LINE__, eherr.str ());
922 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
934 r = readfieldfunc (gridid,
935 const_cast < char *
>(fieldname.c_str ()),
936 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
941 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
942 throw InternalErr (__FILE__, __LINE__, eherr.str ());
946 if (speciallon && fieldtype == 2)
947 CorSpeLon (val.data(), nelms);
948 set_value ((dods_byte *) val.data(), nelms);
960 r = GDgetfillvalue (gridid,
961 const_cast < char *
>(fieldname.c_str ()),
965 int ifillvalue = fillvalue;
966 vector <int16> temp_total_val;
967 temp_total_val.resize(xdim*ydim);
969 r = readfieldfunc(gridid,
970 const_cast < char *
>(fieldname.c_str ()),
971 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
977 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
978 throw InternalErr (__FILE__, __LINE__, eherr.str ());
982 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
994 r = readfieldfunc (gridid,
995 const_cast < char *
>(fieldname.c_str ()),
996 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
1001 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1002 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1007 if (speciallon && fieldtype == 2)
1008 CorSpeLon (val.data(), nelms);
1010 set_value ((dods_int16 *) val.data(), nelms);
1016 uint16 fillvalue = 0;
1020 r = GDgetfillvalue (gridid,
1021 const_cast < char *
>(fieldname.c_str ()),
1026 int ifillvalue = fillvalue;
1028 vector <uint16> temp_total_val;
1029 temp_total_val.resize(xdim*ydim);
1031 r = readfieldfunc(gridid,
1032 const_cast < char *
>(fieldname.c_str ()),
1033 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
1039 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1040 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1044 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
1055 r = readfieldfunc (gridid,
1056 const_cast < char *
>(fieldname.c_str ()),
1057 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
1062 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1063 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1067 if (speciallon && fieldtype == 2)
1068 CorSpeLon (val.data(), nelms);
1070 set_value ((dods_uint16 *) val.data(), nelms);
1080 int32 fillvalue = 0;
1082 r = GDgetfillvalue (gridid,
1083 const_cast < char *
>(fieldname.c_str ()),
1087 int ifillvalue = fillvalue;
1089 vector <int32> temp_total_val;
1090 temp_total_val.resize(xdim*ydim);
1092 r = readfieldfunc(gridid,
1093 const_cast < char *
>(fieldname.c_str ()),
1094 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
1100 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1101 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1105 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
1117 r = readfieldfunc (gridid,
1118 const_cast < char *
>(fieldname.c_str ()),
1119 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
1124 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1125 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1129 if (speciallon && fieldtype == 2)
1130 CorSpeLon (val.data(), nelms);
1132 set_value ((dods_int32 *) val.data(), nelms);
1142 uint32 fillvalue = 0;
1144 r = GDgetfillvalue (gridid,
1145 const_cast < char *
>(fieldname.c_str ()),
1150 int ifillvalue = (
int)fillvalue;
1151 vector <uint32> temp_total_val;
1152 temp_total_val.resize(xdim*ydim);
1153 r = readfieldfunc(gridid,
1154 const_cast < char *
>(fieldname.c_str ()),
1155 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
1161 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1162 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1166 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
1178 r = readfieldfunc (gridid,
1179 const_cast < char *
>(fieldname.c_str ()),
1180 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
1185 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1186 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1190 if (speciallon && fieldtype == 2)
1191 CorSpeLon (val.data(), nelms);
1193 set_value ((dods_uint32 *) val.data(), nelms);
1203 float32 fillvalue =0;
1204 r = GDgetfillvalue (gridid,
1205 const_cast < char *
>(fieldname.c_str ()),
1212 auto ifillvalue =(
int)fillvalue;
1214 vector <float32> temp_total_val;
1215 temp_total_val.resize(xdim*ydim);
1217 r = readfieldfunc(gridid,
1218 const_cast < char *
>(fieldname.c_str ()),
1219 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
1225 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1226 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1230 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
1241 r = readfieldfunc (gridid,
1242 const_cast < char *
>(fieldname.c_str ()),
1243 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
1248 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1249 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1253 if (speciallon && fieldtype == 2)
1254 CorSpeLon (val.data(), nelms);
1256 set_value ((dods_float32 *) val.data(), nelms);
1267 float64 fillvalue = 0;
1268 r = GDgetfillvalue (gridid,
1269 const_cast < char *
>(fieldname.c_str ()),
1275 auto ifillvalue = (
int)fillvalue;
1276 vector <float64> temp_total_val;
1277 temp_total_val.resize(xdim*ydim);
1278 r = readfieldfunc(gridid,
1279 const_cast < char *
>(fieldname.c_str ()),
1280 nullptr,
nullptr,
nullptr, (
void *)(temp_total_val.data()));
1286 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1287 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1291 HandleFillLatLon(temp_total_val, val.data(),ydimmajor,fieldtype,xdim,ydim,offset32.data(),count32.data(),step32.data(),ifillvalue);
1303 r = readfieldfunc (gridid,
1304 const_cast < char *
>(fieldname.c_str ()),
1305 offset32.data(), step32.data(), count32.data(), (
void*)(val.data()));
1310 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
1311 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1315 if (speciallon && fieldtype == 2)
1316 CorSpeLon (val.data(), nelms);
1318 set_value ((dods_float64 *) val.data(), nelms);
1325 throw InternalErr (__FILE__, __LINE__,
"unsupported data type.");
1330 r = detachfunc (gridid);
1333 eherr <<
"Grid " << datasetname.c_str () <<
" cannot be detached.";
1334 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1346HDFEOS2ArrayGridGeoField::format_constraint (
int *offset,
int *step,
1353 Dim_iter p = dim_begin ();
1354 while (p != dim_end ()) {
1356 int start = dimension_start (p,
true);
1357 int stride = dimension_stride (p,
true);
1358 int stop = dimension_stop (p,
true);
1363 oss <<
"Array/Grid hyperslab start point "<< start <<
1364 " is greater than stop point " << stop <<
".";
1365 throw Error(malformed_expr, oss.str());
1370 count[id] = ((stop - start) / stride) + 1;
1374 "=format_constraint():"
1375 <<
"id=" <<
id <<
" offset=" << offset[
id]
1376 <<
" step=" << step[
id]
1377 <<
" count=" << count[
id]
1390HDFEOS2ArrayGridGeoField::CalculateLatLon (int32 gridid,
int g_fieldtype,
1391 int g_specialformat,
1392 float64 * outlatlon,float64* latlon_all,
1393 const int32 * offset,
const int32 * count,
1394 const int32 * step,
int nelms,
bool write_latlon_cache)
1402 float64 lowright[2];
1404 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
1407 eherr <<
"cannot obtain grid information.";
1408 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1414 if (g_specialformat == 1) {
1415 upleft[0] = upleft[0] * 1000000;
1416 upleft[1] = upleft[1] * 1000000;
1417 lowright[0] = lowright[0] * 1000000;
1418 lowright[1] = lowright[1] * 1000000;
1425 if (g_specialformat == 2) {
1427 upleft[1] = 90000000.0;
1428 lowright[0] = 360000000.0;
1429 lowright[1] = -90000000.0;
1438 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
1441 eherr <<
"cannot obtain grid projection information";
1442 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1448 r = GDpixreginfo (gridid, &pixreg);
1451 eherr <<
"cannot obtain grid pixel registration info.";
1452 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1459 r = GDorigininfo (gridid, &origin);
1462 eherr <<
"cannot obtain grid origin info.";
1463 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1470 rows.resize(xdim*ydim);
1471 cols.resize(xdim*ydim);
1472 lon.resize(xdim*ydim);
1473 lat.resize(xdim*ydim);
1489 for (k = j = 0; j < ydim; ++j) {
1490 for (i = 0; i < xdim; ++i) {
1505 for (k = j = 0; j < xdim; ++j) {
1506 for (i = 0; i < ydim; ++i) {
1515 r = GDij2ll (projcode, zone, params, sphere, xdim, ydim, upleft, lowright,
1516 xdim * ydim, rows.data(), cols.data(), lon.data(), lat.data(), pixreg, origin);
1520 eherr <<
"cannot calculate grid latitude and longitude";
1521 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1525 if (
true == write_latlon_cache) {
1526 if (GCTP_CEA == projcode || GCTP_GEO == projcode) {
1529 int32 temp_offset[2];
1530 int32 temp_count[2];
1538 temp_count[0] = ydim;
1540 temp_lat.resize(ydim);
1541 LatLon2DSubset(temp_lat.data(),ydim,xdim,lat.data(),temp_offset,temp_count,temp_step);
1545 temp_count[1] = xdim;
1546 temp_lon.resize(xdim);
1547 LatLon2DSubset(temp_lon.data(),ydim,xdim,lon.data(),temp_offset,temp_count,temp_step);
1549 for(i = 0; i<ydim;i++)
1550 latlon_all[i] = temp_lat[i];
1555 if (speciallon ==
true) {
1556 CorSpeLon(temp_lon.data(),xdim);
1559 for(i = 0; i<xdim;i++)
1560 latlon_all[i+ydim] = temp_lon[i];
1565 temp_count[1] = ydim;
1567 temp_lat.resize(ydim);
1568 LatLon2DSubset(temp_lat.data(),xdim,ydim,lat.data(),temp_offset,temp_count,temp_step);
1572 temp_count[0] = xdim;
1573 temp_lon.resize(xdim);
1574 LatLon2DSubset(temp_lon.data(),xdim,ydim,lon.data(),temp_offset,temp_count,temp_step);
1576 for(i = 0; i<ydim;i++)
1577 latlon_all[i] = temp_lat[i];
1582 if (speciallon ==
true)
1583 CorSpeLon(temp_lon.data(),xdim);
1585 for(i = 0; i<xdim;i++)
1586 latlon_all[i+ydim] = temp_lon[i];
1591 memcpy((
char*)(&latlon_all[0]),lat.data(),xdim*ydim*
sizeof(
double));
1592 memcpy((
char*)(&latlon_all[0])+xdim*ydim*
sizeof(
double),lon.data(),xdim*ydim*
sizeof(
double));
1598 if (nelms == (xdim * ydim)) {
1599 if (g_fieldtype == 1)
1600 memcpy (outlatlon, lat.data(), xdim * ydim * sizeof (
double));
1602 memcpy (outlatlon, lon.data(), xdim * ydim * sizeof (
double));
1606 if (g_fieldtype == 1)
1607 LatLon2DSubset (outlatlon, ydim, xdim, lat.data(), offset, count,
1610 LatLon2DSubset (outlatlon, ydim, xdim, lon.data(), offset, count,
1614 if (g_fieldtype == 1)
1615 LatLon2DSubset (outlatlon, xdim, ydim, lat.data(), offset, count,
1618 LatLon2DSubset (outlatlon, xdim, ydim, lon.data(), offset, count,
1626template<
class T>
void
1627HDFEOS2ArrayGridGeoField::LatLon2DSubset (T * outlatlon,
int ,
1628 int minordim, T * latlon,
1629 const int32 * offset,
const int32 * count,
1630 const int32 * step)
const
1637 int dim0count = count[0];
1638 int dim1count = count[1];
1639 int dim0index[dim0count];
1640 int dim1index[dim1count];
1642 for (i = 0; i < count[0]; i++)
1643 dim0index[i] = offset[0] + i * step[0];
1646 for (j = 0; j < count[1]; j++)
1647 dim1index[j] = offset[1] + j * step[1];
1652 for (i = 0; i < count[0]; i++) {
1653 for (j = 0; j < count[1]; j++) {
1655 outlatlon[k] = *(latlon + (dim0index[i] * minordim) + dim1index[j]);
1665template <
class T >
bool HDFEOS2ArrayGridGeoField::CorLatLon (T * latlon,
1679 for (
int i = 0; i < elms; i++)
1680 if ((
int) (latlon[i]) == fv)
1687 for (
int i = 0; i < 3; i++)
1688 if ((
int) (latlon[i]) == fv)
1691 if ((
int) (latlon[elms - 1]) != fv)
1694 T increment = latlon[2] - latlon[1];
1699 index = findfirstfv (latlon, 0, elms - 1, fv);
1702 eherr <<
"cannot calculate the fill value. ";
1703 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1706 for (
int i = index; i < elms; i++) {
1708 latlon[i] = latlon[i - 1] + increment;
1711 if (i != (elms - 1) && (g_fieldtype == 1) &&
1712 ((
float) (latlon[i]) < -90.0 || (
float) (latlon[i]) > 90.0))
1719 if (i != (elms - 1) && (g_fieldtype == 2) &&
1720 ((
float) (latlon[i]) < -180.0 || (
float) (latlon[i]) > 360.0))
1723 if (g_fieldtype == 1) {
1724 if ((
float) (latlon[elms - 1]) < -90.0)
1725 latlon[elms - 1] = (T)-90;
1726 if ((
float) (latlon[elms - 1]) > 90.0)
1727 latlon[elms - 1] = (T)90;
1730 if (g_fieldtype == 2) {
1731 if ((
float) (latlon[elms - 1]) < -180.0)
1732 latlon[elms - 1] = (T)-180.0;
1733 if ((
float) (latlon[elms - 1]) > 360.0)
1734 latlon[elms - 1] = (T)360.0;
1740template <
class T >
void
1741HDFEOS2ArrayGridGeoField::CorSpeLon (T * lon,
int xdim)
const
1744 float64 accuracy = 1e-3;
1750 for (i = 0; i < xdim; i++) {
1751 if ((
double) lon[i] < 180.0)
1752 temp = 180.0 - (double) lon[i];
1753 if ((
double) lon[i] > 180.0)
1754 temp = (double) lon[i] - 180.0;
1756 if (temp < accuracy) {
1760 else if ((
static_cast < double >(lon[i]) < 180.0)
1761 &&(
static_cast<double>(lon[i + 1]) > 180.0)) {
1769 if (speindex != -1) {
1770 for (i = speindex + 1; i < xdim; i++) {
1772 static_cast < T
> (
static_cast < double >(lon[i]) - 360.0);
1780HDFEOS2ArrayGridGeoField::getCorrectSubset (
const int *offset,
const int *count,
1781 const int *step, int32 * offset32,
1782 int32 * count32, int32 * step32,
1783 bool gf_condenseddim,
bool gf_ydimmajor,
1784 int gf_fieldtype,
int gf_rank)
const
1788 offset32[0] = (int32) offset[0];
1789 count32[0] = (int32) count[0];
1790 step32[0] = (int32) step[0];
1792 else if (gf_condenseddim) {
1796 for (
int i = 0; i < gf_rank; i++) {
1802 if (gf_ydimmajor && gf_fieldtype == 1) {
1803 offset32[0] = (int32) offset[0];
1804 count32[0] = (int32) count[0];
1805 step32[0] = (int32) step[0];
1807 else if (gf_ydimmajor && gf_fieldtype == 2) {
1808 offset32[1] = (int32) offset[0];
1809 count32[1] = (int32) count[0];
1810 step32[1] = (int32) step[0];
1812 else if (!gf_ydimmajor && gf_fieldtype == 1) {
1813 offset32[1] = (int32) offset[0];
1814 count32[1] = (int32) count[0];
1815 step32[1] = (int32) step[0];
1817 else if (!gf_ydimmajor && gf_fieldtype == 2) {
1818 offset32[0] = (int32) offset[0];
1819 count32[0] = (int32) count[0];
1820 step32[0] = (int32) step[0];
1824 throw InternalErr (__FILE__, __LINE__,
1825 "Lat/lon subset is wrong for condensed lat/lon");
1829 for (
int i = 0; i < gf_rank; i++) {
1830 offset32[i] = (int32) offset[i];
1831 count32[i] = (int32) count[i];
1832 step32[i] = (int32) step[i];
1840template <
class T>
void
1841HDFEOS2ArrayGridGeoField::HandleFillLatLon(
vector<T> total_latlon, T* latlon,
bool gf_ydimmajor,
int gf_fieldtype, int32 xdim , int32 ydim,
const int32* offset,
const int32* count,
const int32* step,
int fv) {
1843 class vector <T> temp_lat;
1844 class vector <T> temp_lon;
1846 if (
true == gf_ydimmajor) {
1848 if (1 == gf_fieldtype) {
1849 temp_lat.resize(ydim);
1850 for (
int i = 0; i <(
int)ydim; i++)
1851 temp_lat[i] = total_latlon[i*xdim];
1853 if (
false == CorLatLon(temp_lat.data(),gf_fieldtype,ydim,fv))
1854 throw InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1856 for (
int i = 0; i <(
int)(count[0]); i++)
1857 latlon[i] = temp_lat[offset[0] + i* step[0]];
1861 temp_lon.resize(xdim);
1862 for (
int i = 0; i <(
int)xdim; i++)
1863 temp_lon[i] = total_latlon[i];
1866 if (
false == CorLatLon(temp_lon.data(),gf_fieldtype,xdim,fv))
1867 throw InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1869 for (
int i = 0; i <(
int)(count[1]); i++)
1870 latlon[i] = temp_lon[offset[1] + i* step[1]];
1876 if (1 == gf_fieldtype) {
1877 temp_lat.resize(xdim);
1878 for (
int i = 0; i <(
int)xdim; i++)
1879 temp_lat[i] = total_latlon[i];
1881 if (
false == CorLatLon(temp_lat.data(),gf_fieldtype,ydim,fv))
1882 throw InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1884 for (
int i = 0; i <(
int)(count[1]); i++)
1885 latlon[i] = temp_lat[offset[1] + i* step[1]];
1889 temp_lon.resize(ydim);
1890 for (
int i = 0; i <(
int)ydim; i++)
1891 temp_lon[i] = total_latlon[i*xdim];
1894 if (
false == CorLatLon(temp_lon.data(),gf_fieldtype,xdim,fv))
1895 throw InternalErr(__FILE__,__LINE__,
"Cannot handle the fill values in lat/lon correctly");
1897 for (
int i = 0; i <(
int)(count[0]); i++)
1898 latlon[i] = temp_lon[offset[0] + i* step[0]];
1905template <
class T >
int
1906HDFEOS2ArrayGridGeoField::findfirstfv (T * array,
int start,
int end,
1910 if (start == end || start == (end - 1)) {
1911 if (
static_cast < int >(array[start]) == fillvalue)
1917 int current = (start + end) / 2;
1919 if (
static_cast < int >(array[current]) == fillvalue)
1920 return findfirstfv (array, start, current, fillvalue);
1922 return findfirstfv (array, current, end, fillvalue);
1934HDFEOS2ArrayGridGeoField::CalculateSpeLatLon (int32 gridid,
int gf_fieldtype,
1935 float64 * outlatlon,
1936 const int32 * offset32,
1937 const int32 * count32,
const int32 * step32)
const
1945 float64 lowright[2];
1947 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
1950 eherr <<
"cannot obtain grid information.";
1951 throw InternalErr (__FILE__, __LINE__, eherr.str ());
1961 if (0 == xdim || 0 == ydim)
1962 throw InternalErr(__FILE__,__LINE__,
"xdim or ydim cannot be zero");
1964 if (gf_fieldtype == 1) {
1965 double latstep = 180.0 / ydim;
1967 for (
int i = 0; i < (
int) (count32[0]); i++)
1968 outlatlon[i] = 90.0 -latstep/2 - latstep * (offset32[0] + i * step32[0]);
1971 double lonstep = 360.0 / xdim;
1973 for (
int i = 0; i < (
int) (count32[1]); i++)
1974 outlatlon[i] = -180.0 + lonstep/2 + lonstep * (offset32[1] + i * step32[1]);
1984HDFEOS2ArrayGridGeoField::CalculateSOMLatLon(int32 gridid,
const int *start,
const int *count,
const int *step,
int nelms,
const string & cache_fpath,
bool write_latlon_cache)
1986 int32 projcode = -1;
1989 float64 params[NPROJ];
1992 r = GDprojinfo (gridid, &projcode, &zone, &sphere, params);
1994 throw InternalErr (__FILE__, __LINE__,
"GDprojinfo doesn't return the correct values");
1998 char dimlist[STRLEN];
1999 r = GDinqdims(gridid, dimlist, dim);
2003 throw InternalErr (__FILE__, __LINE__,
"GDinqdims doesn't return the correct values");
2005 bool is_block_180 =
false;
2006 for(
int i=0; i<MAXNDIM; i++)
2010 is_block_180 =
true;
2014 if (
false == is_block_180) {
2016 eherr <<
"Number of Block is not " << NBLOCK ;
2017 throw InternalErr(__FILE__,__LINE__,eherr.str());
2025 r = GDgridinfo (gridid, &xdim, &ydim, ulc, lrc);
2027 throw InternalErr(__FILE__,__LINE__,
"GDgridinfo doesn't return the correct values");
2030 float32 offset[NOFFSET];
2031 char som_rw_code[]=
"r";
2032 r = GDblkSOMoffset(gridid, offset, NOFFSET, som_rw_code);
2034 throw InternalErr(__FILE__,__LINE__,
"GDblkSOMoffset doesn't return the correct values");
2036 int status = misr_init(NBLOCK, xdim, ydim, offset, ulc, lrc);
2038 throw InternalErr(__FILE__,__LINE__,
"misr_init doesn't return the correct values");
2041 int (*inv_trans[MAXPROJ+1])(double, double,
double*,
double*);
2042 inv_init((
int)projcode, (
int)zone, (
double*)params, (
int)sphere,
nullptr,
nullptr, (
int*)&iflg, inv_trans);
2044 throw InternalErr(__FILE__,__LINE__,
"inv_init doesn't return correct values");
2064 if (
true == write_latlon_cache) {
2066 latlon_all.resize(xdim*ydim*NBLOCK*2);
2067 for(i =1; i <NBLOCK+1;i++)
2074 misrinv(b, l, s, &somx, &somy);
2075 sominv(somx, somy, &lon_r, &lat_r);
2076 latlon_all[npts] = lat_r*R2D;
2077 latlon_all[xdim*ydim*NBLOCK+npts] = lon_r*R2D;
2083 llcache->write_cached_data(cache_fpath,xdim*ydim*NBLOCK*2*
sizeof(
double),latlon_all);
2087 latlon.resize(nelms);
2101 for(i=0; i<count[0]; i++)
2102 for(j=0; j<count[1]; j++)
2103 for(k=0; k<count[2]; k++)
2105 if (fieldtype == 1) {
2106 latlon[npts] = latlon_all[start[0]*ydim*xdim+start[1]*ydim+start[2]+
2107 i*ydim*xdim*step[0]+j*ydim*step[1]+k*step[2]];
2110 latlon[npts] = latlon_all[xdim*ydim*NBLOCK+start[0]*ydim*xdim+start[1]*ydim+start[2]+
2111 i*ydim*xdim*step[0]+j*ydim*step[1]+k*step[2]];
2117 set_value ((dods_float64 *) latlon.data(), nelms);
2121 latlon.resize(nelms);
2123 int e1=s1+count[0]*step[0];
2125 int e2=s2+count[1]*step[1];
2127 int e3=s3+count[2]*step[2];
2128 for(i=s1; i<e1; i+=step[0])
2129 for(j=s2; j<e2; j+=step[1])
2130 for(k=s3; k<e3; k+=step[2])
2135 misrinv(b, l, s, &somx, &somy);
2136 sominv(somx, somy, &lon_r, &lat_r);
2138 latlon[npts] = lat_r*R2D;
2140 latlon[npts] = lon_r*R2D;
2143 set_value ((dods_float64 *) latlon.data(), nelms);
2154HDFEOS2ArrayGridGeoField::CalculateLargeGeoLatLon(int32 gridid,
int gf_fieldtype, float64* latlon, float64* latlon_all,
const int *start,
const int *count,
const int *step,
int nelms,
bool write_latlon_cache)
const
2160 float64 lowright[2];
2162 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
2164 throw InternalErr(__FILE__,__LINE__,
"GDgridinfo failed");
2167 if (0 == xdim || 0 == ydim) {
2168 throw InternalErr(__FILE__,__LINE__,
"xdim or ydim should not be zero. ");
2171 if (upleft[0]>180.0 || upleft[0] <-180.0 ||
2172 upleft[1]>90.0 || upleft[1] <-90.0 ||
2173 lowright[0] >180.0 || lowright[0] <-180.0 ||
2174 lowright[1] >90.0 || lowright[1] <-90.0) {
2176 throw InternalErr(__FILE__,__LINE__,
"lat/lon corner points are out of range. ");
2179 if (count[0] != nelms) {
2180 throw InternalErr(__FILE__,__LINE__,
"rank is not 1 ");
2182 float lat_step = (float)(lowright[1] - upleft[1])/ydim;
2183 float lon_step = (float)(lowright[0] - upleft[0])/xdim;
2185 if (
true == write_latlon_cache) {
2187 for(
int i = 0;i<ydim;i++)
2188 latlon_all[i] = upleft[1] + i*lat_step + lat_step/2;
2190 for(
int i = 0;i<xdim;i++)
2191 latlon_all[i+ydim] = upleft[0] + i*lon_step + lon_step/2;
2197 if (1 == gf_fieldtype) {
2198 auto start_lat = (float)(upleft[1] + start[0] *lat_step + lat_step/2);
2199 float step_lat = lat_step *step[0];
2200 for (
int i = 0; i < count[0]; i++)
2201 latlon[i] = start_lat +i *step_lat;
2204 auto start_lon = (float)(upleft[0] + start[0] *lon_step + lon_step/2);
2205 float step_lon = lon_step *step[0];
2206 for (
int i = 0; i < count[0]; i++)
2207 latlon[i] = start_lon +i *step_lon;
2216HDFEOS2ArrayGridGeoField::CalculateLAMAZLatLon(int32 gridid,
int gf_fieldtype, float64* latlon, float64* latlon_all,
const int *start,
const int *count,
const int *step,
bool write_latlon_cache)
2222 float64 lowright[2];
2224 r = GDgridinfo (gridid, &xdim, &ydim, upleft, lowright);
2226 throw InternalErr(__FILE__,__LINE__,
"GDgridinfo failed");
2229 tmp1.resize(xdim*ydim);
2230 int32 tmp2[] = {0, 0};
2231 int32 tmp3[] = {xdim, ydim};
2232 int32 tmp4[] = {1, 1};
2234 CalculateLatLon (gridid, gf_fieldtype, specialformat, tmp1.data(), latlon_all, tmp2, tmp3, tmp4, xdim*ydim,write_latlon_cache);
2236 if (write_latlon_cache ==
true) {
2240 temp_lat_all.resize(xdim*ydim);
2241 lat_all.resize(xdim*ydim);
2245 temp_lon_all.resize(xdim*ydim);
2246 lon_all.resize(xdim*ydim);
2248 for(
int w=0; w < xdim*ydim; w++){
2249 temp_lat_all[w] = latlon_all[w];
2250 lat_all[w] = latlon_all[w];
2251 temp_lon_all[w] = latlon_all[w+xdim*ydim];
2252 lon_all[w] = latlon_all[w+xdim*ydim];
2257 for(
int i=0; i<ydim; i++)
2258 for(
int j=0; j<xdim; j++)
2259 if (isundef_lat(lat_all[i*xdim+j]))
2260 lat_all[i*xdim+j]=nearestNeighborLatVal(temp_lat_all.data(), i, j, ydim, xdim);
2261 for(
int i=0; i<ydim; i++)
2262 for(
int j=0; j<xdim; j++)
2263 if (isundef_lon(lon_all[i*xdim+j]))
2264 lon_all[i*xdim+j]=nearestNeighborLonVal(temp_lon_all.data(), i, j, ydim, xdim);
2267 for(
int i=0; i<xdim; i++)
2268 for(
int j=0; j<ydim; j++)
2269 if (isundef_lat(lat_all[i*ydim+j]))
2270 lat_all[i*ydim+j]=nearestNeighborLatVal(temp_lat_all.data(), i, j, xdim, ydim);
2272 for(
int i=0; i<xdim; i++)
2273 for(
int j=0; j<ydim; j++)
2274 if (isundef_lon(lon_all[i*ydim+j]))
2275 lon_all[i*ydim+j]=nearestNeighborLonVal(temp_lon_all.data(), i, j, xdim, ydim);
2279 for(
int i = 0; i<xdim*ydim;i++) {
2280 latlon_all[i] = lat_all[i];
2281 latlon_all[i+xdim*ydim] = lon_all[i];
2288 tmp5.resize(xdim*ydim);
2290 for(
int w=0; w < xdim*ydim; w++)
2295 if (gf_fieldtype==1) {
2296 for(
int i=0; i<ydim; i++)
2297 for(
int j=0; j<xdim; j++)
2298 if (isundef_lat(tmp1[i*xdim+j]))
2299 tmp1[i*xdim+j]=nearestNeighborLatVal(tmp5.data(), i, j, ydim, xdim);
2300 }
else if (gf_fieldtype==2){
2301 for(
int i=0; i<ydim; i++)
2302 for(
int j=0; j<xdim; j++)
2303 if (isundef_lon(tmp1[i*xdim+j]))
2304 tmp1[i*xdim+j]=nearestNeighborLonVal(tmp5.data(), i, j, ydim, xdim);
2307 if (gf_fieldtype==1) {
2308 for(
int i=0; i<xdim; i++)
2309 for(
int j=0; j<ydim; j++)
2310 if (isundef_lat(tmp1[i*ydim+j]))
2311 tmp1[i*ydim+j]=nearestNeighborLatVal(tmp5.data(), i, j, xdim, ydim);
2312 }
else if (gf_fieldtype==2) {
2313 for(
int i=0; i<xdim; i++)
2314 for(
int j=0; j<ydim; j++)
2315 if (isundef_lon(tmp1[i*ydim+j]))
2316 tmp1[i*ydim+j]=nearestNeighborLonVal(tmp5.data(), i, j, xdim, ydim);
2320 for(
int i=start[0], k=0; i<start[0]+count[0]*step[0]; i+=step[0])
2321 for(
int j=start[1]; j<start[1]+count[1]*step[1]; j+= step[1])
2322 latlon[k++] = tmp1[i*ydim+j];
virtual void unlock_and_close(const std::string &target)
virtual void purge_file(const std::string &file)
Purge a single file from the cache.
static BESH4Cache * get_instance()
static void close_fileid(int32 sdfd, int32 file_id, int32 gridfd, int32 swathfd, bool pass_fileid_key)