[949] | 1 | #include "machdefs.h"
|
---|
| 2 | #include <stdlib.h>
|
---|
[839] | 3 | #include "fitsfile.h"
|
---|
| 4 | #include "pexceptions.h"
|
---|
| 5 | #include "strutil.h"
|
---|
[903] | 6 | #include "anydataobj.h"
|
---|
| 7 | #include "fitsspherehealpix.h"
|
---|
[1136] | 8 |
|
---|
| 9 |
|
---|
[1359] | 10 | void BnTblLine::setFormat(int dc, int fc, int ic, int lc, int bc,int cc, vector<string> names)
|
---|
[1218] | 11 | {
|
---|
[1359] | 12 | int nbcols = dc + fc + ic + cc + lc + bc;
|
---|
[1218] | 13 | int maxName = names.size();
|
---|
| 14 | if (nbcols != maxName)
|
---|
| 15 | {
|
---|
| 16 | cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl;
|
---|
| 17 | maxName = nbcols < maxName ? nbcols : maxName;
|
---|
| 18 | }
|
---|
| 19 | ColName_ = vector<string>(nbcols);
|
---|
| 20 | for (int k=0; k < maxName; k++) ColName_[k] = names[k];
|
---|
| 21 | if (dc >0) ddata_ = vector<double>(dc);
|
---|
| 22 | if (fc >0) fdata_ = vector<float>(fc);
|
---|
| 23 | if (ic >0) idata_ = vector<int>(fc);
|
---|
| 24 | if (cc >0) cdata_ = vector<string>(fc);
|
---|
[1359] | 25 | if (lc >0) ldata_ = vector<long>(lc);
|
---|
| 26 | if (bc >0) bdata_ = vector<unsigned char>(bc);
|
---|
[1218] | 27 | }
|
---|
| 28 |
|
---|
| 29 | bool BnTblLine::sameFormat(const BnTblLine& btl) const
|
---|
| 30 | {
|
---|
[1359] | 31 | if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size() && btl.ldata_.size() == ldata_.size() && btl.bdata_.size() == bdata_.size()) return true;
|
---|
[1218] | 32 | else return false;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | void BnTblLine::Print()
|
---|
| 36 | {
|
---|
| 37 | int k;
|
---|
| 38 | cout << " ********* ligne ************* " << endl;
|
---|
| 39 | cout << " *** noms de variables " << endl;
|
---|
| 40 | for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " ";
|
---|
| 41 | cout << endl;
|
---|
| 42 | cout << " *** variables doubles " << endl;
|
---|
| 43 | for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " ";
|
---|
| 44 | cout << endl;
|
---|
| 45 | cout << " *** variables float " << endl;
|
---|
| 46 | for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " ";
|
---|
| 47 | cout << endl;
|
---|
| 48 | cout << " *** variables int " << endl;
|
---|
| 49 | for (k=0; k < idata_.size(); k++) cout << idata_[k] << " ";
|
---|
| 50 | cout << endl;
|
---|
| 51 | cout << " *** variables string " << endl;
|
---|
| 52 | for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " ";
|
---|
| 53 | cout << endl;
|
---|
[1359] | 54 | cout << " *** variables long " << endl;
|
---|
| 55 | for (k=0; k < ldata_.size(); k++) cout << ldata_[k] << " ";
|
---|
| 56 | cout << endl;
|
---|
| 57 | cout << " *** variables byte " << endl;
|
---|
| 58 | for (k=0; k < bdata_.size(); k++) cout << (int)bdata_[k] << " ";
|
---|
| 59 | cout << endl;
|
---|
[1218] | 60 | cout << " ***************************** " << endl;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | /*!
|
---|
| 66 | \class SOPHYA::FitsIOHandler
|
---|
| 67 | The class structure is analogous to Sophya-PPersist system :
|
---|
| 68 | Each SOPHYA object XXX is associated with a object of class FITS_XXX
|
---|
| 69 | (inheriting from FitsFileHandler), to which input/output operations with FITS
|
---|
| 70 | files are delegated (through a class Hierarchy : FitsFile (virtual),
|
---|
| 71 | FitsInFile, FitsOutFile) . A typical example of use is the following :
|
---|
| 72 |
|
---|
| 73 | \verbatim
|
---|
| 74 | int m=... ;
|
---|
| 75 | SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object
|
---|
| 76 | .... fill the sphere ....
|
---|
| 77 |
|
---|
| 78 | FITS_SphereHEALPix<r_8> fits_sph1(sphere1);
|
---|
| 79 | // delegated object
|
---|
| 80 | fits_sph.Write("myfile.fits"); // writing on FITS file
|
---|
| 81 |
|
---|
| 82 | FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits");
|
---|
| 83 | // load a delegated object
|
---|
| 84 | // from FITS file
|
---|
| 85 | SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2;
|
---|
| 86 | // casting the delegated object
|
---|
| 87 | // into a SOPHYA object
|
---|
| 88 | \endverbatim
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | */
|
---|
| 92 |
|
---|
| 93 | /*! \fn void SOPHYA::FitsIOHandler::Read(char flnm[],int hdunum)
|
---|
| 94 |
|
---|
| 95 | this method is called from inherited objects :
|
---|
| 96 |
|
---|
| 97 | opens a file 'flnm'
|
---|
| 98 |
|
---|
| 99 | gets parameters in extension-header (hdunum)
|
---|
| 100 |
|
---|
| 101 | calls the method 'ReadFromFits' from the inherited object
|
---|
| 102 | */
|
---|
[1136] | 103 | void FitsIOHandler::Read(char flnm[],int hdunum)
|
---|
[839] | 104 | {
|
---|
[1136] | 105 | FitsInFile ifts(flnm);
|
---|
| 106 | Read(ifts, hdunum);
|
---|
[839] | 107 | }
|
---|
[1218] | 108 |
|
---|
| 109 | /*! \fn void SOPHYA::FitsIOHandler::Read(FitsInFile& is, int hdunum)
|
---|
| 110 | Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. If hdunum is not addressed, , one reads the next extension, with respect to the current position.
|
---|
| 111 | */
|
---|
[1136] | 112 | void FitsIOHandler::Read(FitsInFile& is, int hdunum)
|
---|
| 113 | {
|
---|
[1300] | 114 | is.ReadHeader(hdunum);
|
---|
[1136] | 115 | ReadFromFits(is);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 |
|
---|
[1218] | 119 | /*! \fn void SOPHYA::FitsIOHandler::Write(char flnm[])
|
---|
| 120 | this method is called from inherited objects.
|
---|
| 121 |
|
---|
| 122 | for writing a new object in a new fits-extension :
|
---|
| 123 |
|
---|
[1234] | 124 | \warning By convention, primary header may contain fits-image data.
|
---|
| 125 | For switching off this convention (i.e. to make sure that all data will be on fits-extensions) use the method :
|
---|
[1218] | 126 |
|
---|
| 127 | firstImageOnPrimaryHeader() (see below)
|
---|
| 128 |
|
---|
| 129 | calls the method 'WriteToFits' from the inherited object
|
---|
| 130 |
|
---|
| 131 | */
|
---|
[1193] | 132 | void FitsIOHandler::Write(char flnm[])
|
---|
[1136] | 133 |
|
---|
| 134 | {
|
---|
[1231] | 135 | FitsOutFile of(flnm, FitsFile::unknown);
|
---|
[1136] | 136 | Write(of);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | void FitsIOHandler::Write(FitsOutFile& os)
|
---|
| 140 | {
|
---|
| 141 | WriteToFits(os);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
[1218] | 145 | /*!
|
---|
| 146 | \class SOPHYA::FitsIOHandler
|
---|
| 147 | Class (virtual) for managing FITS format files
|
---|
| 148 | */
|
---|
[1136] | 149 |
|
---|
[1218] | 150 |
|
---|
[839] | 151 |
|
---|
| 152 | FitsFile::~FitsFile()
|
---|
| 153 | {
|
---|
| 154 | int status = 0;
|
---|
[1175] | 155 | if( fptr_ != NULL)
|
---|
[903] | 156 | {
|
---|
| 157 | fits_close_file(fptr_,&status);
|
---|
[1175] | 158 | // je ne fais pas delete fptr_, c'est la lib. fitsio qui a fait
|
---|
| 159 | // new...
|
---|
[903] | 160 | }
|
---|
[1175] | 161 | if( status ) printerror( status );
|
---|
[839] | 162 | }
|
---|
[903] | 163 |
|
---|
[1136] | 164 |
|
---|
| 165 | void FitsFile::printerror(int &status)
|
---|
| 166 | //*****************************************************/
|
---|
| 167 | //* Print out cfitsio error messages and exit program */
|
---|
| 168 | //*****************************************************/
|
---|
[1045] | 169 | {
|
---|
[1136] | 170 | if( status )
|
---|
| 171 | {
|
---|
| 172 | fits_report_error(stderr,status);
|
---|
| 173 | throw IOExc("FitsFile:: error FITSIO status");
|
---|
| 174 | }
|
---|
| 175 | return;
|
---|
| 176 | }
|
---|
[903] | 177 |
|
---|
[1136] | 178 | void FitsFile::printerror(int& status, char* texte)
|
---|
| 179 | //*****************************************************/
|
---|
| 180 | //* Print out cfitsio error messages and exit program */
|
---|
| 181 | //*****************************************************/
|
---|
| 182 | {
|
---|
| 183 | // print out cfitsio error messages and exit program
|
---|
| 184 | // print error report
|
---|
[1235] | 185 | fits_report_error(stderr, status);
|
---|
[1136] | 186 | cout << " erreur:: " << texte << endl;
|
---|
| 187 | throw IOExc("FitsFile:: error FITSIO status");
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | void FitsFile::ResetStatus(int& status)
|
---|
| 191 | {
|
---|
| 192 | fits_status_ = status;
|
---|
| 193 | status = 0;
|
---|
[1235] | 194 | fits_clear_errmsg();
|
---|
[1136] | 195 | }
|
---|
| 196 |
|
---|
[1209] | 197 | string FitsFile::GetErrStatus(int status)
|
---|
[1136] | 198 | {
|
---|
| 199 | char text[31];
|
---|
| 200 | fits_get_errstatus(status, text);
|
---|
| 201 | return string(text);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[1218] | 204 | /*!
|
---|
| 205 | \class SOPHYA::FitsInFile
|
---|
| 206 |
|
---|
[1246] | 207 | class for reading SOPHYA objects from FITS Format Files (uses cfitsio lib)
|
---|
[1218] | 208 | */
|
---|
| 209 |
|
---|
[1136] | 210 | FitsInFile::FitsInFile()
|
---|
| 211 | {
|
---|
| 212 | InitNull();
|
---|
| 213 | }
|
---|
[1218] | 214 |
|
---|
[1231] | 215 | FitsInFile::FitsInFile(string const & flnm)
|
---|
[1136] | 216 | {
|
---|
[1175] | 217 | InitNull();
|
---|
| 218 | int status = 0;
|
---|
[1231] | 219 | fits_open_file(&fptr_,flnm.c_str(),READONLY,&status);
|
---|
| 220 | if( status ) printerror( status );
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | FitsInFile::FitsInFile(const char * flnm)
|
---|
| 224 | {
|
---|
| 225 | InitNull();
|
---|
| 226 | int status = 0;
|
---|
[1175] | 227 | fits_open_file(&fptr_,flnm,READONLY,&status);
|
---|
| 228 | if( status ) printerror( status );
|
---|
[1136] | 229 | }
|
---|
| 230 |
|
---|
| 231 |
|
---|
| 232 | void FitsInFile::InitNull()
|
---|
| 233 | {
|
---|
[1300] | 234 | imageDataType_ = FitsDataType_NULL;
|
---|
[1045] | 235 | naxis_ = 0;
|
---|
| 236 | nbData_ = 0;
|
---|
| 237 | nrows_ = 0;
|
---|
| 238 | nbcols_ = 0;
|
---|
| 239 | naxisn_.clear();
|
---|
| 240 | repeat_.clear();
|
---|
| 241 | noms_.clear();
|
---|
| 242 | taille_des_chaines_.clear();
|
---|
| 243 | dvl_.Clear();
|
---|
[1175] | 244 |
|
---|
[1045] | 245 | }
|
---|
| 246 |
|
---|
[1218] | 247 | //////////////////////////////////////////////////////////
|
---|
| 248 | // methods with general purpose
|
---|
| 249 | /////////////////////////////////////////////////////////
|
---|
[1045] | 250 |
|
---|
[1136] | 251 | int FitsInFile::NbBlocks(char flnm[])
|
---|
[903] | 252 | {
|
---|
| 253 | int status = 0;
|
---|
| 254 | int nbhdu = 0;
|
---|
| 255 | fitsfile* fileptr;
|
---|
| 256 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
| 257 | if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" );
|
---|
| 258 | fits_get_num_hdus(fileptr, &nbhdu, &status);
|
---|
| 259 | fits_close_file(fileptr,&status);
|
---|
| 260 | return nbhdu;
|
---|
| 261 | }
|
---|
[1334] | 262 | int FitsInFile::NbBlocks()
|
---|
| 263 | {
|
---|
| 264 | int status = 0;
|
---|
| 265 | int nbhdu = 0;
|
---|
| 266 | fits_get_num_hdus(fptr_, &nbhdu, &status);
|
---|
| 267 | return nbhdu;
|
---|
| 268 | }
|
---|
[903] | 269 |
|
---|
[1231] | 270 | void FitsInFile::GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl )
|
---|
[903] | 271 | {
|
---|
| 272 | int status = 0;
|
---|
| 273 | fitsfile* fileptr;
|
---|
| 274 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
[1209] | 275 | if( status ) printerror( status, "GetBlockType: erreur ouverture fichier" );
|
---|
[903] | 276 | // move to the specified HDU number
|
---|
| 277 | int hdutype = 0;
|
---|
| 278 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
[1209] | 279 | if( status ) printerror( status,"GetBlockType: erreur movabs");
|
---|
[903] | 280 | if(hdutype == IMAGE_HDU)
|
---|
| 281 | {
|
---|
[1231] | 282 | typeOfExtension = FitsExtensionType_IMAGE;
|
---|
[1300] | 283 | GetImageParameters (fileptr, dataType, naxis, naxisn);
|
---|
[903] | 284 | }
|
---|
| 285 | else
|
---|
| 286 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 287 | {
|
---|
| 288 | int nrows = 0;
|
---|
| 289 | vector<string> noms;
|
---|
[1300] | 290 | vector<FitsDataType> types;
|
---|
[903] | 291 | vector<int> taille_des_chaines;
|
---|
[971] | 292 | GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines);
|
---|
| 293 | int k;
|
---|
| 294 | for (k=0; k< naxisn.size(); k++) naxisn[k] *= nrows;
|
---|
[903] | 295 | if(hdutype == ASCII_TBL)
|
---|
| 296 | {
|
---|
[1231] | 297 | typeOfExtension = FitsExtensionType_ASCII_TBL;
|
---|
| 298 | dataType = FitsDataType_ASCII;
|
---|
[903] | 299 | }
|
---|
| 300 | else
|
---|
| 301 | {
|
---|
[1231] | 302 | typeOfExtension = FitsExtensionType_BINARY_TBL;
|
---|
[1300] | 303 | dataType = types[0];
|
---|
[903] | 304 | }
|
---|
| 305 | }
|
---|
| 306 | else
|
---|
| 307 | {
|
---|
| 308 | cout << " hdutype= " << hdutype << endl;
|
---|
[1209] | 309 | throw IOExc("FitsFile::GetBlockType: this HDU type is unknown");
|
---|
[903] | 310 | }
|
---|
| 311 |
|
---|
[971] | 312 | KeywordsIntoDVList(fileptr, dvl, hdunum);
|
---|
[903] | 313 | fits_close_file(fileptr,&status);
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[1136] | 316 |
|
---|
[1300] | 317 | void FitsInFile::ReadHeader(int hdunum)
|
---|
[1045] | 318 | {
|
---|
[1300] | 319 | // InitNull();
|
---|
[1045] | 320 | int status = 0;
|
---|
[1334] | 321 | if (hdunum<0)
|
---|
| 322 | {
|
---|
| 323 | throw PException(" FITS_AutoReader::ReadObject : hdu number must be not negative");
|
---|
| 324 | }
|
---|
[1234] | 325 | if (hdunum != 0 ) hdunum_ = hdunum;
|
---|
| 326 |
|
---|
| 327 | // si le numero de header non precise
|
---|
| 328 | else
|
---|
[1045] | 329 | {
|
---|
[1234] | 330 | // si c'est le premier objet a lire
|
---|
| 331 | if (hdunum_ == 0)
|
---|
[1045] | 332 | {
|
---|
[1234] | 333 | // on calcule le numero de header a lire
|
---|
[1246] | 334 | if (imageOnPrimary_ == true ) hdunum_ = 1;
|
---|
[1234] | 335 | else hdunum_ = 2;
|
---|
[1045] | 336 | }
|
---|
[1234] | 337 | // sinon objet suivant
|
---|
| 338 | else hdunum_++;
|
---|
[1045] | 339 | }
|
---|
[1234] | 340 | getHeader();
|
---|
[1334] | 341 | if ( hdutype_ == FitsExtensionType_NULL )
|
---|
| 342 | {
|
---|
| 343 | if (hdunum == 0 && hdunum_ == 1)
|
---|
| 344 | {
|
---|
| 345 | hdunum_++;
|
---|
| 346 | getHeader();
|
---|
| 347 | }
|
---|
| 348 | else
|
---|
| 349 | {
|
---|
| 350 | cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
[1045] | 353 | }
|
---|
| 354 |
|
---|
[1354] | 355 | string FitsInFile::getStringKeyword(int hdunum, string keyw, int& retStatus)
|
---|
| 356 | {
|
---|
| 357 | string s;
|
---|
| 358 | retStatus = 0;
|
---|
| 359 | int status = 0;
|
---|
| 360 | if (hdunum != hdunum_ )
|
---|
| 361 | {
|
---|
| 362 | int hdutype;
|
---|
| 363 | fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | char value[FLEN_VALUE];
|
---|
| 367 | char* keyname= const_cast<char*>(keyw.c_str());
|
---|
| 368 | fits_read_key_str(fptr_,keyname,value,NULL,&status);
|
---|
| 369 | if (status == 0)
|
---|
| 370 | s = string(value);
|
---|
| 371 | else retStatus = status;
|
---|
| 372 | if (hdunum != hdunum_ )
|
---|
| 373 | {
|
---|
| 374 | int hdutype;
|
---|
| 375 | if (hdunum_ != 0)
|
---|
| 376 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 377 | else fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 378 |
|
---|
| 379 | }
|
---|
| 380 | return s;
|
---|
| 381 | }
|
---|
| 382 | bool FitsInFile::hasKeyword(int hdunum, string keyw)
|
---|
[1353] | 383 | {
|
---|
| 384 | bool has=false;
|
---|
| 385 | int status = 0;
|
---|
| 386 | if (hdunum != hdunum_ )
|
---|
| 387 | {
|
---|
| 388 | int hdutype;
|
---|
| 389 | fits_movabs_hdu(fptr_,hdunum,&hdutype,&status);
|
---|
| 390 | }
|
---|
[1218] | 391 |
|
---|
[1353] | 392 | char value[FLEN_VALUE];
|
---|
| 393 | char* keyname= const_cast<char*>(keyw.c_str());
|
---|
| 394 | fits_read_keyword(fptr_,keyname,value,NULL,&status);
|
---|
| 395 | if (status == 0)
|
---|
| 396 | has = true;
|
---|
| 397 | else
|
---|
| 398 | if (status == KEY_NO_EXIST ) status =0;
|
---|
| 399 | else fits_report_error(stderr,status);
|
---|
| 400 | if (hdunum != hdunum_ )
|
---|
| 401 | {
|
---|
| 402 | int hdutype;
|
---|
| 403 | if (hdunum_ != 0)
|
---|
| 404 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 405 | else fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 406 |
|
---|
| 407 | }
|
---|
| 408 | return has;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
[1300] | 411 | void FitsInFile::GetImageParameters (fitsfile* fileptr,FitsDataType& dataType,int& naxis,vector<int>& naxisn)
|
---|
[1218] | 412 | {
|
---|
| 413 | int hdunum=0;
|
---|
[1334] | 414 | // cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum) << endl;
|
---|
[1218] | 415 | int status= 0;
|
---|
| 416 |
|
---|
| 417 | // bits per pixels
|
---|
[1300] | 418 | int bitpix=0;
|
---|
[1218] | 419 | fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
|
---|
| 420 | if( status ) printerror( status );
|
---|
[1300] | 421 | if(bitpix == DOUBLE_IMG) dataType = FitsDataType_double;
|
---|
| 422 | else if(bitpix == FLOAT_IMG) dataType = FitsDataType_float;
|
---|
| 423 | else if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = FitsDataType_int;
|
---|
| 424 | else if (bitpix == BYTE_IMG) dataType = FitsDataType_char;
|
---|
| 425 | else
|
---|
| 426 | {
|
---|
| 427 | cout << " bitpix= " << bitpix << endl;
|
---|
| 428 | throw PException(" FitsFile::GetImageParameters : unsupported FITS data type");
|
---|
| 429 | }
|
---|
[1218] | 430 |
|
---|
| 431 | // number of dimensions in the FITS array
|
---|
| 432 | naxis= 0;
|
---|
| 433 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 434 | if( status ) printerror( status );
|
---|
| 435 | // read the NAXISn keywords to get image size
|
---|
| 436 | long* naxes = new long[naxis] ;
|
---|
| 437 | int nfound;
|
---|
| 438 | fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
|
---|
| 439 | if( status ) printerror( status );
|
---|
| 440 | if (nfound != naxis )
|
---|
| 441 | cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
|
---|
| 442 | int k;
|
---|
| 443 | for (k=0; k<naxis; k++)
|
---|
| 444 | {
|
---|
| 445 | naxisn.push_back( (int)naxes[k] );
|
---|
| 446 | }
|
---|
| 447 | delete [] naxes;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 |
|
---|
| 451 |
|
---|
| 452 |
|
---|
| 453 | /*! \fn DVList SOPHYA::FitsInFile::DVListFromPrimaryHeader() const
|
---|
| 454 |
|
---|
| 455 | \return the keywords of primary header in a DVList
|
---|
| 456 |
|
---|
| 457 | */
|
---|
[1143] | 458 | DVList FitsInFile::DVListFromPrimaryHeader() const
|
---|
| 459 | {
|
---|
| 460 | int status;
|
---|
| 461 | DVList dvl;
|
---|
| 462 | KeywordsIntoDVList(fptr_, dvl, 1);
|
---|
| 463 | int hdutype = 0;
|
---|
| 464 | if (hdunum_ > 0) fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 465 | return dvl;
|
---|
| 466 | }
|
---|
[1136] | 467 |
|
---|
[1234] | 468 | void FitsInFile::getHeader()
|
---|
[971] | 469 | {
|
---|
[1300] | 470 | // si hdunum_ > 1 lit le header correspondant
|
---|
| 471 | // si hdunum_ = 1 se positionne au (et lit le) premier header qui
|
---|
| 472 | // contient reellement un objet
|
---|
[1234] | 473 | int status=0;
|
---|
| 474 | if (hdunum_ < 1) throw PException(" attempt to read hdunum < 1");
|
---|
[1300] | 475 | InitNull();
|
---|
[1234] | 476 | if (hdunum_ == 1)
|
---|
[839] | 477 | {
|
---|
[1234] | 478 | // presence of image ?
|
---|
| 479 | int naxis= 0;
|
---|
| 480 | fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 481 | if( status ) printerror( status );
|
---|
| 482 | if (naxis > 0 ) // there is an image
|
---|
| 483 | {
|
---|
[1334] | 484 | hdutype_ = FitsExtensionType_IMAGE;
|
---|
[1300] | 485 | GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
|
---|
[1234] | 486 | nbData_ = 1;
|
---|
| 487 | int k;
|
---|
| 488 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
| 489 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
| 490 | }
|
---|
| 491 | else
|
---|
| 492 | {
|
---|
[1334] | 493 | hdutype_ = FitsExtensionType_NULL;
|
---|
| 494 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
[1234] | 495 | }
|
---|
[839] | 496 | }
|
---|
[1234] | 497 | else
|
---|
[839] | 498 | {
|
---|
[1234] | 499 | int hdutype;
|
---|
| 500 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1334] | 501 |
|
---|
| 502 | if( status )
|
---|
[1234] | 503 | {
|
---|
[1334] | 504 | if (status == END_OF_FILE)
|
---|
| 505 | {
|
---|
| 506 | hdutype_= FitsExtensionType_EOF;
|
---|
| 507 | status =0;
|
---|
| 508 | return;
|
---|
| 509 | }
|
---|
| 510 | else
|
---|
| 511 | {
|
---|
| 512 | cout << "WARNING (FitsInFile::getHeader) : error during movabs" << endl;
|
---|
| 513 | hdutype_= FitsExtensionType_ERROR;
|
---|
| 514 | status =0;
|
---|
| 515 | return;
|
---|
| 516 | }
|
---|
| 517 | // printerror( status,":FitsInFile::getHeader : erreur movabs");
|
---|
| 518 | }
|
---|
| 519 | if(hdutype == IMAGE_HDU)
|
---|
| 520 | {
|
---|
| 521 | hdutype_= FitsExtensionType_IMAGE;
|
---|
[1300] | 522 | GetImageParameters (fptr_, imageDataType_, naxis_, naxisn_);
|
---|
[1234] | 523 | nbData_ = 1;
|
---|
| 524 | int k;
|
---|
| 525 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
| 526 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
| 527 | }
|
---|
[1334] | 528 | else if(hdutype == ASCII_TBL)
|
---|
[1234] | 529 | {
|
---|
[1334] | 530 | hdutype_= FitsExtensionType_ASCII_TBL;
|
---|
[1234] | 531 | GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
|
---|
| 532 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
| 533 | }
|
---|
[1334] | 534 | else if(hdutype == BINARY_TBL)
|
---|
| 535 | {
|
---|
| 536 | hdutype_= FitsExtensionType_BINARY_TBL;
|
---|
| 537 | GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
|
---|
| 538 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
| 539 | }
|
---|
| 540 | else
|
---|
| 541 | {
|
---|
| 542 | hdutype_= FitsExtensionType_NULL;
|
---|
| 543 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
| 544 | }
|
---|
[839] | 545 | }
|
---|
[971] | 546 | }
|
---|
[839] | 547 |
|
---|
[1136] | 548 |
|
---|
[1234] | 549 | void FitsInFile::moveToFollowingHeader()
|
---|
| 550 | {
|
---|
| 551 | int status = 0;
|
---|
| 552 | hdunum_++;
|
---|
| 553 | getHeader();
|
---|
[1334] | 554 | if ( hdutype_ == FitsExtensionType_NULL )
|
---|
| 555 | {
|
---|
| 556 | cout << " WARNING (FitsInFile::ReadHeader) : no SOPHYA object on HDU number : " << hdunum_ << endl;
|
---|
| 557 |
|
---|
| 558 | }
|
---|
[1234] | 559 | }
|
---|
[1218] | 560 |
|
---|
| 561 |
|
---|
| 562 |
|
---|
[1234] | 563 |
|
---|
| 564 |
|
---|
[1218] | 565 | /*! \fn int SOPHYA::FitsInFile::NbColsFromFits() const
|
---|
| 566 | \return number of columns (return 1 if IMAGE)
|
---|
| 567 | */
|
---|
[1136] | 568 | int FitsInFile::NbColsFromFits() const
|
---|
[839] | 569 | {
|
---|
[1334] | 570 | if(hdutype_ == FitsExtensionType_BINARY_TBL) return nbcols_;
|
---|
[971] | 571 | else
|
---|
[1334] | 572 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_IMAGE) return 1;
|
---|
[839] | 573 | else
|
---|
| 574 | {
|
---|
[1353] | 575 | cout << " hdutype= " << hdutype_ << endl;
|
---|
[1334] | 576 | throw PException("FitsFile::NbColsFromFits, HDU not supported");
|
---|
[839] | 577 | }
|
---|
| 578 | }
|
---|
| 579 |
|
---|
[1218] | 580 | /*! \fn int SOPHYA::FitsInFile::NentriesFromFits(int nocol) const
|
---|
| 581 | \return number of data in the current IMAGE extension on FITS file, or number
|
---|
| 582 | of data of column number 'nocol' of the current BINTABLE extension
|
---|
| 583 | */
|
---|
[1136] | 584 | int FitsInFile::NentriesFromFits(int nocol) const
|
---|
[839] | 585 | {
|
---|
[1334] | 586 | if(hdutype_ == FitsExtensionType_BINARY_TBL) return nrows_*repeat_[nocol];
|
---|
[1136] | 587 | else
|
---|
[1334] | 588 | if(hdutype_ == FitsExtensionType_ASCII_TBL) return nrows_;
|
---|
[1136] | 589 | else
|
---|
[1334] | 590 | if(hdutype_ == FitsExtensionType_IMAGE) return nbData_;
|
---|
[1136] | 591 | else
|
---|
[839] | 592 | {
|
---|
[1353] | 593 | cout << "hdutype= " << hdutype_ << endl;
|
---|
[1334] | 594 | throw PException("FitsFile::NentriesFromFits, this HDU is not supported");
|
---|
[839] | 595 | }
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[1218] | 598 | /*! \fn char SOPHYA::FitsInFile::ColTypeFromFits(int nocol) const
|
---|
| 599 |
|
---|
| 600 | return a character denoting data type of column number 'nocol' in a BINTABLE :
|
---|
| 601 |
|
---|
| 602 | D : double
|
---|
| 603 |
|
---|
| 604 | E : float
|
---|
| 605 |
|
---|
| 606 | I : integer
|
---|
| 607 |
|
---|
| 608 | S : character string
|
---|
| 609 |
|
---|
| 610 | */
|
---|
| 611 |
|
---|
[1300] | 612 | FitsFile::FitsDataType FitsInFile::ColTypeFromFits(int nocol) const
|
---|
[839] | 613 | {
|
---|
[1334] | 614 | if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
|
---|
[839] | 615 | {
|
---|
[1136] | 616 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 617 | }
|
---|
[1136] | 618 | return types_[nocol];
|
---|
[839] | 619 | }
|
---|
[1218] | 620 |
|
---|
| 621 |
|
---|
| 622 | /*! \fn string SOPHYA::FitsInFile::ColNameFromFits(int nocol) const
|
---|
| 623 |
|
---|
| 624 | \return name of the column number 'nocol' of the current BINTABLE extension
|
---|
| 625 | */
|
---|
| 626 |
|
---|
[1136] | 627 | string FitsInFile::ColNameFromFits(int nocol) const
|
---|
[839] | 628 | {
|
---|
[1334] | 629 | if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
|
---|
[1045] | 630 | {
|
---|
[1136] | 631 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
[1045] | 632 | }
|
---|
[1136] | 633 | return noms_[nocol];
|
---|
[839] | 634 | }
|
---|
| 635 |
|
---|
[1218] | 636 | /*! \fn int DSOPHYA::FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
| 637 |
|
---|
| 638 | \return number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
|
---|
| 639 | */
|
---|
| 640 |
|
---|
[1136] | 641 | int FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
[839] | 642 | {
|
---|
[1334] | 643 | if(hdutype_ != FitsExtensionType_ASCII_TBL && hdutype_ != FitsExtensionType_BINARY_TBL)
|
---|
[1136] | 644 | {
|
---|
| 645 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
| 646 | }
|
---|
| 647 | int index=-1;
|
---|
| 648 | int k;
|
---|
| 649 | for (k=0; k<=nocol; k++)
|
---|
| 650 | {
|
---|
[1300] | 651 | if (types_[k] == FitsDataType_char) index++;
|
---|
[1136] | 652 | }
|
---|
| 653 | return taille_des_chaines_[index];
|
---|
[839] | 654 | }
|
---|
[1218] | 655 |
|
---|
| 656 |
|
---|
| 657 |
|
---|
| 658 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
| 659 |
|
---|
| 660 | Get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
| 661 | */
|
---|
| 662 |
|
---|
[1193] | 663 | void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
[839] | 664 | {
|
---|
| 665 | int status= 0;
|
---|
[1136] | 666 | int anull;
|
---|
| 667 | double dnull= 0.;
|
---|
| 668 | float fnull= 0.;
|
---|
| 669 | int inull= 0;
|
---|
| 670 | char* cnull= "";
|
---|
| 671 | int dcount = 0.;
|
---|
| 672 | int fcount = 0.;
|
---|
| 673 | int icount = 0;
|
---|
| 674 | int ccount =0;
|
---|
| 675 | int ncol;
|
---|
| 676 | long nels=1;
|
---|
| 677 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
[861] | 678 | {
|
---|
[1136] | 679 | switch (types_[ncol])
|
---|
| 680 | {
|
---|
[1300] | 681 | case FitsDataType_double :
|
---|
[1136] | 682 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
|
---|
| 683 | break;
|
---|
[1300] | 684 | case FitsDataType_float :
|
---|
[1136] | 685 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
|
---|
| 686 | break;
|
---|
[1300] | 687 | case FitsDataType_int :
|
---|
[1136] | 688 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
|
---|
| 689 | &anull,&status);
|
---|
| 690 | break;
|
---|
[1300] | 691 | case FitsDataType_char :
|
---|
[1136] | 692 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
|
---|
| 693 | break;
|
---|
| 694 | }
|
---|
| 695 | if (status)
|
---|
| 696 | {
|
---|
| 697 | ResetStatus(status);
|
---|
| 698 | break;
|
---|
| 699 | }
|
---|
[861] | 700 | }
|
---|
[903] | 701 | }
|
---|
[839] | 702 |
|
---|
[1218] | 703 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
| 704 | Get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
| 705 | */
|
---|
[1193] | 706 | void FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
| 707 | {
|
---|
| 708 | int status= 0;
|
---|
| 709 | int anull;
|
---|
| 710 | double dnull= 0.;
|
---|
| 711 | float fnull= 0.;
|
---|
| 712 | int inull= 0;
|
---|
| 713 | char* cnull= "";
|
---|
| 714 | int dcount = 0.;
|
---|
| 715 | int fcount = 0.;
|
---|
| 716 | int icount = 0;
|
---|
| 717 | int ccount =0;
|
---|
| 718 | int ncol;
|
---|
| 719 | long nels=1;
|
---|
| 720 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
| 721 | {
|
---|
| 722 | switch (types_[ncol])
|
---|
| 723 | {
|
---|
[1300] | 724 | case FitsDataType_double :
|
---|
[1193] | 725 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anull,&status);
|
---|
[1300] | 726 | break;
|
---|
| 727 | case FitsDataType_float :
|
---|
[1193] | 728 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anull,&status);
|
---|
| 729 | break;
|
---|
[1300] | 730 | case FitsDataType_int :
|
---|
[1359] | 731 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++], &anull,&status);
|
---|
[1193] | 732 | break;
|
---|
[1359] | 733 | case FitsDataType_long :
|
---|
| 734 | fits_read_col(fptr_,TLONG,ncol+1,NoLine+1,1,1,&inull,&ligne.ldata_[icount++], &anull,&status);
|
---|
| 735 | break;
|
---|
| 736 | case FitsDataType_byte :
|
---|
| 737 | fits_read_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1,&inull,&ligne.bdata_[icount++], &anull,&status);
|
---|
| 738 | break;
|
---|
[1300] | 739 | case FitsDataType_char :
|
---|
[1193] | 740 | char* chaine = new char[taille_des_chaines_[ccount]];
|
---|
| 741 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anull,&status);
|
---|
| 742 | ligne.cdata_[ccount++] = string(chaine);
|
---|
| 743 | break;
|
---|
| 744 | }
|
---|
| 745 | if (status)
|
---|
| 746 | {
|
---|
| 747 | ResetStatus(status);
|
---|
| 748 | break;
|
---|
| 749 | }
|
---|
| 750 | }
|
---|
| 751 | }
|
---|
| 752 |
|
---|
[1218] | 753 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
| 754 |
|
---|
| 755 | Get the NoLine-th float 'line' from the current BINTABLE extension on FITS file,
|
---|
| 756 | */
|
---|
[1136] | 757 | void FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
[903] | 758 | {
|
---|
[1136] | 759 | int status= 0;
|
---|
| 760 | int anull;
|
---|
| 761 | float fnull= 0.;
|
---|
| 762 | long nels=1;
|
---|
| 763 | int ncol;
|
---|
| 764 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
[861] | 765 | {
|
---|
[1136] | 766 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
|
---|
| 767 | if (status)
|
---|
[903] | 768 | {
|
---|
[1136] | 769 | ResetStatus(status);
|
---|
| 770 | break;
|
---|
[903] | 771 | }
|
---|
[1136] | 772 | }
|
---|
| 773 | }
|
---|
[839] | 774 |
|
---|
[903] | 775 |
|
---|
[1218] | 776 | /*! \fn void SPOPHYA::FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
|
---|
| 777 |
|
---|
| 778 | fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
|
---|
| 779 |
|
---|
| 780 | \param <nentries> number of data to be read
|
---|
| 781 | */
|
---|
[1353] | 782 | void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
|
---|
[839] | 783 | {
|
---|
| 784 | int status= 0;
|
---|
| 785 | int DTYPE;
|
---|
| 786 | long repeat,width;
|
---|
| 787 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 788 | if( DTYPE != TDOUBLE)
|
---|
| 789 | {
|
---|
[1045] | 790 | if (DTYPE == TFLOAT) cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
|
---|
| 791 | else
|
---|
| 792 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
|
---|
[839] | 793 | }
|
---|
| 794 | long nels=nentries;
|
---|
[971] | 795 | int anull;
|
---|
[839] | 796 | // no checking for undefined pixels
|
---|
[971] | 797 | double dnull= 0.;
|
---|
| 798 | // fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
|
---|
| 799 | // if (status != 0)
|
---|
| 800 | // {
|
---|
| 801 | // dnull = -1.6375e30; // default value
|
---|
| 802 | // status = 0;
|
---|
| 803 | // }
|
---|
| 804 | if (nentries != nrows_*repeat)
|
---|
| 805 | {
|
---|
| 806 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 807 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 808 | }
|
---|
[839] | 809 | fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
|
---|
| 810 | &anull,&status);
|
---|
| 811 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
[971] | 812 |
|
---|
[839] | 813 | }
|
---|
| 814 |
|
---|
[1218] | 815 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
|
---|
| 816 |
|
---|
| 817 | same as previous method with float data
|
---|
| 818 | */
|
---|
[1353] | 819 | void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
|
---|
[839] | 820 | {
|
---|
| 821 | int status= 0;
|
---|
| 822 | int DTYPE;
|
---|
| 823 | long repeat,width;
|
---|
| 824 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 825 | if( DTYPE != TFLOAT)
|
---|
| 826 | {
|
---|
[1045] | 827 | if (DTYPE == TDOUBLE) cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
|
---|
| 828 | else
|
---|
| 829 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
|
---|
[839] | 830 | }
|
---|
| 831 | long nels=nentries;
|
---|
[971] | 832 | int anull;
|
---|
[839] | 833 | // no checking for undefined pixels
|
---|
| 834 | float fnull= 0.;
|
---|
[971] | 835 | // fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
|
---|
| 836 | // if (status != 0)
|
---|
| 837 | // {
|
---|
| 838 | // fnull = -1.6375e30; // default value
|
---|
| 839 | // status = 0;
|
---|
| 840 | // }
|
---|
| 841 | if (nentries != nrows_*repeat)
|
---|
| 842 | {
|
---|
| 843 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 844 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 845 | }
|
---|
[839] | 846 | fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
|
---|
| 847 | &anull,&status);
|
---|
| 848 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 849 | }
|
---|
[1136] | 850 |
|
---|
[1218] | 851 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
|
---|
| 852 |
|
---|
| 853 | same as previous method with int data
|
---|
| 854 | */
|
---|
| 855 |
|
---|
[1353] | 856 | void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
|
---|
[839] | 857 | {
|
---|
| 858 | int status= 0;
|
---|
| 859 | int DTYPE;
|
---|
| 860 | long repeat,width;
|
---|
| 861 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 862 | if( DTYPE != TLONG && DTYPE != TINT && DTYPE != TSHORT )
|
---|
| 863 | {
|
---|
| 864 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
|
---|
| 865 | }
|
---|
| 866 | long nels=nentries;
|
---|
| 867 | // no checking for undefined pixels
|
---|
| 868 | int anull;
|
---|
| 869 | int inull= 0;
|
---|
[971] | 870 | // fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
|
---|
| 871 | // if (status != 0)
|
---|
| 872 | // {
|
---|
| 873 | // inull = -999999; // default value
|
---|
| 874 | // status = 0;
|
---|
| 875 | // }
|
---|
| 876 | if (nentries != nrows_*repeat)
|
---|
| 877 | {
|
---|
| 878 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 879 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 880 | }
|
---|
[839] | 881 | fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
|
---|
| 882 | &anull,&status);
|
---|
| 883 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 884 | }
|
---|
[1136] | 885 |
|
---|
[1218] | 886 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
| 887 |
|
---|
| 888 | same as previous method with char* data
|
---|
| 889 | */
|
---|
| 890 |
|
---|
[1136] | 891 | void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
[839] | 892 | {
|
---|
| 893 | int status= 0;
|
---|
| 894 | int DTYPE;
|
---|
| 895 | long repeat,width;
|
---|
| 896 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
[1300] | 897 | if( DTYPE != TSTRING && DTYPE != TBYTE)
|
---|
[839] | 898 | {
|
---|
[1300] | 899 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non string");
|
---|
[839] | 900 | }
|
---|
| 901 | long nels=nentries;
|
---|
| 902 | // no checking for undefined pixels
|
---|
| 903 | int anull;
|
---|
[971] | 904 | char* cnull= "";
|
---|
| 905 | if (nentries != nrows_*repeat/width)
|
---|
| 906 | {
|
---|
| 907 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat/width << endl;
|
---|
| 908 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 909 | }
|
---|
[839] | 910 | long frow=1;
|
---|
| 911 | long felem=1;
|
---|
| 912 | fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
|
---|
| 913 | &anull,&status);
|
---|
| 914 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 915 | }
|
---|
[1045] | 916 |
|
---|
[1218] | 917 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(double* map, int nentries) const
|
---|
| 918 | fill the array 'map' with double data from the current extension on FITS file.
|
---|
| 919 | If the extension is BINTABLE, the first column is provided.
|
---|
| 920 |
|
---|
| 921 | \param <nentries> number of data to be read
|
---|
| 922 | */
|
---|
[1353] | 923 | void FitsInFile::GetSingleColumn(double* map, int nentries) const
|
---|
[1136] | 924 | {
|
---|
| 925 | int status = 0;
|
---|
[1334] | 926 | if(hdutype_ == FitsExtensionType_IMAGE)
|
---|
[1045] | 927 | {
|
---|
[1136] | 928 |
|
---|
[1300] | 929 | if(imageDataType_ != FitsDataType_double)
|
---|
[1047] | 930 | {
|
---|
[1136] | 931 | cout << " The data type on fits file is not double...";
|
---|
| 932 | cout << " Conversion to double achieved by cfitsio lib" << endl;
|
---|
[1047] | 933 | }
|
---|
[1136] | 934 |
|
---|
| 935 | // no checking for undefined pixels
|
---|
| 936 | int anull;
|
---|
| 937 | double dnull= 0.;
|
---|
| 938 |
|
---|
| 939 | long nels= nentries;
|
---|
| 940 | fits_read_img(fptr_,TDOUBLE,1,nels,&dnull,map,&anull,&status);
|
---|
| 941 | if( status ) printerror( status );
|
---|
[1045] | 942 | }
|
---|
[1136] | 943 | else
|
---|
[1334] | 944 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
|
---|
[1136] | 945 | {
|
---|
| 946 | GetBinTabFCol(map,nentries, 0);
|
---|
| 947 | }
|
---|
| 948 | else
|
---|
| 949 | {
|
---|
[1353] | 950 | cout << " hdutype= " << hdutype_ << endl;
|
---|
[1334] | 951 | throw IOExc("FitsFile::GetSingleColumn, this HDU is unknown");
|
---|
[1136] | 952 | }
|
---|
[1045] | 953 | }
|
---|
| 954 |
|
---|
[1218] | 955 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
|
---|
| 956 | same as above with float data
|
---|
| 957 | */
|
---|
[1353] | 958 | void FitsInFile::GetSingleColumn(float* map, int nentries) const
|
---|
[1045] | 959 | {
|
---|
[1136] | 960 | int status = 0;
|
---|
[1334] | 961 | if(hdutype_ == FitsExtensionType_IMAGE)
|
---|
[1045] | 962 | {
|
---|
[1300] | 963 | if(imageDataType_ != FitsDataType_float)
|
---|
[1047] | 964 | {
|
---|
[1136] | 965 | cout << " The data type on fits file is not float ";
|
---|
| 966 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
[1047] | 967 | }
|
---|
[1136] | 968 | // no checking for undefined pixels
|
---|
| 969 | int anull;
|
---|
| 970 | float fnull= 0.;
|
---|
| 971 |
|
---|
| 972 | long nels= nentries;
|
---|
| 973 | fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
|
---|
| 974 | if( status ) printerror( status );
|
---|
[1045] | 975 | }
|
---|
[839] | 976 | else
|
---|
[1334] | 977 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
|
---|
[1136] | 978 | {
|
---|
| 979 | GetBinTabFCol(map,nentries, 0);
|
---|
| 980 | }
|
---|
[839] | 981 | else
|
---|
| 982 | {
|
---|
[1353] | 983 | cout << " hdutype= " << hdutype_ << endl;
|
---|
[1136] | 984 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
[839] | 985 | }
|
---|
| 986 | }
|
---|
| 987 |
|
---|
[1218] | 988 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
|
---|
| 989 | same as above with int data
|
---|
| 990 | */
|
---|
[1353] | 991 | void FitsInFile::GetSingleColumn( int* map, int nentries) const
|
---|
[839] | 992 | {
|
---|
[1136] | 993 | int status = 0;
|
---|
[1334] | 994 | if(hdutype_ == FitsExtensionType_IMAGE)
|
---|
[839] | 995 | {
|
---|
[1300] | 996 | if(imageDataType_ != FitsDataType_int)
|
---|
[1136] | 997 | {
|
---|
| 998 | cout << " The data type on fits file is not int ";
|
---|
| 999 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
| 1000 | }
|
---|
| 1001 | // no checking for undefined pixels
|
---|
| 1002 | int anull;
|
---|
| 1003 | float fnull= 0.;
|
---|
| 1004 |
|
---|
| 1005 | long nels= nentries;
|
---|
| 1006 | fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
|
---|
| 1007 | if( status ) printerror( status );
|
---|
[839] | 1008 | }
|
---|
| 1009 | else
|
---|
[1334] | 1010 | if(hdutype_ == FitsExtensionType_ASCII_TBL || hdutype_ == FitsExtensionType_BINARY_TBL)
|
---|
[1136] | 1011 | {
|
---|
| 1012 | GetBinTabFCol(map,nentries, 0);
|
---|
| 1013 | }
|
---|
[839] | 1014 | else
|
---|
[1136] | 1015 | {
|
---|
[1353] | 1016 | cout << " hdutype= " << hdutype_ << endl;
|
---|
[1136] | 1017 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
| 1018 | }
|
---|
[839] | 1019 | }
|
---|
| 1020 |
|
---|
[1136] | 1021 | void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
[903] | 1022 | vector<int>& repeat,
|
---|
| 1023 | vector<string>& noms,
|
---|
[1300] | 1024 | vector<FitsDataType>& types,
|
---|
[903] | 1025 | vector<int>& taille_des_chaines)
|
---|
[839] | 1026 | {
|
---|
| 1027 | int status= 0;
|
---|
[903] | 1028 | int hdunum=0;
|
---|
| 1029 | int hdutype=0;
|
---|
| 1030 | fits_get_hdu_num(fileptr,&hdunum);
|
---|
| 1031 | fits_get_hdu_type(fileptr, &hdutype, &status);
|
---|
| 1032 |
|
---|
| 1033 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
[839] | 1034 | {
|
---|
[903] | 1035 | throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1036 | }
|
---|
[1334] | 1037 | // if(hdutype == ASCII_TBL)
|
---|
| 1038 | // cout << " Reading a FITS ascii table in HDU : " << hdunum << endl;
|
---|
| 1039 | // if(hdutype == BINARY_TBL)
|
---|
| 1040 | // cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
|
---|
[839] | 1041 |
|
---|
| 1042 | // get the number of columns
|
---|
[903] | 1043 | fits_get_num_cols(fileptr, &nbcols,&status);
|
---|
[839] | 1044 | if( status ) printerror( status );
|
---|
| 1045 |
|
---|
| 1046 | // get the number of rows
|
---|
| 1047 | long naxis2= 0;
|
---|
[903] | 1048 | fits_get_num_rows(fileptr,&naxis2,&status);
|
---|
[839] | 1049 | if( status ) printerror( status );
|
---|
[903] | 1050 | nrows = (int)naxis2;
|
---|
[839] | 1051 |
|
---|
| 1052 | // get the datatype, names and the repeat count
|
---|
[903] | 1053 | noms.clear();
|
---|
| 1054 | noms.reserve(nbcols);
|
---|
| 1055 | types.clear();
|
---|
| 1056 | types.reserve(nbcols);
|
---|
| 1057 | repeat.clear();
|
---|
| 1058 | repeat.reserve(nbcols);
|
---|
| 1059 | taille_des_chaines.clear();
|
---|
[839] | 1060 | char **ttype = new char*[nbcols];
|
---|
[923] | 1061 | int ii;
|
---|
[1175] | 1062 | //
|
---|
| 1063 | //
|
---|
[923] | 1064 | for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
|
---|
[839] | 1065 | int nfound;
|
---|
[903] | 1066 | fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
|
---|
[839] | 1067 | if( status ) printerror( status,"erreur lecture des noms de colonne");
|
---|
| 1068 | int rept=0;
|
---|
[1300] | 1069 | if(hdutype == ASCII_TBL)
|
---|
[839] | 1070 | {
|
---|
[1300] | 1071 | for(ii = 0; ii < nbcols; ii++)
|
---|
[839] | 1072 | {
|
---|
[1300] | 1073 | int DTYPE;
|
---|
| 1074 | long width;
|
---|
| 1075 | long repete = 0;
|
---|
| 1076 | fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
|
---|
| 1077 | if( status ) printerror( status,"erreur lecture type de colonne");
|
---|
| 1078 | rept = repete;
|
---|
| 1079 | noms.push_back(string(ttype[ii]));
|
---|
| 1080 | switch (DTYPE)
|
---|
| 1081 | {
|
---|
| 1082 | case TDOUBLE :
|
---|
| 1083 | types.push_back(FitsDataType_double);
|
---|
| 1084 | break;
|
---|
| 1085 | case TFLOAT :
|
---|
| 1086 | types.push_back(FitsDataType_float);
|
---|
| 1087 | break;
|
---|
| 1088 | case TLONG :
|
---|
[1359] | 1089 | types.push_back(FitsDataType_long);
|
---|
[1300] | 1090 | break;
|
---|
| 1091 | case TSHORT :
|
---|
| 1092 | types.push_back(FitsDataType_int);
|
---|
| 1093 | break;
|
---|
| 1094 | case TSTRING :
|
---|
| 1095 | types.push_back(FitsDataType_char);
|
---|
| 1096 | taille_des_chaines.push_back(width);
|
---|
| 1097 | rept/=width;
|
---|
| 1098 | break;
|
---|
| 1099 | default :
|
---|
| 1100 | cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
|
---|
| 1101 | throw IOExc("FitsFile::GetBinTabParameters, unsupported data type of field, for ASCII table");
|
---|
| 1102 | }
|
---|
| 1103 | repeat.push_back(rept);
|
---|
[839] | 1104 | }
|
---|
[1136] | 1105 | }
|
---|
[1300] | 1106 | else
|
---|
| 1107 | {
|
---|
| 1108 | for(ii = 0; ii < nbcols; ii++)
|
---|
| 1109 | {
|
---|
| 1110 | int DTYPE;
|
---|
| 1111 | long width;
|
---|
| 1112 | long repete = 0;
|
---|
| 1113 | fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
|
---|
| 1114 | if( status ) printerror( status,"erreur lecture type de colonne");
|
---|
| 1115 | rept = repete;
|
---|
| 1116 | noms.push_back(string(ttype[ii]));
|
---|
| 1117 | switch (DTYPE)
|
---|
| 1118 | {
|
---|
| 1119 | case TDOUBLE :
|
---|
| 1120 | types.push_back(FitsDataType_double);
|
---|
| 1121 | break;
|
---|
| 1122 | case TFLOAT :
|
---|
| 1123 | types.push_back(FitsDataType_float);
|
---|
| 1124 | break;
|
---|
| 1125 | case TLONG :
|
---|
[1359] | 1126 | types.push_back(FitsDataType_long);
|
---|
[1300] | 1127 | break;
|
---|
| 1128 | case TINT :
|
---|
| 1129 | types.push_back(FitsDataType_int);
|
---|
| 1130 | break;
|
---|
| 1131 | case TSHORT :
|
---|
| 1132 | types.push_back(FitsDataType_int);
|
---|
| 1133 | break;
|
---|
| 1134 | case TSTRING :
|
---|
| 1135 | types.push_back(FitsDataType_char);
|
---|
| 1136 | taille_des_chaines.push_back(width);
|
---|
| 1137 | rept/=width;
|
---|
| 1138 | break;
|
---|
| 1139 | case TBYTE :
|
---|
[1359] | 1140 | types.push_back(FitsDataType_byte);
|
---|
[1300] | 1141 | break;
|
---|
| 1142 | default :
|
---|
| 1143 | cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
|
---|
| 1144 | throw IOExc("FitsFile::GetBinTabParameters, unsupported data type of field, for BINTABLE");
|
---|
| 1145 | }
|
---|
| 1146 | repeat.push_back(rept);
|
---|
| 1147 | }
|
---|
| 1148 | }
|
---|
[1136] | 1149 | for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
|
---|
| 1150 | delete [] ttype;
|
---|
| 1151 | }
|
---|
| 1152 |
|
---|
| 1153 | void FitsInFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
|
---|
| 1154 | {
|
---|
| 1155 | int status = 0;
|
---|
| 1156 | int hdutype;
|
---|
| 1157 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
| 1158 | if( status ) printerror( status,":KeywordsIntoDVList : erreur movabs");
|
---|
| 1159 | // get number of keywords
|
---|
| 1160 | int nkeys,keypos;
|
---|
| 1161 | fits_get_hdrpos(fileptr,&nkeys,&keypos,&status);
|
---|
| 1162 | if( status ) printerror( status );
|
---|
| 1163 |
|
---|
| 1164 | // put keywords in a DVList object
|
---|
| 1165 | char keyname[LEN_KEYWORD]= "";
|
---|
| 1166 | char strval[FLEN_VALUE]= "";
|
---|
| 1167 | char dtype;
|
---|
| 1168 | char card[FLEN_CARD];
|
---|
| 1169 | char *comkey = "COMMENT";
|
---|
[1143] | 1170 | char comment[FLEN_COMMENT];
|
---|
[1136] | 1171 |
|
---|
| 1172 | // shift with the number of mandatory keywords
|
---|
[1143] | 1173 | // int num= 8;
|
---|
| 1174 | int num= 0;
|
---|
| 1175 | // primary header
|
---|
| 1176 | if (hdunum == 1)
|
---|
| 1177 | {
|
---|
| 1178 | // read NAXIS
|
---|
| 1179 | int naxis=0;
|
---|
| 1180 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 1181 | // number of mandatory keywords
|
---|
| 1182 | num = naxis+3;
|
---|
| 1183 | }
|
---|
| 1184 | // extensions
|
---|
| 1185 | else
|
---|
| 1186 | {
|
---|
| 1187 | if (hdutype == IMAGE_HDU)
|
---|
| 1188 | {
|
---|
| 1189 | // read NAXIS
|
---|
| 1190 | int naxis=0;
|
---|
| 1191 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 1192 | // number of mandatory keywords
|
---|
| 1193 | num = naxis+5;
|
---|
| 1194 | }
|
---|
| 1195 | else
|
---|
| 1196 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 1197 | {
|
---|
| 1198 | // number of mandatory keywords
|
---|
| 1199 | num = 8;
|
---|
| 1200 | }
|
---|
| 1201 | }
|
---|
[1136] | 1202 | int j;
|
---|
| 1203 | for(j = num+1; j <= nkeys; j++)
|
---|
| 1204 | {
|
---|
| 1205 | fits_read_keyn(fileptr,j,card,strval,NULL,&status);
|
---|
| 1206 | if(status) printerror(status);
|
---|
| 1207 |
|
---|
| 1208 | strncpy(keyname,card,LEN_KEYWORD-1);
|
---|
| 1209 | if(strncmp(keyname,comkey,LEN_KEYWORD-1) != 0 && strlen(keyname) != 0
|
---|
| 1210 | && strlen(strval) != 0)
|
---|
| 1211 | {
|
---|
| 1212 | fits_get_keytype(strval,&dtype,&status);
|
---|
| 1213 | if(status) printerror(status);
|
---|
| 1214 |
|
---|
| 1215 | strip(keyname, 'B',' ');
|
---|
| 1216 | strip(strval, 'B',' ');
|
---|
| 1217 | strip(strval, 'B','\'');
|
---|
| 1218 |
|
---|
| 1219 | switch( dtype )
|
---|
| 1220 | {
|
---|
| 1221 | case 'C':
|
---|
[1143] | 1222 | fits_read_key(fileptr,TSTRING,keyname,strval,comment,&status);
|
---|
| 1223 | dvl[keyname]= strval;
|
---|
| 1224 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1225 | break;
|
---|
| 1226 | case 'I':
|
---|
| 1227 | int ival;
|
---|
[1143] | 1228 | fits_read_key(fileptr,TINT,keyname,&ival,comment,&status);
|
---|
[1136] | 1229 | dvl[keyname]= (int_4) ival; // Portage mac DY
|
---|
[1143] | 1230 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1231 | break;
|
---|
| 1232 | case 'L':
|
---|
| 1233 | int ilog;
|
---|
[1143] | 1234 | fits_read_key(fileptr,TLOGICAL,keyname,&ilog,comment,&status);
|
---|
[1136] | 1235 | dvl[keyname]= (int_4) ilog;
|
---|
[1143] | 1236 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1237 | break;
|
---|
| 1238 | case 'F':
|
---|
| 1239 | double dval;
|
---|
[1143] | 1240 | fits_read_key(fileptr,TDOUBLE,keyname,&dval,comment,&status);
|
---|
[1136] | 1241 | dvl[keyname]= dval;
|
---|
[1143] | 1242 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1243 | break;
|
---|
| 1244 | }
|
---|
| 1245 |
|
---|
| 1246 | }
|
---|
[839] | 1247 | }
|
---|
[1136] | 1248 | // dvl_.Print();
|
---|
| 1249 | }
|
---|
| 1250 |
|
---|
[1218] | 1251 |
|
---|
| 1252 | /*!
|
---|
| 1253 | \class SOPHYA::FitsOutFile
|
---|
| 1254 | Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
|
---|
| 1255 | */
|
---|
| 1256 |
|
---|
[1136] | 1257 | FitsOutFile::FitsOutFile()
|
---|
| 1258 | {
|
---|
[1193] | 1259 | InitNull();
|
---|
[903] | 1260 | }
|
---|
[839] | 1261 |
|
---|
[1218] | 1262 | /*! \fn SOPHYA::FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
|
---|
| 1263 |
|
---|
| 1264 | \param <WriteMode> enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default)
|
---|
| 1265 |
|
---|
| 1266 | */
|
---|
[1231] | 1267 |
|
---|
| 1268 | FitsOutFile::FitsOutFile(string const & flnm, WriteMode wrm)
|
---|
[1136] | 1269 | {
|
---|
[1231] | 1270 | InitNull();
|
---|
| 1271 | openoutputfitsfile(flnm.c_str(), wrm);
|
---|
| 1272 | }
|
---|
[839] | 1273 |
|
---|
[1231] | 1274 | FitsOutFile::FitsOutFile(const char * flnm, WriteMode wrm)
|
---|
| 1275 | {
|
---|
[1136] | 1276 | InitNull();
|
---|
[1231] | 1277 | openoutputfitsfile(flnm, wrm);
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | void FitsOutFile::openoutputfitsfile(const char * flnm, WriteMode wrm)
|
---|
| 1281 | {
|
---|
[1136] | 1282 | int status = 0;
|
---|
[839] | 1283 |
|
---|
[1136] | 1284 | // create new FITS file
|
---|
[1183] | 1285 | fits_create_file(&fptr_,flnm,&status);
|
---|
| 1286 | if( status )
|
---|
[1136] | 1287 | {
|
---|
[1193] | 1288 |
|
---|
| 1289 | switch (wrm)
|
---|
| 1290 | {
|
---|
[1183] | 1291 | // si on veut ecrire a la fin de ce fichier
|
---|
[1193] | 1292 | case append :
|
---|
[1183] | 1293 | status = 0;
|
---|
[1235] | 1294 | fits_clear_errmsg();
|
---|
[1183] | 1295 | fits_open_file(&fptr_,flnm,READWRITE,&status);
|
---|
| 1296 | if( status )
|
---|
| 1297 | {
|
---|
| 1298 | cout << " error opening file: " << flnm << endl;
|
---|
| 1299 | printerror(status, "failure opening a file supposed to exist");
|
---|
| 1300 | }
|
---|
| 1301 | else cout << " file " << flnm << " opened, new objects will be appended " << endl;
|
---|
| 1302 | fits_get_num_hdus(fptr_, &hdunum_, &status);
|
---|
| 1303 | int hdutype;
|
---|
| 1304 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1305 | if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
|
---|
[1193] | 1306 | break;
|
---|
| 1307 |
|
---|
| 1308 | case clear :
|
---|
[1183] | 1309 | {
|
---|
| 1310 | status = 0;
|
---|
[1235] | 1311 | fits_clear_errmsg();
|
---|
[1183] | 1312 | char* newname = new char[strlen(flnm)+1];
|
---|
| 1313 | //
|
---|
| 1314 | newname[0] = '!';
|
---|
| 1315 | newname[1] = '\0';
|
---|
| 1316 | strcat(newname, flnm);
|
---|
| 1317 | fits_create_file(&fptr_,newname,&status);
|
---|
[1193] | 1318 | delete [] newname;
|
---|
[1183] | 1319 | if (status)
|
---|
| 1320 | {
|
---|
| 1321 | cout << " error opening file: " << flnm << endl;
|
---|
| 1322 | printerror(status, "unable to open file, supposed to exist");
|
---|
| 1323 | }
|
---|
[1193] | 1324 | else cout << " WARNING : file " << flnm << " is overwritten " << endl;
|
---|
| 1325 | break;
|
---|
[1183] | 1326 | }
|
---|
[1193] | 1327 | case unknown :
|
---|
| 1328 | printerror(status, " file seems already to exist");
|
---|
| 1329 | break;
|
---|
[1183] | 1330 |
|
---|
[1193] | 1331 | }
|
---|
[1136] | 1332 | }
|
---|
| 1333 | }
|
---|
| 1334 |
|
---|
| 1335 |
|
---|
| 1336 |
|
---|
[1218] | 1337 | /*! \fn void SOPHYA::FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl)
|
---|
| 1338 |
|
---|
| 1339 | create an IMAGE header on FITS file.
|
---|
| 1340 | \param <type> type of data (see method ColTypeFromFits)
|
---|
| 1341 | \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
|
---|
| 1342 | \param <naxisn> array containind sizes of the different dimensions
|
---|
| 1343 | */
|
---|
[1221] | 1344 | void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* ptr_dvl)
|
---|
[1136] | 1345 | {
|
---|
| 1346 | int status = 0;
|
---|
| 1347 | long naxis = nbdim;
|
---|
| 1348 | long* naxes = new long[nbdim];
|
---|
[1246] | 1349 | bool hdunfirst= (hdunum_ == 0);
|
---|
| 1350 | if (hdunfirst)
|
---|
[1136] | 1351 | {
|
---|
[1143] | 1352 | if (imageOnPrimary_ == false)
|
---|
| 1353 | {
|
---|
[1234] | 1354 | hdunum_ = 1;
|
---|
[1143] | 1355 | fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
|
---|
[1246] | 1356 | }
|
---|
[1136] | 1357 | }
|
---|
| 1358 | int k;
|
---|
| 1359 | for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
|
---|
| 1360 | if (type == 'D')
|
---|
| 1361 | fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
|
---|
| 1362 | else
|
---|
| 1363 | if (type == 'E')
|
---|
| 1364 | fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
|
---|
| 1365 | else
|
---|
| 1366 | if (type == 'I')
|
---|
| 1367 | fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
|
---|
| 1368 | else
|
---|
| 1369 | {
|
---|
| 1370 | cout << " type of data: " << type << endl;
|
---|
| 1371 | throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
|
---|
| 1372 | }
|
---|
[1353] | 1373 |
|
---|
[1246] | 1374 | // on ajoute eventuellement un dvlist prepare et la doc SOPHYA
|
---|
[1136] | 1375 | hdunum_++;
|
---|
[1246] | 1376 | if (hdunfirst)
|
---|
| 1377 | {
|
---|
| 1378 | addDVListOnPrimary();
|
---|
| 1379 | writeSignatureOnFits(1);
|
---|
| 1380 | }
|
---|
[1143] | 1381 |
|
---|
[1353] | 1382 | // header format FITS
|
---|
| 1383 |
|
---|
| 1384 | writeAppendedHeaderOnFits();
|
---|
| 1385 |
|
---|
| 1386 | // write supplementary keywords (from SOPHYA)
|
---|
[1143] | 1387 | // dvl.Print();
|
---|
[1221] | 1388 | if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
|
---|
[1143] | 1389 |
|
---|
[1136] | 1390 | delete [] naxes;
|
---|
| 1391 | if( status ) printerror( status, "erreur creation HDU IMAGE" );
|
---|
| 1392 |
|
---|
| 1393 | }
|
---|
[1218] | 1394 |
|
---|
| 1395 |
|
---|
| 1396 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, double* map) const
|
---|
| 1397 |
|
---|
| 1398 | write double data from array 'map'on an IMAGE extension
|
---|
| 1399 | \param <nbData> number of data to be written
|
---|
| 1400 | */
|
---|
[1353] | 1401 | void FitsOutFile::PutImageToFits(int nbData, double* map) const
|
---|
[1136] | 1402 | {
|
---|
| 1403 | int status = 0;
|
---|
| 1404 | long npix= nbData;
|
---|
| 1405 | fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
|
---|
[1209] | 1406 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1136] | 1407 | }
|
---|
| 1408 |
|
---|
[1218] | 1409 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, float* map) const
|
---|
| 1410 |
|
---|
| 1411 | same as previous method with float data
|
---|
| 1412 | */
|
---|
[1353] | 1413 | void FitsOutFile::PutImageToFits(int nbData, float* map) const
|
---|
[1136] | 1414 | {
|
---|
| 1415 | int status = 0;
|
---|
| 1416 | long npix= nbData;
|
---|
| 1417 | fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
|
---|
[1209] | 1418 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1136] | 1419 |
|
---|
| 1420 | }
|
---|
[1218] | 1421 |
|
---|
| 1422 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits( int nbData, int* map) const
|
---|
| 1423 |
|
---|
| 1424 | same as previous method with int data */
|
---|
[1353] | 1425 | void FitsOutFile::PutImageToFits( int nbData, int* map) const
|
---|
[1136] | 1426 | {
|
---|
| 1427 | int status = 0;
|
---|
| 1428 |
|
---|
| 1429 | long npix= nbData;
|
---|
| 1430 | fits_write_img(fptr_,TINT,1,npix,map,&status);
|
---|
[1209] | 1431 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1136] | 1432 | }
|
---|
| 1433 |
|
---|
| 1434 |
|
---|
| 1435 |
|
---|
[1218] | 1436 | /*! \fn void SOPHYA::FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
|
---|
| 1437 |
|
---|
| 1438 | create an BINTABLE header on FITS file.
|
---|
| 1439 | \param <fieldType> array conta
|
---|
| 1440 | ining characters denoting types of the different column (see method ColTypeFromFits)
|
---|
| 1441 | \param <Noms> array of the names of columns
|
---|
| 1442 | \param <nentries> number of data of each column
|
---|
| 1443 | \param <tfields> number of columns
|
---|
| 1444 | \param <dvl> a SOPHYA DVList containing keywords to be appended
|
---|
| 1445 | \param <extname> keyword EXTNAME for FITS file
|
---|
| 1446 | \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
|
---|
| 1447 | */
|
---|
[1300] | 1448 | void FitsOutFile::makeHeaderBntblOnFits(string fieldType, vector<string> Noms, int nentries, int tfields, DVList* ptr_dvl, string extname, vector<int> taille_des_chaines)
|
---|
[839] | 1449 | {
|
---|
[1209] | 1450 | int k;
|
---|
[839] | 1451 | int status = 0;
|
---|
| 1452 | long nrows;
|
---|
[1300] | 1453 | // verifications de coherences
|
---|
[1209] | 1454 |
|
---|
[1193] | 1455 | if (fieldType.length() != tfields)
|
---|
[839] | 1456 | {
|
---|
[1193] | 1457 | cout << " nombre de champs :" << tfields << "nombre de types: " << fieldType.length() << endl;
|
---|
[1136] | 1458 | throw ParmError("FitsFile:: fields and types don't match");
|
---|
[839] | 1459 |
|
---|
| 1460 | }
|
---|
[1209] | 1461 | if (tfields > Noms.size())
|
---|
| 1462 | {
|
---|
| 1463 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of column names not equal to total number of columns" << endl;
|
---|
| 1464 | for (k=0; k<(tfields-Noms.size()); k++) Noms.push_back( string(" "));
|
---|
| 1465 | }
|
---|
| 1466 |
|
---|
| 1467 | // nombre de variables "chaines de caracteres"
|
---|
| 1468 | int nbString = 0;
|
---|
| 1469 | for (k=0; k<tfields;k++) if (fieldType[k] == 'A') nbString++;
|
---|
| 1470 | // coherence de la longueur du vecteur des tailles
|
---|
| 1471 | if (nbString > taille_des_chaines.size())
|
---|
| 1472 | {
|
---|
| 1473 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of string lengths not equal to total number of columns" << endl;
|
---|
| 1474 | int strSz=0;
|
---|
| 1475 | for (k=0; k<taille_des_chaines.size(); k++) if ( taille_des_chaines[k] > strSz) strSz = taille_des_chaines[k];
|
---|
| 1476 | for (k=0; k<(nbString-taille_des_chaines.size()); k++) taille_des_chaines.push_back(strSz);
|
---|
| 1477 | }
|
---|
[839] | 1478 | char ** ttype= new char*[tfields];
|
---|
| 1479 | char ** tform= new char*[tfields];
|
---|
| 1480 | char largeur[FLEN_VALUE];
|
---|
| 1481 | int noColString=0;
|
---|
[971] | 1482 | for (k=0; k<tfields;k++)
|
---|
[839] | 1483 | {
|
---|
| 1484 | char format[FLEN_VALUE];
|
---|
| 1485 |
|
---|
| 1486 | if(nentries < 1024)
|
---|
| 1487 | {
|
---|
| 1488 | nrows= nentries;
|
---|
| 1489 | if (fieldType[k] == 'A')
|
---|
| 1490 | {
|
---|
| 1491 | sprintf(largeur,"%d",taille_des_chaines[noColString++]);
|
---|
| 1492 | strcpy(format,largeur);
|
---|
| 1493 | }
|
---|
| 1494 | else strcpy(format,"1");
|
---|
| 1495 | }
|
---|
| 1496 | else
|
---|
| 1497 | {
|
---|
| 1498 | nrows = nentries/1024;
|
---|
| 1499 | if(nentries%1024 != 0) nrows++;
|
---|
| 1500 | if (fieldType[k] == 'A')
|
---|
| 1501 | {
|
---|
[1136] | 1502 | char largaux[FLEN_VALUE];
|
---|
| 1503 | sprintf(largeur,"%d",taille_des_chaines[noColString]);
|
---|
| 1504 | sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
|
---|
| 1505 | noColString++;
|
---|
| 1506 | strcpy(format, largaux);
|
---|
[839] | 1507 | }
|
---|
| 1508 | else strcpy(format,"1024");
|
---|
| 1509 | }
|
---|
| 1510 | strncat(format,&fieldType[k],1);
|
---|
| 1511 | if (fieldType[k] == 'A')
|
---|
| 1512 | {
|
---|
| 1513 | strcat(format,largeur);
|
---|
| 1514 | }
|
---|
[1193] | 1515 | ttype[k] = const_cast<char*>(Noms[k].c_str());
|
---|
[839] | 1516 | tform[k]= new char[FLEN_VALUE];
|
---|
| 1517 | strcpy(tform[k],format);
|
---|
| 1518 | }
|
---|
[1193] | 1519 | char* extn = const_cast<char*>(extname.c_str());
|
---|
[839] | 1520 |
|
---|
| 1521 | // create a new empty binary table onto the FITS file
|
---|
| 1522 | // physical units if they exist, are defined in the DVList object
|
---|
| 1523 | // so the NULL pointer is given for the tunit parameters.
|
---|
| 1524 | nrows=0;
|
---|
| 1525 | fits_create_tbl(fptr_,BINARY_TBL,nrows,tfields,ttype,tform,
|
---|
| 1526 | NULL,extn,&status);
|
---|
| 1527 | if( status ) printerror( status );
|
---|
[1353] | 1528 |
|
---|
| 1529 | int ii;
|
---|
| 1530 | for(ii = 0; ii < tfields; ii++)
|
---|
| 1531 | {
|
---|
| 1532 | delete [] tform[ii];
|
---|
| 1533 | }
|
---|
| 1534 | delete [] ttype;
|
---|
| 1535 | delete [] tform;
|
---|
| 1536 |
|
---|
| 1537 | // on ajoute eventuellement des mots-cles
|
---|
| 1538 |
|
---|
[1246] | 1539 | if ( hdunum_ == 0 )
|
---|
| 1540 | {
|
---|
| 1541 | hdunum_ = 2;
|
---|
| 1542 | addDVListOnPrimary();
|
---|
| 1543 | writeSignatureOnFits(1);
|
---|
| 1544 | }
|
---|
[1026] | 1545 | else hdunum_++;
|
---|
[1353] | 1546 |
|
---|
| 1547 | // header format FITS
|
---|
| 1548 |
|
---|
| 1549 | writeAppendedHeaderOnFits();
|
---|
| 1550 |
|
---|
| 1551 | // write SOPHYA keywords
|
---|
[1221] | 1552 | if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
|
---|
[839] | 1553 | }
|
---|
| 1554 |
|
---|
[1353] | 1555 |
|
---|
| 1556 |
|
---|
[1218] | 1557 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
|
---|
| 1558 |
|
---|
| 1559 | write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
|
---|
| 1560 | \param <nentries> number of data to be written
|
---|
| 1561 | */
|
---|
[1353] | 1562 |
|
---|
| 1563 | void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
|
---|
[839] | 1564 | {
|
---|
| 1565 | int status = 0;
|
---|
[971] | 1566 | int hdutype;
|
---|
[839] | 1567 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1568 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1569 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
[867] | 1570 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1571 | {
|
---|
| 1572 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1573 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[867] | 1574 | }
|
---|
[839] | 1575 | int code;
|
---|
| 1576 | long repeat, width;
|
---|
| 1577 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1578 | if( code != TDOUBLE)
|
---|
| 1579 | {
|
---|
[1209] | 1580 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;
|
---|
[839] | 1581 | }
|
---|
| 1582 | fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1583 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1584 | }
|
---|
[1218] | 1585 |
|
---|
| 1586 |
|
---|
| 1587 |
|
---|
| 1588 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
|
---|
| 1589 |
|
---|
| 1590 | same as previous method with float data
|
---|
| 1591 | */
|
---|
[1353] | 1592 | void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
|
---|
[839] | 1593 | {
|
---|
| 1594 | int status = 0;
|
---|
| 1595 | int hdutype;
|
---|
| 1596 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1597 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1598 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1599 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1600 | {
|
---|
| 1601 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1602 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1603 | }
|
---|
| 1604 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1605 | {
|
---|
[1209] | 1606 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1607 | }
|
---|
| 1608 | int code;
|
---|
| 1609 | long repeat, width;
|
---|
| 1610 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1611 | if( code != TFLOAT)
|
---|
| 1612 | {
|
---|
[1209] | 1613 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;
|
---|
[839] | 1614 | }
|
---|
| 1615 | fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1616 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1617 | }
|
---|
[1218] | 1618 |
|
---|
| 1619 |
|
---|
| 1620 | /*! \fn void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
|
---|
| 1621 |
|
---|
| 1622 | same as previous method with int data
|
---|
| 1623 | */
|
---|
[1353] | 1624 | void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
|
---|
[839] | 1625 | {
|
---|
| 1626 | int status = 0;
|
---|
| 1627 | int hdutype;
|
---|
| 1628 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1629 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1630 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1631 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1632 | {
|
---|
| 1633 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1634 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1635 | }
|
---|
| 1636 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1637 | {
|
---|
[1209] | 1638 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1639 | }
|
---|
| 1640 | int code;
|
---|
| 1641 | long repeat, width;
|
---|
| 1642 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1643 | if( code != TLONG && code != TINT && code != TSHORT )
|
---|
| 1644 | {
|
---|
[1209] | 1645 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;
|
---|
[839] | 1646 | }
|
---|
| 1647 | fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
[971] | 1648 | if( status ) printerror( status," ecriture du fichier fits" );
|
---|
[839] | 1649 | }
|
---|
[1218] | 1650 |
|
---|
| 1651 |
|
---|
| 1652 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
| 1653 | same as previous method with char* data
|
---|
| 1654 | */
|
---|
[1209] | 1655 | void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
[839] | 1656 | {
|
---|
| 1657 | int status = 0;
|
---|
| 1658 | int hdutype;
|
---|
| 1659 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1660 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1661 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1662 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1663 | {
|
---|
| 1664 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1665 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1666 | }
|
---|
| 1667 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1668 | {
|
---|
[1209] | 1669 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1670 | }
|
---|
| 1671 | int code;
|
---|
| 1672 | long repeat, width;
|
---|
| 1673 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1674 | if( code != TSTRING)
|
---|
| 1675 | {
|
---|
[1209] | 1676 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;
|
---|
[839] | 1677 | }
|
---|
| 1678 | fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1679 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1680 | }
|
---|
| 1681 |
|
---|
[1209] | 1682 | void FitsOutFile::PutBinTabLine(long NoLine, BnTblLine& ligne) const
|
---|
[1193] | 1683 | {
|
---|
[1209] | 1684 | // on ne fait pas de verification de type, ni de dimension ici, pour
|
---|
| 1685 | // des raisons de performances
|
---|
| 1686 | int k;
|
---|
[1193] | 1687 | int status= 0;
|
---|
| 1688 | int anull;
|
---|
[1209] | 1689 | int ncol=0;
|
---|
[1193] | 1690 | long nels=1;
|
---|
[1209] | 1691 | // int nbcols;
|
---|
| 1692 | // fits_get_num_cols(fptr_, &nbcols,&status);
|
---|
| 1693 | for (k=0; k<ligne.ddata_.size(); k++, ncol++)
|
---|
[1193] | 1694 | {
|
---|
[1209] | 1695 | fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ligne.ddata_[k] ,&status);
|
---|
| 1696 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture double" );
|
---|
[1193] | 1697 | }
|
---|
[1209] | 1698 | for (k=0; k<ligne.fdata_.size(); k++, ncol++)
|
---|
| 1699 | {
|
---|
| 1700 | fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &ligne.fdata_[k] ,&status);
|
---|
| 1701 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture float" );
|
---|
| 1702 | }
|
---|
| 1703 | for (k=0; k<ligne.idata_.size(); k++, ncol++)
|
---|
| 1704 | {
|
---|
| 1705 | fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &ligne.idata_[k] ,&status);
|
---|
| 1706 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier" );
|
---|
| 1707 | }
|
---|
[1359] | 1708 | for (k=0; k<ligne.ldata_.size(); k++, ncol++)
|
---|
| 1709 | {
|
---|
| 1710 | fits_write_col(fptr_,TLONG,ncol+1,NoLine+1,1,1, &ligne.ldata_[k] ,&status);
|
---|
| 1711 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier long" );
|
---|
| 1712 | }
|
---|
| 1713 | for (k=0; k<ligne.bdata_.size(); k++, ncol++)
|
---|
| 1714 | {
|
---|
| 1715 | fits_write_col(fptr_,TBYTE,ncol+1,NoLine+1,1,1, &ligne.bdata_[k] ,&status);
|
---|
| 1716 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture byte" );
|
---|
| 1717 | }
|
---|
[1209] | 1718 |
|
---|
| 1719 | for (k=0; k<ligne.cdata_.size(); k++, ncol++)
|
---|
| 1720 | {
|
---|
[1220] | 1721 | fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, (void*)ligne.cdata_[k].c_str() ,&status);
|
---|
[1209] | 1722 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture caracteres" );
|
---|
| 1723 | }
|
---|
[1193] | 1724 | }
|
---|
| 1725 |
|
---|
| 1726 |
|
---|
[1218] | 1727 | /* \fn void SOPHYA::FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
|
---|
| 1728 |
|
---|
| 1729 | Put keywords from a DVList into the primary header of the fits-file
|
---|
| 1730 | */
|
---|
[1246] | 1731 | void FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl)
|
---|
[1143] | 1732 | {
|
---|
| 1733 | int status = 0;
|
---|
| 1734 | int hdutype;
|
---|
[1246] | 1735 | if (hdunum_ == 0)
|
---|
| 1736 | {
|
---|
| 1737 | if (dvlToPrimary_ == NULL) dvlToPrimary_ = new DVList(dvl);
|
---|
| 1738 | else dvlToPrimary_->Merge(dvl);
|
---|
| 1739 | }
|
---|
| 1740 | else
|
---|
| 1741 | {
|
---|
| 1742 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1743 | addKeywordsOfDVList(dvl);
|
---|
| 1744 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1745 | }
|
---|
[1143] | 1746 | }
|
---|
[839] | 1747 |
|
---|
[1143] | 1748 |
|
---|
[1246] | 1749 | void FitsOutFile::writeSignatureOnFits(int hdunum) const
|
---|
[839] | 1750 | {
|
---|
| 1751 | int status = 0;
|
---|
[1246] | 1752 | int hdutype;
|
---|
[839] | 1753 | char keyname[LEN_KEYWORD];
|
---|
| 1754 | char strval[FLEN_VALUE];
|
---|
| 1755 | char comment[FLEN_COMMENT];
|
---|
[1246] | 1756 | if (hdunum_ == 0)
|
---|
| 1757 | {
|
---|
| 1758 | cerr << " WARNING : can't write keywords on non existing primary header" << endl;
|
---|
| 1759 | return;
|
---|
| 1760 | }
|
---|
| 1761 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1762 | //
|
---|
[971] | 1763 | strncpy(keyname, "CREATOR", LEN_KEYWORD);
|
---|
| 1764 | keyname[LEN_KEYWORD-1] = '\0';
|
---|
| 1765 | strcpy(strval, "SOPHYA");
|
---|
| 1766 | strcpy(comment," SOPHYA Package - FITSIOServer ");
|
---|
| 1767 | fits_write_key(fptr_, TSTRING, keyname, &strval, comment, &status);
|
---|
| 1768 | if( status ) printerror( status );
|
---|
[1143] | 1769 | fits_write_date(fptr_, &status);
|
---|
[971] | 1770 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
| 1771 | fits_write_comment(fptr_, " SOPHYA package - FITSIOSever ", &status);
|
---|
| 1772 | fits_write_comment(fptr_, " (C) LAL/IN2P3-CNRS Orsay, FRANCE 2000", &status);
|
---|
| 1773 | fits_write_comment(fptr_, " (C) DAPNIA/CEA Saclay, FRANCE 2000", &status);
|
---|
| 1774 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
[1045] | 1775 | if( status ) printerror( status, "erreur writeSignatureOnFits" );
|
---|
[1246] | 1776 | //
|
---|
| 1777 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[839] | 1778 | }
|
---|
| 1779 |
|
---|
[903] | 1780 |
|
---|
[1246] | 1781 | void FitsOutFile::addKeywordsOfDVList( DVList& dvl) const
|
---|
[1143] | 1782 | {
|
---|
| 1783 | int status = 0;
|
---|
| 1784 | fits_write_comment(fptr_,"---------- keywords from SOPHYA ---------", &status);
|
---|
| 1785 | DVList::ValList::const_iterator it;
|
---|
| 1786 | for(it = dvl.Begin(); it != dvl.End(); it++)
|
---|
| 1787 | {
|
---|
[1311] | 1788 | MuTyV::MTVType keytype= (*it).second.elval.Type();
|
---|
[1143] | 1789 | char keyname[10];
|
---|
| 1790 | strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
|
---|
[1183] | 1791 | string key(keyname);
|
---|
[1143] | 1792 | char comment[FLEN_COMMENT];
|
---|
| 1793 | char strval[FLEN_VALUE]= "";
|
---|
| 1794 | char *comkey = "COMMENT";
|
---|
[1353] | 1795 | // fits_read_keyword(fptr_, keyname, strval, NULL, &status);
|
---|
| 1796 | // if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 )
|
---|
[1143] | 1797 | {
|
---|
[1183] | 1798 | string coco = dvl.GetComment(key);
|
---|
| 1799 | coco.copy( comment, FLEN_COMMENT-1);
|
---|
| 1800 | int bout = (coco.length() < FLEN_COMMENT) ? coco.length() : FLEN_COMMENT-1;
|
---|
| 1801 | comment[bout]= '\0';
|
---|
[1143] | 1802 | status = 0;
|
---|
| 1803 | switch (keytype)
|
---|
| 1804 | {
|
---|
[1311] | 1805 | case MuTyV::MTVInteger :
|
---|
[1143] | 1806 | {
|
---|
[1183] | 1807 | int ival = (int)dvl.GetI(key);
|
---|
| 1808 | fits_write_key(fptr_,TINT,keyname,&ival, comment,&status);
|
---|
[1143] | 1809 | break;
|
---|
| 1810 | }
|
---|
[1311] | 1811 | case MuTyV::MTVFloat :
|
---|
[1143] | 1812 | {
|
---|
[1183] | 1813 | double dval= (double)dvl.GetD(key);
|
---|
[1143] | 1814 | fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
|
---|
| 1815 | break;
|
---|
| 1816 | }
|
---|
[1311] | 1817 | case MuTyV::MTVString :
|
---|
[1143] | 1818 | {
|
---|
[1183] | 1819 | char strvaleur[FLEN_VALUE]= "";
|
---|
| 1820 | string valChaine = dvl.GetS(key);
|
---|
| 1821 | valChaine.copy(strvaleur, FLEN_VALUE-1);
|
---|
| 1822 | int fin = (valChaine.length() < FLEN_VALUE) ? valChaine.length() : FLEN_VALUE-1;
|
---|
| 1823 | strvaleur[fin]= '\0';
|
---|
| 1824 |
|
---|
| 1825 | fits_write_key(fptr_,TSTRING,keyname,&strvaleur,comment,&status);
|
---|
[1143] | 1826 | break;
|
---|
| 1827 | }
|
---|
| 1828 | }
|
---|
| 1829 | }
|
---|
| 1830 | if( status ) printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" );
|
---|
| 1831 | }
|
---|
| 1832 | fits_write_comment(fptr_,"--------------------------------------", &status);
|
---|
| 1833 | }
|
---|
[903] | 1834 |
|
---|
| 1835 |
|
---|
[1246] | 1836 | void FitsOutFile::addDVListOnPrimary()
|
---|
| 1837 | {
|
---|
| 1838 | int status = 0;
|
---|
| 1839 | int hdutype;
|
---|
| 1840 | if (hdunum_ == 0)
|
---|
| 1841 | {
|
---|
| 1842 | cerr << " WARNING : can't write keywords on non existing primary header" << endl;
|
---|
| 1843 | return;
|
---|
| 1844 | }
|
---|
| 1845 | if (dvlToPrimary_ != NULL)
|
---|
| 1846 | {
|
---|
| 1847 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1848 | addKeywordsOfDVList(*dvlToPrimary_);
|
---|
| 1849 | delete dvlToPrimary_;
|
---|
| 1850 | dvlToPrimary_ = NULL;
|
---|
| 1851 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1852 | }
|
---|
| 1853 | }
|
---|
[839] | 1854 |
|
---|
[1353] | 1855 |
|
---|
| 1856 | /*! \fn void FitsOutFile::appendInHeader(FitsInFile& infits, int hdunum)
|
---|
| 1857 |
|
---|
| 1858 | get a header from FitsInFile and append to the header beeing built
|
---|
| 1859 | (shifting mandatory keywords)
|
---|
| 1860 | */
|
---|
| 1861 |
|
---|
| 1862 | void FitsOutFile::appendInputHeader(FitsInFile& infits, int hdunum)
|
---|
| 1863 | {
|
---|
| 1864 | int status = 0;
|
---|
| 1865 | int hdutype;
|
---|
| 1866 | fitsfile* fptr=infits.fitsfilePtr();
|
---|
| 1867 | fits_movabs_hdu(fptr,hdunum,&hdutype,&status);
|
---|
| 1868 | if( status ) fits_report_error(stderr,status);
|
---|
| 1869 |
|
---|
| 1870 | // get number of keywords
|
---|
| 1871 | int nkeys,keypos;
|
---|
| 1872 | fits_get_hdrpos(fptr,&nkeys,&keypos,&status);
|
---|
| 1873 | if( status ) fits_report_error(stderr,status);
|
---|
| 1874 | // shift with the number of mandatory keywords
|
---|
| 1875 | int num= 0;
|
---|
| 1876 | // if primary header
|
---|
| 1877 | if (hdunum == 1)
|
---|
| 1878 | {
|
---|
| 1879 | // read NAXIS
|
---|
| 1880 | int naxis=0;
|
---|
| 1881 | fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 1882 | // number of mandatory keywords
|
---|
| 1883 | num = naxis+3;
|
---|
| 1884 | }
|
---|
| 1885 | // extensions
|
---|
| 1886 | else
|
---|
| 1887 | {
|
---|
| 1888 | if (hdutype == IMAGE_HDU)
|
---|
| 1889 | {
|
---|
| 1890 | // read NAXIS
|
---|
| 1891 | int naxis=0;
|
---|
| 1892 | fits_read_key(fptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 1893 | // number of mandatory keywords
|
---|
| 1894 | num = naxis+5;
|
---|
| 1895 | }
|
---|
| 1896 | else
|
---|
| 1897 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 1898 | {
|
---|
| 1899 | // number of mandatory keywords
|
---|
| 1900 | num = 8;
|
---|
| 1901 | }
|
---|
| 1902 | }
|
---|
| 1903 | int j;
|
---|
| 1904 | char keyname[LEN_KEYWORD];
|
---|
| 1905 | char value[FLEN_VALUE];
|
---|
| 1906 | char comment[FLEN_COMMENT];
|
---|
| 1907 | for(j = num+1; j <= nkeys; j++)
|
---|
| 1908 | {
|
---|
| 1909 | char dtype;
|
---|
| 1910 | fits_read_keyn(fptr,j,keyname,value,comment,&status);
|
---|
| 1911 | if(status)
|
---|
| 1912 | {
|
---|
| 1913 | fits_report_error(stderr,status);
|
---|
| 1914 | status=0;
|
---|
| 1915 | }
|
---|
| 1916 | string kn(keyname);
|
---|
| 1917 | string cm(comment);
|
---|
| 1918 | string val(value);
|
---|
| 1919 | FitsKeyword kw(kn, val, cm);
|
---|
| 1920 | mots_cles_.push_back(kw);
|
---|
| 1921 | }
|
---|
| 1922 | }
|
---|
| 1923 | void FitsOutFile::writeAppendedHeaderOnFits()
|
---|
| 1924 | {
|
---|
| 1925 | for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++)
|
---|
| 1926 | {
|
---|
| 1927 | (*it).writeOnFits(fptr_);
|
---|
| 1928 | }
|
---|
| 1929 | mots_cles_.clear();
|
---|
| 1930 | }
|
---|
| 1931 |
|
---|
| 1932 | void FitsOutFile::insertKeywordOnHeader(string keyname, double value, string comment)
|
---|
| 1933 | {
|
---|
| 1934 | char* cvalue = new char[16];
|
---|
| 1935 | sprintf(cvalue,"%e",value);
|
---|
| 1936 | FitsKeyword kw(keyname, string(cvalue), comment);
|
---|
| 1937 | mots_cles_.push_back(kw);
|
---|
| 1938 | }
|
---|
| 1939 |
|
---|
| 1940 | void FitsOutFile::insertCommentLineOnHeader(string comment)
|
---|
| 1941 | {
|
---|
| 1942 | FitsKeyword kw(comment);
|
---|
| 1943 | mots_cles_.push_back(kw);
|
---|
| 1944 | }
|
---|
| 1945 |
|
---|
| 1946 | void FitsOutFile::PrintHeaderToBeAppended()
|
---|
| 1947 | {
|
---|
| 1948 | cout << " contenu du header en cours de fabrication " << endl;
|
---|
| 1949 | for (list<FitsKeyword>::iterator it=mots_cles_.begin(); it !=mots_cles_.end(); it++)
|
---|
| 1950 | {
|
---|
| 1951 | (*it).Print();
|
---|
| 1952 | }
|
---|
| 1953 | }
|
---|
| 1954 |
|
---|
| 1955 |
|
---|
| 1956 | FitsKeyword::FitsKeyword()
|
---|
| 1957 | {
|
---|
| 1958 | datatype_=' ';
|
---|
| 1959 | keyname_ = string("");
|
---|
| 1960 | dvalue_=0.;
|
---|
| 1961 | ivalue_=1;
|
---|
| 1962 | svalue_=string("");
|
---|
| 1963 | comment_=string("");
|
---|
| 1964 | }
|
---|
| 1965 |
|
---|
| 1966 | FitsKeyword::FitsKeyword(string comment)
|
---|
| 1967 | {
|
---|
| 1968 | datatype_=' ';
|
---|
| 1969 | keyname_=string("COMMENT");
|
---|
| 1970 | comment_=comment;
|
---|
| 1971 | }
|
---|
| 1972 |
|
---|
| 1973 | FitsKeyword::FitsKeyword(string keyname, string value, string comment) : keyname_(keyname), comment_(comment)
|
---|
| 1974 | {
|
---|
| 1975 | int status=0;
|
---|
| 1976 | char dtype;
|
---|
| 1977 | const char* val= value.c_str();
|
---|
| 1978 | char* valk = const_cast<char*>(val);
|
---|
| 1979 | fits_get_keytype(valk,&dtype,&status);
|
---|
| 1980 | if(status)
|
---|
| 1981 | {
|
---|
| 1982 | status=0;
|
---|
[1354] | 1983 | if (status == VALUE_UNDEFINED) cout << "WARNING (FitsKeyword) : undefined keyword value " << endl;
|
---|
[1353] | 1984 | datatype_=' ';
|
---|
| 1985 | }
|
---|
| 1986 | else datatype_=dtype;
|
---|
| 1987 |
|
---|
| 1988 | switch( datatype_ )
|
---|
| 1989 | {
|
---|
| 1990 | case 'C':
|
---|
| 1991 | {
|
---|
[1354] | 1992 | strip(valk, 'B','\'');
|
---|
| 1993 | svalue_ = string(valk);
|
---|
[1353] | 1994 | break;
|
---|
| 1995 | }
|
---|
| 1996 | case 'I':
|
---|
| 1997 | {
|
---|
| 1998 | ivalue_ = atoi(val);
|
---|
| 1999 | break;
|
---|
| 2000 | }
|
---|
| 2001 | case 'L':
|
---|
| 2002 | {
|
---|
[1354] | 2003 | bool bb = value.c_str();
|
---|
| 2004 | ivalue_ = (int)bb;
|
---|
[1353] | 2005 | break;
|
---|
| 2006 | }
|
---|
| 2007 | case 'F':
|
---|
| 2008 | {
|
---|
| 2009 | dvalue_ = atof(val);
|
---|
| 2010 | break;
|
---|
| 2011 | }
|
---|
| 2012 | case 'X':
|
---|
| 2013 | {
|
---|
| 2014 | throw IOExc("FitsKeyword , complex keyword value not supported");
|
---|
| 2015 | }
|
---|
| 2016 | }
|
---|
| 2017 | }
|
---|
| 2018 |
|
---|
| 2019 | void FitsKeyword::writeOnFits(fitsfile* ptr)
|
---|
| 2020 | {
|
---|
| 2021 | int status=0;
|
---|
| 2022 | // char* keyname = new char[LEN_KEYWORD];
|
---|
| 2023 | // char* comment = new char[FLEN_COMMENT];
|
---|
| 2024 | char* keyname;
|
---|
| 2025 | char* comment;
|
---|
| 2026 | keyname = const_cast<char*>(keyname_.c_str());
|
---|
| 2027 | comment = const_cast<char*>(comment_.c_str());
|
---|
| 2028 | // get number of keywords
|
---|
| 2029 | int nkeys,keypos;
|
---|
| 2030 | fits_get_hdrpos(ptr,&nkeys,&keypos,&status);
|
---|
| 2031 | switch( datatype_ )
|
---|
| 2032 | {
|
---|
| 2033 | case 'C':
|
---|
| 2034 | {
|
---|
| 2035 | char value[FLEN_VALUE];
|
---|
| 2036 | strncpy(value,svalue_.c_str(),FLEN_VALUE) ;
|
---|
| 2037 | fits_write_key(ptr,TSTRING,keyname,&value, comment,&status);
|
---|
| 2038 | fits_report_error(stderr,status);
|
---|
| 2039 | break;
|
---|
| 2040 | }
|
---|
| 2041 | case 'I':
|
---|
| 2042 | {
|
---|
| 2043 | fits_write_key(ptr,TINT,keyname,&ivalue_, comment,&status);
|
---|
| 2044 | fits_report_error(stderr,status);
|
---|
| 2045 | break;
|
---|
| 2046 | }
|
---|
| 2047 | case 'L':
|
---|
| 2048 | {
|
---|
| 2049 | fits_write_key(ptr,TLOGICAL,keyname,&ivalue_, comment,&status);
|
---|
| 2050 | fits_report_error(stderr,status);
|
---|
| 2051 | break;
|
---|
| 2052 | }
|
---|
| 2053 | case 'F':
|
---|
| 2054 | {
|
---|
| 2055 | fits_write_key(ptr,TDOUBLE,keyname,&dvalue_, comment,&status);
|
---|
| 2056 | fits_report_error(stderr,status);
|
---|
| 2057 | break;
|
---|
| 2058 | }
|
---|
| 2059 | case 'X':
|
---|
| 2060 | {
|
---|
| 2061 | cout << "FitsKeyword : complex keyword value not supported" << endl;;
|
---|
| 2062 | }
|
---|
| 2063 | default :
|
---|
| 2064 | {
|
---|
| 2065 | char *comkey = "COMMENT";
|
---|
| 2066 | if(strncmp(keyname,comkey,LEN_KEYWORD-1) == 0)
|
---|
| 2067 | {
|
---|
| 2068 | fits_write_comment(ptr,comment,&status);
|
---|
| 2069 | fits_report_error(stderr,status);
|
---|
| 2070 | }
|
---|
| 2071 | else
|
---|
| 2072 | {
|
---|
| 2073 | cout << " WARNING (FitsKeyword::writeOnFits) : unrecognized keyword : " << keyname_ << endl;
|
---|
| 2074 | }
|
---|
| 2075 | }
|
---|
| 2076 | }
|
---|
| 2077 | }
|
---|
| 2078 |
|
---|
| 2079 | void FitsKeyword::Print()
|
---|
| 2080 | {
|
---|
| 2081 | switch( datatype_ )
|
---|
| 2082 | {
|
---|
| 2083 | case 'C':
|
---|
| 2084 | {
|
---|
| 2085 | cout << " mot cle : " << keyname_ << " valeur : " << svalue_ << " commentaire : " << comment_ <<endl;
|
---|
| 2086 | break;
|
---|
| 2087 | }
|
---|
| 2088 | case 'I':
|
---|
| 2089 | {
|
---|
| 2090 | cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl;
|
---|
| 2091 | break;
|
---|
| 2092 | }
|
---|
| 2093 | case 'L':
|
---|
| 2094 | {
|
---|
| 2095 | cout << " mot cle : " << keyname_ << " valeur : " << ivalue_ << " commentaire : " << comment_ <<endl;
|
---|
| 2096 | break;
|
---|
| 2097 | }
|
---|
| 2098 | case 'F':
|
---|
| 2099 | {
|
---|
| 2100 | cout << " mot cle : " << keyname_ << " valeur : " << dvalue_ << " commentaire : " << comment_ <<endl;
|
---|
| 2101 | break;
|
---|
| 2102 | }
|
---|
| 2103 | case 'X':
|
---|
| 2104 | {
|
---|
| 2105 | cout << "FitsKeyword : complex keyword value not supported" << endl;;
|
---|
| 2106 | }
|
---|
| 2107 | default :
|
---|
| 2108 | {
|
---|
| 2109 | cout << " mot cle : " << keyname_ << " commentaire : " << comment_ <<endl;
|
---|
| 2110 | }
|
---|
| 2111 | }
|
---|
| 2112 | }
|
---|