Changeset 3184 in ntrip for trunk/BNC/bncoutf.cpp


Ignore:
Timestamp:
Mar 29, 2011, 8:19:50 PM (13 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncoutf.cpp

    r3174 r3184  
    2020
    2121#include "bncoutf.h"
     22#include "bncsettings.h"
    2223
    2324using namespace std;
     
    2526// Constructor
    2627////////////////////////////////////////////////////////////////////////////
    27 bncoutf::bncoutf(const QString& prep, const QString& ext, const QString& path,
    28                  const QString& intr, int sampl) {
     28bncoutf::bncoutf(const QString& sklFileName, const QString& intr, int sampl) {
     29
     30  bncSettings settings;
    2931
    3032  _headerWritten = false;
    31   _prep          = prep;
    32   _ext           = ext;
    3333  _sampl         = sampl;
    3434  _intr          = intr;
    35   _path          = path;
     35
     36  QFileInfo fileInfo(sklFileName);
     37  _path        = fileInfo.absolutePath() + QDir::separator();
     38  _sklBaseName = fileInfo.baseName();
     39  _extension   = fileInfo.completeSuffix();
     40
    3641  expandEnvVar(_path);
    37   if ( _path.length() > 0 && _path[_path.length()-1] != QDir::separator() ) {
    38     _path += QDir::separator();
     42  if (!_extension.isEmpty()) {
     43    _extension = "." + _extension;
    3944  }
     45
     46  _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
    4047}
    4148
     
    5259}
    5360
    54 // Next File Epoch (static)
     61// Epoch String
    5562////////////////////////////////////////////////////////////////////////////
    56 QString bncoutf::nextEpochStr(const QDateTime& datTim,
    57                              const QString& intStr, QDateTime* nextEpoch) {
     63QString bncoutf::epochStr(const QDateTime& datTim, const QString& intStr) {
    5864
    5965  QString epoStr;
    60 
    61   QTime nextTime;
    62   QDate nextDate;
    6366
    6467  int indHlp = intStr.indexOf("min");
     
    7073    if (datTim.time().minute() >= 60-step) {
    7174      epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
    72       if (datTim.time().hour() < 23) {
    73         nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
    74         nextDate = datTim.date();
    75       }
    76       else {
    77         nextTime.setHMS(0, 0, 0);
    78         nextDate = datTim.date().addDays(1);
    79       }
    8075    }
    8176    else {
     
    8378        if (datTim.time().minute() < limit) {
    8479          epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
    85           nextTime.setHMS(datTim.time().hour(), limit, 0);
    86           nextDate = datTim.date();
    8780          break;
    8881        }
     
    9386    char ch = 'A' + datTim.time().hour();
    9487    epoStr = QString("_") + ch;
    95     if (datTim.time().hour() < 23) {
    96       nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
    97       nextDate = datTim.date();
    98     }
    99     else {
    100       nextTime.setHMS(0, 0, 0);
    101       nextDate = datTim.date().addDays(1);
    102     }
    10388  }
    10489  else {
    10590    epoStr = "";
    106     nextTime.setHMS(0, 0, 0);
    107     nextDate = datTim.date().addDays(1);
    108   }
    109 
    110   if (nextEpoch) {
    111     *nextEpoch = QDateTime(nextDate, nextTime, Qt::UTC);
    11291  }
    11392
     
    11796// File Name according to RINEX Standards
    11897////////////////////////////////////////////////////////////////////////////
    119 void bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
    120 
    121   QString epoStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
     98QString bncoutf::resolveFileName(int GPSweek, const QDateTime& datTim) {
    12299
    123100  int dayOfWeek = datTim.date().dayOfWeek();
     
    125102    dayOfWeek = 0;
    126103  }
     104  QString gpswd    = QString().arg(GPSweek).arg(dayOfWeek);
     105  QString baseName = _sklBaseName.replace("${GPSWD}", gpswd);
     106  QString epoStr   = epochStr(datTim, _intr);
    127107
    128   _fName = (_path + _prep
    129             + QString("%1").arg(GPSweek)
    130             + QString("%1").arg(dayOfWeek)
    131             + epoStr
    132             + _ext).toAscii();
     108  return _path + baseName + epoStr + _extension;
    133109}
    134110
    135 // Write One Epoch
     111// Re-Open Output File
    136112////////////////////////////////////////////////////////////////////////////
    137 t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString&,
    138                      const ColumnVector&, bool append) {
     113t_irc bncoutf::reopen(int GPSweek, double GPSweeks) {
    139114
    140115  if (_sampl != 0 && fmod(GPSweeks, _sampl) != 0.0) {
     
    144119  QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
    145120
     121  QString newFileName = resolveFileName(GPSweek, datTim);
     122
    146123  // Close the file
    147124  // --------------
    148   if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
     125  if (newFileName != _fName) {
    149126    closeFile();
    150127    _headerWritten = false;
     128    _fName = newFileName;
    151129  }
    152130
    153   // Write Header
    154   // ------------
     131  // Re-Open File, Write Header
     132  // --------------------------
    155133  if (!_headerWritten) {
    156     resolveFileName(GPSweek, datTim);
    157134    _out.setf(ios::showpoint | ios::fixed);
    158     if (append && QFile::exists(_fName)) {
    159       _out.open(_fName.data(), ios::out | ios::app);
     135    if (_append && QFile::exists(_fName)) {
     136      _out.open(_fName.toAscii().data(), ios::out | ios::app);
    160137    }
    161138    else {
    162       _out.open(_fName.data());
     139      _out.open(_fName.toAscii().data());
    163140      writeHeader(datTim);
    164141    }
     
    168145  return success;
    169146}
     147
     148// Write String
     149////////////////////////////////////////////////////////////////////////////
     150t_irc bncoutf::write(int GPSweek, double GPSweeks, const QString& str) {
     151  reopen(GPSweek, GPSweeks);
     152  _out << str.toAscii().data();
     153  _out.flush();
     154  return success;
     155}
Note: See TracChangeset for help on using the changeset viewer.