bes Updated for version 3.20.13
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
38namespace libdap {
39class BaseType;
40class DDS;
41class Array;
42}
43
45
52private:
53 libdap::DDS *_dds;
54 std::string _returnAs;
55 std::string _indent_increment;
56 std::string atomicVals;
57 std::string currDataType;
58 std::string domainType;
59 std::string coordRefType;
60 bool xExists;
61 bool yExists;
62 bool zExists;
63 bool tExists;
64 bool isParam;
65 bool isAxis;
66 bool canConvertToCovJson;
67
68 struct Axis {
69 std::string name;
70 std::string values;
71 };
72
73 struct Parameter {
74 std::string id;
75 std::string name;
76 std::string type;
77 std::string dataType;
78 std::string unit;
79 std::string longName;
80 std::string standardName;
81 std::string shape;
82 std::string values;
83 };
84
85 unsigned int axisCount;
86 std::vector<Axis *> axes;
87 std::string axis_t_units;
88 unsigned int parameterCount;
89 std::vector<Parameter *> parameters;
90 std::vector<int> shapeVals;
91
92#if 0
93 std::string axis_x_varname;
94 std::string axis_y_varname;
95 std::string axis_z_varname;
96 std::string axis_t_varname;
97#endif
98
99 struct axisVar {
100 int dim_size;
101 std::string name;
102 std::string dim_name;
103 std::string bound_name;
104 };
105 axisVar axisVar_x;
106 axisVar axisVar_y;
107 axisVar axisVar_z;
108 axisVar axisVar_t;
109
110 std::vector<float> axisVar_x_bnd_val;
111 std::vector<float> axisVar_y_bnd_val;
112 std::vector<float> axisVar_z_bnd_val;
113 std::vector<double> axisVar_t_bnd_val;
114
115 std::vector<std::string>bnd_dim_names;
116 std::vector<std::string>par_vars;
117
118 bool is_simple_cf_geographic;
119
120 bool check_add_axis(libdap::Array *d_a, const std::string &, const std::vector<std::string> &, axisVar &, bool is_t_axis);
121 void check_bounds(libdap::DDS *dds, std::map<std::string,std::string>& vname_b_name);
122 void obtain_bound_values(libdap::DDS *dds, const axisVar& av, std::vector<float>& av_bnd_val,std::string &bnd_dim_name,bool);
123 void obtain_bound_values(libdap::DDS *dds, const axisVar& av, std::vector<double>& av_bnd_val,std::string &bnd_dim_name,bool);
124 //bool obtain_bound_values_worker(libdap::DDS *dds, libdap::Array *d_a, const std::string & bound_name, std::string &bound_dim_name);
125 libdap::Array * obtain_bound_values_worker(libdap::DDS *dds, const std::string & bound_name, std::string &bound_dim_name);
126
127 bool obtain_valid_vars(libdap::DDS *dds, short axis_var_z_count, short axis_var_t_count);
128 // Current only support the double precision for time.
129 //std::string cf_time_to_greg(double time);
130 std::string cf_time_to_greg(long long time);
131 void print_bound(std::ostream *strm, const std::vector<std::string> & t_bnd_val,const std::string & indent,bool is_t_axis) const;
132
144 bool canConvert();
145
167 void getAttributes(std::ostream *strm, libdap::AttrTable &attr_table, std::string name,
168 bool *axisRetrieved, bool *parameterRetrieved);
169
170 void getAttributes_simple_cf_geographic(std::ostream *strm, libdap::AttrTable &attr_table, std::string name,
171 bool *axisRetrieved, bool *parameterRetrieved);
172
173
182 string sanitizeTimeOriginString(std::string timeOrigin);
183
199 void transform(std::ostream *strm, libdap::DDS *dds, std::string indent, bool sendData, bool testOverride);
200
213 void transform(std::ostream *strm, libdap::BaseType *bt, std::string indent, bool sendData);
214
232 void transform(std::ostream *strm, libdap::Constructor *cnstrctr, std::string indent, bool sendData);
233
244 void transform(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
245
257 void transformAtomic(libdap::BaseType *bt, std::string indent, bool sendData);
258
269 void transformNodeWorker(std::ostream *strm, vector<libdap::BaseType *> leaves, vector<libdap::BaseType *> nodes,
270 string indent, bool sendData);
271
279 void printCoverage(std::ostream *strm, std::string indent);
280
314 void printDomain(std::ostream *strm, std::string indent);
315
330 void printAxes(std::ostream *strm, std::string indent);
331
353 void printReference(std::ostream *strm, std::string indent);
354
386 void printParameters(std::ostream *strm, std::string indent);
387
410 void printRanges(std::ostream *strm, std::string indent);
411
422 void printCoverageJSON(std::ostream *strm, string indent, bool testOverride);
423
441 template<typename T>
442 void covjsonSimpleTypeArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
443
464 void covjsonStringArray(std::ostream *strm, libdap::Array *a, std::string indent, bool sendData);
465
478 template<typename T>
479 unsigned int covjsonSimpleTypeArrayWorker(std::ostream *strm, T *values, unsigned int indx,
480 std::vector<unsigned int> *shape, unsigned int currentDim, bool is_axis_t_sgeo,libdap::Type a_type);
481
490 void addAxis(std::string name, std::string values);
491
507 void addParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
508 std::string longName, std::string standardName, std::string shape, std::string values);
509
510 // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
511 void setAxesExistence(bool x, bool y, bool z, bool t) {
512 this->xExists = x;
513 this->yExists = y;
514 this->zExists = z;
515 this->tExists = t;
516 }
517
518 void setDomainType(int domainType) {
519 this->domainType = domainType;
520 }
521 // ---------------------------------------------------------------------------------------------------------
522
523public:
537 virtual void transform(std::ostream &ostrm, bool sendData, bool testOverride);
538
556 FoDapCovJsonTransform(libdap::DDS *dds);
557
562 {
563 for (std::vector<Axis *>::const_iterator i = axes.begin(); i != axes.end(); ++i)
564 delete (*i);
565
566 for (std::vector<Parameter *>::const_iterator i = parameters.begin(); i != parameters.end(); ++i)
567 delete (*i);
568 }
569
580 virtual void dump(std::ostream &strm) const;
581
582 // FOR TESTING PURPOSES ------------------------------------------------------------------------------------
583 virtual void addTestAxis(std::string name, std::string values) {
584 addAxis(name, values);
585 }
586
587 virtual void addTestParameter(std::string id, std::string name, std::string type, std::string dataType, std::string unit,
588 std::string longName, std::string standardName, std::string shape, std::string values) {
589 addParameter(id, name, type, dataType, unit, longName, standardName, shape, values);
590 }
591
592 virtual void setTestAxesExistence(bool x, bool y, bool z, bool t) {
593 setAxesExistence(x, y, z, t);
594 }
595
596 virtual void setTestDomainType(int domainType) {
597 setDomainType(domainType);
598 }
599
600 virtual void printCoverage(std::ostream &ostrm, std::string indent) {
601 printCoverage(&ostrm, indent);
602 }
603
604 virtual void printDomain(std::ostream &ostrm, std::string indent) {
605 printDomain(&ostrm, indent);
606 }
607
608 virtual void printAxes(std::ostream &ostrm, std::string indent) {
609 printAxes(&ostrm, indent);
610 }
611
612 virtual void printReference(std::ostream &ostrm, std::string indent) {
613 printReference(&ostrm, indent);
614 }
615
616 virtual void printParameters(std::ostream &ostrm, std::string indent) {
617 printParameters(&ostrm, indent);
618 }
619
620 virtual void printRanges(std::ostream &ostrm, std::string indent) {
621 printRanges(&ostrm, indent);
622 }
623 // ---------------------------------------------------------------------------------------------------------
624};
625
626#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
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.