| [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];
 | 
|---|
| [3188] | 1147 | }
 | 
|---|
| [2453] | 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];
 | 
|---|
| [3188] | 1170 | }
 | 
|---|
| [2453] | 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];
 | 
|---|
| [3188] | 1192 | }
 | 
|---|
| [2453] | 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];
 | 
|---|
| [3188] | 1214 | }
 | 
|---|
| [2453] | 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];
 | 
|---|
| [3188] | 1236 | }
 | 
|---|
| [2791] | 1237 | 
 | 
|---|
| [3188] | 1238 | /*! Read image pixel numcol,numrow with numcol=[0,Naxis1[ and numrow=[0,Naxis2[ */
 | 
|---|
 | 1239 | double FitsImg2DRd::Read(LONGLONG numcol, LONGLONG numrow)
 | 
|---|
 | 1240 | {
 | 
|---|
 | 1241 |  int sta=0;
 | 
|---|
 | 1242 |  if(numcol<0 || numrow<0 || numcol>=Naxis[0] || numrow>=Naxis[1])
 | 
|---|
 | 1243 |    throw
 | 
|---|
 | 1244 |      NotAvailableOperation("FitsImg2DRd::Read(col,row): bad col/row number\n");
 | 
|---|
 | 1245 | 
 | 
|---|
 | 1246 |    LONGLONG deb = numrow*Naxis[0] + numcol + 1;
 | 
|---|
 | 1247 |    double val = 0.;
 | 
|---|
 | 1248 |    fits_read_img(GetFitsPtr(),TDOUBLE,deb,1,&NulVal,&val,NULL,&sta);
 | 
|---|
 | 1249 | 
 | 
|---|
 | 1250 |    if(sta) {
 | 
|---|
 | 1251 |      FitsOpenFile::printerror(sta);
 | 
|---|
 | 1252 |      throw
 | 
|---|
 | 1253 |        NotAvailableOperation("FitsImg2DRd::Read(col,num): Error Reading Fits file\n");
 | 
|---|
 | 1254 |    }
 | 
|---|
 | 1255 | 
 | 
|---|
 | 1256 |    return val;
 | 
|---|
 | 1257 | }
 | 
|---|
 | 1258 | 
 | 
|---|
| [2791] | 1259 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1260 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1261 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1262 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1263 | 
 | 
|---|
 | 1264 | //! Class for reading a 2D image from a FITS file
 | 
|---|
 | 1265 | 
 | 
|---|
 | 1266 | /*!
 | 
|---|
 | 1267 |   \class SOPHYA::FitsImg2DRead
 | 
|---|
 | 1268 |   \ingroup FitsIOServer
 | 
|---|
 | 1269 |   Class for reading a 2D image from a FITS file
 | 
|---|
 | 1270 | */
 | 
|---|
 | 1271 | 
 | 
|---|
 | 1272 | //////////////////////////////////////////////////////////////
 | 
|---|
 | 1273 | /*!
 | 
|---|
 | 1274 |   Constructor.
 | 
|---|
 | 1275 |   \param fname : name of the FITS file
 | 
|---|
 | 1276 |   \param ihdu : number of the HDU where the image is.
 | 
|---|
 | 1277 |   \param lp : debug level
 | 
|---|
 | 1278 |   \verbatim
 | 
|---|
 | 1279 |   - if ihdu<=0 first IMAGE hdu is taken
 | 
|---|
 | 1280 |   - if ihdu>nhdu ihdu is set to nhdu
 | 
|---|
 | 1281 |   \endverbatim
 | 
|---|
 | 1282 |   \warning ihdu = [1,nhdu]
 | 
|---|
 | 1283 | */
 | 
|---|
 | 1284 | FitsImg2DRead::FitsImg2DRead(string fname,int ihdu,int lp)
 | 
|---|
 | 1285 | : FitsImg2DRd(new FitsOpenFile(fname),ihdu,lp)
 | 
