bes  Updated for version 3.20.5
CSVDAS.cc
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 #include <memory>
37 
38 #include "CSVDAS.h"
39 
40 #include "DAS.h"
41 #include "Error.h"
42 
43 #include "CSV_Obj.h"
44 
45 #include <BESNotFoundError.h>
46 #include <BESDebug.h>
47 
48 void csv_read_attributes(DAS &das, const string &filename)
49 {
50 #if 0
51  AttrTable *attr_table_ptr = NULL;
52  string type;
53 #endif
54 
55 #if 0
56  CSV_Obj* csvObj = new CSV_Obj();
57 #endif
58 
59  auto_ptr<CSV_Obj> csvObj(new CSV_Obj);
60 
61  if (!csvObj->open(filename)) {
62 #if 0
63  string err = (string) "Unable to open file " + filename;
64  delete csvObj;
65 #endif
66 
67  throw BESNotFoundError(string("Unable to open file ").append(filename), __FILE__, __LINE__);
68  }
69 
70  csvObj->load();
71 
72  BESDEBUG( "csv", "File Loaded:" << endl << *csvObj << endl );
73 
74  vector<string> fieldList;
75  csvObj->getFieldList(fieldList);
76 
77  //loop through all the fields
78  vector<string>::iterator it = fieldList.begin();
79  vector<string>::iterator et = fieldList.end();
80  for (; it != et; it++) {
81  AttrTable *attr_table_ptr = das.get_table((string(*it)).c_str());
82 
83  if (!attr_table_ptr) attr_table_ptr = das.add_table(string(*it), new AttrTable);
84 
85  //only one attribute, field type, called "type"
86  string type = csvObj->getFieldType(*it);
87  attr_table_ptr->append_attr("type", "String", type);
88  }
89 
90 #if 0
91  delete csvObj;
92 #endif
93 
94 }
95 
BESNotFoundError
error thrown if the resource requested cannot be found
Definition: BESNotFoundError.h:40
CSV_Obj
Definition: CSV_Obj.h:49