Index: trunk/BNC/bncgetthread.cpp
===================================================================
--- trunk/BNC/bncgetthread.cpp	(revision 1137)
+++ trunk/BNC/bncgetthread.cpp	(revision 1138)
@@ -62,4 +62,16 @@
 // Constructor
 ////////////////////////////////////////////////////////////////////////////
+bncGetThread::bncGetThread(const QByteArray& rawInpFileName, 
+                           const QByteArray& format) {
+
+  _decoder    = 0;
+  _socket     = 0;
+  _rawOutFile = 0;
+  _format     = format;
+  
+  _rawInpFile = new QFile(rawInpFileName);
+  _rawInpFile->open(QIODevice::ReadOnly);
+}
+
 bncGetThread::bncGetThread(const QUrl& mountPoint, 
                            const QByteArray& format,
@@ -82,4 +94,5 @@
   _nextSleep  =  1;       //  1 second
   _iMount     = iMount;   // index in mountpoints array
+  _rawInpFile = 0;
 
   // Check name conflict
@@ -151,10 +164,10 @@
   // ----------
   if (false) {    // special option used for testing
-    QByteArray rawFileName = "./" + _staID + ".raw";
-    _rawFile = new QFile(rawFileName);
-    _rawFile->open(QIODevice::WriteOnly);
+    QByteArray rawOutFileName = "./" + _staID + ".raw";
+    _rawOutFile = new QFile(rawOutFileName);
+    _rawOutFile->open(QIODevice::WriteOnly);
   }
   else {
-    _rawFile = 0;
+    _rawOutFile = 0;
   }
 
@@ -175,5 +188,6 @@
   delete _decoder;
   delete _rnx;
-  delete _rawFile;
+  delete _rawInpFile;
+  delete _rawOutFile;
 }
 