|---|
 | 1286 | {
 | 
|---|
 | 1287 | }
 | 
|---|
 | 1288 | 
 | 
|---|
 | 1289 | /*! Constructor. see below */
 | 
|---|
 | 1290 | FitsImg2DRead::FitsImg2DRead(const char * cfname,int ihdu,int lp)
 | 
|---|
 | 1291 | : FitsImg2DRd(new FitsOpenFile(cfname),ihdu,lp)
 | 
|---|
 | 1292 | {
 | 
|---|
 | 1293 | }
 | 
|---|
 | 1294 | 
 | 
|---|
 | 1295 | /*! Constructor by default */
 | 
|---|
 | 1296 | FitsImg2DRead::FitsImg2DRead()
 | 
|---|
 | 1297 | : FitsImg2DRd()
 | 
|---|
 | 1298 | {
 | 
|---|
 | 1299 | }
 | 
|---|
 | 1300 | 
 | 
|---|
 | 1301 | /*! Constructor by copy */
 | 
|---|
 | 1302 | FitsImg2DRead::FitsImg2DRead(FitsImg2DRead& fimg)
 | 
|---|
 | 1303 | {
 | 
|---|
 | 1304 |  // --- ATTENTION ---
 | 
|---|
 | 1305 |  // FitsImg2DRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
 | 
|---|
 | 1306 |  FitsOpenFile* fof = new FitsOpenFile(*fimg.GetFitsOpenFile());
 | 
|---|
 | 1307 |  Init(fof,fimg.HDU(),fimg.DbgLevel);
 | 
|---|
 | 1308 | }
 | 
|---|
 | 1309 | 
 | 
|---|
 | 1310 | /*! Destructor. */
 | 
|---|
 | 1311 | FitsImg2DRead::~FitsImg2DRead()
 | 
|---|
 | 1312 | {
 | 
|---|
 | 1313 |  // On detruit le FitsOpenFile, cad qu'on ferme (fits_file_close) le fichier FITS
 | 
|---|
 | 1314 |  if(FitsOF!=NULL) delete FitsOF;
 | 
|---|
 | 1315 | }
 | 
|---|
| [3114] | 1316 | 
 | 
|---|
 | 1317 | 
 | 
|---|
 | 1318 | 
 | 
|---|
 | 1319 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1320 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1321 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1322 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1323 | 
 | 
|---|
 | 1324 | //! Class for reading a 3D image from a FITS file
 | 
|---|
 | 1325 | 
 | 
|---|
 | 1326 | /*!
 | 
|---|
 | 1327 |   \class SOPHYA::FitsImg3DRd
 | 
|---|
 | 1328 |   \ingroup FitsIOServer
 | 
|---|
 | 1329 |   Class for reading a 3D image from a FITS file
 | 
|---|
 | 1330 | */
 | 
|---|
 | 1331 | 
 | 
|---|
 | 1332 | //////////////////////////////////////////////////////////////
 | 
|---|
 | 1333 | /*!
 | 
|---|
 | 1334 |   Constructor.
 | 
|---|
 | 1335 |   \param fof : Pointer to the Class for opening the FITS file
 | 
|---|
 | 1336 |   \param ihdu : number of the HDU where the 3D image is.
 | 
|---|
 | 1337 |   \param lp : debug level
 | 
|---|
 | 1338 |   \verbatim
 | 
|---|
 | 1339 |   - if ihdu<=0 first IMAGE hdu is taken
 | 
|---|
 | 1340 |   - if ihdu>nhdu ihdu is set to nhdu
 | 
|---|
 | 1341 |   \endverbatim
 | 
|---|
 | 1342 |   \warning ihdu = [1,nhdu]
 | 
|---|
 | 1343 | */
 | 
|---|
 | 1344 | FitsImg3DRd::FitsImg3DRd(FitsOpenFile* fof,int ihdu,int lp)
 | 
|---|
 | 1345 | {
 | 
|---|
 | 1346 |  Init(fof,ihdu,lp);
 | 
|---|
 | 1347 | }
 | 
