bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
FoDapCovJsonTransform.h
1// -*- mode: c++; c-basic-offset:4 -*-
2//
3// FoDapCovJsonTransform.h
4//
5// This file is part of BES CovJSON File Out Module
6//
7// Copyright (c) 2018 OPeNDAP, Inc.
8// Author: Corey Hemphill <hemphilc@oregonstate.edu>
9// Author: River Hendriksen <hendriri@oregonstate.edu>
10// Author: Riley Rimer <rrimer@oregonstate.edu>
11//
12// Adapted from the File Out JSON module implemented by Nathan Potter
13//
14// This library is free software; you can redistribute it and/or
15// modify it under the terms of the GNU Lesser General Public
16// License as published by the Free Software Foundation; either
17// version 2.1 of the License, or (at your option) any later version.
18//
19// This library is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22// Lesser General Public License for more details.
23//
24// You should have received a copy of the GNU Lesser General Public
25// License along with this library; if not, write to the Free Software
26// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27//
28
29#ifndef FODAPNJSONTRANSFORM_H_
30#define FODAPNJSONTRANSFORM_H_
31
32#include <string>
33#include <vector>
34#include <map>
35
36#include <BESObj.h>
37
38enum DSGType {
39 UNSUPPORTED_DSG,SPOINT,POINTS,PROFILE
40};
41namespace libdap {
42class BaseType;
43class DDS;
44class DMR;
45class D4Group;
46class Array;
47}
48
50
57private:
58 libdap::DDS *_dds;
59 libdap::DMR *_dmr;
60 std::string _returnAs;
61 std::string _indent_increment = " ";
62 std::string atomicVals;
63 std::string currDataType;
64 std::string domainType = "Unknown";
65 std::string coordRefType = "GeographicCRS";
66 bool xExists = false;
67 bool yExists = false;
68 bool zExists = false;
69 bool tExists = false;
70 bool isParam = false;
71 bool isAxis = false;
72 bool canConvertToCovJson = false;
73
74 struct Axis {
75 std::string name;
76 std::string values;
77 };
78
79 struct Parameter {
80 std::string id;
81 std::string name;
82 std::string type;
83 std::string dataType;
84 std::string unit;
85 std::string longName;
86 std::string standardName;
87 std::string shape;
88 std::string values;
89 };
90
91 unsigned int axisCount = 0;
92 std::vector<Axis *> axes;
93 std::string axis_t_units;
94 std::string axis_z_units;
95 std::string axis_z_direction;
96 std::string axis_z_standardName;
97
98 unsigned int parameterCount = 0;
99 std::vector<Parameter *> parameters;
100 std::vector<int> shapeVals;
101
102#if 0
103 std::string axis_x_varname;
104 std::string axis_y_varname;
105 std::string axis_z_varname;
106 std::string axis_t_varname;
107#endif
108
109 struct axisVar {
110 int dim_size;
111 std::string name;
112 std::string dim_name;
113 std::string bound_name;
114 };
115 axisVar axisVar_x;
116 axisVar axisVar_y;
117 axisVar axisVar_z;
118 axisVar axisVar_t;
119
120 std::vector<float> axisVar_x_bnd_val;
121 std::vector<float> axisVar_y_bnd_val;
122 std::vector<float> axisVar_z_bnd_val;
123 std::vector<double> axisVar_t_bnd_val;
124
125 std::vector<std::string>bnd_dim_names;
126 std::vector<std::string>par_vars;
127
128 bool is_simple_cf_geographic = false;
129 bool is_dap2_grid = false;
130 bool is_geo_dap2_grid = false;
131
132 // Discrete Sampling Geometries
133 DSGType dsg_type = UNSUPPORTED_DSG;
134
135 // TODO: add more error messages.
136#if 0
137 std::string err_msg;
138 bool err_msg_set = false;
139#endif
140
141 bool is_cf_grid_mapping_var(libdap::BaseType *v) const;
142
143 bool is_supported_vars_by_type(libdap::BaseType*v) const;
144 void handle_axisVars_array(libdap::BaseType*v,axisVar & this_axisVar) ;
145 void set_axisVar(libdap::BaseType*v,const string &val);
146 bool is_simple_dsg(DSGType dsg);
147 bool is_simple_dsg_common() const;
148 DSGType is_single_point () const;
149 DSGType is_point_series () const;
150 DSGType is_single_profile () const;
151 bool is_valid_single_point_par_var(libdap::BaseType*) const;
152 bool is_fake_coor_vars(libdap::Array*) const;
153 bool is_valid_array_dsg_par_var(libdap::Array*) const;
154 bool is_valid_dsg_par_var(libdap::BaseType *);
155 bool obtain_valid_dsg_par_vars(libdap::DDS *);
156 bool check_update_simple_dsg(libdap::DDS *);
157
158 void check_update_simple_geo(libdap::DDS *dds,bool sendData);
159 void check_update_simple_geo_dap4(libdap::D4Group *d4g);
160 bool check_add_axis(libdap::Array *d_a, const std::string &, const std::vector<std::string> &, axisVar &, bool is_t_axis);
161 void check_bounds(libdap::DDS *dds, std::map<std::string,std::string>& vname_b_name);
162 void obtain_bound_values(libdap::DDS *dds, const axisVar& av, std::vector<float>& av_bnd_val,std::string &bnd_dim_name,bool);
163 void obtain_bound_values(libdap::DDS *dds, const axisVar& av, std::vector<double>& av_bnd_val,std::string &bnd_dim_name,bool);
164 libdap::Array * obtain_bound_values_worker(libdap::DDS *dds, const std::string & bound_name, std::string &bound_dim_name);
165
166
167 bool obtain_valid_vars(libdap::DDS *dds, short axis_var_z_count, short axis_var_t_count);
168 bool obtain_valid_vars_dap4(libdap::D4Group *d4g, short axis_var_z_count, short axis_var_t_count);
169
170 // Convert CF time to gregorian calendar.
171 std::string cf_time_to_greg(long long time);
172 void print_bound(std::ostream *strm, const std::vector<std::string> & t_bnd_val,const std::string & indent,bool is_t_axis) const;
173
174 // Check DAP2 CF units
175 bool check_geo_dap2_grid(libdap::DDS *dds, const vector<string> & dap2_grid_map_names) const;
176 short check_cf_unit_attr(libdap::Array *d_a) const;
188 // Note we add more accurate checks to see whether covjson can be supported prior to this function.
189 // Currently this function serves as a wrapper of these checks.
190 bool canConvert();
191
213 void getAttributes(std::ostream *strm, libdap::AttrTable &attr_table, std::string name,
214 bool *axisRetrieved, bool *parameterRetrieved);
215
216 // Different types need to be handled differently. Eventually the getAttributes() listed above becomes
217 // the wrapper of the functions declared below.
218 void getAttributes_simple_cf_geographic_dsg(std::ostream *strm, libdap::AttrTable &attr_table, const std::string& name,
219 bool *axisRetrieved, bool *parameterRetrieved);
220
221
222
231 // TODO: this function is not necessary. May be removed.
232 string sanitizeTimeOriginString(std::string timeOrigin);
233
249 void transform(std::ostream *strm, libdap::DDS *dds, std::string indent, bool sendData, bool testOverride);
250
251 void transform(std::ostream *strm, libdap::DMR *dmr, const std::string& indent, bool sendData, bool testOverride);
252
265 void transform(std::ostream *strm, libdap::BaseType *bt, std::string indent, bool sendData);
266
284 void transform(std::ostream *strm, libdap::Constructor *cnstrctr, std::string indent, bool sendData);
285
296 void transform(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
297
309 void transformAtomic(ostream *strm, libdap::BaseType *bt, const std::string& indent, bool sendData);
310#if 0
311 //void transformAtomic(libdap::BaseType *bt, std::string indent, bool sendData);
312#endif
313
324 void transformNodeWorker(std::ostream *strm, vector<libdap::BaseType *> leaves, vector<libdap::BaseType *> nodes,
325 string indent, bool sendData);
326
334 void printCoverage(std::ostream *strm, std::string indent);
335
369 void printDomain(std::ostream *strm, std::string indent);
370
385 void printAxes(std::ostream *strm, std::string indent);
386
408 void printReference(std::ostream *strm, std::string indent);
409
441 void printParameters(std::ostream *strm, std::string indent);
442
465 void printRanges(std::ostream *strm, std::string indent);
466
477 void printCoverageJSON(std::ostream *strm, string indent, bool testOverride);
478
496 template<typename T>
497 void covjsonSimpleTypeArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
498
519 void covjsonStringArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
520
533 template<typename T>
534 unsigned int covjsonSimpleTypeArrayWorker(std::ostream *strm, T *values, unsigned int indx,
535 std::vector<unsigned int> *shape, unsigned int currentDim, bool is_axis_t_sgeo,libdap::Type a_type);
536
545 void addAxis(std::string name, std::string values);
546
562 void addParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
563 std::string longName, std::string standardName, std::string shape, std::string values);
564
565 // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
566 void setAxesExistence(bool x, bool y, bool z, bool t) {
567 this->xExists = x;
568 this->yExists = y;
569 this->zExists = z;
570 this->tExists = t;
571 }
572
573 void setDomainType(int domainType) {
574 this->domainType = domainType;
575 }
576 // ---------------------------------------------------------------------------------------------------------
577
578public:
592 virtual void transform(std::ostream &ostrm, bool sendData, bool testOverride);
593 virtual void transform_dap4(std::ostream &ostrm, bool sendData, bool testOverride);
594
612 explicit FoDapCovJsonTransform(libdap::DDS *dds);
613 explicit FoDapCovJsonTransform(libdap::DMR *dmr);
614
619 {
620 for (std::vector<Axis *>::const_iterator i = axes.begin(); i != axes.end(); ++i)
621 delete (*i);
622
623 for (std::vector<Parameter *>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
624 delete (*i);
625 }
626
637 virtual void dump(std::ostream &strm) const;
638
639 // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
640 virtual void addTestAxis(std::string name, std::string values) {
641 addAxis(name, values);
642 }
643
644 virtual void addTestParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
645 std::string longName, std::string standardName, std::string shape, std::string values) {
646 addParameter(id, name, type, dataType, unit, longName, standardName, shape, values);
647 }
648
649 virtual void setTestAxesExistence(bool x, bool y, bool z, bool t) {
650 setAxesExistence(x, y, z, t);
651 }
652
653 virtual void setTestDomainType(int domainType) {
654 setDomainType(domainType);
655 }
656
657 virtual void printCoverage(std::ostream &ostrm, std::string indent) {
658 printCoverage(&ostrm, indent);
659 }
660
661 virtual void printDomain(std::ostream &ostrm, std::string indent) {
662 printDomain(&ostrm, indent);
663 }
664
665 virtual void printAxes(std::ostream &ostrm, std::string indent) {
666 printAxes(&ostrm, indent);
667 }
668
669 virtual void printReference(std::ostream &ostrm, std::string indent) {
670 printReference(&ostrm, indent);
671 }
672
673 virtual void printParameters(std::ostream &ostrm, std::string indent) {
674 printParameters(&ostrm, indent);
675 }
676
677 virtual void printRanges(std::ostream &ostrm, std::string indent) {
678 printRanges(&ostrm, indent);
679 }
680 // ---------------------------------------------------------------------------------------------------------
681};
682
683#endif /* FODAPCOVJSONTRANSFORM_H_ */
Structure storing information used by the BES to handle the request.
top level BES object to house generic methods
Definition BESObj.h:54
FoDapCovJsonTransform(libdap::DDS *dds)
Get the CovJSON encoding for a DDS.
virtual void dump(std::ostream &strm) const
Dumps information about this transformation object for debugging purposes.
virtual void transform(std::ostream &ostrm, bool sendData, bool testOverride)
Transforms each of the marked variables of the DDS to CovJSON.
virtual ~FoDapCovJsonTransform()
Destructs the FoDapCovJsonTransform object and frees all memory.
STL class.
STL class.