[1654] | 1 | /* Lecteur de colonne de table Fits (binaire ou ASCII) avec buffer */
|
---|
[2615] | 2 | #include "sopnamsp.h"
|
---|
[1654] | 3 | #include "machdefs.h"
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 | #include <stdio.h>
|
---|
| 6 | #include "pexceptions.h"
|
---|
| 7 | #include "fabtcolread.h"
|
---|
[2449] | 8 |
|
---|
| 9 | ///////////////////////////////////////////////////////////////////
|
---|
| 10 | ///////////////////////////////////////////////////////////////////
|
---|
| 11 | ///////////////////////////////////////////////////////////////////
|
---|
| 12 | ///////////////////////////////////////////////////////////////////
|
---|
| 13 |
|
---|
| 14 | //! Class for opening a FITS file for reading
|
---|
| 15 |
|
---|
| 16 | /*!
|
---|
| 17 | \class SOPHYA::FitsOpenFile
|
---|
| 18 | \ingroup FitsIOServer
|
---|
| 19 | Class for opening a FITS file for reading
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | /*!
|
---|
| 23 | Constructor.
|
---|
| 24 | \param fname : FITS file name to be opened for reading
|
---|
| 25 | */
|
---|
| 26 | FitsOpenFile::FitsOpenFile(string fname)
|
---|
| 27 | {
|
---|
| 28 | Init(fname.c_str());
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /*!
|
---|
| 32 | Constructor.
|
---|
| 33 | \param cfname : FITS file name to be opened for reading
|
---|
| 34 | */
|
---|
| 35 | FitsOpenFile::FitsOpenFile(const char *cfname)
|
---|
| 36 | {
|
---|
| 37 | Init(cfname);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /*!
|
---|
| 41 | Constructor by default.
|
---|
| 42 | */
|
---|
| 43 | FitsOpenFile::FitsOpenFile()
|
---|
| 44 | {
|
---|
| 45 | FitsFN = "";
|
---|
[2456] | 46 | NHdu = IHdu = HduType = 0;
|
---|
| 47 | HasBeenPos = false;
|
---|
[2449] | 48 | FitsPtr = NULL;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /*!
|
---|
| 52 | Constructor by copy.
|
---|
| 53 | */
|
---|
| 54 | FitsOpenFile::FitsOpenFile(FitsOpenFile& fof)
|
---|
| 55 | {
|
---|
[2456] | 56 | Init(fof.FileName().c_str());
|
---|
[2449] | 57 | }
|
---|
| 58 |
|
---|
| 59 | /*!
|
---|
| 60 | Destructor.
|
---|
| 61 | */
|
---|
| 62 | FitsOpenFile::~FitsOpenFile()
|
---|
| 63 | {
|
---|
| 64 | Delete();
|
---|
| 65 | FitsFN = "";
|
---|
[2456] | 66 | NHdu = IHdu = HduType = 0;
|
---|
| 67 | HasBeenPos = false;
|
---|
[2449] | 68 | }
|
---|
| 69 |
|
---|
| 70 | /*!
|
---|
| 71 | Delete routine called by the destructor.
|
---|
| 72 | */
|
---|
| 73 | void FitsOpenFile::Delete(void)
|
---|
| 74 | {
|
---|
| 75 | if(FitsPtr != NULL) {
|
---|
| 76 | int sta = 0;
|
---|
| 77 | if(fits_close_file(FitsPtr,&sta)) printerror(sta);
|
---|
| 78 | FitsPtr = NULL;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /*! Init routine called by the constructor */
|
---|
| 83 | void FitsOpenFile::Init(const char* fname)
|
---|
| 84 | {
|
---|
[2456] | 85 | // Parametres Generaux
|
---|
| 86 | FitsFN = fname;
|
---|
| 87 | NHdu = IHdu = HduType = 0;
|
---|
| 88 | HasBeenPos = false;
|
---|
| 89 | FitsPtr = NULL;
|
---|
[2449] | 90 |
|
---|
[2456] | 91 | // Ouverture du fichier
|
---|
| 92 | if(FitsFN.size() <= 0 )
|
---|
| 93 | throw ParmError("FitsOpenFile::Init: Fits file name error\n");
|
---|
[2449] | 94 |
|
---|
[2456] | 95 | int sta = 0;
|
---|
| 96 | if(fits_open_file(&FitsPtr,FitsFN.c_str(),READONLY,&sta)) {
|
---|
| 97 | printerror(sta);
|
---|
| 98 | FitsPtr = NULL;
|
---|
| 99 | throw NullPtrError("FitsOpenFile::Init: Error opening Fits file\n");
|
---|
| 100 | }
|
---|
[2449] | 101 |
|
---|
[2456] | 102 | // Get number of hdu
|
---|
| 103 | if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
|
---|
| 104 | printerror(sta);
|
---|
| 105 | NHdu = 0;
|
---|
| 106 | Delete();
|
---|
| 107 | throw NotAvailableOperation("FitsOpenFile::Init: Error getting NHdu\n");
|
---|
| 108 | }
|
---|
| 109 | if(NHdu<=0) {
|
---|
| 110 | Delete();
|
---|
| 111 | throw SzMismatchError("FitsOpenFile::Init: Bad NHdu\n");
|
---|
| 112 | }
|
---|
[2449] | 113 |
|
---|
[2456] | 114 | MoveToHDU(1);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | /*! Move to an HDU
|
---|
| 118 | \param ihdu: hdu number to move
|
---|
| 119 | \warning ihdu = [1,nhdu]
|
---|
| 120 | \return 0 if positionning failed, ihdu if success
|
---|
| 121 | */
|
---|
| 122 | int FitsOpenFile::MoveToHDU(int ihdu)
|
---|
| 123 | {
|
---|
| 124 | if(FitsPtr==NULL)
|
---|
| 125 | throw NullPtrError("FitsOpenFile::MoveToHDU: no fits file open FitsPtr==NULL\n");
|
---|
| 126 | int ihdusave = IHdu;
|
---|
| 127 | if(ihdu<=0) ihdu=1; if(ihdu>NHdu) ihdu=NHdu;
|
---|
| 128 | int sta=0;
|
---|
| 129 | if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) {
|
---|
| 130 | printerror(sta);
|
---|
| 131 | // On se repositionne ou on etait
|
---|
| 132 | fits_movabs_hdu(FitsPtr,ihdusave,&HduType,&sta);
|
---|
| 133 | IHdu = ihdusave;
|
---|
| 134 | } else IHdu = ihdu;
|
---|
| 135 | return IHdu;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | /*! Move to the first HDU of a certain type
|
---|
| 139 | \param hdutype: type of the hdu
|
---|
| 140 | \param hdudeb: start at that hdu
|
---|
| 141 | \return the type of HDU the file is positionned
|
---|
| 142 | */
|
---|
| 143 | int FitsOpenFile::MoveToFirst(int hdutype,int ihdudeb)
|
---|
| 144 | {
|
---|
| 145 | if(ihdudeb<=0) ihdudeb=1; if(ihdudeb>NHdu) ihdudeb=NHdu;
|
---|
| 146 | int ihdusave = IHdu;
|
---|
| 147 | for(int ihdu=ihdudeb;ihdu<=NHdu;ihdu++) {
|
---|
| 148 | MoveToHDU(ihdu);
|
---|
| 149 | if(HduType==hdutype) break;
|
---|
[2449] | 150 | }
|
---|
[2456] | 151 | // Si echec, on se repositionne ou on etait
|
---|
| 152 | if(HduType!=hdutype) MoveToHDU(ihdusave);
|
---|
| 153 | return HduType;
|
---|
| 154 | }
|
---|
[2449] | 155 |
|
---|
[2456] | 156 | /*! Move to the last HDU of a certain type
|
---|
| 157 | \param hdutype: type of the hdu
|
---|
| 158 | \param hdudeb: stop at that hdu
|
---|
| 159 | \return the type of HDU the file is positionned
|
---|
| 160 | */
|
---|
| 161 | int FitsOpenFile::MoveToLast(int hdutype,int ihdudeb)
|
---|
| 162 | {
|
---|
| 163 | if(ihdudeb<=0) ihdudeb=1; if(ihdudeb>NHdu) ihdudeb=NHdu;
|
---|
| 164 | int ihdusave = IHdu;
|
---|
| 165 | for(int ihdu=NHdu;ihdu>=ihdudeb;ihdu--) {
|
---|
| 166 | MoveToHDU(ihdu);
|
---|
| 167 | if(HduType==hdutype) break;
|
---|
| 168 | }
|
---|
| 169 | // Si echec, on se repositionne ou on etait
|
---|
| 170 | if(HduType!=hdutype) MoveToHDU(ihdusave);
|
---|
| 171 | return HduType;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | /*! Print */
|
---|
| 175 | void FitsOpenFile::Print(void)
|
---|
| 176 | {
|
---|
| 177 | cout<<"FitsOpenFile::Print: "<<FitsFN
|
---|
| 178 | <<" hdu="<<IHdu<<"/"<<NHdu<<" type="<<HduType
|
---|
| 179 | <<" hasbeenpos="<<HasBeenPos<<endl;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[2453] | 182 | //////////////////////////////////////////////////////////////
|
---|
| 183 | //// Methodes statiques
|
---|
| 184 | //////////////////////////////////////////////////////////////
|
---|
| 185 | /*!
|
---|
| 186 | Read a fitsheader key into double
|
---|
| 187 | \param fitsptr : cfitio pointer to Fits file
|
---|
| 188 | \param keyname : name of the key
|
---|
| 189 | \return value into double
|
---|
| 190 | */
|
---|
| 191 | double FitsOpenFile::ReadKey(fitsfile *fitsptr,char *keyname)
|
---|
| 192 | {
|
---|
[2456] | 193 | if(keyname==NULL || fitsptr==NULL) return 0.;
|
---|
[2453] | 194 | int sta=0; double val=0.;
|
---|
| 195 | if(fits_read_key(fitsptr,TDOUBLE,keyname,&val,NULL,&sta))
|
---|
| 196 | printerror(sta);
|
---|
| 197 | return val;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | /*!
|
---|
| 201 | Read a fitsheader key into long
|
---|
| 202 | \param fitsptr : cfitio pointer to Fits file
|
---|
| 203 | \param keyname : name of the key
|
---|
| 204 | \return value into long
|
---|
| 205 | */
|
---|
| 206 | long FitsOpenFile::ReadKeyL(fitsfile *fitsptr,char *keyname)
|
---|
| 207 | {
|
---|
[2456] | 208 | if(keyname==NULL || fitsptr==NULL) return 0;
|
---|
[2453] | 209 | int sta=0; long val=0;
|
---|
| 210 | if(fits_read_key(fitsptr,TLONG,keyname,&val,NULL,&sta))
|
---|
| 211 | printerror(sta);
|
---|
| 212 | return val;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | /*!
|
---|
[3128] | 216 | Read a fitsheader key into long
|
---|
| 217 | \param fitsptr : cfitio pointer to Fits file
|
---|
| 218 | \param keyname : name of the key
|
---|
| 219 | \return value into long long
|
---|
| 220 | */
|
---|
| 221 | LONGLONG FitsOpenFile::ReadKeyLL(fitsfile *fitsptr,char *keyname)
|
---|
| 222 | {
|
---|
| 223 | if(keyname==NULL || fitsptr==NULL) return 0;
|
---|
| 224 | int sta=0; LONGLONG val=0;
|
---|
| 225 | if(fits_read_key(fitsptr,TLONGLONG,keyname,&val,NULL,&sta))
|
---|
| 226 | printerror(sta);
|
---|
| 227 | return val;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | /*!
|
---|
[2453] | 231 | Read a fitsheader key into string
|
---|
| 232 | \param fitsptr : cfitio pointer to Fits file
|
---|
| 233 | \param keyname : name of the key
|
---|
| 234 | \return value into string
|
---|
| 235 | */
|
---|
| 236 | string FitsOpenFile::ReadKeyS(fitsfile *fitsptr,char *keyname)
|
---|
| 237 | {
|
---|
[2456] | 238 | if(keyname==NULL || fitsptr==NULL) return (string)"";
|
---|
[2453] | 239 | int sta=0; char val[FLEN_VALUE];
|
---|
| 240 | if(fits_read_key(fitsptr,TSTRING,keyname,val,NULL,&sta))
|
---|
| 241 | printerror(sta);
|
---|
| 242 | string sval = val;
|
---|
| 243 | return sval;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | /*!
|
---|
| 247 | CFitsIO error printing routine
|
---|
| 248 | \param sta : cfitio error return code
|
---|
| 249 | */
|
---|
| 250 | void FitsOpenFile::printerror(int sta)
|
---|
[2449] | 251 | {
|
---|
| 252 | int stat = sta;
|
---|
| 253 | fits_report_error(stdout,stat);
|
---|
| 254 | fflush(stdout);
|
---|
| 255 | return;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | ///////////////////////////////////////////////////////////////////
|
---|
| 259 | ///////////////////////////////////////////////////////////////////
|
---|
| 260 | ///////////////////////////////////////////////////////////////////
|
---|
| 261 | ///////////////////////////////////////////////////////////////////
|
---|
| 262 |
|
---|
| 263 | ///////////////////////////////////////////////////////////////////
|
---|
[1654] | 264 | //! Class for reading a column in a FITS ASCII or BINARY table
|
---|
| 265 |
|
---|
| 266 | /*!
|
---|
[2449] | 267 | \class SOPHYA::FitsABTColRd
|
---|
[1654] | 268 | \ingroup FitsIOServer
|
---|
[2789] | 269 | Class for reading a column in a FITS ASCII or BINARY table.
|
---|
| 270 | You can read many columns of the same FITS table by instanciating
|
---|
| 271 | many FitsABTColRd on the same FitsOpenFile. So, the FITS file is
|
---|
| 272 | opened only once. Of course the various FitsABTColRd must read
|
---|
| 273 | the same FITS file HDU.
|
---|
[1654] | 274 | \verbatim
|
---|
[1659] | 275 | -- Exemple:
|
---|
[2449] | 276 | // Open the fits file with FitsOpenFile
|
---|
| 277 | FitsOpenFile fof = new FitsOpenFile("myfits.fits");
|
---|
| 278 | // Select the column to be read
|
---|
| 279 | FitsABTColRd fbt(fof,"BoloMuv_28",0,1000,1,3);
|
---|
[2456] | 280 | FitsABTColRd fbt2(fof,"BoloMuv_29",0,1000,1,3);
|
---|
[1654] | 281 | fbt.SetDebug(3);
|
---|
| 282 | fbt.Print(3);
|
---|
[1659] | 283 | // Read element by element
|
---|
[3128] | 284 | for(LONGLONG i=0;i<fbt.GetNbLine();i++) {
|
---|
[1654] | 285 | double x = fbt.Read(i);
|
---|
[2456] | 286 | double y = fbt2.Read(i);
|
---|
| 287 | if(i%lpmod==0) cout<<i<<": "<<x<<", "<<y<<endl;
|
---|
[1654] | 288 | }
|
---|
[1659] | 289 | // Read into a vector
|
---|
| 290 | TVector<double> data;
|
---|
[3128] | 291 | LONGLONG n = fbt.Read(32,50,data);
|
---|
[1659] | 292 | cout<<"Number of values read: "<<n<<endl;
|
---|
| 293 | data.ReSize(100);
|
---|
| 294 | n = fbt.Read(10,-1,data);
|
---|
| 295 | cout<<"Number of values read: "<<n<<endl;
|
---|
[2456] | 296 | TVector<double> data2;
|
---|
| 297 | fbt2.Read(32,50,data);
|
---|
[2449] | 298 | // Close the fits file
|
---|
| 299 | delete fof;
|
---|
[1654] | 300 | \endverbatim
|
---|
| 301 | */
|
---|
| 302 |
|
---|
| 303 | //////////////////////////////////////////////////////////////
|
---|
| 304 | /*!
|
---|
| 305 | Constructor.
|
---|
[2449] | 306 | \param fof : Pointer to the Class for opening the FITS file
|
---|
[1659] | 307 | \param collabel : label of the column to be read
|
---|
| 308 | \param ihdu : number of the HDU where the column is.
|
---|
| 309 | \param blen : read buffer length
|
---|
| 310 | \param bsens : buffer reading direction
|
---|
| 311 | \param lp : debug level
|
---|
[1654] | 312 | \verbatim
|
---|
[2456] | 313 | - if ihdu<=0 first BINARY or ASCII table is taken
|
---|
| 314 | - if ihdu>nhdu ihdu is set to nhdu
|
---|
[1659] | 315 | - bsens>0 read forward
|
---|
| 316 | bsens<0 read backward
|
---|
| 317 | bsens==0 read centered
|
---|
[1654] | 318 | \endverbatim
|
---|
[1659] | 319 | \warning ihdu = [1,nhdu]
|
---|
[1654] | 320 | */
|
---|
[2449] | 321 | FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,string collabel
|
---|
| 322 | ,int ihdu,long blen,long bsens,int lp)
|
---|
[1654] | 323 | {
|
---|
[2449] | 324 | Init(fof,collabel.c_str(),-1,ihdu,blen,bsens,lp);
|
---|
[1654] | 325 | }
|
---|
| 326 |
|
---|
| 327 | /*!
|
---|
| 328 | Constructor.
|
---|
[1659] | 329 | Same as before but the column is identified by its column number
|
---|
| 330 | \param colnum : number of the column to be read
|
---|
| 331 | \warning col = [0,ncol[
|
---|
[1654] | 332 | */
|
---|
[2449] | 333 | FitsABTColRd::FitsABTColRd(FitsOpenFile* fof,int colnum
|
---|
| 334 | ,int ihdu,long blen,long bsens,int lp)
|
---|
[1654] | 335 | {
|
---|
[2449] | 336 | Init(fof,"",colnum,ihdu,blen,bsens,lp);
|
---|
[1654] | 337 | }
|
---|
| 338 |
|
---|
[2449] | 339 | /*! Constructor by copy */
|
---|
| 340 | FitsABTColRd::FitsABTColRd(FitsABTColRd& fbt)
|
---|
[1654] | 341 | {
|
---|
[2449] | 342 | Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str()
|
---|
[2456] | 343 | ,fbt.GetColNum(),fbt.HDU()
|
---|
[2449] | 344 | ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
|
---|
[1654] | 345 | }
|
---|
| 346 |
|
---|
[2449] | 347 | /*! Constructor by default */
|
---|
| 348 | FitsABTColRd::FitsABTColRd()
|
---|
[1654] | 349 | {
|
---|
[2449] | 350 | ColLabel = ""; ColTUnit = ""; ColTForm = "";
|
---|
| 351 | ColNum = -1; ColTypeCode = 0;
|
---|
| 352 | NBcol = 0; NBline = 0;
|
---|
| 353 | SetNulVal(); SetDebug(0);
|
---|
| 354 | NFitsRead = 0;
|
---|
[3114] | 355 | FitsOF = NULL;
|
---|
[2449] | 356 | LineDeb = LineFin = -1;
|
---|
| 357 | Buffer = NULL;
|
---|
[1654] | 358 | }
|
---|
| 359 |
|
---|
| 360 | /*! Init routine called by the constructor */
|
---|
[2449] | 361 | void FitsABTColRd::Init(FitsOpenFile* fof,const char* collabel,int colnum
|
---|
[1654] | 362 | ,int ihdu,long blen,long bsens,int lp)
|
---|
| 363 | {
|
---|
[2449] | 364 | // Initialisation des Parametres Generaux
|
---|
[2456] | 365 | ColLabel=collabel; ColTUnit=""; ColTForm=""; ColNum=colnum; ColTypeCode=0;
|
---|
| 366 | NBcol = 0; NBline = 0;
|
---|
| 367 | SetNulVal(); SetDebug(lp);
|
---|
[1654] | 368 | NFitsRead = 0;
|
---|
[3114] | 369 | FitsOF = NULL;
|
---|
[1654] | 370 | LineDeb = LineFin = -1;
|
---|
| 371 | Buffer = NULL;
|
---|
| 372 |
|
---|
[2449] | 373 | // Caracteristiques du FitsOpenFile
|
---|
| 374 | FitsOF = fof;
|
---|
[2456] | 375 | if(FitsOF==NULL)
|
---|
[2449] | 376 | throw NullPtrError("FitsABTColRd::Init: FitsOpenFile pointer is NULL\n");
|
---|
[2456] | 377 |
|
---|
[3114] | 378 | if(GetFitsPtr()==NULL)
|
---|
[2449] | 379 | throw NullPtrError("FitsABTColRd::Init: FitsPtr pointer is NULL\n");
|
---|
[1654] | 380 |
|
---|
[2449] | 381 | int sta = 0;
|
---|
[2456] | 382 | if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU();
|
---|
[2449] | 383 |
|
---|
[1654] | 384 | // Get HDU for bin/ascii table
|
---|
[2456] | 385 | // ATTENTION: le fichier est ouvert mais non positionne sur un HDU,
|
---|
| 386 | // une classe utilisant ce fichier doit le positionner sur un HDU.
|
---|
| 387 | // Par contre, si une autre classe utilise ce meme FitsOpenFile,
|
---|
| 388 | // elle ne peut le positionner que sur ce meme HDU !
|
---|
| 389 | if(FitsOF->GetPosStatus()==false) {
|
---|
| 390 | if(ihdu==0) { // find the first BINARY then the first ASCII
|
---|
| 391 | int rc = FitsOF->MoveToFirst(BINARY_TBL);
|
---|
| 392 | if(rc!=BINARY_TBL) FitsOF->MoveToFirst(ASCII_TBL);
|
---|
| 393 | } else {
|
---|
| 394 | int rc = FitsOF->MoveToHDU(ihdu);
|
---|
| 395 | if(rc!=ihdu)
|
---|
| 396 | throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n");
|
---|
[1654] | 397 | }
|
---|
[2456] | 398 | } else { // Fits file has already been positionned
|
---|
| 399 | if(ihdu>0 && ihdu!=HDU())
|
---|
| 400 | throw RangeCheckError("FitsABTColRd::Init: file already posit. at another HDU\n");
|
---|
[1654] | 401 | }
|
---|
[2456] | 402 |
|
---|
| 403 | // Check HDUType and set position status to TRUE
|
---|
| 404 | if(HDUType()!=BINARY_TBL && HDUType()!=ASCII_TBL)
|
---|
[2449] | 405 | throw TypeMismatchExc("FitsABTColRd::Init: HDU not ASCII/BINARY table\n");
|
---|
[2456] | 406 | if(DbgLevel>1) cout<<"...Init ihdu="<<ihdu<<" HduType="<<HDUType()<<endl;
|
---|
| 407 | FitsOF->SetPosStatus(true);
|
---|
[1654] | 408 |
|
---|
| 409 | // Get number of columns
|
---|
[3114] | 410 | if(fits_get_num_cols(GetFitsPtr(),&NBcol,&sta)) {
|
---|
[2456] | 411 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 412 | throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n");
|
---|
[1654] | 413 | }
|
---|
| 414 | if(DbgLevel>1) cout<<"...Init NBcol="<<NBcol<<endl;
|
---|
[2456] | 415 | if(NBcol<1)
|
---|
[2449] | 416 | throw RangeCheckError("FitsABTColRd::Init: Bad number of colums\n");
|
---|
[1654] | 417 |
|
---|
| 418 | // Get number of rows
|
---|
[3128] | 419 | if(fits_get_num_rowsll(GetFitsPtr(),&NBline,&sta)) {
|
---|
[2456] | 420 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 421 | throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n");
|
---|
[1654] | 422 | }
|
---|
| 423 | if(DbgLevel>1) cout<<"...Init NBline="<<NBline<<endl;
|
---|
[2456] | 424 | if(NBline<1)
|
---|
[2449] | 425 | throw RangeCheckError("FitsABTColRd::Init: Bad number of rows\n");
|
---|
[1654] | 426 |
|
---|
| 427 | // Get column number
|
---|
[1660] | 428 | char labelcol[128];
|
---|
[1654] | 429 | if(ColLabel.size() > 0) {
|
---|
| 430 | strcpy(labelcol,ColLabel.c_str());
|
---|
[3114] | 431 | if(fits_get_colnum(GetFitsPtr(),CASESEN,labelcol,&ColNum,&sta)) {
|
---|
[2456] | 432 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 433 | throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n");
|
---|
[1654] | 434 | }
|
---|
| 435 | ColNum--; // Convention [0,ncol[
|
---|
| 436 | }
|
---|
| 437 | if(DbgLevel>1) cout<<"...Init ColNum="<<ColNum<<endl;
|
---|
[2456] | 438 | if(ColNum<0 || ColNum>=NBcol)
|
---|
[2449] | 439 | throw RangeCheckError("FitsABTColRd::Init: Bad column number\n");
|
---|
[1654] | 440 |
|
---|
| 441 | // Get column type
|
---|
[3128] | 442 | if(fits_get_coltypell(GetFitsPtr(),ColNum+1,&ColTypeCode,NULL,NULL,&sta)) {
|
---|
[2456] | 443 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 444 | throw ParmError("FitsABTColRd::Init: Error getting column type\n");
|
---|
[1654] | 445 | }
|
---|
| 446 | if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl;
|
---|
[1660] | 447 | if(ColTypeCode==TSTRING || ColTypeCode==TCOMPLEX || ColTypeCode==TDBLCOMPLEX
|
---|
[2456] | 448 | || ColTypeCode<0 )
|
---|
[2449] | 449 | throw ParmError("FitsABTColRd::Init: Selected column is not Numerical\n");
|
---|
[1654] | 450 |
|
---|
| 451 | // Get column name back, tunit, tform
|
---|
[2174] | 452 | char tunit[64], tform[64], tdisp[64];
|
---|
[3128] | 453 | LONGLONG repeat=0; double tscale=1., tzero=0.;
|
---|
[1654] | 454 | int rc=0;
|
---|
[2456] | 455 | if(HDUType()==BINARY_TBL) {
|
---|
[3128] | 456 | fits_get_bcolparmsll(GetFitsPtr(),ColNum+1,labelcol,tunit,tform
|
---|
[2174] | 457 | ,&repeat,&tscale,&tzero,NULL,tdisp,&sta);
|
---|
[1654] | 458 | } else {
|
---|
[3128] | 459 | long repeatlng;
|
---|
| 460 | fits_get_acolparms(GetFitsPtr(),ColNum+1,labelcol,&repeatlng,tunit,tform
|
---|
[2174] | 461 | ,&tscale,&tzero,NULL,tdisp,&sta);
|
---|
[3128] | 462 | repeat = repeatlng;
|
---|
[1654] | 463 | }
|
---|
| 464 | if(rc) {
|
---|
[2456] | 465 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 466 | throw RangeCheckError("FitsABTColRd::Init: Error getting the column caracteristics\n");
|
---|
[1654] | 467 | }
|
---|
| 468 | ColLabel = labelcol;
|
---|
| 469 | ColTUnit = tunit;
|
---|
| 470 | ColTForm = tform;
|
---|
| 471 |
|
---|
[2456] | 472 | // Set the buffer for reading
|
---|
| 473 | ChangeBuffer(blen,bsens);
|
---|
| 474 |
|
---|
[1654] | 475 | if(DbgLevel)
|
---|
[2449] | 476 | cout<<"FitsABTColRd::Init Num="<<ColNum<<" Label="<<ColLabel
|
---|
[2173] | 477 | <<" TypeCode="<<ColTypeCode<<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl;
|
---|
| 478 | if(DbgLevel>1)
|
---|
[2174] | 479 | cout<<" (repeat="<<repeat<<",tscale="<<tscale<<",tzero="<<tzero
|
---|
| 480 | <<",tdisp="<<tdisp<<")"<<endl;
|
---|
[1654] | 481 |
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | /*! Destructor. */
|
---|
[2449] | 485 | FitsABTColRd::~FitsABTColRd()
|
---|
[1654] | 486 | {
|
---|
| 487 | Delete();
|
---|
| 488 | }
|
---|
| 489 |
|
---|
[2449] | 490 | /*! Delete called by the destructor */
|
---|
| 491 | void FitsABTColRd::Delete(void)
|
---|
[1814] | 492 | {
|
---|
[2449] | 493 | if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
|
---|
| 494 | LineDeb = LineFin = -1;
|
---|
| 495 | //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
|
---|
[1814] | 496 | }
|
---|
[1654] | 497 |
|
---|
| 498 | //////////////////////////////////////////////////////////////
|
---|
[1659] | 499 | /*! Change the buffer caracteristiques (see creator) */
|
---|
[2449] | 500 | void FitsABTColRd::ChangeBuffer(long blen,long bsens)
|
---|
[1654] | 501 | {
|
---|
[1657] | 502 | long oldnbuffer = NBuffer;
|
---|
| 503 |
|
---|
| 504 | // Compute buffer caracteristics
|
---|
[1654] | 505 | BuffLen = (blen<=0)? 1: blen;
|
---|
| 506 | BuffSens = bsens;
|
---|
[1657] | 507 | NBuffer = BuffLen;
|
---|
| 508 | if(bsens==0 && NBuffer%2==0) NBuffer++;
|
---|
[1654] | 509 |
|
---|
[1657] | 510 | // De-allocate if necessary
|
---|
[1659] | 511 | if(Buffer!=NULL) {
|
---|
| 512 | // On des-alloue si pas assez de place
|
---|
| 513 | // ou si l'ancienne place est beaucoup trop grande (>25%)
|
---|
| 514 | if(oldnbuffer<NBuffer || (oldnbuffer>NBuffer+long(0.25*NBuffer)) )
|
---|
| 515 | {delete [] Buffer; Buffer=NULL;}
|
---|
| 516 | }
|
---|
[1654] | 517 |
|
---|
[1657] | 518 | // Re-allocate
|
---|
| 519 | if(Buffer==NULL) Buffer = new double[NBuffer];
|
---|
| 520 |
|
---|
[1654] | 521 | // Tell program that nothing is into buffer
|
---|
| 522 | LineDeb = LineFin = -1;
|
---|
| 523 | }
|
---|
| 524 |
|
---|
[2449] | 525 | //////////////////////////////////////////////////////////////
|
---|
[2451] | 526 | /*!
|
---|
| 527 | Read a fitsheader key into double
|
---|
| 528 | \param keyname : name of the key
|
---|
| 529 | \return value into double
|
---|
| 530 | */
|
---|
[2449] | 531 | double FitsABTColRd::ReadKey(char *keyname)
|
---|
[1654] | 532 | {
|
---|
[3114] | 533 | return FitsOpenFile::ReadKey(GetFitsPtr(),keyname);
|
---|
[1654] | 534 | }
|
---|
| 535 |
|
---|
[2451] | 536 | /*!
|
---|
| 537 | Read a fitsheader key into long
|
---|
| 538 | \param keyname : name of the key
|
---|
| 539 | \return value into long
|
---|
| 540 | */
|
---|
| 541 | long FitsABTColRd::ReadKeyL(char *keyname)
|
---|
| 542 | {
|
---|
[3114] | 543 | return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname);
|
---|
[2451] | 544 | }
|
---|
| 545 |
|
---|
| 546 | /*!
|
---|
[3128] | 547 | Read a fitsheader key into long long
|
---|
| 548 | \param keyname : name of the key
|
---|
| 549 | \return value into long long
|
---|
| 550 | */
|
---|
| 551 | LONGLONG FitsABTColRd::ReadKeyLL(char *keyname)
|
---|
| 552 | {
|
---|
| 553 | return FitsOpenFile::ReadKeyLL(GetFitsPtr(),keyname);
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | /*!
|
---|
[2451] | 557 | Read a fitsheader key into string
|
---|
| 558 | \param keyname : name of the key
|
---|
| 559 | \return value into string
|
---|
| 560 | */
|
---|
| 561 | string FitsABTColRd::ReadKeyS(char *keyname)
|
---|
| 562 | {
|
---|
[3114] | 563 | return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname);
|
---|
[2451] | 564 | }
|
---|
| 565 |
|
---|
[1654] | 566 | /////////////////////////////////////////////////
|
---|
| 567 | /*!
|
---|
[1659] | 568 | Read row "n" and return the value into a double
|
---|
| 569 | \warning be carefull for the range: row = [0,NRows[
|
---|
| 570 | \return value in double
|
---|
| 571 | \param n : number of the row to be read.
|
---|
[1654] | 572 | \verbatim
|
---|
[1659] | 573 | usebuffer == true : use read optimisation with bufferisation
|
---|
| 574 | == false : no optimisation with bufferisation
|
---|
| 575 | just read one value
|
---|
[1654] | 576 | \endverbatim
|
---|
| 577 | */
|
---|
[3128] | 578 | double FitsABTColRd::Read(LONGLONG n,bool usebuffer)
|
---|
[1654] | 579 | // Attention: n=nline [0,NBline[, cfistio veut [1,NBline]
|
---|
| 580 | // Attention: colnum [0,NBcol[ , cfistio veut [1,NBcol]
|
---|
| 581 | {
|
---|
[1659] | 582 | int sta=0;
|
---|
[1654] | 583 | if(n<0 || n>=NBline)
|
---|
[2449] | 584 | throw RangeCheckError("FitsABTColRd::Read try to read outside line range\n");
|
---|
[1654] | 585 |
|
---|
| 586 | // Pas de bufferisation, on lit betement
|
---|
[1659] | 587 | if(NBuffer==1 || !usebuffer) {
|
---|
[1654] | 588 | NFitsRead++;
|
---|
[1659] | 589 | double val;
|
---|
[3114] | 590 | fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n+1,1,1,NULL,&val,NULL,&sta);
|
---|
[1654] | 591 | if(sta) {
|
---|
[2453] | 592 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 593 | throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n");
|
---|
[1654] | 594 | }
|
---|
[1659] | 595 | // On ne remplit Buffer[0] que si on a choisit
|
---|
| 596 | // un mode de lecture non bufferise (n==1) DES LE DEBUT.
|
---|
| 597 | // Si on a initialement choisit un mode bufferise (avec n>1),
|
---|
| 598 | // Buffer contient les valeurs chargees auparavent.
|
---|
| 599 | // Il ne faut pas faire {Buffer[0]=val; LineDeb=LineFin=n;}
|
---|
| 600 | // car on perd l'info de ces valeurs.
|
---|
| 601 | if(NBuffer==1) {Buffer[0]=val; LineDeb=LineFin=n;}
|
---|
| 602 | return val;
|
---|
[1654] | 603 | }
|
---|
| 604 |
|
---|
| 605 | // Gestion avec bufferisation
|
---|
[1659] | 606 | if(!Buffer)
|
---|
[2449] | 607 | throw RangeCheckError("FitsABTColRd::Read: Buffer not allocated\n");
|
---|
[1654] | 608 | if(n<LineDeb || n>LineFin) {
|
---|
| 609 | NFitsRead++;
|
---|
[3128] | 610 | LONGLONG row1,row2,nrow;
|
---|
[1654] | 611 | if(BuffSens>0) { // Cas remplissage forward
|
---|
| 612 | row1 = n+1;
|
---|
[1657] | 613 | row2 = row1+NBuffer-1; if(row2>NBline) row2 = NBline;
|
---|
[1654] | 614 | } else if(BuffSens<0) { // Cas remplissage backward
|
---|
| 615 | row2 = n+1;
|
---|
[1657] | 616 | row1 = row2-NBuffer+1; if(row1<1) row1 = 1;
|
---|
[1654] | 617 | } else { // Cas remplissage centre
|
---|
[1657] | 618 | row1 = n+1 - NBuffer/2; if(row1<1) row1 = 1;
|
---|
| 619 | row2 = n+1 + NBuffer/2; if(row2>NBline) row2 = NBline;
|
---|
[1654] | 620 | }
|
---|
| 621 | nrow = row2 - row1 + 1;
|
---|
| 622 | LineDeb = row1-1; LineFin = row2-1;
|
---|
| 623 | //cout<<"DBG-FitsRead: row1="<<row1<<" row2="<<row2<<" nrow="<<nrow
|
---|
| 624 | // <<" LineDeb,Fin="<<LineDeb<<","<<LineFin<<endl;
|
---|
[3114] | 625 | fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,row1,1,nrow,NULL,Buffer,NULL,&sta);
|
---|
[1654] | 626 | if(sta) {
|
---|
[2453] | 627 | FitsOpenFile::printerror(sta);
|
---|
[1654] | 628 | LineDeb = LineFin = -1;
|
---|
[2449] | 629 | throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n");
|
---|
[1654] | 630 | }
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | long ibuf = n-LineDeb;
|
---|
| 634 | return Buffer[ibuf];
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | /*!
|
---|
[1659] | 638 | Read rows from "n1" to "n2" and return the values into TVector of double
|
---|
| 639 | \return NREAD the number of values read (n2-n1+1).
|
---|
| 640 | \warning row = [0,NRows[, the routine read [n1,n2]
|
---|
[1654] | 641 | \verbatim
|
---|
[1659] | 642 | - if n2<0 then read [n1,n2] where "n2=min(n1+vector_size-1,nrows-1)"
|
---|
| 643 | - Last row read is ALWAYS: "n2 = n1 + NREAD -1"
|
---|
| 644 | - The TVector is never resized if not necessary
|
---|
| 645 | -------------------------------------------------------------------------
|
---|
| 646 | - ex: suppose the column table contains 10 elements: nrows=10, rows=[0,9]
|
---|
| 647 |
|
---|
| 648 | TVector<double> V(5);
|
---|
| 649 | bt.Read(3,5,V) -> read rows=3,4,5 -> V.Size()==5 -> return 3
|
---|
| 650 | bt.Read(3,-1,V) -> read rows=3,4,5,6,7 -> V.Size()==5 -> return 5
|
---|
| 651 | bt.Read(7,-1,V) -> read rows=7,8,9 -> V.Size()==5 -> return 3
|
---|
| 652 | bt.Read(2,-1,V) -> read rows=2,3,4,5,6 -> V.Size()==5 -> return 5
|
---|
| 653 | bt.Read(-1,5,V) -> throw exception
|
---|
| 654 |
|
---|
| 655 | TVector<double> V(5);
|
---|
| 656 | bt.Read(3,99,V) -> read rows=3,4,5,6,7,8,9 -> V.Size()==7 -> return 7
|
---|
| 657 |
|
---|
| 658 | TVector<double> V(5);
|
---|
| 659 | bt.Read(2,8,V) -> read rows=2,3,4,5,6,7,8 -> V.Size()==7 -> return 7
|
---|
| 660 |
|
---|
| 661 | TVector<double> V;
|
---|
| 662 | bt.Read(3,5,V) -> read rows=3,4,5 -> V.Size()==3 -> return 3
|
---|
| 663 |
|
---|
| 664 | TVector<double> V;
|
---|
| 665 | bt.Read(3,-1,V) -> throw exception
|
---|
| 666 | -------------------------------------------------------------------------
|
---|
[1654] | 667 | \endverbatim
|
---|
| 668 | */
|
---|
[3128] | 669 | LONGLONG FitsABTColRd::Read(LONGLONG n1,LONGLONG n2,TVector<double>& data)
|
---|
[1654] | 670 | {
|
---|
[1659] | 671 | if(n1<0 || n1>=NBline)
|
---|
[2449] | 672 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
|
---|
[1659] | 673 | if(data.Size()<=0 && n2<n1)
|
---|
[2449] | 674 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
|
---|
[1659] | 675 | if(n2<0) n2 = n1 + data.Size()-1;
|
---|
| 676 | if(n2>=NBline) n2 = NBline-1;
|
---|
[1654] | 677 |
|
---|
[3128] | 678 | LONGLONG nread = n2-n1+1;
|
---|
[1659] | 679 | if(data.Size()<nread) data.SetSize(nread);
|
---|
| 680 |
|
---|
[3128] | 681 | //for(LONGLONG i=n1;i<=n2;i++) data(i-n1) = Read(i);
|
---|
[1659] | 682 | int sta=0;
|
---|
[3114] | 683 | fits_read_col(GetFitsPtr(),TDOUBLE,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);
|
---|
[1659] | 684 | if(sta) {
|
---|
[2453] | 685 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 686 | throw NotAvailableOperation("FitsABTColRd::Read_TVector<double>: Error Reading Fits file\n");
|
---|
[1659] | 687 | }
|
---|
| 688 |
|
---|
| 689 | return nread;
|
---|
[1654] | 690 | }
|
---|
| 691 |
|
---|
[1659] | 692 | /*! idem before but for TVector of float */
|
---|
[3128] | 693 | LONGLONG FitsABTColRd::Read(LONGLONG n1,LONGLONG n2,TVector<float>& data)
|
---|
[1659] | 694 | {
|
---|
| 695 | if(n1<0 || n1>=NBline)
|
---|
[2449] | 696 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
|
---|
[1659] | 697 | if(data.Size()<=0 && n2<n1)
|
---|
[2449] | 698 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
|
---|
[1659] | 699 | if(n2<0) n2 = n1 + data.Size()-1;
|
---|
| 700 | if(n2>=NBline) n2 = NBline-1;
|
---|
| 701 |
|
---|
[3128] | 702 | LONGLONG nread = n2-n1+1;
|
---|
[1659] | 703 | if(data.Size()<nread) data.SetSize(nread);
|
---|
| 704 |
|
---|
[3128] | 705 | //for(LONGLONG i=n1;i<=n2;i++) data(i-n1) = Read(i);
|
---|
[1659] | 706 | int sta=0;
|
---|
[3114] | 707 | fits_read_col(GetFitsPtr(),TFLOAT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);
|
---|
[1659] | 708 | if(sta) {
|
---|
[2453] | 709 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 710 | throw NotAvailableOperation("FitsABTColRd::Read_TVector<float>: Error Reading Fits file\n");
|
---|
[1659] | 711 | }
|
---|
| 712 |
|
---|
| 713 | return nread;
|
---|
| 714 | }
|
---|
| 715 |
|
---|
[2170] | 716 | /*! idem before but for TVector of unsigned short */
|
---|
[3128] | 717 | LONGLONG FitsABTColRd::Read(LONGLONG n1,LONGLONG n2,TVector<uint_2>& data)
|
---|
[2170] | 718 | {
|
---|
| 719 | if(n1<0 || n1>=NBline)
|
---|
[2449] | 720 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
|
---|
[2170] | 721 | if(data.Size()<=0 && n2<n1)
|
---|
[2449] | 722 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
|
---|
[2170] | 723 | if(n2<0) n2 = n1 + data.Size()-1;
|
---|
| 724 | if(n2>=NBline) n2 = NBline-1;
|
---|
| 725 |
|
---|
[3128] | 726 | LONGLONG nread = n2-n1+1;
|
---|
[2170] | 727 | if(data.Size()<nread) data.SetSize(nread);
|
---|
| 728 |
|
---|
| 729 | int sta=0;
|
---|
[3114] | 730 | fits_read_col(GetFitsPtr(),TUSHORT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);
|
---|
[2170] | 731 | if(sta) {
|
---|
[2453] | 732 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 733 | throw NotAvailableOperation("FitsABTColRd::Read_TVector<uint_2>: Error Reading Fits file\n");
|
---|
[2170] | 734 | }
|
---|
| 735 |
|
---|
| 736 | return nread;
|
---|
| 737 | }
|
---|
| 738 |
|
---|
[1659] | 739 | /*! idem before but for TVector of int_4 */
|
---|
[3128] | 740 | LONGLONG FitsABTColRd::Read(LONGLONG n1,LONGLONG n2,TVector<int_4>& data)
|
---|
[1659] | 741 | {
|
---|
| 742 | if(n1<0 || n1>=NBline)
|
---|
[2449] | 743 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
|
---|
[1659] | 744 | if(data.Size()<=0 && n2<n1)
|
---|
[2449] | 745 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
|
---|
[1659] | 746 | if(n2<0) n2 = n1 + data.Size()-1;
|
---|
| 747 | if(n2>=NBline) n2 = NBline-1;
|
---|
| 748 |
|
---|
[3128] | 749 | LONGLONG nread = n2-n1+1;
|
---|
[1659] | 750 | if(data.Size()<nread) data.SetSize(nread);
|
---|
| 751 |
|
---|
[3128] | 752 | //for(LONGLONG i=n1;i<=n2;i++) data(i-n1) = Read(i);
|
---|
[1659] | 753 | int sta=0;
|
---|
| 754 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
[3114] | 755 | fits_read_col(GetFitsPtr(),T,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);
|
---|
[1659] | 756 | if(sta) {
|
---|
[2453] | 757 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 758 | throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_4>: Error Reading Fits file\n");
|
---|
[1659] | 759 | }
|
---|
| 760 |
|
---|
| 761 | return nread;
|
---|
| 762 | }
|
---|
| 763 |
|
---|
[2169] | 764 | /*! idem before but for TVector of int_8 */
|
---|
[3128] | 765 | LONGLONG FitsABTColRd::Read(LONGLONG n1,LONGLONG n2,TVector<int_8>& data)
|
---|
[2169] | 766 | {
|
---|
| 767 | #ifdef TLONGLONG
|
---|
| 768 | if(n1<0 || n1>=NBline)
|
---|
[2449] | 769 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 1srt line \n");
|
---|
[2169] | 770 | if(data.Size()<=0 && n2<n1)
|
---|
[2449] | 771 | throw RangeCheckError("FitsABTColRd::Read TVector bad requested 2sd line \n");
|
---|
[2169] | 772 | if(n2<0) n2 = n1 + data.Size()-1;
|
---|
| 773 | if(n2>=NBline) n2 = NBline-1;
|
---|
| 774 |
|
---|
[3128] | 775 | LONGLONG nread = n2-n1+1;
|
---|
[2169] | 776 | if(data.Size()<nread) data.SetSize(nread);
|
---|
| 777 |
|
---|
| 778 | int sta=0;
|
---|
[3114] | 779 | fits_read_col(GetFitsPtr(),TLONGLONG,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta);
|
---|
[2169] | 780 | if(sta) {
|
---|
[2453] | 781 | FitsOpenFile::printerror(sta);
|
---|
[2449] | 782 | throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_8>: Error Reading Fits file\n");
|
---|
[2169] | 783 | }
|
---|
| 784 |
|
---|
| 785 | return nread;
|
---|
| 786 | #else
|
---|
[2449] | 787 | throw PException("FitsABTColRd::Read(..,TVector<int_8>&) Not in that cfitsio version");
|
---|
[2169] | 788 | #endif
|
---|
| 789 | }
|
---|
| 790 |
|
---|
[1654] | 791 | /////////////////////////////////////////////////
|
---|
[1659] | 792 | /*!
|
---|
| 793 | Return the number of the first row where "val1"<=val<="val2" starting at row "rowstart"
|
---|
| 794 | \verbatim
|
---|
| 795 | - The search is performed from "rowstart" to the end
|
---|
| 796 | in ascending order (from "rowstart" to nrows).
|
---|
| 797 | - Warning: "rowstart<0" means "rowstart==0" (search all the table column)
|
---|
| 798 | That is the default
|
---|
| 799 | \endverbatim
|
---|
| 800 | \return <0 means not found
|
---|
| 801 | */
|
---|
[3128] | 802 | LONGLONG FitsABTColRd::FirstRow(double val1,double val2,LONGLONG rowstart)
|
---|
[1659] | 803 | {
|
---|
[3128] | 804 | LONGLONG row = -1;
|
---|
[1659] | 805 | if(NBline==0) return row;
|
---|
| 806 | // Change buffer for efficiency
|
---|
| 807 | long bsens=BuffSens; bool bchange=false;
|
---|
| 808 | if(bsens<=0) {ChangeBuffer(BuffLen,1); bchange=true;}
|
---|
| 809 | if(rowstart<0) rowstart = 0;
|
---|
| 810 | if(rowstart>=NBline) rowstart = NBline-1;
|
---|
[3128] | 811 | for(LONGLONG i=rowstart;i<NBline;i++) {
|
---|
[1659] | 812 | double val = Read(i);
|
---|
| 813 | if(val<val1 || val>val2) continue;
|
---|
| 814 | row = i;
|
---|
| 815 | break;
|
---|
| 816 | }
|
---|
| 817 | if(bchange) ChangeBuffer(BuffLen,bsens);
|
---|
| 818 | return row;
|
---|
| 819 | }
|
---|
| 820 |
|
---|
| 821 | /*!
|
---|
| 822 | Return the number of the first row where val1<=val<=val2 starting at row rowstart
|
---|
| 823 | \return <0 means not found
|
---|
| 824 | \verbatim
|
---|
| 825 | - The search is performed from "rowstart" to the beginning
|
---|
| 826 | in descending order (from "rowstart" to 0).
|
---|
| 827 | - Warning: "rowstart<0" means "rowstart==nrows-1" (search all the table column)
|
---|
| 828 | That is the default
|
---|
| 829 | \endverbatim
|
---|
| 830 | */
|
---|
[3128] | 831 | LONGLONG FitsABTColRd::LastRow(double val1,double val2,LONGLONG rowstart)
|
---|
[1659] | 832 | {
|
---|
[3128] | 833 | LONGLONG row = -1;
|
---|
[1659] | 834 | if(NBline==0) return row;
|
---|
| 835 | // Change buffer for efficiency
|
---|
| 836 | long bsens=BuffSens; bool bchange=false;
|
---|
| 837 | if(bsens>=0) {ChangeBuffer(BuffLen,-1); bchange=true;}
|
---|
| 838 | if(rowstart<0 || rowstart>=NBline) rowstart = NBline-1;
|
---|
[3128] | 839 | for(LONGLONG i=rowstart;i>=0;i--) {
|
---|
[1659] | 840 | double val = Read(i);
|
---|
| 841 | if(val<val1 || val>val2) continue;
|
---|
| 842 | row = i;
|
---|
| 843 | break;
|
---|
| 844 | }
|
---|
| 845 | if(bchange) ChangeBuffer(BuffLen,bsens);
|
---|
| 846 | return row;
|
---|
| 847 | }
|
---|
| 848 |
|
---|
[1654] | 849 | /*! Print on stream os */
|
---|
[2449] | 850 | void FitsABTColRd::Print(ostream& os,int lp) const
|
---|
[1654] | 851 | {
|
---|
[2449] | 852 | os<<"FitsABTColRd:Print ("<<BuffLen<<","<<BuffSens<<","<<NulVal<<")"
|
---|
[1654] | 853 | <<" ncols="<<NBcol<<" nrows="<<NBline;
|
---|
| 854 | if(lp>0) os<<" NRead="<<NFitsRead;
|
---|
[2456] | 855 | os<<"\n... "<<FileName()<<"["<<HDU()<<"/"<<NHDU()<<" type="<<HDUType()<<"]"
|
---|
| 856 | <<"\n... Label["<<ColNum<<"]="<<ColLabel<<" TypeCode="<<ColTypeCode
|
---|
[1654] | 857 | <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm
|
---|
| 858 | <<endl;
|
---|
| 859 | }
|
---|
[2449] | 860 |
|
---|
| 861 | ///////////////////////////////////////////////////////////////////
|
---|
| 862 | ///////////////////////////////////////////////////////////////////
|
---|
| 863 | ///////////////////////////////////////////////////////////////////
|
---|
| 864 | ///////////////////////////////////////////////////////////////////
|
---|
| 865 |
|
---|
| 866 | //! Class for reading a column in a FITS ASCII or BINARY table with fits file opening
|
---|
| 867 |
|
---|
| 868 | /*!
|
---|
| 869 | \class SOPHYA::FitsABTColRead
|
---|
| 870 | \ingroup FitsIOServer
|
---|
[2789] | 871 | Class for reading a column in a FITS ASCII or BINARY table with fits file opening.
|
---|
| 872 | The FITS file is opened each time you instanciate a FitsABTColRead.
|
---|
| 873 | So reading "n" columns of the same FITS table by instanciating "n"
|
---|
| 874 | FitsABTColRead, will open "n" times te FITS file.
|
---|
| 875 | Use FitsABTColRd if you want to open the FITS file only once.
|
---|
[2449] | 876 | \verbatim
|
---|
| 877 | -- Exemple:
|
---|
| 878 | FitsABTColRead fbt("myfits.fits","BoloMuv_28",0,1000,1,3);
|
---|
| 879 | fbt.SetDebug(3);
|
---|
| 880 | fbt.Print(3);
|
---|
| 881 | // Read element by element
|
---|
[3128] | 882 | for(LONGLONG i=0;i<fbt.GetNbLine();i++) {
|
---|
[2449] | 883 | double x = fbt.Read(i);
|
---|
| 884 | if(i%lpmod==0) cout<<i<<": "<<x<<endl;
|
---|
| 885 | }
|
---|
| 886 | // Read into a vector
|
---|
| 887 | TVector<double> data;
|
---|
[3128] | 888 | LONGLONG n = fbt.Read(32,50,data);
|
---|
[2449] | 889 | cout<<"Number of values read: "<<n<<endl;
|
---|
| 890 | data.ReSize(100);
|
---|
| 891 | n = fbt.Read(10,-1,data);
|
---|
| 892 | cout<<"Number of values read: "<<n<<endl;
|
---|
| 893 | \endverbatim
|
---|
| 894 | */
|
---|
| 895 |
|
---|
| 896 |
|
---|
| 897 | //////////////////////////////////////////////////////////////
|
---|
| 898 | /*!
|
---|
| 899 | Constructor.
|
---|
| 900 | \param fname : FITS file name to be read
|
---|
| 901 | \param collabel : label of the column to be read
|
---|
| 902 | \param ihdu : number of the HDU where the column is.
|
---|
| 903 | \param blen : read buffer length
|
---|
| 904 | \param bsens : buffer reading direction
|
---|
| 905 | \param lp : debug level
|
---|
| 906 | \verbatim
|
---|
[2456] | 907 | - if ihdu<=0 first BINARY or ASCII table is taken
|
---|
| 908 | - if ihdu>nhdu ihdu is set to nhdu
|
---|
[2449] | 909 | - bsens>0 read forward
|
---|
| 910 | bsens<0 read backward
|
---|
| 911 | bsens==0 read centered
|
---|
| 912 | \endverbatim
|
---|
| 913 | \warning ihdu = [1,nhdu]
|
---|
| 914 | */
|
---|
| 915 | FitsABTColRead::FitsABTColRead(string fname,string collabel
|
---|
| 916 | ,int ihdu,long blen,long bsens,int lp)
|
---|
| 917 | : FitsABTColRd(new FitsOpenFile(fname),collabel,ihdu,blen,bsens,lp)
|
---|
| 918 | {
|
---|
| 919 | }
|
---|
| 920 |
|
---|
| 921 | /*!
|
---|
| 922 | Constructor.
|
---|
| 923 | Same as before but the column is identified by its column number
|
---|
| 924 | \param colnum : number of the column to be read
|
---|
| 925 | \warning col = [0,ncol[
|
---|
| 926 | */
|
---|
| 927 | FitsABTColRead::FitsABTColRead(string fname,int colnum
|
---|
| 928 | ,int ihdu,long blen,long bsens,int lp)
|
---|
| 929 | : FitsABTColRd(new FitsOpenFile(fname),colnum,ihdu,blen,bsens,lp)
|
---|
| 930 | {
|
---|
| 931 | }
|
---|
| 932 |
|
---|
| 933 | /*! Constructor. see below */
|
---|
| 934 | FitsABTColRead::FitsABTColRead(const char * cfname,const char* collabel
|
---|
| 935 | ,int ihdu,long blen,long bsens,int lp)
|
---|
| 936 | : FitsABTColRd(new FitsOpenFile(cfname),collabel,ihdu,blen,bsens,lp)
|
---|
| 937 | {
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | /*! Constructor. see below */
|
---|
| 941 | FitsABTColRead::FitsABTColRead(const char * cfname,int colnum
|
---|
| 942 | ,int ihdu,long blen,long bsens,int lp)
|
---|
| 943 | : FitsABTColRd(new FitsOpenFile(cfname),colnum,ihdu,blen,bsens,lp)
|
---|
| 944 | {
|
---|
| 945 | }
|
---|
| 946 | /*! Constructor by default */
|
---|
| 947 | FitsABTColRead::FitsABTColRead()
|
---|
[2791] | 948 | : FitsABTColRd()
|
---|
[2449] | 949 | {
|
---|
| 950 | }
|
---|
| 951 |
|
---|
| 952 | /*! Constructor by copy */
|
---|
| 953 | FitsABTColRead::FitsABTColRead(FitsABTColRead& fbt)
|
---|
| 954 | {
|
---|
| 955 | // --- ATTENTION ---
|
---|
| 956 | // FitsABTColRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
|
---|
| 957 | FitsOpenFile* fof = new FitsOpenFile(*fbt.GetFitsOpenFile());
|
---|
| 958 | Init(fof,fbt.GetColLabel().c_str()
|
---|
[2456] | 959 | ,fbt.GetColNum(),fbt.HDU()
|
---|
[2449] | 960 | ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
|
---|
| 961 | }
|
---|
| 962 |
|
---|
| 963 | /*! Destructor. */
|
---|
| 964 | FitsABTColRead::~FitsABTColRead()
|
---|
| 965 | {
|
---|
[2789] | 966 | Delete(); // ?? inutile ??
|
---|
| 967 | // On detruit le FitsOpenFile, cad qu'on ferme (fits_file_close) le fichier FITS
|
---|
[2449] | 968 | if(FitsOF!=NULL) delete FitsOF;
|
---|
| 969 | }
|
---|
[2453] | 970 |
|
---|
| 971 | ///////////////////////////////////////////////////////////////////
|
---|
[2791] | 972 | ///////////////////////////////////////////////////////////////////
|
---|
| 973 | ///////////////////////////////////////////////////////////////////
|
---|
| 974 | ///////////////////////////////////////////////////////////////////
|
---|
| 975 |
|
---|
[2453] | 976 | //! Class for reading a 2D image from a FITS file
|
---|
| 977 |
|
---|
| 978 | /*!
|
---|
| 979 | \class SOPHYA::FitsImg2DRd
|
---|
| 980 | \ingroup FitsIOServer
|
---|
| 981 | Class for reading a 2D image from a FITS file
|
---|
| 982 | */
|
---|
| 983 |
|
---|
| 984 | //////////////////////////////////////////////////////////////
|
---|
| 985 | /*!
|
---|
| 986 | Constructor.
|
---|
| 987 | \param fof : Pointer to the Class for opening the FITS file
|
---|
[2456] | 988 | \param ihdu : number of the HDU where the image is.
|
---|
[2453] | 989 | \param lp : debug level
|
---|
| 990 | \verbatim
|
---|
[2456] | 991 | - if ihdu<=0 first IMAGE hdu is taken
|
---|
| 992 | - if ihdu>nhdu ihdu is set to nhdu
|
---|
[2453] | 993 | \endverbatim
|
---|
| 994 | \warning ihdu = [1,nhdu]
|
---|
| 995 | */
|
---|
| 996 | FitsImg2DRd::FitsImg2DRd(FitsOpenFile* fof,int ihdu,int lp)
|
---|
| 997 | {
|
---|
| 998 | Init(fof,ihdu,lp);
|
---|
| 999 | }
|
---|
| 1000 |
|
---|
| 1001 | /*! Constructor by copy */
|
---|
| 1002 | FitsImg2DRd::FitsImg2DRd(FitsImg2DRd& fbt)
|
---|
| 1003 | {
|
---|
[2456] | 1004 | Init(fbt.GetFitsOpenFile(),fbt.HDU(),fbt.DbgLevel);
|
---|
[2453] | 1005 | }
|
---|
| 1006 |
|
---|
| 1007 | /*! Constructor by default */
|
---|
| 1008 | FitsImg2DRd::FitsImg2DRd()
|
---|
| 1009 | {
|
---|
| 1010 | Naxis[0] = Naxis[1] = 0;
|
---|
| 1011 | SetNulVal(); SetDebug(0);
|
---|
[3114] | 1012 | FitsOF = NULL;
|
---|
[2453] | 1013 | }
|
---|
| 1014 |
|
---|
| 1015 | /*! Init routine called by the constructor */
|
---|
| 1016 | void FitsImg2DRd::Init(FitsOpenFile* fof,int ihdu,int lp)
|
---|
| 1017 | {
|
---|
| 1018 | // Initialisation des Parametres Generaux
|
---|
| 1019 | Naxis[0] = Naxis[1] = 0;
|
---|
| 1020 | SetNulVal(); SetDebug(lp);
|
---|
[3114] | 1021 | FitsOF = NULL;
|
---|
[2453] | 1022 |
|
---|
| 1023 | // Caracteristiques du FitsOpenFile
|
---|
| 1024 | FitsOF = fof;
|
---|
| 1025 | if(FitsOF==NULL)
|
---|
| 1026 | throw NullPtrError("FitsImg2DRd::Init: FitsOpenFile pointer is NULL\n");
|
---|
[2456] | 1027 |
|
---|
[3114] | 1028 | if(GetFitsPtr()==NULL)
|
---|
[2453] | 1029 | throw NullPtrError("FitsImg2DRd::Init: FitsPtr pointer is NULL\n");
|
---|
| 1030 |
|
---|
| 1031 | int sta = 0;
|
---|
[2456] | 1032 | if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU();
|
---|
[2453] | 1033 |
|
---|
| 1034 | // Get HDU 2D image
|
---|
[2456] | 1035 | // ATTENTION: ... cf blabla equivalent dans FitsABTColRd::Init()
|
---|
| 1036 | if(FitsOF->GetPosStatus()==false) {
|
---|
| 1037 | if(ihdu==0) { // find the first IMAGE_HDU
|
---|
| 1038 | FitsOF->MoveToFirst(IMAGE_HDU);
|
---|
| 1039 | } else {
|
---|
| 1040 | int rc = FitsOF->MoveToHDU(ihdu);
|
---|
| 1041 | if(rc!=ihdu)
|
---|
[3114] | 1042 | throw RangeCheckError("FitsImg2DRd::Init: Error moving to requested HDU\n");
|
---|
[2453] | 1043 | }
|
---|
[2456] | 1044 | } else { // Fits file has already been positionned
|
---|
| 1045 | if(ihdu>0 && ihdu!=HDU())
|
---|
[3114] | 1046 | throw RangeCheckError("FitsImg2DRd::Init: file already posit. at another HDU\n");
|
---|
[2453] | 1047 | }
|
---|
[2456] | 1048 |
|
---|
| 1049 | // Check HDUType and set position status to TRUE
|
---|
| 1050 | if(HDUType()!=IMAGE_HDU)
|
---|
[2453] | 1051 | throw TypeMismatchExc("FitsImg2DRd::Init: HDU not IMAGE_HDU\n");
|
---|
[2456] | 1052 | FitsOF->SetPosStatus(true);
|
---|
[2453] | 1053 |
|
---|
| 1054 | // Get NAXIS 1 et 2
|
---|
| 1055 | int nfound=0;
|
---|
[3128] | 1056 | // car fits_read_keys_lnglng n'est pas prototype dans longnam.h
|
---|
| 1057 | if(ffgknjj(GetFitsPtr(),"NAXIS",1,2,Naxis,&nfound,&sta)) {
|
---|
[2453] | 1058 | FitsOpenFile::printerror(sta);
|
---|
| 1059 | throw RangeCheckError("FitsImg2DRd::Init: Error reading NAXIS cards\n");
|
---|
| 1060 | }
|
---|
| 1061 | if(DbgLevel>1)
|
---|
[2456] | 1062 | cout<<"...Init(hdu="<<HDU()<<") NAXIS1="<<Naxis[0]<<" NAXIS2="
|
---|
| 1063 | <<Naxis[1]<<" (nfound="<<nfound<<")"<<endl;
|
---|
[2453] | 1064 | if(nfound!=2 || Naxis[0]<=0 || Naxis[1]<=0)
|
---|
| 1065 | throw NotAvailableOperation("FitsImg2DRd::Init: bad Naxis[0-1] value\n");
|
---|
| 1066 |
|
---|
| 1067 | }
|
---|
| 1068 |
|
---|
| 1069 | /*! Destructor. */
|
---|
| 1070 | FitsImg2DRd::~FitsImg2DRd()
|
---|
| 1071 | {
|
---|
| 1072 | //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
|
---|
| 1073 | Naxis[0] = Naxis[1] = 0;
|
---|
| 1074 | }
|
---|
| 1075 |
|
---|
| 1076 | //////////////////////////////////////////////////////////////
|
---|
| 1077 | /*!
|
---|
| 1078 | Read a fitsheader key into double
|
---|
| 1079 | \param keyname : name of the key
|
---|
| 1080 | \return value into double
|
---|
| 1081 | */
|
---|
| 1082 | double FitsImg2DRd::ReadKey(char *keyname)
|
---|
| 1083 | {
|
---|
[3114] | 1084 | return FitsOpenFile::ReadKey(GetFitsPtr(),keyname);
|
---|
[2453] | 1085 | }
|
---|
| 1086 |
|
---|
| 1087 | /*!
|
---|
| 1088 | Read a fitsheader key into long
|
---|
| 1089 | \param keyname : name of the key
|
---|
| 1090 | \return value into long
|
---|
| 1091 | */
|
---|
| 1092 | long FitsImg2DRd::ReadKeyL(char *keyname)
|
---|
| 1093 | {
|
---|
[3114] | 1094 | return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname);
|
---|
[2453] | 1095 | }
|
---|
| 1096 |
|
---|
| 1097 | /*!
|
---|
[3128] | 1098 | Read a fitsheader key into long long
|
---|
| 1099 | \param keyname : name of the key
|
---|
| 1100 | \return value into long long
|
---|
| 1101 | */
|
---|
| 1102 | LONGLONG FitsImg2DRd::ReadKeyLL(char *keyname)
|
---|
| 1103 | {
|
---|
| 1104 | return FitsOpenFile::ReadKeyLL(GetFitsPtr(),keyname);
|
---|
| 1105 | }
|
---|
| 1106 |
|
---|
| 1107 | /*!
|
---|
[2453] | 1108 | Read a fitsheader key into string
|
---|
| 1109 | \param keyname : name of the key
|
---|
| 1110 | \return value into string
|
---|
| 1111 | */
|
---|
| 1112 | string FitsImg2DRd::ReadKeyS(char *keyname)
|
---|
| 1113 | {
|
---|
[3114] | 1114 | return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname);
|
---|
[2453] | 1115 | }
|
---|
| 1116 |
|
---|
| 1117 | //////////////////////////////////////////////////////////////
|
---|
| 1118 | /* REMARQUE:
|
---|
| 1119 | * Si une image FITS a NAXIS1=100 et NAXIS2=50
|
---|
| 1120 | * alors un tableau 2D juste assez grand pour contenir l'image
|
---|
| 1121 | * doit etre declare array[50][100] (et non pas array[100][50])
|
---|
| 1122 | * array[NAXIS2][NAXIS1]
|
---|
| 1123 | */
|
---|
| 1124 | /*!
|
---|
| 1125 | Read image into a TMatrix<uint_2>
|
---|
| 1126 | \warning TMatrix data(Naxis2,Naxis1)
|
---|
| 1127 | */
|
---|
[3128] | 1128 | LONGLONG FitsImg2DRd::Read(TMatrix<uint_2>& data)
|
---|
[2453] | 1129 | {
|
---|
| 1130 | int sta=0;
|
---|
| 1131 | uint_2* arr = new uint_2[Naxis[0]];
|
---|
| 1132 | data.ReSize(Naxis[1],Naxis[0]);
|
---|
| 1133 |
|
---|
[3128] | 1134 | for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1135 | LONGLONG deb = j*Naxis[0]+1, nel = Naxis[0];
|
---|
[3114] | 1136 | fits_read_img(GetFitsPtr(),TUSHORT,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
[2453] | 1137 | if(sta) {
|
---|
| 1138 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1139 | throw
|
---|
| 1140 | NotAvailableOperation("FitsImg2DRd::Read(TMatrix<uint_2>): Error Reading Fits file\n");
|
---|
| 1141 | }
|
---|
[3128] | 1142 | for(LONGLONG i=0;i<Naxis[0];i++) data(j,i) = arr[i];
|
---|
[2453] | 1143 | }
|
---|
| 1144 |
|
---|
| 1145 | delete [] arr;
|
---|
| 1146 | return Naxis[0]*Naxis[1];
|
---|
| 1147 | }
|
---|
| 1148 |
|
---|
| 1149 | /*! Read image into a TMatrix<int_4> */
|
---|
[3128] | 1150 | LONGLONG FitsImg2DRd::Read(TMatrix<int_4>& data)
|
---|
[2453] | 1151 | {
|
---|
| 1152 | int sta=0;
|
---|
| 1153 | int_4* arr = new int_4[Naxis[0]];
|
---|
| 1154 | data.ReSize(Naxis[1],Naxis[0]);
|
---|
| 1155 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
| 1156 |
|
---|
[3128] | 1157 | for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1158 | LONGLONG deb = j*Naxis[0]+1, nel = Naxis[0];
|
---|
[3114] | 1159 | fits_read_img(GetFitsPtr(),T,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
[2453] | 1160 | if(sta) {
|
---|
| 1161 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1162 | throw
|
---|
| 1163 | NotAvailableOperation("FitsImg2DRd::Read(TMatrix<int_4>): Error Reading Fits file\n");
|
---|
| 1164 | }
|
---|
[3128] | 1165 | for(LONGLONG i=0;i<Naxis[0];i++) data(j,i) = arr[i];
|
---|
[2453] | 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | delete [] arr;
|
---|
| 1169 | return Naxis[0]*Naxis[1];
|
---|
| 1170 | }
|
---|
| 1171 |
|
---|
| 1172 | /*! Read image into a TMatrix<int_8> */
|
---|
[3128] | 1173 | LONGLONG FitsImg2DRd::Read(TMatrix<int_8>& data)
|
---|
[2453] | 1174 | {
|
---|
| 1175 | int sta=0;
|
---|
| 1176 | int_8* arr = new int_8[Naxis[0]];
|
---|
| 1177 | data.ReSize(Naxis[1],Naxis[0]);
|
---|
| 1178 |
|
---|
[3128] | 1179 | for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1180 | LONGLONG deb = j*Naxis[0]+1, nel = Naxis[0];
|
---|
[3114] | 1181 | fits_read_img(GetFitsPtr(),TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
[2453] | 1182 | if(sta) {
|
---|
| 1183 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1184 | throw
|
---|
| 1185 | NotAvailableOperation("FitsImg2DRd::Read(TMatrix<int_8>): Error Reading Fits file\n");
|
---|
| 1186 | }
|
---|
[3128] | 1187 | for(LONGLONG i=0;i<Naxis[0];i++) data(j,i) = arr[i];
|
---|
[2453] | 1188 | }
|
---|
| 1189 |
|
---|
| 1190 | delete [] arr;
|
---|
| 1191 | return Naxis[0]*Naxis[1];
|
---|
| 1192 | }
|
---|
| 1193 |
|
---|
| 1194 | /*! Read image into a TMatrix<float> */
|
---|
[3128] | 1195 | LONGLONG FitsImg2DRd::Read(TMatrix<float>& data)
|
---|
[2453] | 1196 | {
|
---|
| 1197 | int sta=0;
|
---|
| 1198 | float* arr = new float[Naxis[0]];
|
---|
| 1199 | data.ReSize(Naxis[1],Naxis[0]);
|
---|
| 1200 |
|
---|
[3128] | 1201 | for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1202 | LONGLONG deb = j*Naxis[0]+1, nel = Naxis[0];
|
---|
[3114] | 1203 | fits_read_img(GetFitsPtr(),TFLOAT,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
[2453] | 1204 | if(sta) {
|
---|
| 1205 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1206 | throw
|
---|
| 1207 | NotAvailableOperation("FitsImg2DRd::Read(TMatrix<float>): Error Reading Fits file\n");
|
---|
| 1208 | }
|
---|
[3128] | 1209 | for(LONGLONG i=0;i<Naxis[0];i++) data(j,i) = arr[i];
|
---|
[2453] | 1210 | }
|
---|
| 1211 |
|
---|
| 1212 | delete [] arr;
|
---|
| 1213 | return Naxis[0]*Naxis[1];
|
---|
| 1214 | }
|
---|
| 1215 |
|
---|
| 1216 | /*! Read image into a TMatrix<double> */
|
---|
[3128] | 1217 | LONGLONG FitsImg2DRd::Read(TMatrix<double>& data)
|
---|
[2453] | 1218 | {
|
---|
| 1219 | int sta=0;
|
---|
| 1220 | double* arr = new double[Naxis[0]];
|
---|
| 1221 | data.ReSize(Naxis[1],Naxis[0]);
|
---|
| 1222 |
|
---|
[3128] | 1223 | for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1224 | LONGLONG deb = j*Naxis[0]+1, nel = Naxis[0];
|
---|
[3114] | 1225 | fits_read_img(GetFitsPtr(),TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
[2453] | 1226 | if(sta) {
|
---|
| 1227 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1228 | throw
|
---|
| 1229 | NotAvailableOperation("FitsImg2DRd::Read(TMatrix<double>): Error Reading Fits file\n");
|
---|
| 1230 | }
|
---|
[3128] | 1231 | for(LONGLONG i=0;i<Naxis[0];i++) data(j,i) = arr[i];
|
---|
[2453] | 1232 | }
|
---|
| 1233 |
|
---|
| 1234 | delete [] arr;
|
---|
| 1235 | return Naxis[0]*Naxis[1];
|
---|
| 1236 | }
|
---|
[2791] | 1237 |
|
---|
| 1238 | ///////////////////////////////////////////////////////////////////
|
---|
| 1239 | ///////////////////////////////////////////////////////////////////
|
---|
| 1240 | ///////////////////////////////////////////////////////////////////
|
---|
| 1241 | ///////////////////////////////////////////////////////////////////
|
---|
| 1242 |
|
---|
| 1243 | //! Class for reading a 2D image from a FITS file
|
---|
| 1244 |
|
---|
| 1245 | /*!
|
---|
| 1246 | \class SOPHYA::FitsImg2DRead
|
---|
| 1247 | \ingroup FitsIOServer
|
---|
| 1248 | Class for reading a 2D image from a FITS file
|
---|
| 1249 | */
|
---|
| 1250 |
|
---|
| 1251 | //////////////////////////////////////////////////////////////
|
---|
| 1252 | /*!
|
---|
| 1253 | Constructor.
|
---|
| 1254 | \param fname : name of the FITS file
|
---|
| 1255 | \param ihdu : number of the HDU where the image is.
|
---|
| 1256 | \param lp : debug level
|
---|
| 1257 | \verbatim
|
---|
| 1258 | - if ihdu<=0 first IMAGE hdu is taken
|
---|
| 1259 | - if ihdu>nhdu ihdu is set to nhdu
|
---|
| 1260 | \endverbatim
|
---|
| 1261 | \warning ihdu = [1,nhdu]
|
---|
| 1262 | */
|
---|
| 1263 | FitsImg2DRead::FitsImg2DRead(string fname,int ihdu,int lp)
|
---|
| 1264 | : FitsImg2DRd(new FitsOpenFile(fname),ihdu,lp)
|
---|
| 1265 | {
|
---|
| 1266 | }
|
---|
| 1267 |
|
---|
| 1268 | /*! Constructor. see below */
|
---|
| 1269 | FitsImg2DRead::FitsImg2DRead(const char * cfname,int ihdu,int lp)
|
---|
| 1270 | : FitsImg2DRd(new FitsOpenFile(cfname),ihdu,lp)
|
---|
| 1271 | {
|
---|
| 1272 | }
|
---|
| 1273 |
|
---|
| 1274 | /*! Constructor by default */
|
---|
| 1275 | FitsImg2DRead::FitsImg2DRead()
|
---|
| 1276 | : FitsImg2DRd()
|
---|
| 1277 | {
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | /*! Constructor by copy */
|
---|
| 1281 | FitsImg2DRead::FitsImg2DRead(FitsImg2DRead& fimg)
|
---|
| 1282 | {
|
---|
| 1283 | // --- ATTENTION ---
|
---|
| 1284 | // FitsImg2DRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
|
---|
| 1285 | FitsOpenFile* fof = new FitsOpenFile(*fimg.GetFitsOpenFile());
|
---|
| 1286 | Init(fof,fimg.HDU(),fimg.DbgLevel);
|
---|
| 1287 | }
|
---|
| 1288 |
|
---|
| 1289 | /*! Destructor. */
|
---|
| 1290 | FitsImg2DRead::~FitsImg2DRead()
|
---|
| 1291 | {
|
---|
| 1292 | // On detruit le FitsOpenFile, cad qu'on ferme (fits_file_close) le fichier FITS
|
---|
| 1293 | if(FitsOF!=NULL) delete FitsOF;
|
---|
| 1294 | }
|
---|
[3114] | 1295 |
|
---|
| 1296 |
|
---|
| 1297 |
|
---|
| 1298 | ///////////////////////////////////////////////////////////////////
|
---|
| 1299 | ///////////////////////////////////////////////////////////////////
|
---|
| 1300 | ///////////////////////////////////////////////////////////////////
|
---|
| 1301 | ///////////////////////////////////////////////////////////////////
|
---|
| 1302 |
|
---|
| 1303 | //! Class for reading a 3D image from a FITS file
|
---|
| 1304 |
|
---|
| 1305 | /*!
|
---|
| 1306 | \class SOPHYA::FitsImg3DRd
|
---|
| 1307 | \ingroup FitsIOServer
|
---|
| 1308 | Class for reading a 3D image from a FITS file
|
---|
| 1309 | */
|
---|
| 1310 |
|
---|
| 1311 | //////////////////////////////////////////////////////////////
|
---|
| 1312 | /*!
|
---|
| 1313 | Constructor.
|
---|
| 1314 | \param fof : Pointer to the Class for opening the FITS file
|
---|
| 1315 | \param ihdu : number of the HDU where the 3D image is.
|
---|
| 1316 | \param lp : debug level
|
---|
| 1317 | \verbatim
|
---|
| 1318 | - if ihdu<=0 first IMAGE hdu is taken
|
---|
| 1319 | - if ihdu>nhdu ihdu is set to nhdu
|
---|
| 1320 | \endverbatim
|
---|
| 1321 | \warning ihdu = [1,nhdu]
|
---|
| 1322 | */
|
---|
| 1323 | FitsImg3DRd::FitsImg3DRd(FitsOpenFile* fof,int ihdu,int lp)
|
---|
| 1324 | {
|
---|
| 1325 | Init(fof,ihdu,lp);
|
---|
| 1326 | }
|
---|
| 1327 |
|
---|
| 1328 | /*! Constructor by copy */
|
---|
| 1329 | FitsImg3DRd::FitsImg3DRd(FitsImg3DRd& fbt)
|
---|
| 1330 | {
|
---|
| 1331 | Init(fbt.GetFitsOpenFile(),fbt.HDU(),fbt.DbgLevel);
|
---|
| 1332 | }
|
---|
| 1333 |
|
---|
| 1334 | /*! Constructor by default */
|
---|
| 1335 | FitsImg3DRd::FitsImg3DRd()
|
---|
| 1336 | {
|
---|
| 1337 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 1338 | SetNulVal(); SetDebug(0);
|
---|
| 1339 | FitsOF = NULL;
|
---|
| 1340 | }
|
---|
| 1341 |
|
---|
| 1342 | /*! Init routine called by the constructor */
|
---|
| 1343 | void FitsImg3DRd::Init(FitsOpenFile* fof,int ihdu,int lp)
|
---|
| 1344 | {
|
---|
| 1345 | // Initialisation des Parametres Generaux
|
---|
| 1346 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 1347 | SetNulVal(); SetDebug(lp);
|
---|
| 1348 | FitsOF = NULL;
|
---|
| 1349 |
|
---|
| 1350 | // Caracteristiques du FitsOpenFile
|
---|
| 1351 | FitsOF = fof;
|
---|
| 1352 | if(FitsOF==NULL)
|
---|
| 1353 | throw NullPtrError("FitsImg3DRd::Init: FitsOpenFile pointer is NULL\n");
|
---|
| 1354 |
|
---|
| 1355 | if(GetFitsPtr()==NULL)
|
---|
| 1356 | throw NullPtrError("FitsImg3DRd::Init: FitsPtr pointer is NULL\n");
|
---|
| 1357 |
|
---|
| 1358 | int sta = 0;
|
---|
| 1359 | if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU();
|
---|
| 1360 |
|
---|
| 1361 | // Get HDU 3D image
|
---|
| 1362 | // ATTENTION: ... cf blabla equivalent dans FitsABTColRd::Init()
|
---|
| 1363 | if(FitsOF->GetPosStatus()==false) {
|
---|
| 1364 | if(ihdu==0) { // find the first IMAGE_HDU
|
---|
| 1365 | FitsOF->MoveToFirst(IMAGE_HDU);
|
---|
| 1366 | } else {
|
---|
| 1367 | int rc = FitsOF->MoveToHDU(ihdu);
|
---|
| 1368 | if(rc!=ihdu)
|
---|
| 1369 | throw RangeCheckError("FitsImg3DRd::Init: Error moving to requested HDU\n");
|
---|
| 1370 | }
|
---|
| 1371 | } else { // Fits file has already been positionned
|
---|
| 1372 | if(ihdu>0 && ihdu!=HDU())
|
---|
| 1373 | throw RangeCheckError("FitsImg3DRd::Init: file already posit. at another HDU\n");
|
---|
| 1374 | }
|
---|
| 1375 |
|
---|
| 1376 | // Check HDUType and set position status to TRUE
|
---|
| 1377 | if(HDUType()!=IMAGE_HDU)
|
---|
| 1378 | throw TypeMismatchExc("FitsImg3DRd::Init: HDU not IMAGE_HDU\n");
|
---|
| 1379 | FitsOF->SetPosStatus(true);
|
---|
| 1380 |
|
---|
| 1381 | // Get NAXIS 1, 2 et 3
|
---|
| 1382 | int nfound=0;
|
---|
[3128] | 1383 | // car fits_read_keys_lnglng n'est pas prototype dans longnam.h
|
---|
| 1384 | if(ffgknjj(GetFitsPtr(),"NAXIS",1,3,Naxis,&nfound,&sta)) {
|
---|
[3114] | 1385 | FitsOpenFile::printerror(sta);
|
---|
| 1386 | throw RangeCheckError("FitsImg3DRd::Init: Error reading NAXIS cards\n");
|
---|
| 1387 | }
|
---|
| 1388 | if(DbgLevel>1)
|
---|
| 1389 | cout<<"...Init(hdu="<<HDU()<<") NAXIS1="<<Naxis[0]<<" NAXIS2="
|
---|
| 1390 | <<Naxis[1]<<" NAXIS3="<<Naxis[2]<<" (nfound="<<nfound<<")"<<endl;
|
---|
| 1391 | if(nfound!=3 || Naxis[0]<=0 || Naxis[1]<=0 || Naxis[2]<=0)
|
---|
| 1392 | throw NotAvailableOperation("FitsImg3DRd::Init: bad Naxis[0-2] value\n");
|
---|
| 1393 |
|
---|
| 1394 | }
|
---|
| 1395 |
|
---|
| 1396 | /*! Destructor. */
|
---|
| 1397 | FitsImg3DRd::~FitsImg3DRd()
|
---|
| 1398 | {
|
---|
| 1399 | //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
|
---|
| 1400 | Naxis[0] = Naxis[1] = Naxis[2] = 0;
|
---|
| 1401 | }
|
---|
| 1402 |
|
---|
| 1403 | //////////////////////////////////////////////////////////////
|
---|
| 1404 | /*!
|
---|
| 1405 | Read a fitsheader key into double
|
---|
| 1406 | \param keyname : name of the key
|
---|
| 1407 | \return value into double
|
---|
| 1408 | */
|
---|
| 1409 | double FitsImg3DRd::ReadKey(char *keyname)
|
---|
| 1410 | {
|
---|
| 1411 | return FitsOpenFile::ReadKey(GetFitsPtr(),keyname);
|
---|
| 1412 | }
|
---|
| 1413 |
|
---|
| 1414 | /*!
|
---|
| 1415 | Read a fitsheader key into long
|
---|
| 1416 | \param keyname : name of the key
|
---|
| 1417 | \return value into long
|
---|
| 1418 | */
|
---|
| 1419 | long FitsImg3DRd::ReadKeyL(char *keyname)
|
---|
| 1420 | {
|
---|
| 1421 | return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname);
|
---|
| 1422 | }
|
---|
| 1423 |
|
---|
| 1424 | /*!
|
---|
[3128] | 1425 | Read a fitsheader key into long long
|
---|
| 1426 | \param keyname : name of the key
|
---|
| 1427 | \return value into long long
|
---|
| 1428 | */
|
---|
| 1429 | LONGLONG FitsImg3DRd::ReadKeyLL(char *keyname)
|
---|
| 1430 | {
|
---|
| 1431 | return FitsOpenFile::ReadKeyLL(GetFitsPtr(),keyname);
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 | /*!
|
---|
[3114] | 1435 | Read a fitsheader key into string
|
---|
| 1436 | \param keyname : name of the key
|
---|
| 1437 | \return value into string
|
---|
| 1438 | */
|
---|
| 1439 | string FitsImg3DRd::ReadKeyS(char *keyname)
|
---|
| 1440 | {
|
---|
| 1441 | return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname);
|
---|
| 1442 | }
|
---|
| 1443 |
|
---|
| 1444 | //////////////////////////////////////////////////////////////
|
---|
| 1445 | /* REMARQUE:
|
---|
| 1446 | * Dans TArray A(naxis1,naxis2,naxis3);
|
---|
| 1447 | * A(i,j,k) -> i varie le plus vite et k le moins vite
|
---|
| 1448 | */
|
---|
| 1449 | /*!
|
---|
| 1450 | Read 3D image into a TArray<uint_2>
|
---|
| 1451 | */
|
---|
[3128] | 1452 | LONGLONG FitsImg3DRd::Read(TArray<uint_2>& data)
|
---|
[3114] | 1453 | {
|
---|
| 1454 | int sta=0;
|
---|
| 1455 | uint_2* arr = new uint_2[Naxis[0]];
|
---|
| 1456 | sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
|
---|
| 1457 |
|
---|
[3128] | 1458 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1459 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
|
---|
[3114] | 1460 | fits_read_img(GetFitsPtr(),TUSHORT,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
| 1461 | if(sta) {
|
---|
| 1462 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1463 | throw
|
---|
| 1464 | NotAvailableOperation("FitsImg3DRd::Read(TArray<uint_2>): Error Reading Fits file\n");
|
---|
| 1465 | }
|
---|
[3128] | 1466 | for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
|
---|
[3114] | 1467 | }
|
---|
| 1468 |
|
---|
| 1469 | delete [] arr;
|
---|
| 1470 | return Naxis[0]*Naxis[1]*Naxis[2];
|
---|
| 1471 | }
|
---|
| 1472 |
|
---|
| 1473 | /*! Read 3D image into a TArray<int_4> */
|
---|
[3128] | 1474 | LONGLONG FitsImg3DRd::Read(TArray<int_4>& data)
|
---|
[3114] | 1475 | {
|
---|
| 1476 | int sta=0;
|
---|
| 1477 | int_4* arr = new int_4[Naxis[0]];
|
---|
| 1478 | sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
|
---|
| 1479 | int T = (sizeof(long)==4) ? TLONG: TINT;
|
---|
| 1480 |
|
---|
[3128] | 1481 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1482 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
|
---|
[3114] | 1483 | fits_read_img(GetFitsPtr(),T,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
| 1484 | if(sta) {
|
---|
| 1485 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1486 | throw
|
---|
| 1487 | NotAvailableOperation("FitsImg3DRd::Read(TArray<int_4>): Error Reading Fits file\n");
|
---|
| 1488 | }
|
---|
[3128] | 1489 | for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
|
---|
[3114] | 1490 | }
|
---|
| 1491 |
|
---|
| 1492 | delete [] arr;
|
---|
| 1493 | return Naxis[0]*Naxis[1]*Naxis[2];
|
---|
| 1494 | }
|
---|
| 1495 |
|
---|
| 1496 | /*! Read 3D image into a TArray<int_8> */
|
---|
[3128] | 1497 | LONGLONG FitsImg3DRd::Read(TArray<int_8>& data)
|
---|
[3114] | 1498 | {
|
---|
| 1499 | int sta=0;
|
---|
| 1500 | int_8* arr = new int_8[Naxis[0]];
|
---|
| 1501 | sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
|
---|
| 1502 |
|
---|
[3128] | 1503 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1504 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
|
---|
[3114] | 1505 | fits_read_img(GetFitsPtr(),TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
| 1506 | if(sta) {
|
---|
| 1507 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1508 | throw
|
---|
| 1509 | NotAvailableOperation("FitsImg3DRd::Read(TArray<int_8>): Error Reading Fits file\n");
|
---|
| 1510 | }
|
---|
[3128] | 1511 | for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
|
---|
[3114] | 1512 | }
|
---|
| 1513 |
|
---|
| 1514 | delete [] arr;
|
---|
| 1515 | return Naxis[0]*Naxis[1]*Naxis[2];
|
---|
| 1516 | }
|
---|
| 1517 |
|
---|
| 1518 | /*! Read 3D image into a TArray<float> */
|
---|
[3128] | 1519 | LONGLONG FitsImg3DRd::Read(TArray<float>& data)
|
---|
[3114] | 1520 | {
|
---|
| 1521 | int sta=0;
|
---|
| 1522 | float* arr = new float[Naxis[0]];
|
---|
| 1523 | sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
|
---|
| 1524 |
|
---|
[3128] | 1525 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1526 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
|
---|
[3114] | 1527 | fits_read_img(GetFitsPtr(),TFLOAT,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
| 1528 | if(sta) {
|
---|
| 1529 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1530 | throw
|
---|
| 1531 | NotAvailableOperation("FitsImg3DRd::Read(TArray<float>): Error Reading Fits file\n");
|
---|
| 1532 | }
|
---|
[3128] | 1533 | for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
|
---|
[3114] | 1534 | }
|
---|
| 1535 |
|
---|
| 1536 | delete [] arr;
|
---|
| 1537 | return Naxis[0]*Naxis[1]*Naxis[2];
|
---|
| 1538 | }
|
---|
| 1539 |
|
---|
| 1540 | /*! Read 3D image into a TArray<double> */
|
---|
[3128] | 1541 | LONGLONG FitsImg3DRd::Read(TArray<double>& data)
|
---|
[3114] | 1542 | {
|
---|
| 1543 | int sta=0;
|
---|
| 1544 | double* arr = new double[Naxis[0]];
|
---|
| 1545 | sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
|
---|
| 1546 |
|
---|
[3128] | 1547 | for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
|
---|
| 1548 | LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
|
---|
[3114] | 1549 | fits_read_img(GetFitsPtr(),TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta);
|
---|
| 1550 | if(sta) {
|
---|
| 1551 | FitsOpenFile::printerror(sta); delete [] arr;
|
---|
| 1552 | throw
|
---|
| 1553 | NotAvailableOperation("FitsImg3DRd::Read(TArray<double>): Error Reading Fits file\n");
|
---|
| 1554 | }
|
---|
[3128] | 1555 | for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
|
---|
[3114] | 1556 | }
|
---|
| 1557 |
|
---|
| 1558 | delete [] arr;
|
---|
| 1559 | return Naxis[0]*Naxis[1]*Naxis[2];
|
---|
| 1560 | }
|
---|
| 1561 |
|
---|
| 1562 | ///////////////////////////////////////////////////////////////////
|
---|
| 1563 | ///////////////////////////////////////////////////////////////////
|
---|
| 1564 | ///////////////////////////////////////////////////////////////////
|
---|
| 1565 | ///////////////////////////////////////////////////////////////////
|
---|
| 1566 |
|
---|
| 1567 | //! Class for reading a 3D image from a FITS file
|
---|
| 1568 |
|
---|
| 1569 | /*!
|
---|
| 1570 | \class SOPHYA::FitsImg3DRead
|
---|
| 1571 | \ingroup FitsIOServer
|
---|
| 1572 | Class for reading a 3D image from a FITS file
|
---|
| 1573 | */
|
---|
| 1574 |
|
---|
| 1575 | //////////////////////////////////////////////////////////////
|
---|
| 1576 | /*!
|
---|
| 1577 | Constructor.
|
---|
| 1578 | \param fname : name of the FITS file
|
---|
| 1579 | \param ihdu : number of the HDU where the 3D image is.
|
---|
| 1580 | \param lp : debug level
|
---|
| 1581 | \verbatim
|
---|
| 1582 | - if ihdu<=0 first IMAGE hdu is taken
|
---|
| 1583 | - if ihdu>nhdu ihdu is set to nhdu
|
---|
| 1584 | \endverbatim
|
---|
| 1585 | \warning ihdu = [1,nhdu]
|
---|
| 1586 | */
|
---|
| 1587 | FitsImg3DRead::FitsImg3DRead(string fname,int ihdu,int lp)
|
---|
| 1588 | : FitsImg3DRd(new FitsOpenFile(fname),ihdu,lp)
|
---|
| 1589 | {
|
---|
| 1590 | }
|
---|
| 1591 |
|
---|
| 1592 | /*! Constructor. see below */
|
---|
| 1593 | FitsImg3DRead::FitsImg3DRead(const char * cfname,int ihdu,int lp)
|
---|
| 1594 | : FitsImg3DRd(new FitsOpenFile(cfname),ihdu,lp)
|
---|
| 1595 | {
|
---|
| 1596 | }
|
---|
| 1597 |
|
---|
| 1598 | /*! Constructor by default */
|
---|
| 1599 | FitsImg3DRead::FitsImg3DRead()
|
---|
| 1600 | : FitsImg3DRd()
|
---|
| 1601 | {
|
---|
| 1602 | }
|
---|
| 1603 |
|
---|
| 1604 | /*! Constructor by copy */
|
---|
| 1605 | FitsImg3DRead::FitsImg3DRead(FitsImg3DRead& fimg)
|
---|
| 1606 | {
|
---|
| 1607 | // --- ATTENTION ---
|
---|
| 1608 | // FitsImg3DRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
|
---|
| 1609 | FitsOpenFile* fof = new FitsOpenFile(*fimg.GetFitsOpenFile());
|
---|
| 1610 | Init(fof,fimg.HDU(),fimg.DbgLevel);
|
---|
| 1611 | }
|
---|
| 1612 |
|
---|
| 1613 | /*! Destructor. */
|
---|
| 1614 | FitsImg3DRead::~FitsImg3DRead()
|
---|
| 1615 | {
|
---|
| 1616 | // On detruit le FitsOpenFile, cad qu'on ferme (fits_file_close) le fichier FITS
|
---|
| 1617 | if(FitsOF!=NULL) delete FitsOF;
|
---|
| 1618 | }
|
---|