32 {
"$Id: GridGeoConstraint.cc 24281 2011-03-09 00:22:31Z jimg $"
62 GridGeoConstraint::GridGeoConstraint(
Grid *grid)
63 :
GeoConstraint(), d_grid(grid), d_latitude(0), d_longitude(0)
67 throw Error(
"The geogrid() function works only with Grids of two or three dimensions.");
70 if (!build_lat_lon_maps())
71 throw Error(
string(
"The grid '") + d_grid->
name()
72 +
"' does not have identifiable latitude/longitude map vectors.");
74 if (!lat_lon_dimensions_ok())
75 throw Error(
"The geogrid() function will only work when the Grid's Longitude and Latitude\nmaps are the rightmost dimensions.");
79 :
GeoConstraint(), d_grid(grid), d_latitude(0), d_longitude(0)
83 throw Error(
"The geogrid() function works only with Grids of two or three dimensions.");
86 if (!build_lat_lon_maps(lat, lon))
87 throw Error(
string(
"The grid '") + d_grid->
name()
88 +
"' does not have valid latitude/longitude map vectors.");
91 if (!lat_lon_dimensions_ok())
92 throw Error(
"The geogrid() function will only work when the Grid's Longitude and Latitude\nmaps are the rightmost dimensions.");
110 bool GridGeoConstraint::build_lat_lon_maps()
122 while (m != d_grid->
map_end() && (!d_latitude || !d_longitude)) {
123 string units_value = (*m)->get_attr_table().get_attr(
"units");
125 string map_name = (*m)->name();
131 units_value, map_name)) {
139 d_latitude = dynamic_cast <
Array * >(*m);
141 throw InternalErr(__FILE__, __LINE__,
"Expected an array.");
142 if (!d_latitude->
read_p())
153 units_value, map_name)) {
155 d_longitude = dynamic_cast < Array * >(*m);
157 throw InternalErr(__FILE__, __LINE__,
"Expected an array.");
158 if (!d_longitude->
read_p())
166 if (m + 1 == d_grid->
map_end())
184 bool GridGeoConstraint::build_lat_lon_maps(Array *lat, Array *lon)
190 while (m != d_grid->
map_end() && (!d_latitude || !d_longitude)) {
192 if (!d_latitude && *m == lat) {
196 if (!d_latitude->
read_p())
205 if (!d_longitude && *m == lon) {
209 if (!d_longitude->
read_p())
217 if (m + 1 == d_grid->
map_end())
239 GridGeoConstraint::lat_lon_dimensions_ok()
245 if (*rightmost == d_longitude && *next_rightmost == d_latitude)
247 else if (*rightmost == d_latitude && *next_rightmost == d_longitude)
279 throw InternalErr(
"The Latitude and Longitude constraints must be set before calling apply_constraint_to_data().");
292 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.");
353 DBG(cerr <<
"Inverted latitude sense" << endl);
372 if (*i != d_latitude && *i != d_longitude) {
373 if ((*i)->send_p()) {
374 DBG(cerr <<
"reading grid map: " << (*i)->name() << endl);
387 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?
char * get_array_data() 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)
virtual void reorder_data_longitude_axis(Array &a, Array::Dim_iter lon_dim)
void set_latitude_index_top(int top)
set< string > get_coards_lat_units() const
virtual int length() const
set< string > get_lon_names() const
void set_longitude_rightmost(bool state)
int get_longitude_index_left() const
Array::Dim_iter get_lon_dim() 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)
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.
void set_array_using_double(Array *dest, double *src, int src_len)
GridGeoConstraint(Grid *grid)
Initialize GeoConstraint with a Grid.
int get_longitude_index_right() const
double * extract_double_array(Array *a)
int get_array_data_size() const
int get_latitude_index_bottom() const
set< string > get_coards_lon_units() const
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. Thrown if called for Structure, Sequence or Grid.
virtual void transform_longitude_to_neg_pos_notation()
LatitudeSense get_latitude_sense() const
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
string name() const
Returns the name of the class instance.
set< string > get_lat_names() const
void set_longitude_index_right(int right)
string remove_quotes(const string &s)
Notation get_longitude_notation() const
virtual void reorder_longitude_map(int longitude_index_left)
int get_lon_length() const
void set_longitude_index_left(int left)
A class for error processing.
Array::Dim_iter get_lat_dim() const
A multidimensional array of identical data types.
bool is_bounding_box_set() const
void set_lon_dim(Array::Dim_iter lon)
int get_latitude_index_top() const
virtual void apply_constraint_to_data()
void set_lon_length(int len)