bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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 namespace std;
49
50void csv_read_attributes(DAS &das, const string &filename)
51{
52 unique_ptr<CSV_Obj> csvObj(new CSV_Obj);
53
54 if (!csvObj->open(filename)) {
55 throw BESNotFoundError(string("Unable to open file ").append(filename), __FILE__, __LINE__);
56 }
57
58 csvObj->load();
59
60 BESDEBUG( "csv", "File Loaded:" << endl << *csvObj << endl );
61
62 vector<string> fieldList;
63 csvObj->getFieldList(fieldList);
64
65 for (const auto &field: fieldList) {
66 AttrTable *attr_table_ptr = das.get_table(field.c_str());
67
68 if (!attr_table_ptr) attr_table_ptr = das.add_table(field, new AttrTable);
69
70 //only one attribute, field type, called "type"
71 string type = csvObj->getFieldType(field);
72 attr_table_ptr->append_attr("type", "String", type);
73 }
74}
75
error thrown if the resource requested cannot be found