main.cc

Go to the documentation of this file.
00001 // main.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<iostream>
00036 #include"CSV_Obj.h"
00037 
00038 using namespace std;
00039 
00040 #define EXIT_ERROR 1
00041 
00042 void printHeader(CSV_Obj* foo);
00043 void printAllData(CSV_Obj* foo);
00044 
00045 int main(int argc, char* argv[]) {
00046   
00047   CSV_Obj* foo = new CSV_Obj();
00048   char* filepath;
00049   
00050   if(argc > 1) { 
00051     filepath = argv[1]; 
00052   } else { 
00053     filepath = "/Users/zednik/data/temperature.csv"; 
00054   }
00055   
00056   if (!foo->open(filepath)) {  
00057     cout << "Could not open .CSV file." << endl; 
00058     return EXIT_ERROR;
00059   }
00060 
00061   foo->load();
00062   printHeader(foo);
00063   printAllData(foo);
00064 
00065   delete foo;
00066   return EXIT_SUCCESS;
00067 }
00068 
00069 void printAllData(CSV_Obj* foo) {
00070   int count = foo->getRecordCount();
00071   for(int index = 0; index < count; index++) {
00072     string recStr;
00073     vector<string> rec = foo->getRecord(index);
00074     for(vector<string>::iterator it = rec.begin(); it != rec.end(); it++) {
00075       recStr += *it + ", ";
00076     }
00077     recStr = recStr.substr(0, recStr.length() - 2);
00078     cout << recStr << endl;
00079   }
00080 }
00081 
00082 void printHeader(CSV_Obj* foo) {
00083   string FL = "Field List: ";
00084   vector<string> fList = foo->getFieldList();
00085   for(vector<string>::iterator it = fList.begin(); it != fList.end(); it++) {
00086     FL += *it + ", ";
00087   }
00088   FL = FL.substr(0, FL.length() - 2);
00089   cout << FL << endl;
00090 }

Generated on Tue May 11 20:02:06 2010 for OPeNDAP Hyrax Back End Server (BES) by  doxygen 1.4.7