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