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