|---|
 | 1348 | 
 | 
|---|
 | 1349 | /*! Constructor by copy */
 | 
|---|
 | 1350 | FitsImg3DRd::FitsImg3DRd(FitsImg3DRd& fbt)
 | 
|---|
 | 1351 | {
 | 
|---|
 | 1352 |  Init(fbt.GetFitsOpenFile(),fbt.HDU(),fbt.DbgLevel);
 | 
|---|
 | 1353 | }
 | 
|---|
 | 1354 | 
 | 
|---|
 | 1355 | /*! Constructor by default */
 | 
|---|
 | 1356 | FitsImg3DRd::FitsImg3DRd()
 | 
|---|
 | 1357 | {
 | 
|---|
 | 1358 |  Naxis[0] = Naxis[1] = Naxis[2] = 0;
 | 
|---|
 | 1359 |  SetNulVal(); SetDebug(0);
 | 
|---|
 | 1360 |  FitsOF = NULL;
 | 
|---|
 | 1361 | }
 | 
|---|
 | 1362 | 
 | 
|---|
 | 1363 | /*! Init routine called by the constructor */
 | 
|---|
 | 1364 | void FitsImg3DRd::Init(FitsOpenFile* fof,int ihdu,int lp)
 | 
|---|
 | 1365 | {
 | 
|---|
 | 1366 |  // Initialisation des Parametres Generaux
 | 
|---|
 | 1367 |  Naxis[0] = Naxis[1] = Naxis[2] = 0;
 | 
|---|
 | 1368 |  SetNulVal(); SetDebug(lp);
 | 
|---|
 | 1369 |  FitsOF = NULL;
 | 
|---|
 | 1370 | 
 | 
|---|
 | 1371 |  // Caracteristiques du FitsOpenFile
 | 
|---|
 | 1372 |  FitsOF = fof;
 | 
|---|
 | 1373 |  if(FitsOF==NULL)
 | 
|---|
 | 1374 |    throw NullPtrError("FitsImg3DRd::Init: FitsOpenFile pointer is NULL\n");
 | 
|---|
 | 1375 | 
 | 
|---|
 | 1376 |  if(GetFitsPtr()==NULL)
 | 
|---|
 | 1377 |    throw NullPtrError("FitsImg3DRd::Init: FitsPtr pointer is NULL\n");
 | 
|---|
 | 1378 | 
 | 
|---|
 | 1379 |  int sta = 0;
 | 
|---|
 | 1380 |  if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU(); 
 | 
|---|
 | 1381 | 
 | 
|---|
 | 1382 |  // Get HDU 3D image
 | 
|---|
 | 1383 |  // ATTENTION: ... cf blabla equivalent dans FitsABTColRd::Init()
 | 
|---|
 | 1384 |  if(FitsOF->GetPosStatus()==false) {
 | 
|---|
 | 1385 |    if(ihdu==0) { // find the first IMAGE_HDU
 | 
|---|
 | 1386 |      FitsOF->MoveToFirst(IMAGE_HDU);
 | 
|---|
 | 1387 |    } else {
 | 
|---|
 | 1388 |      int rc = FitsOF->MoveToHDU(ihdu);
 | 
|---|
 | 1389 |      if(rc!=ihdu)
 | 
|---|
 | 1390 |        throw RangeCheckError("FitsImg3DRd::Init: Error moving to requested HDU\n");
 | 
|---|
 | 1391 |    }
 | 
|---|
 | 1392 |  } else { // Fits file has already been positionned
 | 
|---|
 | 1393 |    if(ihdu>0 && ihdu!=HDU())
 | 
|---|
 | 1394 |      throw RangeCheckError("FitsImg3DRd::Init: file already posit. at another HDU\n");
 | 
|---|
 | 1395 |  }
 | 
|---|
 | 1396 | 
 | 
|---|
 | 1397 |  // Check HDUType and set position status to TRUE
 | 
|---|
 | 1398 |  if(HDUType()!=IMAGE_HDU)
 | 
|---|
 | 1399 |    throw TypeMismatchExc("FitsImg3DRd::Init: HDU not IMAGE_HDU\n");
 | 
|---|
 | 1400 |  FitsOF->SetPosStatus(true);
 | 
|---|
 | 1401 | 
 | 
|---|
 | 1402 |  // Get NAXIS 1, 2 et 3
 | 
|---|
 | 1403 |  int nfound=0;
 | 
|---|
| [3128] | 1404 |  // car fits_read_keys_lnglng n'est pas prototype dans longnam.h
 | 
|---|
 | 1405 |  if(ffgknjj(GetFitsPtr(),"NAXIS",1,3,Naxis,&nfound,&sta)) {
 | 
|---|
| [3114] | 1406 |    FitsOpenFile::printerror(sta);
 | 
|---|
 | 1407 |    throw RangeCheckError("FitsImg3DRd::Init: Error reading NAXIS cards\n");
 | 
|---|
 | 1408 |  }
 | 
|---|
 | 1409 |  if(DbgLevel>1)
 | 
|---|
 | 1410 |    cout<<"...Init(hdu="<<HDU()<<")  NAXIS1="<<Naxis[0]<<" NAXIS2="
 | 
|---|
 | 1411 |        <<Naxis[1]<<" NAXIS3="<<Naxis[2]<<" (nfound="<<nfound<<")"<<endl;
 | 
|---|
 | 1412 |  if(nfound!=3 || Naxis[0]<=0 || Naxis[1]<=0 || Naxis[2]<=0)
 | 
|---|
 | 1413 |    throw NotAvailableOperation("FitsImg3DRd::Init: bad Naxis[0-2] value\n");
 | 
|---|
 | 1414 | 
 | 
|---|
 | 1415 | }
 | 
