Index: trunk/BNC/bnc.pro
===================================================================
--- trunk/BNC/bnc.pro	(revision 80)
+++ trunk/BNC/bnc.pro	(revision 82)
@@ -1,5 +1,5 @@
 
 HEADERS =             bncgetthread.h    bncwindow.h   bnctabledlg.h   \
-          bnccaster.h bncrinex.h                                      \
+          bnccaster.h bncrinex.h bncapp.h bncutils.h                  \
           RTCM/format.h RTCM/GPSDecoder.h RTCM/m_data.h RTCM/RTCM.h   \
           RTCM3/rtcm3.h RTCM3/rtcm3torinex.h                          \
@@ -9,5 +9,5 @@
 
 SOURCES = bncmain.cpp bncgetthread.cpp  bncwindow.cpp bnctabledlg.cpp \
-          bnccaster.cpp bncrinex.cpp                                  \
+          bnccaster.cpp bncrinex.cpp bncapp.cpp bncutils.cpp          \
           RTCM/m_date.cpp RTCM/RTCM.cpp                               \
           RTCM3/rtcm3.cpp RTCM3/rtcm3torinex.cpp                      \
Index: trunk/BNC/bncapp.cpp
===================================================================
--- trunk/BNC/bncapp.cpp	(revision 82)
+++ trunk/BNC/bncapp.cpp	(revision 82)
@@ -0,0 +1,52 @@
+
+/* -------------------------------------------------------------------------
+ * Bernese NTRIP Client
+ * -------------------------------------------------------------------------
+ *
+ * Class:      bncApp
+ *
+ * Purpose:    This class implements the main application
+ *
+ * Author:     L. Mervart
+ *
+ * Created:    29-Aug-2006
+ *
+ * Changes:    
+ *
+ * -----------------------------------------------------------------------*/
+
+#include <iostream>
+
+#include "bncapp.h" 
+
+using namespace std;
+
+// Constructor
+////////////////////////////////////////////////////////////////////////////
+bncApp::bncApp(int argc, char* argv[], bool GUIenabled) : 
+  QApplication(argc, argv, GUIenabled) {
+}
+
+// Destructor
+////////////////////////////////////////////////////////////////////////////
+bncApp::~bncApp() {
+}
+
+// Write a Program Message
+////////////////////////////////////////////////////////////////////////////
+void bncApp::slotMessage(const QByteArray msg) {
+#ifndef WIN32
+  cerr << msg.data() << endl;
+#else
+  static bool        first = true;
+  static QFile       logFile("BNC.LOG");
+  static QTextStream logStream;
+  if (first) {
+    first = false;
+    logFile.open(QIODevice::WriteOnly);
+    logStream.setDevice(&logFile);
+  }
+  logStream << msg.data() << endl;
+  logStream.flush();
+#endif
+}
Index: trunk/BNC/bncapp.h
===================================================================
--- trunk/BNC/bncapp.h	(revision 82)
+++ trunk/BNC/bncapp.h	(revision 82)
@@ -0,0 +1,19 @@
+
+#ifndef BNCAPP_H
+#define BNCAPP_H
+
+#include <QApplication>
+
+class bncApp : public QApplication {
+  Q_OBJECT
+
+  public:
+    bncApp(int argc, char* argv[], bool GUIenabled);
+    virtual ~bncApp();  
+
+  public slots:
+    void slotMessage(const QByteArray msg);
+  
+  private slots:
+};
+#endif
Index: trunk/BNC/bnccaster.cpp
===================================================================
--- trunk/BNC/bnccaster.cpp	(revision 80)
+++ trunk/BNC/bnccaster.cpp	(revision 82)
@@ -120,7 +120,8 @@
 void bncCaster::slotGetThreadError(const QByteArray& mountPoint) {
   _mountPoints.removeAll(mountPoint);
-  qWarning("Mountpoint size %d", _mountPoints.size());
+  emit( newMessage(
+           QString("Mountpoint size %1").arg(_mountPoints.size()).toAscii()) );
   if (_mountPoints.size() == 0) {
-    qWarning("bncCaster:: last get thread terminated\n");
+    emit(newMessage("bncCaster:: last get thread terminated"));
     emit getThreadErrors();
   }
Index: trunk/BNC/bnccaster.h
===================================================================
--- trunk/BNC/bnccaster.h	(revision 80)
+++ trunk/BNC/bnccaster.h	(revision 82)
@@ -20,7 +20,9 @@
    ~bncCaster();
    void addGetThread(bncGetThread* getThread);
+   int  nMountPoints() const {return _mountPoints.size();}
 
  signals:
    void getThreadErrors();   
+   void newMessage(const QByteArray& msg);
 
  public slots:
Index: trunk/BNC/bncgetthread.cpp
===================================================================
--- trunk/BNC/bncgetthread.cpp	(revision 80)
+++ trunk/BNC/bncgetthread.cpp	(revision 82)
@@ -61,5 +61,8 @@
                                   const QByteArray& mountPoint,
                                   const QByteArray& user, 
-                                  const QByteArray& password) {
+                                  const QByteArray& password,
+                                  QString& msg) {
+
+  msg.clear();
 
   QTcpSocket* socket = new QTcpSocket();
@@ -82,5 +85,5 @@
 
   if (!socket->waitForConnected(timeOut)) {
-    qWarning("Connect timeout");
+    msg += "Connect timeout\n";
     delete socket;
     return 0;
@@ -95,10 +98,10 @@
                       "\r\n\r\n";
 
-  qWarning(reqStr);
+  msg += reqStr;
 
   socket->write(reqStr, reqStr.length());
 
   if (!socket->waitForBytesWritten(timeOut)) {
-    qWarning("Write timeout");
+    msg += "Write timeout\n";
     delete socket;
     return 0;
@@ -114,6 +117,9 @@
   // Send the Request
   // ----------------
+  QString msg;
   _socket = bncGetThread::request(_host, _port, _proxyHost, _proxyPort, 
-                                  _mountPoint, _user, _password);
+                                  _mountPoint, _user, _password, msg);
+  emit(newMessage(msg.toAscii()));
+
   if (!_socket) {
     return exit(1);
@@ -126,10 +132,10 @@
     QString line = _socket->readLine();
     if (line.indexOf("ICY 200 OK") != 0) {
-      qWarning(("Wrong Caster Response:\n" + line).toAscii());
+      emit(newMessage(("Wrong Caster Response:\n" + line).toAscii()));
       return exit(1);
     }
   }
   else {
-    qWarning("Response Timeout");
+    emit(newMessage("Response Timeout"));
     return exit(1);
   }
@@ -140,17 +146,17 @@
 
   if      (_format.indexOf("RTCM_2") != -1) {
-    qWarning("Get Data: " + _mountPoint + " in RTCM 2.x format");
+    emit(newMessage("Get Data: " + _mountPoint + " in RTCM 2.x format"));
     decoder = new RTCM('A',true);
   }
   else if (_format.indexOf("RTCM_3") != -1) {
-    qWarning("Get Data: " + _mountPoint + " in RTCM 3.0 format");
+    emit(newMessage("Get Data: " + _mountPoint + " in RTCM 3.0 format"));
     decoder = new rtcm3();
   }
   else if (_format.indexOf("RTIGS") != -1) {
-    qWarning("Get Data: " + _mountPoint + " in RTIGS format");
+    emit(newMessage("Get Data: " + _mountPoint + " in RTIGS format"));
     decoder = new rtigs();
   }
   else {
-    qWarning(_mountPoint + " Unknown data format " + _format);
+    emit(newMessage(_mountPoint + " Unknown data format " + _format));
     return exit(1);
   }
@@ -173,5 +179,5 @@
     }
     else {
-      qWarning("Data Timeout");
+      emit(newMessage("Data Timeout"));
       return exit(1);
     }
@@ -188,2 +194,3 @@
   QThread::exit(exitCode);
 }
