44 using std::ostringstream;
45 using std::istringstream;
47 #include <libdap/DDS.h>
48 #include <libdap/Structure.h>
49 #include <libdap/Constructor.h>
50 #include <libdap/Array.h>
51 #include <libdap/Grid.h>
52 #include <libdap/Sequence.h>
53 #include <libdap/Float64.h>
54 #include <libdap/Str.h>
55 #include <libdap/Url.h>
58 #include <BESInternalError.h>
59 #include <DapFunctionUtils.h>
60 #include "FoDapCovJsonTransform.h"
61 #include "focovjson_utils.h"
63 #define FoDapCovJsonTransform_debug_key "focovjson"
66 bool FoDapCovJsonTransform::canConvert()
74 if(xExists && yExists && zExists && tExists) {
76 if (shapeVals.size() < 4)
81 if((shapeVals[0] > 1) && (shapeVals[1] > 1) && (shapeVals[2] >= 1) && (shapeVals[3] >= 0)) {
88 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] >= 1) && ((shapeVals[3] <= 1) && (shapeVals[3] >= 0))) {
89 domainType =
"Vertical Profile";
97 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1) && (shapeVals[3] >= 0)) {
98 domainType =
"Point Series";
104 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1) && (shapeVals[3] == 1)) {
105 domainType =
"Point";
115 else if(xExists && yExists && !zExists && tExists) {
117 if (shapeVals.size() < 3)
122 if((shapeVals[0] > 1) && (shapeVals[1] > 1) && (shapeVals[2] >= 0)) {
131 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] >= 0)) {
132 domainType =
"Point Series";
138 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1)) {
139 domainType =
"Point";
148 else if(xExists && yExists && !zExists && !tExists) {
150 if (shapeVals.size() < 2)
155 if((shapeVals[0] > 1) && (shapeVals[1] > 1)) {
162 else if((shapeVals[0] == 1) && (shapeVals[1] == 1)) {
163 domainType =
"Point";
172 unsigned int FoDapCovJsonTransform::covjsonSimpleTypeArrayWorker(ostream *strm, T *values,
unsigned int indx,
173 vector<unsigned int> *shape,
unsigned int currentDim)
175 unsigned int currentDimSize = (*shape)[currentDim];
181 for(
unsigned int i = 0; i < currentDimSize; i++) {
182 if(currentDim < shape->size() - 1) {
183 BESDEBUG(FoDapCovJsonTransform_debug_key,
184 "covjsonSimpleTypeArrayWorker() - Recursing! indx: " << indx <<
" currentDim: " << currentDim <<
" currentDimSize: " << currentDimSize << endl);
185 indx = covjsonSimpleTypeArrayWorker<T>(strm, values, indx, shape, currentDim + 1);
186 if(i + 1 != currentDimSize) {
194 if(
typeid(T) ==
typeid(
string)) {
196 string val =
reinterpret_cast<string*
>(values)[indx++];
197 *strm <<
"\"" << focovjson::escape_for_covjson(val) <<
"\"";
200 *strm << values[indx++];
209 void FoDapCovJsonTransform::covjsonSimpleTypeArray(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
211 string childindent = indent + _indent_increment;
212 bool axisRetrieved =
false;
213 bool parameterRetrieved =
false;
215 currDataType = a->var()->type_name();
220 getAttributes(strm, a->get_attr_table(), a->name(), &axisRetrieved, ¶meterRetrieved);
227 if((axisRetrieved ==
true) && (parameterRetrieved ==
false)) {
228 struct Axis *currAxis;
229 currAxis = axes[axisCount - 1];
231 int numDim = a->dimensions(
true);
232 vector<unsigned int> shape(numDim);
233 long length = focovjson::computeConstrainedShape(a, &shape);
239 if (currAxis->name.compare(
"t") != 0) {
241 currAxis->values +=
"\"values\": [";
242 unsigned int indx = 0;
243 vector<T> src(length);
247 indx = covjsonSimpleTypeArrayWorker(&astrm, &src[0], 0, &shape, 0);
248 currAxis->values += astrm.str();
250 currAxis->values +=
"]";
252 if (length != indx) {
253 BESDEBUG(FoDapCovJsonTransform_debug_key,
254 "covjsonSimpleTypeArray(Axis) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
256 assert(length == indx);
259 currAxis->values +=
"\"values\": []";
265 else if(axisRetrieved ==
false && parameterRetrieved ==
true) {
266 struct Parameter *currParameter;
267 currParameter = parameters[parameterCount - 1];
269 int numDim = a->dimensions(
true);
270 vector<unsigned int> shape(numDim);
271 long length = focovjson::computeConstrainedShape(a, &shape);
277 currParameter->shape +=
"\"shape\": [";
278 for(vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
280 currParameter->shape +=
", ";
289 istringstream (otemp.str());
290 istringstream (otemp.str()) >> tempVal;
291 shapeVals.push_back(tempVal);
295 if((i == 0) && tExists) {
296 currParameter->shape +=
"1";
299 currParameter->shape += otemp.str();
302 currParameter->shape +=
"],";
305 currParameter->values +=
"\"values\": [";
306 unsigned int indx = 0;
307 vector<T> src(length);
311 indx = covjsonSimpleTypeArrayWorker(&pstrm, &src[0], 0, &shape, 0);
312 currParameter->values += pstrm.str();
314 currParameter->values +=
"]";
316 if (length != indx) {
317 BESDEBUG(FoDapCovJsonTransform_debug_key,
318 "covjsonSimpleTypeArray(Parameter) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
320 assert(length == indx);
323 currParameter->values +=
"\"values\": []";
328 void FoDapCovJsonTransform::covjsonStringArray(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
330 string childindent = indent + _indent_increment;
331 bool axisRetrieved =
false;
332 bool parameterRetrieved =
false;
334 currDataType = a->var()->type_name();
342 getAttributes(strm, a->get_attr_table(), a->name(), &axisRetrieved, ¶meterRetrieved);
349 if((axisRetrieved ==
true) && (parameterRetrieved ==
false)) {
350 struct Axis *currAxis;
351 currAxis = axes[axisCount - 1];
353 int numDim = a->dimensions(
true);
354 vector<unsigned int> shape(numDim);
355 long length = focovjson::computeConstrainedShape(a, &shape);
357 if (currAxis->name.compare(
"t") != 0) {
359 currAxis->values +=
"\"values\": ";
360 unsigned int indx = 0;
362 vector<string> sourceValues;
363 a->value(sourceValues);
366 indx = covjsonSimpleTypeArrayWorker(&astrm, (
string *) (&sourceValues[0]), 0, &shape, 0);
367 currAxis->values += astrm.str();
369 if (length != indx) {
370 BESDEBUG(FoDapCovJsonTransform_debug_key,
371 "covjsonStringArray(Axis) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
373 assert(length == indx);
376 currAxis->values +=
"\"values\": []";
382 else if(axisRetrieved ==
false && parameterRetrieved ==
true) {
383 struct Parameter *currParameter;
384 currParameter = parameters[parameterCount - 1];
386 int numDim = a->dimensions(
true);
387 vector<unsigned int> shape(numDim);
388 long length = focovjson::computeConstrainedShape(a, &shape);
390 currParameter->shape +=
"\"shape\": [";
391 for(vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
393 currParameter->shape +=
", ";
402 istringstream (otemp.str());
403 istringstream (otemp.str()) >> tempVal;
404 shapeVals.push_back(tempVal);
408 if((i == 0) && tExists) {
409 currParameter->shape +=
"1";
412 currParameter->shape += otemp.str();
415 currParameter->shape +=
"],";
418 currParameter->values +=
"\"values\": ";
419 unsigned int indx = 0;
421 vector<string> sourceValues;
422 a->value(sourceValues);
425 indx = covjsonSimpleTypeArrayWorker(&pstrm, (
string *) (&sourceValues[0]), 0, &shape, 0);
426 currParameter->values += pstrm.str();
428 if (length != indx) {
429 BESDEBUG(FoDapCovJsonTransform_debug_key,
430 "covjsonStringArray(Parameter) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
432 assert(length == indx);
435 currParameter->values +=
"\"values\": []";
440 void FoDapCovJsonTransform::addAxis(
string name,
string values)
442 struct Axis *newAxis =
new Axis;
444 newAxis->name = name;
445 newAxis->values = values;
447 this->axes.push_back(newAxis);
451 void FoDapCovJsonTransform::addParameter(
string id,
string name,
string type,
string dataType,
string unit,
452 string longName,
string standardName,
string shape,
string values)
454 struct Parameter *newParameter =
new Parameter;
456 newParameter->id = id;
457 newParameter->name = name;
458 newParameter->type = type;
459 newParameter->dataType = dataType;
460 newParameter->unit = unit;
461 newParameter->longName = longName;
462 newParameter->standardName = standardName;
463 newParameter->shape = shape;
464 newParameter->values = values;
466 this->parameters.push_back(newParameter);
467 this->parameterCount++;
470 void FoDapCovJsonTransform::getAttributes(ostream *strm, libdap::AttrTable &attr_table,
string name,
471 bool *axisRetrieved,
bool *parameterRetrieved)
474 string currAxisTimeOrigin;
477 string currStandardName;
482 *axisRetrieved =
false;
483 *parameterRetrieved =
false;
490 if((name.compare(
"lon") == 0) || (name.compare(
"LON") == 0)
491 || (name.compare(
"longitude") == 0) || (name.compare(
"LONGITUDE") == 0)
492 || (name.compare(
"COADSX") == 0)) {
503 else if((name.compare(
"lat") == 0) || (name.compare(
"LAT") == 0)
504 || (name.compare(
"latitude") == 0) || (name.compare(
"LATITUDE") == 0)
505 || (name.compare(
"COADSY") == 0)) {
516 else if((name.compare(
"lev") == 0) || (name.compare(
"LEV") == 0)
517 || (name.compare(
"height") == 0) || (name.compare(
"HEIGHT") == 0)
518 || (name.compare(
"depth") == 0) || (name.compare(
"DEPTH") == 0)
519 || (name.compare(
"pres") == 0) || (name.compare(
"PRES") == 0)) {
530 else if((name.compare(
"time") == 0) || (name.compare(
"TIME") == 0)) {
546 if(attr_table.get_size() != 0) {
547 libdap::AttrTable::Attr_iter begin = attr_table.attr_begin();
548 libdap::AttrTable::Attr_iter end = attr_table.attr_end();
550 for(libdap::AttrTable::Attr_iter at_iter = begin; at_iter != end; at_iter++) {
554 switch (attr_table.get_attr_type(at_iter)) {
555 case libdap::Attr_container: {
556 libdap::AttrTable *atbl = attr_table.get_attr_table(at_iter);
558 getAttributes(strm, *atbl, name, axisRetrieved, parameterRetrieved);
562 vector<string> *values = attr_table.get_attr_vector(at_iter);
564 for(vector<string>::size_type i = 0; i < values->size(); i++) {
565 string currName = attr_table.get_name(at_iter);
566 string currValue = (*values)[i];
585 if(currName.compare(
"units") == 0) {
586 currUnit = currValue;
589 if(currAxisName.compare(
"t") == 0) {
590 currAxisTimeOrigin = currValue;
601 else if(currName.compare(
"long_name") == 0) {
602 currLongName = currValue;
605 else if(currName.compare(
"standard_name") == 0) {
606 currStandardName = currValue;
620 if(currAxisName.compare(
"t") == 0) {
621 addAxis(currAxisName,
"\"values\": [\"" + sanitizeTimeOriginString(currAxisTimeOrigin) +
"\"]");
624 addAxis(currAxisName,
"");
628 if((currUnit.find(
"east") != string::npos) || (currUnit.find(
"East") != string::npos) ||
629 (currUnit.find(
"north") != string::npos) || (currUnit.find(
"North") != string::npos)) {
630 coordRefType =
"ProjectedCRS";
633 *axisRetrieved =
true;
636 addParameter(
"", name,
"", currDataType, currUnit, currLongName, currStandardName,
"",
"");
637 *parameterRetrieved =
true;
644 string FoDapCovJsonTransform::sanitizeTimeOriginString(
string timeOrigin)
664 vector<string> subStrs = {
"hours",
"hour",
"minutes",
"minute",
665 "seconds",
"second",
"since",
" " };
667 string cleanTimeOrigin = timeOrigin;
670 if(timeOrigin.find(
"base_time") != string::npos) {
671 cleanTimeOrigin =
"2020-01-01T12:00:00Z";
674 for(
unsigned int i = 0; i < subStrs.size(); i++)
675 focovjson::removeSubstring(cleanTimeOrigin, subStrs[i]);
678 return cleanTimeOrigin;
682 _dds(dds), _returnAs(
""), _indent_increment(
" "), atomicVals(
""), currDataType(
""), domainType(
"Unknown"),
683 coordRefType(
"GeographicCRS"), xExists(false), yExists(false), zExists(false), tExists(false), isParam(false),
684 isAxis(false), canConvertToCovJson(false), axisCount(0), parameterCount(0)
686 if (!_dds)
throw BESInternalError(
"File out COVJSON, null DDS passed to constructor", __FILE__, __LINE__);
691 strm << BESIndent::LMarg <<
"FoDapCovJsonTransform::dump - (" << (
void *)
this <<
")" << endl;
696 BESIndent::UnIndent();
699 void FoDapCovJsonTransform::transform(ostream &ostrm,
bool sendData,
bool testOverride)
701 transform(&ostrm, _dds,
"", sendData, testOverride);
704 void FoDapCovJsonTransform::transform(ostream *strm, libdap::Constructor *cnstrctr,
string indent,
bool sendData)
706 vector<libdap::BaseType *> leaves;
707 vector<libdap::BaseType *> nodes;
709 libdap::DDS::Vars_iter vi = cnstrctr->var_begin();
710 libdap::DDS::Vars_iter ve = cnstrctr->var_end();
712 for(; vi != ve; vi++) {
713 if((*vi)->send_p()) {
714 libdap::BaseType *v = *vi;
717 if(type == libdap::dods_array_c) {
718 type = v->var()->type();
720 if(v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
729 transformNodeWorker(strm, leaves, nodes, indent, sendData);
732 void FoDapCovJsonTransform::transformNodeWorker(ostream *strm, vector<libdap::BaseType *> leaves,
733 vector<libdap::BaseType *> nodes,
string indent,
bool sendData)
736 for(vector<libdap::BaseType *>::size_type l = 0; l < leaves.size(); l++) {
737 libdap::BaseType *v = leaves[l];
738 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Processing LEAF: " << v->name() << endl);
743 transform(strm, v, indent + _indent_increment, sendData);
747 for(vector<libdap::BaseType *>::size_type n = 0; n < nodes.size(); n++) {
748 libdap::BaseType *v = nodes[n];
749 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Processing NODE: " << v->name() << endl);
754 transform(strm, v, indent + _indent_increment, sendData);
758 void FoDapCovJsonTransform::printCoverageJSON(ostream *strm,
string indent,
bool testOverride)
764 canConvertToCovJson =
true;
767 canConvertToCovJson = canConvert();
771 if(canConvertToCovJson) {
773 printCoverage(strm, indent);
777 throw BESInternalError(
"File cannot be converted to CovJSON format due to missing or incompatible spatial dimensions", __FILE__, __LINE__);
781 void FoDapCovJsonTransform::printCoverage(ostream *strm,
string indent)
783 string child_indent1 = indent + _indent_increment;
784 string child_indent2 = child_indent1 + _indent_increment;
786 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing COVERAGE" << endl);
788 *strm << indent <<
"{" << endl;
789 *strm << child_indent1 <<
"\"type\": \"Coverage\"," << endl;
791 printDomain(strm, child_indent1);
793 printParameters(strm, child_indent1);
795 printRanges(strm, child_indent1);
797 *strm << indent <<
"}" << endl;
800 void FoDapCovJsonTransform::printDomain(ostream *strm,
string indent)
802 string child_indent1 = indent + _indent_increment;
804 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing DOMAIN" << endl);
806 *strm << indent <<
"\"domain\": {" << endl;
807 *strm << child_indent1 <<
"\"type\" : \"Domain\"," << endl;
808 *strm << child_indent1 <<
"\"domainType\": \"" + domainType +
"\"," << endl;
811 printAxes(strm, child_indent1);
814 printReference(strm, child_indent1);
816 *strm << indent <<
"}," << endl;
819 void FoDapCovJsonTransform::printAxes(ostream *strm,
string indent)
821 string child_indent1 = indent + _indent_increment;
822 string child_indent2 = child_indent1 + _indent_increment;
824 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing AXES" << endl);
830 *strm << indent <<
"\"axes\": {" << endl;
831 for(
unsigned int i = 0; i < axisCount; i++) {
832 for(
unsigned int j = 0; j < axisCount; j++) {
836 if(xExists && yExists && zExists && tExists) {
837 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
838 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
839 *strm << child_indent2 << axes[j]->values << endl;
841 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
842 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
843 *strm << child_indent2 << axes[j]->values << endl;
845 else if((i == 2) && (axes[j]->name.compare(
"z") == 0)) {
846 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
847 *strm << child_indent2 << axes[j]->values << endl;
849 else if((i == 3) && (axes[j]->name.compare(
"t") == 0)) {
850 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
851 *strm << child_indent2 << axes[j]->values << endl;
855 else if(xExists && yExists && !zExists && tExists) {
856 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
857 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
858 *strm << child_indent2 << axes[j]->values << endl;
860 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
861 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
862 *strm << child_indent2 << axes[j]->values << endl;
864 else if((i == 2) && (axes[j]->name.compare(
"t") == 0)) {
865 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
866 *strm << child_indent2 << axes[j]->values << endl;
870 else if(xExists && yExists && !zExists && !tExists) {
871 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
872 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
873 *strm << child_indent2 << axes[j]->values << endl;
875 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
876 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
877 *strm << child_indent2 << axes[j]->values << endl;
881 if(i == axisCount - 1) {
882 *strm << child_indent1 <<
"}" << endl;
885 *strm << child_indent1 <<
"}," << endl;
888 *strm << indent <<
"}," << endl;
891 void FoDapCovJsonTransform::printReference(ostream *strm,
string indent)
893 string child_indent1 = indent + _indent_increment;
894 string child_indent2 = child_indent1 + _indent_increment;
897 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing REFERENCES" << endl);
900 coordVars +=
"\"x\"";
904 if(coordVars.length() > 0) {
907 coordVars +=
"\"y\"";
911 if(coordVars.length() > 0) {
914 coordVars +=
"\"z\"";
917 *strm << indent <<
"\"referencing\": [{" << endl;
921 *strm << child_indent1 <<
"\"coordinates\": [\"t\"]," << endl;
922 *strm << child_indent1 <<
"\"system\": {" << endl;
923 *strm << child_indent2 <<
"\"type\": \"TemporalRS\"," << endl;
924 *strm << child_indent2 <<
"\"calendar\": \"Gregorian\"" << endl;
925 *strm << child_indent1 <<
"}" << endl;
926 *strm << indent <<
"}," << endl;
927 *strm << indent <<
"{" << endl;
931 *strm << child_indent1 <<
"\"coordinates\": [" << coordVars <<
"]," << endl;
932 *strm << child_indent1 <<
"\"system\": {" << endl;
933 *strm << child_indent2 <<
"\"type\": \"" + coordRefType +
"\"," << endl;
937 if(coordRefType.compare(
"ProjectedCRS") == 0) {
939 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/EPSG/0/27700\"" << endl;
942 if(xExists && yExists && zExists) {
944 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/EPSG/0/4979\"" << endl;
948 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/OGC/1.3/CRS84\"" << endl;
952 *strm << child_indent1 <<
"}" << endl;
953 *strm << indent <<
"}]" << endl;
956 void FoDapCovJsonTransform::printParameters(ostream *strm,
string indent)
958 string child_indent1 = indent + _indent_increment;
959 string child_indent2 = child_indent1 + _indent_increment;
960 string child_indent3 = child_indent2 + _indent_increment;
961 string child_indent4 = child_indent3 + _indent_increment;
963 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing PARAMETERS" << endl);
966 *strm << indent <<
"\"parameters\": {" << endl;
967 for(
unsigned int i = 0; i < parameterCount; i++) {
968 *strm << child_indent1 <<
"\"" << parameters[i]->name <<
"\": {" << endl;
969 *strm << child_indent2 <<
"\"type\": \"Parameter\"," << endl;
970 *strm << child_indent2 <<
"\"description\": {" << endl;
972 if(parameters[i]->longName.compare(
"") != 0) {
973 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->longName <<
"\"" << endl;
975 else if(parameters[i]->standardName.compare(
"") != 0) {
976 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->standardName <<
"\"" << endl;
979 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->name <<
"\"" << endl;
982 *strm << child_indent2 <<
"}," << endl;
983 *strm << child_indent2 <<
"\"unit\": {" << endl;
984 *strm << child_indent3 <<
"\"label\": {" << endl;
985 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->unit <<
"\"" << endl;
986 *strm << child_indent3 <<
"}," << endl;
987 *strm << child_indent3 <<
"\"symbol\": {" << endl;
988 *strm << child_indent4 <<
"\"value\": \"" << parameters[i]->unit <<
"\"," << endl;
989 *strm << child_indent4 <<
"\"type\": \"http://www.opengis.net/def/uom/UCUM/\"" << endl;
990 *strm << child_indent3 <<
"}" << endl;
991 *strm << child_indent2 <<
"}," << endl;
992 *strm << child_indent2 <<
"\"observedProperty\": {" << endl;
998 if(parameters[i]->standardName.compare(
"") != 0) {
999 *strm << child_indent3 <<
"\"id\": \"http://vocab.nerc.ac.uk/standard_name/" << parameters[i]->standardName <<
"/\"," << endl;
1007 *strm << child_indent3 <<
"\"label\": {" << endl;
1009 if(parameters[i]->longName.compare(
"") != 0) {
1010 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->longName <<
"\"" << endl;
1012 else if(parameters[i]->standardName.compare(
"") != 0) {
1013 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->standardName <<
"\"" << endl;
1016 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->name <<
"\"" << endl;
1019 *strm << child_indent3 <<
"}" << endl;
1020 *strm << child_indent2 <<
"}" << endl;
1022 if(i == parameterCount - 1) {
1023 *strm << child_indent1 <<
"}" << endl;
1026 *strm << child_indent1 <<
"}," << endl;
1030 *strm << indent <<
"}," << endl;
1033 void FoDapCovJsonTransform::printRanges(ostream *strm,
string indent)
1035 string child_indent1 = indent + _indent_increment;
1036 string child_indent2 = child_indent1 + _indent_increment;
1037 string child_indent3 = child_indent2 + _indent_increment;
1040 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing RANGES" << endl);
1043 axisNames +=
"\"t\"";
1047 if(axisNames.length() > 0) {
1050 axisNames +=
"\"z\"";
1054 if(axisNames.length() > 0) {
1057 axisNames +=
"\"y\"";
1061 if(axisNames.length() > 0) {
1064 axisNames +=
"\"x\"";
1068 *strm << indent <<
"\"ranges\": {" << endl;
1069 for(
unsigned int i = 0; i < parameterCount; i++) {
1072 if(parameters[i]->dataType.find(
"int") == 0 || parameters[i]->dataType.find(
"Int") == 0
1073 || parameters[i]->dataType.find(
"integer") == 0 || parameters[i]->dataType.find(
"Integer") == 0) {
1074 dataType =
"integer";
1076 else if(parameters[i]->dataType.find(
"float") == 0 || parameters[i]->dataType.find(
"Float") == 0) {
1079 else if(parameters[i]->dataType.find(
"string") == 0 || parameters[i]->dataType.find(
"String") == 0) {
1080 dataType =
"string";
1083 dataType =
"string";
1088 *strm << child_indent1 <<
"\"" << parameters[i]->name <<
"\": {" << endl;
1089 *strm << child_indent2 <<
"\"type\": \"NdArray\"," << endl;
1090 *strm << child_indent2 <<
"\"dataType\": \"" << dataType <<
"\", " << endl;
1091 *strm << child_indent2 <<
"\"axisNames\": [" << axisNames <<
"]," << endl;
1092 *strm << child_indent2 << parameters[i]->shape << endl;
1093 *strm << child_indent2 << parameters[i]->values << endl;
1095 if(i == parameterCount - 1) {
1096 *strm << child_indent1 <<
"}" << endl;
1099 *strm << child_indent1 <<
"}," << endl;
1103 *strm << indent <<
"}" << endl;
1106 void FoDapCovJsonTransform::transform(ostream *strm, libdap::DDS *dds,
string indent,
bool sendData,
bool testOverride)
1109 vector<libdap::BaseType *> leaves;
1110 vector<libdap::BaseType *> nodes;
1112 libdap::DDS::Vars_iter vi = dds->var_begin();
1113 libdap::DDS::Vars_iter ve = dds->var_end();
1114 for(; vi != ve; vi++) {
1115 if((*vi)->send_p()) {
1116 libdap::BaseType *v = *vi;
1118 if(type == libdap::dods_array_c) {
1119 type = v->var()->type();
1121 if(v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
1125 leaves.push_back(v);
1132 transformNodeWorker(strm, leaves, nodes, indent + _indent_increment + _indent_increment, sendData);
1135 printCoverageJSON(strm, indent, testOverride);
1138 void FoDapCovJsonTransform::transform(ostream *strm, libdap::BaseType *bt,
string indent,
bool sendData)
1140 switch(bt->type()) {
1142 case libdap::dods_byte_c:
1143 case libdap::dods_int16_c:
1144 case libdap::dods_uint16_c:
1145 case libdap::dods_int32_c:
1146 case libdap::dods_uint32_c:
1147 case libdap::dods_float32_c:
1148 case libdap::dods_float64_c:
1149 case libdap::dods_str_c:
1150 case libdap::dods_url_c:
1151 transformAtomic(bt, indent, sendData);
1154 case libdap::dods_structure_c:
1155 transform(strm, (libdap::Structure *) bt, indent, sendData);
1158 case libdap::dods_grid_c:
1159 transform(strm, (libdap::Grid *) bt, indent, sendData);
1162 case libdap::dods_sequence_c:
1163 transform(strm, (libdap::Sequence *) bt, indent, sendData);
1166 case libdap::dods_array_c:
1167 transform(strm, (libdap::Array *) bt, indent, sendData);
1170 case libdap::dods_int8_c:
1171 case libdap::dods_uint8_c:
1172 case libdap::dods_int64_c:
1173 case libdap::dods_uint64_c:
1174 case libdap::dods_enum_c:
1175 case libdap::dods_group_c: {
1176 string s = (string)
"File out COVJSON, DAP4 types not yet supported.";
1182 string s = (string)
"File out COVJSON, Unrecognized type.";
1189 void FoDapCovJsonTransform::transformAtomic(libdap::BaseType *b,
string indent,
bool sendData)
1191 string childindent = indent + _indent_increment;
1192 struct Axis *newAxis =
new Axis;
1194 newAxis->name =
"test";
1196 newAxis->values +=
"\"values\": [";
1197 if(b->type() == libdap::dods_str_c || b->type() == libdap::dods_url_c) {
1198 libdap::Str *strVar = (libdap::Str *) b;
1199 string tmpString = strVar->value();
1200 newAxis->values +=
"\"";
1201 newAxis->values += focovjson::escape_for_covjson(tmpString);
1202 newAxis->values +=
"\"";
1205 ostringstream otemp;
1206 istringstream itemp;
1208 b->print_val(otemp,
"",
false);
1209 istringstream (otemp.str());
1210 istringstream (otemp.str()) >> tempVal;
1211 newAxis->values += otemp.str();
1213 newAxis->values +=
"]";
1216 newAxis->values +=
"\"values\": []";
1219 axes.push_back(newAxis);
1223 void FoDapCovJsonTransform::transform(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
1225 BESDEBUG(FoDapCovJsonTransform_debug_key,
1226 "FoCovJsonTransform::transform() - Processing Array. " <<
" a->type(): " << a->type() <<
" a->var()->type(): " << a->var()->type() << endl);
1228 switch(a->var()->type()) {
1230 case libdap::dods_byte_c:
1231 covjsonSimpleTypeArray<libdap::dods_byte>(strm, a, indent, sendData);
1234 case libdap::dods_int16_c:
1235 covjsonSimpleTypeArray<libdap::dods_int16>(strm, a, indent, sendData);
1238 case libdap::dods_uint16_c:
1239 covjsonSimpleTypeArray<libdap::dods_uint16>(strm, a, indent, sendData);
1242 case libdap::dods_int32_c:
1243 covjsonSimpleTypeArray<libdap::dods_int32>(strm, a, indent, sendData);
1246 case libdap::dods_uint32_c:
1247 covjsonSimpleTypeArray<libdap::dods_uint32>(strm, a, indent, sendData);
1250 case libdap::dods_float32_c:
1251 covjsonSimpleTypeArray<libdap::dods_float32>(strm, a, indent, sendData);
1254 case libdap::dods_float64_c:
1255 covjsonSimpleTypeArray<libdap::dods_float64>(strm, a, indent, sendData);
1258 case libdap::dods_str_c: {
1259 covjsonStringArray(strm, a, indent, sendData);
1263 case libdap::dods_url_c: {
1264 covjsonStringArray(strm, a, indent, sendData);
1268 case libdap::dods_structure_c:
1269 throw BESInternalError(
"File out COVJSON, Arrays of Structure objects not a supported return type.", __FILE__, __LINE__);
1271 case libdap::dods_grid_c:
1272 throw BESInternalError(
"File out COVJSON, Arrays of Grid objects not a supported return type.", __FILE__, __LINE__);
1274 case libdap::dods_sequence_c:
1275 throw BESInternalError(
"File out COVJSON, Arrays of Sequence objects not a supported return type.", __FILE__, __LINE__);
1277 case libdap::dods_array_c:
1278 throw BESInternalError(
"File out COVJSON, Arrays of Array objects not a supported return type.", __FILE__, __LINE__);
1280 case libdap::dods_int8_c:
1281 case libdap::dods_uint8_c:
1282 case libdap::dods_int64_c:
1283 case libdap::dods_uint64_c:
1284 case libdap::dods_enum_c:
1285 case libdap::dods_group_c:
1286 throw BESInternalError(
"File out COVJSON, DAP4 types not yet supported.", __FILE__, __LINE__);
1289 throw BESInternalError(
"File out COVJSON, Unrecognized type.", __FILE__, __LINE__);
exception thrown if internal error encountered