Index: /trunk/BNS/bns.cpp
===================================================================
--- /trunk/BNS/bns.cpp	(revision 849)
+++ /trunk/BNS/bns.cpp	(revision 850)
@@ -87,5 +87,10 @@
   }
   else {
-    _rnx = new bnsRinex();
+    QString prep  = "BNS";
+    QString ext   = ".rnx";
+    QString path  = settings.value("rnxPath").toString();
+    QString intr  = settings.value("rnxIntr").toString();
+    int     sampl = settings.value("rnxSampl").toInt();
+    _rnx = new bnsRinex(prep, ext, path, intr, sampl);
   }
 
@@ -96,5 +101,10 @@
   }
   else {
-    _sp3 = new bnsSP3();
+    QString prep  = "BNS";
+    QString ext   = ".clk";
+    QString path  = settings.value("sp3Path").toString();
+    QString intr  = settings.value("sp3Intr").toString();
+    int     sampl = settings.value("sp3Sampl").toInt();
+    _sp3 = new bnsSP3(prep, ext, path, intr, sampl);
   }
 }
Index: /trunk/BNS/bns.pro
===================================================================
--- /trunk/BNS/bns.pro	(revision 849)
+++ /trunk/BNS/bns.pro	(revision 850)
@@ -23,5 +23,5 @@
 
 HEADERS =             bns.h   bnswindow.h   bnshlpdlg.h   bnshtml.h   \
-          bnseph.h    bnsutils.h bnsrinex.h bnssp3.h
+          bnseph.h    bnsutils.h bnsrinex.h bnssp3.h bnsoutf.h
 
 HEADERS += newmat/controlw.h newmat/include.h newmat/myexcept.h  \
@@ -30,5 +30,5 @@
 
 SOURCES = bnsmain.cpp bns.cpp bnswindow.cpp bnshlpdlg.cpp bnshtml.cpp \
-          bnseph.cpp  bnsutils.cpp bnsrinex.cpp bnssp3.cpp
+          bnseph.cpp  bnsutils.cpp bnsrinex.cpp bnssp3.cpp bnsoutf.cpp
 
 SOURCES += newmat/bandmat.cpp newmat/cholesky.cpp newmat/evalue.cpp  \