+
Index: trunk/BNC/bncgetthread.h
===================================================================
--- trunk/BNC/bncgetthread.h	(revision 80)
+++ trunk/BNC/bncgetthread.h	(revision 82)
@@ -23,5 +23,6 @@
                                       const QByteArray& mountPoint,
                                       const QByteArray& user, 
-                                      const QByteArray& password);
+                                      const QByteArray& password,
+                                      QString& msg);
    QByteArray mountPoint() {return _mountPoint;}
 
@@ -29,8 +30,10 @@
    void newObs(const QByteArray& mountPoint, Observation* obs);
    void error(const QByteArray& mountPoint);
+   void newMessage(const QByteArray& msg);
 
  protected:
    virtual void run();
  private:
+   void message(const QString&);
    void exit(int exitCode = 0);
    QTcpSocket* _socket;
Index: trunk/BNC/bncmain.cpp
===================================================================
--- trunk/BNC/bncmain.cpp	(revision 80)
+++ trunk/BNC/bncmain.cpp	(revision 82)
@@ -16,30 +16,15 @@
  * -----------------------------------------------------------------------*/
 
-#ifdef WIN32
-#include <windows.h>
-#endif
-
 #include <QApplication>
 #include <QFile>
 #include <iostream>
 
+#include "bncapp.h"
 #include "bncwindow.h"
 
 using namespace std;
 
