Index: trunk/BNC/bncapp.cpp
===================================================================
--- trunk/BNC/bncapp.cpp	(revision 532)
+++ trunk/BNC/bncapp.cpp	(revision 533)
@@ -49,6 +49,4 @@
 using namespace std;
 
-const int RINEX_3 = 1;
-
 struct converttimeinfo {
   int second;    /* seconds of GPS time [0..59] */
@@ -72,14 +70,12 @@
   QApplication(argc, argv, GUIenabled) {
 
+  _bncVersion  = "BNC 1.4";
+
   _logFileFlag = 0;
   _logFile     = 0;
   _logStream   = 0;
 
-  _bncVersion  = "BNC 1.4";
-
   // Lists of Ephemeris
   // ------------------
-  _ephFile     = 0;
-  _ephStream   = 0;
   for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
     _gpsEph[ii-PRN_GPS_START] = 0;
@@ -89,18 +85,11 @@
   }
 
-  // Eph file
-  // --------
-  _ephFile   = 0;
-  _ephStream = 0;
-  QString ephFileName = "TEST.EPH";
-  ////  QString ephFileName = settings.value("ephFile").toString();
-  if ( !ephFileName.isEmpty() ) {
-    expandEnvVar(ephFileName);
-    _ephFile = new QFile(ephFileName);
-    _ephFile->open(QIODevice::WriteOnly);
-    _ephStream = new QTextStream();
-    _ephStream->setDevice(_ephFile);
-    printEphHeader();
-  }
+  // Eph file(s)
+  // -----------
+  _rinex3 = -1;
+  _ephFileGPS       = 0;
+  _ephStreamGPS     = 0;
+  _ephFileGlonass   = 0;
+  _ephStreamGlonass = 0;
 }
 
@@ -110,6 +99,10 @@
   delete _logStream;
   delete _logFile;
-  delete _ephStream;
-  delete _ephFile;
+  delete _ephStreamGPS;
+  delete _ephFileGPS;
+  if (_rinex3 == 0) {
+    delete _ephStreamGlonass;
+    delete _ephFileGlonass;
+  }
   for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
     delete _gpsEph[ii-PRN_GPS_START];
@@ -160,5 +153,5 @@
   QMutexLocker locker(&_mutex);
 
