Index: branches/mergetest/external/atnf/PKSIO/SDFITSwriter.cc
===================================================================
--- branches/mergetest/external/atnf/PKSIO/SDFITSwriter.cc	(revision 1777)
+++ branches/mergetest/external/atnf/PKSIO/SDFITSwriter.cc	(revision 1779)
@@ -35,6 +35,7 @@
 
 #include <atnf/PKSIO/MBrecord.h>
-#include <atnf/PKSIO/PKSmsg.h>
 #include <atnf/PKSIO/SDFITSwriter.h>
+
+#include <casa/Logging/LogIO.h>
 
 #include <casa/iostream.h>
@@ -51,4 +52,7 @@
 // Factor to convert radians to degrees.
 const double R2D = 180.0 / PI;
+
+// Class name
+const string className = "SDFITSwriter" ;
 
 //------------------------------------------------- SDFITSwriter::SDFITSwriter
@@ -58,7 +62,4 @@
   // Default constructor.
   cSDptr = 0x0;
-
-  // By default, messages are written to stderr.
-  initMsg();
 }
 
@@ -91,11 +92,10 @@
         int    extraSysCal)
 {
+  const string methodName = "create()" ;
+
   if (cSDptr) {
-    logMsg("ERROR: Output file already open, close it first.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Output file already open, close it first.");
     return 1;
   }
-
-  // Clear the message stack.
-  clearMsg();
 
   // Prepend an '!' to the output name to force it to be overwritten.
@@ -107,6 +107,6 @@
   cStatus = 0;
   if (fits_create_file(&cSDptr, sdname, &cStatus)) {
-    sprintf(cMsg, "ERROR: Failed to create SDFITS file\n       %s", sdName);
-    logMsg(cMsg);
+    sprintf(cMsg, "Failed to create SDFITS file\n       %s", sdName);
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, cMsg);
     return cStatus;
   }
@@ -156,5 +156,5 @@
   // Write required primary header keywords.
   if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) {
-    logMsg("ERROR: Failed to write required primary header keywords.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to write required primary header keywords.");
     return cStatus;
   }
@@ -188,5 +188,5 @@
 
   if (cStatus) {
-    logMsg("ERROR: Failed in writing primary header.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing primary header.");
     return cStatus;
   }
@@ -198,5 +198,5 @@
   if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL,
       "SINGLE DISH", &cStatus)) {
-    logMsg("ERROR: Failed to create a binary table extension.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to create a binary table extension.");
     return 1;
   }
@@ -548,5 +548,5 @@
 
   if (cStatus) {
-    logMsg("ERROR: Failed in writing binary table header.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table header.");
   }
 
@@ -560,4 +560,7 @@
 int SDFITSwriter::write(MBrecord &mbrec)
 {
+  const string methodName = "write()" ;
+  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
+
   char *cptr;
 
@@ -565,7 +568,8 @@
   int IFno = mbrec.IFno[0];
   if (IFno < 1 || cNIF < IFno) {
-    cerr << "SDFITSwriter::write: "
-         << "Invalid IF number " << IFno
-         << " (maximum " << cNIF << ")." << endl;
+    os << LogIO::WARN
+       << "SDFITSwriter::write: "
+       << "Invalid IF number " << IFno
+       << " (maximum " << cNIF << ")." << LogIO::POST ;
     return 1;
   }
@@ -574,8 +578,10 @@
   int nChan = cNChan[iIF];
   if (mbrec.nChan[0] != nChan) {
-    cerr << "SDFITSriter::write: "
-         << "Wrong number of channels for IF " << IFno << "," << endl
-         << "                    "
-         << "got " << nChan << " should be " << mbrec.nChan[0] << "." << endl;
+    os << LogIO::WARN
+       << "SDFITSriter::write: "
+       << "Wrong number of channels for IF " << IFno << "," << endl
+       << "                    "
+       << "got " << nChan << " should be " << mbrec.nChan[0] << "." << endl;
+    os << LogIO::POST ;
     return 1;
   }
@@ -583,8 +589,10 @@
   int nPol = cNPol[iIF];
   if (mbrec.nPol[0] != nPol) {
-    cerr << "SDFITSriter::write: "
-         << "Wrong number of polarizations for IF " << IFno << "," << endl
-         << "                    "
-         << "got " << nPol << " should be " << mbrec.nPol[0] << "." << endl;
+    os << LogIO::WARN
+       << "SDFITSriter::write: "
+       << "Wrong number of polarizations for IF " << IFno << "," << endl
+       << "                    "
+       << "got " << nPol << " should be " << mbrec.nPol[0] << "." << endl;
+    os << LogIO::POST ;
     return 1;
   }
@@ -768,5 +776,5 @@
 
   if (cStatus) {
-    logMsg("ERROR: Failed in writing binary table entry.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table entry.");
   }
 
@@ -782,4 +790,6 @@
 
 {
+  const string methodName = "history()" ;
+
   if (!cSDptr) {
     return 1;
@@ -787,5 +797,5 @@
 
   if (fits_write_history(cSDptr, text, &cStatus)) {
-    logMsg("ERROR: Failed in writing HISTORY records.");
+    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing HISTORY records.");
   }
 
@@ -799,8 +809,10 @@
 void SDFITSwriter::close()
 {
+  const string methodName = "close()" ;
+
   if (cSDptr) {
     cStatus = 0;
     if (fits_close_file(cSDptr, &cStatus)) {
-      logMsg("ERROR: Failed to close file.");
+      log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close file.");
     }
 
@@ -815,8 +827,10 @@
 void SDFITSwriter::deleteFile()
 {
+  const string methodName = "deleteFile()" ;
+
   if (cSDptr) {
     cStatus = 0;
     if (fits_delete_file(cSDptr, &cStatus)) {
-      logMsg("ERROR: Failed to close and delete file.");
+      log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close and delete file.");
     }
 
@@ -825,20 +839,24 @@
 }
 
-//------------------------------------------------------- SDFITSwriter::logMsg
+//------------------------------------------------------- SDFITSwriter::log
 
 // Log a message.  If the current CFITSIO status value is non-zero, also log
 // the corresponding error message and dump the CFITSIO message stack.
 
-void SDFITSwriter::logMsg(const char *msg)
+void SDFITSwriter::log(LogOrigin origin, LogIO::Command cmd, const char *msg)
 {
-  PKSmsg::logMsg(msg);
+  LogIO os( origin ) ;
+
+  os << cmd << msg << endl ;
 
   if (cStatus) {
     fits_get_errstatus(cStatus, cMsg);
-    PKSmsg::logMsg(cMsg);
+    os << cMsg << endl ; 
 
     while (fits_read_errmsg(cMsg)) {
-      PKSmsg::logMsg(cMsg);
-    }
-  }
+      os << cMsg << endl ;
+    }
+  }
+
+  os << LogIO::POST ;
 }
