32 {
"$Id: GridGeoConstraint.cc 23447 2010-08-27 19:38:04Z jimg $" 64 GridGeoConstraint::GridGeoConstraint(
Grid *grid)
65 :
GeoConstraint(), d_grid(grid), d_latitude(0), d_longitude(0)
69 throw Error(
"The geogrid() function works only with Grids of two or three dimensions.");
72 if (!build_lat_lon_maps())
73 throw Error(
string(
"The grid '") + d_grid->
name()
74 +
"' does not have identifiable latitude/longitude map vectors.");
76 if (!lat_lon_dimensions_ok())
77 throw Error(
"The geogrid() function will only work when the Grid's Longitude and Latitude\nmaps are the rightmost dimensions.");
81 :
GeoConstraint(), d_grid(grid), d_latitude(0), d_longitude(0)
85 throw Error(
"The geogrid() function works only with Grids of two or three dimensions.");
88 if (!build_lat_lon_maps(lat, lon))
89 throw Error(
string(
"The grid '") + d_grid->
name()
90 +
"' does not have valid latitude/longitude map vectors.");
93 if (!lat_lon_dimensions_ok())
94 throw Error(
"The geogrid() function will only work when the Grid's Longitude and Latitude\nmaps are the rightmost dimensions.");
112 bool GridGeoConstraint::build_lat_lon_maps()
124 while (m != d_grid->
map_end() && (!d_latitude || !d_longitude)) {
125 string units_value = (*m)->get_attr_table().get_attr(
"units");
127 string map_name = (*m)->name();
133 units_value, map_name)) {
141 d_latitude = dynamic_cast <
Array * >(*m);
143 throw InternalErr(__FILE__, __LINE__,
"Expected an array.");
144 if (!d_latitude->
read_p())
155 units_value, map_name)) {
157 d_longitude = dynamic_cast <
Array * >(*m);
159 throw InternalErr(__FILE__, __LINE__,
"Expected an array.");
160 if (!d_longitude->
read_p())
168 if (m + 1 == d_grid->
map_end())
186 bool GridGeoConstraint::build_lat_lon_maps(
Array *lat,
Array *lon)
192 while (m != d_grid->
map_end() && (!d_latitude || !d_longitude)) {
194 if (!d_latitude && *m == lat) {
198 if (!d_latitude->
read_p())
207 if (!d_longitude && *m == lon) {
211 if (!d_longitude->
read_p())
219 if (m + 1 == d_grid->
map_end())
241 GridGeoConstraint::lat_lon_dimensions_ok()
247 if (*rightmost == d_longitude && *next_rightmost == d_latitude)
249 else if (*rightmost == d_latitude && *next_rightmost == d_longitude)
281 throw InternalErr(
"The Latitude and Longitude constraints must be set before calling apply_constraint_to_data().");
294 throw Error(
"The upper and lower latitude indices appear to be reversed. Please provide the latitude bounding box numbers giving the northern-most latitude first.");
355 DBG(cerr <<
"Inverted latitude sense" << endl);
374 if (*i != d_latitude && *i != d_longitude) {
375 if ((*i)->send_p()) {
376 DBG(cerr <<
"reading grid map: " << (*i)->name() << endl);
389 throw InternalErr(__FILE__, __LINE__,
"Expected data size not copied to the Grid's buffer.");
void set_lat_dim(Array::Dim_iter lat)
virtual bool read()
Read data into a local buffer.
virtual void add_constraint(Dim_iter i, int start, int stride, int stop)
Adds a constraint to an Array dimension.
virtual bool read_p()
Has this variable been read?
string name() const
Returns the name of the class instance.
set< string > get_coards_lon_units() const
void set_latitude_index_bottom(int bottom)
virtual unsigned int dimensions(bool constrained=false)
Return the total number of dimensions in the array.
void set_lon(double *lon)
Array::Dim_iter get_lat_dim() const
bool is_bounding_box_set() const
set< string > get_lon_names() const
virtual void reorder_data_longitude_axis(Array &a, Array::Dim_iter lon_dim)
int get_lon_length() const
void set_latitude_index_top(int top)
set< string > get_lat_names() const
void set_longitude_rightmost(bool state)
int get_array_data_size() const
void set_lat(double *lat)
bool unit_or_name_match(set< string > units, set< string > names, const string &var_units, const string &var_name)
void set_lat_length(int len)
int get_latitude_index_bottom() const
int get_longitude_index_left() const
A class for software fault reporting.
virtual void transpose_vector(double *src, const int length)
Map_riter map_rbegin()
Returns an iterator referencing the first Map vector.
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
Notation get_longitude_notation() const
void set_array_using_double(Array *dest, double *src, int src_len)
GridGeoConstraint(Grid *grid)
Initialize GeoConstraint with a Grid.
double * extract_double_array(Array *a)
virtual void flip_latitude_within_array(Array &a, int lat_length, int lon_length)
std::vector< dimension >::iterator Dim_iter
virtual void set_read_p(bool state)
Sets the value of the read_p property.
Holds the Grid data type.
virtual unsigned int val2buf(void *val, bool reuse=false)
Reads data into the Vector buffer.
virtual void transform_longitude_to_neg_pos_notation()
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required...
std::vector< BaseType * >::iterator Map_iter
std::vector< BaseType * >::reverse_iterator Map_riter
LatitudeSense get_latitude_sense() const
void set_longitude_index_right(int right)
string remove_quotes(const string &s)
virtual void reorder_longitude_map(int longitude_index_left)
virtual int length() const
void set_longitude_index_left(int left)
int get_longitude_index_right() const
int get_latitude_index_top() const
A class for error processing.
char * get_array_data() const
A multidimensional array of identical data types.
set< string > get_coards_lat_units() const
void set_lon_dim(Array::Dim_iter lon)
Array::Dim_iter get_lon_dim() const
virtual void apply_constraint_to_data()
void set_lon_length(int len)