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" 75 bool FoDapCovJsonTransform::canConvert()
83 if(xExists && yExists && zExists && tExists) {
85 if (shapeVals.size() < 4)
90 if((shapeVals[0] > 1) && (shapeVals[1] > 1) && (shapeVals[2] >= 1) && (shapeVals[3] >= 0)) {
97 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] >= 1) && ((shapeVals[3] <= 1) && (shapeVals[3] >= 0))) {
98 domainType = VerticalProfile;
106 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1) && (shapeVals[3] >= 0)) {
107 domainType = PointSeries;
113 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1) && (shapeVals[3] == 1)) {
124 else if(xExists && yExists && !zExists && tExists) {
126 if (shapeVals.size() < 3)
131 if((shapeVals[0] > 1) && (shapeVals[1] > 1) && (shapeVals[2] >= 0)) {
140 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] >= 0)) {
141 domainType = PointSeries;
147 else if((shapeVals[0] == 1) && (shapeVals[1] == 1) && (shapeVals[2] == 1)) {
157 else if(xExists && yExists && !zExists && !tExists) {
159 if (shapeVals.size() < 2)
164 if((shapeVals[0] > 1) && (shapeVals[1] > 1)) {
171 else if((shapeVals[0] == 1) && (shapeVals[1] == 1)) {
193 unsigned int FoDapCovJsonTransform::covjsonSimpleTypeArrayWorker(ostream *strm, T *values,
unsigned int indx,
194 vector<unsigned int> *shape,
unsigned int currentDim)
196 unsigned int currentDimSize = (*shape)[currentDim];
203 for(
unsigned int i = 0; i < currentDimSize; i++) {
204 if(currentDim < shape->size() - 1) {
205 BESDEBUG(FoDapCovJsonTransform_debug_key,
206 "covjsonSimpleTypeArrayWorker() - Recursing! indx: " << indx <<
" currentDim: " << currentDim <<
" currentDimSize: " << currentDimSize << endl);
207 indx = covjsonSimpleTypeArrayWorker<T>(strm, values, indx, shape, currentDim + 1);
208 if(i + 1 != currentDimSize) {
216 if(
typeid(T) ==
typeid(
string)) {
218 string val = reinterpret_cast<string*>(values)[indx++];
219 *strm <<
"\"" << focovjson::escape_for_covjson(val) <<
"\"";
222 *strm << values[indx++];
250 void FoDapCovJsonTransform::covjsonSimpleTypeArray(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
252 string childindent = indent + _indent_increment;
253 bool axisRetrieved =
false;
254 bool parameterRetrieved =
false;
256 currDataType = a->var()->type_name();
261 getAttributes(strm, a->get_attr_table(), a->name(), &axisRetrieved, ¶meterRetrieved);
268 if((axisRetrieved ==
true) && (parameterRetrieved ==
false)) {
269 struct Axis *currAxis;
270 currAxis = axes[axisCount - 1];
272 int numDim = a->dimensions(
true);
273 vector<unsigned int> shape(numDim);
274 long length = focovjson::computeConstrainedShape(a, &shape);
280 if (currAxis->name.compare(
"t") != 0) {
282 currAxis->values +=
"\"values\": ";
283 unsigned int indx = 0;
284 vector<T> src(length);
288 indx = covjsonSimpleTypeArrayWorker(&astrm, &src[0], 0, &shape, 0);
289 currAxis->values += astrm.str();
291 if (length != indx) {
292 BESDEBUG(FoDapCovJsonTransform_debug_key,
293 "covjsonSimpleTypeArray(Axis) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
295 assert(length == indx);
298 currAxis->values +=
"\"values\": []";
304 else if(axisRetrieved ==
false && parameterRetrieved ==
true) {
305 struct Parameter *currParameter;
306 currParameter = parameters[parameterCount - 1];
308 int numDim = a->dimensions(
true);
309 vector<unsigned int> shape(numDim);
310 long length = focovjson::computeConstrainedShape(a, &shape);
316 currParameter->shape +=
"\"shape\": [";
317 for(vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
319 currParameter->shape +=
", ";
328 istringstream (otemp.str());
329 istringstream (otemp.str()) >> tempVal;
330 shapeVals.push_back(tempVal);
334 if((i == 0) && tExists) {
335 currParameter->shape +=
"1";
338 currParameter->shape += otemp.str();
341 currParameter->shape +=
"],";
344 currParameter->values +=
"\"values\": ";
345 unsigned int indx = 0;
346 vector<T> src(length);
350 indx = covjsonSimpleTypeArrayWorker(&pstrm, &src[0], 0, &shape, 0);
351 currParameter->values += pstrm.str();
353 if (length != indx) {
354 BESDEBUG(FoDapCovJsonTransform_debug_key,
355 "covjsonSimpleTypeArray(Parameter) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
357 assert(length == indx);
360 currParameter->values +=
"\"values\": []";
386 void FoDapCovJsonTransform::covjsonStringArray(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
388 string childindent = indent + _indent_increment;
389 bool axisRetrieved =
false;
390 bool parameterRetrieved =
false;
392 currDataType = a->var()->type_name();
400 getAttributes(strm, a->get_attr_table(), a->name(), &axisRetrieved, ¶meterRetrieved);
407 if((axisRetrieved ==
true) && (parameterRetrieved ==
false)) {
408 struct Axis *currAxis;
409 currAxis = axes[axisCount - 1];
411 int numDim = a->dimensions(
true);
412 vector<unsigned int> shape(numDim);
413 long length = focovjson::computeConstrainedShape(a, &shape);
415 if (currAxis->name.compare(
"t") != 0) {
417 currAxis->values +=
"\"values\": ";
418 unsigned int indx = 0;
420 vector<string> sourceValues;
421 a->value(sourceValues);
424 indx = covjsonSimpleTypeArrayWorker(&astrm, (
string *) (&sourceValues[0]), 0, &shape, 0);
425 currAxis->values += astrm.str();
427 if (length != indx) {
428 BESDEBUG(FoDapCovJsonTransform_debug_key,
429 "covjsonStringArray(Axis) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
431 assert(length == indx);
434 currAxis->values +=
"\"values\": []";
440 else if(axisRetrieved ==
false && parameterRetrieved ==
true) {
441 struct Parameter *currParameter;
442 currParameter = parameters[parameterCount - 1];
444 int numDim = a->dimensions(
true);
445 vector<unsigned int> shape(numDim);
446 long length = focovjson::computeConstrainedShape(a, &shape);
448 currParameter->shape +=
"\"shape\": [";
449 for(vector<unsigned int>::size_type i = 0; i < shape.size(); i++) {
451 currParameter->shape +=
", ";
460 istringstream (otemp.str());
461 istringstream (otemp.str()) >> tempVal;
462 shapeVals.push_back(tempVal);
466 if((i == 0) && tExists) {
467 currParameter->shape +=
"1";
470 currParameter->shape += otemp.str();
473 currParameter->shape +=
"],";
476 currParameter->values +=
"\"values\": ";
477 unsigned int indx = 0;
479 vector<string> sourceValues;
480 a->value(sourceValues);
483 indx = covjsonSimpleTypeArrayWorker(&pstrm, (
string *) (&sourceValues[0]), 0, &shape, 0);
484 currParameter->values += pstrm.str();
486 if (length != indx) {
487 BESDEBUG(FoDapCovJsonTransform_debug_key,
488 "covjsonStringArray(Parameter) - indx NOT equal to content length! indx: " << indx <<
" length: " << length << endl);
490 assert(length == indx);
493 currParameter->values +=
"\"values\": []";
520 void FoDapCovJsonTransform::getAttributes(ostream *strm, libdap::AttrTable &attr_table,
string name,
521 bool *axisRetrieved,
bool *parameterRetrieved)
524 string currAxisTimeOrigin;
527 string currStandardName;
537 if((name.compare(
"lon") == 0) || (name.compare(
"LON") == 0)
538 || (name.compare(
"longitude") == 0) || (name.compare(
"LONGITUDE") == 0)
539 || (name.compare(
"COADSX") == 0)) {
550 else if((name.compare(
"lat") == 0) || (name.compare(
"LAT") == 0)
551 || (name.compare(
"latitude") == 0) || (name.compare(
"LATITUDE") == 0)
552 || (name.compare(
"COADSY") == 0)) {
563 else if((name.compare(
"lev") == 0) || (name.compare(
"LEV") == 0)
564 || (name.compare(
"height") == 0) || (name.compare(
"HEIGHT") == 0)
565 || (name.compare(
"depth") == 0) || (name.compare(
"DEPTH") == 0)
566 || (name.compare(
"pres") == 0) || (name.compare(
"PRES") == 0)) {
577 else if((name.compare(
"time") == 0) || (name.compare(
"TIME") == 0)) {
593 if(attr_table.get_size() != 0) {
594 libdap::AttrTable::Attr_iter begin = attr_table.attr_begin();
595 libdap::AttrTable::Attr_iter end = attr_table.attr_end();
597 for(libdap::AttrTable::Attr_iter at_iter = begin; at_iter != end; at_iter++) {
598 switch (attr_table.get_attr_type(at_iter)) {
599 case libdap::Attr_container: {
600 libdap::AttrTable *atbl = attr_table.get_attr_table(at_iter);
602 getAttributes(strm, *atbl, name, axisRetrieved, parameterRetrieved);
606 vector<string> *values = attr_table.get_attr_vector(at_iter);
608 for(vector<string>::size_type i = 0; i < values->size(); i++) {
609 string currName = attr_table.get_name(at_iter);
610 string currValue = (*values)[i];
629 if(currName.compare(
"units") == 0) {
631 if(currAxisName.compare(
"t") == 0) {
632 currAxisTimeOrigin = currValue;
636 currUnit = currValue;
640 else if(currName.compare(
"long_name") == 0) {
641 currLongName = currValue;
644 else if(currName.compare(
"standard_name") == 0) {
645 currStandardName = currValue;
657 struct Axis *newAxis =
new Axis;
658 newAxis->name = currAxisName;
664 if(currAxisName.compare(
"t") == 0) {
703 newAxis->values +=
"\"values\": [\"";
705 newAxis->values +=
"2018-01-01T00:12:20Z";
706 newAxis->values +=
"\"]";
708 axes.push_back(newAxis);
710 *axisRetrieved =
true;
711 *parameterRetrieved =
false;
734 struct Parameter *newParameter =
new Parameter;
735 newParameter->name = name;
736 newParameter->dataType = currDataType;
737 newParameter->unit = currUnit;
738 newParameter->longName = currLongName;
739 parameters.push_back(newParameter);
741 *axisRetrieved =
false;
742 *parameterRetrieved =
true;
767 _dds(dds), _returnAs(
""), _indent_increment(
" "), atomicVals(
""), currDataType(
""), domainType(0),
768 xExists(false), yExists(false), zExists(false), tExists(false), isParam(false), isAxis(false),
769 canConvertToCovJson(false), axisCount(0), parameterCount(0)
771 if (!_dds)
throw BESInternalError(
"File out COVJSON, null DDS passed to constructor", __FILE__, __LINE__);
787 strm << BESIndent::LMarg <<
"FoDapCovJsonTransform::dump - (" << (
void *)
this <<
")" << endl;
792 BESIndent::UnIndent();
809 void FoDapCovJsonTransform::transform(ostream &ostrm,
bool sendData,
bool testOverride)
811 transform(&ostrm, _dds,
"", sendData, testOverride);
832 void FoDapCovJsonTransform::transform(ostream *strm, libdap::Constructor *cnstrctr,
string indent,
bool sendData)
834 vector<libdap::BaseType *> leaves;
835 vector<libdap::BaseType *> nodes;
837 libdap::DDS::Vars_iter vi = cnstrctr->var_begin();
838 libdap::DDS::Vars_iter ve = cnstrctr->var_end();
840 for(; vi != ve; vi++) {
841 if((*vi)->send_p()) {
842 libdap::BaseType *v = *vi;
845 if(type == libdap::dods_array_c) {
846 type = v->var()->type();
848 if(v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
857 transformNodeWorker(strm, leaves, nodes, indent, sendData);
871 void FoDapCovJsonTransform::transformNodeWorker(ostream *strm, vector<libdap::BaseType *> leaves,
872 vector<libdap::BaseType *> nodes,
string indent,
bool sendData)
875 for(vector<libdap::BaseType *>::size_type l = 0; l < leaves.size(); l++) {
876 libdap::BaseType *v = leaves[l];
877 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Processing LEAF: " << v->name() << endl);
882 transform(strm, v, indent + _indent_increment, sendData);
886 for(vector<libdap::BaseType *>::size_type n = 0; n < nodes.size(); n++) {
887 libdap::BaseType *v = nodes[n];
888 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Processing NODE: " << v->name() << endl);
893 transform(strm, v, indent + _indent_increment, sendData);
906 void FoDapCovJsonTransform::printCoverageHeaderWorker(ostream *strm,
string indent,
bool isCoverageCollection)
908 string child_indent1 = indent + _indent_increment;
909 string child_indent2 = child_indent1 + _indent_increment;
911 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing COVERAGE HEADER" << endl);
915 *strm << indent <<
"{" << endl;
916 *strm << child_indent1 <<
"\"type\": \"Coverage\"," << endl;
917 *strm << child_indent1 <<
"\"domain\": {" << endl;
918 *strm << child_indent2 <<
"\"type\" : \"Domain\"," << endl;
920 if(domainType == Grid) {
921 *strm << child_indent2 <<
"\"domainType\": \"Grid\"," << endl;
923 else if(domainType == VerticalProfile) {
924 *strm << child_indent2 <<
"\"domainType\": \"Vertical Profile\"," << endl;
926 else if(domainType == PointSeries) {
927 *strm << child_indent2 <<
"\"domainType\": \"Point Series\"," << endl;
929 else if(domainType == Point) {
930 *strm << child_indent2 <<
"\"domainType\": \"Point\"," << endl;
933 *strm << child_indent2 <<
"\"domainType\": \"Unknown\"," << endl;
1001 void FoDapCovJsonTransform::printAxesWorker(ostream *strm,
string indent)
1003 string child_indent1 = indent + _indent_increment;
1004 string child_indent2 = child_indent1 + _indent_increment;
1006 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing AXES" << endl);
1012 *strm << indent <<
"\"axes\": {" << endl;
1013 for(
unsigned int i = 0; i < axisCount; i++) {
1014 for(
unsigned int j = 0; j < axisCount; j++) {
1018 if(xExists && yExists && zExists && tExists) {
1019 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
1020 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1021 *strm << child_indent2 << axes[j]->values << endl;
1023 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
1024 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1025 *strm << child_indent2 << axes[j]->values << endl;
1027 else if((i == 2) && (axes[j]->name.compare(
"z") == 0)) {
1028 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1029 *strm << child_indent2 << axes[j]->values << endl;
1031 else if((i == 3) && (axes[j]->name.compare(
"t") == 0)) {
1032 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1033 *strm << child_indent2 << axes[j]->values << endl;
1037 else if(xExists && yExists && !zExists && tExists) {
1038 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
1039 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1040 *strm << child_indent2 << axes[j]->values << endl;
1042 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
1043 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1044 *strm << child_indent2 << axes[j]->values << endl;
1046 else if((i == 2) && (axes[j]->name.compare(
"t") == 0)) {
1047 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1048 *strm << child_indent2 << axes[j]->values << endl;
1052 else if(xExists && yExists && !zExists && !tExists) {
1053 if((i == 0) && (axes[j]->name.compare(
"x") == 0)) {
1054 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1055 *strm << child_indent2 << axes[j]->values << endl;
1057 else if((i == 1) && (axes[j]->name.compare(
"y") == 0)) {
1058 *strm << child_indent1 <<
"\"" << axes[j]->name <<
"\": {" << endl;
1059 *strm << child_indent2 << axes[j]->values << endl;
1063 if(i == axisCount - 1) {
1064 *strm << child_indent1 <<
"}" << endl;
1067 *strm << child_indent1 <<
"}," << endl;
1070 if(parameterCount == 1) {
1071 *strm << indent <<
"}," << endl;
1074 *strm << indent <<
"}" << endl;
1085 void FoDapCovJsonTransform::printReferenceWorker(ostream *strm,
string indent)
1087 string child_indent1 = indent + _indent_increment;
1088 string child_indent2 = child_indent1 + _indent_increment;
1091 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing REFERENCES" << endl);
1094 coordVars +=
"\"x\"";
1098 if(coordVars.length() > 0) {
1101 coordVars +=
"\"y\"";
1105 if(coordVars.length() > 0) {
1108 coordVars +=
"\"z\"";
1126 *strm << indent <<
"\"referencing\": [{" << endl;
1128 *strm << child_indent1 <<
"\"coordinates\": [\"t\"]," << endl;
1129 *strm << child_indent1 <<
"\"system\": {" << endl;
1130 *strm << child_indent2 <<
"\"type\": \"TemporalRS\"," << endl;
1131 *strm << child_indent2 <<
"\"calendar\": \"Gregorian\"" << endl;
1132 *strm << child_indent1 <<
"}" << endl;
1133 *strm << indent <<
"}," << endl;
1134 *strm << indent <<
"{" << endl;
1136 *strm << child_indent1 <<
"\"coordinates\": [" << coordVars <<
"]," << endl;
1137 *strm << child_indent1 <<
"\"system\": {" << endl;
1138 *strm << child_indent2 <<
"\"type\": \"GeographicCRS\"," << endl;
1139 *strm << child_indent2 <<
"\"id\": \"http://www.opengis.net/def/crs/OGC/1.3/CRS84\"" << endl;
1140 *strm << child_indent1 <<
"}" << endl;
1142 if(parameterCount > 1) {
1143 *strm << indent <<
"}]," << endl;
1146 *strm << indent <<
"}]" << endl;
1149 if(parameterCount == 1) {
1150 *strm << _indent_increment <<
"}," << endl;
1161 void FoDapCovJsonTransform::printParametersWorker(ostream *strm,
string indent)
1163 string child_indent1 = indent + _indent_increment;
1164 string child_indent2 = child_indent1 + _indent_increment;
1165 string child_indent3 = child_indent2 + _indent_increment;
1166 string child_indent4 = child_indent3 + _indent_increment;
1168 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing PARAMETERS" << endl);
1173 *strm << indent <<
"\"parameters\": {" << endl;
1174 for(
unsigned int i = 0; i < parameterCount; i++) {
1175 *strm << child_indent1 <<
"\"" << parameters[i]->name <<
"\": {" << endl;
1176 *strm << child_indent2 <<
"\"type\": \"Parameter\"," << endl;
1177 *strm << child_indent2 <<
"\"description\": {" << endl;
1179 if(parameters[i]->longName.compare(
"") != 0) {
1180 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->longName <<
"\"," << endl;
1182 else if(parameters[i]->standardName.compare(
"") != 0) {
1183 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->standardName <<
"\"" << endl;
1186 *strm << child_indent3 <<
"\"en\": \"" << parameters[i]->name <<
"\"" << endl;
1189 *strm << child_indent2 <<
"}," << endl;
1190 *strm << child_indent2 <<
"\"unit\": {" << endl;
1191 *strm << child_indent3 <<
"\"label\": {" << endl;
1192 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->unit <<
"\"" << endl;
1193 *strm << child_indent3 <<
"}" << endl;
1194 *strm << child_indent2 <<
"}," << endl;
1195 *strm << child_indent2 <<
"\"symbol\": {" << endl;
1196 *strm << child_indent3 <<
"\"value\": \"" << parameters[i]->unit <<
"\"," << endl;
1197 *strm << child_indent3 <<
"\"type\": \"http://www.opengis.net/def/uom/UCUM/\"" << endl;
1198 *strm << child_indent2 <<
"}," << endl;
1199 *strm << child_indent2 <<
"\"observedProperty\": {" << endl;
1205 if(parameters[i]->standardName.compare(
"") != 0) {
1206 *strm << child_indent3 <<
"\"id\": \"http://vocab.nerc.ac.uk/standard_name/" << parameters[i]->standardName <<
"/\"" << endl;
1214 *strm << child_indent3 <<
"\"label\": {" << endl;
1216 if(parameters[i]->longName.compare(
"") != 0) {
1217 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->longName <<
"\"" << endl;
1219 else if(parameters[i]->standardName.compare(
"") != 0) {
1220 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->standardName <<
"\"" << endl;
1223 *strm << child_indent4 <<
"\"en\": \"" << parameters[i]->name <<
"\"" << endl;
1226 *strm << child_indent3 <<
"}" << endl;
1227 *strm << child_indent2 <<
"}" << endl;
1229 if(i == parameterCount - 1) {
1230 *strm << child_indent1 <<
"}" << endl;
1233 *strm << child_indent1 <<
"}," << endl;
1236 if(parameterCount > 1) {
1237 *strm << indent <<
"}," << endl;
1251 void FoDapCovJsonTransform::printRangesWorker(ostream *strm,
string indent)
1253 string child_indent1 = indent + _indent_increment;
1254 string child_indent2 = child_indent1 + _indent_increment;
1255 string child_indent3 = child_indent2 + _indent_increment;
1258 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing RANGES" << endl);
1261 axisNames +=
"\"t\"";
1265 if(axisNames.length() > 0) {
1268 axisNames +=
"\"z\"";
1272 if(axisNames.length() > 0) {
1275 axisNames +=
"\"y\"";
1279 if(axisNames.length() > 0) {
1282 axisNames +=
"\"x\"";
1286 *strm << indent <<
"}," << endl;
1287 *strm << indent <<
"\"ranges\": {" << endl;
1288 for(
unsigned int i = 0; i < parameterCount; i++) {
1291 if(parameters[i]->dataType.find(
"int") == 0 || parameters[i]->dataType.find(
"Int") == 0
1292 || parameters[i]->dataType.find(
"integer") == 0 || parameters[i]->dataType.find(
"Integer") == 0) {
1293 dataType =
"integer";
1295 else if(parameters[i]->dataType.find(
"float") == 0 || parameters[i]->dataType.find(
"Float") == 0) {
1298 else if(parameters[i]->dataType.find(
"string") == 0 || parameters[i]->dataType.find(
"String") == 0) {
1299 dataType =
"string";
1302 dataType =
"string";
1307 *strm << child_indent1 <<
"\"" << parameters[i]->name <<
"\": {" << endl;
1308 *strm << child_indent2 <<
"\"type\": \"NdArray\"," << endl;
1309 *strm << child_indent2 <<
"\"dataType\": \"" << dataType <<
"\", " << endl;
1310 *strm << child_indent2 <<
"\"axisNames\": [" << axisNames <<
"]," << endl;
1311 *strm << child_indent2 << parameters[i]->shape << endl;
1312 *strm << child_indent2 << parameters[i]->values << endl;
1314 if(i == parameterCount - 1) {
1315 *strm << child_indent1 <<
"}" << endl;
1318 *strm << child_indent1 <<
"}," << endl;
1321 if(parameterCount == 1) {
1322 *strm << indent <<
"}" << endl;
1333 void FoDapCovJsonTransform::printCoverageFooterWorker(ostream *strm,
string indent)
1335 string child_indent1 = indent + _indent_increment;
1336 string child_indent2 = child_indent1 + _indent_increment;
1338 BESDEBUG(FoDapCovJsonTransform_debug_key,
"Printing COVERAGE FOOTER" << endl);
1340 if(parameterCount > 1) {
1341 *strm << child_indent2 <<
"}" << endl;
1342 *strm << child_indent1 <<
"}]" << endl;
1345 *strm << indent <<
"}" << endl;
1359 void FoDapCovJsonTransform::printCoverageJSON(ostream *strm,
string indent,
bool testOverride)
1361 string child_indent1 = indent + _indent_increment;
1362 string child_indent2 = child_indent1 + _indent_increment;
1363 string child_indent3 = child_indent2 + _indent_increment;
1369 canConvertToCovJson =
true;
1372 canConvertToCovJson = canConvert();
1376 if(canConvertToCovJson) {
1406 printCoverageHeaderWorker(strm, indent,
false);
1409 printAxesWorker(strm, child_indent2);
1412 printReferenceWorker(strm, child_indent2);
1415 printParametersWorker(strm, child_indent2);
1418 printRangesWorker(strm, child_indent1);
1421 printCoverageFooterWorker(strm, indent);
1426 throw BESInternalError(
"File cannot be converted to COVJSON format due to missing or incompatible spatial dimensions", __FILE__, __LINE__);
1446 void FoDapCovJsonTransform::transform(ostream *strm, libdap::DDS *dds,
string indent,
bool sendData,
bool testOverride)
1449 vector<libdap::BaseType *> leaves;
1450 vector<libdap::BaseType *> nodes;
1452 libdap::DDS::Vars_iter vi = dds->var_begin();
1453 libdap::DDS::Vars_iter ve = dds->var_end();
1454 for(; vi != ve; vi++) {
1455 if((*vi)->send_p()) {
1456 libdap::BaseType *v = *vi;
1458 if(type == libdap::dods_array_c) {
1459 type = v->var()->type();
1461 if(v->is_constructor_type() || (v->is_vector_type() && v->var()->is_constructor_type())) {
1465 leaves.push_back(v);
1472 transformNodeWorker(strm, leaves, nodes, indent + _indent_increment + _indent_increment, sendData);
1475 printCoverageJSON(strm, indent, testOverride);
1491 void FoDapCovJsonTransform::transform(ostream *strm, libdap::BaseType *bt,
string indent,
bool sendData)
1493 switch(bt->type()) {
1495 case libdap::dods_byte_c:
1496 case libdap::dods_int16_c:
1497 case libdap::dods_uint16_c:
1498 case libdap::dods_int32_c:
1499 case libdap::dods_uint32_c:
1500 case libdap::dods_float32_c:
1501 case libdap::dods_float64_c:
1502 case libdap::dods_str_c:
1503 case libdap::dods_url_c:
1504 transformAtomic(bt, indent, sendData);
1507 case libdap::dods_structure_c:
1508 transform(strm, (libdap::Structure *) bt, indent, sendData);
1511 case libdap::dods_grid_c:
1512 transform(strm, (libdap::Grid *) bt, indent, sendData);
1515 case libdap::dods_sequence_c:
1516 transform(strm, (libdap::Sequence *) bt, indent, sendData);
1519 case libdap::dods_array_c:
1520 transform(strm, (libdap::Array *) bt, indent, sendData);
1523 case libdap::dods_int8_c:
1524 case libdap::dods_uint8_c:
1525 case libdap::dods_int64_c:
1526 case libdap::dods_uint64_c:
1527 case libdap::dods_enum_c:
1528 case libdap::dods_group_c: {
1529 string s = (string)
"File out COVJSON, DAP4 types not yet supported.";
1535 string s = (string)
"File out COVJSON, Unrecognized type.";
1557 void FoDapCovJsonTransform::transformAtomic(libdap::BaseType *b,
string indent,
bool sendData)
1559 string childindent = indent + _indent_increment;
1560 struct Axis *newAxis =
new Axis;
1562 newAxis->name =
"test";
1564 newAxis->values +=
"\"values\": [";
1565 if(b->type() == libdap::dods_str_c || b->type() == libdap::dods_url_c) {
1566 libdap::Str *strVar = (libdap::Str *) b;
1567 string tmpString = strVar->value();
1568 newAxis->values +=
"\"";
1569 newAxis->values += focovjson::escape_for_covjson(tmpString);
1570 newAxis->values +=
"\"";
1573 ostringstream otemp;
1574 istringstream itemp;
1576 b->print_val(otemp,
"",
false);
1577 istringstream (otemp.str());
1578 istringstream (otemp.str()) >> tempVal;
1579 newAxis->values += otemp.str();
1581 newAxis->values +=
"]";
1584 newAxis->values +=
"\"values\": []";
1587 axes.push_back(newAxis);
1602 void FoDapCovJsonTransform::transform(ostream *strm, libdap::Array *a,
string indent,
bool sendData)
1604 BESDEBUG(FoDapCovJsonTransform_debug_key,
1605 "FoCovJsonTransform::transform() - Processing Array. " <<
" a->type(): " << a->type() <<
" a->var()->type(): " << a->var()->type() << endl);
1607 switch(a->var()->type()) {
1609 case libdap::dods_byte_c:
1610 covjsonSimpleTypeArray<libdap::dods_byte>(strm, a, indent, sendData);
1613 case libdap::dods_int16_c:
1614 covjsonSimpleTypeArray<libdap::dods_int16>(strm, a, indent, sendData);
1617 case libdap::dods_uint16_c:
1618 covjsonSimpleTypeArray<libdap::dods_uint16>(strm, a, indent, sendData);
1621 case libdap::dods_int32_c:
1622 covjsonSimpleTypeArray<libdap::dods_int32>(strm, a, indent, sendData);
1625 case libdap::dods_uint32_c:
1626 covjsonSimpleTypeArray<libdap::dods_uint32>(strm, a, indent, sendData);
1629 case libdap::dods_float32_c:
1630 covjsonSimpleTypeArray<libdap::dods_float32>(strm, a, indent, sendData);
1633 case libdap::dods_float64_c:
1634 covjsonSimpleTypeArray<libdap::dods_float64>(strm, a, indent, sendData);
1637 case libdap::dods_str_c: {
1638 covjsonStringArray(strm, a, indent, sendData);
1642 case libdap::dods_url_c: {
1643 covjsonStringArray(strm, a, indent, sendData);
1647 case libdap::dods_structure_c:
1648 throw BESInternalError(
"File out COVJSON, Arrays of Structure objects not a supported return type.", __FILE__, __LINE__);
1650 case libdap::dods_grid_c:
1651 throw BESInternalError(
"File out COVJSON, Arrays of Grid objects not a supported return type.", __FILE__, __LINE__);
1653 case libdap::dods_sequence_c:
1654 throw BESInternalError(
"File out COVJSON, Arrays of Sequence objects not a supported return type.", __FILE__, __LINE__);
1656 case libdap::dods_array_c:
1657 throw BESInternalError(
"File out COVJSON, Arrays of Array objects not a supported return type.", __FILE__, __LINE__);
1659 case libdap::dods_int8_c:
1660 case libdap::dods_uint8_c:
1661 case libdap::dods_int64_c:
1662 case libdap::dods_uint64_c:
1663 case libdap::dods_enum_c:
1664 case libdap::dods_group_c:
1665 throw BESInternalError(
"File out COVJSON, DAP4 types not yet supported.", __FILE__, __LINE__);
1668 throw BESInternalError(
"File out COVJSON, Unrecognized type.", __FILE__, __LINE__);
exception thrown if inernal error encountered