41#include <BESInternalError.h>
42#include <BESNotFoundError.h>
43#include <libdap/BaseTypeFactory.h>
44#include <libdap/DDS.h>
45#include <libdap/Error.h>
47#include <libdap/Str.h>
48#include <libdap/Int16.h>
49#include <libdap/Int32.h>
50#include <libdap/Float32.h>
51#include <libdap/Float64.h>
52#include <libdap/mime_util.h>
54#include <libdap/Array.h>
58void csv_read_descriptors(DDS &dds,
const string &filename)
68 if (!csvObj->open(filename)) {
70 string err = (string)
"Unable to open file " + filename;
75 BESDEBUG(
"csv",
"File loaded:" << endl << *csvObj << endl );
77 dds.set_dataset_name(name_path(filename));
80 csvObj->getFieldList(fieldList);
81 int recordCount = csvObj->getRecordCount();
83 throw BESError(
"Could not read record count from the CSV dataset.", BES_NOT_FOUND_ERROR, __FILE__, __LINE__);
87 for (; it != et; it++) {
88 string fieldName = (*it);
89 type = csvObj->getFieldType(fieldName);
90 ar = dds.get_factory()->NewArray(fieldName);
91 data = csvObj->getFieldData(fieldName);
93 if (type.compare(
string(STRING)) == 0) {
94 string* strings =
new string[recordCount];
96 bt = dds.get_factory()->NewStr(fieldName);
98 ar->append_dim(recordCount,
"record");
103 for (; iv != ev; iv++) {
104 strings[index] = *iv;
108 ar->set_value(strings, recordCount);
111 else if (type.compare(
string(INT16)) == 0) {
112 short* int16 =
new short[recordCount];
113 bt = dds.get_factory()->NewInt16(fieldName);
115 ar->append_dim(recordCount,
"record");
120 for (; iv != ev; iv++) {
125 ar->set_value(int16, recordCount);
128 else if (type.compare(
string(INT32)) == 0) {
129 int *int32 =
new int[recordCount];
130 bt = dds.get_factory()->NewInt32(fieldName);
132 ar->append_dim(recordCount,
"record");
137 for (; iv != ev; iv++) {
142 ar->set_value((dods_int32*) int32, recordCount);
145 else if (type.compare(
string(FLOAT32)) == 0) {
146 float *floats =
new float[recordCount];
147 bt = dds.get_factory()->NewFloat32(fieldName);
149 ar->append_dim(recordCount,
"record");
154 for (; iv != ev; iv++) {
159 ar->set_value(floats, recordCount);
162 else if (type.compare(
string(FLOAT64)) == 0) {
163 double *doubles =
new double[recordCount];
164 bt = dds.get_factory()->NewFloat64(fieldName);
166 ar->append_dim(recordCount,
"record");
171 for (; iv != ev; iv++) {
172 doubles[index] = *iv;
176 ar->set_value(doubles, recordCount);
181 string err = (string)
"Unknown type for field " + fieldName;
Base exception class for the BES with basic string message.
exception thrown if internal error encountered
error thrown if the resource requested cannot be found