-#ifdef WIN32
-QFile       logFile("BNC.LOG");
-QTextStream logStream;
-#endif
-
-void myMessageOutput(QtMsgType, const char *msg) {
-#ifdef WIN32
-  logStream << msg << endl;
-  logStream.flush();
-#else
-  cerr << msg << endl;
-#endif
-}
-
+// Main Program
+/////////////////////////////////////////////////////////////////////////////
 int main(int argc, char *argv[]) {
 
@@ -49,11 +34,5 @@
   }
 
-  QApplication app(argc, argv, GUIenabled);
-
-#ifdef WIN32
-  logFile.open(QIODevice::WriteOnly);
-  logStream.setDevice(&logFile);
-#endif
-  qInstallMsgHandler(myMessageOutput);
+  bncApp app(argc, argv, GUIenabled);
 
   QCoreApplication::setOrganizationName("AIUB");
@@ -61,8 +40,6 @@
   QCoreApplication::setApplicationName("Bernese NTRIP Client");
 
-  bncWindow* bncWin = 0;
-
   if (GUIenabled) {
-    bncWin = new bncWindow();
+    bncWindow* bncWin = new bncWindow();
     bncWin->show();
   }
@@ -78,4 +55,6 @@
 
     app.connect(caster, SIGNAL(getThreadErrors()), &app, SLOT(quit()));
+    app.connect(caster, SIGNAL(newMessage(const QByteArray&)), 
+                &app, SLOT(slotMessage(const QByteArray&)));
 
     caster->start();
@@ -84,4 +63,5 @@
     while (it.hasNext()) {
       QStringList hlp = it.next().split(" ");
+      if (hlp.size() <= 1) continue;
       QUrl url(hlp[0]);
       QByteArray mountPoint = url.path().mid(1).toAscii();
@@ -92,8 +72,14 @@
                                                  mountPoint, user, password,
                                                  format);
+      app.connect(getThread, SIGNAL(newMessage(const QByteArray&)), 
+                  &app, SLOT(slotMessage(const QByteArray&)));
+
       caster->addGetThread(getThread);
 
       getThread->start();
     }
+    if (caster->nMountPoints() == 0) {
+      return 0;
+    }
   }
   return app.exec();
Index: trunk/BNC/bncrinex.cpp
===================================================================
--- trunk/BNC/bncrinex.cpp	(revision 80)
+++ trunk/BNC/bncrinex.cpp	(revision 82)
@@ -16,8 +16,13 @@
  * -----------------------------------------------------------------------*/
 
+#include <QSettings>
+#include <QDir>
+#include <QDate>
+#include <QFile>
+#include <QTextStream>
 #include <iomanip>
 
 #include "bncrinex.h"
-
+#include "bncutils.h"
 #include "RTCM3/rtcm3torinex.h"
 
@@ -29,4 +34,5 @@
   _statID        = StatID;
   _headerWritten = false;
+  readSkeleton();
 }
 
@@ -37,4 +43,56 @@
 }
 