|---|
 | 1416 | 
 | 
|---|
 | 1417 | /*! Destructor. */
 | 
|---|
 | 1418 | FitsImg3DRd::~FitsImg3DRd()
 | 
|---|
 | 1419 | {
 | 
|---|
 | 1420 |  //--- Surtout on ne "fits_close_file" pas le fichier FITS !!!
 | 
|---|
 | 1421 |  Naxis[0] = Naxis[1] = Naxis[2] = 0;
 | 
|---|
 | 1422 | }
 | 
|---|
 | 1423 | 
 | 
|---|
 | 1424 | //////////////////////////////////////////////////////////////
 | 
|---|
 | 1425 | /*!
 | 
|---|
 | 1426 |   Read a fitsheader key into double
 | 
|---|
 | 1427 |   \param keyname : name of the key
 | 
|---|
 | 1428 |   \return value into double
 | 
|---|
 | 1429 | */
 | 
|---|
 | 1430 | double FitsImg3DRd::ReadKey(char *keyname)
 | 
|---|
 | 1431 | {
 | 
|---|
 | 1432 |  return FitsOpenFile::ReadKey(GetFitsPtr(),keyname);
 | 
|---|
 | 1433 | }
 | 
|---|
 | 1434 | 
 | 
|---|
 | 1435 | /*!
 | 
|---|
 | 1436 |   Read a fitsheader key into long
 | 
|---|
 | 1437 |   \param keyname : name of the key
 | 
|---|
 | 1438 |   \return value into long
 | 
|---|
 | 1439 | */
 | 
|---|
 | 1440 | long FitsImg3DRd::ReadKeyL(char *keyname)
 | 
|---|
 | 1441 | {
 | 
|---|
 | 1442 |  return FitsOpenFile::ReadKeyL(GetFitsPtr(),keyname);
 | 
|---|
 | 1443 | }
 | 
|---|
 | 1444 | 
 | 
|---|
 | 1445 | /*!
 | 
|---|
| [3128] | 1446 |   Read a fitsheader key into long long
 | 
|---|
 | 1447 |   \param keyname : name of the key
 | 
|---|
 | 1448 |   \return value into long long
 | 
|---|
 | 1449 | */
 | 