-  if (!_ephStream) {
+  if (!_ephStreamGPS) {
     delete gpseph;
     return;
@@ -182,5 +175,5 @@
   QMutexLocker locker(&_mutex);
 
-  if (!_ephStream) {
+  if (!_ephStreamGlonass) {
     delete glonasseph;
     return;
@@ -203,18 +196,90 @@
 ////////////////////////////////////////////////////////////////////////////
 void bncApp::printEphHeader() {
-  if (_ephStream) {
-    QString line;
-
-    line.sprintf(
-          "%9.2f%11sN: GNSS NAV DATA    M: Mixed%12sRINEX VERSION / TYPE\n", 
-          3.0, "", "");
-    *_ephStream << line;
-
-    char buffer[100];
-    HandleRunBy(buffer, sizeof(buffer), 0, RINEX_3);
-    line.sprintf("%s\n%60sEND OF HEADER\n", buffer, "");
-    *_ephStream << line;
-
-    _ephStream->flush();
+
+  if (_rinex3 == -1) {
+    QSettings settings;
+
+    if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
+      _rinex3 = 1;    
+    }
+    else {
+      _rinex3 = 0;
+    }
+
+    _ephPath = settings.value("ephPath").toString();
+
+    if ( !_ephPath.isEmpty() ) {
+      if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
+        _ephPath += QDir::separator();
+      }
+      expandEnvVar(_ephPath);
+    }
+  }
+
+  if (!_ephPath.isEmpty()) {
+
+    QDate date = QDate::currentDate();
+
+    QString ephFileNameGPS = _ephPath + "GPS_" +
+          QString("%1").arg(date.dayOfYear(), 3, 10, QChar('0')) +
+                            date.toString("0.yyN");
+
+    cout << ephFileNameGPS.toAscii().data() << endl;
+
+    if (_ephFileNameGPS == ephFileNameGPS) {
+      return;
+    }
+    else {
+      _ephFileNameGPS = ephFileNameGPS;
+    }
+
+    delete _ephStreamGPS;
+    delete _ephFileGPS;
+
+    _ephFileGPS = new QFile(ephFileNameGPS);
+    _ephFileGPS->open(QIODevice::WriteOnly);
+    _ephStreamGPS = new QTextStream();
+    _ephStreamGPS->setDevice(_ephFileGPS);
+
+    if      (_rinex3 == 1) {
+      _ephFileGlonass   = _ephFileGPS;
+      _ephStreamGlonass = _ephStreamGPS;
+    }
+    else if (_rinex3 == 0) {
+      QString ephFileNameGlonass = _ephPath + "GLO_" +
+          QString("%1").arg(date.dayOfYear(), 3, 10, QChar('0')) +
+                            date.toString("0.yyN");
+
+      cout << ephFileNameGlonass.toAscii().data() << endl;
+
+      delete _ephStreamGlonass;
+      delete _ephFileGlonass;
+
+      _ephFileGlonass = new QFile(ephFileNameGlonass);
+      _ephFileGlonass->open(QIODevice::WriteOnly);
+      _ephStreamGlonass = new QTextStream();
+      _ephStreamGlonass->setDevice(_ephFileGlonass);
+
+    }
+
+
+    if (_rinex3 == 1) {
+      QString line;
+
+      line.sprintf(
+            "%9.2f%11sN: GNSS NAV DATA    M: Mixed%12sRINEX VERSION / TYPE\n", 
+            3.0, "", "");
+      *_ephStreamGPS << line;
+
+      char buffer[100];
+      HandleRunBy(buffer, sizeof(buffer), 0, _rinex3);
+      line.sprintf("%s\n%60sEND OF HEADER\n", buffer, "");
+      *_ephStreamGPS << line;
+
+      _ephStreamGPS->flush();
+    }
+    else if (_rinex3 == 0) {
+
+    }
   }
 }
@@ -225,5 +290,7 @@
 void bncApp::printGPSEph(gpsephemeris* ep) {
 
-  if (_ephStream) {
+  printEphHeader();
+
+  if (_ephStreamGPS) {
 
     QString line;
@@ -232,5 +299,5 @@
     converttime(&cti, ep->GPSweek, ep->TOC);
 
-    if (RINEX_3) {
+    if      (_rinex3 == 1) {
       line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
                    ep->satellite, cti.year, cti.month, cti.day, cti.hour,
@@ -238,5 +305,5 @@
                    ep->clock_driftrate);
     }
-    else {
+    else if (_rinex3 == 0) {
       line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
                    ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
@@ -244,21 +311,21 @@
                    ep->clock_drift, ep->clock_driftrate);
     }
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
 
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
                  ep->Crs, ep->Delta_n, ep->M0);
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
     
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
                  ep->e, ep->Cus, ep->sqrt_A);
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
 
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e",
                  (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
     
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->i0,
                  ep->Crc, ep->omega, ep->OMEGADOT);
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
 
     double dd = 0;
@@ -270,5 +337,5 @@
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
                  (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
 
     if(ep->URAindex <= 6) /* URA index */
@@ -278,10 +345,10 @@
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", dd,
                  ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
-    *_ephStream << line << endl;
+    *_ephStreamGPS << line << endl;
 
     line.sprintf("   %19.12e%19.12e", ((double)ep->TOW), 0.0);
-    *_ephStream << line << endl;
-
-    _ephStream->flush();
+    *_ephStreamGPS << line << endl;
+
+    _ephStreamGPS->flush();
   }
 }
@@ -291,5 +358,7 @@
 void bncApp::printGlonassEph(glonassephemeris* ep) {
 
-  if (_ephStream) {
+  printEphHeader();
+
+  if (_ephStreamGlonass) {
     int ww  = ep->GPSWeek;
     int tow = ep->GPSTOW; 
@@ -306,10 +375,10 @@
     QString line;
 
-    if (RINEX_3) {
+    if      (_rinex3 == 1) {
       line.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
                    ep->almanac_number, cti.year, cti.month, cti.day, cti.hour, 
                    cti.minute, cti.second, -ep->tau, ep->gamma, (double) ii);
     }
-    else {
+    else if (_rinex3 == 0) {
       line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
                    ep->almanac_number, cti.year%100, cti.month, cti.day, 
@@ -317,21 +386,21 @@
                    ep->gamma, (double) ii);
     }
-    *_ephStream << line << endl;
+    *_ephStreamGlonass << line << endl;
     
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->x_pos,
                  ep->x_velocity, ep->x_acceleration, 
                  (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
-    *_ephStream << line << endl;
+    *_ephStreamGlonass << line << endl;
      
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->y_pos,
                  ep->y_velocity, ep->y_acceleration, 
                  (double) ep->frequency_number);
-    *_ephStream << line << endl;
+    *_ephStreamGlonass << line << endl;
     
     line.sprintf("   %19.12e%19.12e%19.12e%19.12e", ep->z_pos,
                  ep->z_velocity, ep->z_acceleration, (double) ep->E);
-    *_ephStream << line << endl;
-
-    _ephStream->flush();
-  }
-}
+    *_ephStreamGlonass << line << endl;
+
+    _ephStreamGlonass->flush();
+  }
+}
Index: trunk/BNC/bncapp.h
===================================================================
--- trunk/BNC/bncapp.h	(revision 532)
+++ trunk/BNC/bncapp.h	(revision 533)
@@ -53,6 +53,11 @@
     QString           _bncVersion;
     QMutex            _mutex;
-    QFile*            _ephFile;
-    QTextStream*      _ephStream;
+    QString           _ephPath;
+    QString           _ephFileNameGPS;
+    int               _rinex3;
+    QFile*            _ephFileGPS;
+    QTextStream*      _ephStreamGPS;
+    QFile*            _ephFileGlonass;
+    QTextStream*      _ephStreamGlonass;
     gpsephemeris*     _gpsEph[PRN_GPS_END - PRN_GPS_START + 1];
     glonassephemeris* _glonassEph[PRN_GLONASS_END - PRN_GLONASS_START + 1];
Index: trunk/BNC/bncmain.cpp
===================================================================
--- trunk/BNC/bncmain.cpp	(revision 532)
+++ trunk/BNC/bncmain.cpp	(revision 533)
@@ -61,6 +61,4 @@
   }
 
-  bncApp app(argc, argv, GUIenabled);
-
   QCoreApplication::setOrganizationName("BKG");
   QCoreApplication::setOrganizationDomain("www.ifag.de");
@@ -77,4 +75,6 @@
     settings.setValue("waitTime",   2);
   }
