00001 #pragma ident "$Id: BLQDataReader.cpp 1717 2009-02-22 10:42:34Z architest $"
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "BLQDataReader.hpp"
00034
00035
00036
00037 namespace gpstk
00038 {
00039
00040
00041
00042 void BLQDataReader::loadData(void)
00043 throw( FFStreamError, gpstk::StringUtils::StringException )
00044 {
00045
00046
00047 int row(0);
00048
00049
00050 string nameString("");
00051
00052
00053 BLQDataReader::tideData data;
00054
00055
00056 while(1)
00057 {
00058
00059 try
00060 {
00061
00062 if(row>6)
00063 {
00064
00065
00066 setData(nameString, data);
00067
00068
00069 data.harmonics.resize(6,11,0.0);
00070
00071
00072 row = 0;
00073 }
00074
00075 std::string line;
00076
00077 formattedGetLine(line, true);
00078
00079
00080 if (line.size()>255)
00081 {
00082 FFStreamError e("Line too long");
00083 GPSTK_THROW(e);
00084 }
00085
00086
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
00099 line = StringUtils::strip(line);
00100
00101
00102 if (line.size()==0)
00103 {
00104 continue;
00105 }
00106
00107
00108
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
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 }
00137 catch (EndOfFile& e)
00138 {
00139
00140
00141 (*this).close();
00142
00143 return;
00144 }
00145 catch (...)
00146 {
00147
00148
00149 (*this).close();
00150
00151 return;
00152
00153 }
00154
00155 }
00156
00157 }
00158
00159
00160
00161
00162
00163 void BLQDataReader::open(const char* fn)
00164 {
00165
00166
00167 (*this).close();
00168
00169
00170 FFTextStream::open(fn, std::ios::in);
00171 loadData();
00172
00173 return;
00174 }
00175
00176
00177
00178
00179
00180 void BLQDataReader::open(const string& fn)
00181 {
00182
00183
00184 (*this).close();
00185
00186
00187 FFTextStream::open(fn.c_str(), std::ios::in);
00188 loadData();
00189
00190 return;
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 Matrix<double> BLQDataReader::getTideHarmonics(const string& station)
00207 {
00208
00209
00210 tideDataIt iter( OceanTidesData.find( StringUtils::upperCase(station) ) );
00211 if ( iter != OceanTidesData.end() )
00212 {
00213
00214 return (*iter).second.harmonics;
00215 }
00216 else
00217 {
00218
00219 Matrix<double> dummy(6,11,0.0);
00220 return dummy;
00221 };
00222
00223 }
00224
00225
00226
00227 }
00228