Index: /trunk/BNS/bnsoutf.cpp
===================================================================
--- /trunk/BNS/bnsoutf.cpp	(revision 850)
+++ /trunk/BNS/bnsoutf.cpp	(revision 850)
@@ -0,0 +1,152 @@
+
+/* -------------------------------------------------------------------------
+ * BKG NTRIP Server
+ * -------------------------------------------------------------------------
+ *
+ * Class:      bnsoutf
+ *
+ * Purpose:    writes SP3 files
+ *
+ * Author:     L. Mervart
+ *
+ * Created:    25-Apr-2008
+ *
+ * Changes:    
+ *
+ * -----------------------------------------------------------------------*/
+
+#include <iomanip>
+
+#include "bnsoutf.h"
+#include "bnsutils.h"
+
+using namespace std;
+
+// Constructor
+////////////////////////////////////////////////////////////////////////////
+bnsoutf::bnsoutf(const QString& prep, const QString& ext, const QString& path,
+                 const QString& intr, int sampl) {
+
+  _headerWritten = false;
+  _prep          = prep;
+  _ext           = ext;
+  _sampl         = sampl;
+  _intr          = intr;
+  _path          = path;
+  expandEnvVar(_path);
+  if ( _path.length() > 0 && _path[_path.length()-1] != QDir::separator() ) {
+    _path += QDir::separator();
+  }
+}
+
+// Destructor
+////////////////////////////////////////////////////////////////////////////
+bnsoutf::~bnsoutf() {
+  closeFile();
+}
+
+// Close the Old RINEX File
+////////////////////////////////////////////////////////////////////////////
+void bnsoutf::closeFile() {
+  _out.close();
+}
+
+// Next File Epoch (static)
+////////////////////////////////////////////////////////////////////////////
+QString bnsoutf::nextEpochStr(const QDateTime& datTim, 
+                             const QString& intStr, QDateTime* nextEpoch) {
+
+  QString epoStr;
+
+  QTime nextTime;
+  QDate nextDate;
+
+  int indHlp = intStr.indexOf("min");
+
+  if ( indHlp != -1) {
+    int step = intStr.left(indHlp-1).toInt();
+    char ch = 'A' + datTim.time().hour();
+    epoStr = ch;
+    if (datTim.time().minute() >= 60-step) {
+      epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
+      if (datTim.time().hour() < 23) {
+        nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
+        nextDate = datTim.date();
+      }
+      else {
+        nextTime.setHMS(0, 0, 0);
+        nextDate = datTim.date().addDays(1);
+      }
+    }
+    else {
+      for (int limit = step; limit <= 60-step; limit += step) {
+        if (datTim.time().minute() < limit) {
+          epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
+          nextTime.setHMS(datTim.time().hour(), limit, 0);
+          nextDate = datTim.date();
+          break;
+        }
+      }
+    }
+  }
+  else if (intStr == "1 hour") {
+    char ch = 'A' + datTim.time().hour();
+    epoStr = ch;
+    if (datTim.time().hour() < 23) {
+      nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
+      nextDate = datTim.date();
+    }
+    else {
+      nextTime.setHMS(0, 0, 0);
+      nextDate = datTim.date().addDays(1);
+    }
+  }
+  else {
+    epoStr = "0";
+    nextTime.setHMS(0, 0, 0);
+    nextDate = datTim.date().addDays(1);
+  }
+
+  if (nextEpoch) {
+   *nextEpoch = QDateTime(nextDate, nextTime);
+  }
+
+  return epoStr;
+}
+
+// File Name according to RINEX Standards
+////////////////////////////////////////////////////////////////////////////
+void bnsoutf::resolveFileName(const QDateTime& datTim) {
+
+  QString hlpStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
+
+  _fName = (_prep
+            + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
+            + hlpStr 
+            + _ext).toAscii();
+}
+
+// Write One Epoch
+////////////////////////////////////////////////////////////////////////////
+void bnsoutf::write(int GPSweek, double GPSweeks, const QString&, 
+                   const ColumnVector&) {
+
+  QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
+
+  // Close the file
+  // --------------
+  if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
+    closeFile();
+    _headerWritten = false;
+  }
+
+  // Write Header
+  // ------------
+  if (!_headerWritten) {
+    resolveFileName(datTim);
+    _out.open(_fName.data());
+    _out.setf(ios::showpoint | ios::fixed);
+    writeHeader(datTim);
+    _headerWritten = true;
+  }
+}
Index: /trunk/BNS/bnsoutf.h
===================================================================
--- /trunk/BNS/bnsoutf.h	(revision 850)
+++ /trunk/BNS/bnsoutf.h	(revision 850)
@@ -0,0 +1,38 @@
+#ifndef BNSOUTF_H
+#define BNSOUTF_H
+
+#include <fstream>
+#include <newmat.h>
+#include <QtCore>
+
+class bnsoutf {
+ public:
+  bnsoutf(const QString& prep, const QString& ext, const QString& path,
+          const QString& intr, int sampl);
+  virtual ~bnsoutf();
+
+  virtual void write(int GPSweek, double GPSweeks, const QString& prn, 
+                     const ColumnVector& xx);
+
+ protected:
+  virtual void writeHeader(const QDateTime& datTim) = 0;
+  std::ofstream _out;
+
+ private:
+  QString nextEpochStr(const QDateTime& datTim,
+                       const QString& intStr, 
+                       QDateTime* nextEpoch = 0);
+  void resolveFileName(const QDateTime& datTim);
+  void closeFile();
+
+  int           _sampl;
+  bool          _headerWritten;
+  QDateTime     _nextCloseEpoch;
+  QString       _path;
+  QString       _intr;
+  QString       _ext;
+  QString       _prep;
+  QByteArray    _fName;
+};
+
+#endif
Index: /trunk/BNS/bnsrinex.cpp
===================================================================
--- /trunk/BNS/bnsrinex.cpp	(revision 849)
+++ /trunk/BNS/bnsrinex.cpp	(revision 850)
@@ -24,5 +24,7 @@
 // Constructor
 ////////////////////////////////////////////////////////////////////////////
