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