Index: /trunk/BNC/bncapp.cpp
===================================================================
--- /trunk/BNC/bncapp.cpp	(revision 533)
+++ /trunk/BNC/bncapp.cpp	(revision 534)
@@ -87,5 +87,5 @@
   // Eph file(s)
   // -----------
-  _rinex3 = -1;
+  _rinexVers        = 0;
   _ephFileGPS       = 0;
   _ephStreamGPS     = 0;
@@ -101,5 +101,5 @@
   delete _ephStreamGPS;
   delete _ephFileGPS;
-  if (_rinex3 == 0) {
+  if (_rinexVers == 2) {
     delete _ephStreamGlonass;
     delete _ephFileGlonass;
@@ -153,4 +153,6 @@
   QMutexLocker locker(&_mutex);
 
+  printEphHeader();
+
   if (!_ephStreamGPS) {
     delete gpseph;
@@ -175,4 +177,6 @@
   QMutexLocker locker(&_mutex);
 
+  printEphHeader();
+
   if (!_ephStreamGlonass) {
     delete glonasseph;
@@ -197,12 +201,14 @@
 void bncApp::printEphHeader() {
 
-  if (_rinex3 == -1) {
+  // Initialization
+  // --------------
+  if (_rinexVers == 0) {
     QSettings settings;
 
     if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
-      _rinex3 = 1;    
+      _rinexVers = 3;    
     }
     else {
-      _rinex3 = 0;
+      _rinexVers = 2;
     }
 
@@ -217,4 +223,6 @@
   }
 
+  // (Re-)Open output File(s)
+  // ------------------------
   if (!_ephPath.isEmpty()) {
 
@@ -224,6 +232,4 @@
           QString("%1").arg(date.dayOfYear(), 3, 10, QChar('0')) +
                             date.toString("0.yyN");
-
-    cout << ephFileNameGPS.toAscii().data() << endl;
 
     if (_ephFileNameGPS == ephFileNameGPS) {
@@ -242,14 +248,12 @@
     _ephStreamGPS->setDevice(_ephFileGPS);
 
-    if      (_rinex3 == 1) {
+    if      (_rinexVers == 3) {
       _ephFileGlonass   = _ephFileGPS;
       _ephStreamGlonass = _ephStreamGPS;
     }
-    else if (_rinex3 == 0) {
+    else if (_rinexVers == 2) {
       QString ephFileNameGlonass = _ephPath + "GLO_" +
           QString("%1").arg(date.dayOfYear(), 3, 10, QChar('0')) +
                             date.toString("0.yyN");
-
-      cout << ephFileNameGlonass.toAscii().data() << endl;
 
       delete _ephStreamGlonass;
@@ -260,9 +264,9 @@
       _ephStreamGlonass = new QTextStream();
       _ephStreamGlonass->setDevice(_ephFileGlonass);
-
-    }
-
-
-    if (_rinex3 == 1) {
+    }
+
+    // Header - RINEX Version 3
+    // ------------------------
+    if (_rinexVers == 3) {
       QString line;
 
@@ -273,5 +277,5 @@
 
       char buffer[100];
-      HandleRunBy(buffer, sizeof(buffer), 0, _rinex3);
+      HandleRunBy(buffer, sizeof(buffer), 0, 1);
       line.sprintf("%s\n%60sEND OF HEADER\n", buffer, "");
       *_ephStreamGPS << line;
@@ -279,16 +283,16 @@
       _ephStreamGPS->flush();
     }
-    else if (_rinex3 == 0) {
-
-    }
-  }
-}
-
+
+    // Header - RINEX Version 2
+    // ------------------------
+    else if (_rinexVers == 2) {
+
+    }
+  }
+}
 
 // 
 ////////////////////////////////////////////////////////////////////////////
 void bncApp::printGPSEph(gpsephemeris* ep) {
-
-  printEphHeader();
 
   if (_ephStreamGPS) {
@@ -299,5 +303,5 @@
     converttime(&cti, ep->GPSweek, ep->TOC);
 
-    if      (_rinex3 == 1) {
+    if      (_rinexVers == 3) {
       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,
@@ -305,5 +309,5 @@
                    ep->clock_driftrate);
     }
-    else if (_rinex3 == 0) {
+    else if (_rinexVers == 2) {
       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,
@@ -358,6 +362,4 @@
 void bncApp::printGlonassEph(glonassephemeris* ep) {
 
-  printEphHeader();
-
   if (_ephStreamGlonass) {
     int ww  = ep->GPSWeek;
@@ -375,10 +377,10 @@
     QString line;
 
-    if      (_rinex3 == 1) {
+    if      (_rinexVers == 3) {
       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 if (_rinex3 == 0) {
+    else if (_rinexVers == 2) {
       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, 
Index: /trunk/BNC/bncapp.h
===================================================================
--- /trunk/BNC/bncapp.h	(revision 533)
+++ /trunk/BNC/bncapp.h	(revision 534)
@@ -55,5 +55,5 @@
     QString           _ephPath;
     QString           _ephFileNameGPS;
-    int               _rinex3;
+    int               _rinexVers;
     QFile*            _ephFileGPS;
     QTextStream*      _ephStreamGPS;
