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.");