Changeset 1452 for trunk/external/atnf/PKSIO/SDFITSwriter.cc
- Timestamp:
- 11/19/08 20:41:16 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/external/atnf/PKSIO/SDFITSwriter.cc
r1399 r1452 2 2 //# SDFITSwriter.cc: ATNF CFITSIO interface class for SDFITS output. 3 3 //#--------------------------------------------------------------------------- 4 //# Copyright (C) 2000-200 74 //# Copyright (C) 2000-2008 5 5 //# Mark Calabretta, ATNF 6 6 //# … … 27 27 //# AUSTRALIA 28 28 //# 29 //# $Id: SDFITSwriter.cc,v 19.1 2 2007/11/12 03:37:56cal103 Exp $29 //# $Id: SDFITSwriter.cc,v 19.15 2008-11-17 06:58:58 cal103 Exp $ 30 30 //#--------------------------------------------------------------------------- 31 31 //# Original: 2000/07/24, Mark Calabretta, ATNF 32 32 //#--------------------------------------------------------------------------- 33 33 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 34 40 #include <algorithm> 35 41 #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>43 42 44 43 using namespace std; … … 55 54 { 56 55 // Default constructor. 57 cSDptr = 0; 56 cSDptr = 0x0; 57 58 // By default, messages are written to stderr. 59 initMsg(); 58 60 } 59 61 … … 86 88 int extraSysCal) 87 89 { 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 88 98 // Prepend an '!' to the output name to force it to be overwritten. 89 99 char sdname[80]; … … 94 104 cStatus = 0; 95 105 if (fits_create_file(&cSDptr, sdname, &cStatus)) { 106 sprintf(cMsg, "ERROR: Failed to create SDFITS file\n %s", sdName); 107 logMsg(cMsg); 96 108 return cStatus; 97 109 } … … 141 153 // Write required primary header keywords. 142 154 if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) { 155 logMsg("ERROR: Failed to write required primary header keywords."); 143 156 return cStatus; 144 157 } … … 160 173 char version[7]; 161 174 char date[11]; 162 sscanf("$Revision: 19.1 2$", "%*s%s", version);163 sscanf("$Date: 200 7/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); 164 177 sprintf(text, "SDFITSwriter (v%s, %s)", version, date); 165 178 fits_write_key_str(cSDptr, "ORIGIN", text, "output class", &cStatus); … … 171 184 fits_write_comment(cSDptr, text, &cStatus); 172 185 186 if (cStatus) { 187 logMsg("ERROR: Failed in writing primary header."); 188 return cStatus; 189 } 190 191 173 192 // Create an SDFITS extension. 174 193 long nrow = 0; … … 176 195 if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL, 177 196 "SINGLE DISH", &cStatus)) { 197 logMsg("ERROR: Failed to create a binary table extension."); 178 198 return 1; 179 199 } … … 524 544 } 525 545 546 if (cStatus) { 547 logMsg("ERROR: Failed in writing binary table header."); 548 } 549 526 550 return cStatus; 527 551 } … … 531 555 // Write a record to the SDFITS file. 532 556 533 int SDFITSwriter::write( PKSMBrecord &mbrec)557 int SDFITSwriter::write(MBrecord &mbrec) 534 558 { 535 559 char *cptr; … … 740 764 } 741 765 766 if (cStatus) { 767 logMsg("ERROR: Failed in writing binary table entry."); 768 } 769 742 770 return cStatus; 743 771 } … … 751 779 752 780 { 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 } 754 788 755 789 return cStatus; 756 }757 758 //-------------------------------------------------- SDFITSwriter::reportError759 760 // Print the error message corresponding to the input status value and all the761 // messages on the CFITSIO error stack to stderr.762 763 void SDFITSwriter::reportError()764 {765 fits_report_error(stderr, cStatus);766 790 } 767 791 … … 774 798 if (cSDptr) { 775 799 cStatus = 0; 776 fits_close_file(cSDptr, &cStatus); 800 if (fits_close_file(cSDptr, &cStatus)) { 801 logMsg("ERROR: Failed to close file."); 802 } 803 777 804 cSDptr = 0; 778 805 } … … 787 814 if (cSDptr) { 788 815 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 790 820 cSDptr = 0; 791 821 } 792 822 } 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 829 void 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.