Index: branches/mergetest/external/atnf/PKSIO/MBFITSreader.cc
===================================================================
--- branches/mergetest/external/atnf/PKSIO/MBFITSreader.cc	(revision 1777)
+++ branches/mergetest/external/atnf/PKSIO/MBFITSreader.cc	(revision 1779)
@@ -41,4 +41,6 @@
 #include <atnf/PKSIO/MBrecord.h>
 
+#include <casa/Logging/LogIO.h>
+
 #include <casa/math.h>
 #include <casa/iostream.h>
@@ -57,4 +59,7 @@
 const double HALFPI = PI / 2.0;
 const double R2D = 180.0 / PI;
+
+// Class name
+const string className = "MBFITSreader" ;
 
 //------------------------------------------------- MBFITSreader::MBFITSreader
@@ -99,8 +104,5 @@
 
   // Tell RPFITSIN not to report errors directly.
-  iostat_.errlun = -1;
-
-  // By default, messages are written to stderr.
-  initMsg();
+  //iostat_.errlun = -1;
 }
 
@@ -131,6 +133,6 @@
         int  &extraSysCal)
 {
-  // Clear the message stack.
-  clearMsg();
+  const string methodName = "open()" ;
+  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
 
   if (cMBopen) {
@@ -143,6 +145,6 @@
   int jstat = -3;
   if (rpfitsin(jstat)) {
-    sprintf(cMsg, "ERROR: Failed to open MBFITS file\n       %s", rpname);
-    logMsg(cMsg);
+    sprintf(cMsg, "Failed to open MBFITS file\n%s", rpname);
+    os << LogIO::SEVERE << cMsg << LogIO::POST ;
     return 1;
   }
@@ -161,7 +163,7 @@
   jstat = -1;
   if (rpfitsin(jstat)) {
-    sprintf(cMsg, "ERROR: Failed to read MBFITS header in file\n"
-                  "       %s", rpname);
-    logMsg(cMsg);
+    sprintf(cMsg, "Failed to read MBFITS header in file\n"
+                  "%s", rpname);
+    os << LogIO::SEVERE << cMsg << LogIO::POST ;
     close();
     return 1;
@@ -173,11 +175,11 @@
   // Non-ATNF data may not store the position in (u,v,w).
   if (strncmp(names_.sta, "tid", 3) == 0) {
-    sprintf(cMsg, "WARNING: Found Tidbinbilla data");
+    sprintf(cMsg, "Found Tidbinbilla data");
     cSUpos = 1;
   } else if (strncmp(names_.sta, "HOB", 3) == 0) {
-    sprintf(cMsg, "WARNING: Found Hobart data");
+    sprintf(cMsg, "Found Hobart data");
     cSUpos = 1;
   } else if (strncmp(names_.sta, "CED", 3) == 0) {
-    sprintf(cMsg, "WARNING: Found Ceduna data");
+    sprintf(cMsg, "Found Ceduna data");
     cSUpos = 1;
   } else {
@@ -187,5 +189,5 @@
   if (cSUpos) {
     strcat(cMsg, ", using telescope position\n         from SU table.");
-    logMsg(cMsg);
+    os << LogIO::WARN << cMsg << LogIO::POST ;
     cInterp = 0;
   }
@@ -207,5 +209,5 @@
 
   if (cNBeam <= 0) {
-    logMsg("ERROR: Couldn't determine number of beams.");
+    os << LogIO::SEVERE << "Couldn't determine number of beams." << LogIO::POST ;
     close();
     return 1;
@@ -232,6 +234,6 @@
 
       sprintf(cMsg,
-        "WARNING: RPFITSIN returned beam number %2d for AN table\n"
-        "         entry %2d with name '%.8s'", beamNo, iBeam+1, sta);
+        "RPFITSIN returned beam number %2d for AN table\n"
+        "entry %2d with name '%.8s'", beamNo, iBeam+1, sta);
 
       char text[8];
@@ -245,5 +247,5 @@
       }
 
-      logMsg(cMsg);
+      os << LogIO::WARN << cMsg << LogIO::POST ;
     }
 
@@ -339,5 +341,5 @@
   // Read the first syscal record.
   if (rpget(1, cEOS)) {
-    logMsg("ERROR: Failed to read first syscal record.");
+    os << LogIO::SEVERE << "Failed to read first syscal record." << LogIO::POST ;
     close();
     return 1;
@@ -374,6 +376,9 @@
         double &bandwidth)
 {
+  const string methodName = "getHeader()" ;
+  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
+
   if (!cMBopen) {
-    logMsg("ERROR: An MBFITS file has not been opened.");
+    os << LogIO::SEVERE << "An MBFITS file has not been opened." << LogIO::POST ;
     return 1;
   }
@@ -511,4 +516,7 @@
         MBrecord &MBrec)
 {
+  const string methodName = "read()" ;
+  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
+
   int beamNo = -1;
   int haveData, pCode = 0, status;
@@ -517,5 +525,5 @@
 
   if (!cMBopen) {
-    logMsg("ERROR: An MBFITS file has not been opened.");
+    os << LogIO::SEVERE << "An MBFITS file has not been opened." << LogIO::POST ;
     return 1;
   }
@@ -562,5 +570,5 @@
 
 #ifdef PKSIO_DEBUG
-        fprintf(stderr, "\nEnd-of-file detected, flushing last cycle.\n");
+        os << LogIO::DEBUGGING << "\nEnd-of-file detected, flushing last cycle.\n" << LogIO::POST ;
 #endif
 
@@ -646,6 +654,5 @@
 
           if (cNBin > 1 && cNBeamSel > 1) {
-            logMsg("ERROR: Cannot handle binning mode for multiple beams.\n"
-                   "       Select a single beam for input.");
+            os << LogIO::SEVERE << "Cannot handle binning mode for multiple beams.\nSelect a single beam for input." << LogIO::POST ;
             close();
             return 1;
@@ -717,6 +724,7 @@
           // the start of the next.
 #ifdef PKSIO_DEBUG
-          fprintf(stderr, "Change-of-day on cUTC: %.1f -> %.1f\n",
-            cPrevUTC, cUTC);
+          char buf[256] ;
+          sprintf(buf, "Change-of-day on cUTC: %.1f -> %.1f\n", cPrevUTC, cUTC);
+          os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
           // Can't change the recorded value of cUTC directly (without also
@@ -724,5 +732,6 @@
           // an offset to be applied when comparing integration timestamps.
           cod = 86400.0;
-        }
+
+        } 
 
         if ((cUTC+cod) < cPrevUTC - 1.0) {
@@ -738,9 +747,10 @@
             // All other data should be fully time ordered.
             sprintf(cMsg,
-              "WARNING: Cycle %d:%03d-%03d, UTC went backwards from\n"
-              "         %.1f to %.1f!  Incrementing day number,\n"
-              "         positions may be unreliable.", cScanNo, cCycleNo,
+              "Cycle %d:%03d-%03d, UTC went backwards from\n"
+              "%.1f to %.1f!  Incrementing day number,\n"
+              "positions may be unreliable.", cScanNo, cCycleNo,
               cCycleNo+1, cPrevUTC, cUTC);
-            logMsg(cMsg);
+            //logMsg(cMsg);
+            os << LogIO::WARN << cMsg << LogIO::POST ;
             cUTC += 86400.0;
           }
@@ -782,9 +792,11 @@
         }
 
-        fprintf(stderr, "\n In:%4d%4d%3d%3d  %.3f %c %.3f (%+.3fs) - "
+        sprintf(buf, "\n In:%4d%4d%3d%3d  %.3f %c %.3f (%+.3fs) - "
           "%sflushing\n", cScanNo, cCycleNo, beamNo, cIFno, cUTC, rel, cW, dt,
           cFlushing ? "" : "not ");
+        os << LogIO::DEBUGGING << buf << LogIO::POST ;
         if (cEOS) {
-          fprintf(stderr, "Start of new scan, flushing previous scan.\n");
+          sprintf(buf, "Start of new scan, flushing previous scan.\n");
+          os << LogIO::DEBUGGING << buf << LogIO::POST ;
         }
 #endif
@@ -884,6 +896,7 @@
 
 #ifdef PKSIO_DEBUG
-      fprintf(stderr, "This (%d) ra, dec, UTC: %9.4f %9.4f %10.3f %9.4f\n",
+      sprintf(buf, "This (%d) ra, dec, UTC: %9.4f %9.4f %10.3f %9.4f\n",
         iMBuff->cycleNo, thisRA*R2D, thisDec*R2D, thisUTC, thisPA*R2D);
+      os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
 
@@ -921,6 +934,7 @@
 
 #ifdef PKSIO_DEBUG
-          fprintf(stderr, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f "
+          sprintf(buf, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f "
             "(0.000s)\n", cCycleNo, cU*R2D, cV*R2D, cW);
+          os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
 
@@ -937,7 +951,8 @@
 
 #ifdef PKSIO_DEBUG
-          fprintf(stderr, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f "
+          sprintf(buf, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f "
             "(%+.3fs)\n", cCycleNo, nextRA*R2D, nextDec*R2D, nextUTC,
             utcDiff(nextUTC, thisUTC));
+          os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
 
@@ -1089,6 +1104,7 @@
 #ifdef PKSIO_DEBUG
       double avRate = sqrt(cAvRate[0]*cAvRate[0] + cAvRate[1]*cAvRate[1]);
-      fprintf(stderr, "RA, Dec, Av & PA rates: %8.4f %8.4f %8.4f %8.4f "
+      sprintf(buf, "RA, Dec, Av & PA rates: %8.4f %8.4f %8.4f %8.4f "
         "pCode %d\n", raRate*R2D, decRate*R2D, avRate*R2D, paRate*R2D, pCode);
+      os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
 
@@ -1113,8 +1129,9 @@
 
 #ifdef PKSIO_DEBUG
-        fprintf(stderr, "Intp (%d) ra, dec, UTC: %9.4f %9.4f %10.3f (pCode, "
+        sprintf(buf, "Intp (%d) ra, dec, UTC: %9.4f %9.4f %10.3f (pCode, "
           "age: %d %.1fs)\n", iMBuff->cycleNo, cBuffer[jbuff].ra*R2D,
           cBuffer[jbuff].dec*R2D, cBuffer[jbuff].utc, iMBuff->pCode,
           iMBuff->rateAge);
+        os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
       }
@@ -1130,6 +1147,7 @@
 
 #ifdef PKSIO_DEBUG
-      fprintf(stderr, "Out:%4d%4d%3d%3d\n", MBrec.scanNo, MBrec.cycleNo,
+      sprintf(buf, "Out:%4d%4d%3d%3d\n", MBrec.scanNo, MBrec.cycleNo,
         MBrec.beamNo, MBrec.IFno[0]);
+      os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
 
@@ -1172,7 +1190,7 @@
         // Sanity check on the number of IFs in the new scan.
         if (if_.n_if != cNIF) {
-          sprintf(cMsg, "WARNING: Scan %d has %d IFs instead of %d, "
+          sprintf(cMsg, "Scan %d has %d IFs instead of %d, "
             "continuing.", cScanNo, if_.n_if, cNIF);
-          logMsg(cMsg);
+          os << LogIO::WARN << cMsg << LogIO::POST ;
         }
       }
@@ -1186,5 +1204,6 @@
 
 #ifdef PKSIO_DEBUG
-      fprintf(stderr, "Buf:%4d%4d%3d%3d\n", cScanNo, cCycleNo, beamNo, cIFno);
+      sprintf(buf, "Buf:%4d%4d%3d%3d\n", cScanNo, cCycleNo, beamNo, cIFno);
+      os << LogIO::DEBUGGING << buf << LogIO::POST ;
 #endif
 
@@ -1265,8 +1284,8 @@
         // Integration cycle written to the output file twice (the only known
         // example is 1999-05-22_1914_000-031805_03v.hpf).
-        sprintf(cMsg, "WARNING: Integration cycle %d:%d, beam %2d, \n"
-                      "         IF %d was duplicated.", cScanNo, cCycleNo-1,
+        sprintf(cMsg, "Integration cycle %d:%d, beam %2d, \n"
+                      "IF %d was duplicated.", cScanNo, cCycleNo-1,
                       beamNo, cIFno);
-        logMsg(cMsg);
+        os << LogIO::WARN << cMsg << LogIO::POST ;
       }
       iMBuff->nChan[iIFSel] = nChan;
@@ -1454,4 +1473,7 @@
 int MBFITSreader::rpget(int syscalonly, int &EOS)
 {
+  const string methodName = "rpget()" ;
+  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
+
   EOS = 0;
 
@@ -1469,5 +1491,5 @@
       // Read failed; retry.
       numErr++;
-      logMsg("WARNING: RPFITS read failed - retrying.");
+      os << LogIO::WARN << "RPFITS read failed - retrying." << LogIO::POST ;
       jstat = 0;
       break;
@@ -1525,7 +1547,7 @@
     default:
       // Shouldn't reach here.
-      sprintf(cMsg, "WARNING: Unrecognized RPFITSIN return code: %d "
+      sprintf(cMsg, "Unrecognized RPFITSIN return code: %d "
                     "(retrying).", jstat);
-      logMsg(cMsg);
+      os << LogIO::WARN << cMsg << LogIO::POST ;
       jstat = 0;
       break;
@@ -1533,5 +1555,5 @@
   }
 
-  logMsg("ERROR: RPFITS read failed too many times.");
+  os << LogIO::SEVERE << "RPFITS read failed too many times." << LogIO::POST ;
   return 2;
 }
@@ -1549,4 +1571,5 @@
 
   // Handle messages from RPFITSIN.
+/**
   if (names_.errmsg[0] != ' ') {
     int i;
@@ -1559,5 +1582,5 @@
     logMsg(cMsg);
   }
-
+**/
   return jstat;
 }