|---|
 | 1450 | LONGLONG FitsImg3DRd::ReadKeyLL(char *keyname)
 | 
|---|
 | 1451 | {
 | 
|---|
 | 1452 |  return FitsOpenFile::ReadKeyLL(GetFitsPtr(),keyname);
 | 
|---|
 | 1453 | }
 | 
|---|
 | 1454 | 
 | 
|---|
 | 1455 | /*!
 | 
|---|
| [3114] | 1456 |   Read a fitsheader key into string
 | 
|---|
 | 1457 |   \param keyname : name of the key
 | 
|---|
 | 1458 |   \return value into string
 | 
|---|
 | 1459 | */
 | 
|---|
 | 1460 | string FitsImg3DRd::ReadKeyS(char *keyname)
 | 
|---|
 | 1461 | {
 | 
|---|
 | 1462 |  return FitsOpenFile::ReadKeyS(GetFitsPtr(),keyname);
 | 
|---|
 | 1463 | }
 | 
|---|
 | 1464 | 
 | 
|---|
 | 1465 | //////////////////////////////////////////////////////////////
 | 
|---|
 | 1466 | /* REMARQUE:
 | 
|---|
 | 1467 |  * Dans TArray A(naxis1,naxis2,naxis3);
 | 
|---|
 | 1468 |  *      A(i,j,k) -> i varie le plus vite et k le moins vite
 | 
|---|
 | 1469 |  */
 | 
|---|
 | 1470 | /*!
 | 
|---|
 | 1471 | Read 3D image into a TArray<uint_2>
 | 
|---|
 | 1472 | */
 | 
|---|
| [3128] | 1473 | LONGLONG FitsImg3DRd::Read(TArray<uint_2>& data)
 | 
|---|
| [3114] | 1474 | {
 | 
|---|
 | 1475 |  int sta=0;
 | 
|---|
 | 1476 |  uint_2* arr = new uint_2[Naxis[0]];
 | 
|---|
 | 1477 |  sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
 | 
|---|
 | 1478 | 
 | 
|---|
| [3128] | 1479 |  for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
 | 
|---|
 | 1480 |    LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
 | 
|---|
| [3114] | 1481 |    fits_read_img(GetFitsPtr(),TUSHORT,deb,nel,&NulVal,arr,NULL,&sta);
 | 
|---|
 | 1482 |    if(sta) {
 | 
|---|
 | 1483 |      FitsOpenFile::printerror(sta); delete [] arr;
 | 
|---|
 | 1484 |      throw
 | 
|---|
 | 1485 |        NotAvailableOperation("FitsImg3DRd::Read(TArray<uint_2>): Error Reading Fits file\n");
 | 
|---|
 | 1486 |    }
 | 
|---|
| [3128] | 1487 |    for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
 | 
|---|
| [3114] | 1488 |  }
 | 
|---|
 | 1489 | 
 | 
|---|
 | 1490 |  delete [] arr;
 | 
|---|
 | 1491 |  return Naxis[0]*Naxis[1]*Naxis[2];
 | 
|---|
| [3188] | 1492 | }
 | 
|---|
| [3114] | 1493 | 
 | 
|---|
 | 1494 | /*! Read 3D image into a TArray<int_4> */
 | 
|---|
| [3128] | 1495 | LONGLONG FitsImg3DRd::Read(TArray<int_4>& data)
 | 
