Changeset 2456 in Sophya for trunk/SophyaExt/FitsIOServer


Ignore:
Timestamp:
Nov 18, 2003, 1:06:24 AM (22 years ago)
Author:
cmv
Message:

amelioration architecture classe cmv 18/11/03

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fabtcolread.cc

    r2453 r2456  
    4343{
    4444  FitsFN = "";
    45   NHdu = -1;
     45  NHdu = IHdu = HduType = 0;
     46  HasBeenPos = false;
    4647  FitsPtr = NULL;
    4748}
     
    5253FitsOpenFile::FitsOpenFile(FitsOpenFile& fof)
    5354{
    54   Init(fof.GetFileName().c_str());
     55  Init(fof.FileName().c_str());
    5556}
    5657
     
    6263  Delete();
    6364  FitsFN = "";
    64   NHdu = 0;
     65  NHdu = IHdu = HduType = 0;
     66  HasBeenPos = false;
    6567}
    6668
     
    8082void FitsOpenFile::Init(const char* fname)
    8183{
    82    // Parametres Generaux
    83    FitsFN = fname;
    84    NHdu = 0;
    85    FitsPtr = NULL;
    86 
    87    // Ouverture du fichier
    88    if(FitsFN.size() <= 0 )
    89       throw ParmError("FitsOpenFile::Init: Fits file name error\n");
    90 
    91    int sta = 0;
    92    if(fits_open_file(&FitsPtr,FitsFN.c_str(),READONLY,&sta)) {
    93      printerror(sta);
    94      FitsPtr = NULL;
    95      throw NullPtrError("FitsOpenFile::Init: Error opening Fits file\n");
    96    }
    97 
    98    // Get number of hdu
    99    if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
    100      printerror(sta);
    101      NHdu = 0;
    102      Delete();
    103      throw NotAvailableOperation("FitsOpenFile::Init: Error getting NHdu\n");
    104    }
    105    if(NHdu<=0) {
    106      Delete();
    107      throw SzMismatchError("FitsOpenFile::Init: Bad NHdu\n");
    108    }
    109 
    110  }
     84  // Parametres Generaux
     85  FitsFN = fname;
     86  NHdu = IHdu = HduType = 0;
     87  HasBeenPos = false;
     88  FitsPtr = NULL;
     89
     90  // Ouverture du fichier
     91  if(FitsFN.size() <= 0 )
     92     throw ParmError("FitsOpenFile::Init: Fits file name error\n");
     93
     94  int sta = 0;
     95  if(fits_open_file(&FitsPtr,FitsFN.c_str(),READONLY,&sta)) {
     96    printerror(sta);
     97    FitsPtr = NULL;
     98    throw NullPtrError("FitsOpenFile::Init: Error opening Fits file\n");
     99  }
     100
     101  // Get number of hdu
     102  if(fits_get_num_hdus(FitsPtr,&NHdu,&sta)) {
     103    printerror(sta);
     104    NHdu = 0;
     105    Delete();
     106    throw NotAvailableOperation("FitsOpenFile::Init: Error getting NHdu\n");
     107  }
     108  if(NHdu<=0) {
     109    Delete();
     110    throw SzMismatchError("FitsOpenFile::Init: Bad NHdu\n");
     111  }
     112
     113  MoveToHDU(1);
     114}
     115
     116/*! Move to an HDU
     117\param ihdu: hdu number to move
     118\warning ihdu = [1,nhdu]
     119\return 0 if positionning failed, ihdu if success
     120*/
     121int FitsOpenFile::MoveToHDU(int ihdu)
     122{
     123 if(FitsPtr==NULL)
     124   throw NullPtrError("FitsOpenFile::MoveToHDU: no fits file open FitsPtr==NULL\n");
     125 int ihdusave = IHdu;
     126 if(ihdu<=0) ihdu=1; if(ihdu>NHdu) ihdu=NHdu;
     127 int sta=0;
     128 if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) {
     129   printerror(sta);
     130   // On se repositionne ou on etait
     131   fits_movabs_hdu(FitsPtr,ihdusave,&HduType,&sta);
     132   IHdu = ihdusave;
     133 } else IHdu = ihdu;
     134 return IHdu;
     135}
     136
     137/*! Move to the first HDU of a certain type
     138\param hdutype: type of the hdu
     139\param hdudeb: start at that hdu
     140\return the type of HDU the file is positionned
     141*/
     142int FitsOpenFile::MoveToFirst(int hdutype,int ihdudeb)
     143{
     144 if(ihdudeb<=0) ihdudeb=1; if(ihdudeb>NHdu) ihdudeb=NHdu;
     145 int ihdusave = IHdu;
     146 for(int ihdu=ihdudeb;ihdu<=NHdu;ihdu++) {
     147   MoveToHDU(ihdu);
     148   if(HduType==hdutype) break;
     149 }
     150 // Si echec, on se repositionne ou on etait
     151 if(HduType!=hdutype) MoveToHDU(ihdusave);
     152 return HduType;
     153}
     154
     155/*! Move to the last HDU of a certain type
     156\param hdutype: type of the hdu
     157\param hdudeb: stop at that hdu
     158\return the type of HDU the file is positionned
     159*/
     160int FitsOpenFile::MoveToLast(int hdutype,int ihdudeb)
     161{
     162 if(ihdudeb<=0) ihdudeb=1; if(ihdudeb>NHdu) ihdudeb=NHdu;
     163 int ihdusave = IHdu;
     164 for(int ihdu=NHdu;ihdu>=ihdudeb;ihdu--) {
     165   MoveToHDU(ihdu);
     166   if(HduType==hdutype) break;
     167 }
     168 // Si echec, on se repositionne ou on etait
     169 if(HduType!=hdutype) MoveToHDU(ihdusave);
     170 return HduType;
     171}
     172
     173/*! Print */
     174void FitsOpenFile::Print(void)
     175{
     176 cout<<"FitsOpenFile::Print: "<<FitsFN
     177     <<" hdu="<<IHdu<<"/"<<NHdu<<" type="<<HduType
     178     <<" hasbeenpos="<<HasBeenPos<<endl;
     179}
    111180
    112181//////////////////////////////////////////////////////////////
     
    121190double FitsOpenFile::ReadKey(fitsfile *fitsptr,char *keyname)
    122191{
    123  if(keyname==NULL) return 0.;
     192 if(keyname==NULL || fitsptr==NULL) return 0.;
    124193 int sta=0; double val=0.;
    125194 if(fits_read_key(fitsptr,TDOUBLE,keyname,&val,NULL,&sta))
     
    136205long FitsOpenFile::ReadKeyL(fitsfile *fitsptr,char *keyname)
    137206{
    138  if(keyname==NULL) return 0;
     207 if(keyname==NULL || fitsptr==NULL) return 0;
    139208 int sta=0; long val=0;
    140209 if(fits_read_key(fitsptr,TLONG,keyname,&val,NULL,&sta))
     
    151220string FitsOpenFile::ReadKeyS(fitsfile *fitsptr,char *keyname)
    152221{
    153  if(keyname==NULL) return (string)"";
     222 if(keyname==NULL || fitsptr==NULL) return (string)"";
    154223 int sta=0; char val[FLEN_VALUE];
    155224 if(fits_read_key(fitsptr,TSTRING,keyname,val,NULL,&sta))
     
    189258  // Select the column to be read
    190259  FitsABTColRd fbt(fof,"BoloMuv_28",0,1000,1,3);
     260  FitsABTColRd fbt2(fof,"BoloMuv_29",0,1000,1,3);
    191261  fbt.SetDebug(3);
    192262  fbt.Print(3);
     
    194264  for(long i=0;i<fbt.GetNbLine();i++) {
    195265    double x = fbt.Read(i);
    196     if(i%lpmod==0) cout<<i<<": "<<x<<endl;
     266    double y = fbt2.Read(i);
     267    if(i%lpmod==0) cout<<i<<": "<<x<<", "<<y<<endl;
    197268  }
    198269  // Read into a vector
     
    203274  n = fbt.Read(10,-1,data);
    204275    cout<<"Number of values read: "<<n<<endl;
     276  TVector<double> data2;
     277  fbt2.Read(32,50,data);
    205278  // Close the fits file
    206279  delete fof;
     
    218291  \param lp : debug level
    219292  \verbatim
    220   - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken
     293  - if ihdu<=0 first BINARY or ASCII table is taken
     294  - if ihdu>nhdu ihdu is set to nhdu
    221295  - bsens>0    read forward
    222296    bsens<0    read backward
     
    247321{
    248322  Init(fbt.GetFitsOpenFile(),fbt.GetColLabel().c_str()
    249       ,fbt.GetColNum(),fbt.GetHDU()
     323      ,fbt.GetColNum(),fbt.HDU()
    250324      ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
    251325}
     
    254328FitsABTColRd::FitsABTColRd()
    255329{
    256  FitsFN = "";
    257330 ColLabel = ""; ColTUnit = ""; ColTForm = "";
    258331 ColNum = -1; ColTypeCode = 0;
    259  IHdu = 0; NHdu = 0; HduType = 0;
    260332 NBcol = 0; NBline = 0;
    261333 SetNulVal(); SetDebug(0);
     
    271343{
    272344 // Initialisation des Parametres Generaux
    273  FitsFN = "";
    274  ColLabel = collabel;
    275  ColTUnit = "";
    276  ColTForm = "";
    277  ColNum = colnum;
    278  ColTypeCode = 0;
    279  IHdu = ihdu;
    280  NHdu = 0;
    281  HduType = 0;
    282  NBcol = 0;
    283  NBline = 0;
    284  SetNulVal();
    285  SetDebug(lp);
     345 ColLabel=collabel; ColTUnit=""; ColTForm=""; ColNum=colnum; ColTypeCode=0;
     346 NBcol = 0; NBline = 0;
     347 SetNulVal(); SetDebug(lp);
    286348 NFitsRead = 0;
    287  FitsOF = NULL;
    288  FitsPtr = NULL;
     349 FitsOF = NULL; FitsPtr = NULL;
    289350 LineDeb = LineFin = -1;
    290351 Buffer = NULL;
    291  ChangeBuffer(blen,bsens);
    292352
    293353 // Caracteristiques du FitsOpenFile
    294354 FitsOF = fof;
    295  if(FitsOF==NULL) {
    296    Delete();
     355 if(FitsOF==NULL)
    297356   throw NullPtrError("FitsABTColRd::Init: FitsOpenFile pointer is NULL\n");
    298  }
     357
    299358 FitsPtr = FitsOF->GetFitsPtr();
    300  if(FitsPtr==NULL) {
    301    Delete();
     359 if(FitsPtr==NULL)
    302360   throw NullPtrError("FitsABTColRd::Init: FitsPtr pointer is NULL\n");
    303  }
    304  NHdu = FitsOF->GetNHdu();
    305  if(DbgLevel>1) cout<<"FitsABTColRd::Init  NHdu="<<NHdu<<endl;
    306  if(NHdu<=0) {
    307    Delete();
    308    throw SzMismatchError("FitsABTColRd::Init: Bad NHdu\n");
    309  }
    310  FitsFN = FitsOF->GetFileName();
    311  if(FitsFN.size() <= 0 ) {
    312    Delete();
    313    throw ParmError("FitsABTColRd::Init: Fits file name error\n");
    314  }
    315361
    316362 int sta = 0;
     363 if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU();
    317364
    318365 // Get HDU for bin/ascii table
    319  // si IHdu <=0 || >NHdu on cherche la 1ere bin/ascii table
    320  // sinon on se positionne sur IHdu
    321  if(IHdu<=0 || IHdu>NHdu)
    322    for(int ihdu=1;ihdu<=NHdu;ihdu++) {
    323      if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) FitsOpenFile::printerror(sta);
    324      if(DbgLevel>1) cout<<"...Init ihdu="
    325                         <<ihdu<<" HduType="<<HduType<<endl;
    326      if(HduType==BINARY_TBL || HduType==ASCII_TBL) {IHdu = ihdu; break;}
     366 // ATTENTION: le fichier est ouvert mais non positionne sur un HDU,
     367 // une classe utilisant ce fichier doit le positionner sur un HDU.
     368 // Par contre, si une autre classe utilise ce meme FitsOpenFile,
     369 // elle ne peut le positionner que sur ce meme HDU !
     370 if(FitsOF->GetPosStatus()==false) {
     371   if(ihdu==0) { // find the first BINARY then the first ASCII
     372     int rc = FitsOF->MoveToFirst(BINARY_TBL);
     373     if(rc!=BINARY_TBL) FitsOF->MoveToFirst(ASCII_TBL);
     374   } else {
     375     int rc = FitsOF->MoveToHDU(ihdu);
     376     if(rc!=ihdu)
     377       throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n");
    327378   }
    328  if(IHdu<=0 || IHdu>NHdu) {
    329    cout<<"NO BINARY or ASCII hdu found"<<endl;
    330    IHdu = 0; Delete();
    331    throw TypeMismatchExc("FitsABTColRd::Init: NO BINARY or ASCII hdu found\n");
    332  }
    333  if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) {
    334    FitsOpenFile::printerror(sta); Delete();
    335    throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n");
    336  }
    337  if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) {
    338    Delete();
     379 } else { // Fits file has already been positionned
     380   if(ihdu>0 && ihdu!=HDU())
     381     throw RangeCheckError("FitsABTColRd::Init: file already posit. at another HDU\n");
     382 }
     383
     384 // Check HDUType and set position status to TRUE
     385 if(HDUType()!=BINARY_TBL && HDUType()!=ASCII_TBL)
    339386   throw TypeMismatchExc("FitsABTColRd::Init: HDU not ASCII/BINARY table\n");
    340  }
     387 if(DbgLevel>1) cout<<"...Init ihdu="<<ihdu<<" HduType="<<HDUType()<<endl;
     388 FitsOF->SetPosStatus(true);
    341389
    342390 // Get number of columns
    343391 if(fits_get_num_cols(FitsPtr,&NBcol,&sta)) {
    344    FitsOpenFile::printerror(sta); Delete();
     392   FitsOpenFile::printerror(sta);
    345393   throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n");
    346394 }
    347395 if(DbgLevel>1) cout<<"...Init  NBcol="<<NBcol<<endl;
    348  if(NBcol<1) {
    349    Delete();
     396 if(NBcol<1)
    350397   throw RangeCheckError("FitsABTColRd::Init: Bad number of colums\n");
    351  }
    352398
    353399 // Get number of rows
    354400 if(fits_get_num_rows(FitsPtr,&NBline,&sta)) {
    355    FitsOpenFile::printerror(sta); Delete();
     401   FitsOpenFile::printerror(sta);
    356402   throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n");
    357403 }
    358404 if(DbgLevel>1) cout<<"...Init  NBline="<<NBline<<endl;
    359  if(NBline<1) {
    360    Delete();
     405 if(NBline<1)
    361406   throw RangeCheckError("FitsABTColRd::Init: Bad number of rows\n");
    362  }
    363407
    364408 // Get column number
     
    367411   strcpy(labelcol,ColLabel.c_str());
    368412   if(fits_get_colnum(FitsPtr,CASESEN,labelcol,&ColNum,&sta)) {
    369      FitsOpenFile::printerror(sta); Delete();
     413     FitsOpenFile::printerror(sta);
    370414     throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n");
    371415   }
     
    373417 }
    374418 if(DbgLevel>1) cout<<"...Init  ColNum="<<ColNum<<endl;
    375  if(ColNum<0 || ColNum>=NBcol) {
    376    Delete();
     419 if(ColNum<0 || ColNum>=NBcol)
    377420   throw RangeCheckError("FitsABTColRd::Init: Bad column number\n");
    378  }
    379421
    380422 // Get column type
    381423 if(fits_get_coltype(FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) {
    382    FitsOpenFile::printerror(sta); Delete();
     424   FitsOpenFile::printerror(sta);
    383425   throw ParmError("FitsABTColRd::Init: Error getting column type\n");
    384426 }
    385427 if(DbgLevel>1) cout<<"...Init ColTypeCode="<<ColTypeCode<<endl;
    386428 if(ColTypeCode==TSTRING || ColTypeCode==TCOMPLEX ||  ColTypeCode==TDBLCOMPLEX
    387                          || ColTypeCode<0 ) {
    388    Delete();
     429                         || ColTypeCode<0 )
    389430   throw ParmError("FitsABTColRd::Init: Selected column is not Numerical\n");
    390  }
    391431
    392432 // Get column name back, tunit, tform
     
    394434 long repeat=0; double tscale=1., tzero=0.;
    395435 int rc=0;
    396  if(HduType==BINARY_TBL) {
     436 if(HDUType()==BINARY_TBL) {
    397437   fits_get_bcolparms(FitsPtr,ColNum+1,labelcol,tunit,tform
    398438                     ,&repeat,&tscale,&tzero,NULL,tdisp,&sta);
     
    402442 }
    403443 if(rc) {
    404    FitsOpenFile::printerror(sta); Delete();
     444   FitsOpenFile::printerror(sta);
    405445   throw RangeCheckError("FitsABTColRd::Init: Error getting the column caracteristics\n");
    406446 }
     
    408448 ColTUnit = tunit;
    409449 ColTForm = tform;
     450
     451 // Set the buffer for reading
     452 ChangeBuffer(blen,bsens);
    410453
    411454 if(DbgLevel)
     
    779822   <<" ncols="<<NBcol<<" nrows="<<NBline;
    780823 if(lp>0) os<<" NRead="<<NFitsRead;
    781  os<<"\n... "<<FitsFN<<"["<<IHdu<<"/"<<NHdu<<"]"
    782    <<"\n... Label["<<ColNum<<"]="<<ColLabel
    783    <<" TypeCode="<<ColTypeCode
     824 os<<"\n... "<<FileName()<<"["<<HDU()<<"/"<<NHDU()<<" type="<<HDUType()<<"]"
     825   <<"\n... Label["<<ColNum<<"]="<<ColLabel<<" TypeCode="<<ColTypeCode
    784826   <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm
    785827   <<endl;
     
    828870  \param lp : debug level
    829871  \verbatim
    830   - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken
     872  - if ihdu<=0 first BINARY or ASCII table is taken
     873  - if ihdu>nhdu ihdu is set to nhdu
    831874  - bsens>0    read forward
    832875    bsens<0    read backward
     
    878921 FitsOpenFile* fof = new FitsOpenFile(*fbt.GetFitsOpenFile());
    879922 Init(fof,fbt.GetColLabel().c_str()
    880      ,fbt.GetColNum(),fbt.GetHDU()
     923     ,fbt.GetColNum(),fbt.HDU()
    881924     ,fbt.GetBLen(),fbt.GetBSens(),fbt.DbgLevel);
    882925}
     
    902945  Constructor.
    903946  \param fof : Pointer to the Class for opening the FITS file
    904   \param ihdu : number of the HDU where the column is.
     947  \param ihdu : number of the HDU where the image is.
    905948  \param lp : debug level
    906949  \verbatim
    907   - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken
     950  - if ihdu<=0 first IMAGE hdu is taken
     951  - if ihdu>nhdu ihdu is set to nhdu
    908952  \endverbatim
    909953  \warning ihdu = [1,nhdu]
     
    917961FitsImg2DRd::FitsImg2DRd(FitsImg2DRd& fbt)
    918962{
    919  Init(fbt.GetFitsOpenFile(),fbt.GetHDU(),fbt.DbgLevel);
     963 Init(fbt.GetFitsOpenFile(),fbt.HDU(),fbt.DbgLevel);
    920964}
    921965
     
    923967FitsImg2DRd::FitsImg2DRd()
    924968{
    925  FitsFN = "";
    926  IHdu = 0; NHdu = 0; HduType = 0;
    927969 Naxis[0] = Naxis[1] = 0;
    928970 SetNulVal(); SetDebug(0);
     
    934976{
    935977 // Initialisation des Parametres Generaux
    936  FitsFN = "";
    937  IHdu = ihdu; NHdu = 0; HduType = 0;
    938978 Naxis[0] = Naxis[1] = 0;
    939979 SetNulVal(); SetDebug(lp);
     
    944984 if(FitsOF==NULL)
    945985   throw NullPtrError("FitsImg2DRd::Init: FitsOpenFile pointer is NULL\n");
     986
    946987 FitsPtr = FitsOF->GetFitsPtr();
    947988 if(FitsPtr==NULL)
    948989   throw NullPtrError("FitsImg2DRd::Init: FitsPtr pointer is NULL\n");
    949  NHdu = FitsOF->GetNHdu();
    950  if(DbgLevel>1) cout<<"FitsImg2DRd::Init  NHdu="<<NHdu<<endl;
    951  if(NHdu<=0)
    952    throw SzMismatchError("FitsImg2DRd::Init: Bad NHdu\n");
    953  FitsFN = FitsOF->GetFileName();
    954  if(FitsFN.size() <= 0 )
    955    throw ParmError("FitsImg2DRd::Init: Fits file name error\n");
    956990
    957991 int sta = 0;
     992 if(ihdu<0) ihdu=0; if(ihdu>NHDU()) ihdu=NHDU();
    958993
    959994 // Get HDU 2D image
    960  // si IHdu <=0 || >NHdu on cherche la 1ere image
    961  // sinon on se positionne sur IHdu
    962  if(IHdu<=0 || IHdu>NHdu)
    963    for(int ihdu=1;ihdu<=NHdu;ihdu++) {
    964      if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) FitsOpenFile::printerror(sta);
    965      if(DbgLevel>1)
    966        cout<<"...Init ihdu="<<ihdu<<" HduType="<<HduType<<endl;
    967      if(HduType==IMAGE_HDU) {IHdu = ihdu; break;}
     995 // ATTENTION: ... cf blabla equivalent dans FitsABTColRd::Init()
     996 if(FitsOF->GetPosStatus()==false) {
     997   if(ihdu==0) { // find the first IMAGE_HDU
     998     FitsOF->MoveToFirst(IMAGE_HDU);
     999   } else {
     1000     int rc = FitsOF->MoveToHDU(ihdu);
     1001     if(rc!=ihdu)
     1002       throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n");
    9681003   }
    969  if(IHdu<=0 || IHdu>NHdu) {
    970    cout<<"NO IMAGE_HDU hdu found"<<endl;
    971    IHdu = 0;
    972    throw TypeMismatchExc("FitsImg2DRd::Init: NO IMAGE_HDU hdu found\n");
    973  }
    974  if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) {
    975    FitsOpenFile::printerror(sta);
    976    throw RangeCheckError("FitsImg2DRd::Init: Error moving to requested HDU\n");
    977  }
    978  if(HduType!=IMAGE_HDU)
     1004 } else { // Fits file has already been positionned
     1005   if(ihdu>0 && ihdu!=HDU())
     1006     throw RangeCheckError("FitsABTColRd::Init: file already posit. at another HDU\n");
     1007 }
     1008
     1009 // Check HDUType and set position status to TRUE
     1010 if(HDUType()!=IMAGE_HDU)
    9791011   throw TypeMismatchExc("FitsImg2DRd::Init: HDU not IMAGE_HDU\n");
     1012 FitsOF->SetPosStatus(true);
    9801013
    9811014 // Get NAXIS 1 et 2
     
    9861019 }
    9871020 if(DbgLevel>1)
    988    cout<<"...Init(hdu="<<IHdu<<")  NAXIS1="<<Naxis[0]<<" NAXIS2="<<Naxis[1]<<" (nfound="<<nfound<<")"<<endl;
     1021   cout<<"...Init(hdu="<<HDU()<<")  NAXIS1="<<Naxis[0]<<" NAXIS2="
     1022       <<Naxis[1]<<" (nfound="<<nfound<<")"<<endl;
    9891023 if(nfound!=2 || Naxis[0]<=0 || Naxis[1]<=0)
    9901024   throw NotAvailableOperation("FitsImg2DRd::Init: bad Naxis[0-1] value\n");
  • trunk/SophyaExt/FitsIOServer/fabtcolread.h

    r2453 r2456  
    2424  virtual ~FitsOpenFile();
    2525
    26   inline string GetFileName() {return FitsFN;}
    27   inline int GetNHdu() {return NHdu;}
    28   inline fitsfile* GetFitsPtr() {return FitsPtr;}
     26  inline string FileName() const {return FitsFN;}
     27  //! Get the number of the HDU read
     28  inline int HDU(void) const {return IHdu;}
     29  //! Get the number of the HDU type
     30  inline int HDUType(void) const {return HduType;}
     31  //! Get the number of HDU in file
     32  inline int NHDU() const {return NHdu;}
     33  //! Get the CFISTIO fits file pointer
     34  inline fitsfile* GetFitsPtr() const {return FitsPtr;}
     35  //! Set the positionning status of the file
     36  inline void SetPosStatus(bool sta=true) {HasBeenPos = sta;}
     37  //! Get the positionning status of the file
     38  inline bool GetPosStatus(void) const {return HasBeenPos;}
     39
     40  int MoveToHDU(int ihdu);
     41  int MoveToFirst(int hdutype,int ihdudeb=1);
     42  int MoveToLast(int hdutype,int ihdudeb=1);
     43  void Print(void);
    2944
    3045  static double ReadKey(fitsfile *fitsptr,char *keyname);
     
    3853
    3954  string FitsFN;
    40   int NHdu;
     55  int NHdu, IHdu, HduType;
    4156  fitsfile *FitsPtr;
     57  bool HasBeenPos;
    4258};
    4359
     
    6278  double Read(long n,bool usebuffer=true);
    6379
    64   long   Read(long n1,long n2,TVector<uint_2>& data);
    65   long   Read(long n1,long n2,TVector<int_4>& data);
    66   long   Read(long n1,long n2,TVector<int_8>& data);
    67   long   Read(long n1,long n2,TVector<float>& data);
    68   long   Read(long n1,long n2,TVector<double>& data);
     80  long Read(long n1,long n2,TVector<uint_2>& data);
     81  long Read(long n1,long n2,TVector<int_4>& data);
     82  long Read(long n1,long n2,TVector<int_8>& data);
     83  long Read(long n1,long n2,TVector<float>& data);
     84  long Read(long n1,long n2,TVector<double>& data);
    6985
    7086  //! return the value of the first row
     
    7995
    8096  //! Set debug level
    81   inline void    SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
     97  inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
    8298  //! Set null value to be return when reading null data (0=return the data)
    83   inline void    SetNulVal(double nulval=0.) {NulVal = nulval;}
     99  inline void SetNulVal(double nulval=0.) {NulVal = nulval;}
    84100  //! Get the FITS file name
    85   inline string  GetFileName(void) {return FitsFN;}
     101  inline string FileName(void) const
     102         {if(FitsOF) return FitsOF->FileName(); else return (string)"";}
    86103  //! Get the pointer to FitsOpenFile
    87   inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;}
     104  inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
    88105  //! Get the FITS file pointer (cfistio pointer)
    89   inline fitsfile* GetFitsPointer(void) {return FitsPtr;}
     106  inline fitsfile* GetFitsPtr(void) const {return FitsPtr;}
    90107  //! Get the number of HDU in the FITS file
    91   inline int     GetNHDU(void) {return NHdu;}
     108  inline int NHDU(void) const
     109         {if(FitsOF) return FitsOF->NHDU(); else return 0;}
    92110  //! Get the number of the HDU read
    93   inline int     GetHDU(void) {return IHdu;}
     111  inline int HDU(void) const
     112         {if(FitsOF) return FitsOF->HDU(); else return 0;}
    94113  //! Get the HDU type
    95   inline int     GetHDUType(void) {return HduType;}
     114  inline int HDUType(void) const
     115         {if(FitsOF) return FitsOF->HDUType(); else return 0;}
    96116  //! Get the number of rows in the FITS HDU to be read
    97   inline long    GetNbLine(void) {return NBline;}
     117  inline long GetNbLine(void) const {return NBline;}
    98118  //! Get the number of columns in the FITS HDU to be read
    99   inline int     GetNbCol(void) {return NBcol;}
     119  inline int GetNbCol(void) const {return NBcol;}
    100120  //! Get the columns number that is read
    101   inline int     GetColNum(void) {return ColNum;}
     121  inline int GetColNum(void) const {return ColNum;}
    102122  //! Get the columns label that is read
    103   inline string  GetColLabel(void) {return ColLabel;}
     123  inline string GetColLabel(void) const {return ColLabel;}
    104124  //! Get the columns type code that is read
    105   inline int     GetColTypeCode(void) {return ColTypeCode;}
     125  inline int GetColTypeCode(void) const {return ColTypeCode;}
    106126  //! Get the columns fits tunit that is read
    107   inline string  GetColTUnit(void) {return ColTUnit;}
     127  inline string GetColTUnit(void) const {return ColTUnit;}
    108128  //! Get the columns fits tform that is read
    109   inline string  GetColTForm(void) {return ColTForm;}
     129  inline string GetColTForm(void) const {return ColTForm;}
    110130  //! Get the read requested buffer length
    111   inline long    GetBLen(void) {return BuffLen;}
     131  inline long GetBLen(void) const {return BuffLen;}
    112132  //! Get the read buffer direction
    113   inline long    GetBSens(void) {return BuffSens;}
     133  inline long GetBSens(void) const {return BuffSens;}
    114134  //! Print to os
    115   virtual void   Print(ostream& os,int lp=1) const;
     135  virtual void Print(ostream& os,int lp=1) const;
    116136  //! Print to stdout
    117   inline  void   Print(int lp=1) const {Print(cout,lp);}
     137  inline  void Print(int lp=1) const {Print(cout,lp);}
    118138  //! Get the read effective buffer length
    119   inline long    GetNBuffer(void) {return NBuffer;}
     139  inline long GetNBuffer(void) const {return NBuffer;}
    120140  //! Get the read bufferpointer
    121141  inline double* GetBuffer(void) {return Buffer;}
     
    126146  void Delete(void);
    127147
    128   string FitsFN,ColLabel,ColTUnit,ColTForm;
    129   int ColNum,ColTypeCode,IHdu,NHdu,HduType,NBcol;
     148  string ColLabel,ColTUnit,ColTForm;
     149  int ColNum,ColTypeCode,NBcol;
    130150  long NBline;
    131151
     
    136156  unsigned long NFitsRead;
    137157  FitsOpenFile* FitsOF;
    138   fitsfile* FitsPtr;
     158  fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout!
    139159  long LineDeb, LineFin;
    140160  double *Buffer;
     
    175195  string ReadKeyS(char *keyname);
    176196
    177   long   Read(TMatrix<uint_2>& data);
    178   long   Read(TMatrix<int_4>& data);
    179   long   Read(TMatrix<int_8>& data);
    180   long   Read(TMatrix<float>& data);
    181   long   Read(TMatrix<double>& data);
     197  long Read(TMatrix<uint_2>& data);
     198  long Read(TMatrix<int_4>& data);
     199  long Read(TMatrix<int_8>& data);
     200  long Read(TMatrix<float>& data);
     201  long Read(TMatrix<double>& data);
    182202
    183203  //! Set debug level
     
    186206  inline void    SetNulVal(double nulval=0.) {NulVal = nulval;}
    187207  //! Get the pointer to FitsOpenFile
    188   inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;}
     208  inline FitsOpenFile* GetFitsOpenFile(void) const {return FitsOF;}
     209  //! Get the FITS file pointer (cfistio pointer)
     210  inline fitsfile* GetFitsPtr(void) const {return FitsPtr;}
     211  //! Get the number of HDU in the FITS file
     212  inline int NHDU(void) const
     213         {if(FitsOF) return FitsOF->NHDU(); else return 0;}
    189214  //! Get the number of the HDU read
    190   inline int     GetHDU(void) {return IHdu;}
     215  inline int HDU(void) const
     216         {if(FitsOF) return FitsOF->HDU(); else return 0;}
    191217  //! Get the HDU type
    192   inline int     GetHDUType(void) {return HduType;}
     218  inline int HDUType(void) const
     219         {if(FitsOF) return FitsOF->HDUType(); else return 0;}
    193220  //! Get NAXIS1
    194   inline long    GetNaxis1(void) {return Naxis[0];}
     221  inline long Naxis1(void) const {return Naxis[0];}
    195222  //! Get NAXIS2
    196   inline long    GetNaxis2(void) {return Naxis[1];}
     223  inline long Naxis2(void) const {return Naxis[1];}
    197224
    198225protected:
    199226  void Init(FitsOpenFile* fof,int ihdu,int lp);
    200227
    201   string FitsFN;
    202   int IHdu,NHdu,HduType;
    203228  long Naxis[2];
    204 
    205229  double NulVal;
    206230  unsigned short DbgLevel;
    207231
    208232  FitsOpenFile* FitsOF;
    209   fitsfile* FitsPtr;
    210 };
     233  fitsfile* FitsPtr; // Redite avec FitsOF->FitsPtr, mais utilise partout!
     234};
Note: See TracChangeset for help on using the changeset viewer.