+// Read Skeleton Header File
+////////////////////////////////////////////////////////////////////////////
+void bncRinex::readSkeleton() {
+
+  // Resolve Skeleton File Name
+  // --------------------------
+  QSettings settings;
+  QString sklName = settings.value("rnxPath").toString();
+  expandEnvVar(sklName);
+  if ( sklName[sklName.length()-1] != QDir::separator() ) {
+    sklName += QDir::separator();
+  }
+  sklName += _statID.left(4) + "." + settings.value("rnxSkel").toString();
+
+  // Read the File
+  // -------------
+  QFile skl(sklName);
+  if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
+    QTextStream in(&skl);
+    while ( !in.atEnd() ) {
+      _headerLines.append( in.readLine() );
+      if (_headerLines.last().indexOf("END OF HEADER") != -1) {
+        break;
+      }
+    }
+  }
+}
+
+// File Name according to RINEX Standards
+////////////////////////////////////////////////////////////////////////////
+void bncRinex::resolveFileName(struct converttimeinfo& cti) {
+
+  QSettings settings;
+  QString path = settings.value("rnxPath").toString();
+  expandEnvVar(path);
+
+  if ( path[path.length()-1] != QDir::separator() ) {
+    path += QDir::separator();
+  }
+
+  QDate date(cti.year, cti.month, cti.day);
+
+  QChar ch = '0';
+
+  path += _statID.left(4) +
+          QString("%1%2.%3O").arg(date.dayOfYear(), 3, 10, QChar('0'))
+                             .arg(ch)
+                             .arg(date.year() % 100, 2, 10, QChar('0'));
+
+  _fName = path.toAscii();
+}
+
 // Write RINEX Header
 ////////////////////////////////////////////////////////////////////////////
@@ -43,44 +101,71 @@
   // Open the Output File
   // --------------------
-  QByteArray fname = _statID + ".RXO";
-  _out.open(fname.data());
-
-  // Write mandatory Records
-  // -----------------------
+  resolveFileName(cti);
+  _out.open(_fName.data());
   _out.setf(ios::fixed);
   _out.setf(ios::left);
