43 #include <BaseTypeFactory.h>
52 #include <mime_util.h>
70 if( !csvObj->
open( filename ) )
73 string err = (string)
"Unable to open file " + filename ;
78 BESDEBUG(
"csv",
"File loaded:" << endl << *csvObj << endl ) ;
80 dds.set_dataset_name( name_path( filename ) ) ;
82 vector<string> fieldList;
86 vector<string>::iterator it = fieldList.begin() ;
87 vector<string>::iterator et = fieldList.end() ;
88 for( ; it != et; it++ )
90 string fieldName = (*it) ;
92 ar = dds.get_factory()->NewArray( fieldName ) ;
95 if( type.compare(
string( STRING ) ) == 0 )
97 string* strings =
new string[recordCount] ;
99 bt = dds.get_factory()->NewStr( fieldName ) ;
101 ar->append_dim( recordCount,
"record" ) ;
104 vector<string>::iterator iv = ((vector<string>*)data)->begin() ;
105 vector<string>::iterator ev = ((vector<string>*)data)->end() ;
106 for( ; iv != ev; iv++)
108 strings[index] = *iv ;
112 ar->set_value( strings, recordCount ) ;
115 else if( type.compare(
string( INT16 ) ) == 0 )
117 short* int16 =
new short[recordCount] ;
118 bt = dds.get_factory()->NewInt16( fieldName ) ;
120 ar->append_dim( recordCount,
"record" ) ;
123 vector<short>::iterator iv = ((vector<short>*)data)->begin() ;
124 vector<short>::iterator ev = ((vector<short>*)data)->end() ;
125 for( ; iv != ev; iv++)
131 ar->set_value( int16, recordCount ) ;
134 else if( type.compare(
string( INT32 ) ) == 0 )
136 int *int32 =
new int[recordCount] ;
137 bt = dds.get_factory()->NewInt32( fieldName ) ;
139 ar->append_dim( recordCount,
"record" ) ;
142 vector<int>::iterator iv = ((vector<int>*)data)->begin() ;
143 vector<int>::iterator ev = ((vector<int>*)data)->end() ;
144 for( ; iv != ev; iv++)
150 ar->set_value( (dods_int32*)int32, recordCount ) ;
153 else if( type.compare(
string( FLOAT32 ) ) == 0 )
155 float *floats =
new float[recordCount] ;
156 bt = dds.get_factory()->NewFloat32( fieldName ) ;
158 ar->append_dim( recordCount,
"record" ) ;
161 vector<float>::iterator iv = ((vector<float>*)data)->begin() ;
162 vector<float>::iterator ev = ((vector<float>*)data)->end() ;
163 for( ; iv != ev; iv++)
165 floats[index] = *iv ;
169 ar->set_value( floats, recordCount ) ;
172 else if( type.compare(
string( FLOAT64 ) ) == 0 )
174 double *doubles =
new double[recordCount] ;
175 bt = dds.get_factory()->NewFloat64( fieldName ) ;
177 ar->append_dim( recordCount,
"record" ) ;
180 vector<double>::iterator iv = ((vector<double>*)data)->begin() ;
181 vector<double>::iterator ev = ((vector<double>*)data)->end() ;
182 for( ; iv != ev; iv++)
184 doubles[index] = *iv;
188 ar->set_value( doubles, recordCount ) ;
194 string err = (string)
"Unknown type for field " + fieldName ;
error thrown if the resource requested cannot be found
exception thrown if inernal error encountered
void * getFieldData(const string &field)
bool open(const string &filepath)
void csv_read_descriptors(DDS &dds, const string &filename)
string getFieldType(const string &fieldName)
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
void getFieldList(vector< string > &list)