16 #ifdef USE_HDFEOS2_LIB
17 #ifndef HDFEOS2ARRAY_GRIDGEOFIELD_H
18 #define HDFEOS2ARRAY_GRIDGEOFIELD_H
23 #include "HdfEosDef.h"
26 class HDFEOS2ArrayGridGeoField:
public Array
29 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 =
"", BaseType * v = 0):
32 fieldtype (fieldtype),
34 ydimmajor (ydimmajor),
35 condenseddim (condenseddim),
36 speciallon (speciallon),
37 specialformat (specialformat),
45 virtual ~ HDFEOS2ArrayGridGeoField ()
48 int format_constraint (
int *cor,
int *step,
int *edg);
50 BaseType *ptr_duplicate ()
52 return new HDFEOS2ArrayGridGeoField (*
this);
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, int32 * offset, int32 * count, int32 * step,
int nelms,
bool write_latlon_cache);
136 void CalculateSpeLatLon (int32 gridid,
int fieldtype, float64 * outlatlon, int32 * offset, int32 * count, int32 * step,
int nelms);
139 void CalculateLargeGeoLatLon(int32 gridid,
int fieldtype, float64* latlon, float64* latlon_all,
int *start,
int *count,
int *step,
int nelms,
bool write_latlon_cache);
141 bool isundef_lat(
double value)
143 if(isinf(value))
return(
true);
144 if(isnan(value))
return(
true);
146 if(value < -90.0 || value > 90.0)
return(
true);
150 bool isundef_lon(
double value)
152 if(isinf(value))
return(
true);
153 if(isnan(value))
return(
true);
155 if(value < -180.0 || value > 180.0)
return(
true);
161 double nearestNeighborLatVal(
double *array,
int row,
int col,
int YDim,
int XDim)
164 if(row < 0 || row > YDim || col < 0 || col > XDim)
166 cerr <<
"nearestNeighborLatVal("<<row<<
", "<<col<<
", "<<YDim<<
", "<<XDim;
167 cerr <<
"): index out of range"<<endl;
171 if(row < YDim/2 && col < XDim/2)
173 if(!isundef_lat(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
174 if(!isundef_lat(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
175 if(!isundef_lat(array[(row+1)*XDim+col+1]))
return(array[(row+1)*XDim+col+1]);
177 return(nearestNeighborLatVal(array, row+1, col+1, YDim, XDim));
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));
207 double nearestNeighborLonVal(
double *array,
int row,
int col,
int YDim,
int XDim)
210 if(row < 0 || row > YDim || col < 0 || col > XDim)
212 cerr <<
"nearestNeighborLonVal("<<row<<
", "<<col<<
", "<<YDim<<
", "<<XDim;
213 cerr <<
"): index out of range"<<endl;
217 if(row < YDim/2 && col < XDim/2)
219 if(!isundef_lon(array[(row+1)*XDim+col]))
return(array[(row+1)*XDim+col]);
220 if(!isundef_lon(array[row*XDim+col+1]))
return(array[row*XDim+col+1]);
221 if(!isundef_lon(array[(row+1)*XDim+col+1]))
return(array[(row+1)*XDim+col+1]);
223 return(nearestNeighborLonVal(array, row+1, col+1, YDim, XDim));
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));
259 void CalculateSOMLatLon(int32,
int*,
int*,
int*,
int,
const string &,
bool);
262 void CalculateLAMAZLatLon(int32,
int, float64*, float64*,
int*,
int*,
int*,
int,
bool);
265 template <
class T>
void LatLon2DSubset (T* outlatlon,
int ydim,
int xdim, T* latlon, int32 * offset, int32 * count, int32 * step);
269 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);
272 template <
class T >
bool CorLatLon (T * latlon,
int fieldtype,
int elms,
int fv);
275 template <
class T >
void CorSpeLon (T * lon,
int xdim);
279 void getCorrectSubset (
int *offset,
int *count,
int *step, int32 * offset32, int32 * count32, int32 * step32,
bool condenseddim,
bool ydimmajor,
int fieldtype,
int rank);
282 template <
class T >
int findfirstfv (T * array,
int start,
int end,
int fillvalue);
static class NCMLUtil overview