|---|
| [3114] | 1496 | {
 | 
|---|
 | 1497 |  int sta=0;
 | 
|---|
 | 1498 |  int_4* arr = new int_4[Naxis[0]];
 | 
|---|
 | 1499 |  sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
 | 
|---|
 | 1500 |  int T = (sizeof(long)==4) ? TLONG: TINT;
 | 
|---|
 | 1501 | 
 | 
|---|
| [3128] | 1502 |  for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
 | 
|---|
 | 1503 |    LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
 | 
|---|
| [3114] | 1504 |    fits_read_img(GetFitsPtr(),T,deb,nel,&NulVal,arr,NULL,&sta);
 | 
|---|
 | 1505 |    if(sta) {
 | 
|---|
 | 1506 |      FitsOpenFile::printerror(sta); delete [] arr;
 | 
|---|
 | 1507 |      throw
 | 
|---|
 | 1508 |        NotAvailableOperation("FitsImg3DRd::Read(TArray<int_4>): Error Reading Fits file\n");
 | 
|---|
 | 1509 |    }
 | 
|---|
| [3128] | 1510 |    for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
 | 
|---|
| [3114] | 1511 |  }
 | 
|---|
 | 1512 | 
 | 
|---|
 | 1513 |  delete [] arr;
 | 
|---|
 | 1514 |  return Naxis[0]*Naxis[1]*Naxis[2];
 | 
|---|
| [3188] | 1515 | }
 | 
|---|
| [3114] | 1516 | 
 | 
|---|
 | 1517 | /*! Read 3D image into a TArray<int_8> */
 | 
|---|
| [3128] | 1518 | LONGLONG FitsImg3DRd::Read(TArray<int_8>& data)
 | 
|---|
| [3114] | 1519 | {
 | 
|---|
 | 1520 |  int sta=0;
 | 
|---|
 | 1521 |  int_8* arr = new int_8[Naxis[0]];
 | 
|---|
 | 1522 |  sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
 | 
|---|
 | 1523 | 
 | 
|---|
| [3128] | 1524 |  for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
 | 
|---|
 | 1525 |    LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
 | 
|---|
| [3114] | 1526 |    fits_read_img(GetFitsPtr(),TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta);
 | 
|---|
 | 1527 |    if(sta) {
 | 
|---|
 | 1528 |      FitsOpenFile::printerror(sta); delete [] arr;
 | 
|---|
 | 1529 |      throw
 | 
|---|
 | 1530 |        NotAvailableOperation("FitsImg3DRd::Read(TArray<int_8>): Error Reading Fits file\n");
 | 
|---|
 | 1531 |    }
 | 
|---|
| [3128] | 1532 |    for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
 | 
|---|
| [3114] | 1533 |  }
 | 
|---|
 | 1534 | 
 | 
|---|
 | 1535 |  delete [] arr;
 | 
|---|
 | 1536 |  return Naxis[0]*Naxis[1]*Naxis[2];
 | 
|---|
| [3188] | 1537 | }
 | 
|---|
| [3114] | 1538 | 
 | 
|---|
 | 1539 | /*! Read 3D image into a TArray<float> */
 | 
|---|
| [3128] | 1540 | LONGLONG FitsImg3DRd::Read(TArray<float>& data)
 | 
|---|
| [3114] | 1541 | {
 | 
|---|
 | 1542 |  int sta=0;
 | 
|---|
 | 1543 |  float* arr = new float[Naxis[0]];
 | 
|---|
 | 1544 |  sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
 | 
|---|
 | 1545 | 
 | 
|---|
| [3128] | 1546 |  for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
 | 
|---|
 | 1547 |    LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
 | 
|---|
| [3114] | 1548 |    fits_read_img(GetFitsPtr(),TFLOAT,deb,nel,&NulVal,arr,NULL,&sta);
 | 
|---|
 | 1549 |    if(sta) {
 | 
|---|
 | 1550 |      FitsOpenFile::printerror(sta); delete [] arr;
 | 
|---|
 | 1551 |      throw
 | 
|---|
 | 1552 |        NotAvailableOperation("FitsImg3DRd::Read(TArray<float>): Error Reading Fits file\n");
 | 
|---|
 | 1553 |    }
 | 
|---|
| [3128] | 1554 |    for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
 | 
|---|
| [3114] | 1555 |  }
 | 
|---|
 | 1556 | 
 | 
|---|
 | 1557 |  delete [] arr;
 | 
