[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 | {
|
---|
[1234] | 106 | is.ReadFInit(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 | {
|
---|
[1175] | 226 |
|
---|
[1045] | 227 | bitpix_ = 0;
|
---|
| 228 | naxis_ = 0;
|
---|
| 229 | nbData_ = 0;
|
---|
| 230 | nrows_ = 0;
|
---|
| 231 | nbcols_ = 0;
|
---|
| 232 | naxisn_.clear();
|
---|
| 233 | repeat_.clear();
|
---|
| 234 | noms_.clear();
|
---|
| 235 | taille_des_chaines_.clear();
|
---|
| 236 | dvl_.Clear();
|
---|
[1175] | 237 |
|
---|
| 238 |
|
---|
[1045] | 239 | }
|
---|
| 240 |
|
---|
[1218] | 241 | //////////////////////////////////////////////////////////
|
---|
| 242 | // methods with general purpose
|
---|
| 243 | /////////////////////////////////////////////////////////
|
---|
[1045] | 244 |
|
---|
[1136] | 245 | int FitsInFile::NbBlocks(char flnm[])
|
---|
[903] | 246 | {
|
---|
| 247 | int status = 0;
|
---|
| 248 | int nbhdu = 0;
|
---|
| 249 | fitsfile* fileptr;
|
---|
| 250 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
| 251 | if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" );
|
---|
| 252 | fits_get_num_hdus(fileptr, &nbhdu, &status);
|
---|
| 253 | fits_close_file(fileptr,&status);
|
---|
| 254 | return nbhdu;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[1231] | 257 | void FitsInFile::GetBlockType(char flnm[], int hdunum, FitsExtensionType& typeOfExtension, int& naxis, vector<int>& naxisn, FitsDataType& dataType, DVList& dvl )
|
---|
[903] | 258 | {
|
---|
| 259 | int status = 0;
|
---|
| 260 | fitsfile* fileptr;
|
---|
| 261 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
[1209] | 262 | if( status ) printerror( status, "GetBlockType: erreur ouverture fichier" );
|
---|
[903] | 263 | // move to the specified HDU number
|
---|
| 264 | int hdutype = 0;
|
---|
| 265 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
[1209] | 266 | if( status ) printerror( status,"GetBlockType: erreur movabs");
|
---|
[903] | 267 | if(hdutype == IMAGE_HDU)
|
---|
| 268 | {
|
---|
[1231] | 269 | typeOfExtension = FitsExtensionType_IMAGE;
|
---|
[903] | 270 | int bitpix;
|
---|
| 271 | GetImageParameters (fileptr, bitpix, naxis, naxisn);
|
---|
[1231] | 272 | if(bitpix == DOUBLE_IMG) dataType = FitsDataType_double;
|
---|
[903] | 273 | else
|
---|
[1231] | 274 | if(bitpix == FLOAT_IMG) dataType = FitsDataType_float;
|
---|
[903] | 275 | else
|
---|
[1231] | 276 | if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = FitsDataType_int;
|
---|
[903] | 277 | else
|
---|
| 278 | {
|
---|
| 279 | cout << " bitpix= " << bitpix << endl;
|
---|
[1209] | 280 | throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
|
---|
[903] | 281 | }
|
---|
| 282 |
|
---|
| 283 | }
|
---|
| 284 | else
|
---|
| 285 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 286 | {
|
---|
| 287 | int nrows = 0;
|
---|
| 288 | vector<string> noms;
|
---|
| 289 | vector<char> types;
|
---|
| 290 | vector<int> taille_des_chaines;
|
---|
[971] | 291 | GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines);
|
---|
| 292 | int k;
|
---|
| 293 | for (k=0; k< naxisn.size(); k++) naxisn[k] *= nrows;
|
---|
[903] | 294 | if(hdutype == ASCII_TBL)
|
---|
| 295 | {
|
---|
[1231] | 296 | typeOfExtension = FitsExtensionType_ASCII_TBL;
|
---|
| 297 | dataType = FitsDataType_ASCII;
|
---|
[903] | 298 | }
|
---|
| 299 | else
|
---|
| 300 | {
|
---|
[1231] | 301 | typeOfExtension = FitsExtensionType_BINARY_TBL;
|
---|
| 302 | if(types[0] == 'D') dataType = FitsDataType_double;
|
---|
[903] | 303 | else
|
---|
[1231] | 304 | if(types[0] == 'E') dataType = FitsDataType_float;
|
---|
[903] | 305 | else
|
---|
[1231] | 306 | if(types[0] == 'I' ) dataType = FitsDataType_int;
|
---|
[903] | 307 | else
|
---|
[1231] | 308 | if(types[0] == 'S' ) dataType = FitsDataType_char;
|
---|
[903] | 309 | else
|
---|
| 310 | {
|
---|
| 311 | cout << " types[0]= " << types[0] << endl;
|
---|
[1209] | 312 | throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
|
---|
[903] | 313 | }
|
---|
| 314 | }
|
---|
| 315 | }
|
---|
| 316 | else
|
---|
| 317 | {
|
---|
| 318 | cout << " hdutype= " << hdutype << endl;
|
---|
[1209] | 319 | throw IOExc("FitsFile::GetBlockType: this HDU type is unknown");
|
---|
[903] | 320 | }
|
---|
| 321 |
|
---|
[971] | 322 | KeywordsIntoDVList(fileptr, dvl, hdunum);
|
---|
[903] | 323 | fits_close_file(fileptr,&status);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[1136] | 326 |
|
---|
| 327 | void FitsInFile::ReadFInit(int hdunum)
|
---|
[1045] | 328 | {
|
---|
[1234] | 329 | InitNull();
|
---|
[1045] | 330 | int status = 0;
|
---|
[1136] | 331 |
|
---|
[1234] | 332 | if (hdunum != 0 ) hdunum_ = hdunum;
|
---|
| 333 |
|
---|
| 334 | // si le numero de header non precise
|
---|
| 335 | else
|
---|
[1045] | 336 | {
|
---|
[1234] | 337 | // si c'est le premier objet a lire
|
---|
| 338 | if (hdunum_ == 0)
|
---|
[1045] | 339 | {
|
---|
[1234] | 340 | // on calcule le numero de header a lire
|
---|
[1246] | 341 | if (imageOnPrimary_ == true ) hdunum_ = 1;
|
---|
[1234] | 342 | else hdunum_ = 2;
|
---|
[1045] | 343 | }
|
---|
[1234] | 344 | // sinon objet suivant
|
---|
| 345 | else hdunum_++;
|
---|
[1045] | 346 | }
|
---|
[1234] | 347 | getHeader();
|
---|
| 348 |
|
---|
[1045] | 349 | }
|
---|
| 350 |
|
---|
[1218] | 351 |
|
---|
| 352 | void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
|
---|
| 353 | {
|
---|
| 354 | int hdunum=0;
|
---|
| 355 | cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum) << endl;
|
---|
| 356 | int status= 0;
|
---|
| 357 |
|
---|
| 358 | // bits per pixels
|
---|
| 359 | fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
|
---|
| 360 | if( status ) printerror( status );
|
---|
| 361 |
|
---|
| 362 | // number of dimensions in the FITS array
|
---|
| 363 | naxis= 0;
|
---|
| 364 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 365 | if( status ) printerror( status );
|
---|
| 366 | // read the NAXISn keywords to get image size
|
---|
| 367 | long* naxes = new long[naxis] ;
|
---|
| 368 | int nfound;
|
---|
| 369 | fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
|
---|
| 370 | if( status ) printerror( status );
|
---|
| 371 | if (nfound != naxis )
|
---|
| 372 | cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
|
---|
| 373 | int k;
|
---|
| 374 | for (k=0; k<naxis; k++)
|
---|
| 375 | {
|
---|
| 376 | naxisn.push_back( (int)naxes[k] );
|
---|
| 377 | }
|
---|
| 378 | delete [] naxes;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 |
|
---|
| 382 |
|
---|
| 383 |
|
---|
| 384 | /*! \fn DVList SOPHYA::FitsInFile::DVListFromPrimaryHeader() const
|
---|
| 385 |
|
---|
| 386 | \return the keywords of primary header in a DVList
|
---|
| 387 |
|
---|
| 388 | */
|
---|
[1143] | 389 | DVList FitsInFile::DVListFromPrimaryHeader() const
|
---|
| 390 | {
|
---|
| 391 | int status;
|
---|
| 392 | DVList dvl;
|
---|
| 393 | KeywordsIntoDVList(fptr_, dvl, 1);
|
---|
| 394 | int hdutype = 0;
|
---|
| 395 | if (hdunum_ > 0) fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 396 | return dvl;
|
---|
| 397 | }
|
---|
[1136] | 398 |
|
---|
[1234] | 399 | void FitsInFile::getHeader()
|
---|
[971] | 400 | {
|
---|
[1234] | 401 | int status=0;
|
---|
| 402 | if (hdunum_ < 1) throw PException(" attempt to read hdunum < 1");
|
---|
| 403 | if (hdunum_ == 1)
|
---|
[839] | 404 | {
|
---|
[1234] | 405 | // presence of image ?
|
---|
| 406 | int naxis= 0;
|
---|
| 407 | fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 408 | if( status ) printerror( status );
|
---|
| 409 | if (naxis > 0 ) // there is an image
|
---|
| 410 | {
|
---|
| 411 | hdutype_ = IMAGE_HDU;
|
---|
| 412 | GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
|
---|
| 413 | nbData_ = 1;
|
---|
| 414 | int k;
|
---|
| 415 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
| 416 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
| 417 | }
|
---|
| 418 | else
|
---|
| 419 | {
|
---|
[1246] | 420 | // the object to be read is probably a bin or ascii table
|
---|
| 421 | // (on an extension)
|
---|
| 422 | hdunum_++;
|
---|
| 423 | getHeader();
|
---|
| 424 |
|
---|
| 425 | // throw PException(" first header : no image, probably error in hdunum");
|
---|
[1234] | 426 | }
|
---|
[839] | 427 | }
|
---|
[1234] | 428 | else
|
---|
[839] | 429 | {
|
---|
[1234] | 430 | int hdutype;
|
---|
| 431 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 432 | if( status ) printerror( status,":FitsInFile::getHeader : erreur movabs");
|
---|
| 433 | hdutype_= hdutype;
|
---|
| 434 | if(hdutype_ == IMAGE_HDU)
|
---|
| 435 | {
|
---|
| 436 | GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
|
---|
| 437 | nbData_ = 1;
|
---|
| 438 | int k;
|
---|
| 439 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
| 440 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
| 441 | }
|
---|
| 442 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 443 | {
|
---|
| 444 | GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
|
---|
| 445 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
| 446 | }
|
---|
[839] | 447 | }
|
---|
[971] | 448 | }
|
---|
[839] | 449 |
|
---|
[1136] | 450 |
|
---|
[1234] | 451 | void FitsInFile::moveToFollowingHeader()
|
---|
| 452 | {
|
---|
| 453 | int status = 0;
|
---|
| 454 | hdunum_++;
|
---|
| 455 | getHeader();
|
---|
| 456 | }
|
---|
[1218] | 457 |
|
---|
| 458 |
|
---|
| 459 |
|
---|
[1234] | 460 |
|
---|
| 461 |
|
---|
[1218] | 462 | /*! \fn int SOPHYA::FitsInFile::NbColsFromFits() const
|
---|
| 463 | \return number of columns (return 1 if IMAGE)
|
---|
| 464 | */
|
---|
[1136] | 465 | int FitsInFile::NbColsFromFits() const
|
---|
[839] | 466 | {
|
---|
[1136] | 467 | if(hdutype_ == BINARY_TBL) return nbcols_;
|
---|
[971] | 468 | else
|
---|
[1136] | 469 | if(hdutype_ == ASCII_TBL || hdutype_ == IMAGE_HDU) return 1;
|
---|
[839] | 470 | else
|
---|
| 471 | {
|
---|
[1136] | 472 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 473 | throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
|
---|
[839] | 474 | }
|
---|
| 475 | }
|
---|
| 476 |
|
---|
[1218] | 477 | /*! \fn int SOPHYA::FitsInFile::NentriesFromFits(int nocol) const
|
---|
| 478 | \return number of data in the current IMAGE extension on FITS file, or number
|
---|
| 479 | of data of column number 'nocol' of the current BINTABLE extension
|
---|
| 480 | */
|
---|
[1136] | 481 | int FitsInFile::NentriesFromFits(int nocol) const
|
---|
[839] | 482 | {
|
---|
[1136] | 483 | if(hdutype_ == BINARY_TBL ) return nrows_*repeat_[nocol];
|
---|
| 484 | else
|
---|
| 485 | if(hdutype_ == ASCII_TBL) return nrows_;
|
---|
| 486 | else
|
---|
| 487 | if(hdutype_ == IMAGE_HDU) return nbData_;
|
---|
| 488 | else
|
---|
[839] | 489 | {
|
---|
[1136] | 490 | cout << "hdutype= " << hdutype_ << endl;
|
---|
| 491 | throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
|
---|
[839] | 492 | }
|
---|
| 493 | }
|
---|
| 494 |
|
---|
[1218] | 495 | /*! \fn char SOPHYA::FitsInFile::ColTypeFromFits(int nocol) const
|
---|
| 496 |
|
---|
| 497 | return a character denoting data type of column number 'nocol' in a BINTABLE :
|
---|
| 498 |
|
---|
| 499 | D : double
|
---|
| 500 |
|
---|
| 501 | E : float
|
---|
| 502 |
|
---|
| 503 | I : integer
|
---|
| 504 |
|
---|
| 505 | S : character string
|
---|
| 506 |
|
---|
| 507 | */
|
---|
| 508 |
|
---|
[1136] | 509 | char FitsInFile::ColTypeFromFits(int nocol) const
|
---|
[839] | 510 | {
|
---|
[1136] | 511 | if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
|
---|
[839] | 512 | {
|
---|
[1136] | 513 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 514 | }
|
---|
[1136] | 515 | return types_[nocol];
|
---|
[839] | 516 | }
|
---|
[1218] | 517 |
|
---|
| 518 |
|
---|
| 519 | /*! \fn string SOPHYA::FitsInFile::ColNameFromFits(int nocol) const
|
---|
| 520 |
|
---|
| 521 | \return name of the column number 'nocol' of the current BINTABLE extension
|
---|
| 522 | */
|
---|
| 523 |
|
---|
[1136] | 524 | string FitsInFile::ColNameFromFits(int nocol) const
|
---|
[839] | 525 | {
|
---|
[1136] | 526 | if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
|
---|
[1045] | 527 | {
|
---|
[1136] | 528 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
[1045] | 529 | }
|
---|
[1136] | 530 | return noms_[nocol];
|
---|
[839] | 531 | }
|
---|
| 532 |
|
---|
[1218] | 533 | /*! \fn int DSOPHYA::FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
| 534 |
|
---|
| 535 | \return number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension
|
---|
| 536 | */
|
---|
| 537 |
|
---|
[1136] | 538 | int FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
[839] | 539 | {
|
---|
[1136] | 540 | if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
|
---|
| 541 | {
|
---|
| 542 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
| 543 | }
|
---|
| 544 | int index=-1;
|
---|
| 545 | int k;
|
---|
| 546 | for (k=0; k<=nocol; k++)
|
---|
| 547 | {
|
---|
| 548 | if (types_[k] == 'S') index++;
|
---|
| 549 | }
|
---|
| 550 | return taille_des_chaines_[index];
|
---|
[839] | 551 | }
|
---|
[1218] | 552 |
|
---|
| 553 |
|
---|
| 554 |
|
---|
| 555 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
| 556 |
|
---|
| 557 | Get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
| 558 | */
|
---|
| 559 |
|
---|
[1193] | 560 | void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
[839] | 561 | {
|
---|
| 562 | int status= 0;
|
---|
[1136] | 563 | int anull;
|
---|
| 564 | double dnull= 0.;
|
---|
| 565 | float fnull= 0.;
|
---|
| 566 | int inull= 0;
|
---|
| 567 | char* cnull= "";
|
---|
| 568 | int dcount = 0.;
|
---|
| 569 | int fcount = 0.;
|
---|
| 570 | int icount = 0;
|
---|
| 571 | int ccount =0;
|
---|
| 572 | int ncol;
|
---|
| 573 | long nels=1;
|
---|
| 574 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
[861] | 575 | {
|
---|
[1136] | 576 | switch (types_[ncol])
|
---|
| 577 | {
|
---|
| 578 | case 'D' :
|
---|
| 579 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
|
---|
| 580 | break;
|
---|
| 581 | case 'E' :
|
---|
| 582 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
|
---|
| 583 | break;
|
---|
| 584 | case 'I' :
|
---|
| 585 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
|
---|
| 586 | &anull,&status);
|
---|
| 587 | break;
|
---|
| 588 | case 'S' :
|
---|
| 589 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
|
---|
| 590 | break;
|
---|
| 591 | }
|
---|
| 592 | if (status)
|
---|
| 593 | {
|
---|
| 594 | ResetStatus(status);
|
---|
| 595 | break;
|
---|
| 596 | }
|
---|
[861] | 597 | }
|
---|
[903] | 598 | }
|
---|
[839] | 599 |
|
---|
[1218] | 600 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
| 601 | Get the NoLine-th 'line' from the current BINTABLE extension on FITS file,
|
---|
| 602 | */
|
---|
[1193] | 603 | void FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
| 604 | {
|
---|
| 605 | int status= 0;
|
---|
| 606 | int anull;
|
---|
| 607 | double dnull= 0.;
|
---|
| 608 | float fnull= 0.;
|
---|
| 609 | int inull= 0;
|
---|
| 610 | char* cnull= "";
|
---|
| 611 | int dcount = 0.;
|
---|
| 612 | int fcount = 0.;
|
---|
| 613 | int icount = 0;
|
---|
| 614 | int ccount =0;
|
---|
| 615 | int ncol;
|
---|
| 616 | long nels=1;
|
---|
| 617 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
| 618 | {
|
---|
| 619 | switch (types_[ncol])
|
---|
| 620 | {
|
---|
| 621 | case 'D' :
|
---|
| 622 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anull,&status);
|
---|
| 623 | break;
|
---|
| 624 | case 'E' :
|
---|
| 625 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anull,&status);
|
---|
| 626 | break;
|
---|
| 627 | case 'I' :
|
---|
| 628 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++],
|
---|
| 629 | &anull,&status);
|
---|
| 630 | break;
|
---|
| 631 | case 'S' :
|
---|
| 632 | char* chaine = new char[taille_des_chaines_[ccount]];
|
---|
| 633 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anull,&status);
|
---|
| 634 | ligne.cdata_[ccount++] = string(chaine);
|
---|
| 635 | break;
|
---|
| 636 | }
|
---|
| 637 | if (status)
|
---|
| 638 | {
|
---|
| 639 | ResetStatus(status);
|
---|
| 640 | break;
|
---|
| 641 | }
|
---|
| 642 | }
|
---|
| 643 | }
|
---|
| 644 |
|
---|
[1218] | 645 | /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
| 646 |
|
---|
| 647 | Get the NoLine-th float 'line' from the current BINTABLE extension on FITS file,
|
---|
| 648 | */
|
---|
[1136] | 649 | void FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
[903] | 650 | {
|
---|
[1136] | 651 | int status= 0;
|
---|
| 652 | int anull;
|
---|
| 653 | float fnull= 0.;
|
---|
| 654 | long nels=1;
|
---|
| 655 | int ncol;
|
---|
| 656 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
[861] | 657 | {
|
---|
[1136] | 658 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
|
---|
| 659 | if (status)
|
---|
[903] | 660 | {
|
---|
[1136] | 661 | ResetStatus(status);
|
---|
| 662 | break;
|
---|
[903] | 663 | }
|
---|
[1136] | 664 | }
|
---|
| 665 | }
|
---|
[839] | 666 |
|
---|
[903] | 667 |
|
---|
[1218] | 668 | /*! \fn void SPOPHYA::FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
|
---|
| 669 |
|
---|
| 670 | fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol'
|
---|
| 671 |
|
---|
| 672 | \param <nentries> number of data to be read
|
---|
| 673 | */
|
---|
[1136] | 674 | void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
|
---|
[839] | 675 | {
|
---|
| 676 | int status= 0;
|
---|
| 677 | int DTYPE;
|
---|
| 678 | long repeat,width;
|
---|
| 679 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 680 | if( DTYPE != TDOUBLE)
|
---|
| 681 | {
|
---|
[1045] | 682 | if (DTYPE == TFLOAT) cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
|
---|
| 683 | else
|
---|
| 684 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
|
---|
[839] | 685 | }
|
---|
| 686 | long nels=nentries;
|
---|
[971] | 687 | int anull;
|
---|
[839] | 688 | // no checking for undefined pixels
|
---|
[971] | 689 | double dnull= 0.;
|
---|
| 690 | // fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
|
---|
| 691 | // if (status != 0)
|
---|
| 692 | // {
|
---|
| 693 | // dnull = -1.6375e30; // default value
|
---|
| 694 | // status = 0;
|
---|
| 695 | // }
|
---|
| 696 | if (nentries != nrows_*repeat)
|
---|
| 697 | {
|
---|
| 698 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 699 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 700 | }
|
---|
[839] | 701 | fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
|
---|
| 702 | &anull,&status);
|
---|
| 703 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
[971] | 704 |
|
---|
[839] | 705 | }
|
---|
| 706 |
|
---|
[1218] | 707 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
|
---|
| 708 |
|
---|
| 709 | same as previous method with float data
|
---|
| 710 | */
|
---|
[1136] | 711 | void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
|
---|
[839] | 712 | {
|
---|
| 713 | int status= 0;
|
---|
| 714 | int DTYPE;
|
---|
| 715 | long repeat,width;
|
---|
| 716 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 717 | if( DTYPE != TFLOAT)
|
---|
| 718 | {
|
---|
[1045] | 719 | if (DTYPE == TDOUBLE) cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
|
---|
| 720 | else
|
---|
| 721 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
|
---|
[839] | 722 | }
|
---|
| 723 | long nels=nentries;
|
---|
[971] | 724 | int anull;
|
---|
[839] | 725 | // no checking for undefined pixels
|
---|
| 726 | float fnull= 0.;
|
---|
[971] | 727 | // fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
|
---|
| 728 | // if (status != 0)
|
---|
| 729 | // {
|
---|
| 730 | // fnull = -1.6375e30; // default value
|
---|
| 731 | // status = 0;
|
---|
| 732 | // }
|
---|
| 733 | if (nentries != nrows_*repeat)
|
---|
| 734 | {
|
---|
| 735 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 736 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 737 | }
|
---|
[839] | 738 | fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
|
---|
| 739 | &anull,&status);
|
---|
| 740 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 741 | }
|
---|
[1136] | 742 |
|
---|
[1218] | 743 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
|
---|
| 744 |
|
---|
| 745 | same as previous method with int data
|
---|
| 746 | */
|
---|
| 747 |
|
---|
[1136] | 748 | void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
|
---|
[839] | 749 | {
|
---|
| 750 | int status= 0;
|
---|
| 751 | int DTYPE;
|
---|
| 752 | long repeat,width;
|
---|
| 753 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 754 | if( DTYPE != TLONG && DTYPE != TINT && DTYPE != TSHORT )
|
---|
| 755 | {
|
---|
| 756 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
|
---|
| 757 | }
|
---|
| 758 | long nels=nentries;
|
---|
| 759 | // no checking for undefined pixels
|
---|
| 760 | int anull;
|
---|
| 761 | int inull= 0;
|
---|
[971] | 762 | // fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
|
---|
| 763 | // if (status != 0)
|
---|
| 764 | // {
|
---|
| 765 | // inull = -999999; // default value
|
---|
| 766 | // status = 0;
|
---|
| 767 | // }
|
---|
| 768 | if (nentries != nrows_*repeat)
|
---|
| 769 | {
|
---|
| 770 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 771 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 772 | }
|
---|
[839] | 773 | fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
|
---|
| 774 | &anull,&status);
|
---|
| 775 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 776 | }
|
---|
[1136] | 777 |
|
---|
[1218] | 778 | /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
| 779 |
|
---|
| 780 | same as previous method with char* data
|
---|
| 781 | */
|
---|
| 782 |
|
---|
[1136] | 783 | void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
[839] | 784 | {
|
---|
| 785 | int status= 0;
|
---|
| 786 | int DTYPE;
|
---|
| 787 | long repeat,width;
|
---|
| 788 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 789 | if( DTYPE != TSTRING )
|
---|
| 790 | {
|
---|
| 791 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
|
---|
| 792 | }
|
---|
| 793 | long nels=nentries;
|
---|
| 794 | // no checking for undefined pixels
|
---|
| 795 | int anull;
|
---|
[971] | 796 | char* cnull= "";
|
---|
| 797 | if (nentries != nrows_*repeat/width)
|
---|
| 798 | {
|
---|
| 799 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat/width << endl;
|
---|
| 800 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 801 | }
|
---|
[839] | 802 | long frow=1;
|
---|
| 803 | long felem=1;
|
---|
| 804 | fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
|
---|
| 805 | &anull,&status);
|
---|
| 806 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 807 | }
|
---|
[1045] | 808 |
|
---|
[1218] | 809 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(double* map, int nentries) const
|
---|
| 810 | fill the array 'map' with double data from the current extension on FITS file.
|
---|
| 811 | If the extension is BINTABLE, the first column is provided.
|
---|
| 812 |
|
---|
| 813 | \param <nentries> number of data to be read
|
---|
| 814 | */
|
---|
[1136] | 815 | void FitsInFile::GetSingleColumn(double* map, int nentries) const
|
---|
| 816 | {
|
---|
| 817 | int status = 0;
|
---|
| 818 | if(hdutype_ == IMAGE_HDU)
|
---|
[1045] | 819 | {
|
---|
[1136] | 820 |
|
---|
| 821 | if(bitpix_ != DOUBLE_IMG)
|
---|
[1047] | 822 | {
|
---|
[1136] | 823 | cout << " The data type on fits file is not double...";
|
---|
| 824 | cout << " Conversion to double achieved by cfitsio lib" << endl;
|
---|
[1047] | 825 | }
|
---|
[1136] | 826 |
|
---|
| 827 | // no checking for undefined pixels
|
---|
| 828 | int anull;
|
---|
| 829 | double dnull= 0.;
|
---|
| 830 |
|
---|
| 831 | long nels= nentries;
|
---|
| 832 | fits_read_img(fptr_,TDOUBLE,1,nels,&dnull,map,&anull,&status);
|
---|
| 833 | if( status ) printerror( status );
|
---|
[1045] | 834 | }
|
---|
[1136] | 835 | else
|
---|
| 836 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 837 | {
|
---|
| 838 | GetBinTabFCol(map,nentries, 0);
|
---|
| 839 | }
|
---|
| 840 | else
|
---|
| 841 | {
|
---|
| 842 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 843 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
| 844 | }
|
---|
[1045] | 845 | }
|
---|
| 846 |
|
---|
[1218] | 847 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const
|
---|
| 848 | same as above with float data
|
---|
| 849 | */
|
---|
[1136] | 850 | void FitsInFile::GetSingleColumn(float* map, int nentries) const
|
---|
[1045] | 851 | {
|
---|
[1136] | 852 | int status = 0;
|
---|
| 853 | if(hdutype_ == IMAGE_HDU)
|
---|
[1045] | 854 | {
|
---|
[1136] | 855 | if(bitpix_ != FLOAT_IMG)
|
---|
[1047] | 856 | {
|
---|
[1136] | 857 | cout << " The data type on fits file is not float ";
|
---|
| 858 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
[1047] | 859 | }
|
---|
[1136] | 860 | // no checking for undefined pixels
|
---|
| 861 | int anull;
|
---|
| 862 | float fnull= 0.;
|
---|
| 863 |
|
---|
| 864 | long nels= nentries;
|
---|
| 865 | fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
|
---|
| 866 | if( status ) printerror( status );
|
---|
[1045] | 867 | }
|
---|
[839] | 868 | else
|
---|
[1136] | 869 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 870 | {
|
---|
| 871 | GetBinTabFCol(map,nentries, 0);
|
---|
| 872 | }
|
---|
[839] | 873 | else
|
---|
| 874 | {
|
---|
[1136] | 875 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 876 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
[839] | 877 | }
|
---|
| 878 | }
|
---|
| 879 |
|
---|
[1218] | 880 | /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const
|
---|
| 881 | same as above with int data
|
---|
| 882 | */
|
---|
[1136] | 883 | void FitsInFile::GetSingleColumn( int* map, int nentries) const
|
---|
[839] | 884 | {
|
---|
[1136] | 885 | int status = 0;
|
---|
| 886 | if(hdutype_ == IMAGE_HDU)
|
---|
[839] | 887 | {
|
---|
[1136] | 888 | if(bitpix_ != LONG_IMG)
|
---|
| 889 | {
|
---|
| 890 | cout << " The data type on fits file is not int ";
|
---|
| 891 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
| 892 | }
|
---|
| 893 | // no checking for undefined pixels
|
---|
| 894 | int anull;
|
---|
| 895 | float fnull= 0.;
|
---|
| 896 |
|
---|
| 897 | long nels= nentries;
|
---|
| 898 | fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
|
---|
| 899 | if( status ) printerror( status );
|
---|
[839] | 900 | }
|
---|
| 901 | else
|
---|
[1136] | 902 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 903 | {
|
---|
| 904 | GetBinTabFCol(map,nentries, 0);
|
---|
| 905 | }
|
---|
[839] | 906 | else
|
---|
[1136] | 907 | {
|
---|
| 908 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 909 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
| 910 | }
|
---|
[839] | 911 | }
|
---|
| 912 |
|
---|
[1136] | 913 | void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
[903] | 914 | vector<int>& repeat,
|
---|
| 915 | vector<string>& noms,
|
---|
| 916 | vector<char>& types,
|
---|
| 917 | vector<int>& taille_des_chaines)
|
---|
[839] | 918 | {
|
---|
| 919 | int status= 0;
|
---|
[903] | 920 | int hdunum=0;
|
---|
| 921 | int hdutype=0;
|
---|
| 922 | fits_get_hdu_num(fileptr,&hdunum);
|
---|
| 923 | fits_get_hdu_type(fileptr, &hdutype, &status);
|
---|
| 924 |
|
---|
| 925 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
[839] | 926 | {
|
---|
[903] | 927 | throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 928 | }
|
---|
[903] | 929 | if(hdutype == ASCII_TBL)
|
---|
| 930 | cout << " Reading a FITS ascii table in HDU : " << hdunum << endl;
|
---|
| 931 | if(hdutype == BINARY_TBL)
|
---|
| 932 | cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
|
---|
[839] | 933 |
|
---|
| 934 | // get the number of columns
|
---|
[903] | 935 | fits_get_num_cols(fileptr, &nbcols,&status);
|
---|
[839] | 936 | if( status ) printerror( status );
|
---|
| 937 |
|
---|
| 938 | // get the number of rows
|
---|
| 939 | long naxis2= 0;
|
---|
[903] | 940 | fits_get_num_rows(fileptr,&naxis2,&status);
|
---|
[839] | 941 | if( status ) printerror( status );
|
---|
[903] | 942 | nrows = (int)naxis2;
|
---|
[839] | 943 |
|
---|
| 944 | // get the datatype, names and the repeat count
|
---|
[903] | 945 | noms.clear();
|
---|
| 946 | noms.reserve(nbcols);
|
---|
| 947 | types.clear();
|
---|
| 948 | types.reserve(nbcols);
|
---|
| 949 | repeat.clear();
|
---|
| 950 | repeat.reserve(nbcols);
|
---|
| 951 | taille_des_chaines.clear();
|
---|
[839] | 952 | char **ttype = new char*[nbcols];
|
---|
[923] | 953 | int ii;
|
---|
[1175] | 954 | //
|
---|
| 955 | //
|
---|
[923] | 956 | for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
|
---|
[839] | 957 | int nfound;
|
---|
[903] | 958 | fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
|
---|
[839] | 959 | if( status ) printerror( status,"erreur lecture des noms de colonne");
|
---|
| 960 | int rept=0;
|
---|
[923] | 961 | for(ii = 0; ii < nbcols; ii++)
|
---|
[839] | 962 | {
|
---|
| 963 | int DTYPE;
|
---|
| 964 | long width;
|
---|
[903] | 965 | long repete = 0;
|
---|
| 966 | fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
|
---|
[839] | 967 | if( status ) printerror( status,"erreur lecture type de colonne");
|
---|
[903] | 968 | rept = repete;
|
---|
| 969 | noms.push_back(string(ttype[ii]));
|
---|
[839] | 970 | switch (DTYPE)
|
---|
| 971 | {
|
---|
| 972 | case TDOUBLE :
|
---|
[903] | 973 | types.push_back('D');
|
---|
[839] | 974 | break;
|
---|
| 975 | case TFLOAT :
|
---|
[903] | 976 | types.push_back('E');
|
---|
[839] | 977 | break;
|
---|
| 978 | case TLONG :
|
---|
[903] | 979 | types.push_back('I');
|
---|
[839] | 980 | break;
|
---|
| 981 | case TINT :
|
---|
[903] | 982 | types.push_back('I');
|
---|
[839] | 983 | break;
|
---|
| 984 | case TSHORT :
|
---|
[903] | 985 | types.push_back('I');
|
---|
[839] | 986 | break;
|
---|
| 987 | case TSTRING :
|
---|
[903] | 988 | types.push_back('S');
|
---|
| 989 | taille_des_chaines.push_back(width);
|
---|
[839] | 990 | rept/=width;
|
---|
| 991 | break;
|
---|
| 992 | default :
|
---|
| 993 | cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
|
---|
| 994 | throw IOExc("FitsFile:: unknown type of field");
|
---|
| 995 | }
|
---|
[903] | 996 | repeat.push_back(rept);
|
---|
[1136] | 997 | }
|
---|
| 998 | for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
|
---|
| 999 | delete [] ttype;
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
| 1002 | void FitsInFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
|
---|
| 1003 | {
|
---|
| 1004 | int status = 0;
|
---|
| 1005 | int hdutype;
|
---|
| 1006 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
| 1007 | if( status ) printerror( status,":KeywordsIntoDVList : erreur movabs");
|
---|
| 1008 | // get number of keywords
|
---|
| 1009 | int nkeys,keypos;
|
---|
| 1010 | fits_get_hdrpos(fileptr,&nkeys,&keypos,&status);
|
---|
| 1011 | if( status ) printerror( status );
|
---|
| 1012 |
|
---|
| 1013 | // put keywords in a DVList object
|
---|
| 1014 | char keyname[LEN_KEYWORD]= "";
|
---|
| 1015 | char strval[FLEN_VALUE]= "";
|
---|
| 1016 | char dtype;
|
---|
| 1017 | char card[FLEN_CARD];
|
---|
| 1018 | char *comkey = "COMMENT";
|
---|
[1143] | 1019 | char comment[FLEN_COMMENT];
|
---|
[1136] | 1020 |
|
---|
| 1021 | // shift with the number of mandatory keywords
|
---|
[1143] | 1022 | // int num= 8;
|
---|
| 1023 | int num= 0;
|
---|
| 1024 | // primary header
|
---|
| 1025 | if (hdunum == 1)
|
---|
| 1026 | {
|
---|
| 1027 | // read NAXIS
|
---|
| 1028 | int naxis=0;
|
---|
| 1029 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 1030 | // number of mandatory keywords
|
---|
| 1031 | num = naxis+3;
|
---|
| 1032 | }
|
---|
| 1033 | // extensions
|
---|
| 1034 | else
|
---|
| 1035 | {
|
---|
| 1036 | if (hdutype == IMAGE_HDU)
|
---|
| 1037 | {
|
---|
| 1038 | // read NAXIS
|
---|
| 1039 | int naxis=0;
|
---|
| 1040 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 1041 | // number of mandatory keywords
|
---|
| 1042 | num = naxis+5;
|
---|
| 1043 | }
|
---|
| 1044 | else
|
---|
| 1045 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 1046 | {
|
---|
| 1047 | // number of mandatory keywords
|
---|
| 1048 | num = 8;
|
---|
| 1049 | }
|
---|
| 1050 | }
|
---|
[1136] | 1051 | int j;
|
---|
| 1052 | for(j = num+1; j <= nkeys; j++)
|
---|
| 1053 | {
|
---|
| 1054 | fits_read_keyn(fileptr,j,card,strval,NULL,&status);
|
---|
| 1055 | if(status) printerror(status);
|
---|
| 1056 |
|
---|
| 1057 | strncpy(keyname,card,LEN_KEYWORD-1);
|
---|
| 1058 | if(strncmp(keyname,comkey,LEN_KEYWORD-1) != 0 && strlen(keyname) != 0
|
---|
| 1059 | && strlen(strval) != 0)
|
---|
| 1060 | {
|
---|
| 1061 | fits_get_keytype(strval,&dtype,&status);
|
---|
| 1062 | if(status) printerror(status);
|
---|
| 1063 |
|
---|
| 1064 | strip(keyname, 'B',' ');
|
---|
| 1065 | strip(strval, 'B',' ');
|
---|
| 1066 | strip(strval, 'B','\'');
|
---|
| 1067 |
|
---|
| 1068 | switch( dtype )
|
---|
| 1069 | {
|
---|
| 1070 | case 'C':
|
---|
[1143] | 1071 | fits_read_key(fileptr,TSTRING,keyname,strval,comment,&status);
|
---|
| 1072 | dvl[keyname]= strval;
|
---|
| 1073 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1074 | break;
|
---|
| 1075 | case 'I':
|
---|
| 1076 | int ival;
|
---|
[1143] | 1077 | fits_read_key(fileptr,TINT,keyname,&ival,comment,&status);
|
---|
[1136] | 1078 | dvl[keyname]= (int_4) ival; // Portage mac DY
|
---|
[1143] | 1079 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1080 | break;
|
---|
| 1081 | case 'L':
|
---|
| 1082 | int ilog;
|
---|
[1143] | 1083 | fits_read_key(fileptr,TLOGICAL,keyname,&ilog,comment,&status);
|
---|
[1136] | 1084 | dvl[keyname]= (int_4) ilog;
|
---|
[1143] | 1085 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1086 | break;
|
---|
| 1087 | case 'F':
|
---|
| 1088 | double dval;
|
---|
[1143] | 1089 | fits_read_key(fileptr,TDOUBLE,keyname,&dval,comment,&status);
|
---|
[1136] | 1090 | dvl[keyname]= dval;
|
---|
[1143] | 1091 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 1092 | break;
|
---|
| 1093 | }
|
---|
| 1094 |
|
---|
| 1095 | }
|
---|
[839] | 1096 | }
|
---|
[1136] | 1097 | // dvl_.Print();
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
[1218] | 1100 |
|
---|
| 1101 | /*!
|
---|
| 1102 | \class SOPHYA::FitsOutFile
|
---|
| 1103 | Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib)
|
---|
| 1104 | */
|
---|
| 1105 |
|
---|
[1136] | 1106 | FitsOutFile::FitsOutFile()
|
---|
| 1107 | {
|
---|
[1193] | 1108 | InitNull();
|
---|
[903] | 1109 | }
|
---|
[839] | 1110 |
|
---|
[1218] | 1111 | /*! \fn SOPHYA::FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
|
---|
| 1112 |
|
---|
| 1113 | \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)
|
---|
| 1114 |
|
---|
| 1115 | */
|
---|
[1231] | 1116 |
|
---|
| 1117 | FitsOutFile::FitsOutFile(string const & flnm, WriteMode wrm)
|
---|
[1136] | 1118 | {
|
---|
[1231] | 1119 | InitNull();
|
---|
| 1120 | openoutputfitsfile(flnm.c_str(), wrm);
|
---|
| 1121 | }
|
---|
[839] | 1122 |
|
---|
[1231] | 1123 | FitsOutFile::FitsOutFile(const char * flnm, WriteMode wrm)
|
---|
| 1124 | {
|
---|
[1136] | 1125 | InitNull();
|
---|
[1231] | 1126 | openoutputfitsfile(flnm, wrm);
|
---|
| 1127 | }
|
---|
| 1128 |
|
---|
| 1129 | void FitsOutFile::openoutputfitsfile(const char * flnm, WriteMode wrm)
|
---|
| 1130 | {
|
---|
[1136] | 1131 | int status = 0;
|
---|
[839] | 1132 |
|
---|
[1136] | 1133 | // create new FITS file
|
---|
[1183] | 1134 | fits_create_file(&fptr_,flnm,&status);
|
---|
| 1135 | if( status )
|
---|
[1136] | 1136 | {
|
---|
[1193] | 1137 |
|
---|
| 1138 | switch (wrm)
|
---|
| 1139 | {
|
---|
[1183] | 1140 | // si on veut ecrire a la fin de ce fichier
|
---|
[1193] | 1141 | case append :
|
---|
[1183] | 1142 | status = 0;
|
---|
[1235] | 1143 | fits_clear_errmsg();
|
---|
[1183] | 1144 | fits_open_file(&fptr_,flnm,READWRITE,&status);
|
---|
| 1145 | if( status )
|
---|
| 1146 | {
|
---|
| 1147 | cout << " error opening file: " << flnm << endl;
|
---|
| 1148 | printerror(status, "failure opening a file supposed to exist");
|
---|
| 1149 | }
|
---|
| 1150 | else cout << " file " << flnm << " opened, new objects will be appended " << endl;
|
---|
| 1151 | fits_get_num_hdus(fptr_, &hdunum_, &status);
|
---|
| 1152 | int hdutype;
|
---|
| 1153 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1154 | if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
|
---|
[1193] | 1155 | break;
|
---|
| 1156 |
|
---|
| 1157 | case clear :
|
---|
[1183] | 1158 | {
|
---|
| 1159 | status = 0;
|
---|
[1235] | 1160 | fits_clear_errmsg();
|
---|
[1183] | 1161 | char* newname = new char[strlen(flnm)+1];
|
---|
| 1162 | //
|
---|
| 1163 | newname[0] = '!';
|
---|
| 1164 | newname[1] = '\0';
|
---|
| 1165 | strcat(newname, flnm);
|
---|
| 1166 | fits_create_file(&fptr_,newname,&status);
|
---|
[1193] | 1167 | delete [] newname;
|
---|
[1183] | 1168 | if (status)
|
---|
| 1169 | {
|
---|
| 1170 | cout << " error opening file: " << flnm << endl;
|
---|
| 1171 | printerror(status, "unable to open file, supposed to exist");
|
---|
| 1172 | }
|
---|
[1193] | 1173 | else cout << " WARNING : file " << flnm << " is overwritten " << endl;
|
---|
| 1174 | break;
|
---|
[1183] | 1175 | }
|
---|
[1193] | 1176 | case unknown :
|
---|
| 1177 | printerror(status, " file seems already to exist");
|
---|
| 1178 | break;
|
---|
[1183] | 1179 |
|
---|
[1193] | 1180 | }
|
---|
[1136] | 1181 | }
|
---|
| 1182 | }
|
---|
| 1183 |
|
---|
| 1184 |
|
---|
| 1185 |
|
---|
[1218] | 1186 | /*! \fn void SOPHYA::FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl)
|
---|
| 1187 |
|
---|
| 1188 | create an IMAGE header on FITS file.
|
---|
| 1189 | \param <type> type of data (see method ColTypeFromFits)
|
---|
| 1190 | \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS
|
---|
| 1191 | \param <naxisn> array containind sizes of the different dimensions
|
---|
| 1192 | */
|
---|
[1221] | 1193 | void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* ptr_dvl)
|
---|
[1136] | 1194 | {
|
---|
| 1195 | int status = 0;
|
---|
| 1196 | long naxis = nbdim;
|
---|
| 1197 | long* naxes = new long[nbdim];
|
---|
[1246] | 1198 | bool hdunfirst= (hdunum_ == 0);
|
---|
| 1199 | if (hdunfirst)
|
---|
[1136] | 1200 | {
|
---|
[1143] | 1201 | if (imageOnPrimary_ == false)
|
---|
| 1202 | {
|
---|
[1234] | 1203 | hdunum_ = 1;
|
---|
[1143] | 1204 | fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
|
---|
[1246] | 1205 | }
|
---|
[1136] | 1206 | }
|
---|
| 1207 | int k;
|
---|
| 1208 | for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
|
---|
| 1209 | if (type == 'D')
|
---|
| 1210 | fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
|
---|
| 1211 | else
|
---|
| 1212 | if (type == 'E')
|
---|
| 1213 | fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
|
---|
| 1214 | else
|
---|
| 1215 | if (type == 'I')
|
---|
| 1216 | fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
|
---|
| 1217 | else
|
---|
| 1218 | {
|
---|
| 1219 | cout << " type of data: " << type << endl;
|
---|
| 1220 | throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
|
---|
| 1221 | }
|
---|
[1246] | 1222 | // on ajoute eventuellement un dvlist prepare et la doc SOPHYA
|
---|
[1136] | 1223 | hdunum_++;
|
---|
[1246] | 1224 | if (hdunfirst)
|
---|
| 1225 | {
|
---|
| 1226 | addDVListOnPrimary();
|
---|
| 1227 | writeSignatureOnFits(1);
|
---|
| 1228 | }
|
---|
[1143] | 1229 |
|
---|
| 1230 | // write supplementary keywords
|
---|
| 1231 | // dvl.Print();
|
---|
[1221] | 1232 | if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
|
---|
[1143] | 1233 |
|
---|
[1136] | 1234 | delete [] naxes;
|
---|
| 1235 | if( status ) printerror( status, "erreur creation HDU IMAGE" );
|
---|
| 1236 |
|
---|
| 1237 | }
|
---|
[1218] | 1238 |
|
---|
| 1239 |
|
---|
| 1240 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, double* map) const
|
---|
| 1241 |
|
---|
| 1242 | write double data from array 'map'on an IMAGE extension
|
---|
| 1243 | \param <nbData> number of data to be written
|
---|
| 1244 | */
|
---|
[1209] | 1245 | void FitsOutFile::PutImageToFits(int nbData, double* map) const
|
---|
[1136] | 1246 | {
|
---|
| 1247 | int status = 0;
|
---|
| 1248 | long npix= nbData;
|
---|
| 1249 | fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
|
---|
[1209] | 1250 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1136] | 1251 | }
|
---|
| 1252 |
|
---|
[1218] | 1253 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, float* map) const
|
---|
| 1254 |
|
---|
| 1255 | same as previous method with float data
|
---|
| 1256 | */
|
---|
[1209] | 1257 | void FitsOutFile::PutImageToFits(int nbData, float* map) const
|
---|
[1136] | 1258 | {
|
---|
| 1259 | int status = 0;
|
---|
| 1260 | long npix= nbData;
|
---|
| 1261 | fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
|
---|
[1209] | 1262 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1136] | 1263 |
|
---|
| 1264 | }
|
---|
[1218] | 1265 |
|
---|
| 1266 | /*! \fn void SOPHYA::FitsOutFile::PutImageToFits( int nbData, int* map) const
|
---|
| 1267 |
|
---|
| 1268 | same as previous method with int data */
|
---|
[1209] | 1269 | void FitsOutFile::PutImageToFits( int nbData, int* map) const
|
---|
[1136] | 1270 | {
|
---|
| 1271 | int status = 0;
|
---|
| 1272 |
|
---|
| 1273 | long npix= nbData;
|
---|
| 1274 | fits_write_img(fptr_,TINT,1,npix,map,&status);
|
---|
[1209] | 1275 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1136] | 1276 | }
|
---|
| 1277 |
|
---|
| 1278 |
|
---|
| 1279 |
|
---|
[1218] | 1280 | /*! \fn void SOPHYA::FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
|
---|
| 1281 |
|
---|
| 1282 | create an BINTABLE header on FITS file.
|
---|
| 1283 | \param <fieldType> array conta
|
---|
| 1284 | ining characters denoting types of the different column (see method ColTypeFromFits)
|
---|
| 1285 | \param <Noms> array of the names of columns
|
---|
| 1286 | \param <nentries> number of data of each column
|
---|
| 1287 | \param <tfields> number of columns
|
---|
| 1288 | \param <dvl> a SOPHYA DVList containing keywords to be appended
|
---|
| 1289 | \param <extname> keyword EXTNAME for FITS file
|
---|
| 1290 | \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType'
|
---|
| 1291 | */
|
---|
[1221] | 1292 | void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList* ptr_dvl, string extname, vector<int> taille_des_chaines)
|
---|
[839] | 1293 | {
|
---|
[1209] | 1294 | int k;
|
---|
[839] | 1295 | int status = 0;
|
---|
| 1296 | long nrows;
|
---|
[1209] | 1297 | // verifications de coherence
|
---|
| 1298 |
|
---|
[1193] | 1299 | if (fieldType.length() != tfields)
|
---|
[839] | 1300 | {
|
---|
[1193] | 1301 | cout << " nombre de champs :" << tfields << "nombre de types: " << fieldType.length() << endl;
|
---|
[1136] | 1302 | throw ParmError("FitsFile:: fields and types don't match");
|
---|
[839] | 1303 |
|
---|
| 1304 | }
|
---|
[1209] | 1305 | if (tfields > Noms.size())
|
---|
| 1306 | {
|
---|
| 1307 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of column names not equal to total number of columns" << endl;
|
---|
| 1308 | for (k=0; k<(tfields-Noms.size()); k++) Noms.push_back( string(" "));
|
---|
| 1309 | }
|
---|
| 1310 |
|
---|
| 1311 | // nombre de variables "chaines de caracteres"
|
---|
| 1312 | int nbString = 0;
|
---|
| 1313 | for (k=0; k<tfields;k++) if (fieldType[k] == 'A') nbString++;
|
---|
| 1314 | // coherence de la longueur du vecteur des tailles
|
---|
| 1315 | if (nbString > taille_des_chaines.size())
|
---|
| 1316 | {
|
---|
| 1317 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of string lengths not equal to total number of columns" << endl;
|
---|
| 1318 | int strSz=0;
|
---|
| 1319 | for (k=0; k<taille_des_chaines.size(); k++) if ( taille_des_chaines[k] > strSz) strSz = taille_des_chaines[k];
|
---|
| 1320 | for (k=0; k<(nbString-taille_des_chaines.size()); k++) taille_des_chaines.push_back(strSz);
|
---|
| 1321 | }
|
---|
[839] | 1322 | char ** ttype= new char*[tfields];
|
---|
| 1323 | char ** tform= new char*[tfields];
|
---|
| 1324 | char largeur[FLEN_VALUE];
|
---|
| 1325 | int noColString=0;
|
---|
[971] | 1326 | for (k=0; k<tfields;k++)
|
---|
[839] | 1327 | {
|
---|
| 1328 | char format[FLEN_VALUE];
|
---|
| 1329 |
|
---|
| 1330 | if(nentries < 1024)
|
---|
| 1331 | {
|
---|
| 1332 | nrows= nentries;
|
---|
| 1333 | if (fieldType[k] == 'A')
|
---|
| 1334 | {
|
---|
| 1335 | sprintf(largeur,"%d",taille_des_chaines[noColString++]);
|
---|
| 1336 | strcpy(format,largeur);
|
---|
| 1337 | }
|
---|
| 1338 | else strcpy(format,"1");
|
---|
| 1339 | }
|
---|
| 1340 | else
|
---|
| 1341 | {
|
---|
| 1342 | nrows = nentries/1024;
|
---|
| 1343 | if(nentries%1024 != 0) nrows++;
|
---|
| 1344 | if (fieldType[k] == 'A')
|
---|
| 1345 | {
|
---|
[1136] | 1346 | char largaux[FLEN_VALUE];
|
---|
| 1347 | sprintf(largeur,"%d",taille_des_chaines[noColString]);
|
---|
| 1348 | sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
|
---|
| 1349 | noColString++;
|
---|
| 1350 | strcpy(format, largaux);
|
---|
[839] | 1351 | }
|
---|
| 1352 | else strcpy(format,"1024");
|
---|
| 1353 | }
|
---|
| 1354 | strncat(format,&fieldType[k],1);
|
---|
| 1355 | if (fieldType[k] == 'A')
|
---|
| 1356 | {
|
---|
| 1357 | strcat(format,largeur);
|
---|
| 1358 | }
|
---|
[1193] | 1359 | ttype[k] = const_cast<char*>(Noms[k].c_str());
|
---|
[839] | 1360 | tform[k]= new char[FLEN_VALUE];
|
---|
| 1361 | strcpy(tform[k],format);
|
---|
| 1362 | }
|
---|
[1193] | 1363 | char* extn = const_cast<char*>(extname.c_str());
|
---|
[839] | 1364 |
|
---|
| 1365 | // create a new empty binary table onto the FITS file
|
---|
| 1366 | // physical units if they exist, are defined in the DVList object
|
---|
| 1367 | // so the NULL pointer is given for the tunit parameters.
|
---|
| 1368 | nrows=0;
|
---|
| 1369 | fits_create_tbl(fptr_,BINARY_TBL,nrows,tfields,ttype,tform,
|
---|
| 1370 | NULL,extn,&status);
|
---|
| 1371 | if( status ) printerror( status );
|
---|
[1246] | 1372 | // on ajoute eventuellement un dvlist prepare
|
---|
| 1373 | if ( hdunum_ == 0 )
|
---|
| 1374 | {
|
---|
| 1375 | hdunum_ = 2;
|
---|
| 1376 | addDVListOnPrimary();
|
---|
| 1377 | writeSignatureOnFits(1);
|
---|
| 1378 | }
|
---|
[1026] | 1379 | else hdunum_++;
|
---|
[971] | 1380 | int ii;
|
---|
| 1381 | for(ii = 0; ii < tfields; ii++)
|
---|
[839] | 1382 | {
|
---|
| 1383 | delete [] tform[ii];
|
---|
| 1384 | }
|
---|
| 1385 | delete [] ttype;
|
---|
| 1386 | delete [] tform;
|
---|
| 1387 | //
|
---|
| 1388 | // write supplementary keywords
|
---|
[1221] | 1389 | if (ptr_dvl != NULL) addKeywordsOfDVList(*ptr_dvl);
|
---|
[839] | 1390 | }
|
---|
| 1391 |
|
---|
[1218] | 1392 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
|
---|
| 1393 |
|
---|
| 1394 | write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension.
|
---|
| 1395 | \param <nentries> number of data to be written
|
---|
| 1396 | */
|
---|
[1209] | 1397 | void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
|
---|
[839] | 1398 | {
|
---|
| 1399 | int status = 0;
|
---|
[971] | 1400 | int hdutype;
|
---|
[839] | 1401 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1402 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1403 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
[867] | 1404 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1405 | {
|
---|
| 1406 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1407 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[867] | 1408 | }
|
---|
[839] | 1409 | int code;
|
---|
| 1410 | long repeat, width;
|
---|
| 1411 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1412 | if( code != TDOUBLE)
|
---|
| 1413 | {
|
---|
[1209] | 1414 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;
|
---|
[839] | 1415 | }
|
---|
| 1416 | fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1417 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1418 | }
|
---|
[1218] | 1419 |
|
---|
| 1420 |
|
---|
| 1421 |
|
---|
| 1422 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
|
---|
| 1423 |
|
---|
| 1424 | same as previous method with float data
|
---|
| 1425 | */
|
---|
[1209] | 1426 | void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
|
---|
[839] | 1427 | {
|
---|
| 1428 | int status = 0;
|
---|
| 1429 | int hdutype;
|
---|
| 1430 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1431 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1432 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1433 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1434 | {
|
---|
| 1435 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1436 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1437 | }
|
---|
| 1438 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1439 | {
|
---|
[1209] | 1440 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1441 | }
|
---|
| 1442 | int code;
|
---|
| 1443 | long repeat, width;
|
---|
| 1444 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1445 | if( code != TFLOAT)
|
---|
| 1446 | {
|
---|
[1209] | 1447 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;
|
---|
[839] | 1448 | }
|
---|
| 1449 | fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1450 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1451 | }
|
---|
[1218] | 1452 |
|
---|
| 1453 |
|
---|
| 1454 | /*! \fn void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
|
---|
| 1455 |
|
---|
| 1456 | same as previous method with int data
|
---|
| 1457 | */
|
---|
[1209] | 1458 | void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
|
---|
[839] | 1459 | {
|
---|
| 1460 | int status = 0;
|
---|
| 1461 | int hdutype;
|
---|
| 1462 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1463 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1464 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1465 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1466 | {
|
---|
| 1467 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1468 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1469 | }
|
---|
| 1470 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1471 | {
|
---|
[1209] | 1472 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1473 | }
|
---|
| 1474 | int code;
|
---|
| 1475 | long repeat, width;
|
---|
| 1476 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1477 | if( code != TLONG && code != TINT && code != TSHORT )
|
---|
| 1478 | {
|
---|
[1209] | 1479 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;
|
---|
[839] | 1480 | }
|
---|
| 1481 | fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
[971] | 1482 | if( status ) printerror( status," ecriture du fichier fits" );
|
---|
[839] | 1483 | }
|
---|
[1218] | 1484 |
|
---|
| 1485 |
|
---|
| 1486 | /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
| 1487 | same as previous method with char* data
|
---|
| 1488 | */
|
---|
[1209] | 1489 | void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
[839] | 1490 | {
|
---|
| 1491 | int status = 0;
|
---|
| 1492 | int hdutype;
|
---|
| 1493 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1494 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1495 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1496 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1497 | {
|
---|
| 1498 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1499 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1500 | }
|
---|
| 1501 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1502 | {
|
---|
[1209] | 1503 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1504 | }
|
---|
| 1505 | int code;
|
---|
| 1506 | long repeat, width;
|
---|
| 1507 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1508 | if( code != TSTRING)
|
---|
| 1509 | {
|
---|
[1209] | 1510 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;
|
---|
[839] | 1511 | }
|
---|
| 1512 | fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1513 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1514 | }
|
---|
| 1515 |
|
---|
[1209] | 1516 | void FitsOutFile::PutBinTabLine(long NoLine, BnTblLine& ligne) const
|
---|
[1193] | 1517 | {
|
---|
[1209] | 1518 | // on ne fait pas de verification de type, ni de dimension ici, pour
|
---|
| 1519 | // des raisons de performances
|
---|
| 1520 | int k;
|
---|
[1193] | 1521 | int status= 0;
|
---|
| 1522 | int anull;
|
---|
[1209] | 1523 | int ncol=0;
|
---|
[1193] | 1524 | long nels=1;
|
---|
[1209] | 1525 | // int nbcols;
|
---|
| 1526 | // fits_get_num_cols(fptr_, &nbcols,&status);
|
---|
| 1527 | for (k=0; k<ligne.ddata_.size(); k++, ncol++)
|
---|
[1193] | 1528 | {
|
---|
[1209] | 1529 | fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ligne.ddata_[k] ,&status);
|
---|
| 1530 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture double" );
|
---|
[1193] | 1531 | }
|
---|
[1209] | 1532 | for (k=0; k<ligne.fdata_.size(); k++, ncol++)
|
---|
| 1533 | {
|
---|
| 1534 | fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &ligne.fdata_[k] ,&status);
|
---|
| 1535 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture float" );
|
---|
| 1536 | }
|
---|
| 1537 | for (k=0; k<ligne.idata_.size(); k++, ncol++)
|
---|
| 1538 | {
|
---|
| 1539 | fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &ligne.idata_[k] ,&status);
|
---|
| 1540 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier" );
|
---|
| 1541 | }
|
---|
| 1542 |
|
---|
| 1543 | for (k=0; k<ligne.cdata_.size(); k++, ncol++)
|
---|
| 1544 | {
|
---|
[1220] | 1545 | fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, (void*)ligne.cdata_[k].c_str() ,&status);
|
---|
[1209] | 1546 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture caracteres" );
|
---|
| 1547 | }
|
---|
[1193] | 1548 | }
|
---|
| 1549 |
|
---|
| 1550 |
|
---|
[1218] | 1551 | /* \fn void SOPHYA::FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
|
---|
| 1552 |
|
---|
| 1553 | Put keywords from a DVList into the primary header of the fits-file
|
---|
| 1554 | */
|
---|
[1246] | 1555 | void FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl)
|
---|
[1143] | 1556 | {
|
---|
| 1557 | int status = 0;
|
---|
| 1558 | int hdutype;
|
---|
[1246] | 1559 | if (hdunum_ == 0)
|
---|
| 1560 | {
|
---|
| 1561 | if (dvlToPrimary_ == NULL) dvlToPrimary_ = new DVList(dvl);
|
---|
| 1562 | else dvlToPrimary_->Merge(dvl);
|
---|
| 1563 | }
|
---|
| 1564 | else
|
---|
| 1565 | {
|
---|
| 1566 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1567 | addKeywordsOfDVList(dvl);
|
---|
| 1568 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1569 | }
|
---|
[1143] | 1570 | }
|
---|
[839] | 1571 |
|
---|
[1143] | 1572 |
|
---|
[1246] | 1573 | void FitsOutFile::writeSignatureOnFits(int hdunum) const
|
---|
[839] | 1574 | {
|
---|
| 1575 | int status = 0;
|
---|
[1246] | 1576 | int hdutype;
|
---|
[839] | 1577 | char keyname[LEN_KEYWORD];
|
---|
| 1578 | char strval[FLEN_VALUE];
|
---|
| 1579 | char comment[FLEN_COMMENT];
|
---|
[1246] | 1580 | if (hdunum_ == 0)
|
---|
| 1581 | {
|
---|
| 1582 | cerr << " WARNING : can't write keywords on non existing primary header" << endl;
|
---|
| 1583 | return;
|
---|
| 1584 | }
|
---|
| 1585 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1586 | //
|
---|
[971] | 1587 | strncpy(keyname, "CREATOR", LEN_KEYWORD);
|
---|
| 1588 | keyname[LEN_KEYWORD-1] = '\0';
|
---|
| 1589 | strcpy(strval, "SOPHYA");
|
---|
| 1590 | strcpy(comment," SOPHYA Package - FITSIOServer ");
|
---|
| 1591 | fits_write_key(fptr_, TSTRING, keyname, &strval, comment, &status);
|
---|
| 1592 | if( status ) printerror( status );
|
---|
[1143] | 1593 | fits_write_date(fptr_, &status);
|
---|
[971] | 1594 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
| 1595 | fits_write_comment(fptr_, " SOPHYA package - FITSIOSever ", &status);
|
---|
| 1596 | fits_write_comment(fptr_, " (C) LAL/IN2P3-CNRS Orsay, FRANCE 2000", &status);
|
---|
| 1597 | fits_write_comment(fptr_, " (C) DAPNIA/CEA Saclay, FRANCE 2000", &status);
|
---|
| 1598 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
[1045] | 1599 | if( status ) printerror( status, "erreur writeSignatureOnFits" );
|
---|
[1246] | 1600 | //
|
---|
| 1601 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[839] | 1602 | }
|
---|
| 1603 |
|
---|
[903] | 1604 |
|
---|
[1246] | 1605 | void FitsOutFile::addKeywordsOfDVList( DVList& dvl) const
|
---|
[1143] | 1606 | {
|
---|
| 1607 | int status = 0;
|
---|
| 1608 | fits_write_comment(fptr_,"---------- keywords from SOPHYA ---------", &status);
|
---|
| 1609 | DVList::ValList::const_iterator it;
|
---|
| 1610 | for(it = dvl.Begin(); it != dvl.End(); it++)
|
---|
| 1611 | {
|
---|
| 1612 | char keytype= (*it).second.elval.typ;
|
---|
| 1613 | char keyname[10];
|
---|
| 1614 | strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
|
---|
[1183] | 1615 | string key(keyname);
|
---|
[1143] | 1616 | char comment[FLEN_COMMENT];
|
---|
| 1617 | char strval[FLEN_VALUE]= "";
|
---|
| 1618 | char *comkey = "COMMENT";
|
---|
| 1619 | fits_read_keyword(fptr_, keyname, strval, NULL, &status);
|
---|
| 1620 | if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 )
|
---|
| 1621 | {
|
---|
[1183] | 1622 | string coco = dvl.GetComment(key);
|
---|
| 1623 | coco.copy( comment, FLEN_COMMENT-1);
|
---|
| 1624 | int bout = (coco.length() < FLEN_COMMENT) ? coco.length() : FLEN_COMMENT-1;
|
---|
| 1625 | comment[bout]= '\0';
|
---|
[1143] | 1626 | status = 0;
|
---|
| 1627 | switch (keytype)
|
---|
| 1628 | {
|
---|
| 1629 | case 'I' :
|
---|
| 1630 | {
|
---|
[1183] | 1631 | int ival = (int)dvl.GetI(key);
|
---|
| 1632 | fits_write_key(fptr_,TINT,keyname,&ival, comment,&status);
|
---|
[1143] | 1633 | break;
|
---|
| 1634 | }
|
---|
| 1635 | case 'D' :
|
---|
| 1636 | {
|
---|
[1183] | 1637 | double dval= (double)dvl.GetD(key);
|
---|
[1143] | 1638 | fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
|
---|
| 1639 | break;
|
---|
| 1640 | }
|
---|
| 1641 | case 'S' :
|
---|
| 1642 | {
|
---|
[1183] | 1643 | char strvaleur[FLEN_VALUE]= "";
|
---|
| 1644 | string valChaine = dvl.GetS(key);
|
---|
| 1645 | valChaine.copy(strvaleur, FLEN_VALUE-1);
|
---|
| 1646 | int fin = (valChaine.length() < FLEN_VALUE) ? valChaine.length() : FLEN_VALUE-1;
|
---|
| 1647 | strvaleur[fin]= '\0';
|
---|
| 1648 |
|
---|
| 1649 | fits_write_key(fptr_,TSTRING,keyname,&strvaleur,comment,&status);
|
---|
[1143] | 1650 | break;
|
---|
| 1651 | }
|
---|
| 1652 | }
|
---|
| 1653 | }
|
---|
| 1654 | if( status ) printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" );
|
---|
| 1655 | }
|
---|
| 1656 | fits_write_comment(fptr_,"--------------------------------------", &status);
|
---|
| 1657 | }
|
---|
[903] | 1658 |
|
---|
| 1659 |
|
---|
[1246] | 1660 | void FitsOutFile::addDVListOnPrimary()
|
---|
| 1661 | {
|
---|
| 1662 | int status = 0;
|
---|
| 1663 | int hdutype;
|
---|
| 1664 | if (hdunum_ == 0)
|
---|
| 1665 | {
|
---|
| 1666 | cerr << " WARNING : can't write keywords on non existing primary header" << endl;
|
---|
| 1667 | return;
|
---|
| 1668 | }
|
---|
| 1669 | if (dvlToPrimary_ != NULL)
|
---|
| 1670 | {
|
---|
| 1671 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1672 | addKeywordsOfDVList(*dvlToPrimary_);
|
---|
| 1673 | delete dvlToPrimary_;
|
---|
| 1674 | dvlToPrimary_ = NULL;
|
---|
| 1675 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1676 | }
|
---|
| 1677 | }
|
---|
[839] | 1678 |
|
---|