42#include <dods-datatypes.h>
59 if (d_grid->get_array()->dimensions() < 2 || d_grid->get_array()->dimensions() > 3)
60 throw Error(
"The geogrid() function works only with Grids of two or three dimensions.");
63 if (!build_lat_lon_maps())
64 throw Error(
string(
"The grid '") + d_grid->name() +
65 "' does not have identifiable latitude/longitude map vectors.");
67 if (!lat_lon_dimensions_ok())
68 throw Error(
"The geogrid() function will only work when the Grid's Longitude and Latitude maps are the "
69 "rightmost dimensions (grid: " +
70 grid->
name() +
", 1).");
74 : GeoConstraint(), d_grid(grid), d_latitude(0), d_longitude(0) {
75 if (d_grid->get_array()->dimensions() < 2 || d_grid->get_array()->dimensions() > 3)
76 throw Error(
"The geogrid() function works only with Grids of two or three dimensions.");
79 if (!build_lat_lon_maps(lat, lon))
80 throw Error(
string(
"The grid '") + d_grid->name() +
"' does not have valid latitude/longitude map vectors.");
82 if (!lat_lon_dimensions_ok())
83 throw Error(
"The geogrid() function will only work when the Grid's Longitude and Latitude maps are the "
84 "rightmost dimensions (grid: " +
85 grid->
name() +
", 2).");
103bool GridGeoConstraint::build_lat_lon_maps() {
116 while (m != d_grid->
map_end() && (!d_latitude || !d_longitude)) {
117 string units_value = (*m)->get_attr_table().get_attr(
"units");
119 string map_name = (*m)->name();
131 d_latitude =
dynamic_cast<Array *
>(*m);
133 throw InternalErr(__FILE__, __LINE__,
"Expected an array.");
134 if (!d_latitude->
read_p())
146 d_longitude =
dynamic_cast<Array *
>(*m);
148 throw InternalErr(__FILE__, __LINE__,
"Expected an array.");
149 if (!d_longitude->
read_p())
157 if (m + 1 == d_grid->
map_end())
175bool GridGeoConstraint::build_lat_lon_maps(Array *lat, Array *lon) {
180 while (m != d_grid->map_end() && (!d_latitude || !d_longitude)) {
182 if (!d_latitude && *m == lat) {
186 if (!d_latitude->read_p())
195 if (!d_longitude && *m == lon) {
199 if (!d_longitude->read_p())
207 if (m + 1 == d_grid->map_end())
228bool GridGeoConstraint::lat_lon_dimensions_ok() {
233 if (*rightmost == d_longitude && *next_rightmost == d_latitude)
235 else if (*rightmost == d_latitude && *next_rightmost == d_longitude)
267 "The Latitude and Longitude constraints must be set before calling apply_constraint_to_data().");
280 throw Error(
"The upper and lower latitude indices appear to be reversed. Please provide the latitude bounding "
281 "box numbers giving the northern-most latitude first.");
326 fd = d_longitude->dim_begin();
335 DBG(cerr <<
"Inverted latitude sense" << endl);
353 if (*i != d_latitude && *i != d_longitude) {
354 if ((*i)->send_p()) {
355 DBG(cerr <<
"reading grid map: " << (*i)->name() << endl);
368 throw InternalErr(__FILE__, __LINE__,
"Expected data size not copied to the Grid's buffer.");
370 d_grid->set_read_p(
true);
372 d_grid->get_array()->read();
set< string > get_coards_lon_units() const
int get_latitude_index_bottom() const
libdap::Array::Dim_iter get_lon_dim() const
libdap::Array::Dim_iter get_lat_dim() const
int get_array_data_size() const
set< string > get_lat_names() const
virtual void reorder_longitude_map(int longitude_index_left)
virtual void transform_longitude_to_neg_pos_notation()
virtual void reorder_data_longitude_axis(libdap::Array &a, libdap::Array::Dim_iter lon_dim)
void set_lon(double *lon)
void set_lon_dim(libdap::Array::Dim_iter lon)
void set_longitude_rightmost(bool state)
void set_lat(double *lat)
void set_longitude_index_right(int right)
int get_latitude_index_top() const
Notation get_longitude_notation() const
LatitudeSense get_latitude_sense() const
char * get_array_data() const
void set_lat_dim(libdap::Array::Dim_iter lat)
int get_longitude_index_left() const
void set_lat_length(int len)
bool is_bounding_box_set() const
set< string > get_coards_lat_units() const
set< string > get_lon_names() const
void set_latitude_index_top(int top)
virtual void flip_latitude_within_array(libdap::Array &a, int lat_length, int lon_length)
int get_longitude_index_right() const
void set_lon_length(int len)
int get_lon_length() const
void set_latitude_index_bottom(int bottom)
virtual void transpose_vector(double *src, const int length)
void set_longitude_index_left(int left)
GridGeoConstraint(libdap::Grid *grid)
Initialize GeoConstraint with a Grid.
virtual void apply_constraint_to_data()
A multidimensional array of identical data types.
std::vector< dimension >::iterator Dim_iter
virtual bool read()
Read data into a local buffer.
virtual string name() const
Returns the name of the class instance.
virtual bool read_p()
Has this variable been read?
A class for error processing.
Holds the Grid data type.
Map_iter map_begin()
Returns an iterator referencing the first Map vector.
std::vector< BaseType * >::reverse_iterator Map_riter
std::vector< BaseType * >::iterator Map_iter
Array * get_array()
Returns the Grid Array. This method returns the array using an Array*, so no cast is required.
A class for software fault reporting.
int length() const override
Returns the number of elements in the vector. Note that some child classes of Vector use the length o...
bool unit_or_name_match(set< string > units, set< string > names, const string &var_units, const string &var_name)
top level DAP object to house generic methods
string remove_quotes(const string &s)
void set_array_using_double(Array *dest, double *src, int src_len)
double * extract_double_array(Array *a)