MSCData.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: MSCData.cpp 2453 2010-08-13 17:22:09Z afarris $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //  
00021 //  Copyright 2004, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 //============================================================================
00026 //
00027 //This software developed by Applied Research Laboratories at the University of
00028 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00029 //Department of Defense. The U.S. Government retains all rights to use,
00030 //duplicate, distribute, disclose, or release this software. 
00031 //
00032 //Pursuant to DoD Directive 523024 
00033 //
00034 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00035 //                           release, distribution is unlimited.
00036 //
00037 //=============================================================================
00038 
00039 
00045 #include <math.h>
00046 #include "MSCData.hpp"
00047 #include "MSCStream.hpp"
00048 
00049 using namespace gpstk::StringUtils;
00050 using namespace std;
00051 
00052 namespace gpstk
00053 {
00054 
00055    static const unsigned long SEC_YEAR = 
00056    static_cast<unsigned long>(365.25 * gpstk::DayTime::SEC_DAY);
00057 
00058    void MSCData::reallyPutRecord(gpstk::FFStream & ffs) const
00059       throw(std::exception, gpstk::FFStreamError, StringException)
00060    {
00061       MSCStream& strm = dynamic_cast<MSCStream&>(ffs);
00062       
00063       string line;
00064 
00065       if ( time == DayTime::BEGINNING_OF_TIME )
00066       {
00067          line += string(7, ' ');
00068       }
00069       else
00070       {
00071          line += rightJustify(asString<short>(time.DOYyear()), 4);
00072          line += rightJustify(asString<short>(time.DOYday()), 3 , '0');
00073       }
00074       line += rightJustify(asString<long>(station), 5);
00075       line += leftJustify(mnemonic, 7);
00076       if ( refepoch == DayTime::BEGINNING_OF_TIME )
00077       {
00078          line += string(14, ' ');
00079       }
00080       else
00081       {
00082          line += rightJustify(asString<short>(refepoch.DOYyear()), 4);
00083          line += " ";
00084          line += rightJustify(asString<short>(refepoch.DOYday()), 3, '0');
00085          line += " ";
00086          line += rightJustify(asString<long>(refepoch.DOYsecond()), 5, '0');
00087       }
00088       if ( effepoch == DayTime::BEGINNING_OF_TIME )
00089       {
00090          line += string(14, ' ');
00091       }
00092       else
00093       {
00094          line += rightJustify(asString<short>(effepoch.DOYyear()), 4);
00095          line += " ";
00096          line += rightJustify(asString<short>(effepoch.DOYday()), 3, '0');
00097          line += " ";
00098          line += rightJustify(asString<long>(effepoch.DOYsecond()), 5, '0');
00099       }
00100       line += rightJustify(asString(coordinates[0], 3), 12);
00101       line += rightJustify(asString(coordinates[1], 3), 12);
00102       line += rightJustify(asString(coordinates[2], 3), 12);
00103       line += rightJustify(asString(velocities[0], 4), 7);            
00104       line += rightJustify(asString(velocities[1], 4), 7);
00105       line += rightJustify(asString(velocities[2], 4), 7);
00106       
00107       ffs << line << endl;
00108       strm.lineNumber++;
00109    }
00110 
00111    void MSCData::reallyGetRecord(gpstk::FFStream& ffs)
00112       throw(std::exception, gpstk::FFStreamError,
00113             gpstk::StringUtils::StringException)
00114    {
00115       MSCStream& strm = dynamic_cast<MSCStream&>(ffs);
00116 
00117       string currentLine;
00118       
00119       strm.formattedGetLine(currentLine, true);
00120       int len = currentLine.length(); //90 for old; 104 for new
00121 
00122       if(len == 90) //old format
00123       {
00124          short year = asInt(currentLine.substr(0, 4));
00125          short day =  asInt(currentLine.substr(4, 3));
00126          time.setYDoySod(year, day, 0.0);
00127 
00128          station = asInt(currentLine.substr(7, 5));
00129          mnemonic = currentLine.substr(12, 7);
00130 
00131          double epoch, intg, frac, sod;
00132          short doy;
00133          // can't have DOY 0, so use doy + 1 when generating times
00134          epoch = asDouble(currentLine.substr(19, 7));
00135          frac = modf(epoch, &intg);
00136          doy = (short)(frac * SEC_YEAR / gpstk::DayTime::SEC_DAY);
00137          sod = (frac * SEC_YEAR) - (doy * gpstk::DayTime::SEC_DAY);
00138          refepoch = gpstk::DayTime((short)intg, doy+1, sod);
00139          
00140          epoch = asDouble(currentLine.substr(26, 7));
00141          frac = modf(epoch, &intg);
00142          doy = (short)(frac * SEC_YEAR / gpstk::DayTime::SEC_DAY);
00143          sod = (frac * SEC_YEAR) - (doy * gpstk::DayTime::SEC_DAY);
00144          effepoch = gpstk::DayTime((short)intg, doy+1, sod);
00145          
00146          coordinates[0] = asDouble(currentLine.substr(33, 12));
00147          coordinates[1] = asDouble(currentLine.substr(45, 12));
00148          coordinates[2] = asDouble(currentLine.substr(57, 12));
00149          
00150          velocities[0] = asDouble(currentLine.substr(69, 7));
00151          velocities[1] = asDouble(currentLine.substr(76, 7));
00152          velocities[2] = asDouble(currentLine.substr(83, 7));
00153       }
00154       else if(len == 104) //new format
00155       {
00156          if  ( ( currentLine.substr(0, 4) == string(' ', 4) ) ||
00157                ( currentLine.substr(4, 3) == string(' ', 3) ) ||
00158                ( asInt(currentLine.substr(0, 4)) == 0 )       ||
00159                ( asInt(currentLine.substr(4, 3)) == 0 ) )
00160          {
00161             time = DayTime::BEGINNING_OF_TIME;
00162          }
00163          else
00164          {
00165             time = DayTime( (short)asInt(currentLine.substr(0, 4)),
00166                             (short)asInt(currentLine.substr(4, 3)),
00167                             (double)0.0 );
00168          }
00169          
00170          station = asInt(currentLine.substr(7, 5));
00171          mnemonic = currentLine.substr(12, 7);
00172 
00173          if ( ( currentLine.substr(19, 4) == string(' ', 4) ) ||
00174               ( currentLine.substr(24, 3) == string(' ', 3) ) ||
00175               ( asInt(currentLine.substr(19, 4)) == 0 )       ||
00176               ( asInt(currentLine.substr(24, 3)) == 0 ) )
00177          {
00178             refepoch = DayTime::BEGINNING_OF_TIME;
00179          }
00180          else
00181          {
00182             refepoch = DayTime( (short)asInt(currentLine.substr(19, 4)),
00183                                 (short)asInt(currentLine.substr(24, 3)),
00184                                 asDouble(currentLine.substr(28,5)) );
00185          }
00186          if ( ( currentLine.substr(33, 4) == string(' ', 4) ) ||
00187               ( currentLine.substr(38, 3) == string(' ', 3) ) ||
00188               ( asInt(currentLine.substr(33, 4)) == 0 )       ||
00189               ( asInt(currentLine.substr(38, 3)) == 0 ) )
00190          {
00191             effepoch = DayTime::BEGINNING_OF_TIME;
00192          }
00193          else
00194          {
00195             effepoch = DayTime( (short)asInt(currentLine.substr(33, 4)),
00196                                 (short)asInt(currentLine.substr(38, 3)),
00197                                 asDouble(currentLine.substr(42,5)) );
00198          }
00199 
00200          coordinates[0] = asDouble(currentLine.substr(47, 12));
00201          coordinates[1] = asDouble(currentLine.substr(59, 12));
00202          coordinates[2] = asDouble(currentLine.substr(71, 12));
00203             
00204          velocities[0] = asDouble(currentLine.substr(83, 7));
00205          velocities[1] = asDouble(currentLine.substr(90, 7));
00206          velocities[2] = asDouble(currentLine.substr(97, 7));
00207       }
00208       else //non-valid or unreadable coords file format
00209       {
00210       }
00211    }
00212 
00213    Xvt MSCData::getXvt(const DayTime& t)
00214       const throw(InvalidRequest)
00215    {
00216       try
00217       {
00218          //
00219          // Calculate the elapsed time between the reference time
00220          // and the time of interest in order to determine the 
00221          // total station drift.
00222          double dt = (t - refepoch) / SEC_YEAR;
00223          Xvt xvt;
00224          xvt.x = coordinates;
00225          xvt.v = velocities;
00226          xvt.dtime = 0.0;
00227          xvt.ddtime = 0.0;
00228          const Triple& drift = velocities;
00229       
00230             // compute the position given the total drift vectors
00231          xvt.x[0] += drift[0] * dt;
00232          xvt.x[1] += drift[1] * dt;
00233          xvt.x[2] += drift[2] * dt;
00234          return( xvt );
00235       }
00236       catch(InvalidRequest& ir)
00237       {
00238          GPSTK_RETHROW(ir);
00239       }
00240    } // end of MSCData::getXvt()
00241 
00242 
00243 }

Generated on Wed Sep 8 03:30:55 2010 for GPS ToolKit Software Library by  doxygen 1.3.9.1