00001 #pragma ident "$Id: SEMHeader.cpp 2741 2011-06-22 16:37:02Z nwu $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #include "StringUtils.hpp"
00031 #include "icd_200_constants.hpp"
00032
00033 #include "SEMHeader.hpp"
00034 #include "SEMStream.hpp"
00035
00036
00037 using namespace gpstk::StringUtils;
00038 using namespace std;
00039
00040 namespace gpstk
00041 {
00042 short SEMHeader::nearFullWeek = 0;
00043
00044 void SEMHeader::reallyPutRecord(FFStream& ffs) const
00045 throw(std::exception, FFStreamError,
00046 gpstk::StringUtils::StringException)
00047 {
00048 string line;
00049
00050 SEMStream& strm = dynamic_cast<SEMStream&>(ffs);
00051
00052 line = leftJustify(asString<short>(numRecords),2);
00053 line += " ";
00054 line += Title;
00055 strm << line << endl;
00056 line.erase();
00057
00058 line = rightJustify(asString<short>(week),4);
00059 line += " ";
00060 line += asString<long>(Toa);
00061 strm << line << endl;
00062 line.erase();
00063
00064 }
00065
00066
00067 void SEMHeader::reallyGetRecord(FFStream& ffs)
00068 throw(std::exception, FFStreamError,
00069 gpstk::StringUtils::StringException)
00070 {
00071 string line;
00072
00073 SEMStream& strm = dynamic_cast<SEMStream&>(ffs);
00074
00075
00076 strm.formattedGetLine(line);
00077
00078 numRecords = (short) asInt(line.substr(0,2));
00079 Title = line.substr(3,24);
00080
00081
00082 strm.formattedGetLine(line);
00083 week = (short) asInt(line.substr(0,4));
00084 Toa = asInt(line.substr(5,6));
00085
00086 if (nearFullWeek > 0)
00087 {
00088
00089 week %= 1024;
00090 week += (nearFullWeek / 1024) * 1024;
00091 short diff = nearFullWeek - week;
00092 if (diff > 512)
00093 week += 512;
00094 else if(diff < -512)
00095 week -= 512;
00096 }
00097
00098 strm.header = *this;
00099 strm.headerRead = true;
00100
00101 }
00102
00103 void SEMHeader::dump(ostream& s) const
00104 {
00105 std::cout << "numRecords = " << numRecords << std::endl;
00106 std::cout << "Title = " << Title << std::endl;
00107 std::cout << "week = " << week << std::endl;
00108 std::cout << "Toa = " << Toa << std::endl;
00109 }
00110
00111 }