[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 |
|
---|
| 10 | void FitsIOHandler::Read(char flnm[],int hdunum)
|
---|
[839] | 11 | {
|
---|
[1136] | 12 | FitsInFile ifts(flnm);
|
---|
| 13 | Read(ifts, hdunum);
|
---|
[839] | 14 | }
|
---|
[1136] | 15 | void FitsIOHandler::Read(FitsInFile& is, int hdunum)
|
---|
| 16 | {
|
---|
[1175] | 17 | if (hdunum == 0) is.moveToFollowingHeader();
|
---|
| 18 | else is.ReadFInit(hdunum);
|
---|
[1136] | 19 | ReadFromFits(is);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 |
|
---|
[1193] | 23 | void FitsIOHandler::Write(char flnm[])
|
---|
[1136] | 24 |
|
---|
| 25 | {
|
---|
[1193] | 26 | FitsOutFile of(flnm, unknown);
|
---|
[1136] | 27 | Write(of);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void FitsIOHandler::Write(FitsOutFile& os)
|
---|
| 31 | {
|
---|
| 32 | WriteToFits(os);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 |
|
---|
[839] | 37 |
|
---|
| 38 | FitsFile::~FitsFile()
|
---|
| 39 | {
|
---|
| 40 | int status = 0;
|
---|
[1175] | 41 | if( fptr_ != NULL)
|
---|
[903] | 42 | {
|
---|
| 43 | fits_close_file(fptr_,&status);
|
---|
[1175] | 44 | // je ne fais pas delete fptr_, c'est la lib. fitsio qui a fait
|
---|
| 45 | // new...
|
---|
[903] | 46 | }
|
---|
[1175] | 47 | if( status ) printerror( status );
|
---|
[839] | 48 | }
|
---|
[903] | 49 |
|
---|
[1136] | 50 |
|
---|
| 51 | void FitsFile::printerror(int &status)
|
---|
| 52 | //*****************************************************/
|
---|
| 53 | //* Print out cfitsio error messages and exit program */
|
---|
| 54 | //*****************************************************/
|
---|
[1045] | 55 | {
|
---|
[1136] | 56 | if( status )
|
---|
| 57 | {
|
---|
| 58 | fits_report_error(stderr,status);
|
---|
| 59 | throw IOExc("FitsFile:: error FITSIO status");
|
---|
| 60 | }
|
---|
| 61 | return;
|
---|
| 62 | }
|
---|
[903] | 63 |
|
---|
[1136] | 64 | void FitsFile::printerror(int& status, char* texte)
|
---|
| 65 | //*****************************************************/
|
---|
| 66 | //* Print out cfitsio error messages and exit program */
|
---|
| 67 | //*****************************************************/
|
---|
| 68 | {
|
---|
| 69 | // print out cfitsio error messages and exit program
|
---|
| 70 | // print error report
|
---|
| 71 | fits_report_error(stderr, status);
|
---|
| 72 | cout << " erreur:: " << texte << endl;
|
---|
| 73 | throw IOExc("FitsFile:: error FITSIO status");
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void FitsFile::ResetStatus(int& status)
|
---|
| 77 | {
|
---|
| 78 | fits_status_ = status;
|
---|
| 79 | status = 0;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[1209] | 82 | string FitsFile::GetErrStatus(int status)
|
---|
[1136] | 83 | {
|
---|
| 84 | char text[31];
|
---|
| 85 | fits_get_errstatus(status, text);
|
---|
| 86 | return string(text);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | FitsInFile::FitsInFile()
|
---|
| 90 | {
|
---|
| 91 | InitNull();
|
---|
| 92 | }
|
---|
| 93 | //FitsInFile::FitsInFile(char flnm[], int hdunum)
|
---|
| 94 | FitsInFile::FitsInFile(char flnm[])
|
---|
| 95 | {
|
---|
[1175] | 96 | InitNull();
|
---|
| 97 | int status = 0;
|
---|
| 98 | fits_open_file(&fptr_,flnm,READONLY,&status);
|
---|
| 99 | if( status ) printerror( status );
|
---|
[1136] | 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | void FitsInFile::InitNull()
|
---|
| 104 | {
|
---|
[1175] | 105 |
|
---|
[1045] | 106 | bitpix_ = 0;
|
---|
| 107 | naxis_ = 0;
|
---|
| 108 | nbData_ = 0;
|
---|
| 109 | nrows_ = 0;
|
---|
| 110 | nbcols_ = 0;
|
---|
| 111 | naxisn_.clear();
|
---|
| 112 | repeat_.clear();
|
---|
| 113 | noms_.clear();
|
---|
| 114 | taille_des_chaines_.clear();
|
---|
| 115 | dvl_.Clear();
|
---|
[1175] | 116 |
|
---|
| 117 |
|
---|
[1045] | 118 | }
|
---|
| 119 |
|
---|
| 120 |
|
---|
[1136] | 121 | int FitsInFile::NbBlocks(char flnm[])
|
---|
[903] | 122 | {
|
---|
| 123 | int status = 0;
|
---|
| 124 | int nbhdu = 0;
|
---|
| 125 | fitsfile* fileptr;
|
---|
| 126 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
| 127 | if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" );
|
---|
| 128 | fits_get_num_hdus(fileptr, &nbhdu, &status);
|
---|
| 129 | fits_close_file(fileptr,&status);
|
---|
| 130 | return nbhdu;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[1209] | 133 | void FitsInFile::GetBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
|
---|
[903] | 134 | {
|
---|
| 135 | int status = 0;
|
---|
| 136 | fitsfile* fileptr;
|
---|
| 137 | fits_open_file(&fileptr,flnm,READONLY,&status);
|
---|
[1209] | 138 | if( status ) printerror( status, "GetBlockType: erreur ouverture fichier" );
|
---|
[903] | 139 | // move to the specified HDU number
|
---|
| 140 | int hdutype = 0;
|
---|
| 141 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
[1209] | 142 | if( status ) printerror( status,"GetBlockType: erreur movabs");
|
---|
[903] | 143 | if(hdutype == IMAGE_HDU)
|
---|
| 144 | {
|
---|
| 145 | typeOfExtension = "IMAGE";
|
---|
| 146 | int bitpix;
|
---|
| 147 | GetImageParameters (fileptr, bitpix, naxis, naxisn);
|
---|
| 148 | if(bitpix == DOUBLE_IMG) dataType = "double";
|
---|
| 149 | else
|
---|
| 150 | if(bitpix == FLOAT_IMG) dataType = "float";
|
---|
| 151 | else
|
---|
| 152 | if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = "int";
|
---|
| 153 | else
|
---|
| 154 | {
|
---|
| 155 | cout << " bitpix= " << bitpix << endl;
|
---|
[1209] | 156 | throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
|
---|
[903] | 157 | }
|
---|
| 158 |
|
---|
| 159 | }
|
---|
| 160 | else
|
---|
| 161 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 162 | {
|
---|
| 163 | int nrows = 0;
|
---|
| 164 | vector<string> noms;
|
---|
| 165 | vector<char> types;
|
---|
| 166 | vector<int> taille_des_chaines;
|
---|
[971] | 167 | GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines);
|
---|
| 168 | int k;
|
---|
| 169 | for (k=0; k< naxisn.size(); k++) naxisn[k] *= nrows;
|
---|
[903] | 170 | if(hdutype == ASCII_TBL)
|
---|
| 171 | {
|
---|
| 172 | typeOfExtension = "ASCII_TBL";
|
---|
| 173 | dataType = "ASCII";
|
---|
| 174 | }
|
---|
| 175 | else
|
---|
| 176 | {
|
---|
| 177 | typeOfExtension = "BINARY_TBL";
|
---|
| 178 | if(types[0] == 'D') dataType = "double";
|
---|
| 179 | else
|
---|
| 180 | if(types[0] == 'E') dataType = "float";
|
---|
| 181 | else
|
---|
| 182 | if(types[0] == 'I' ) dataType = "int";
|
---|
| 183 | else
|
---|
| 184 | if(types[0] == 'S' ) dataType = "char*";
|
---|
| 185 | else
|
---|
| 186 | {
|
---|
| 187 | cout << " types[0]= " << types[0] << endl;
|
---|
[1209] | 188 | throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
|
---|
[903] | 189 | }
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | else
|
---|
| 193 | {
|
---|
| 194 | cout << " hdutype= " << hdutype << endl;
|
---|
[1209] | 195 | throw IOExc("FitsFile::GetBlockType: this HDU type is unknown");
|
---|
[903] | 196 | }
|
---|
| 197 |
|
---|
[971] | 198 | KeywordsIntoDVList(fileptr, dvl, hdunum);
|
---|
[903] | 199 | fits_close_file(fileptr,&status);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[1136] | 202 | void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn)
|
---|
[839] | 203 | {
|
---|
[1136] | 204 | int hdunum=0;
|
---|
| 205 | cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum) << endl;
|
---|
| 206 | int status= 0;
|
---|
| 207 |
|
---|
| 208 | // bits per pixels
|
---|
| 209 | fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status);
|
---|
| 210 | if( status ) printerror( status );
|
---|
| 211 |
|
---|
| 212 | // number of dimensions in the FITS array
|
---|
| 213 | naxis= 0;
|
---|
| 214 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 215 | if( status ) printerror( status );
|
---|
| 216 | // read the NAXISn keywords to get image size
|
---|
| 217 | long* naxes = new long[naxis] ;
|
---|
| 218 | int nfound;
|
---|
| 219 | fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status);
|
---|
| 220 | if( status ) printerror( status );
|
---|
| 221 | if (nfound != naxis )
|
---|
| 222 | cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl;
|
---|
| 223 | int k;
|
---|
| 224 | for (k=0; k<naxis; k++)
|
---|
| 225 | {
|
---|
| 226 | naxisn.push_back( (int)naxes[k] );
|
---|
| 227 | }
|
---|
| 228 | delete [] naxes;
|
---|
[971] | 229 | }
|
---|
[839] | 230 |
|
---|
[971] | 231 |
|
---|
[1136] | 232 | void FitsInFile::ReadFInit(int hdunum)
|
---|
[1045] | 233 | {
|
---|
[1143] | 234 | InitNull();
|
---|
[1136] | 235 | // int status = 0;
|
---|
| 236 |
|
---|
| 237 | // fits_open_file(&fptr_,flnm,READONLY,&status);
|
---|
| 238 | // if( status ) printerror( status );
|
---|
| 239 |
|
---|
[1045] | 240 | int status = 0;
|
---|
[1136] | 241 |
|
---|
[1045] | 242 | if (hdunum <= 1)
|
---|
| 243 | {
|
---|
| 244 | hdunum_ = 1;
|
---|
| 245 | // presence of image ?
|
---|
| 246 | int naxis= 0;
|
---|
| 247 | fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 248 | if( status ) printerror( status );
|
---|
| 249 | if (naxis > 0 ) // there is an image
|
---|
| 250 | {
|
---|
| 251 | hdutype_ = IMAGE_HDU;
|
---|
| 252 | GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
|
---|
| 253 | nbData_ = 1;
|
---|
| 254 | int k;
|
---|
| 255 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
| 256 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
| 257 | }
|
---|
| 258 | else
|
---|
| 259 | {
|
---|
| 260 | throw PException(" first header : no image, probably error in hdunum");
|
---|
| 261 | }
|
---|
| 262 | //
|
---|
| 263 | }
|
---|
| 264 | else
|
---|
| 265 | {
|
---|
| 266 | hdunum_ = hdunum-1;
|
---|
| 267 | int hdutype;
|
---|
| 268 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 269 | if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
|
---|
| 270 | moveToFollowingHeader();
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 |
|
---|
[1143] | 274 | DVList FitsInFile::DVListFromPrimaryHeader() const
|
---|
| 275 | {
|
---|
| 276 | int status;
|
---|
| 277 | DVList dvl;
|
---|
| 278 | KeywordsIntoDVList(fptr_, dvl, 1);
|
---|
| 279 | int hdutype = 0;
|
---|
| 280 | if (hdunum_ > 0) fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 281 | return dvl;
|
---|
| 282 | }
|
---|
[1136] | 283 |
|
---|
| 284 |
|
---|
| 285 | void FitsInFile::moveToFollowingHeader()
|
---|
[971] | 286 | {
|
---|
| 287 | int status = 0;
|
---|
[839] | 288 | int hdutype;
|
---|
[1143] | 289 | InitNull();
|
---|
[971] | 290 | fits_movrel_hdu(fptr_, 1,&hdutype,&status);
|
---|
| 291 | if( status ) printerror( status," lecture du header suivant" );
|
---|
| 292 | hdunum_++;
|
---|
[839] | 293 | hdutype_= hdutype;
|
---|
| 294 | if(hdutype_ == IMAGE_HDU)
|
---|
| 295 | {
|
---|
[903] | 296 | GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
|
---|
| 297 | nbData_ = 1;
|
---|
[971] | 298 | int k;
|
---|
| 299 | for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
|
---|
| 300 | KeywordsIntoDVList(fptr_, dvl_,hdunum_);
|
---|
[839] | 301 | }
|
---|
| 302 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 303 | {
|
---|
[903] | 304 | GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
|
---|
[971] | 305 | KeywordsIntoDVList(fptr_, dvl_, hdunum_);
|
---|
[839] | 306 | }
|
---|
[971] | 307 | }
|
---|
[839] | 308 |
|
---|
[1136] | 309 |
|
---|
| 310 | int FitsInFile::NbColsFromFits() const
|
---|
[839] | 311 | {
|
---|
[1136] | 312 | if(hdutype_ == BINARY_TBL) return nbcols_;
|
---|
[971] | 313 | else
|
---|
[1136] | 314 | if(hdutype_ == ASCII_TBL || hdutype_ == IMAGE_HDU) return 1;
|
---|
[839] | 315 | else
|
---|
| 316 | {
|
---|
[1136] | 317 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 318 | throw PException("FitsFile::NbColsFromFits, this HDU is unknown");
|
---|
[839] | 319 | }
|
---|
| 320 | }
|
---|
| 321 |
|
---|
[1136] | 322 | int FitsInFile::NentriesFromFits(int nocol) const
|
---|
[839] | 323 | {
|
---|
[1136] | 324 | if(hdutype_ == BINARY_TBL ) return nrows_*repeat_[nocol];
|
---|
| 325 | else
|
---|
| 326 | if(hdutype_ == ASCII_TBL) return nrows_;
|
---|
| 327 | else
|
---|
| 328 | if(hdutype_ == IMAGE_HDU) return nbData_;
|
---|
| 329 | else
|
---|
[839] | 330 | {
|
---|
[1136] | 331 | cout << "hdutype= " << hdutype_ << endl;
|
---|
| 332 | throw PException("FitsFile::NentriesFromFits, this HDU is unknown");
|
---|
[839] | 333 | }
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[1136] | 336 | char FitsInFile::ColTypeFromFits(int nocol) const
|
---|
[839] | 337 | {
|
---|
[1136] | 338 | if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
|
---|
[839] | 339 | {
|
---|
[1136] | 340 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 341 | }
|
---|
[1136] | 342 | return types_[nocol];
|
---|
[839] | 343 | }
|
---|
[1136] | 344 | string FitsInFile::ColNameFromFits(int nocol) const
|
---|
[839] | 345 | {
|
---|
[1136] | 346 | if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
|
---|
[1045] | 347 | {
|
---|
[1136] | 348 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
[1045] | 349 | }
|
---|
[1136] | 350 | return noms_[nocol];
|
---|
[839] | 351 | }
|
---|
| 352 |
|
---|
[1136] | 353 | int FitsInFile::ColStringLengthFromFits(int nocol) const
|
---|
[839] | 354 | {
|
---|
[1136] | 355 | if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL)
|
---|
| 356 | {
|
---|
| 357 | throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table");
|
---|
| 358 | }
|
---|
| 359 | int index=-1;
|
---|
| 360 | int k;
|
---|
| 361 | for (k=0; k<=nocol; k++)
|
---|
| 362 | {
|
---|
| 363 | if (types_[k] == 'S') index++;
|
---|
| 364 | }
|
---|
| 365 | return taille_des_chaines_[index];
|
---|
[839] | 366 | }
|
---|
[1193] | 367 | void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
|
---|
[839] | 368 | {
|
---|
| 369 | int status= 0;
|
---|
[1136] | 370 | int anull;
|
---|
| 371 | double dnull= 0.;
|
---|
| 372 | float fnull= 0.;
|
---|
| 373 | int inull= 0;
|
---|
| 374 | char* cnull= "";
|
---|
| 375 | int dcount = 0.;
|
---|
| 376 | int fcount = 0.;
|
---|
| 377 | int icount = 0;
|
---|
| 378 | int ccount =0;
|
---|
| 379 | int ncol;
|
---|
| 380 | long nels=1;
|
---|
| 381 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
[861] | 382 | {
|
---|
[1136] | 383 | switch (types_[ncol])
|
---|
| 384 | {
|
---|
| 385 | case 'D' :
|
---|
| 386 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status);
|
---|
| 387 | break;
|
---|
| 388 | case 'E' :
|
---|
| 389 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status);
|
---|
| 390 | break;
|
---|
| 391 | case 'I' :
|
---|
| 392 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++],
|
---|
| 393 | &anull,&status);
|
---|
| 394 | break;
|
---|
| 395 | case 'S' :
|
---|
| 396 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
|
---|
| 397 | break;
|
---|
| 398 | }
|
---|
| 399 | if (status)
|
---|
| 400 | {
|
---|
| 401 | ResetStatus(status);
|
---|
| 402 | break;
|
---|
| 403 | }
|
---|
[861] | 404 | }
|
---|
[903] | 405 | }
|
---|
[839] | 406 |
|
---|
[1193] | 407 | void FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne)
|
---|
| 408 | {
|
---|
| 409 | int status= 0;
|
---|
| 410 | int anull;
|
---|
| 411 | double dnull= 0.;
|
---|
| 412 | float fnull= 0.;
|
---|
| 413 | int inull= 0;
|
---|
| 414 | char* cnull= "";
|
---|
| 415 | int dcount = 0.;
|
---|
| 416 | int fcount = 0.;
|
---|
| 417 | int icount = 0;
|
---|
| 418 | int ccount =0;
|
---|
| 419 | int ncol;
|
---|
| 420 | long nels=1;
|
---|
| 421 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
| 422 | {
|
---|
| 423 | switch (types_[ncol])
|
---|
| 424 | {
|
---|
| 425 | case 'D' :
|
---|
| 426 | fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anull,&status);
|
---|
| 427 | break;
|
---|
| 428 | case 'E' :
|
---|
| 429 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anull,&status);
|
---|
| 430 | break;
|
---|
| 431 | case 'I' :
|
---|
| 432 | fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++],
|
---|
| 433 | &anull,&status);
|
---|
| 434 | break;
|
---|
| 435 | case 'S' :
|
---|
| 436 | char* chaine = new char[taille_des_chaines_[ccount]];
|
---|
| 437 | fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anull,&status);
|
---|
| 438 | ligne.cdata_[ccount++] = string(chaine);
|
---|
| 439 | break;
|
---|
| 440 | }
|
---|
| 441 | if (status)
|
---|
| 442 | {
|
---|
| 443 | ResetStatus(status);
|
---|
| 444 | break;
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | }
|
---|
| 448 |
|
---|
[1136] | 449 | void FitsInFile::GetBinTabLine(int NoLine, float* fdata)
|
---|
[903] | 450 | {
|
---|
[1136] | 451 | int status= 0;
|
---|
| 452 | int anull;
|
---|
| 453 | float fnull= 0.;
|
---|
| 454 | long nels=1;
|
---|
| 455 | int ncol;
|
---|
| 456 | for (ncol=0; ncol<nbcols_; ncol++)
|
---|
[861] | 457 | {
|
---|
[1136] | 458 | fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status);
|
---|
| 459 | if (status)
|
---|
[903] | 460 | {
|
---|
[1136] | 461 | ResetStatus(status);
|
---|
| 462 | break;
|
---|
[903] | 463 | }
|
---|
[1136] | 464 | }
|
---|
| 465 | }
|
---|
[839] | 466 |
|
---|
[903] | 467 |
|
---|
[1136] | 468 | void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const
|
---|
[839] | 469 | {
|
---|
| 470 | int status= 0;
|
---|
| 471 | int DTYPE;
|
---|
| 472 | long repeat,width;
|
---|
| 473 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 474 | if( DTYPE != TDOUBLE)
|
---|
| 475 | {
|
---|
[1045] | 476 | if (DTYPE == TFLOAT) cout << " WARNING: reading double from float : conversion will be made by fitsio library" << endl;
|
---|
| 477 | else
|
---|
| 478 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double");
|
---|
[839] | 479 | }
|
---|
| 480 | long nels=nentries;
|
---|
[971] | 481 | int anull;
|
---|
[839] | 482 | // no checking for undefined pixels
|
---|
[971] | 483 | double dnull= 0.;
|
---|
| 484 | // fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status);
|
---|
| 485 | // if (status != 0)
|
---|
| 486 | // {
|
---|
| 487 | // dnull = -1.6375e30; // default value
|
---|
| 488 | // status = 0;
|
---|
| 489 | // }
|
---|
| 490 | if (nentries != nrows_*repeat)
|
---|
| 491 | {
|
---|
| 492 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 493 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 494 | }
|
---|
[839] | 495 | fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs,
|
---|
| 496 | &anull,&status);
|
---|
| 497 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
[971] | 498 |
|
---|
[839] | 499 | }
|
---|
| 500 |
|
---|
[1136] | 501 | void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const
|
---|
[839] | 502 | {
|
---|
| 503 | int status= 0;
|
---|
| 504 | int DTYPE;
|
---|
| 505 | long repeat,width;
|
---|
| 506 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 507 | if( DTYPE != TFLOAT)
|
---|
| 508 | {
|
---|
[1045] | 509 | if (DTYPE == TDOUBLE) cout << " WARNING: reading float from double : conversion will be made by fitsio library" << endl;
|
---|
| 510 | else
|
---|
| 511 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
|
---|
[839] | 512 | }
|
---|
| 513 | long nels=nentries;
|
---|
[971] | 514 | int anull;
|
---|
[839] | 515 | // no checking for undefined pixels
|
---|
| 516 | float fnull= 0.;
|
---|
[971] | 517 | // fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status);
|
---|
| 518 | // if (status != 0)
|
---|
| 519 | // {
|
---|
| 520 | // fnull = -1.6375e30; // default value
|
---|
| 521 | // status = 0;
|
---|
| 522 | // }
|
---|
| 523 | if (nentries != nrows_*repeat)
|
---|
| 524 | {
|
---|
| 525 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 526 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 527 | }
|
---|
[839] | 528 | fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs,
|
---|
| 529 | &anull,&status);
|
---|
| 530 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 531 | }
|
---|
[1136] | 532 |
|
---|
| 533 | void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const
|
---|
[839] | 534 | {
|
---|
| 535 | int status= 0;
|
---|
| 536 | int DTYPE;
|
---|
| 537 | long repeat,width;
|
---|
| 538 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 539 | if( DTYPE != TLONG && DTYPE != TINT && DTYPE != TSHORT )
|
---|
| 540 | {
|
---|
| 541 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier");
|
---|
| 542 | }
|
---|
| 543 | long nels=nentries;
|
---|
| 544 | // no checking for undefined pixels
|
---|
| 545 | int anull;
|
---|
| 546 | int inull= 0;
|
---|
[971] | 547 | // fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status);
|
---|
| 548 | // if (status != 0)
|
---|
| 549 | // {
|
---|
| 550 | // inull = -999999; // default value
|
---|
| 551 | // status = 0;
|
---|
| 552 | // }
|
---|
| 553 | if (nentries != nrows_*repeat)
|
---|
| 554 | {
|
---|
| 555 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl;
|
---|
| 556 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 557 | }
|
---|
[839] | 558 | fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs,
|
---|
| 559 | &anull,&status);
|
---|
| 560 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 561 | }
|
---|
[1136] | 562 |
|
---|
| 563 | void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const
|
---|
[839] | 564 | {
|
---|
| 565 | int status= 0;
|
---|
| 566 | int DTYPE;
|
---|
| 567 | long repeat,width;
|
---|
| 568 | fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status);
|
---|
| 569 | if( DTYPE != TSTRING )
|
---|
| 570 | {
|
---|
| 571 | throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float");
|
---|
| 572 | }
|
---|
| 573 | long nels=nentries;
|
---|
| 574 | // no checking for undefined pixels
|
---|
| 575 | int anull;
|
---|
[971] | 576 | char* cnull= "";
|
---|
| 577 | if (nentries != nrows_*repeat/width)
|
---|
| 578 | {
|
---|
| 579 | cout << " found " << nentries << " pixels, expected: " << nrows_*repeat/width << endl;
|
---|
| 580 | throw PException(" FitsFile:::GetBinTabFCol ");
|
---|
| 581 | }
|
---|
[839] | 582 | long frow=1;
|
---|
| 583 | long felem=1;
|
---|
| 584 | fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs,
|
---|
| 585 | &anull,&status);
|
---|
| 586 | if( status ) printerror( status,"erreur lecture de colonne" );
|
---|
| 587 | }
|
---|
[1045] | 588 |
|
---|
[1136] | 589 | void FitsInFile::GetSingleColumn(double* map, int nentries) const
|
---|
| 590 | {
|
---|
| 591 | int status = 0;
|
---|
| 592 | if(hdutype_ == IMAGE_HDU)
|
---|
[1045] | 593 | {
|
---|
[1136] | 594 |
|
---|
| 595 | if(bitpix_ != DOUBLE_IMG)
|
---|
[1047] | 596 | {
|
---|
[1136] | 597 | cout << " The data type on fits file is not double...";
|
---|
| 598 | cout << " Conversion to double achieved by cfitsio lib" << endl;
|
---|
[1047] | 599 | }
|
---|
[1136] | 600 |
|
---|
| 601 | // no checking for undefined pixels
|
---|
| 602 | int anull;
|
---|
| 603 | double dnull= 0.;
|
---|
| 604 |
|
---|
| 605 | long nels= nentries;
|
---|
| 606 | fits_read_img(fptr_,TDOUBLE,1,nels,&dnull,map,&anull,&status);
|
---|
| 607 | if( status ) printerror( status );
|
---|
[1045] | 608 | }
|
---|
[1136] | 609 | else
|
---|
| 610 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 611 | {
|
---|
| 612 | GetBinTabFCol(map,nentries, 0);
|
---|
| 613 | }
|
---|
| 614 | else
|
---|
| 615 | {
|
---|
| 616 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 617 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
| 618 | }
|
---|
[1045] | 619 | }
|
---|
| 620 |
|
---|
[1136] | 621 | void FitsInFile::GetSingleColumn(float* map, int nentries) const
|
---|
[1045] | 622 | {
|
---|
[1136] | 623 | int status = 0;
|
---|
| 624 | if(hdutype_ == IMAGE_HDU)
|
---|
[1045] | 625 | {
|
---|
[1136] | 626 | if(bitpix_ != FLOAT_IMG)
|
---|
[1047] | 627 | {
|
---|
[1136] | 628 | cout << " The data type on fits file is not float ";
|
---|
| 629 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
[1047] | 630 | }
|
---|
[1136] | 631 | // no checking for undefined pixels
|
---|
| 632 | int anull;
|
---|
| 633 | float fnull= 0.;
|
---|
| 634 |
|
---|
| 635 | long nels= nentries;
|
---|
| 636 | fits_read_img(fptr_,TFLOAT,1,nels,&fnull, map,&anull,&status);
|
---|
| 637 | if( status ) printerror( status );
|
---|
[1045] | 638 | }
|
---|
[839] | 639 | else
|
---|
[1136] | 640 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 641 | {
|
---|
| 642 | GetBinTabFCol(map,nentries, 0);
|
---|
| 643 | }
|
---|
[839] | 644 | else
|
---|
| 645 | {
|
---|
[1136] | 646 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 647 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
[839] | 648 | }
|
---|
| 649 | }
|
---|
| 650 |
|
---|
[1136] | 651 | void FitsInFile::GetSingleColumn( int* map, int nentries) const
|
---|
[839] | 652 | {
|
---|
[1136] | 653 | int status = 0;
|
---|
| 654 | if(hdutype_ == IMAGE_HDU)
|
---|
[839] | 655 | {
|
---|
[1136] | 656 | if(bitpix_ != LONG_IMG)
|
---|
| 657 | {
|
---|
| 658 | cout << " The data type on fits file is not int ";
|
---|
| 659 | cout << " Conversion to float achieved by cfitsio lib" << endl;
|
---|
| 660 | }
|
---|
| 661 | // no checking for undefined pixels
|
---|
| 662 | int anull;
|
---|
| 663 | float fnull= 0.;
|
---|
| 664 |
|
---|
| 665 | long nels= nentries;
|
---|
| 666 | fits_read_img(fptr_,TINT,1,nels,&fnull,map,&anull,&status);
|
---|
| 667 | if( status ) printerror( status );
|
---|
[839] | 668 | }
|
---|
| 669 | else
|
---|
[1136] | 670 | if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
|
---|
| 671 | {
|
---|
| 672 | GetBinTabFCol(map,nentries, 0);
|
---|
| 673 | }
|
---|
[839] | 674 | else
|
---|
[1136] | 675 | {
|
---|
| 676 | cout << " hdutype= " << hdutype_ << endl;
|
---|
| 677 | throw IOExc("FitsFile::GetSingleColumn this HDU is unknown");
|
---|
| 678 | }
|
---|
[839] | 679 | }
|
---|
| 680 |
|
---|
[1136] | 681 | void FitsInFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows,
|
---|
[903] | 682 | vector<int>& repeat,
|
---|
| 683 | vector<string>& noms,
|
---|
| 684 | vector<char>& types,
|
---|
| 685 | vector<int>& taille_des_chaines)
|
---|
[839] | 686 | {
|
---|
| 687 | int status= 0;
|
---|
[903] | 688 | int hdunum=0;
|
---|
| 689 | int hdutype=0;
|
---|
| 690 | fits_get_hdu_num(fileptr,&hdunum);
|
---|
| 691 | fits_get_hdu_type(fileptr, &hdutype, &status);
|
---|
| 692 |
|
---|
| 693 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
[839] | 694 | {
|
---|
[903] | 695 | throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 696 | }
|
---|
[903] | 697 | if(hdutype == ASCII_TBL)
|
---|
| 698 | cout << " Reading a FITS ascii table in HDU : " << hdunum << endl;
|
---|
| 699 | if(hdutype == BINARY_TBL)
|
---|
| 700 | cout << " Reading a FITS binary table in HDU : " << hdunum << endl;
|
---|
[839] | 701 |
|
---|
| 702 | // get the number of columns
|
---|
[903] | 703 | fits_get_num_cols(fileptr, &nbcols,&status);
|
---|
[839] | 704 | if( status ) printerror( status );
|
---|
| 705 |
|
---|
| 706 | // get the number of rows
|
---|
| 707 | long naxis2= 0;
|
---|
[903] | 708 | fits_get_num_rows(fileptr,&naxis2,&status);
|
---|
[839] | 709 | if( status ) printerror( status );
|
---|
[903] | 710 | nrows = (int)naxis2;
|
---|
[839] | 711 |
|
---|
| 712 | // get the datatype, names and the repeat count
|
---|
[903] | 713 | noms.clear();
|
---|
| 714 | noms.reserve(nbcols);
|
---|
| 715 | types.clear();
|
---|
| 716 | types.reserve(nbcols);
|
---|
| 717 | repeat.clear();
|
---|
| 718 | repeat.reserve(nbcols);
|
---|
| 719 | taille_des_chaines.clear();
|
---|
[839] | 720 | char **ttype = new char*[nbcols];
|
---|
[923] | 721 | int ii;
|
---|
[1175] | 722 | //
|
---|
| 723 | //
|
---|
[923] | 724 | for (ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE];
|
---|
[839] | 725 | int nfound;
|
---|
[903] | 726 | fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status);
|
---|
[839] | 727 | if( status ) printerror( status,"erreur lecture des noms de colonne");
|
---|
| 728 | int rept=0;
|
---|
[923] | 729 | for(ii = 0; ii < nbcols; ii++)
|
---|
[839] | 730 | {
|
---|
| 731 | int DTYPE;
|
---|
| 732 | long width;
|
---|
[903] | 733 | long repete = 0;
|
---|
| 734 | fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status);
|
---|
[839] | 735 | if( status ) printerror( status,"erreur lecture type de colonne");
|
---|
[903] | 736 | rept = repete;
|
---|
| 737 | noms.push_back(string(ttype[ii]));
|
---|
[839] | 738 | switch (DTYPE)
|
---|
| 739 | {
|
---|
| 740 | case TDOUBLE :
|
---|
[903] | 741 | types.push_back('D');
|
---|
[839] | 742 | break;
|
---|
| 743 | case TFLOAT :
|
---|
[903] | 744 | types.push_back('E');
|
---|
[839] | 745 | break;
|
---|
| 746 | case TLONG :
|
---|
[903] | 747 | types.push_back('I');
|
---|
[839] | 748 | break;
|
---|
| 749 | case TINT :
|
---|
[903] | 750 | types.push_back('I');
|
---|
[839] | 751 | break;
|
---|
| 752 | case TSHORT :
|
---|
[903] | 753 | types.push_back('I');
|
---|
[839] | 754 | break;
|
---|
| 755 | case TSTRING :
|
---|
[903] | 756 | types.push_back('S');
|
---|
| 757 | taille_des_chaines.push_back(width);
|
---|
[839] | 758 | rept/=width;
|
---|
| 759 | break;
|
---|
| 760 | default :
|
---|
| 761 | cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl;
|
---|
| 762 | throw IOExc("FitsFile:: unknown type of field");
|
---|
| 763 | }
|
---|
[903] | 764 | repeat.push_back(rept);
|
---|
[1136] | 765 | }
|
---|
| 766 | for (ii=0; ii < nbcols; ii++) delete [] ttype[ii];
|
---|
| 767 | delete [] ttype;
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | void FitsInFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum)
|
---|
| 771 | {
|
---|
| 772 | int status = 0;
|
---|
| 773 | int hdutype;
|
---|
| 774 | fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
|
---|
| 775 | if( status ) printerror( status,":KeywordsIntoDVList : erreur movabs");
|
---|
| 776 | // get number of keywords
|
---|
| 777 | int nkeys,keypos;
|
---|
| 778 | fits_get_hdrpos(fileptr,&nkeys,&keypos,&status);
|
---|
| 779 | if( status ) printerror( status );
|
---|
| 780 |
|
---|
| 781 | // put keywords in a DVList object
|
---|
| 782 | char keyname[LEN_KEYWORD]= "";
|
---|
| 783 | char strval[FLEN_VALUE]= "";
|
---|
| 784 | char dtype;
|
---|
| 785 | char card[FLEN_CARD];
|
---|
| 786 | char *comkey = "COMMENT";
|
---|
[1143] | 787 | char comment[FLEN_COMMENT];
|
---|
[1136] | 788 |
|
---|
| 789 | // shift with the number of mandatory keywords
|
---|
[1143] | 790 | // int num= 8;
|
---|
| 791 | int num= 0;
|
---|
| 792 | // primary header
|
---|
| 793 | if (hdunum == 1)
|
---|
| 794 | {
|
---|
| 795 | // read NAXIS
|
---|
| 796 | int naxis=0;
|
---|
| 797 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 798 | // number of mandatory keywords
|
---|
| 799 | num = naxis+3;
|
---|
| 800 | }
|
---|
| 801 | // extensions
|
---|
| 802 | else
|
---|
| 803 | {
|
---|
| 804 | if (hdutype == IMAGE_HDU)
|
---|
| 805 | {
|
---|
| 806 | // read NAXIS
|
---|
| 807 | int naxis=0;
|
---|
| 808 | fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status);
|
---|
| 809 | // number of mandatory keywords
|
---|
| 810 | num = naxis+5;
|
---|
| 811 | }
|
---|
| 812 | else
|
---|
| 813 | if(hdutype == ASCII_TBL || hdutype == BINARY_TBL)
|
---|
| 814 | {
|
---|
| 815 | // number of mandatory keywords
|
---|
| 816 | num = 8;
|
---|
| 817 | }
|
---|
| 818 | }
|
---|
[1136] | 819 | int j;
|
---|
| 820 | for(j = num+1; j <= nkeys; j++)
|
---|
| 821 | {
|
---|
| 822 | fits_read_keyn(fileptr,j,card,strval,NULL,&status);
|
---|
| 823 | if(status) printerror(status);
|
---|
| 824 |
|
---|
| 825 | strncpy(keyname,card,LEN_KEYWORD-1);
|
---|
| 826 | if(strncmp(keyname,comkey,LEN_KEYWORD-1) != 0 && strlen(keyname) != 0
|
---|
| 827 | && strlen(strval) != 0)
|
---|
| 828 | {
|
---|
| 829 | fits_get_keytype(strval,&dtype,&status);
|
---|
| 830 | if(status) printerror(status);
|
---|
| 831 |
|
---|
| 832 | strip(keyname, 'B',' ');
|
---|
| 833 | strip(strval, 'B',' ');
|
---|
| 834 | strip(strval, 'B','\'');
|
---|
| 835 |
|
---|
| 836 | switch( dtype )
|
---|
| 837 | {
|
---|
| 838 | case 'C':
|
---|
[1143] | 839 | fits_read_key(fileptr,TSTRING,keyname,strval,comment,&status);
|
---|
| 840 | dvl[keyname]= strval;
|
---|
| 841 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 842 | break;
|
---|
| 843 | case 'I':
|
---|
| 844 | int ival;
|
---|
[1143] | 845 | fits_read_key(fileptr,TINT,keyname,&ival,comment,&status);
|
---|
[1136] | 846 | dvl[keyname]= (int_4) ival; // Portage mac DY
|
---|
[1143] | 847 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 848 | break;
|
---|
| 849 | case 'L':
|
---|
| 850 | int ilog;
|
---|
[1143] | 851 | fits_read_key(fileptr,TLOGICAL,keyname,&ilog,comment,&status);
|
---|
[1136] | 852 | dvl[keyname]= (int_4) ilog;
|
---|
[1143] | 853 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 854 | break;
|
---|
| 855 | case 'F':
|
---|
| 856 | double dval;
|
---|
[1143] | 857 | fits_read_key(fileptr,TDOUBLE,keyname,&dval,comment,&status);
|
---|
[1136] | 858 | dvl[keyname]= dval;
|
---|
[1143] | 859 | dvl.SetComment(keyname, comment);
|
---|
[1136] | 860 | break;
|
---|
| 861 | }
|
---|
| 862 |
|
---|
| 863 | }
|
---|
[839] | 864 | }
|
---|
[1136] | 865 | // dvl_.Print();
|
---|
| 866 | }
|
---|
| 867 |
|
---|
| 868 | FitsOutFile::FitsOutFile()
|
---|
| 869 | {
|
---|
[1193] | 870 | InitNull();
|
---|
[903] | 871 | }
|
---|
[839] | 872 |
|
---|
[1193] | 873 | FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
|
---|
[1136] | 874 | {
|
---|
[839] | 875 |
|
---|
[1136] | 876 | InitNull();
|
---|
| 877 | int status = 0;
|
---|
[839] | 878 |
|
---|
[1136] | 879 | // create new FITS file
|
---|
[1183] | 880 |
|
---|
| 881 | fits_create_file(&fptr_,flnm,&status);
|
---|
| 882 | if( status )
|
---|
[1136] | 883 | {
|
---|
[1193] | 884 |
|
---|
| 885 | switch (wrm)
|
---|
| 886 | {
|
---|
[1183] | 887 | // si on veut ecrire a la fin de ce fichier
|
---|
[1193] | 888 | case append :
|
---|
[1183] | 889 | status = 0;
|
---|
| 890 | fits_open_file(&fptr_,flnm,READWRITE,&status);
|
---|
| 891 | if( status )
|
---|
| 892 | {
|
---|
| 893 | cout << " error opening file: " << flnm << endl;
|
---|
| 894 | printerror(status, "failure opening a file supposed to exist");
|
---|
| 895 | }
|
---|
| 896 | else cout << " file " << flnm << " opened, new objects will be appended " << endl;
|
---|
| 897 | fits_get_num_hdus(fptr_, &hdunum_, &status);
|
---|
| 898 | int hdutype;
|
---|
| 899 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 900 | if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
|
---|
[1193] | 901 | break;
|
---|
| 902 |
|
---|
| 903 | case clear :
|
---|
[1183] | 904 | {
|
---|
| 905 | status = 0;
|
---|
| 906 | char* newname = new char[strlen(flnm)+1];
|
---|
| 907 | //
|
---|
| 908 | newname[0] = '!';
|
---|
| 909 | newname[1] = '\0';
|
---|
| 910 | strcat(newname, flnm);
|
---|
| 911 | fits_create_file(&fptr_,newname,&status);
|
---|
[1193] | 912 | delete [] newname;
|
---|
[1183] | 913 | if (status)
|
---|
| 914 | {
|
---|
| 915 | cout << " error opening file: " << flnm << endl;
|
---|
| 916 | printerror(status, "unable to open file, supposed to exist");
|
---|
| 917 | }
|
---|
[1193] | 918 | else cout << " WARNING : file " << flnm << " is overwritten " << endl;
|
---|
| 919 | break;
|
---|
[1183] | 920 | }
|
---|
[1193] | 921 | case unknown :
|
---|
| 922 | printerror(status, " file seems already to exist");
|
---|
| 923 | break;
|
---|
[1183] | 924 |
|
---|
[1193] | 925 | }
|
---|
[1136] | 926 | }
|
---|
| 927 | }
|
---|
| 928 |
|
---|
| 929 |
|
---|
| 930 |
|
---|
[1143] | 931 | void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl)
|
---|
[1136] | 932 | {
|
---|
| 933 | int status = 0;
|
---|
| 934 | long naxis = nbdim;
|
---|
| 935 | long* naxes = new long[nbdim];
|
---|
| 936 | if (hdunum_ == 1)
|
---|
| 937 | {
|
---|
[1143] | 938 | if (imageOnPrimary_ == false)
|
---|
| 939 | {
|
---|
| 940 | fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
|
---|
| 941 | writeSignatureOnFits(); }
|
---|
[1136] | 942 | else hdunum_--;
|
---|
| 943 | }
|
---|
| 944 | int k;
|
---|
| 945 | for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k];
|
---|
| 946 | if (type == 'D')
|
---|
| 947 | fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status);
|
---|
| 948 | else
|
---|
| 949 | if (type == 'E')
|
---|
| 950 | fits_create_img(fptr_,FLOAT_IMG,naxis,naxes,&status);
|
---|
| 951 | else
|
---|
| 952 | if (type == 'I')
|
---|
| 953 | fits_create_img(fptr_,LONG_IMG,naxis,naxes,&status);
|
---|
| 954 | else
|
---|
| 955 | {
|
---|
| 956 | cout << " type of data: " << type << endl;
|
---|
| 957 | throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data ");
|
---|
| 958 | }
|
---|
| 959 |
|
---|
| 960 | hdunum_++;
|
---|
[1143] | 961 |
|
---|
| 962 | // write supplementary keywords
|
---|
| 963 | // dvl.Print();
|
---|
| 964 | addKeywordsOfDVList(dvl);
|
---|
| 965 |
|
---|
[1136] | 966 | delete [] naxes;
|
---|
| 967 | if( status ) printerror( status, "erreur creation HDU IMAGE" );
|
---|
| 968 |
|
---|
| 969 | }
|
---|
[1209] | 970 | void FitsOutFile::PutImageToFits(int nbData, double* map) const
|
---|
[1136] | 971 | {
|
---|
| 972 | int status = 0;
|
---|
| 973 | long npix= nbData;
|
---|
| 974 | fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
|
---|
[1209] | 975 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1143] | 976 | // writeSignatureOnFits();
|
---|
[1136] | 977 | }
|
---|
| 978 |
|
---|
[1209] | 979 | void FitsOutFile::PutImageToFits(int nbData, float* map) const
|
---|
[1136] | 980 | {
|
---|
| 981 | int status = 0;
|
---|
| 982 | long npix= nbData;
|
---|
| 983 | fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
|
---|
[1209] | 984 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1143] | 985 | // writeSignatureOnFits();
|
---|
[1136] | 986 |
|
---|
| 987 | }
|
---|
[1209] | 988 | void FitsOutFile::PutImageToFits( int nbData, int* map) const
|
---|
[1136] | 989 | {
|
---|
| 990 | int status = 0;
|
---|
| 991 |
|
---|
| 992 | long npix= nbData;
|
---|
| 993 | fits_write_img(fptr_,TINT,1,npix,map,&status);
|
---|
[1209] | 994 | if( status ) printerror( status, "erreur ecriture PutImageToFits" );
|
---|
[1143] | 995 | // writeSignatureOnFits();
|
---|
[1136] | 996 | }
|
---|
| 997 |
|
---|
| 998 |
|
---|
| 999 |
|
---|
[1193] | 1000 | void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
|
---|
[839] | 1001 | {
|
---|
[1209] | 1002 | int k;
|
---|
[839] | 1003 | int status = 0;
|
---|
| 1004 | long nrows;
|
---|
[1209] | 1005 | // verifications de coherence
|
---|
| 1006 |
|
---|
[1193] | 1007 | if (fieldType.length() != tfields)
|
---|
[839] | 1008 | {
|
---|
[1193] | 1009 | cout << " nombre de champs :" << tfields << "nombre de types: " << fieldType.length() << endl;
|
---|
[1136] | 1010 | throw ParmError("FitsFile:: fields and types don't match");
|
---|
[839] | 1011 |
|
---|
| 1012 | }
|
---|
[1209] | 1013 | if (tfields > Noms.size())
|
---|
| 1014 | {
|
---|
| 1015 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of column names not equal to total number of columns" << endl;
|
---|
| 1016 | for (k=0; k<(tfields-Noms.size()); k++) Noms.push_back( string(" "));
|
---|
| 1017 | }
|
---|
| 1018 |
|
---|
| 1019 | // nombre de variables "chaines de caracteres"
|
---|
| 1020 | int nbString = 0;
|
---|
| 1021 | for (k=0; k<tfields;k++) if (fieldType[k] == 'A') nbString++;
|
---|
| 1022 | // coherence de la longueur du vecteur des tailles
|
---|
| 1023 | if (nbString > taille_des_chaines.size())
|
---|
| 1024 | {
|
---|
| 1025 | cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of string lengths not equal to total number of columns" << endl;
|
---|
| 1026 | int strSz=0;
|
---|
| 1027 | for (k=0; k<taille_des_chaines.size(); k++) if ( taille_des_chaines[k] > strSz) strSz = taille_des_chaines[k];
|
---|
| 1028 | for (k=0; k<(nbString-taille_des_chaines.size()); k++) taille_des_chaines.push_back(strSz);
|
---|
| 1029 | }
|
---|
[839] | 1030 | char ** ttype= new char*[tfields];
|
---|
| 1031 | char ** tform= new char*[tfields];
|
---|
| 1032 | char largeur[FLEN_VALUE];
|
---|
| 1033 | int noColString=0;
|
---|
[971] | 1034 | for (k=0; k<tfields;k++)
|
---|
[839] | 1035 | {
|
---|
| 1036 | char format[FLEN_VALUE];
|
---|
| 1037 |
|
---|
| 1038 | if(nentries < 1024)
|
---|
| 1039 | {
|
---|
| 1040 | nrows= nentries;
|
---|
| 1041 | if (fieldType[k] == 'A')
|
---|
| 1042 | {
|
---|
| 1043 | sprintf(largeur,"%d",taille_des_chaines[noColString++]);
|
---|
| 1044 | strcpy(format,largeur);
|
---|
| 1045 | }
|
---|
| 1046 | else strcpy(format,"1");
|
---|
| 1047 | }
|
---|
| 1048 | else
|
---|
| 1049 | {
|
---|
| 1050 | nrows = nentries/1024;
|
---|
| 1051 | if(nentries%1024 != 0) nrows++;
|
---|
| 1052 | if (fieldType[k] == 'A')
|
---|
| 1053 | {
|
---|
[1136] | 1054 | char largaux[FLEN_VALUE];
|
---|
| 1055 | sprintf(largeur,"%d",taille_des_chaines[noColString]);
|
---|
| 1056 | sprintf(largaux,"%d",1024*taille_des_chaines[noColString]);
|
---|
| 1057 | noColString++;
|
---|
| 1058 | strcpy(format, largaux);
|
---|
[839] | 1059 | }
|
---|
| 1060 | else strcpy(format,"1024");
|
---|
| 1061 | }
|
---|
| 1062 | strncat(format,&fieldType[k],1);
|
---|
| 1063 | if (fieldType[k] == 'A')
|
---|
| 1064 | {
|
---|
| 1065 | strcat(format,largeur);
|
---|
| 1066 | }
|
---|
[1193] | 1067 | ttype[k] = const_cast<char*>(Noms[k].c_str());
|
---|
[839] | 1068 | tform[k]= new char[FLEN_VALUE];
|
---|
| 1069 | strcpy(tform[k],format);
|
---|
| 1070 | }
|
---|
[1193] | 1071 | char* extn = const_cast<char*>(extname.c_str());
|
---|
[839] | 1072 |
|
---|
| 1073 | // create a new empty binary table onto the FITS file
|
---|
| 1074 | // physical units if they exist, are defined in the DVList object
|
---|
| 1075 | // so the NULL pointer is given for the tunit parameters.
|
---|
| 1076 | nrows=0;
|
---|
| 1077 | fits_create_tbl(fptr_,BINARY_TBL,nrows,tfields,ttype,tform,
|
---|
| 1078 | NULL,extn,&status);
|
---|
| 1079 | if( status ) printerror( status );
|
---|
[1026] | 1080 | if ( hdunum_ == 0 ) hdunum_ = 2;
|
---|
| 1081 | else hdunum_++;
|
---|
[971] | 1082 | int ii;
|
---|
| 1083 | for(ii = 0; ii < tfields; ii++)
|
---|
[839] | 1084 | {
|
---|
| 1085 | delete [] tform[ii];
|
---|
| 1086 | }
|
---|
| 1087 | delete [] ttype;
|
---|
| 1088 | delete [] tform;
|
---|
| 1089 | //
|
---|
| 1090 | // write supplementary keywords
|
---|
[1143] | 1091 | addKeywordsOfDVList(dvl);
|
---|
[839] | 1092 | }
|
---|
| 1093 |
|
---|
[1209] | 1094 | void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
|
---|
[839] | 1095 | {
|
---|
| 1096 | int status = 0;
|
---|
[971] | 1097 | int hdutype;
|
---|
[839] | 1098 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1099 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1100 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
[867] | 1101 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1102 | {
|
---|
| 1103 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1104 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[867] | 1105 | }
|
---|
[839] | 1106 | int code;
|
---|
| 1107 | long repeat, width;
|
---|
| 1108 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1109 | if( code != TDOUBLE)
|
---|
| 1110 | {
|
---|
[1209] | 1111 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;
|
---|
[839] | 1112 | }
|
---|
| 1113 | fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1114 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1115 | }
|
---|
[1209] | 1116 | void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
|
---|
[839] | 1117 | {
|
---|
| 1118 | int status = 0;
|
---|
| 1119 | int hdutype;
|
---|
| 1120 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1121 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1122 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1123 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1124 | {
|
---|
| 1125 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1126 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1127 | }
|
---|
| 1128 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1129 | {
|
---|
[1209] | 1130 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1131 | }
|
---|
| 1132 | int code;
|
---|
| 1133 | long repeat, width;
|
---|
| 1134 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1135 | if( code != TFLOAT)
|
---|
| 1136 | {
|
---|
[1209] | 1137 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;
|
---|
[839] | 1138 | }
|
---|
| 1139 | fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1140 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1141 | }
|
---|
[1209] | 1142 | void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
|
---|
[839] | 1143 | {
|
---|
| 1144 | int status = 0;
|
---|
| 1145 | int hdutype;
|
---|
| 1146 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1147 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1148 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1149 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1150 | {
|
---|
| 1151 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1152 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1153 | }
|
---|
| 1154 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1155 | {
|
---|
[1209] | 1156 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1157 | }
|
---|
| 1158 | int code;
|
---|
| 1159 | long repeat, width;
|
---|
| 1160 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1161 | if( code != TLONG && code != TINT && code != TSHORT )
|
---|
| 1162 | {
|
---|
[1209] | 1163 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;
|
---|
[839] | 1164 | }
|
---|
| 1165 | fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
|
---|
[971] | 1166 | if( status ) printerror( status," ecriture du fichier fits" );
|
---|
[839] | 1167 | }
|
---|
[1209] | 1168 | void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
|
---|
[839] | 1169 | {
|
---|
| 1170 | int status = 0;
|
---|
| 1171 | int hdutype;
|
---|
| 1172 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
[1209] | 1173 | if( status ) printerror(status,"PutColToFits: le movabs a foire");
|
---|
[839] | 1174 | fits_get_hdu_type(fptr_, &hdutype, &status);
|
---|
| 1175 | if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
|
---|
| 1176 | {
|
---|
| 1177 | cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
|
---|
[1209] | 1178 | throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
|
---|
[839] | 1179 | }
|
---|
| 1180 | if(hdutype == ASCII_TBL && nocol>0)
|
---|
| 1181 | {
|
---|
[1209] | 1182 | throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden");
|
---|
[839] | 1183 | }
|
---|
| 1184 | int code;
|
---|
| 1185 | long repeat, width;
|
---|
| 1186 | fits_get_coltype(fptr_, nocol+1, &code, &repeat,&width, &status);
|
---|
| 1187 | if( code != TSTRING)
|
---|
| 1188 | {
|
---|
[1209] | 1189 | cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;
|
---|
[839] | 1190 | }
|
---|
| 1191 | fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status);
|
---|
| 1192 | if( status ) printerror( status,"erreur ecriture du fichier fits" );
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[1209] | 1195 | void FitsOutFile::PutBinTabLine(long NoLine, BnTblLine& ligne) const
|
---|
[1193] | 1196 | {
|
---|
[1209] | 1197 | // on ne fait pas de verification de type, ni de dimension ici, pour
|
---|
| 1198 | // des raisons de performances
|
---|
| 1199 | int k;
|
---|
[1193] | 1200 | int status= 0;
|
---|
| 1201 | int anull;
|
---|
[1209] | 1202 | int ncol=0;
|
---|
[1193] | 1203 | long nels=1;
|
---|
[1209] | 1204 | // int nbcols;
|
---|
| 1205 | // fits_get_num_cols(fptr_, &nbcols,&status);
|
---|
| 1206 | for (k=0; k<ligne.ddata_.size(); k++, ncol++)
|
---|
[1193] | 1207 | {
|
---|
[1209] | 1208 | fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ligne.ddata_[k] ,&status);
|
---|
| 1209 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture double" );
|
---|
[1193] | 1210 | }
|
---|
[1209] | 1211 | for (k=0; k<ligne.fdata_.size(); k++, ncol++)
|
---|
| 1212 | {
|
---|
| 1213 | fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &ligne.fdata_[k] ,&status);
|
---|
| 1214 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture float" );
|
---|
| 1215 | }
|
---|
| 1216 | for (k=0; k<ligne.idata_.size(); k++, ncol++)
|
---|
| 1217 | {
|
---|
| 1218 | fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &ligne.idata_[k] ,&status);
|
---|
| 1219 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier" );
|
---|
| 1220 | }
|
---|
| 1221 |
|
---|
| 1222 | for (k=0; k<ligne.cdata_.size(); k++, ncol++)
|
---|
| 1223 | {
|
---|
| 1224 | fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, strdup(ligne.cdata_[k].c_str()) ,&status);
|
---|
| 1225 | if( status ) printerror( status, "PutBinTabLine : erreur ecriture caracteres" );
|
---|
| 1226 | }
|
---|
[1193] | 1227 | }
|
---|
| 1228 |
|
---|
| 1229 |
|
---|
[1143] | 1230 | void FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
|
---|
| 1231 | {
|
---|
| 1232 | int status = 0;
|
---|
| 1233 | int hdutype;
|
---|
| 1234 | fits_movabs_hdu(fptr_,1,&hdutype,&status);
|
---|
| 1235 | addKeywordsOfDVList(dvl);
|
---|
| 1236 | fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
|
---|
| 1237 | }
|
---|
[839] | 1238 |
|
---|
[1143] | 1239 |
|
---|
[1136] | 1240 | void FitsOutFile::writeSignatureOnFits() const
|
---|
[839] | 1241 | {
|
---|
| 1242 | int status = 0;
|
---|
| 1243 | char keyname[LEN_KEYWORD];
|
---|
| 1244 | char strval[FLEN_VALUE];
|
---|
| 1245 | char comment[FLEN_COMMENT];
|
---|
[971] | 1246 | strncpy(keyname, "CREATOR", LEN_KEYWORD);
|
---|
| 1247 | keyname[LEN_KEYWORD-1] = '\0';
|
---|
| 1248 | strcpy(strval, "SOPHYA");
|
---|
| 1249 | strcpy(comment," SOPHYA Package - FITSIOServer ");
|
---|
| 1250 | fits_write_key(fptr_, TSTRING, keyname, &strval, comment, &status);
|
---|
| 1251 | if( status ) printerror( status );
|
---|
[1143] | 1252 | fits_write_date(fptr_, &status);
|
---|
[971] | 1253 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
| 1254 | fits_write_comment(fptr_, " SOPHYA package - FITSIOSever ", &status);
|
---|
| 1255 | fits_write_comment(fptr_, " (C) LAL/IN2P3-CNRS Orsay, FRANCE 2000", &status);
|
---|
| 1256 | fits_write_comment(fptr_, " (C) DAPNIA/CEA Saclay, FRANCE 2000", &status);
|
---|
| 1257 | fits_write_comment(fptr_,"..............................................", &status);
|
---|
[1045] | 1258 | if( status ) printerror( status, "erreur writeSignatureOnFits" );
|
---|
[839] | 1259 | }
|
---|
| 1260 |
|
---|
[903] | 1261 |
|
---|
[1143] | 1262 | void FitsOutFile::addKeywordsOfDVList(DVList& dvl) const
|
---|
| 1263 | {
|
---|
| 1264 | int status = 0;
|
---|
| 1265 | fits_write_comment(fptr_,"---------- keywords from SOPHYA ---------", &status);
|
---|
| 1266 | if (hdunum_ == 1) writeSignatureOnFits();
|
---|
| 1267 | DVList::ValList::const_iterator it;
|
---|
| 1268 | for(it = dvl.Begin(); it != dvl.End(); it++)
|
---|
| 1269 | {
|
---|
| 1270 | char keytype= (*it).second.elval.typ;
|
---|
| 1271 | char keyname[10];
|
---|
| 1272 | strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
|
---|
[1183] | 1273 | string key(keyname);
|
---|
[1143] | 1274 | char comment[FLEN_COMMENT];
|
---|
| 1275 | char strval[FLEN_VALUE]= "";
|
---|
| 1276 | char *comkey = "COMMENT";
|
---|
| 1277 | fits_read_keyword(fptr_, keyname, strval, NULL, &status);
|
---|
| 1278 | if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 )
|
---|
| 1279 | {
|
---|
[1183] | 1280 | string coco = dvl.GetComment(key);
|
---|
| 1281 | coco.copy( comment, FLEN_COMMENT-1);
|
---|
| 1282 | int bout = (coco.length() < FLEN_COMMENT) ? coco.length() : FLEN_COMMENT-1;
|
---|
| 1283 | comment[bout]= '\0';
|
---|
[1143] | 1284 | status = 0;
|
---|
| 1285 | switch (keytype)
|
---|
| 1286 | {
|
---|
| 1287 | case 'I' :
|
---|
| 1288 | {
|
---|
[1183] | 1289 | int ival = (int)dvl.GetI(key);
|
---|
| 1290 | fits_write_key(fptr_,TINT,keyname,&ival, comment,&status);
|
---|
[1143] | 1291 | break;
|
---|
| 1292 | }
|
---|
| 1293 | case 'D' :
|
---|
| 1294 | {
|
---|
[1183] | 1295 | double dval= (double)dvl.GetD(key);
|
---|
[1143] | 1296 | fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
|
---|
| 1297 | break;
|
---|
| 1298 | }
|
---|
| 1299 | case 'S' :
|
---|
| 1300 | {
|
---|
[1183] | 1301 | char strvaleur[FLEN_VALUE]= "";
|
---|
| 1302 | string valChaine = dvl.GetS(key);
|
---|
| 1303 | valChaine.copy(strvaleur, FLEN_VALUE-1);
|
---|
| 1304 | int fin = (valChaine.length() < FLEN_VALUE) ? valChaine.length() : FLEN_VALUE-1;
|
---|
| 1305 | strvaleur[fin]= '\0';
|
---|
| 1306 |
|
---|
| 1307 | fits_write_key(fptr_,TSTRING,keyname,&strvaleur,comment,&status);
|
---|
[1143] | 1308 | break;
|
---|
| 1309 | }
|
---|
| 1310 | }
|
---|
| 1311 | }
|
---|
| 1312 | if( status ) printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" );
|
---|
| 1313 | }
|
---|
| 1314 | fits_write_comment(fptr_,"--------------------------------------", &status);
|
---|
| 1315 | }
|
---|
[903] | 1316 |
|
---|
| 1317 |
|
---|
[839] | 1318 |
|
---|