Index: trunk/BNC/src/bncrinex.cpp
===================================================================
--- trunk/BNC/src/bncrinex.cpp	(revision 6224)
+++ trunk/BNC/src/bncrinex.cpp	(revision 6225)
@@ -97,5 +97,5 @@
 bncRinex::~bncRinex() {
   bncSettings settings;
-  if ((_header._version >= 3.0) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
+  if ((_header.version() >= 3.0) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
     _out << ">                              4  1" << endl;
     _out << "END OF FILE" << endl;
@@ -389,10 +389,10 @@
   // Select observations older than maxTime
   // --------------------------------------
-  QList<t_satObs> dumpList;
+  QList<t_satObs> obsList;
   QMutableListIterator<t_satObs> mIt(_obs);
   while (mIt.hasNext()) {
     t_satObs obs = mIt.next();
     if (obs._time.gpsw() * 7*24*3600 + obs._time.gpssec() < maxTime - 0.05) {
-      dumpList.push_back(obs);
+      obsList.push_back(obs);
       mIt.remove();
     }
@@ -401,5 +401,5 @@
   // Easy Return
   // -----------
-  if (dumpList.isEmpty()) {
+  if (obsList.isEmpty()) {
     return;
   }
@@ -407,8 +407,7 @@
   // Time of Epoch
   // -------------
-  const t_satObs& fObs   = dumpList.first();
-  QDateTime datTim    = dateAndTimeFromGPSweek(fObs._time.gpsw(), fObs._time.gpssec());
-  QDateTime datTimNom = dateAndTimeFromGPSweek(fObs._time.gpsw(), 
-                                               floor(fObs._time.gpssec()+0.5));
+  const t_satObs& fObs = obsList.first();
+  QDateTime datTim     = dateAndTimeFromGPSweek(fObs._time.gpsw(), fObs._time.gpssec());
+  QDateTime datTimNom  = dateAndTimeFromGPSweek(fObs._time.gpsw(), floor(fObs._time.gpssec()+0.5));
 
   // Close the file
@@ -422,94 +421,29 @@
   // ------------------
   if (!_headerWritten) {
-    _header._startTime.set(fObs._time.gpsw(), fObs._time.gpssec());
+    _header.setStartTime(fObs._time);
     writeHeader(format, datTimNom);
   }
 
-  // Check whether observation types available
-  // -----------------------------------------
-  QMutableListIterator<t_satObs> mItDump(dumpList);
-  while (mItDump.hasNext()) {
-    t_satObs& obs = mItDump.next();
-    if (!_header._obsTypes.contains(obs._prn.system()) && !_header._obsTypes.contains(obs._prn.system())) {
-      mItDump.remove();
-    }
-  }
-  if (dumpList.isEmpty()) {
-    return;
-  }
-
-  double sec = double(datTim.time().second()) + fmod(fObs._time.gpssec(),1.0);
-
-  // Epoch header line: RINEX Version 3
-  // ----------------------------------
-  if (_header._version >= 3.0) {
-    _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
-         << setw(10) << setprecision(7) << sec
-         << "  " << 0 << setw(3)  << dumpList.size() << endl;
-  }
-  // Epoch header line: RINEX Version 2
-  // ----------------------------------
-  else {
-    _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
-         << setw(10) << setprecision(7) << sec
-         << "  " << 0 << setw(3)  << dumpList.size();
-
-    QListIterator<t_satObs> it(dumpList); int iSat = 0;
-    while (it.hasNext()) {
-      iSat++;
-      const t_satObs& obs = it.next();
-      _out << obs._prn.toString();
-      if (iSat == 12 && it.hasNext()) {
-        _out << endl << "                                ";
-        iSat = 0;
-      }
-    }
-    _out << endl;
-  }
-
-  QListIterator<t_satObs> it(dumpList);
+  // Prepare structure t_rnxEpo
+  // --------------------------
+  t_rnxObsFile::t_rnxEpo rnxEpo;  
+  rnxEpo.tt = fObs._time;
+
+  QListIterator<t_satObs> it(obsList);
   while (it.hasNext()) {
-    const t_satObs& obs = it.next();
-
-    // Cycle slips detection
-    // ---------------------
-    QString prn(obs._prn.toString().c_str());
-    char  lli1 = ' ';
-    char  lli2 = ' ';
-    char  lli5 = ' ';
-    char* lli = 0;
-
-    for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
-      const t_frqObs*     frqObs   = obs._obs[iFrq];
-      QMap<QString, int>* slip_cnt = 0;
-      if      (frqObs->_rnxType2ch[0] == '1') {
-        slip_cnt  = &_slip_cnt_L1;
-        lli       = &lli1;
-      }
-      else if (frqObs->_rnxType2ch[0] == '2') {
-        slip_cnt  = &_slip_cnt_L2;
-        lli       = &lli2;
-      }
-      else if (frqObs->_rnxType2ch[0] == '5') {
-        slip_cnt  = &_slip_cnt_L5;
-        lli       = &lli5;
-      }
-      else {
-        continue;
-      }
-      if (frqObs->_slip) {
-        if ( slip_cnt->find(prn)         != slip_cnt->end() && 
-             slip_cnt->find(prn).value() != frqObs->_slipCounter ) {
-          *lli = '1';
-        }
-      }
-      (*slip_cnt)[prn] = frqObs->_slipCounter;
-    }
-
-    // Write the data
-    // --------------
-    _out << rinexSatLine(obs, lli1, lli2, lli5) << endl;
-  }
-
+    const t_satObs& satObs = it.next();
+    t_rnxObsFile::t_rnxSat rnxSat;
+    rnxSat.prn = satObs._prn;
+
+    rnxEpo.rnxSat.push_back(rnxSat);
+  }
+
+  // Write the epoch
+  // ---------------
+  QString outLines;
+  QTextStream outStream(&outLines);
+  t_rnxObsFile::writeEpoch(&outStream, _header, &rnxEpo);
+
+  _out << outLines.toAscii().data();
   _out.flush();
 }
@@ -518,5 +452,5 @@
 ////////////////////////////////////////////////////////////////////////////
 void bncRinex::closeFile() {
-  if (_header._version == 3) {
+  if (_header.version() == 3) {
     _out << ">                              4  1" << endl;
     _out << "END OF FILE" << endl;
@@ -534,76 +468,4 @@
 }
 
-// One Line in RINEX v2 or v3
-////////////////////////////////////////////////////////////////////////////
-string bncRinex::rinexSatLine(const t_satObs& obs, char lli1, char lli2, char lli5) {
-  ostringstream str;
-  str.setf(ios::showpoint | ios::fixed);
-
-  if (_header._version >= 3.0) {
-    str << obs._prn.toString();
-  }
-
-  const QString obsKinds = "LCDS";
-
-  char sys = obs._prn.system();
-  const QVector<QString>& types = _header._obsTypes[sys];
-  for (int ii = 0; ii < types.size(); ii++) {
-    if (_header._version < 3.0 && ii > 0 && ii % 5 == 0) {
-      str << endl;
-    }
-    double  obsValue = 0.0;
-    char    lli      = ' ';
-    QString rnxType = t_rnxObsFile::type2to3(sys, types[ii]);
-    for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
-      const t_frqObs* frqObs = obs._obs[iFrq];
-      for (int ik = 0; ik < obsKinds.length(); ik++) {
-        QChar ch = obsKinds[ik];
-        QString obsType = (ch + QString(frqObs->_rnxType2ch.c_str()));
-        obsType = t_rnxObsFile::type2to3(sys, obsType).left(rnxType.length());
-        if (rnxType == obsType) {
-          if      (ch == 'L' && frqObs->_phaseValid) {
-            obsValue = frqObs->_phase;
-            if      (obsType[1] == '1') {
-              lli = lli1;
-            }
-            else if (obsType[1] == '2') {
-              lli = lli2;
-            }
-            else if (obsType[1] == '5') {
-              lli = lli5;
-            }
-          }
-          else if (ch == 'C' && frqObs->_codeValid) {
-            obsValue = frqObs->_code;
-          }
-          else if (ch == 'D' && frqObs->_dopplerValid) {
-            obsValue = frqObs->_doppler;
-          }
-          else if (ch == 'S' && frqObs->_snrValid) {
-            obsValue = frqObs->_snr;
-          }
-        }
-      }
-    }
-    str << setw(14) << setprecision(3) << obsValue << lli << ' ';
-  }
-
-  return str.str();
-}
-
-// 
-////////////////////////////////////////////////////////////////////////////
-string bncRinex::obsToStr(double val, int width, int precision) {
-  if (val != 0.0) {
-    ostringstream str;
-    str.setf(ios::showpoint | ios::fixed);
-    str << setw(width) << setprecision(precision) << val;
-    return str.str();
-  }
-  else {
-    return "0.0";
-  }
-}
-
 // One Line in ASCII (Internal) Format
 ////////////////////////////////////////////////////////////////////////////
Index: trunk/BNC/src/bncrinex.h
===================================================================
--- trunk/BNC/src/bncrinex.h	(revision 6224)
+++ trunk/BNC/src/bncrinex.h	(revision 6225)
@@ -51,6 +51,4 @@
 
  private:
-   std::string rinexSatLine(const t_satObs& obs, char lli1, char lli2, char lli5);
-   static std::string obsToStr(double val, int width = 14, int precision = 3);
    void resolveFileName(const QDateTime& datTim);
    bool readSkeleton();
Index: trunk/BNC/src/rinex/rnxobsfile.h
===================================================================
--- trunk/BNC/src/rinex/rnxobsfile.h	(revision 6224)
+++ trunk/BNC/src/rinex/rnxobsfile.h	(revision 6225)
@@ -41,5 +41,4 @@
 
  friend class t_rnxObsFile;
- friend class bncRinex;
 
  public:
@@ -51,4 +50,5 @@
   ~t_rnxObsHeader();
 
+  double      version() const {return _version;}
   t_irc       read(QTextStream* stream, int maxLines = 0);
   void        setDefault(const QString& markerName, int version);
@@ -58,9 +58,11 @@
   int         nTypes(char sys) const;
   QString     obsType(char sys, int index, double version = 0.0) const;
+  void        write(QTextStream* stream, const QMap<QString, QString>* txtMap = 0) const;
+  bncTime     startTime() const {return _startTime;}
+  void        setStartTime(const bncTime& startTime) {_startTime = startTime;}
+
+ private:
   QStringList obsTypesStrings() const;
-  void        write(QTextStream* stream, const QMap<QString, QString>* txtMap = 0) const;
-
- private:
-  float                         _version;
+  double                        _version;
   double                        _interval;
   QString                       _antennaNumber;
@@ -120,5 +122,5 @@
   ~t_rnxObsFile();
   
-  float          version() const {return _header._version;}
+  double         version() const {return _header._version;}
   double         interval() const {return _header._interval;}
   int            numSys() const {return _header.numSys();}
@@ -171,14 +173,20 @@
   static QString type3to2(char sys, const QString& typeV3);
 
+  static void writeEpoch(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo) {
+    if (header.version() >= 3.0) {
+      writeEpochV3(stream, header, epo);
+    }
+    else {
+      writeEpochV2(stream, header, epo);
+    }
+  }
+
+ private:
   static void writeEpochV2(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo);
   static void writeEpochV3(QTextStream* stream, const t_rnxObsHeader& header, const t_rnxEpo* epo);
-
- private:
   t_rnxObsFile() {};
   void openRead(const QString& fileName);
   void openWrite(const QString& fileName);
   void close();
-  void writeEpochV2(const t_rnxEpo* epo);
-  void writeEpochV3(const t_rnxEpo* epo);
   t_rnxEpo* nextEpochV2();
   t_rnxEpo* nextEpochV3();