|---|
 | 1558 |  return Naxis[0]*Naxis[1]*Naxis[2];
 | 
|---|
| [3188] | 1559 | }
 | 
|---|
| [3114] | 1560 | 
 | 
|---|
 | 1561 | /*! Read 3D image into a TArray<double> */
 | 
|---|
| [3128] | 1562 | LONGLONG FitsImg3DRd::Read(TArray<double>& data)
 | 
|---|
| [3114] | 1563 | {
 | 
|---|
 | 1564 |  int sta=0;
 | 
|---|
 | 1565 |  double* arr = new double[Naxis[0]];
 | 
|---|
 | 1566 |  sa_size_t ndim[3] = {Naxis[0],Naxis[1],Naxis[2]}; data.ReSize(3,ndim);
 | 
|---|
 | 1567 | 
 | 
|---|
| [3128] | 1568 |  for(LONGLONG k=0;k<Naxis[2];k++) for(LONGLONG j=0;j<Naxis[1];j++) {
 | 
|---|
 | 1569 |    LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+1, nel = Naxis[0];
 | 
|---|
| [3114] | 1570 |    fits_read_img(GetFitsPtr(),TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta);
 | 
|---|
 | 1571 |    if(sta) {
 | 
|---|
 | 1572 |      FitsOpenFile::printerror(sta); delete [] arr;
 | 
|---|
 | 1573 |      throw
 | 
|---|
 | 1574 |        NotAvailableOperation("FitsImg3DRd::Read(TArray<double>): Error Reading Fits file\n");
 | 
|---|
 | 1575 |    }
 | 
|---|
| [3128] | 1576 |    for(LONGLONG i=0;i<Naxis[0];i++) data(i,j,k) = arr[i];
 | 
|---|
| [3114] | 1577 |  }
 | 
|---|
 | 1578 | 
 | 
|---|
 | 1579 |  delete [] arr;
 | 
|---|
 | 1580 |  return Naxis[0]*Naxis[1]*Naxis[2];
 | 
|---|
| [3188] | 1581 | }
 | 
|---|
| [3114] | 1582 | 
 | 
|---|
| [3188] | 1583 | /*! Read 3D image pixel i,j,k with i=[0,Naxis1[ , j=[0,Naxis2[ , k=[0,Naxis3[ */
 | 
|---|
 | 1584 | double FitsImg3DRd::Read(LONGLONG i, LONGLONG j, LONGLONG k)
 | 
|---|
 | 1585 | {
 | 
|---|
 | 1586 |  int sta=0;
 | 
|---|
 | 1587 |  if(i<0 || j<0 || k<0 || i>=Naxis[0] || j>=Naxis[1] || k>=Naxis[2])
 | 
|---|
 | 1588 |    throw
 | 
|---|
 | 1589 |      NotAvailableOperation("FitsImg3DRd::Read(i,j,k): bad i/j/k number\n");
 | 
|---|
 | 1590 | 
 | 
|---|
 | 1591 |    LONGLONG deb = Naxis[0]*(j+Naxis[1]*k)+i+1;
 | 
|---|
 | 1592 |    double val = 0.;
 | 
|---|
 | 1593 |    fits_read_img(GetFitsPtr(),TDOUBLE,deb,1,&NulVal,&val,NULL,&sta);
 | 
|---|
 | 1594 | 
 | 
|---|
 | 1595 |    if(sta) {
 | 
|---|
 | 1596 |      FitsOpenFile::printerror(sta);
 | 
|---|
 | 1597 |      throw
 | 
|---|
 | 1598 |        NotAvailableOperation("FitsImg3DRd::Read(i,j,k): Error Reading Fits file\n");
 | 
|---|
 | 1599 |    }
 | 
|---|
 | 1600 | 
 | 
|---|
 | 1601 |    return val;
 | 
|---|
 | 1602 | }
 | 
|---|
 | 1603 | 
 | 
