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