-bnsRinex::bnsRinex() {
+bnsRinex::bnsRinex(const QString& prep, const QString& ext, const QString& path,
+               const QString& intr, int sampl) 
+  : bnsoutf(prep, ext, path, intr, sampl) {
 }
 
@@ -32,7 +34,16 @@
 }
 
-// 
+// Write Header
+////////////////////////////////////////////////////////////////////////////
+void bnsRinex::writeHeader(const QDateTime& datTim) {
+  _out << "THIS IS A DUMMY HEADER" << endl;
+}
+
+// Write One Epoch
 ////////////////////////////////////////////////////////////////////////////
 void bnsRinex::write(int GPSweek, double GPSweeks, const QString& prn, 
-                     const ColumnVector& xx) {
+                   const ColumnVector& xx) {
+
+  bnsoutf::write(GPSweek, GPSweeks, prn, xx);
+
 }
Index: /trunk/BNS/bnsrinex.h
===================================================================
--- /trunk/BNS/bnsrinex.h	(revision 849)
+++ /trunk/BNS/bnsrinex.h	(revision 850)
@@ -6,11 +6,16 @@
 #include <QtCore>
 
-class bnsRinex {
+#include "bnsoutf.h"
+
+class bnsRinex : public bnsoutf {
  public:
-   bnsRinex();
-   ~bnsRinex();
-   void write(int GPSweek, double GPSweeks, const QString& prn, 
-              const ColumnVector& xx);
+  bnsRinex(const QString& prep, const QString& ext, const QString& path,
+           const QString& intr, int sampl);
+  virtual ~bnsRinex();
+  virtual void write(int GPSweek, double GPSweeks, const QString& prn, 
+                     const ColumnVector& xx);
+
  private:
+  virtual void writeHeader(const QDateTime& datTim);
 };
 
Index: /trunk/BNS/bnssp3.cpp
===================================================================
--- /trunk/BNS/bnssp3.cpp	(revision 849)
+++ /trunk/BNS/bnssp3.cpp	(revision 850)
@@ -25,17 +25,7 @@
 // Constructor
 ////////////////////////////////////////////////////////////////////////////
-bnsSP3::bnsSP3() {
-  QSettings settings;
-
-  _headerWritten = false;
-  _ID4           = "BNS_";
-  _ext           = ".SP3";
-  _samplingRate  = settings.value("sp3Sampl").toInt();
-  _intr          = settings.value("rnxIntr").toString();
-  _path          = settings.value("rnxPath").toString();
-  expandEnvVar(_path);
-  if ( _path.length() > 0 && _path[_path.length()-1] != QDir::separator() ) {
-    _path += QDir::separator();
-  }
+bnsSP3::bnsSP3(const QString& prep, const QString& ext, const QString& path,
+               const QString& intr, int sampl) 
+  : bnsoutf(prep, ext, path, intr, sampl) {
 }
 
@@ -43,86 +33,4 @@
 ////////////////////////////////////////////////////////////////////////////
 bnsSP3::~bnsSP3() {
-  _out.close();
-}
-
-// Close the Old RINEX File
-////////////////////////////////////////////////////////////////////////////
-void bnsSP3::closeFile() {
-  _out.close();
-}
-
-// Next File Epoch (static)
-////////////////////////////////////////////////////////////////////////////
-QString bnsSP3::nextEpochStr(const QDateTime& datTim, 
-                             const QString& intStr, QDateTime* nextEpoch) {
-
-  QString epoStr;
-
-  QTime nextTime;
-  QDate nextDate;
-
-  int indHlp = intStr.indexOf("min");
-
-  if ( indHlp != -1) {
-    int step = intStr.left(indHlp-1).toInt();
-    char ch = 'A' + datTim.time().hour();
-    epoStr = ch;
-    if (datTim.time().minute() >= 60-step) {
-      epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
-      if (datTim.time().hour() < 23) {
-        nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
-        nextDate = datTim.date();
-      }
-      else {
-        nextTime.setHMS(0, 0, 0);
-        nextDate = datTim.date().addDays(1);
-      }
-    }
-    else {
-      for (int limit = step; limit <= 60-step; limit += step) {
-        if (datTim.time().minute() < limit) {
-          epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
-          nextTime.setHMS(datTim.time().hour(), limit, 0);
-          nextDate = datTim.date();
-          break;
-        }
-      }
-    }
-  }
-  else if (intStr == "1 hour") {
-    char ch = 'A' + datTim.time().hour();
-    epoStr = ch;
-    if (datTim.time().hour() < 23) {
-      nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
-      nextDate = datTim.date();
-    }
-    else {
-      nextTime.setHMS(0, 0, 0);
-      nextDate = datTim.date().addDays(1);
-    }
-  }
-  else {
-    epoStr = "0";
-    nextTime.setHMS(0, 0, 0);
-    nextDate = datTim.date().addDays(1);
-  }
-
-  if (nextEpoch) {
-   *nextEpoch = QDateTime(nextDate, nextTime);
-  }
-
-  return epoStr;
-}
-
-// File Name according to RINEX Standards
-////////////////////////////////////////////////////////////////////////////
-void bnsSP3::resolveFileName(const QDateTime& datTim) {
-
-  QString hlpStr = nextEpochStr(datTim, _intr, &_nextCloseEpoch);
-
-  _fName = (_ID4
-            + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
-            + hlpStr 
-            + _ext).toAscii();
 }
 
@@ -130,15 +38,5 @@
 ////////////////////////////////////////////////////////////////////////////
 void bnsSP3::writeHeader(const QDateTime& datTim) {
-
-  // Open the Output File
-  // --------------------
-  resolveFileName(datTim);
-
-  _out.open(_fName.data());
-  _out.setf(ios::showpoint | ios::fixed);
-
   _out << "THIS IS A DUMMY HEADER" << endl;
-
-  _headerWritten = true;
 }
 
@@ -148,18 +46,5 @@
                    const ColumnVector& xx) {
 
-  QDateTime datTim = dateAndTimeFromGPSweek(GPSweek, GPSweeks);
-
-  // Close the file
-  // --------------
-  if (_nextCloseEpoch.isValid() && datTim >= _nextCloseEpoch) {
-    closeFile();
-    _headerWritten = false;
-  }
-
-  // Write Header
-  // ------------
-  if (!_headerWritten) {
-    writeHeader(datTim);
-  }
+  bnsoutf::write(GPSweek, GPSweeks, prn, xx);
 
   int year, month, day, hour, min;
Index: /trunk/BNS/bnssp3.h
===================================================================
--- /trunk/BNS/bnssp3.h	(revision 849)
+++ /trunk/BNS/bnssp3.h	(revision 850)
@@ -6,29 +6,16 @@
 #include <QtCore>
 
-class bnsSP3 {
+#include "bnsoutf.h"
+
+class bnsSP3 : public bnsoutf {
  public:
-  bnsSP3();
-  ~bnsSP3();
-  void write(int GPSweek, double GPSweeks, const QString& prn, 
-             const ColumnVector& xx);
-
-  static QString nextEpochStr(const QDateTime& datTim,
-                              const QString& intStr, 
-                              QDateTime* nextEpoch = 0);
+  bnsSP3(const QString& prep, const QString& ext, const QString& path,
+         const QString& intr, int sampl);
+  virtual ~bnsSP3();
+  virtual void write(int GPSweek, double GPSweeks, const QString& prn, 
+                     const ColumnVector& xx);
 
  private:
-  void resolveFileName(const QDateTime& datTim);
-  void writeHeader(const QDateTime& datTim);
-  void closeFile();
-
-  int           _samplingRate;
-  bool          _headerWritten;
-  QDateTime     _nextCloseEpoch;
-  std::ofstream _out;
-  QString       _path;
-  QString       _intr;
-  QString       _ext;
-  QString       _ID4;
-  QByteArray    _fName;
+  virtual void writeHeader(const QDateTime& datTim);
 };
 