|---|
| [3114] | 1604 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1605 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1606 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1607 | ///////////////////////////////////////////////////////////////////
 | 
|---|
 | 1608 | 
 | 
|---|
 | 1609 | //! Class for reading a 3D image from a FITS file
 | 
|---|
 | 1610 | 
 | 
|---|
 | 1611 | /*!
 | 
|---|
 | 1612 |   \class SOPHYA::FitsImg3DRead
 | 
|---|
 | 1613 |   \ingroup FitsIOServer
 | 
|---|
 | 1614 |   Class for reading a 3D image from a FITS file
 | 
|---|
 | 1615 | */
 | 
|---|
 | 1616 | 
 | 
|---|
 | 1617 | //////////////////////////////////////////////////////////////
 | 
|---|
 | 1618 | /*!
 | 
|---|
 | 1619 |   Constructor.
 | 
|---|
 | 1620 |   \param fname : name of the FITS file
 | 
|---|
 | 1621 |   \param ihdu : number of the HDU where the 3D image is.
 | 
|---|
 | 1622 |   \param lp : debug level
 | 
|---|
 | 1623 |   \verbatim
 | 
|---|
 | 1624 |   - if ihdu<=0 first IMAGE hdu is taken
 | 
|---|
 | 1625 |   - if ihdu>nhdu ihdu is set to nhdu
 | 
|---|
 | 1626 |   \endverbatim
 | 
|---|
 | 1627 |   \warning ihdu = [1,nhdu]
 | 
|---|
 | 1628 | */
 | 
|---|
 | 1629 | FitsImg3DRead::FitsImg3DRead(string fname,int ihdu,int lp)
 | 
|---|
 | 1630 | : FitsImg3DRd(new FitsOpenFile(fname),ihdu,lp)
 | 
|---|
 | 1631 | {
 | 
|---|
 | 1632 | }
 | 
|---|
 | 1633 | 
 | 
|---|
 | 1634 | /*! Constructor. see below */
 | 
|---|
 | 1635 | FitsImg3DRead::FitsImg3DRead(const char * cfname,int ihdu,int lp)
 | 
|---|
 | 1636 | : FitsImg3DRd(new FitsOpenFile(cfname),ihdu,lp)
 | 
|---|
 | 1637 | {
 | 
|---|
 | 1638 | }
 | 
|---|
 | 1639 | 
 | 
|---|
 | 1640 | /*! Constructor by default */
 | 
|---|
 | 1641 | FitsImg3DRead::FitsImg3DRead()
 | 
|---|
 | 1642 | : FitsImg3DRd()
 | 
|---|
 | 1643 | {
 | 
|---|
 | 1644 | }
 | 
|---|
 | 1645 | 
 | 
|---|
 | 1646 | /*! Constructor by copy */
 | 
|---|
 | 1647 | FitsImg3DRead::FitsImg3DRead(FitsImg3DRead& fimg)
 | 
|---|
 | 1648 | {
 | 
|---|
 | 1649 |  // --- ATTENTION ---
 | 
|---|
 | 1650 |  // FitsImg3DRead ferme le fichier FITS: il faut dupliquer le FitsOpenFile
 | 
|---|
 | 1651 |  FitsOpenFile* fof = new FitsOpenFile(*fimg.GetFitsOpenFile());
 | 
|---|
 | 1652 |  Init(fof,fimg.HDU(),fimg.DbgLevel);
 | 
|---|
 | 1653 | }
 | 
|---|
 | 1654 | 
 | 
|---|
 | 1655 | /*! Destructor. */
 | 
|---|
 | 1656 | FitsImg3DRead::~FitsImg3DRead()
 | 
|---|
 | 1657 | {
 | 
|---|
 | 1658 |  // On detruit le FitsOpenFile, cad qu'on ferme (fits_file_close) le fichier FITS
 | 
|---|
 | 1659 |  if(FitsOF!=NULL) delete FitsOF;
 | 
|---|
 | 1660 | }
 | 
|---|