-
-  double approxPos[3];  approxPos[0]  = approxPos[1]  = approxPos[2]  = 0.0;
-  double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
-
-  _out << "     2.10           OBSERVATION DATA    G (GPS)             RINEX VERSION / TYPE" << endl;
-  _out << "BNC                 LM                  27-Aug-2006         PGM / RUN BY / DATE"  << endl;
-  _out << setw(60) << _statID.data()                               << "MARKER NAME"          << endl;
-  _out << setw(60) << "BKG"                                        << "OBSERVER / AGENCY"    << endl;
-  _out << setw(20) << "unknown"    
-       << setw(20) << "unknown"
-       << setw(20) << "unknown"                                    << "REC # / TYPE / VERS"  << endl;
-  _out << setw(20) << "unknown"
-       << setw(20) << "unknown"
-       << setw(20) << " "                                          << "ANT # / TYPE"         << endl;
-  _out.unsetf(ios::left);
-  _out << setw(14) << setprecision(4) << approxPos[0]
-       << setw(14) << setprecision(4) << approxPos[1]
-       << setw(14) << setprecision(4) << approxPos[2] 
-       << "                  "                                     << "APPROX POSITION XYZ"  << endl;
-  _out << setw(14) << setprecision(4) << antennaNEU[0]
-       << setw(14) << setprecision(4) << antennaNEU[1]
-       << setw(14) << setprecision(4) << antennaNEU[2] 
-       << "                  "                                     << "ANTENNA: DELTA H/E/N" << endl;
-  _out << "     1     1                                                WAVELENGTH FACT L1/2" << endl;
-  _out << "     4    P1    P2    L1    L2                              # / TYPES OF OBSERV"  << endl;
-  _out << setw(6) << cti.year
-       << setw(6) << cti.month
-       << setw(6) << cti.day
-       << setw(6) << cti.hour
-       << setw(6) << cti.minute
-       << setw(13) << setprecision(7) << second 
-       << "                 "                                      << "TIME OF FIRST OBS"    << endl;
-  _out << "                                                            END OF HEADER"        << endl;
+    
+
+  // Copy Skeleton Header
+  // --------------------
+  if (_headerLines.size() > 0) {
+    QStringListIterator it(_headerLines);
+    while (it.hasNext()) {
+      QString line = it.next();
+      if      (line.indexOf("# / TYPES OF OBSERV") != -1) {
+        _out << "     4    P1    P2    L1    L2"
+                "                              # / TYPES OF OBSERV"  << endl;
+      }
+      else if (line.indexOf("TIME OF FIRST OBS") != -1) {
+        _out << setw(6) << cti.year
+             << setw(6) << cti.month
+             << setw(6) << cti.day
+             << setw(6) << cti.hour
+             << setw(6) << cti.minute
+             << setw(13) << setprecision(7) << second 
+             << "                 TIME OF FIRST OBS"    << endl;
+      }
+      else {
+        _out << line.toAscii().data() << endl;
+      }
+    }
+  }
+
+  // Write Dummy Header
+  // ------------------
+  else {
+    double approxPos[3];  approxPos[0]  = approxPos[1]  = approxPos[2]  = 0.0;
+    double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
+    
+    _out << "     2.10           OBSERVATION DATA    G (GPS)             RINEX VERSION / TYPE" << endl;
+    _out << "BNC                 LM                  27-Aug-2006         PGM / RUN BY / DATE"  << endl;
+    _out << setw(60) << _statID.data()                               << "MARKER NAME"          << endl;
+    _out << setw(60) << "BKG"                                        << "OBSERVER / AGENCY"    << endl;
+    _out << setw(20) << "unknown"    
+         << setw(20) << "unknown"
+         << setw(20) << "unknown"                                    << "REC # / TYPE / VERS"  << endl;
+    _out << setw(20) << "unknown"
+         << setw(20) << "unknown"
+         << setw(20) << " "                                          << "ANT # / TYPE"         << endl;
+    _out.unsetf(ios::left);
+    _out << setw(14) << setprecision(4) << approxPos[0]
+         << setw(14) << setprecision(4) << approxPos[1]
+         << setw(14) << setprecision(4) << approxPos[2] 
+         << "                  "                                     << "APPROX POSITION XYZ"  << endl;
+    _out << setw(14) << setprecision(4) << antennaNEU[0]
+         << setw(14) << setprecision(4) << antennaNEU[1]
+         << setw(14) << setprecision(4) << antennaNEU[2] 
+         << "                  "                                     << "ANTENNA: DELTA H/E/N" << endl;
+    _out << "     1     1                                                WAVELENGTH FACT L1/2" << endl;
+    _out << "     4    P1    P2    L1    L2                              # / TYPES OF OBSERV"  << endl;
+    _out << setw(6) << cti.year
+         << setw(6) << cti.month
+         << setw(6) << cti.day
+         << setw(6) << cti.hour
+         << setw(6) << cti.minute
+         << setw(13) << setprecision(7) << second 
+         << "                 "                                      << "TIME OF FIRST OBS"    << endl;
+    _out << "                                                            END OF HEADER"        << endl;
+  }
 
   _headerWritten = true;
Index: trunk/BNC/bncrinex.h
===================================================================
--- trunk/BNC/bncrinex.h	(revision 80)
+++ trunk/BNC/bncrinex.h	(revision 82)
@@ -18,9 +18,13 @@
 
  private:
+   void resolveFileName(struct converttimeinfo& cti);
+   void readSkeleton();
    void writeHeader(struct converttimeinfo& cti, double second);
 
    QByteArray          _statID;
+   QByteArray          _fName;
    QList<Observation*> _obs;
    ofstream            _out;
+   QStringList         _headerLines;
    bool                _headerWritten;
 };
Index: trunk/BNC/bnctabledlg.cpp
===================================================================
--- trunk/BNC/bnctabledlg.cpp	(revision 80)
+++ trunk/BNC/bnctabledlg.cpp	(revision 82)
@@ -89,8 +89,10 @@
   // Send the Request
   // ----------------
+  QString msg;
   QTcpSocket* socket = bncGetThread::request(host, port, _proxyHost, 
                                              _proxyPort, mountPoint, 
-                                             user, password);
+                                             user, password, msg);
   if (!socket) {
+    QMessageBox::warning(0, "BNC", msg);
     return;
   }
Index: trunk/BNC/bnctabledlg.h
===================================================================
--- trunk/BNC/bnctabledlg.h	(revision 80)
+++ trunk/BNC/bnctabledlg.h	(revision 82)
@@ -14,5 +14,5 @@
   signals:
     void newMountPoints(QStringList* mountPoints);
-
+ 
   private slots:
     virtual void accept();
