16 #ifdef USE_HDFEOS2_LIB
17 #ifndef HDFEOS2ARRAY_GRIDGEOFIELD_H
18 #define HDFEOS2ARRAY_GRIDGEOFIELD_H
26 #include "HdfEosDef.h"
29 class HDFEOS2ArrayGridGeoField:
public libdap::Array
32 HDFEOS2ArrayGridGeoField (
int rank,
int fieldtype,
bool llflag,
bool ydimmajor,
bool condenseddim,
bool speciallon,
int specialformat,
const std::string &filename,
const int gridfd,
const std::string & gridname,
const std::string & fieldname,
const string & n =
"", libdap::BaseType * v = 0):
35 fieldtype (fieldtype),
37 ydimmajor (ydimmajor),
38 condenseddim (condenseddim),
39 speciallon (speciallon),
40 specialformat (specialformat),
48 virtual ~ HDFEOS2ArrayGridGeoField ()
51 int format_constraint (
int *cor,
int *step,
int *edg);
53 libdap::BaseType *ptr_duplicate ()
55 return new HDFEOS2ArrayGridGeoField (*
this);
120 std::string filename;
125 std::string gridname;
128 std::string fieldname;
130 void CalculateLatLon (int32 gridid,
int fieldtype,
int specialformat, float64 * outlatlon, float64* latlon_all, int32 * offset, int32 * count, int32 * step,
int nelms,
bool write_latlon_cache);
139 void CalculateSpeLatLon (int32 gridid,
int fieldtype, float64 * outlatlon, int32 * offset, int32 * count, int32 * step);
142 void CalculateLargeGeoLatLon(int32 gridid,
int fieldtype, float64* latlon, float64* latlon_all,
int *start,
int *count,
int *step,
int nelms,
bool write_latlon_cache);
144 bool isundef_lat(
double value)
146 if (std::isinf(value))
return(
true);
147 if (std::isnan(value))
return(
true);
149 if(value < -90.0 || value > 90.0)
155 bool isundef_lon(
double value)
157 if (std::isinf(value))
return(
true);
158 if (std::isnan(value))
return(
true);
160 if(value < -180.0 || value > 180.0)
return(
true);
166 double nearestNeighborLatVal(
double *array,
int row,
int col,
int YDim,
int XDim)
169 if(row < 0 || row > YDim || col < 0 || col > XDim)
171 cerr <<
"nearestNeighborLatVal("<<row<<
", "<<col<<
", "<<YDim<<
", "<<XDim;
172 cerr <<
"): index out of range"<<endl;
176 if(row < YDim/2 && col < XDim/2)
178 if(!isundef_lat(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
179 if(!isundef_lat(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
180 if(!isundef_lat(array[(row+1)*XDim+col+1]))
return(array[(row+1)*XDim+col+1]);
182 return(nearestNeighborLatVal(array, row+1, col+1, YDim, XDim));
184 if(row < YDim/2 && col > XDim/2)
186 if(!isundef_lat(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
187 if(!isundef_lat(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
188 if(!isundef_lat(array[(row+1)*XDim+col-1]))
return(array[(row+1)*XDim+col-1]);
190 return(nearestNeighborLatVal(array, row+1, col-1, YDim, XDim));
192 if(row > YDim/2 && col < XDim/2)
194 if(!isundef_lat(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
195 if(!isundef_lat(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
196 if(!isundef_lat(array[(row-1)*XDim+col+1]))
return(array[(row-1)*XDim+col+1]);
198 return(nearestNeighborLatVal(array, row-1, col+1, YDim, XDim));
200 if(row > YDim/2 && col > XDim/2)
202 if(!isundef_lat(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
203 if(!isundef_lat(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
204 if(!isundef_lat(array[(row-1)*XDim+col-1]))
return(array[(row-1)*XDim+col-1]);
206 return(nearestNeighborLatVal(array, row-1, col-1, YDim, XDim));
212 double nearestNeighborLonVal(
double *array,
int row,
int col,
int YDim,
int XDim)
215 if(row < 0 || row > YDim || col < 0 || col > XDim)
217 cerr <<
"nearestNeighborLonVal("<<row<<
", "<<col<<
", "<<YDim<<
", "<<XDim;
218 cerr <<
"): index out of range"<<endl;
222 if(row < YDim/2 && col < XDim/2)
224 if(!isundef_lon(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
225 if(!isundef_lon(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
226 if(!isundef_lon(array[(row+1)*XDim+col+1]))
return(array[(row+1)*XDim+col+1]);
228 return(nearestNeighborLonVal(array, row+1, col+1, YDim, XDim));
230 if(row < YDim/2 && col > XDim/2)
232 if(!isundef_lon(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
233 if(!isundef_lon(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
234 if(!isundef_lon(array[(row+1)*XDim+col-1]))
return(array[(row+1)*XDim+col-1]);
236 return(nearestNeighborLonVal(array, row+1, col-1, YDim, XDim));
238 if(row > YDim/2 && col < XDim/2)
240 if(!isundef_lon(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
241 if(!isundef_lon(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
242 if(!isundef_lon(array[(row-1)*XDim+col+1]))
return(array[(row-1)*XDim+col+1]);
244 return(nearestNeighborLonVal(array, row-1, col+1, YDim, XDim));
246 if(row > YDim/2 && col > XDim/2)
248 if(!isundef_lon(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
249 if(!isundef_lon(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
250 if(!isundef_lon(array[(row-1)*XDim+col-1]))
return(array[(row-1)*XDim+col-1]);
252 return(nearestNeighborLonVal(array, row-1, col-1, YDim, XDim));
264 void CalculateSOMLatLon(int32,
int*,
int*,
int*,
int,
const string &,
bool);
267 void CalculateLAMAZLatLon(int32,
int, float64*, float64*,
int*,
int*,
int*,
bool);
270 template <
class T>
void LatLon2DSubset (T* outlatlon,
int ydim,
int xdim, T* latlon, int32 * offset, int32 * count, int32 * step);
274 template <
class T>
void HandleFillLatLon(vector<T> total_latlon, T* latlon,
bool ydimmajor,
int fieldtype, int32 xdim , int32 ydim, int32* offset, int32* count, int32* step,
int fv);
277 template <
class T >
bool CorLatLon (T * latlon,
int fieldtype,
int elms,
int fv);
280 template <
class T >
void CorSpeLon (T * lon,
int xdim);
284 void getCorrectSubset (
int *offset,
int *count,
int *step, int32 * offset32, int32 * count32, int32 * step32,
bool condenseddim,
bool ydimmajor,
int fieldtype,
int rank);
287 template <
class T >
int findfirstfv (T * array,
int start,
int end,
int fillvalue);