Changeset 1657 in Sophya for trunk/SophyaExt


Ignore:
Timestamp:
Sep 27, 2001, 7:45:52 PM (24 years ago)
Author:
cmv
Message:

possibilite d'ecrire directement des TVector fabtwriter cmv 27/9/01

Location:
trunk/SophyaExt/FitsIOServer
Files:
4 edited

Legend:

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

    r1654 r1657  
    9898 SetNulVal();
    9999 SetDebug(lp);
    100  BuffLen = (blen<=0) ? 1: blen;
    101  BuffSens = bsens;
    102100 NFitsRead = 0;
    103101 FitsPtr = NULL;
    104102 LineDeb = LineFin = -1;
    105103 Buffer = NULL;
    106  NBuffer = 0;
     104 ChangeBuffer(blen,bsens);
    107105
    108106 //////////////////////////
     
    112110 int sta=0;
    113111 if(FitsFN.size() <= 0 ) {
    114    IHdu = -1;
     112   IHdu = -1; Delete();
    115113   throw ParmError("FitsABTColRead::Init: Fits file name error\n");
    116114 }
     
    145143   }
    146144 if(IHdu<=0 || IHdu>NHdu) {
    147    IHdu = 0;
    148145   cout<<"NO BINARY or ASCII hdu found"<<endl;
    149    Delete();
     146   IHdu = 0; Delete();
    150147   throw TypeMismatchExc("FitsABTColRead::Init: NO BINARY or ASCII hdu found\n");
    151148 }
     
    230227       <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl;
    231228
    232  // Prepare buffer
    233  NBuffer = (BuffSens==0) ? BuffLen+1: BuffLen;
    234  Buffer = new double[NBuffer];
    235229}
    236230
     
    246240void FitsABTColRead::ChangeBuffer(long blen,long bsens)
    247241{
     242 long oldnbuffer = NBuffer;
     243
     244 // Compute buffer caracteristics
    248245 BuffLen = (blen<=0)? 1: blen;
    249246 BuffSens = bsens;
    250 
    251  // De-allocate
    252  if(Buffer==NULL) return;
    253  delete [] Buffer; Buffer=NULL;
     247 NBuffer = BuffLen;
     248 if(bsens==0 && NBuffer%2==0) NBuffer++;
     249
     250 // De-allocate if necessary
     251 if(Buffer!=NULL && oldnbuffer!=NBuffer)
     252   {delete [] Buffer; Buffer=NULL;}
     253
     254 // Re-allocate
     255 if(Buffer==NULL) Buffer = new double[NBuffer];
    254256
    255257 // Tell program that nothing is into buffer
    256258 LineDeb = LineFin = -1;
    257 
    258  // Re-allocate
    259  NBuffer = (BuffSens==0) ? BuffLen+1: BuffLen;
    260  Buffer = new double[NBuffer];
    261259}
    262260
     
    264262void FitsABTColRead::Delete()
    265263{
    266  if(Buffer==NULL) return;
    267  delete [] Buffer; Buffer=NULL;
     264 if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;}
    268265 LineDeb = LineFin = -1;
    269266 int sta = 0;
     
    279276  \endverbatim
    280277*/
    281 r_8 FitsABTColRead::Read(long n)
     278double FitsABTColRead::Read(long n)
    282279// Attention: n=nline [0,NBline[, cfistio veut [1,NBline]
    283280// Attention: colnum  [0,NBcol[ , cfistio veut [1,NBcol]
     
    288285
    289286 // Pas de bufferisation, on lit betement
    290  if(BuffLen==1) {
     287 if(NBuffer==1) {
    291288   NFitsRead++;
    292289   fits_read_col_dbl(FitsPtr,ColNum+1,n+1,1,1,NulVal,Buffer,&anynul,&sta);
     
    308305   if(BuffSens>0) { // Cas remplissage forward
    309306     row1 = n+1;
    310      row2 = row1+BuffLen-1; if(row2>NBline) row2 = NBline;
     307     row2 = row1+NBuffer-1; if(row2>NBline) row2 = NBline;
    311308   } else if(BuffSens<0) { // Cas remplissage backward
    312309     row2 = n+1;
    313      row1 = row2-BuffLen+1; if(row1<1) row1 = 1;
     310     row1 = row2-NBuffer+1; if(row1<1) row1 = 1;
    314311   } else { // Cas remplissage centre
    315      row1 = n+1 - BuffLen/2; if(row1<1) row1 = 1;
    316      row2 = n+1 + BuffLen/2; if(row2>NBline) row2 = NBline;
     312     row1 = n+1 - NBuffer/2; if(row1<1) row1 = 1;
     313     row2 = n+1 + NBuffer/2; if(row2>NBline) row2 = NBline;
    317314   }
    318315   nrow = row2 - row1 + 1;
     
    339336  \endverbatim
    340337*/
    341 void FitsABTColRead::Read(long n1,long n2,TVector<r_8>& data)
     338void FitsABTColRead::Read(long n1,long n2,TVector<double>& data)
    342339{
    343340 if(n1<0 || n1>=NBline || n2<0 || n2>=NBline || n1>n2)
  • trunk/SophyaExt/FitsIOServer/fabtcolread.h

    r1654 r1657  
    3030  void ChangeBuffer(long blen=100,long bsens=1);
    3131
    32   r_8 Read(long n);
    33   void Read(long n1,long n2,TVector<r_8>& data);
     32  double Read(long n);
     33  void Read(long n1,long n2,TVector<double>& data);
    3434
    3535  //! Set debug level
    36   inline void    SetDebug(int lp=0) {DbgLevel = (uint_2) lp;}
     36  inline void    SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
    3737  //! Set null value to be return when reading null data (0=return the data)
    38   inline void    SetNulVal(r_8 nulval=0.) {NulVal = nulval;}
     38  inline void    SetNulVal(double nulval=0.) {NulVal = nulval;}
    3939  //! Get the FITS file name
    4040  inline string  GetFileName(void) {return FitsFN;}
     
    5959  //! Get the columns fits tform that is read
    6060  inline string  GetColTForm(void) {return ColTForm;}
    61   //! Get the read buffer length
     61  //! Get the read requested buffer length
    6262  inline long    GetBLen(void) {return BuffLen;}
    6363  //! Get the read buffer direction
     
    6767  //! Print to stdout
    6868  inline  void   Print(int lp=1) const {Print(cout,lp);}
    69   //! Get the read buffer effective length
    70   inline long    GetBufferLen(void) {return NBuffer;}
     69  //! Get the read effective buffer length
     70  inline long    GetNBuffer(void) {return NBuffer;}
    7171  //! Get the read bufferpointer
    7272  inline double* GetBuffer(void) {return Buffer;}
     
    8282  long NBline;
    8383
    84   r_8 NulVal;
    85   uint_2 DbgLevel;
     84  double NulVal;
     85  unsigned short DbgLevel;
    8686  long BuffLen, BuffSens;
    8787
    88   uint_4 NFitsRead;
     88  unsigned long NFitsRead;
    8989  fitsfile *FitsPtr;
    9090  long LineDeb, LineFin;
  • trunk/SophyaExt/FitsIOServer/fabtwriter.cc

    r1654 r1657  
    1414  FitsABTWriter fbtw("myfits.fits",BINARY_TBL,3);
    1515  fbtw.SetExtName("MY_OWN_EXTENSION");
    16   fbtw.AddCol("vars",TSHORT,"","km");      // col=0
    17   fbtw.AddCol("vars2",TSHORT,"","km");     // col=1
    18   fbtw.AddCol("varl",TLONG,"","Degre");    // col=2
    19   fbtw.AddCol("varf",TFLOAT,"","");        // col=3
    20   fbtw.AddCol("vard",TDOUBLE,"","arcmin"); // col=4
     16  fbtw.AddCol("vars",TSHORT,"","km");       // col=0
     17  fbtw.AddCol("vars2",TSHORT,"","km");      // col=1
     18  fbtw.AddCol("varl",TINT32BIT,"","Degre"); // col=2
     19  fbtw.AddCol("varf",TFLOAT,"","");         // col=3
     20  fbtw.AddCol("vard",TDOUBLE,"","arcmin");  // col=4
    2121  fbtw.SetDebug(3);
    2222  for(long i=0;i<1000;i++) {
     
    8383 }
    8484
    85  // create d'un Primary HDU */
     85 // create d'un Primary HDU
    8686 //long naxes[1] = {0};
    8787 //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) {
     
    105105  \verbatim
    106106  label : column label
    107   datatype : TSHORT TLONG TFLOAT or TDOUBLE
     107  datatype : TSHORT TINT32BIT TFLOAT or TDOUBLE
    108108  tform : fits tform definition
    109109          (can be automatically set if BINARY_TBL and tform="")
     
    117117    throw AllocationError("FitsABTWriter::addcol: table already created\n");
    118118
    119  if(  datatype!=TSHORT && datatype!=TLONG
     119 if(  datatype!=TSHORT && datatype!=TINT32BIT
    120120   && datatype!=TFLOAT && datatype!=TDOUBLE )
    121121   throw ParmError("FitsABTWriter::addcol: datatype not allowed\n");
     
    126126 if(HduType==BINARY_TBL && strlen(tform)<=0) {
    127127   char str[16];
    128    if(datatype==TSHORT)       strcpy(str,"1I");
    129    else if(datatype==TLONG)  strcpy(str,"1J");
    130    else if(datatype==TFLOAT)  strcpy(str,"1E");
    131    else if(datatype==TDOUBLE) strcpy(str,"1D");
     128   if(datatype==TSHORT)         strcpy(str,"1I");
     129   else if(datatype==TINT32BIT) strcpy(str,"1J");
     130   else if(datatype==TFLOAT)    strcpy(str,"1E");
     131   else if(datatype==TDOUBLE)   strcpy(str,"1D");
    132132   TForm.push_back(str);
    133133 } else TForm.push_back(tform);
     
    217217{
    218218  if(FirstTime) createtbl();
    219   short x[1] = {val};
    220   int sta=0;
    221   if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,x,&sta))
     219  int sta=0;
     220  if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,&val,&sta))
    222221    printerrorwrite("short",col,row,sta);
    223222}
    224223
    225224/*! Write long data to FITS file (see below) */
    226 void FitsABTWriter::Write(int col,long row,long val)
    227 {
    228   if(FirstTime) createtbl();
    229   long x[1] = {val};
    230   int sta=0;
    231   if(fits_write_col(FitsPtr,TLONG,col+1,row+1,1,1,x,&sta))
     225void FitsABTWriter::Write(int col,long row,int_4 val)
     226{
     227  if(FirstTime) createtbl();
     228  int sta=0;
     229  // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
     230  int T = (sizeof(long)==4) ? TLONG: TINT;
     231  if(fits_write_col(FitsPtr,T,col+1,row+1,1,1,&val,&sta))
    232232    printerrorwrite("long",col,row,sta);
    233233}
     
    237237{
    238238  if(FirstTime) createtbl();
    239   float x[1] = {val};
    240   int sta=0;
    241   if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,x,&sta))
     239  int sta=0;
     240  if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,&val,&sta))
    242241    printerrorwrite("float",col,row,sta);
    243242}
     
    247246{
    248247  if(FirstTime) createtbl();
    249   double x[1] = {val};
    250   int sta=0;
    251   if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,x,&sta))
     248  int sta=0;
     249  if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,&val,&sta))
    252250    printerrorwrite("double",col,row,sta);
    253251}
    254252
     253//////////////////////////////////////////////////////////////
     254/*!
     255  Write a vector of long data to FITS file.
     256  \verbatim
     257  col : column number [0,ncol[
     258  row : starting row number    [0,nrow[
     259  val : vector to be written
     260  Return: number of the last written row (remember row=[0,nrow[)
     261  \endverbatim
     262*/
     263/*! Write a vector of long data to FITS file (see below) */
     264long FitsABTWriter::Write(int col,long row,TVector<int_4>& val)
     265{
     266  if(FirstTime) createtbl();
     267  long nel = val.Size();
     268  int sta=0;
     269  // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ?
     270  int T = (sizeof(long)==4) ? TLONG: TINT;
     271  if(fits_write_col(FitsPtr,T,col+1,row+1,1,nel,val.Data(),&sta))
     272    printerrorwrite("long",col,row,sta);
     273  return row+nel;
     274}
     275
     276/*! Write a vector of float data to FITS file (see below) */
     277long FitsABTWriter::Write(int col,long row,TVector<float>&  val)
     278{
     279  if(FirstTime) createtbl();
     280  long nel = val.Size();
     281  int sta=0;
     282  if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta))
     283    printerrorwrite("float",col,row,sta);
     284  return row+nel;
     285}
     286
     287/*! Write a vector of double data to FITS file (see below) */
     288long FitsABTWriter::Write(int col,long row,TVector<double>& val)
     289{
     290  if(FirstTime) createtbl();
     291  long nel = val.Size();
     292  int sta=0;
     293  if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta))
     294    printerrorwrite("double",col,row,sta);
     295  return row+nel;
     296}
     297
     298//////////////////////////////////////////////////////////////
    255299void FitsABTWriter::printerrorwrite(char* type,int col,long row,int sta)
    256300{
  • trunk/SophyaExt/FitsIOServer/fabtwriter.h

    r1654 r1657  
    3737  inline void SetExtName(char* extname="") {ExtName = extname;}
    3838  //! Set debug level
    39   inline void SetDebug(int lp=0) {DbgLevel = (uint_2) lp;}
     39  inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}
    4040
    41   void Write(int col,long row,short  val);
    42   void Write(int col,long row,long  val);
    43   void Write(int col,long row,float  val);
     41  void Write(int col,long row,short val);
     42  void Write(int col,long row,int_4 val);
     43  void Write(int col,long row,float val);
    4444  void Write(int col,long row,double val);
     45  long Write(int col,long row,TVector<int_4>& val);
     46  long Write(int col,long row,TVector<float>& val);
     47  long Write(int col,long row,TVector<double>& val);
    4548  //! Return the number of overflows managed by cfitsio
    46   inline uint_4 GetNOverFlow(void) {return NOverFlow;}
     49  inline unsigned long GetNOverFlow(void) {return NOverFlow;}
    4750
    4851protected:
     
    5659  string FitsFN,ExtName;
    5760  int HduType;
    58   uint_2 DbgLevel;
     61  unsigned short DbgLevel;
    5962  fitsfile *FitsPtr;
    6063  bool FirstTime;
     
    6366  vector<string> TForm;
    6467  vector<string> TUnit;
    65   uint_4 NOverFlow;
     68  unsigned long NOverFlow;
    6669};
    6770
Note: See TracChangeset for help on using the changeset viewer.