Changeset 1234 in Sophya for trunk/SophyaExt


Ignore:
Timestamp:
Oct 13, 2000, 12:34:37 PM (25 years ago)
Author:
ansari
Message:

changement convention pour premier header

Location:
trunk/SophyaExt/FitsIOServer
Files:
3 edited

Legend:

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

    r1231 r1234  
    104104void FitsIOHandler::Read(FitsInFile& is, int hdunum)
    105105{
    106     if (hdunum == 0)  is.moveToFollowingHeader();
    107    else is.ReadFInit(hdunum);
     106  //  if (hdunum == 0 ) is.moveToFollowingHeader();
     107  //  else is.ReadFInit(hdunum);
     108  is.ReadFInit(hdunum);
    108109  ReadFromFits(is);
    109110}
     
    115116for writing a new object in a new fits-extension :
    116117
    117 \warning By convention, primary header does not contain fits-image data : i.e.
    118 all data are fits-extensions. The first relevant header will have hdunum=2.
    119 For switching off this convention use the method :
     118\warning By convention, primary header may contain fits-image data.
     119For switching off this convention (i.e. to make sure that all data will be on fits-extensions) use the method :
    120120
    121121firstImageOnPrimaryHeader() (see below)
    122 
    123 In that case do not forget to precise hdunum=1 when reading data on primary header.
    124122
    125123calls the method 'WriteToFits' from the inherited  object
     
    330328void FitsInFile::ReadFInit(int hdunum)
    331329{
    332    InitNull();
    333   // int status = 0;
    334  
    335   //  fits_open_file(&fptr_,flnm,READONLY,&status);
    336   //  if( status ) printerror( status );
    337 
    338   int status = 0;
    339 
    340   if (hdunum <= 1)
    341     {
    342       hdunum_ = 1;
    343       // presence of image ?
    344       int naxis= 0;
    345       fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
    346       if( status ) printerror( status );
    347       if (naxis > 0 )       // there is an image
    348         {
    349           hdutype_ = IMAGE_HDU;
    350           GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
    351           nbData_ =  1;
    352           int k;
    353           for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
    354           KeywordsIntoDVList(fptr_, dvl_,hdunum_);
    355         }
    356       else
    357         {
    358           throw PException(" first header : no image, probably error in hdunum");
    359         }
    360   //
    361     }
    362   else
    363     {
    364       hdunum_ = hdunum-1;
    365       int hdutype;
    366       fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    367       if( status ) printerror( status,":FitsFile::ReadF : erreur movabs");
    368       moveToFollowingHeader();
    369     }
     330  InitNull();
     331  int status = 0;
     332
     333  if (hdunum != 0 ) hdunum_ = hdunum;
     334
     335  // si le numero de header non precise
     336  else
     337    {
     338      // si c'est le premier objet a lire 
     339      if (hdunum_ == 0)
     340        {
     341          // on calcule le numero de header a lire
     342          if (imageOnPrimary_ == true) hdunum_ = 1;
     343          else hdunum_ = 2;
     344        }
     345      // sinon objet suivant 
     346      else hdunum_++;
     347    }
     348  getHeader();
     349
    370350}
    371351
     
    418398   }
    419399
     400void FitsInFile::getHeader()
     401{
     402  int status=0;
     403  if (hdunum_ < 1)  throw PException(" attempt to read hdunum < 1");
     404  if (hdunum_ == 1)
     405    {
     406      // presence of image ?
     407      int naxis= 0;
     408      fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status);
     409      if( status ) printerror( status );
     410      if (naxis > 0 )       // there is an image
     411        {
     412          hdutype_ = IMAGE_HDU;
     413          GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
     414          nbData_ =  1;
     415          int k;
     416          for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
     417          KeywordsIntoDVList(fptr_, dvl_,hdunum_);
     418        }
     419      else
     420        {
     421          throw PException(" first header : no image, probably error in hdunum");
     422        }
     423    }
     424  else
     425    {
     426      int hdutype;
     427      fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
     428      if( status ) printerror( status,":FitsInFile::getHeader : erreur movabs");
     429      hdutype_= hdutype;
     430      if(hdutype_ == IMAGE_HDU)
     431        {
     432          GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
     433          nbData_ =  1;
     434          int k;
     435          for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
     436          KeywordsIntoDVList(fptr_, dvl_,hdunum_);
     437        }
     438      if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
     439        {
     440          GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
     441          KeywordsIntoDVList(fptr_, dvl_, hdunum_);
     442        }
     443    }
     444}
     445
    420446
    421447void FitsInFile::moveToFollowingHeader()
    422448{
    423449  int status = 0;
    424   int hdutype;
    425   InitNull();
    426   fits_movrel_hdu(fptr_, 1,&hdutype,&status);
    427   if( status ) printerror( status," lecture du header suivant" );
    428450  hdunum_++;
    429   hdutype_= hdutype;
    430   if(hdutype_ == IMAGE_HDU)
    431     {
    432       GetImageParameters (fptr_, bitpix_, naxis_, naxisn_);
    433       nbData_ =  1;
    434       int k;
    435       for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k];
    436       KeywordsIntoDVList(fptr_, dvl_,hdunum_);
    437     }
    438   if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL)
    439     {
    440       GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_);
    441       KeywordsIntoDVList(fptr_, dvl_, hdunum_);
    442     }
     451  getHeader();
    443452}
    444453
     
    11821191  long naxis = nbdim;
    11831192  long* naxes = new long[nbdim];
    1184   if (hdunum_ == 1)
     1193  //  if (hdunum_ == 1)
     1194  if (hdunum_ == 0)
    11851195    {
    11861196      if (imageOnPrimary_ == false)
    11871197        {
     1198          hdunum_ = 1;
    11881199          fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status);
    11891200          writeSignatureOnFits();       }
    1190       else  hdunum_--;
     1201      //      else  hdunum_--;
    11911202    }
    11921203  int k;
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1231 r1234  
    7171   static string GetErrStatus(int status);
    7272   inline  int   statusF() const { return fits_status_;}
     73   inline void firstImageOnPrimaryHeader(bool choice) {imageOnPrimary_=choice;}
    7374 
    7475
     
    7879   static  void printerror(int&) ;
    7980   static  void printerror(int&,char* texte) ;
    80    inline void  InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 1;
    81    fits_status_ = 0;}
     81   inline void  InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 0;
     82   fits_status_ = 0; imageOnPrimary_ = true;}
    8283
    8384   fitsfile *fptr_;     /**<  pointer to the FITS file, defined in fitsio.h */
     
    8586   int hdunum_;         /**<   index of header to be read/written */
    8687   int fits_status_;    /**< last status returned by fitsio library. updated only by several methods */
     88   bool imageOnPrimary_;
    8789
    8890 };
     
    184186
    185187void InitNull();
     188void getHeader();
    186189static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum);
    187190static  void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn);
     
    211214   FitsOutFile(const char * flnm, WriteMode wrm = unknown );
    212215   ~FitsOutFile() { ;};
    213    inline void InitNull() {imageOnPrimary_=false;}
     216   inline void InitNull() {;}
    214217
    215218       //////////////////////////////////////////////////////////
     
    224227
    225228
    226    inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}
    227229   void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ;
    228230   void PutImageToFits( int nbData, double* map) const;
     
    261263  void addKeywordsOfDVList(DVList& dvl) const;
    262264
    263   bool imageOnPrimary_;
    264265
    265266 };
  • trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc

    r1221 r1234  
    231231     }
    232232   FitsOutFile  fout(filename);
    233    fout.firstImageOnPrimaryHeader();
     233   fout.firstImageOnPrimaryHeader(true);
    234234   FITS_TArray<r_4> fta(map);
    235235   fta.Write(fout);
     
    262262     }
    263263   FitsOutFile  fout(filename);
    264    fout.firstImageOnPrimaryHeader();
     264   fout.firstImageOnPrimaryHeader(true);
    265265   FITS_TArray<r_4> fta(map);
    266266   fta.Write(fout);
Note: See TracChangeset for help on using the changeset viewer.