Changeset 1757 for branches/alma/external/atnf/PKSIO/SDFITSwriter.cc
- Timestamp:
- 06/09/10 19:03:06 (14 years ago)
- Location:
- branches/alma
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma
-
Property
svn:ignore
set to
.sconf_temp
.sconsign.dblite
-
Property
svn:mergeinfo
set to
/branches/asap-3.x merged eligible
-
Property
svn:ignore
set to
-
branches/alma/external/atnf/PKSIO/SDFITSwriter.cc
r1453 r1757 2 2 //# SDFITSwriter.cc: ATNF CFITSIO interface class for SDFITS output. 3 3 //#--------------------------------------------------------------------------- 4 //# Copyright (C) 2000-20065 //# Mark Calabretta, ATNF4 //# livedata - processing pipeline for single-dish, multibeam spectral data. 5 //# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO 6 6 //# 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. 11 8 //# 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 13 15 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public15 //# License formore details.16 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 //# more details. 16 18 //# 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/>. 20 21 //# 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 27 28 //# AUSTRALIA 28 29 //# 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 $ 30 32 //#--------------------------------------------------------------------------- 31 33 //# Original: 2000/07/24, Mark Calabretta, ATNF 32 34 //#--------------------------------------------------------------------------- 33 35 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 34 43 #include <algorithm> 35 44 #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> 43 46 44 47 using namespace std; … … 49 52 // Factor to convert radians to degrees. 50 53 const double R2D = 180.0 / PI; 54 55 // Class name 56 const string className = "SDFITSwriter" ; 51 57 52 58 //------------------------------------------------- SDFITSwriter::SDFITSwriter … … 55 61 { 56 62 // Default constructor. 57 cSDptr = 0 ;63 cSDptr = 0x0; 58 64 } 59 65 … … 76 82 double antPos[3], 77 83 char* obsMode, 84 char* bunit, 78 85 float equinox, 79 86 char* dopplerFrame, … … 85 92 int extraSysCal) 86 93 { 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 87 101 // Prepend an '!' to the output name to force it to be overwritten. 88 102 char sdname[80]; … … 93 107 cStatus = 0; 94 108 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); 95 111 return cStatus; 96 112 } … … 113 129 break; 114 130 } 115 131 116 132 if (cNChan[iIF] != cNChan[0] || cNPol[iIF] != cNPol[0]) { 117 133 // Varying channels and/or polarizations, need a TDIM column at least. … … 140 156 // Write required primary header keywords. 141 157 if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) { 158 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to write required primary header keywords."); 142 159 return cStatus; 143 160 } … … 159 176 char version[7]; 160 177 char date[11]; 161 sscanf("$Revision: 19.1 0$", "%*s%s", version);162 sscanf("$Date: 200 6/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); 163 180 sprintf(text, "SDFITSwriter (v%s, %s)", version, date); 164 181 fits_write_key_str(cSDptr, "ORIGIN", text, "output class", &cStatus); … … 170 187 fits_write_comment(cSDptr, text, &cStatus); 171 188 189 if (cStatus) { 190 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing primary header."); 191 return cStatus; 192 } 193 194 172 195 // Create an SDFITS extension. 173 196 long nrow = 0; … … 175 198 if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL, 176 199 "SINGLE DISH", &cStatus)) { 200 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to create a binary table extension."); 177 201 return 1; 178 202 } … … 209 233 210 234 // CYCLE (additional, real). 211 fits_insert_col(cSDptr, ++ncol, "CYCLE", "1 I", &cStatus);235 fits_insert_col(cSDptr, ++ncol, "CYCLE", "1J", &cStatus); 212 236 213 237 // DATE-OBS (core, real). … … 355 379 fits_insert_col(cSDptr, ++ncol, "TSYS", tform, &cStatus); 356 380 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); 358 382 359 383 // CALFCTR (additional, real). … … 369 393 370 394 // BASESUB (additional, real). 371 sprintf(tform, "%dE", 9*maxNPol);395 sprintf(tform, "%dE", 24*maxNPol); 372 396 fits_insert_col(cSDptr, ++ncol, "BASESUB", tform, &cStatus); 373 tdim[0] = 9;397 tdim[0] = 24; 374 398 fits_write_tdim(cSDptr, ncol, 2, tdim, &cStatus); 375 399 } … … 396 420 397 421 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); 399 423 400 424 // FLAGGED (additional, logical). … … 444 468 445 469 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); 447 471 } 448 472 … … 523 547 } 524 548 549 if (cStatus) { 550 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table header."); 551 } 552 525 553 return cStatus; 526 554 } … … 530 558 // Write a record to the SDFITS file. 531 559 532 int SDFITSwriter::write( PKSMBrecord &mbrec)560 int SDFITSwriter::write(MBrecord &mbrec) 533 561 { 562 const string methodName = "write()" ; 563 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 564 534 565 char *cptr; 535 566 … … 537 568 int IFno = mbrec.IFno[0]; 538 569 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 ; 542 574 return 1; 543 575 } … … 546 578 int nChan = cNChan[iIF]; 547 579 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 ; 552 586 return 1; 553 587 } … … 555 589 int nPol = cNPol[iIF]; 556 590 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 ; 561 597 return 1; 562 598 } … … 655 691 656 692 // 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], 658 694 &cStatus); 659 695 } … … 739 775 } 740 776 777 if (cStatus) { 778 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table entry."); 779 } 780 741 781 return cStatus; 742 782 } 743 783 744 784 745 //-------------------------------------------------- SDFITSwriter::reportError746 747 // Print the error message corresponding to the input status value and all the748 // messages on the CFITSIO error stack to stderr. 749 750 void SDFITSwriter::reportError() 785 //------------------------------------------------------ SDFITSwriter::history 786 787 // Write a history record. 788 789 int SDFITSwriter::history(char *text) 790 751 791 { 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; 753 803 } 754 804 … … 759 809 void SDFITSwriter::close() 760 810 { 811 const string methodName = "close()" ; 812 761 813 if (cSDptr) { 762 814 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 764 819 cSDptr = 0; 765 820 } … … 772 827 void SDFITSwriter::deleteFile() 773 828 { 829 const string methodName = "deleteFile()" ; 830 774 831 if (cSDptr) { 775 832 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 777 837 cSDptr = 0; 778 838 } 779 839 } 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 846 void 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.