@@ -297,84 +311,87 @@
 t_irc bncGetThread::initRun() {
 
-  // Initialize Socket
-  // -----------------
-  QString msg;
-  _socket = this->request(_mountPoint, _latitude, _longitude, 
-                          _nmea, _timeOut, msg);
-  if (!_socket) {
-    return failure;
-  }
-
-  // Read Caster Response
-  // --------------------
-  _socket->waitForReadyRead(_timeOut);
-  if (_socket->canReadLine()) {
-    QString line = _socket->readLine();
-
-    // Skip messages from proxy server
-    // -------------------------------
-    if (line.indexOf("ICY 200 OK") == -1 && 
-        line.indexOf("200 OK")     != -1 ) {
-      bool proxyRespond = true;
-      while (true) {
-        if (_socket->canReadLine()) {
-          line = _socket->readLine();
-          if (!proxyRespond) {
-            break;
-          }
-          if (line.trimmed().isEmpty()) {
-            proxyRespond = false;
-          }
-        }
-        else {
-          _socket->waitForReadyRead(_timeOut);
-          if (_socket->bytesAvailable() <= 0) {
-            break;
-          }
-        }
-      }
-    }
-
-    if (line.indexOf("Unauthorized") != -1) {
-      QStringList table;
-      bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
-      QString net;
-      QStringListIterator it(table);
-      while (it.hasNext()) {
-        QString line = it.next();
-        if (line.indexOf("STR") == 0) {
-          QStringList tags = line.split(";");
-          if (tags.at(1) == _staID_orig) {
-            net = tags.at(7);
-            break;
-          }
-        }
-      }
-
-      QString reg;
-      it.toFront();
-      while (it.hasNext()) {
-        QString line = it.next();
-        if (line.indexOf("NET") == 0) {
-          QStringList tags = line.split(";");
-          if (tags.at(1) == net) {
-            reg = tags.at(7);
-            break;
-          }          
-        }
-      }
-      emit(newMessage((_staID + ": Caster Response: " + line + 
-                       "          Adjust User-ID and Password Register, see"
-                       "\n          " + reg).toAscii()));
-      return fatal;
-    }
-    if (line.indexOf("ICY 200 OK") != 0) {
-      emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
+  if (!_rawInpFile) {
+
+    // Initialize Socket
+    // -----------------
+    QString msg;
+    _socket = this->request(_mountPoint, _latitude, _longitude, 
+                            _nmea, _timeOut, msg);
+    if (!_socket) {
       return failure;
     }
-  }
-  else {
-    emit(newMessage(_staID + ": Response Timeout"));
-    return failure;
+    
+    // Read Caster Response
+    // --------------------
+    _socket->waitForReadyRead(_timeOut);
+    if (_socket->canReadLine()) {
+      QString line = _socket->readLine();
+    
+      // Skip messages from proxy server
+      // -------------------------------
+      if (line.indexOf("ICY 200 OK") == -1 && 
+          line.indexOf("200 OK")     != -1 ) {
+        bool proxyRespond = true;
+        while (true) {
+          if (_socket->canReadLine()) {
+            line = _socket->readLine();
+            if (!proxyRespond) {
+              break;
+            }
+            if (line.trimmed().isEmpty()) {
+              proxyRespond = false;
+            }
+          }
+          else {
+            _socket->waitForReadyRead(_timeOut);
+            if (_socket->bytesAvailable() <= 0) {
+              break;
+            }
+          }
+        }
+      }
+    
+      if (line.indexOf("Unauthorized") != -1) {
+        QStringList table;
+        bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
+        QString net;
+        QStringListIterator it(table);
+        while (it.hasNext()) {
+          QString line = it.next();
+          if (line.indexOf("STR") == 0) {
+            QStringList tags = line.split(";");
+            if (tags.at(1) == _staID_orig) {
+              net = tags.at(7);
+              break;
+            }
+          }
+        }
+    
+        QString reg;
+        it.toFront();
+        while (it.hasNext()) {
+          QString line = it.next();
+          if (line.indexOf("NET") == 0) {
+            QStringList tags = line.split(";");
+            if (tags.at(1) == net) {
+              reg = tags.at(7);
+              break;
+            }          
+          }
+        }
+        emit(newMessage((_staID + ": Caster Response: " + line + 
+                         "          Adjust User-ID and Password Register, see"
+                         "\n          " + reg).toAscii()));
+        return fatal;
+      }
+      if (line.indexOf("ICY 200 OK") != 0) {
+        emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
+        return failure;
+      }
+    }
+    else {
+      emit(newMessage(_staID + ": Response Timeout"));
+      return failure;
+    }
   }
 
@@ -458,5 +475,5 @@
   while (true) {
     try {
-      if (_socket->state() != QAbstractSocket::ConnectedState) {
+      if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
         emit(newMessage(_staID + ": Socket not connected, reconnecting"));
         tryReconnect();
@@ -469,15 +486,35 @@
       _decoder->_obsList.clear();
 
-      _socket->waitForReadyRead(_timeOut);
-      qint64 nBytes = _socket->bytesAvailable();
+      qint64 nBytes = 0;
+
+      if      (_socket) {
+        _socket->waitForReadyRead(_timeOut);
+        nBytes = _socket->bytesAvailable();
+      }
+      else if (_rawInpFile) {
+        const qint64 maxBytes = 1024;
+        nBytes = maxBytes;
+      }
+
       if (nBytes > 0) {
         emit newBytes(_staID, nBytes);
 
         char* data = new char[nBytes];
-        _socket->read(data, nBytes);
-
-        if (_rawFile) {
-          _rawFile->write(data, nBytes);
-          _rawFile->flush();
+
+        if (_socket) {
+          _socket->read(data, nBytes);
+        }
+        else if (_rawInpFile) {
+          nBytes = _rawInpFile->read(data, nBytes);
+          cout << "nBytes = " << nBytes << endl;
+          if (nBytes <= 0) {
+            cout << "no more data" << endl;
+            ::exit(0);
+          }
+        }
+
+        if (_rawOutFile) {
+          _rawOutFile->write(data, nBytes);
+          _rawOutFile->flush();
         }
 
Index: trunk/BNC/bncgetthread.h
===================================================================
--- trunk/BNC/bncgetthread.h	(revision 1137)
+++ trunk/BNC/bncgetthread.h	(revision 1138)
@@ -41,4 +41,5 @@
 
  public:
+   bncGetThread(const QByteArray&  rawInpFileName, const QByteArray& format);
    bncGetThread(const QUrl& mountPoint, 
                 const QByteArray& format,
@@ -46,4 +47,5 @@
                 const QByteArray& longitude,
                 const QByteArray& nmea, int iMount);
+
    ~bncGetThread();
 
@@ -109,5 +111,6 @@
    QDateTime   _decodeSucc;
    QMutex      _mutex;
-   QFile*      _rawFile;
+   QFile*      _rawOutFile;
+   QFile*      _rawInpFile;
 };
 
Index: trunk/BNC/bncmain.cpp
===================================================================
--- trunk/BNC/bncmain.cpp	(revision 1137)
+++ trunk/BNC/bncmain.cpp	(revision 1138)
@@ -115,17 +115,10 @@
   else {
 
+    signal(SIGINT, catch_signal);
+
     bncCaster* caster = new bncCaster(settings.value("outFile").toString(),
                                       settings.value("outPort").toInt());
     
     app.setCaster(caster);
-
-    // Ctrl-C Signal Handling
-    // ----------------------
-    signal(SIGINT, catch_signal);
-
-    //// beg test
-    ////    QTimer::singleShot(30000, &app, SLOT(slotQuit()));
-    //// end test
-
     app.setPort(settings.value("outEphPort").toInt());
     app.setPortCorr(settings.value("corrPort").toInt());
@@ -137,25 +130,38 @@
     ((bncApp*)qApp)->slotMessage("============ Start BNC ============");
 
-    int iMount = -1;
-    QListIterator<QString> it(settings.value("mountPoints").toStringList());
-    while (it.hasNext()) {
-      ++iMount;
-      QStringList hlp = it.next().split(" ");
-      if (hlp.size() <= 1) continue;
-      QUrl url(hlp[0]);
-      QByteArray format = hlp[1].toAscii();
-      QByteArray latitude = hlp[2].toAscii();
-      QByteArray longitude = hlp[3].toAscii();
-      QByteArray nmea = hlp[4].toAscii();
-      bncGetThread* getThread = new bncGetThread(url, format, latitude, longitude, nmea, iMount);
+    if (false) {
+      bncGetThread* getThread = new bncGetThread("FFMJ2.raw","RTCM_3");
       app.connect(getThread, SIGNAL(newMessage(QByteArray)), 
                   &app, SLOT(slotMessage(const QByteArray)));
-
+      
       caster->addGetThread(getThread);
-
+      
       getThread->start();
     }
-    if (caster->numStations() == 0) {
-      return 0;
+    else {
+      int iMount = -1;
+      QListIterator<QString> it(settings.value("mountPoints").toStringList());
+      while (it.hasNext()) {
+        ++iMount;
+        QStringList hlp = it.next().split(" ");
+        if (hlp.size() <= 1) continue;
+        QUrl url(hlp[0]);
+        QByteArray format = hlp[1].toAscii();
+        QByteArray latitude = hlp[2].toAscii();
+        QByteArray longitude = hlp[3].toAscii();
+        QByteArray nmea = hlp[4].toAscii();
+      
+        bncGetThread* getThread = new bncGetThread(url, format, latitude, longitude, nmea, iMount);
+      
+        app.connect(getThread, SIGNAL(newMessage(QByteArray)), 
+                    &app, SLOT(slotMessage(const QByteArray)));
+      
+        caster->addGetThread(getThread);
+      
+        getThread->start();
+      }
+      if (caster->numStations() == 0) {
+        return 0;
+      }
     }
   }
