00001 // ----------------------------------------------------------------------^ 00002 // Copyright (C) 2004, 2005, 2006, 2007, 2008 Giorgio Calderone 00003 // (mailto: <gcalderone@ifc.inaf.it>) 00004 // 00005 // This file is part of MCS. 00006 // 00007 // MCS is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // MCS is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with MCS; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 // 00021 // ----------------------------------------------------------------------$ 00022 #include "mcs.hh" 00023 using namespace mcs; 00024 00025 //CFITSIO include 00026 #if ENABLE_CFITSIO 00027 #include <fitsio.h> 00028 00029 #define CHECK_FITS_ERROR if (status) throw MCS_ERROR(MSG_FITS_ERROR, fitsError(status).c_str()) 00030 00031 mcs::FITSWriter::FITSWriter() 00032 { fptr = NULL; } 00033 00034 mcs::FITSWriter::~FITSWriter() 00035 { close(); } 00036 00037 00038 void mcs::FITSWriter::open(string fn, bool compressed) 00039 { 00040 int status = 0; 00041 fitsfile *fptr; 00042 00043 fn = "!" + fn; 00044 if (compressed) fn += ".gz"; 00045 00046 fits_create_file(&fptr, fn.c_str(), &status); 00047 CHECK_FITS_ERROR; 00048 this->fptr = fptr; 00049 } 00050 00051 void mcs::FITSWriter::close() 00052 { 00053 fitsfile *fptr = (fitsfile*) this->fptr; 00054 int status = 0; 00055 00056 if (fptr) { 00057 fits_close_file(fptr, &status); 00058 CHECK_FITS_ERROR; 00059 } 00060 00061 fptr = NULL; 00062 } 00063 00064 00065 void mcs::FITSWriter::newBinTable(Record& meta, string HDUName) 00066 { 00067 fitsfile *fptr = (fitsfile*) this->fptr; 00068 int status = 0; 00069 int i; 00070 string s; 00071 00072 char** ttype = NULL; 00073 char** tform = NULL; 00074 char* buf = NULL; 00075 char* p1; 00076 char* p2; 00077 Record& rec = *this; 00078 00079 Record::operator=(meta); 00080 setNull(); 00081 00082 00083 #define FIELD_NAME_LEN 50 00084 #define FIELD_TYPE_LEN 10 00085 ttype = (char**) malloc(sizeof(char*) * count()); 00086 tform = (char**) malloc(sizeof(char*) * count()); 00087 buf = (char*) malloc((FIELD_NAME_LEN + FIELD_TYPE_LEN + 2) * 00088 count()); 00089 memset(buf, 0, (FIELD_NAME_LEN + FIELD_TYPE_LEN + 2) * count()); 00090 00091 p1 = buf; 00092 p2 = buf + FIELD_NAME_LEN * count(); 00093 00094 for (i=0; i<count(); i++) { 00095 ttype[i] = p1; 00096 p1 = stpcpy(p1, rec[i].name().c_str()); 00097 p1++; 00098 00099 if (! Types2S_FITS(rec[i].type(), rec[i].maxLength(), 00100 rec[i].isUnsigned(), s)) { 00101 free(ttype); 00102 free(tform); 00103 free(buf); 00104 throw MCS_ERROR(MSG_TYPE_NOT_HANDLED, i, rec[i].type()); 00105 } 00106 00107 tform[i] = p2; 00108 p2 = stpcpy(p2, s.c_str()); 00109 p2++; 00110 } 00111 00112 fits_create_tbl(fptr, BINARY_TBL, 0, count(), 00113 ttype, tform, 00114 NULL, (char*) HDUName.c_str(), &status); 00115 CHECK_FITS_ERROR; 00116 00117 free(ttype); 00118 free(tform); 00119 free(buf); 00120 } 00121 00122 00123 00124 00125 00126 void mcs::FITSWriter::newImage(Types bitpix, 00127 unsigned int naxis, unsigned int naxes, 00128 void* buf, string name) 00129 { 00130 //fitsfile *fptr = (fitsfile*) this->fptr; 00131 //int status = 0; 00132 int bitpix_fits; 00133 00134 switch(bitpix) { 00135 case TINY: 00136 bitpix_fits = BYTE_IMG; 00137 break; 00138 case SMALL: 00139 bitpix_fits = SHORT_IMG; 00140 break; 00141 case INT: 00142 bitpix_fits = LONG_IMG; 00143 break; 00144 case BIGINT: 00145 bitpix_fits = LONGLONG_IMG; 00146 break; 00147 case FLOAT: 00148 bitpix_fits = FLOAT_IMG; 00149 break; 00150 case DOUBLE: 00151 bitpix_fits = DOUBLE_IMG; 00152 break; 00153 default: 00154 throw; //ERROR 00155 } 00156 00157 //fits_create_img(fptr, bitpix_fits, &naxis, &naxes, &status); 00158 } 00159 00160 #endif //ENABLE_CFITSIO
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha3
|