+
+  bncApp app(argc, argv, GUIenabled);
 
   // Interactive Mode - open the main window
Index: trunk/BNC/bncwindow.cpp
===================================================================
--- trunk/BNC/bncwindow.cpp	(revision 532)
+++ trunk/BNC/bncwindow.cpp	(revision 533)
@@ -150,7 +150,13 @@
   _outPortLineEdit->setWhatsThis(tr("<p>BNC makes synchronized observations available in a binary format on your local host (IP 127.0.0.1) through an IP port. Enter an IP port number to activate this function.</p><p>Default is an empty option field, meaning that no binary output is generated.</p>"));
   _rnxPathLineEdit    = new QLineEdit(settings.value("rnxPath").toString());
-_rnxPathLineEdit->setWhatsThis(tr("<p>Observations can be converted to RINEX Version 2.11. Enter a path for saving the RINEX files in a directory. If this directory does not exist, BNC will not create RINEX files.</p><p>Default value for 'RINEX directory' is an empty option field, meaning that streams are not converted to RINEX.</p>"));
+  _rnxPathLineEdit->setWhatsThis(tr("<p>Observations can be converted to RINEX Version 2.11. Enter a path for saving the RINEX files in a directory. If this directory does not exist, BNC will not create RINEX files.</p><p>Default value for 'RINEX directory' is an empty option field, meaning that streams are not converted to RINEX.</p>"));
+  _ephPathLineEdit    = new QLineEdit(settings.value("ephPath").toString());
+  _ephPathLineEdit->setWhatsThis(tr("<p>Navigation messages can be converted to RINEX files. Enter a path for saving the files in a directory.</p>"));
+  _rnxV3CheckBox = new QCheckBox();
+  _rnxV3CheckBox->setCheckState(Qt::CheckState(settings.value("rnxV3").toInt()));
+  _ephV3CheckBox = new QCheckBox();
+  _ephV3CheckBox->setCheckState(Qt::CheckState(settings.value("ephV3").toInt()));
   _rnxScrpLineEdit    = new QLineEdit(settings.value("rnxScript").toString());
