Ignore:
Timestamp:
07/29/10 19:13:46 (14 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: No (test merging alma branch)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s):

Description:


Location:
branches/mergetest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/mergetest

  • branches/mergetest/external/atnf/PKSIO/SDFITSwriter.cc

    r1736 r1779  
    3535
    3636#include <atnf/PKSIO/MBrecord.h>
    37 #include <atnf/PKSIO/PKSmsg.h>
    3837#include <atnf/PKSIO/SDFITSwriter.h>
     38
     39#include <casa/Logging/LogIO.h>
    3940
    4041#include <casa/iostream.h>
     
    5152// Factor to convert radians to degrees.
    5253const double R2D = 180.0 / PI;
     54
     55// Class name
     56const string className = "SDFITSwriter" ;
    5357
    5458//------------------------------------------------- SDFITSwriter::SDFITSwriter
     
    5862  // Default constructor.
    5963  cSDptr = 0x0;
    60 
    61   // By default, messages are written to stderr.
    62   initMsg();
    6364}
    6465
     
    9192        int    extraSysCal)
    9293{
     94  const string methodName = "create()" ;
     95
    9396  if (cSDptr) {
    94     logMsg("ERROR: Output file already open, close it first.");
     97    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Output file already open, close it first.");
    9598    return 1;
    9699  }
    97 
    98   // Clear the message stack.
    99   clearMsg();
    100100
    101101  // Prepend an '!' to the output name to force it to be overwritten.
     
    107107  cStatus = 0;
    108108  if (fits_create_file(&cSDptr, sdname, &cStatus)) {
    109     sprintf(cMsg, "ERROR: Failed to create SDFITS file\n       %s", sdName);
    110     logMsg(cMsg);
     109    sprintf(cMsg, "Failed to create SDFITS file\n       %s", sdName);
     110    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, cMsg);
    111111    return cStatus;
    112112  }
     
    156156  // Write required primary header keywords.
    157157  if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) {
    158     logMsg("ERROR: Failed to write required primary header keywords.");
     158    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to write required primary header keywords.");
    159159    return cStatus;
    160160  }
     
    188188
    189189  if (cStatus) {
    190     logMsg("ERROR: Failed in writing primary header.");
     190    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing primary header.");
    191191    return cStatus;
    192192  }
     
    198198  if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL,
    199199      "SINGLE DISH", &cStatus)) {
    200     logMsg("ERROR: Failed to create a binary table extension.");
     200    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to create a binary table extension.");
    201201    return 1;
    202202  }
     
    548548
    549549  if (cStatus) {
    550     logMsg("ERROR: Failed in writing binary table header.");
     550    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table header.");
    551551  }
    552552
     
    560560int SDFITSwriter::write(MBrecord &mbrec)
    561561{
     562  const string methodName = "write()" ;
     563  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
     564
    562565  char *cptr;
    563566
     
    565568  int IFno = mbrec.IFno[0];
    566569  if (IFno < 1 || cNIF < IFno) {
    567     cerr << "SDFITSwriter::write: "
    568          << "Invalid IF number " << IFno
    569          << " (maximum " << cNIF << ")." << endl;
     570    os << LogIO::WARN
     571       << "SDFITSwriter::write: "
     572       << "Invalid IF number " << IFno
     573       << " (maximum " << cNIF << ")." << LogIO::POST ;
    570574    return 1;
    571575  }
     
    574578  int nChan = cNChan[iIF];
    575579  if (mbrec.nChan[0] != nChan) {
    576     cerr << "SDFITSriter::write: "
    577          << "Wrong number of channels for IF " << IFno << "," << endl
    578          << "                    "
    579          << "got " << nChan << " should be " << mbrec.nChan[0] << "." << endl;
     580    os << LogIO::WARN
     581       << "SDFITSriter::write: "
     582       << "Wrong number of channels for IF " << IFno << "," << endl
     583       << "                    "
     584       << "got " << nChan << " should be " << mbrec.nChan[0] << "." << endl;
     585    os << LogIO::POST ;
    580586    return 1;
    581587  }
     
    583589  int nPol = cNPol[iIF];
    584590  if (mbrec.nPol[0] != nPol) {
    585     cerr << "SDFITSriter::write: "
    586          << "Wrong number of polarizations for IF " << IFno << "," << endl
    587          << "                    "
    588          << "got " << nPol << " should be " << mbrec.nPol[0] << "." << endl;
     591    os << LogIO::WARN
     592       << "SDFITSriter::write: "
     593       << "Wrong number of polarizations for IF " << IFno << "," << endl
     594       << "                    "
     595       << "got " << nPol << " should be " << mbrec.nPol[0] << "." << endl;
     596    os << LogIO::POST ;
    589597    return 1;
    590598  }
     
    768776
    769777  if (cStatus) {
    770     logMsg("ERROR: Failed in writing binary table entry.");
     778    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table entry.");
    771779  }
    772780
     
    782790
    783791{
     792  const string methodName = "history()" ;
     793
    784794  if (!cSDptr) {
    785795    return 1;
     
    787797
    788798  if (fits_write_history(cSDptr, text, &cStatus)) {
    789     logMsg("ERROR: Failed in writing HISTORY records.");
     799    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing HISTORY records.");
    790800  }
    791801
     
    799809void SDFITSwriter::close()
    800810{
     811  const string methodName = "close()" ;
     812
    801813  if (cSDptr) {
    802814    cStatus = 0;
    803815    if (fits_close_file(cSDptr, &cStatus)) {
    804       logMsg("ERROR: Failed to close file.");
     816      log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close file.");
    805817    }
    806818
     
    815827void SDFITSwriter::deleteFile()
    816828{
     829  const string methodName = "deleteFile()" ;
     830
    817831  if (cSDptr) {
    818832    cStatus = 0;
    819833    if (fits_delete_file(cSDptr, &cStatus)) {
    820       logMsg("ERROR: Failed to close and delete file.");
     834      log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close and delete file.");
    821835    }
    822836
     
    825839}
    826840
    827 //------------------------------------------------------- SDFITSwriter::logMsg
     841//------------------------------------------------------- SDFITSwriter::log
    828842
    829843// Log a message.  If the current CFITSIO status value is non-zero, also log
    830844// the corresponding error message and dump the CFITSIO message stack.
    831845
    832 void SDFITSwriter::logMsg(const char *msg)
     846void SDFITSwriter::log(LogOrigin origin, LogIO::Command cmd, const char *msg)
    833847{
    834   PKSmsg::logMsg(msg);
     848  LogIO os( origin ) ;
     849
     850  os << cmd << msg << endl ;
    835851
    836852  if (cStatus) {
    837853    fits_get_errstatus(cStatus, cMsg);
    838     PKSmsg::logMsg(cMsg);
     854    os << cMsg << endl ;
    839855
    840856    while (fits_read_errmsg(cMsg)) {
    841       PKSmsg::logMsg(cMsg);
    842     }
    843   }
     857      os << cMsg << endl ;
     858    }
     859  }
     860
     861  os << LogIO::POST ;
    844862}
Note: See TracChangeset for help on using the changeset viewer.