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