44 using std::ostringstream;
45 using std::istringstream;
48 #include <Structure.h>
49 #include <Constructor.h>
57 #include <BESInternalError.h>
58 #include <DapFunctionUtils.h>
59 #include "FoDapCovJsonTransform.h"
60 #include "focovjson_utils.h"
62 #define FoDapCovJsonTransform_debug_key "focovjson"
65 bool FoDapCovJsonTransform::canConvert()
73 if(xExists && yExists && zExists && tExists) {
75 if (shapeVals.size() < 4)
80 if((shapeVals[0] > 1) && (shapeVals[1] > 1) && (shapeVals[2] >= 1) && (shapeVals[3] >= 0)) {
87 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] >= 1) && ((shapeVals[3] <= 1) && (shapeVals[3] >= 0))) {
88 domainType =
"Vertical Profile";
96 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1) && (shapeVals[3] >= 0)) {
97 domainType =
"Point Series";
103 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1) && (shapeVals[3] == 1)) {
104 domainType =
"Point";
114 else if(xExists && yExists && !zExists && tExists) {
116 if (shapeVals.size() < 3)
121 if((shapeVals[0] > 1) && (shapeVals[1] > 1) && (shapeVals[2] >= 0)) {
130 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] >= 0)) {
131 domainType =
"Point Series";
137 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1)) {
138 domainType =
"Point";
147 else if(xExists && yExists && !zExists && !tExists) {
149 if (shapeVals.size() < 2)
154 if((shapeVals[0] > 1) && (shapeVals[1] > 1)) {
161 else if((shapeVals[0] == 1) && (shapeVals[1] == 1)) {
162 domainType =
"Point";
171 unsigned int FoDapCovJsonTransform::covjsonSimpleTypeArrayWorker(ostream *strm, T *values,
unsigned int indx,
172 vector<unsigned int> *shape,
unsigned int currentDim)
174 unsigned int currentDimSize = (*shape)[currentDim];
180 for(
unsigned int i = 0; i < currentDimSize; i++) {
181 if(currentDim < shape->size() - 1) {
182 BESDEBUG(FoDapCovJsonTransform_debug_key,
183 "covjsonSimpleTypeArrayWorker() - Recursing! indx: " << indx <<
" currentDim: " << currentDim <<
" currentDimSize: " << currentDimSize << endl);
184 indx = covjsonSimpleTypeArrayWorker<T>(strm, values, indx, shape, currentDim + 1);
185 if(i + 1 != currentDimSize) {
193 if(
typeid(T) ==
typeid(
string)) {
195 string val =
reinterpret_cast<string*
>(values)[indx++];
196 *strm <<
"\"" << focovjson::escape_for_covjson(val) <<
"\"";
199 *strm << values[indx++];
208 void FoDapCovJsonTransform::covjsonSimpleTypeArray(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
210 string childindent = indent + _indent_increment;
211 bool axisRetrieved =
false;
212 bool parameterRetrieved =
false;
214 currDataType = a->var()->type_name();
219 getAttributes(strm, a->get_attr_table(), a->name(), &axisRetrieved, ¶meterRetrieved);
226 if((axisRetrieved ==
true) && (parameterRetrieved ==
false)) {
227 struct Axis *currAxis;
228 currAxis = axes[axisCount - 1];
230 int numDim = a->dimensions(
true);
231 vector<unsigned int> shape(numDim);
232 long length = focovjson::computeConstrainedShape(a, &shape);
238 if (currAxis->name.compare(
"t") != 0) {
240 currAxis->values +=
"\"values\": [";
241 unsigned int indx = 0;
242 vector<T> src(length);
246 indx = covjsonSimpleTypeArrayWorker(&astrm, &src[0], 0, &shape, 0);
247 currAxis->values += astrm.str();
249 currAxis->values +=
"]";
251 if (length != indx) {
252 BESDEBUG(FoDapCovJsonTransform_debug_key,
253 "covjsonSimpleTypeArray(Axis) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
255 assert(length == indx);
258 currAxis->values +=
"\"values\": []";
264 else if(axisRetrieved ==
false && parameterRetrieved ==
true) {
265 struct Parameter *currParameter;
266 currParameter = parameters[parameterCount - 1];
268 int numDim = a->dimensions(
true);
269 vector<unsigned int> shape(numDim);
270 long length = focovjson::computeConstrainedShape(a, &shape);
276 currParameter->shape +=
"\"shape\": [";
277 for(vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
279 currParameter->shape +=
", ";
288 istringstream (otemp.str());
289 istringstream (otemp.str()) >> tempVal;
290 shapeVals.push_back(tempVal);
294 if((i == 0) && tExists) {
295 currParameter->shape +=
"1";
298 currParameter->shape += otemp.str();
301 currParameter->shape +=
"],";
304 currParameter->values +=
"\"values\": [";
305 unsigned int indx = 0;
306 vector<T> src(length);
310 indx = covjsonSimpleTypeArrayWorker(&pstrm, &src[0], 0, &shape, 0);
311 currParameter->values += pstrm.str();
313 currParameter->values +=
"]";
315 if (length != indx) {
316 BESDEBUG(FoDapCovJsonTransform_debug_key,
317 "covjsonSimpleTypeArray(Parameter) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
319 assert(length == indx);
322 currParameter->values +=
"\"values\": []";
327 void FoDapCovJsonTransform::covjsonStringArray(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
329 string childindent = indent + _indent_increment;
330 bool axisRetrieved =
false;
331 bool parameterRetrieved =
false;
333 currDataType = a->var()->type_name();
341 getAttributes(strm, a->get_attr_table(), a->name(), &axisRetrieved, ¶meterRetrieved);
348 if((axisRetrieved ==
true) && (parameterRetrieved ==
false)) {
349 struct Axis *currAxis;
350 currAxis = axes[axisCount - 1];
352 int numDim = a->dimensions(
true);
353 vector<unsigned int> shape(numDim);
354 long length = focovjson::computeConstrainedShape(a, &shape);
356 if (currAxis->name.compare(
"t") != 0) {
358 currAxis->values +=
"\"values\": ";
359 unsigned int indx = 0;
361 vector<string> sourceValues;
362 a->value(sourceValues);
365 indx = covjsonSimpleTypeArrayWorker(&astrm, (
string *) (&sourceValues[0]), 0, &shape, 0);
366 currAxis->values += astrm.str();
368 if (length != indx) {
369 BESDEBUG(FoDapCovJsonTransform_debug_key,
370 "covjsonStringArray(Axis) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
372 assert(length == indx);
375 currAxis->values +=
"\"values\": []";
381 else if(axisRetrieved ==
false && parameterRetrieved ==
true) {
382 struct Parameter *currParameter;
383 currParameter = parameters[parameterCount - 1];
385 int numDim = a->dimensions(
true);
386 vector<unsigned int> shape(numDim);
387 long length = focovjson::computeConstrainedShape(a, &shape);
389 currParameter->shape +=
"\"shape\": [";
390 for(vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
392 currParameter->shape +=
", ";
401 istringstream (otemp.str());
402 istringstream (otemp.str()) >> tempVal;
403 shapeVals.push_back(tempVal);
407 if((i == 0) && tExists) {
408 currParameter->shape +=
"1";
411 currParameter->shape += otemp.str();
414 currParameter->shape +=
"],";
417 currParameter->values +=
"\"values\": ";
418 unsigned int indx = 0;
420 vector<string> sourceValues;
421 a->value(sourceValues);
424 indx = covjsonSimpleTypeArrayWorker(&pstrm, (
string *) (&sourceValues[0]), 0, &shape, 0);
425 currParameter->values += pstrm.str();
427 if (length != indx) {
428 BESDEBUG(FoDapCovJsonTransform_debug_key,
429 "covjsonStringArray(Parameter) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
431 assert(length == indx);
434 currParameter->values +=
"\"values\": []";
439 void FoDapCovJsonTransform::addAxis(
string name,
string values)
441 struct Axis *newAxis =
new Axis;
443 newAxis->name = name;
444 newAxis->values = values;
446 this->axes.push_back(newAxis);
450 void FoDapCovJsonTransform::addParameter(
string id,
string name,
string type,
string dataType,
string unit,
451 string longName,
string standardName,
string shape,
string values)
453 struct Parameter *newParameter =
new Parameter;
455 newParameter->id = id;
456 newParameter->name = name;
457 newParameter->type = type;
458 newParameter->dataType = dataType;
459 newParameter->unit = unit;
460 newParameter->longName = longName;
461 newParameter->standardName = standardName;
462 newParameter->shape = shape;
463 newParameter->values = values;
465 this->parameters.push_back(newParameter);
466 this->parameterCount++;
469 void FoDapCovJsonTransform::getAttributes(ostream *strm, libdap::AttrTable &attr_table,
string name,
470 bool *axisRetrieved,
bool *parameterRetrieved)
473 string currAxisTimeOrigin;
476 string currStandardName;
481 *axisRetrieved =
false;
482 *parameterRetrieved =
false;
489 if((name.compare(
"lon") == 0) || (name.compare(
"LON") == 0)
490 || (name.compare(
"longitude") == 0) || (name.compare(
"LONGITUDE") == 0)
491 || (name.compare(
"COADSX") == 0)) {
502 else if((name.compare(
"lat") == 0) || (name.compare(
"LAT") == 0)
503 || (name.compare(
"latitude") == 0) || (name.compare(
"LATITUDE") == 0)
504 || (name.compare(
"COADSY") == 0)) {
515 else if((name.compare(
"lev") == 0) || (name.compare(
"LEV") == 0)
516 || (name.compare(
"height") == 0) || (name.compare(
"HEIGHT") == 0)
517 || (name.compare(
"depth") == 0) || (name.compare(
"DEPTH") == 0)
518 || (name.compare(
"pres") == 0) || (name.compare(
"PRES") == 0)) {
529 else if((name.compare(
"time") == 0) || (name.compare(
"TIME") == 0)) {
545 if(attr_table.get_size() != 0) {
546 libdap::AttrTable::Attr_iter begin = attr_table.attr_begin();
547 libdap::AttrTable::Attr_iter end = attr_table.attr_end();
549 for(libdap::AttrTable::Attr_iter at_iter = begin; at_iter != end; at_iter++) {
553 switch (attr_table.get_attr_type(at_iter)) {
554 case libdap::Attr_container: {
555 libdap::AttrTable *atbl = attr_table.get_attr_table(at_iter);
557 getAttributes(strm, *atbl, name, axisRetrieved, parameterRetrieved);
561 vector<string> *values = attr_table.get_attr_vector(at_iter);
563 for(vector<string>::size_type i = 0; i < values->size(); i++) {
564 string currName = attr_table.get_name(at_iter);
565 string currValue = (*values)[i];
584 if(currName.compare(
"units") == 0) {
585 currUnit = currValue;
588 if(currAxisName.compare(
"t") == 0) {
589 currAxisTimeOrigin = currValue;
600 else if(currName.compare(
"long_name") == 0) {
601 currLongName = currValue;
604 else if(currName.compare(
"standard_name") == 0) {
605 currStandardName = currValue;
619 if(currAxisName.compare(
"t") == 0) {
620 addAxis(currAxisName,
"\"values\": [\"" + sanitizeTimeOriginString(currAxisTimeOrigin) +
"\"]");
623 addAxis(currAxisName,
"");
627 if((currUnit.find(
"east") != string::npos) || (currUnit.find(
"East") != string::npos) ||
628 (currUnit.find(
"north") != string::npos) || (currUnit.find(
"North") != string::npos)) {
629 coordRefType =
"ProjectedCRS";
632 *axisRetrieved =
true;
635 addParameter(
"", name,
"", currDataType, currUnit, currLongName, currStandardName,
"",
"");
636 *parameterRetrieved =
true;
643 string FoDapCovJsonTransform::sanitizeTimeOriginString(
string timeOrigin)
663 vector<string> subStrs = {
"hours",
"hour",
"minutes",
"minute",
664 "seconds",
"second",
"since",
" " };
666 string cleanTimeOrigin = timeOrigin;
669 if(timeOrigin.find(
"base_time") != string::npos) {
670 cleanTimeOrigin =
"2020-01-01T12:00:00Z";
673 for(
unsigned int i = 0; i < subStrs.size(); i++)
674 focovjson::removeSubstring(cleanTimeOrigin, subStrs[i]);
677 return cleanTimeOrigin;
681 _dds(dds), _returnAs(
""), _indent_increment(
" "), atomicVals(
""), currDataType(
""), domainType(
"Unknown"),
682 coordRefType(
"GeographicCRS"), xExists(false), yExists(false), zExists(false), tExists(false), isParam(false),
683 isAxis(false), canConvertToCovJson(false), axisCount(0), parameterCount(0)
685 if (!_dds)
throw BESInternalError(
"File out COVJSON, null DDS passed to constructor", __FILE__, __LINE__);
690 strm << BESIndent::LMarg <<
"FoDapCovJsonTransform::dump - (" << (
void *)
this <<
")" << endl;
695 BESIndent::UnIndent();
698 void FoDapCovJsonTransform::transform(ostream &ostrm,
bool sendData,
bool testOverride)
700 transform(&ostrm, _dds,
"", sendData, testOverride);
703 void FoDapCovJsonTransform::transform(ostream *strm, libdap::Constructor *cnstrctr,
string indent,
bool sendData)
705 vector<libdap::BaseType *> leaves;
706 vector<libdap::BaseType *> nodes;
708 libdap::DDS::Vars_iter vi = cnstrctr->var_begin();
709 libdap::DDS::Vars_iter ve = cnstrctr->var_end();
711 for(; vi != ve; vi++) {
712 if((*vi)->send_p()) {
713 libdap::BaseType *v = *vi;
716 if(type == libdap::dods_array_c) {
717 type = v->var()->type();
719 if(v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
728 transformNodeWorker(strm, leaves, nodes, indent, sendData);
731 void FoDapCovJsonTransform::transformNodeWorker(ostream *strm, vector<libdap::BaseType *> leaves,
732 vector<libdap::BaseType *> nodes,
string indent,
bool sendData)
735 for(vector<libdap::BaseType *>::size_type l = 0; l < leaves.size(); l++) {
736 libdap::BaseType *v = leaves[l];
737 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Processing LEAF: " << v->name() << endl);
742 transform(strm, v, indent + _indent_increment, sendData);
746 for(vector<libdap::BaseType *>::size_type n = 0; n < nodes.size(); n++) {
747 libdap::BaseType *v = nodes[n];
748 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Processing NODE: " << v->name() << endl);
753 transform(strm, v, indent + _indent_increment, sendData);
757 void FoDapCovJsonTransform::printCoverageJSON(ostream *strm,
string indent,
bool testOverride)
763 canConvertToCovJson =
true;
766 canConvertToCovJson = canConvert();
770 if(canConvertToCovJson) {
772 printCoverage(strm, indent);
776 throw BESInternalError(
"File cannot be converted to CovJSON format due to missing or incompatible spatial dimensions", __FILE__, __LINE__);
780 void FoDapCovJsonTransform::printCoverage(ostream *strm,
string indent)
782 string child_indent1 = indent + _indent_increment;
783 string child_indent2 = child_indent1 + _indent_increment;
785 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing COVERAGE" << endl);
787 *strm << indent <<
"{" << endl;
788 *strm << child_indent1 <<
"\"type\": \"Coverage\"," << endl;
790 printDomain(strm, child_indent1);
792 printParameters(strm, child_indent1);
794 printRanges(strm, child_indent1);
796 *strm << indent <<
"}" << endl;
799 void FoDapCovJsonTransform::printDomain(ostream *strm,
string indent)
801 string child_indent1 = indent + _indent_increment;
803 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing DOMAIN" << endl);
805 *strm << indent <<
"\"domain\": {" << endl;
806 *strm << child_indent1 <<
"\"type\" : \"Domain\"," << endl;
807 *strm << child_indent1 <<
"\"domainType\": \"" + domainType +
"\"," << endl;
810 printAxes(strm, child_indent1);
813 printReference(strm, child_indent1);
815 *strm << indent <<
"}," << endl;
818 void FoDapCovJsonTransform::printAxes(ostream *strm,
string indent)
820 string child_indent1 = indent + _indent_increment;
821 string child_indent2 = child_indent1 + _indent_increment;
823 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing AXES" << endl);
829 *strm << indent <<
"\"axes\": {" << endl;
830 for(
unsigned int i = 0; i < axisCount; i++) {
831 for(
unsigned int j = 0; j < axisCount; j++) {
835 if(xExists && yExists && zExists && tExists) {
836 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
837 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
838 *strm << child_indent2 << axes[j]->values << endl;
840 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
841 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
842 *strm << child_indent2 << axes[j]->values << endl;
844 else if((i == 2) && (axes[j]->name.compare(
"z") == 0)) {
845 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
846 *strm << child_indent2 << axes[j]->values << endl;
848 else if((i == 3) && (axes[j]->name.compare(
"t") == 0)) {
849 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
850 *strm << child_indent2 << axes[j]->values << endl;
854 else if(xExists && yExists && !zExists && tExists) {
855 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
856 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
857 *strm << child_indent2 << axes[j]->values << endl;
859 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
860 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
861 *strm << child_indent2 << axes[j]->values << endl;
863 else if((i == 2) && (axes[j]->name.compare(
"t") == 0)) {
864 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
865 *strm << child_indent2 << axes[j]->values << endl;
869 else if(xExists && yExists && !zExists && !tExists) {
870 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
871 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
872 *strm << child_indent2 << axes[j]->values << endl;
874 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
875 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
876 *strm << child_indent2 << axes[j]->values << endl;
880 if(i == axisCount - 1) {
881 *strm << child_indent1 <<
"}" << endl;
884 *strm << child_indent1 <<
"}," << endl;
887 *strm << indent <<
"}," << endl;
890 void FoDapCovJsonTransform::printReference(ostream *strm,
string indent)
892 string child_indent1 = indent + _indent_increment;
893 string child_indent2 = child_indent1 + _indent_increment;
896 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing REFERENCES" << endl);
899 coordVars +=
"\"x\"";
903 if(coordVars.length() > 0) {
906 coordVars +=
"\"y\"";
910 if(coordVars.length() > 0) {
913 coordVars +=
"\"z\"";
916 *strm << indent <<
"\"referencing\": [{" << endl;
920 *strm << child_indent1 <<
"\"coordinates\": [\"t\"]," << endl;
921 *strm << child_indent1 <<
"\"system\": {" << endl;
922 *strm << child_indent2 <<
"\"type\": \"TemporalRS\"," << endl;
923 *strm << child_indent2 <<
"\"calendar\": \"Gregorian\"" << endl;
924 *strm << child_indent1 <<
"}" << endl;
925 *strm << indent <<
"}," << endl;
926 *strm << indent <<
"{" << endl;
930 *strm << child_indent1 <<
"\"coordinates\": [" << coordVars <<
"]," << endl;
931 *strm << child_indent1 <<
"\"system\": {" << endl;
932 *strm << child_indent2 <<
"\"type\": \"" + coordRefType +
"\"," << endl;
936 if(coordRefType.compare(
"ProjectedCRS") == 0) {
938 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/EPSG/0/27700\"" << endl;
941 if(xExists && yExists && zExists) {
943 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/EPSG/0/4979\"" << endl;
947 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/OGC/1.3/CRS84\"" << endl;
951 *strm << child_indent1 <<
"}" << endl;
952 *strm << indent <<
"}]" << endl;
955 void FoDapCovJsonTransform::printParameters(ostream *strm,
string indent)
957 string child_indent1 = indent + _indent_increment;
958 string child_indent2 = child_indent1 + _indent_increment;
959 string child_indent3 = child_indent2 + _indent_increment;
960 string child_indent4 = child_indent3 + _indent_increment;
962 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing PARAMETERS" << endl);
965 *strm << indent <<
"\"parameters\": {" << endl;
966 for(
unsigned int i = 0; i < parameterCount; i++) {
967 *strm << child_indent1 <<
"\"" << parameters[i]->name <<
"\": {" << endl;
968 *strm << child_indent2 <<
"\"type\": \"Parameter\"," << endl;
969 *strm << child_indent2 <<
"\"description\": {" << endl;
971 if(parameters[i]->longName.compare(
"") != 0) {
972 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->longName <<
"\"" << endl;
974 else if(parameters[i]->standardName.compare(
"") != 0) {
975 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->standardName <<
"\"" << endl;
978 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->name <<
"\"" << endl;
981 *strm << child_indent2 <<
"}," << endl;
982 *strm << child_indent2 <<
"\"unit\": {" << endl;
983 *strm << child_indent3 <<
"\"label\": {" << endl;
984 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->unit <<
"\"" << endl;
985 *strm << child_indent3 <<
"}," << endl;
986 *strm << child_indent3 <<
"\"symbol\": {" << endl;
987 *strm << child_indent4 <<
"\"value\": \"" << parameters[i]->unit <<
"\"," << endl;
988 *strm << child_indent4 <<
"\"type\": \"http://www.opengis.net/def/uom/UCUM/\"" << endl;
989 *strm << child_indent3 <<
"}" << endl;
990 *strm << child_indent2 <<
"}," << endl;
991 *strm << child_indent2 <<
"\"observedProperty\": {" << endl;
997 if(parameters[i]->standardName.compare(
"") != 0) {
998 *strm << child_indent3 <<
"\"id\": \"http://vocab.nerc.ac.uk/standard_name/" << parameters[i]->standardName <<
"/\"," << endl;
1006 *strm << child_indent3 <<
"\"label\": {" << endl;
1008 if(parameters[i]->longName.compare(
"") != 0) {
1009 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->longName <<
"\"" << endl;
1011 else if(parameters[i]->standardName.compare(
"") != 0) {
1012 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->standardName <<
"\"" << endl;
1015 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->name <<
"\"" << endl;
1018 *strm << child_indent3 <<
"}" << endl;
1019 *strm << child_indent2 <<
"}" << endl;
1021 if(i == parameterCount - 1) {
1022 *strm << child_indent1 <<
"}" << endl;
1025 *strm << child_indent1 <<
"}," << endl;
1029 *strm << indent <<
"}," << endl;
1032 void FoDapCovJsonTransform::printRanges(ostream *strm,
string indent)
1034 string child_indent1 = indent + _indent_increment;
1035 string child_indent2 = child_indent1 + _indent_increment;
1036 string child_indent3 = child_indent2 + _indent_increment;
1039 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing RANGES" << endl);
1042 axisNames +=
"\"t\"";
1046 if(axisNames.length() > 0) {
1049 axisNames +=
"\"z\"";
1053 if(axisNames.length() > 0) {
1056 axisNames +=
"\"y\"";
1060 if(axisNames.length() > 0) {
1063 axisNames +=
"\"x\"";
1067 *strm << indent <<
"\"ranges\": {" << endl;
1068 for(
unsigned int i = 0; i < parameterCount; i++) {
1071 if(parameters[i]->dataType.find(
"int") == 0 || parameters[i]->dataType.find(
"Int") == 0
1072 || parameters[i]->dataType.find(
"integer") == 0 || parameters[i]->dataType.find(
"Integer") == 0) {
1073 dataType =
"integer";
1075 else if(parameters[i]->dataType.find(
"float") == 0 || parameters[i]->dataType.find(
"Float") == 0) {
1078 else if(parameters[i]->dataType.find(
"string") == 0 || parameters[i]->dataType.find(
"String") == 0) {
1079 dataType =
"string";
1082 dataType =
"string";
1087 *strm << child_indent1 <<
"\"" << parameters[i]->name <<
"\": {" << endl;
1088 *strm << child_indent2 <<
"\"type\": \"NdArray\"," << endl;
1089 *strm << child_indent2 <<
"\"dataType\": \"" << dataType <<
"\", " << endl;
1090 *strm << child_indent2 <<
"\"axisNames\": [" << axisNames <<
"]," << endl;
1091 *strm << child_indent2 << parameters[i]->shape << endl;
1092 *strm << child_indent2 << parameters[i]->values << endl;
1094 if(i == parameterCount - 1) {
1095 *strm << child_indent1 <<
"}" << endl;
1098 *strm << child_indent1 <<
"}," << endl;
1102 *strm << indent <<
"}" << endl;
1105 void FoDapCovJsonTransform::transform(ostream *strm, libdap::DDS *dds,
string indent,
bool sendData,
bool testOverride)
1108 vector<libdap::BaseType *> leaves;
1109 vector<libdap::BaseType *> nodes;
1111 libdap::DDS::Vars_iter vi = dds->var_begin();
1112 libdap::DDS::Vars_iter ve = dds->var_end();
1113 for(; vi != ve; vi++) {
1114 if((*vi)->send_p()) {
1115 libdap::BaseType *v = *vi;
1117 if(type == libdap::dods_array_c) {
1118 type = v->var()->type();
1120 if(v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
1124 leaves.push_back(v);
1131 transformNodeWorker(strm, leaves, nodes, indent + _indent_increment + _indent_increment, sendData);
1134 printCoverageJSON(strm, indent, testOverride);
1137 void FoDapCovJsonTransform::transform(ostream *strm, libdap::BaseType *bt,
string indent,
bool sendData)
1139 switch(bt->type()) {
1141 case libdap::dods_byte_c:
1142 case libdap::dods_int16_c:
1143 case libdap::dods_uint16_c:
1144 case libdap::dods_int32_c:
1145 case libdap::dods_uint32_c:
1146 case libdap::dods_float32_c:
1147 case libdap::dods_float64_c:
1148 case libdap::dods_str_c:
1149 case libdap::dods_url_c:
1150 transformAtomic(bt, indent, sendData);
1153 case libdap::dods_structure_c:
1154 transform(strm, (libdap::Structure *) bt, indent, sendData);
1157 case libdap::dods_grid_c:
1158 transform(strm, (libdap::Grid *) bt, indent, sendData);
1161 case libdap::dods_sequence_c:
1162 transform(strm, (libdap::Sequence *) bt, indent, sendData);
1165 case libdap::dods_array_c:
1166 transform(strm, (libdap::Array *) bt, indent, sendData);
1169 case libdap::dods_int8_c:
1170 case libdap::dods_uint8_c:
1171 case libdap::dods_int64_c:
1172 case libdap::dods_uint64_c:
1173 case libdap::dods_enum_c:
1174 case libdap::dods_group_c: {
1175 string s = (string)
"File out COVJSON, DAP4 types not yet supported.";
1181 string s = (string)
"File out COVJSON, Unrecognized type.";
1188 void FoDapCovJsonTransform::transformAtomic(libdap::BaseType *b,
string indent,
bool sendData)
1190 string childindent = indent + _indent_increment;
1191 struct Axis *newAxis =
new Axis;
1193 newAxis->name =
"test";
1195 newAxis->values +=
"\"values\": [";
1196 if(b->type() == libdap::dods_str_c || b->type() == libdap::dods_url_c) {
1197 libdap::Str *strVar = (libdap::Str *) b;
1198 string tmpString = strVar->value();
1199 newAxis->values +=
"\"";
1200 newAxis->values += focovjson::escape_for_covjson(tmpString);
1201 newAxis->values +=
"\"";
1204 ostringstream otemp;
1205 istringstream itemp;
1207 b->print_val(otemp,
"",
false);
1208 istringstream (otemp.str());
1209 istringstream (otemp.str()) >> tempVal;
1210 newAxis->values += otemp.str();
1212 newAxis->values +=
"]";
1215 newAxis->values +=
"\"values\": []";
1218 axes.push_back(newAxis);
1222 void FoDapCovJsonTransform::transform(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
1224 BESDEBUG(FoDapCovJsonTransform_debug_key,
1225 "FoCovJsonTransform::transform() - Processing Array. " <<
" a->type(): " << a->type() <<
" a->var()->type(): " << a->var()->type() << endl);
1227 switch(a->var()->type()) {
1229 case libdap::dods_byte_c:
1230 covjsonSimpleTypeArray<libdap::dods_byte>(strm, a, indent, sendData);
1233 case libdap::dods_int16_c:
1234 covjsonSimpleTypeArray<libdap::dods_int16>(strm, a, indent, sendData);
1237 case libdap::dods_uint16_c:
1238 covjsonSimpleTypeArray<libdap::dods_uint16>(strm, a, indent, sendData);
1241 case libdap::dods_int32_c:
1242 covjsonSimpleTypeArray<libdap::dods_int32>(strm, a, indent, sendData);
1245 case libdap::dods_uint32_c:
1246 covjsonSimpleTypeArray<libdap::dods_uint32>(strm, a, indent, sendData);
1249 case libdap::dods_float32_c:
1250 covjsonSimpleTypeArray<libdap::dods_float32>(strm, a, indent, sendData);
1253 case libdap::dods_float64_c:
1254 covjsonSimpleTypeArray<libdap::dods_float64>(strm, a, indent, sendData);
1257 case libdap::dods_str_c: {
1258 covjsonStringArray(strm, a, indent, sendData);
1262 case libdap::dods_url_c: {
1263 covjsonStringArray(strm, a, indent, sendData);
1267 case libdap::dods_structure_c:
1268 throw BESInternalError(
"File out COVJSON, Arrays of Structure objects not a supported return type.", __FILE__, __LINE__);
1270 case libdap::dods_grid_c:
1271 throw BESInternalError(
"File out COVJSON, Arrays of Grid objects not a supported return type.", __FILE__, __LINE__);
1273 case libdap::dods_sequence_c:
1274 throw BESInternalError(
"File out COVJSON, Arrays of Sequence objects not a supported return type.", __FILE__, __LINE__);
1276 case libdap::dods_array_c:
1277 throw BESInternalError(
"File out COVJSON, Arrays of Array objects not a supported return type.", __FILE__, __LINE__);
1279 case libdap::dods_int8_c:
1280 case libdap::dods_uint8_c:
1281 case libdap::dods_int64_c:
1282 case libdap::dods_uint64_c:
1283 case libdap::dods_enum_c:
1284 case libdap::dods_group_c:
1285 throw BESInternalError(
"File out COVJSON, DAP4 types not yet supported.", __FILE__, __LINE__);
1288 throw BESInternalError(
"File out COVJSON, Unrecognized type.", __FILE__, __LINE__);