Ignore:
Timestamp:
06/09/10 19:03:06 (14 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


Location:
branches/alma
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/alma

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

    r1453 r1757  
    22//# SDFITSwriter.cc: ATNF CFITSIO interface class for SDFITS output.
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2000-2006
    5 //# Mark Calabretta, ATNF
     4//# livedata - processing pipeline for single-dish, multibeam spectral data.
     5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
    66//#
    7 //# This library is free software; you can redistribute it and/or modify it
    8 //# under the terms of the GNU Library General Public License as published by
    9 //# the Free Software Foundation; either version 2 of the License, or (at your
    10 //# option) any later version.
     7//# This file is part of livedata.
    118//#
    12 //# This library is distributed in the hope that it will be useful, but WITHOUT
     9//# livedata is free software: you can redistribute it and/or modify it under
     10//# the terms of the GNU General Public License as published by the Free
     11//# Software Foundation, either version 3 of the License, or (at your option)
     12//# any later version.
     13//#
     14//# livedata is distributed in the hope that it will be useful, but WITHOUT
    1315//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    14 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    15 //# License for more details.
     16//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     17//# more details.
    1618//#
    17 //# You should have received a copy of the GNU Library General Public License
    18 //# along with this library; if not, write to the Free Software Foundation,
    19 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
     19//# You should have received a copy of the GNU General Public License along
     20//# with livedata.  If not, see <http://www.gnu.org/licenses/>.
    2021//#
    21 //# Correspondence concerning this software should be addressed as follows:
    22 //#        Internet email: mcalabre@atnf.csiro.au.
    23 //#        Postal address: Dr. Mark Calabretta,
    24 //#                        Australia Telescope National Facility,
    25 //#                        P.O. Box 76,
    26 //#                        Epping, NSW, 2121,
     22//# Correspondence concerning livedata may be directed to:
     23//#        Internet email: mcalabre@atnf.csiro.au
     24//#        Postal address: Dr. Mark Calabretta
     25//#                        Australia Telescope National Facility, CSIRO
     26//#                        PO Box 76
     27//#                        Epping NSW 1710
    2728//#                        AUSTRALIA
    2829//#
    29 //# $Id$
     30//# http://www.atnf.csiro.au/computing/software/livedata.html
     31//# $Id: SDFITSwriter.cc,v 19.18 2009-09-29 07:33:39 cal103 Exp $
    3032//#---------------------------------------------------------------------------
    3133//# Original: 2000/07/24, Mark Calabretta, ATNF
    3234//#---------------------------------------------------------------------------
    3335
     36#include <atnf/PKSIO/MBrecord.h>
     37#include <atnf/PKSIO/SDFITSwriter.h>
     38
     39#include <casa/Logging/LogIO.h>
     40
     41#include <casa/iostream.h>
     42
    3443#include <algorithm>
    3544#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>
     45#include <cstring>
    4346
    4447using namespace std;
     
    4952// Factor to convert radians to degrees.
    5053const double R2D = 180.0 / PI;
     54
     55// Class name
     56const string className = "SDFITSwriter" ;
    5157
    5258//------------------------------------------------- SDFITSwriter::SDFITSwriter
     
    5561{
    5662  // Default constructor.
    57   cSDptr = 0;
     63  cSDptr = 0x0;
    5864}
    5965
     
    7682        double antPos[3],
    7783        char*  obsMode,
     84        char*  bunit,
    7885        float  equinox,
    7986        char*  dopplerFrame,
     
    8592        int    extraSysCal)
    8693{
     94  const string methodName = "create()" ;
     95
     96  if (cSDptr) {
     97    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Output file already open, close it first.");
     98    return 1;
     99  }
     100
    87101  // Prepend an '!' to the output name to force it to be overwritten.
    88102  char sdname[80];
     
    93107  cStatus = 0;
    94108  if (fits_create_file(&cSDptr, sdname, &cStatus)) {
     109    sprintf(cMsg, "Failed to create SDFITS file\n       %s", sdName);
     110    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, cMsg);
    95111    return cStatus;
    96112  }
     
    113129      break;
    114130    }
    115    
     131
    116132    if (cNChan[iIF] != cNChan[0] || cNPol[iIF] != cNPol[0]) {
    117133      // Varying channels and/or polarizations, need a TDIM column at least.
     
    140156  // Write required primary header keywords.
    141157  if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) {
     158    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to write required primary header keywords.");
    142159    return cStatus;
    143160  }
     
    159176  char version[7];
    160177  char date[11];
    161   sscanf("$Revision: 19.10 $", "%*s%s", version);
    162   sscanf("$Date: 2006/07/05 05:44:52 $", "%*s%s", date);
     178  sscanf("$Revision: 19.18 $", "%*s%s", version);
     179  sscanf("$Date: 2009-09-29 07:33:39 $", "%*s%s", date);
    163180  sprintf(text, "SDFITSwriter (v%s, %s)", version, date);
    164181  fits_write_key_str(cSDptr, "ORIGIN", text, "output class", &cStatus);
     
    170187  fits_write_comment(cSDptr, text, &cStatus);
    171188
     189  if (cStatus) {
     190    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing primary header.");
     191    return cStatus;
     192  }
     193
     194
    172195  // Create an SDFITS extension.
    173196  long nrow = 0;
     
    175198  if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL,
    176199      "SINGLE DISH", &cStatus)) {
     200    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to create a binary table extension.");
    177201    return 1;
    178202  }
     
    209233
    210234  // CYCLE (additional, real).
    211   fits_insert_col(cSDptr, ++ncol, "CYCLE", "1I", &cStatus);
     235  fits_insert_col(cSDptr, ++ncol, "CYCLE", "1J", &cStatus);
    212236
    213237  // DATE-OBS (core, real).
     
    355379  fits_insert_col(cSDptr, ++ncol, "TSYS", tform, &cStatus);
    356380  sprintf(tunit, "TUNIT%d", ncol);
    357   fits_write_key_str(cSDptr, tunit, "Jy", "units of field", &cStatus);
     381  fits_write_key_str(cSDptr, tunit, bunit, "units of field", &cStatus);
    358382
    359383  // CALFCTR (additional, real).
     
    369393
    370394    // BASESUB (additional, real).
    371     sprintf(tform, "%dE", 9*maxNPol);
     395    sprintf(tform, "%dE", 24*maxNPol);
    372396    fits_insert_col(cSDptr, ++ncol, "BASESUB", tform, &cStatus);
    373     tdim[0] = 9;
     397    tdim[0] = 24;
    374398    fits_write_tdim(cSDptr, ncol, 2, tdim, &cStatus);
    375399  }
     
    396420
    397421  sprintf(tunit, "TUNIT%d", ncol);
    398   fits_write_key_str(cSDptr, tunit, "Jy", "units of field", &cStatus);
     422  fits_write_key_str(cSDptr, tunit, bunit, "units of field", &cStatus);
    399423
    400424  // FLAGGED (additional, logical).
     
    444468
    445469    sprintf(tunit, "TUNIT%d", ncol);
    446     fits_write_key_str(cSDptr, tunit, "Jy", "units of field", &cStatus);
     470    fits_write_key_str(cSDptr, tunit, bunit, "units of field", &cStatus);
    447471  }
    448472
     
    523547  }
    524548
     549  if (cStatus) {
     550    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table header.");
     551  }
     552
    525553  return cStatus;
    526554}
     
    530558// Write a record to the SDFITS file.
    531559
    532 int SDFITSwriter::write(PKSMBrecord &mbrec)
     560int SDFITSwriter::write(MBrecord &mbrec)
    533561{
     562  const string methodName = "write()" ;
     563  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
     564
    534565  char *cptr;
    535566
     
    537568  int IFno = mbrec.IFno[0];
    538569  if (IFno < 1 || cNIF < IFno) {
    539     cerr << "SDFITSwriter::write: "
    540          << "Invalid IF number " << IFno
    541          << " (maximum " << cNIF << ")." << endl;
     570    os << LogIO::WARN
     571       << "SDFITSwriter::write: "
     572       << "Invalid IF number " << IFno
     573       << " (maximum " << cNIF << ")." << LogIO::POST ;
    542574    return 1;
    543575  }
     
    546578  int nChan = cNChan[iIF];
    547579  if (mbrec.nChan[0] != nChan) {
    548     cerr << "SDFITSriter::write: "
    549          << "Wrong number of channels for IF " << IFno << "," << endl
    550          << "                    "
    551          << "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 ;
    552586    return 1;
    553587  }
     
    555589  int nPol = cNPol[iIF];
    556590  if (mbrec.nPol[0] != nPol) {
    557     cerr << "SDFITSriter::write: "
    558          << "Wrong number of polarizations for IF " << IFno << "," << endl
    559          << "                    "
    560          << "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 ;
    561597    return 1;
    562598  }
     
    655691
    656692    // BASESUB.
    657     fits_write_col_flt(cSDptr, ++icol, cRow, 1, 9*nPol, mbrec.baseSub[0][0],
     693    fits_write_col_flt(cSDptr, ++icol, cRow, 1, 24*nPol, mbrec.baseSub[0][0],
    658694                       &cStatus);
    659695  }
     
    739775  }
    740776
     777  if (cStatus) {
     778    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table entry.");
     779  }
     780
    741781  return cStatus;
    742782}
    743783
    744784
    745 //-------------------------------------------------- SDFITSwriter::reportError
    746 
    747 // Print the error message corresponding to the input status value and all the
    748 // messages on the CFITSIO error stack to stderr.
    749 
    750 void SDFITSwriter::reportError()
     785//------------------------------------------------------ SDFITSwriter::history
     786
     787// Write a history record.
     788
     789int SDFITSwriter::history(char *text)
     790
    751791{
    752   fits_report_error(stderr, cStatus);
     792  const string methodName = "history()" ;
     793
     794  if (!cSDptr) {
     795    return 1;
     796  }
     797
     798  if (fits_write_history(cSDptr, text, &cStatus)) {
     799    log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing HISTORY records.");
     800  }
     801
     802  return cStatus;
    753803}
    754804
     
    759809void SDFITSwriter::close()
    760810{
     811  const string methodName = "close()" ;
     812
    761813  if (cSDptr) {
    762814    cStatus = 0;
    763     fits_close_file(cSDptr, &cStatus);
     815    if (fits_close_file(cSDptr, &cStatus)) {
     816      log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close file.");
     817    }
     818
    764819    cSDptr = 0;
    765820  }
     
    772827void SDFITSwriter::deleteFile()
    773828{
     829  const string methodName = "deleteFile()" ;
     830
    774831  if (cSDptr) {
    775832    cStatus = 0;
    776     fits_delete_file(cSDptr, &cStatus);
     833    if (fits_delete_file(cSDptr, &cStatus)) {
     834      log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close and delete file.");
     835    }
     836
    777837    cSDptr = 0;
    778838  }
    779839}
     840
     841//------------------------------------------------------- SDFITSwriter::log
     842
     843// Log a message.  If the current CFITSIO status value is non-zero, also log
     844// the corresponding error message and dump the CFITSIO message stack.
     845
     846void SDFITSwriter::log(LogOrigin origin, LogIO::Command cmd, const char *msg)
     847{
     848  LogIO os( origin ) ;
     849
     850  os << cmd << msg << endl ;
     851
     852  if (cStatus) {
     853    fits_get_errstatus(cStatus, cMsg);
     854    os << cMsg << endl ;
     855
     856    while (fits_read_errmsg(cMsg)) {
     857      os << cMsg << endl ;
     858    }
     859  }
     860
     861  os << LogIO::POST ;
     862}
Note: See TracChangeset for help on using the changeset viewer.