BLQDataReader.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: BLQDataReader.cpp 1717 2009-02-22 10:42:34Z architest $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2007, 2009
00027 //
00028 //============================================================================
00029 
00030 
00031 
00032 
00033 #include "BLQDataReader.hpp"
00034 
00035 
00036 
00037 namespace gpstk
00038 {
00039 
00040       // Method to store load ocean tide harmonics data in this class'
00041       // data map
00042    void BLQDataReader::loadData(void)
00043       throw( FFStreamError, gpstk::StringUtils::StringException )
00044    {
00045 
00046          // Counter of valid data lines
00047       int row(0);
00048 
00049          // We will store here the station name
00050       string nameString("");
00051 
00052          // Declare structure to store tide harmonics data
00053       BLQDataReader::tideData data;
00054 
00055          // Do this until end-of-file reached or something else happens
00056       while(1)
00057       {
00058 
00059          try
00060          {
00061 
00062             if(row>6)
00063             {
00064                   // If row>6, all station harmonics are already read,
00065                   // so let's store tide data in data map
00066                setData(nameString, data);
00067 
00068                   // Clear harmonics data
00069                data.harmonics.resize(6,11,0.0);
00070 
00071                   // Reset counter to get data from an additional station
00072                row = 0;
00073             }
00074 
00075             std::string line;
00076 
00077             formattedGetLine(line, true);
00078 
00079                // If line is too long, we throw an exception
00080             if (line.size()>255)
00081             {
00082                FFStreamError e("Line too long");
00083                GPSTK_THROW(e);
00084             }
00085 
00086                // Let's find and strip comments, wherever they are
00087             if( StringUtils::firstWord(line)[0] == '$' )
00088             {
00089                formattedGetLine(line, true);
00090             }
00091 
00092             std::string::size_type idx = line.find('$');
00093             if( !(idx == std::string::npos) )
00094             {
00095                line = line.substr(0, idx);
00096             }
00097 
00098                // Remove trailing and leading blanks
00099             line = StringUtils::strip(line);
00100 
00101                // Skip blank lines
00102             if (line.size()==0)
00103             {
00104                continue;
00105             }
00106 
00107                // Let's start to get data out of file
00108                // If this is the first valid line, it contains station name
00109             if (row==0)
00110             {
00111 
00112                nameString =
00113                   StringUtils::upperCase(StringUtils::stripFirstWord(line));
00114 
00115                ++row;
00116 
00117                continue;
00118 
00119             }
00120             else
00121             {
00122 
00123                   // 2nd to 7th valid lines contains tide harmonics
00124                if ( (row>0) && (row<=6) )
00125                {
00126                   for(int col=0; col<11; col++)
00127                   {
00128                      string value(StringUtils::stripFirstWord(line));
00129                      data.harmonics((row-1),col) = StringUtils::asDouble(value);
00130                   }
00131                   ++row;
00132                   continue;
00133                }
00134             }
00135 
00136          }  // End of try block
00137          catch (EndOfFile& e)
00138          {
00139 
00140                // We should close this data stream before returning
00141             (*this).close();
00142 
00143             return;
00144          }
00145          catch (...)
00146          {
00147 
00148                // We should close this data stream before returning
00149             (*this).close();
00150 
00151             return;
00152 
00153          }
00154 
00155       }  // End of 'while(1)...'
00156 
00157    }  // End of method 'BLQDataReader::loadData()'
00158 
00159 
00160 
00161       // Method to open AND load ocean tide harmonics data file. It doesn't
00162       // clear data previously loaded.
00163    void BLQDataReader::open(const char* fn)
00164    {
00165 
00166          // We need to be sure current data stream is closed
00167       (*this).close();
00168 
00169          // Open data stream
00170       FFTextStream::open(fn, std::ios::in);
00171       loadData();
00172 
00173       return;
00174    }  // End of method 'BLQDataReader::open()'
00175 
00176 
00177 
00178       // Method to open AND load ocean tide harmonics data file. It doesn't
00179       // clear data previously loaded.
00180    void BLQDataReader::open(const string& fn)
00181    {
00182 
00183          // We need to be sure current data stream is closed
00184       (*this).close();
00185 
00186          // Open data stream
00187       FFTextStream::open(fn.c_str(), std::ios::in);
00188       loadData();
00189 
00190       return;
00191    }  // End of method 'BLQDataReader::open()'
00192 
00193 
00194 
00195       /* Method to get the ocean tide harmonics corresponding to a
00196        * given station.
00197        *
00198        * @param station   Station name (case is NOT relevant).
00199        *
00200        * @return A Matrix<double> of siw rows and eleven columns
00201        * containing tide harmonics M2, S2, N2, K2, K1, O1, P1, Q1, MF,
00202        * MM and SSA for amplitudes (radial, west, south, in meters) and
00203        * phases (radial, west, south, in degrees). If station is
00204        * not found, this method will return a matrix full of zeros.
00205        */
00206    Matrix<double> BLQDataReader::getTideHarmonics(const string& station)
00207    {
00208 
00209          // First, look if such station exist in data map
00210       tideDataIt iter( OceanTidesData.find( StringUtils::upperCase(station) ) );
00211       if ( iter != OceanTidesData.end() )
00212       {
00213             // if found, return corresponding harmonics matrix
00214          return (*iter).second.harmonics;
00215       }
00216       else
00217       {
00218             // If not, return an empty harmonics matrix
00219          Matrix<double> dummy(6,11,0.0);
00220          return dummy;
00221       };
00222 
00223    }  // End of method 'BLQDataReader::getTideHarmonics()'
00224 
00225 
00226 
00227 }  // End of namespace gpstk
00228 

Generated on Wed Feb 8 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1