17#ifndef HDFEOS2ARRAY_GRIDGEOFIELD_H
18#define HDFEOS2ARRAY_GRIDGEOFIELD_H
22#include <libdap/Array.h>
29class 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 =
nullptr):
35 fieldtype (fieldtype),
37 ydimmajor (ydimmajor),
38 condenseddim (condenseddim),
39 speciallon (speciallon),
40 specialformat (specialformat),
48 ~ HDFEOS2ArrayGridGeoField ()
override =
default;
50 int format_constraint (
int *cor,
int *step,
int *edg);
52 libdap::BaseType *ptr_duplicate ()
override
54 return new HDFEOS2ArrayGridGeoField (*
this);
57 bool read ()
override;
117 std::string filename;
122 std::string gridname;
125 std::string fieldname;
127 void CalculateLatLon (int32 gridid,
int fieldtype,
int specialformat, float64 * outlatlon, float64* latlon_all,
const int32 * offset,
const int32 * count,
const int32 * step,
int nelms,
bool write_latlon_cache);
136 void CalculateSpeLatLon (int32 gridid,
int fieldtype, float64 * outlatlon,
const int32 * offset,
const int32 * count,
const int32 * step)
const;
139 void CalculateLargeGeoLatLon(int32 gridid,
int fieldtype, float64* latlon, float64* latlon_all,
const int *start,
const int *count,
const int *step,
int nelms,
bool write_latlon_cache)
const;
141 bool isundef_lat(
double value)
const
143 if (std::isinf(value))
145 if (std::isnan(value))
149 if(value < -90.0 || value > 90.0)
155 bool isundef_lon(
double value)
const
157 if (std::isinf(value))
159 if (std::isnan(value))
162 if (value < -180.0 || value > 180.0)
169 double nearestNeighborLatVal(
double *array,
int row,
int col,
int YDim,
int XDim)
172 if(row < 0 || row > YDim || col < 0 || col > XDim)
174 cerr <<
"nearestNeighborLatVal("<<row<<
", "<<col<<
", "<<YDim<<
", "<<XDim;
175 cerr <<
"): index out of range"<<endl;
179 if(row < YDim/2 && col < XDim/2)
181 if(!isundef_lat(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
182 if(!isundef_lat(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
183 if(!isundef_lat(array[(row+1)*XDim+col+1]))
return(array[(row+1)*XDim+col+1]);
185 return(nearestNeighborLatVal(array, row+1, col+1, YDim, XDim));
187 if(row < YDim/2 && col > XDim/2)
189 if(!isundef_lat(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
190 if(!isundef_lat(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
191 if(!isundef_lat(array[(row+1)*XDim+col-1]))
return(array[(row+1)*XDim+col-1]);
193 return(nearestNeighborLatVal(array, row+1, col-1, YDim, XDim));
195 if(row > YDim/2 && col < XDim/2)
197 if(!isundef_lat(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
198 if(!isundef_lat(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
199 if(!isundef_lat(array[(row-1)*XDim+col+1]))
return(array[(row-1)*XDim+col+1]);
201 return(nearestNeighborLatVal(array, row-1, col+1, YDim, XDim));
203 if(row > YDim/2 && col > XDim/2)
205 if(!isundef_lat(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
206 if(!isundef_lat(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
207 if(!isundef_lat(array[(row-1)*XDim+col-1]))
return(array[(row-1)*XDim+col-1]);
209 return(nearestNeighborLatVal(array, row-1, col-1, YDim, XDim));
215 double nearestNeighborLonVal(
double *array,
int row,
int col,
int YDim,
int XDim)
218 if(row < 0 || row > YDim || col < 0 || col > XDim)
220 cerr <<
"nearestNeighborLonVal("<<row<<
", "<<col<<
", "<<YDim<<
", "<<XDim;
221 cerr <<
"): index out of range"<<endl;
225 if(row < YDim/2 && col < XDim/2)
227 if(!isundef_lon(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
228 if(!isundef_lon(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
229 if(!isundef_lon(array[(row+1)*XDim+col+1]))
return(array[(row+1)*XDim+col+1]);
231 return(nearestNeighborLonVal(array, row+1, col+1, YDim, XDim));
233 if(row < YDim/2 && col > XDim/2)
235 if(!isundef_lon(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
236 if(!isundef_lon(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
237 if(!isundef_lon(array[(row+1)*XDim+col-1]))
return(array[(row+1)*XDim+col-1]);
239 return(nearestNeighborLonVal(array, row+1, col-1, YDim, XDim));
241 if(row > YDim/2 && col < XDim/2)
243 if(!isundef_lon(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
244 if(!isundef_lon(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
245 if(!isundef_lon(array[(row-1)*XDim+col+1]))
return(array[(row-1)*XDim+col+1]);
247 return(nearestNeighborLonVal(array, row-1, col+1, YDim, XDim));
249 if(row > YDim/2 && col > XDim/2)
251 if(!isundef_lon(array[(row-1)*XDim+col]))
return(array[(row-1)*XDim+col]);
252 if(!isundef_lon(array[row*XDim+col-1]))
return(array[row*XDim+col-1]);
253 if(!isundef_lon(array[(row-1)*XDim+col-1]))
return(array[(row-1)*XDim+col-1]);
255 return(nearestNeighborLonVal(array, row-1, col-1, YDim, XDim));
267 void CalculateSOMLatLon(int32,
const int*,
const int*,
const int*,
int,
const string &,
bool);
270 void CalculateLAMAZLatLon(int32,
int, float64*, float64*,
const int*,
const int*,
const int*,
bool);
273 template <
class T>
void LatLon2DSubset (T* outlatlon,
int ydim,
int xdim, T* latlon,
const int32 * offset,
const int32 * count,
const int32 * step)
const;
277 template <
class T>
void HandleFillLatLon(vector<T> total_latlon, T* latlon,
bool ydimmajor,
int fieldtype, int32 xdim , int32 ydim,
const int32* offset,
const int32* count,
const int32* step,
int fv);
280 template <
class T >
bool CorLatLon (T * latlon,
int fieldtype,
int elms,
int fv);
283 template <
class T >
void CorSpeLon (T * lon,
int xdim)
const;
287 void getCorrectSubset (
const int *offset,
const int *count,
const int *step, int32 * offset32, int32 * count32, int32 * step32,
bool condenseddim,
bool ydimmajor,
int fieldtype,
int rank)
const;
290 template <
class T >
int findfirstfv (T * array,
int start,
int end,
int fillvalue);