CSVDAS.cc

Go to the documentation of this file.
00001 // CSVDAS.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Stephan Zednik <zednik@ucar.edu> and Patrick West <pwest@ucar.edu>
00008 // and Jose Garcia <jgarcia@ucar.edu>
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 // 
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact University Corporation for Atmospheric Research at
00025 // 3080 Center Green Drive, Boulder, CO 80301
00026  
00027 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00028 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00029 //
00030 // Authors:
00031 //      zednik      Stephan Zednik <zednik@ucar.edu>
00032 //      pwest       Patrick West <pwest@ucar.edu>
00033 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00034 
00035 #include <vector>
00036 
00037 #include "CSVDAS.h"
00038 
00039 #include "DAS.h"
00040 #include "Error.h"
00041 
00042 #include "CSV_Obj.h"
00043 
00044 void csv_read_attributes(DAS &das, const string &filename) throw(Error) {
00045 
00046   vector<string> fieldList;
00047   AttrTable *attr_table_ptr = NULL;
00048   string type;
00049 
00050   CSV_Obj* csvObj = new CSV_Obj();
00051   csvObj->open(filename);  //on fail, throw error
00052   csvObj->load(); //on fail, throw error
00053   
00054   fieldList = csvObj->getFieldList();
00055   
00056   //loop through all the fields
00057   for(vector<string>::iterator it = fieldList.begin(); it != fieldList.end(); it++) {
00058 
00059     attr_table_ptr = das.get_table((string(*it)).c_str());
00060 
00061     if(!attr_table_ptr)
00062       attr_table_ptr = das.add_table((string(*it)).c_str(), new AttrTable);
00063     
00064     //only one attribute, field type, called "type"
00065     type = csvObj->getFieldType(*it);
00066     attr_table_ptr->append_attr("type",type,type);
00067   }
00068 
00069   delete csvObj;
00070 }

Generated on 27 Oct 2009 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.6.1