OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
CSVDAS.cc
Go to the documentation of this file.
1 // CSVDAS.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Stephan Zednik <zednik@ucar.edu> and Patrick West <pwest@ucar.edu>
8 // and Jose Garcia <jgarcia@ucar.edu>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact University Corporation for Atmospheric Research at
25 // 3080 Center Green Drive, Boulder, CO 80301
26 
27 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
28 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
29 //
30 // Authors:
31 // zednik Stephan Zednik <zednik@ucar.edu>
32 // pwest Patrick West <pwest@ucar.edu>
33 // jgarcia Jose Garcia <jgarcia@ucar.edu>
34 
35 #include <vector>
36 
37 #include "CSVDAS.h"
38 
39 #include "DAS.h"
40 #include "Error.h"
41 
42 #include "CSV_Obj.h"
43 
44 #include <BESNotFoundError.h>
45 #include <BESDebug.h>
46 
47 void
48 csv_read_attributes(DAS &das, const string &filename)
49 {
50  AttrTable *attr_table_ptr = NULL ;
51  string type ;
52 
53  CSV_Obj* csvObj = new CSV_Obj() ;
54  if( !csvObj->open( filename ) )
55  {
56  string err = (string)"Unable to open file " + filename ;
57  delete csvObj;
58  throw BESNotFoundError( err, __FILE__, __LINE__ ) ;
59  }
60  csvObj->load() ;
61 
62  BESDEBUG( "csv", "File Loaded:" << endl << *csvObj << endl ) ;
63 
64  vector<string> fieldList ;
65  csvObj->getFieldList( fieldList ) ;
66 
67  //loop through all the fields
68  vector<string>::iterator it = fieldList.begin() ;
69  vector<string>::iterator et = fieldList.end() ;
70  for( ; it != et; it++)
71  {
72  attr_table_ptr = das.get_table((string(*it)).c_str());
73 
74  if( !attr_table_ptr )
75  attr_table_ptr =
76  das.add_table(string(*it), new AttrTable);
77 
78  //only one attribute, field type, called "type"
79  type = csvObj->getFieldType(*it);
80  attr_table_ptr->append_attr( "type", type, type ) ;
81  }
82 
83  delete csvObj;
84 }
85 
error thrown if the resource requested cannot be found
#define NULL
Definition: wcsUtil.h:65
bool open(const string &filepath)
Definition: CSV_Obj.cc:79
void csv_read_attributes(DAS &das, const string &filename)
Definition: CSVDAS.cc:48
void load()
Definition: CSV_Obj.cc:84
string getFieldType(const string &fieldName)
Definition: CSV_Obj.cc:127
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
void getFieldList(vector< string > &list)
Definition: CSV_Obj.cc:122