-_rnxScrpLineEdit->setWhatsThis(tr("<p>Whenever a RINEX file is saved, you may like to compress, copy or upload it immediately via FTP. For that you enter the full path of a script or batch file which is then called to carry out these operations. The full RINEX file path will be passed to the script as a command line parameter (%1 on Windows systems, $1 on Unix/Linux systems).</p><p>The triggering event for calling the script or batch file is the end of the 'RINEX file interval'. If that is superposed by a stream outage, the triggering event is the stream reconnect.</p><p>Default value for 'RINEX script' is an empty option field, meaning that no script or batch file shall be called."));
+  _rnxScrpLineEdit->setWhatsThis(tr("<p>Whenever a RINEX file is saved, you may like to compress, copy or upload it immediately via FTP. For that you enter the full path of a script or batch file which is then called to carry out these operations. The full RINEX file path will be passed to the script as a command line parameter (%1 on Windows systems, $1 on Unix/Linux systems).</p><p>The triggering event for calling the script or batch file is the end of the 'RINEX file interval'. If that is superposed by a stream outage, the triggering event is the stream reconnect.</p><p>Default value for 'RINEX script' is an empty option field, meaning that no script or batch file shall be called."));
   _rnxSkelLineEdit    = new QLineEdit(settings.value("rnxSkel").toString());
   _rnxSkelLineEdit->setMaximumWidth(5*ww);
@@ -272,5 +278,8 @@
 
   layout->addWidget(new QLabel("RINEX directory"),               4, 0, 1, 2);
-  layout->addWidget(_rnxPathLineEdit,                            4, 2, 1, 3);
+  layout->addWidget(_rnxPathLineEdit,                            4, 2);
+
+  layout->addWidget(new QLabel("RINEX v3"),                      4, 3, 1, 2);
+  layout->addWidget(_rnxV3CheckBox,                              4, 4);
 
   layout->addWidget(new QLabel("RINEX script (full path)"),      5, 0, 1, 2);
@@ -288,11 +297,17 @@
   layout->addWidget(_rnxAppendCheckBox,                          7, 4);
 
-  layout->addWidget(new QLabel("Mountpoints"),                   8, 0, 1, 2);
-
-  layout->addWidget(_mountPointsTable,                           9, 0, 1, 5);
-
-  layout->addWidget(new QLabel("Log (full path)"),              10, 0, 1, 2);
-  layout->addWidget(_logFileLineEdit,                           10, 2, 1, 3);
-  layout->addWidget(_log,                                       11, 0, 1, 5);
+  layout->addWidget(new QLabel("Ephemeris directory"),           8, 0, 1, 2);
+  layout->addWidget(_ephPathLineEdit,                            8, 2);
+
+  layout->addWidget(new QLabel("RINEX v3"),                      8, 3, 1, 2);
+  layout->addWidget(_ephV3CheckBox,                              8, 4);
+
+  layout->addWidget(new QLabel("Mountpoints"),                   9, 0, 1, 2);
+
+  layout->addWidget(_mountPointsTable,                          10, 0, 1, 5);
+
+  layout->addWidget(new QLabel("Log (full path)"),              11, 0, 1, 2);
+  layout->addWidget(_logFileLineEdit,                           11, 2, 1, 3);
+  layout->addWidget(_log,                                       12, 0, 1, 5);
 }
 
@@ -423,4 +438,5 @@
   settings.setValue("outPort",     _outPortLineEdit->text());
   settings.setValue("rnxPath",     _rnxPathLineEdit->text());
+  settings.setValue("ephPath",     _ephPathLineEdit->text());
   settings.setValue("rnxScript",   _rnxScrpLineEdit->text());
   settings.setValue("rnxIntr",     _rnxIntrComboBox->currentText());
@@ -428,4 +444,6 @@
   settings.setValue("rnxSkel",     _rnxSkelLineEdit->text());
   settings.setValue("rnxAppend",   _rnxAppendCheckBox->checkState());
+  settings.setValue("rnxV3",       _rnxV3CheckBox->checkState());
+  settings.setValue("ephV3",       _ephV3CheckBox->checkState());
   settings.setValue("logFile",     _logFileLineEdit->text());
   
Index: trunk/BNC/bncwindow.h
===================================================================
--- trunk/BNC/bncwindow.h	(revision 532)
+++ trunk/BNC/bncwindow.h	(revision 533)
@@ -80,4 +80,7 @@
     QLineEdit* _outPortLineEdit;
     QLineEdit* _rnxPathLineEdit;
+    QLineEdit* _ephPathLineEdit;
+    QCheckBox* _rnxV3CheckBox;
+    QCheckBox* _ephV3CheckBox;
     QLineEdit* _rnxSkelLineEdit;
     QLineEdit* _rnxScrpLineEdit;
