Ignore:
Timestamp:
11/19/08 20:41:16 (16 years ago)
Author:
Malte Marquarding
Message:

update from livedata CVS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/external/atnf/PKSIO/SDFITSwriter.cc

    r1399 r1452  
    22//# SDFITSwriter.cc: ATNF CFITSIO interface class for SDFITS output.
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2000-2007
     4//# Copyright (C) 2000-2008
    55//# Mark Calabretta, ATNF
    66//#
     
    2727//#                        AUSTRALIA
    2828//#
    29 //# $Id: SDFITSwriter.cc,v 19.12 2007/11/12 03:37:56 cal103 Exp $
     29//# $Id: SDFITSwriter.cc,v 19.15 2008-11-17 06:58:58 cal103 Exp $
    3030//#---------------------------------------------------------------------------
    3131//# Original: 2000/07/24, Mark Calabretta, ATNF
    3232//#---------------------------------------------------------------------------
    3333
     34#include <atnf/PKSIO/MBrecord.h>
     35#include <atnf/PKSIO/PKSmsg.h>
     36#include <atnf/PKSIO/SDFITSwriter.h>
     37
     38#include <casa/iostream.h>
     39
    3440#include <algorithm>
    3541#include <math.h>
    36 
    37 // AIPS++ includes.
    38 #include <casa/iostream.h>
    39 
    40 // ATNF includes.
    41 #include <atnf/PKSIO/PKSMBrecord.h>
    42 #include <atnf/PKSIO/SDFITSwriter.h>
    4342
    4443using namespace std;
     
    5554{
    5655  // Default constructor.
    57   cSDptr = 0;
     56  cSDptr = 0x0;
     57
     58  // By default, messages are written to stderr.
     59  initMsg();
    5860}
    5961
     
    8688        int    extraSysCal)
    8789{
     90  if (cSDptr) {
     91    logMsg("ERROR: Output file already open, close it first.");
     92    return 1;
     93  }
     94
     95  // Clear the message stack.
     96  clearMsg();
     97
    8898  // Prepend an '!' to the output name to force it to be overwritten.
    8999  char sdname[80];
     
    94104  cStatus = 0;
    95105  if (fits_create_file(&cSDptr, sdname, &cStatus)) {
     106    sprintf(cMsg, "ERROR: Failed to create SDFITS file\n       %s", sdName);
     107    logMsg(cMsg);
    96108    return cStatus;
    97109  }
     
    141153  // Write required primary header keywords.
    142154  if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) {
     155    logMsg("ERROR: Failed to write required primary header keywords.");
    143156    return cStatus;
    144157  }
     
    160173  char version[7];
    161174  char date[11];
    162   sscanf("$Revision: 19.12 $", "%*s%s", version);
    163   sscanf("$Date: 2007/11/12 03:37:56 $", "%*s%s", date);
     175  sscanf("$Revision: 19.15 $", "%*s%s", version);
     176  sscanf("$Date: 2008-11-17 06:58:58 $", "%*s%s", date);
    164177  sprintf(text, "SDFITSwriter (v%s, %s)", version, date);
    165178  fits_write_key_str(cSDptr, "ORIGIN", text, "output class", &cStatus);
     
    171184  fits_write_comment(cSDptr, text, &cStatus);
    172185
     186  if (cStatus) {
     187    logMsg("ERROR: Failed in writing primary header.");
     188    return cStatus;
     189  }
     190
     191
    173192  // Create an SDFITS extension.
    174193  long nrow = 0;
     
    176195  if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL,
    177196      "SINGLE DISH", &cStatus)) {
     197    logMsg("ERROR: Failed to create a binary table extension.");
    178198    return 1;
    179199  }
     
    524544  }
    525545
     546  if (cStatus) {
     547    logMsg("ERROR: Failed in writing binary table header.");
     548  }
     549
    526550  return cStatus;
    527551}
     
    531555// Write a record to the SDFITS file.
    532556
    533 int SDFITSwriter::write(PKSMBrecord &mbrec)
     557int SDFITSwriter::write(MBrecord &mbrec)
    534558{
    535559  char *cptr;
     
    740764  }
    741765
     766  if (cStatus) {
     767    logMsg("ERROR: Failed in writing binary table entry.");
     768  }
     769
    742770  return cStatus;
    743771}
     
    751779
    752780{
    753   fits_write_history(cSDptr, text, &cStatus);
     781  if (!cSDptr) {
     782    return 1;
     783  }
     784
     785  if (fits_write_history(cSDptr, text, &cStatus)) {
     786    logMsg("ERROR: Failed in writing HISTORY records.");
     787  }
    754788
    755789  return cStatus;
    756 }
    757 
    758 //-------------------------------------------------- SDFITSwriter::reportError
    759 
    760 // Print the error message corresponding to the input status value and all the
    761 // messages on the CFITSIO error stack to stderr.
    762 
    763 void SDFITSwriter::reportError()
    764 {
    765   fits_report_error(stderr, cStatus);
    766790}
    767791
     
    774798  if (cSDptr) {
    775799    cStatus = 0;
    776     fits_close_file(cSDptr, &cStatus);
     800    if (fits_close_file(cSDptr, &cStatus)) {
     801      logMsg("ERROR: Failed to close file.");
     802    }
     803
    777804    cSDptr = 0;
    778805  }
     
    787814  if (cSDptr) {
    788815    cStatus = 0;
    789     fits_delete_file(cSDptr, &cStatus);
     816    if (fits_delete_file(cSDptr, &cStatus)) {
     817      logMsg("ERROR: Failed to close and delete file.");
     818    }
     819
    790820    cSDptr = 0;
    791821  }
    792822}
     823
     824//------------------------------------------------------- SDFITSwriter::logMsg
     825
     826// Log a message.  If the current CFITSIO status value is non-zero, also log
     827// the corresponding error message and dump the CFITSIO message stack.
     828
     829void SDFITSwriter::logMsg(const char *msg)
     830{
     831  PKSmsg::logMsg(msg);
     832
     833  if (cStatus) {
     834    fits_get_errstatus(cStatus, cMsg);
     835    PKSmsg::logMsg(cMsg);
     836
     837    while (fits_read_errmsg(cMsg)) {
     838      PKSmsg::logMsg(cMsg);
     839    }
     840  }
     841}
Note: See TracChangeset for help on using the changeset viewer.