Changeset 1193 in Sophya for trunk/SophyaExt


Ignore:
Timestamp:
Sep 19, 2000, 5:08:16 PM (25 years ago)
Author:
ansari
Message:

amelioration lecture ligne a ligne

Location:
trunk/SophyaExt/FitsIOServer
Files:
4 edited

Legend:

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

    r1162 r1193  
    11#include "pexceptions.h"
    22#include "fitsbntbllinereader.h"
     3#include "utils.h"
    34///////////////////////////////////////////////////////////
    45//   
     
    6465      }
    6566    }
    66   ColName_ = new char*[nbcols];
     67  vector<string> ColN(nbcols);
    6768  int compt=0;
    6869  for (k=0; k<DfitsCol.size(); k++)
    6970    {
    70       ColName_[compt] = new char[LONNOM+1];
    71       //      strncpy(ColName_[compt], fn->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    72       strncpy(ColName_[compt], inFits_->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM);
    73       ColName_[compt++][ LONNOM] =  '\0';
     71      ColN[compt] = inFits_->ColNameFromFits(DfitsCol[k]);
    7472    }
    7573  for (k=0; k<FfitsCol.size(); k++)
    7674    {
    77       ColName_[compt] = new char[LONNOM+1];
    78       //      strncpy(ColName_[compt], fn->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    79       strncpy(ColName_[compt], inFits_->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM);
    80       ColName_[compt++][ LONNOM] =  '\0';
     75      ColN[compt] =  inFits_->ColNameFromFits(FfitsCol[k]);
    8176    }
    8277  for (k=0; k<IfitsCol.size(); k++)
    8378    {
    84       ColName_[compt] = new char[LONNOM+1];
    85       //      strncpy(ColName_[compt], fn->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    86       strncpy(ColName_[compt], inFits_->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM);
    87       ColName_[compt++][ LONNOM] =  '\0';
     79      ColN[compt] =  inFits_->ColNameFromFits(IfitsCol[k]);
    8880    }
    8981  for (k=0; k<SfitsCol.size(); k++)
    9082    {
    91       ColName_[compt] = new char[LONNOM+1];
    92       //      strncpy(ColName_[compt], fn->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    93       strncpy(ColName_[compt], inFits_->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM);
    94       ColName_[compt++][LONNOM] =  '\0';
     83      ColN[compt] = inFits_->ColNameFromFits(SfitsCol[k]);
    9584    }
    9685
    97   if (DfitsCol.size()>0)
    98     {
    99       dcount_ = DfitsCol.size();
    100       ddata_ = new double[dcount_];
    101     }
    102   if (FfitsCol.size()>0)
    103     {
    104       fcount_ = FfitsCol.size();
    105       fdata_ = new float[fcount_];
    106     }
    107   if (IfitsCol.size()>0)
    108     {
    109       icount_ = IfitsCol.size();
    110       idata_ = new int[icount_];
    111     }
    112   if (SfitsCol.size()>0)
    113     {
    114       ccount_ = SfitsCol.size();
    115       cdata_ = new char*[ccount_];
    116       taille_des_chaines_ = 0;
    117       //      for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, fn->ColStringLengthFromFits(SfitsCol[k]) );
    118       for (k=0; k< ccount_; k++)  taille_des_chaines_ = max( taille_des_chaines_, inFits_->ColStringLengthFromFits(SfitsCol[k]) );
    119       for (k=0; k<ccount_; k++) cdata_[k]=new char[taille_des_chaines_+1];
    120     }
     86  ligne_.setFormat(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(), ColN);
    12187}
    12288
     
    12591{
    12692  if (inFits_ != NULL) delete inFits_;
    127   if (ddata_ != NULL) delete [] ddata_;
    128   if (fdata_ != NULL) delete [] fdata_;
    129   if (idata_ != NULL) delete [] idata_;
    130   if (cdata_ != NULL)
    131     {
    132       if (ccount_ != 0)
    133         {
    134           for (int k=0; k< ccount_; k++)
    135             {
    136               delete [] cdata_[k];
    137               delete [] ColName_[k];
    138             }
    139           delete [] cdata_;
    140           delete [] ColName_;
    141         }
    142       else
    143         {
    144           cout << "FITS_BntblLineReader, destructeur: bizarre, cdata non vide, avec ccount=0 ?" << endl;;       }
    145     }
    14693}
    14794
     95BnTblLine& FITS_BntblLineReader::ReadNextLine()
     96{
     97  inFits_->GetBinTabLine(nextLineToBeRead_++, ligne_);
     98  return ligne_;
     99}
    148100
    149 XNTuple FITS_BntblLineReader::ReadNextLine()
    150 {
    151   inFits_->GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );
    152   XNTuple xnt(dcount_, fcount_, icount_,ccount_, ColName_);
    153   xnt.Fill(ddata_, fdata_, idata_, cdata_);   
    154   return xnt;
    155 }
    156101
    157102void  FITS_BntblLineReader::ReadFromFits(FitsInFile&)
  • trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.h

    r1136 r1193  
    55#define FITSBntblLineReader_SEEN
    66#include "fitsfile.h"
    7 #include "xntuple.h"
     7//#include "xntuple.h"
    88
    99namespace SOPHYA {
     
    2121~FITS_BntblLineReader();
    2222
    23 XNTuple ReadNextLine();
     23//XNTuple ReadNextLineX();
     24BnTblLine& ReadNextLine();
    2425 inline long GetNextLineIndex() const {return nextLineToBeRead_;}
    2526 inline  void SetStartingLineIndex(long n)  { nextLineToBeRead_ = n;}
     
    4344     inFits_ = NULL;
    4445     nextLineToBeRead_= 0;
    45      dcount_ = 0;
    46      fcount_ = 0;
    47      icount_ = 0;
    48      ccount_ = 0;
    49      taille_des_chaines_ = 0;
    50      ddata_ = NULL;
    51      fdata_ = NULL;
    52      idata_ = NULL;
    53      cdata_ = NULL;
    54      ColName_ = NULL;
    5546   }
    5647  // attributs de classe
     
    5849 FitsInFile* inFits_;
    5950  long nextLineToBeRead_;
    60   int dcount_;
    61   int fcount_;
    62   int icount_;
    63   int ccount_;
    64   int  taille_des_chaines_;
    65   double* ddata_;
    66   float*  fdata_;
    67   int*    idata_;
    68   char**  cdata_;
    69   char ** ColName_;
     51  BnTblLine ligne_;
    7052};
     53
     54
    7155//////////////////////////////////////////////////////////////////
    7256
  • trunk/SophyaExt/FitsIOServer/fitsfile.cc

    r1183 r1193  
    2121
    2222
    23 void FitsIOHandler::Write(char flnm[], string WriteMode)
    24 
    25 {
    26 
    27   FitsOutFile of(flnm,  WriteMode);
     23void FitsIOHandler::Write(char flnm[])
     24
     25{
     26  FitsOutFile of(flnm, unknown);
    2827  Write(of);
    2928}
     
    366365  return  taille_des_chaines_[index];
    367366}
    368 void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
     367void  FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)
    369368{
    370369  int status= 0;
     
    396395        case 'S' :
    397396          fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status);
     397          break;
     398        }
     399      if (status)
     400        {
     401          ResetStatus(status);
     402          break;
     403        }
     404    }
     405}
     406
     407void   FitsInFile::GetBinTabLine(long NoLine,  BnTblLine& ligne)
     408{
     409  int status= 0;
     410  int    anull;
     411  double dnull= 0.;
     412  float fnull= 0.;
     413  int inull= 0;
     414  char* cnull= "";
     415  int dcount = 0.;
     416  int fcount = 0.;
     417  int icount = 0;
     418  int ccount =0;
     419  int ncol;
     420  long nels=1;
     421  for (ncol=0; ncol<nbcols_; ncol++)
     422    {
     423      switch (types_[ncol])
     424        {
     425        case 'D' :
     426          fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ligne.ddata_[dcount++],&anull,&status);
     427            break;
     428        case 'E' :
     429          fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&ligne.fdata_[fcount++],&anull,&status);
     430          break;
     431        case 'I' :
     432          fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&ligne.idata_[icount++],
     433                        &anull,&status);
     434          break;
     435        case 'S' :
     436          char* chaine = new char[taille_des_chaines_[ccount]];
     437          fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&chaine,&anull,&status);
     438          ligne.cdata_[ccount++] = string(chaine);
    398439          break;
    399440        }
     
    827868FitsOutFile::FitsOutFile()
    828869{
    829   InitNull();
    830 }
    831 
    832 FitsOutFile::FitsOutFile(char flnm[], string WriteMode)
     870  InitNull(); 
     871}
     872
     873FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm)
    833874{
    834875
     
    841882  if( status )
    842883    {
     884
     885      switch (wrm)
     886        {
    843887      // si on veut ecrire a la fin de ce fichier
    844       if (WriteMode == string("append"))
    845         {
     888        case append :
    846889          status = 0;
    847890          fits_open_file(&fptr_,flnm,READWRITE,&status);
     
    856899          fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    857900          if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
    858         }
    859       else
    860         if (WriteMode == string("clear"))
     901          break;
     902     
     903        case clear :
    861904          {
    862905            status = 0;
     
    867910            strcat(newname, flnm);
    868911            fits_create_file(&fptr_,newname,&status);
     912            delete [] newname;
    869913            if (status)
    870914              {
     
    872916                printerror(status, "unable to open file, supposed to exist");
    873917              }
    874             else  cout << " file " << flnm << " will be overwrited " << endl;
    875              
     918            else  cout << "  WARNING : file " << flnm << " is overwritten " << endl;
     919            break;
    876920          }
    877         else
    878           if  (WriteMode == string("unknown")) printerror(status, " file seems already to exist");
    879 
    880           else  printerror(status, "open file failed");
     921        case unknown :
     922          printerror(status, " file seems already to exist");
     923          break;
    881924     
     925        }
    882926    }
    883927}
     
    954998
    955999
    956 void FitsOutFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines)
     1000void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
    9571001{
    9581002  int status = 0;
    9591003  long nrows;
    960   if (strlen(fieldType) != tfields)
    961     {
    962       cout << " nombre de champs :" << tfields << "nombre de types: " << strlen(fieldType) << endl;
     1004  if (fieldType.length() != tfields)
     1005    {
     1006      cout << " nombre de champs :" << tfields << "nombre de types: " << fieldType.length() << endl;
    9631007      throw ParmError("FitsFile:: fields and types don't match");
    9641008
     
    10021046          strcat(format,largeur);
    10031047        }
    1004       ttype[k]= new char[FLEN_VALUE];
    1005       strcpy(ttype[k],Noms[k]);
     1048      ttype[k] =  const_cast<char*>(Noms[k].c_str());
    10061049      tform[k]= new char[FLEN_VALUE];
    10071050      strcpy(tform[k],format);
    10081051    }
    1009   // value of the EXTNAME keyword
    1010   char extn[FLEN_VALUE];
    1011   strncpy(extn,extname,FLEN_VALUE);
     1052  char* extn = const_cast<char*>(extname.c_str());
    10121053
    10131054  // create a new empty binary table onto the FITS file
     
    10231064  for(ii = 0; ii < tfields; ii++)
    10241065    {
    1025       delete [] ttype[ii];
    10261066      delete [] tform[ii];
    10271067    }
     
    10311071  // write supplementary keywords
    10321072  addKeywordsOfDVList(dvl);
    1033 
    10341073}
    10351074
     
    11341173  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    11351174}
     1175
     1176void FitsOutFile::putBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const
     1177{
     1178  int status= 0;
     1179  int    anull;
     1180  int dcount = 0.;
     1181  int fcount = 0.;
     1182  int icount = 0;
     1183  int ccount =0;
     1184  int ncol;
     1185  long nels=1;
     1186  int nbcols;
     1187  fits_get_num_cols(fptr_, &nbcols,&status);
     1188  for (ncol=0; ncol<nbcols; ncol++)
     1189    {
     1190      int code;
     1191      long repeat, width;
     1192      fits_get_coltype(fptr_, ncol+1, &code, &repeat,&width, &status);
     1193      switch (code)
     1194        {
     1195        case TDOUBLE :
     1196          fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ddata[dcount++] ,&status);
     1197            break;
     1198        case TFLOAT :
     1199          fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &fdata[fcount++] ,&status);
     1200          break;
     1201        case TINT :
     1202          fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &idata[icount++] ,&status);
     1203          break;
     1204        case TLONG :
     1205          fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &idata[icount++] ,&status);
     1206          break;
     1207        case TSHORT :
     1208          fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &idata[icount++] ,&status);
     1209          break;
     1210        case TSTRING :
     1211          fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, &cdata[ccount++] ,&status);
     1212          break;
     1213        }
     1214      if (status)
     1215        {
     1216          cout << " WARNING : unknown type (putBinTabLine) : on fits file= " << code << " (FITS code) " << endl;
     1217          status = 0;
     1218          break;
     1219        }
     1220    }
     1221}
     1222
    11361223
    11371224void  FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1183 r1193  
    1212namespace SOPHYA {
    1313
     14struct BnTblLine
     15 {
     16BnTblLine() {}
     17void setFormat(int dc, int fc, int ic, int cc, vector<string> names)
     18   {
     19    int nbcols = dc + fc + ic + cc;
     20    ColName_ = vector<string>(nbcols);
     21     for (int k=0; k < nbcols; k++) ColName_ = names;
     22    if (dc >0) ddata_ = vector<double>(dc);
     23    if (fc >0) fdata_ = vector<float>(fc);
     24    if (ic >0) idata_ = vector<int>(fc);
     25    if (cc >0) cdata_ = vector<string>(fc);
     26   }
     27   void Print()
     28   {
     29     int k;
     30     int compt = 0;
     31     cout << " ********* ligne ************* " << endl;
     32     cout << " *** noms de variables  " << endl;
     33     for (k=0; k < compt + ColName_.size(); k++) cout << ColName_[k] << " ";
     34     cout << endl;
     35     cout << " *** variables doubles  " << endl;
     36     for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " ";
     37     cout << endl;
     38     cout << " *** variables float  " << endl;
     39     for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " ";
     40     cout << endl;
     41     cout << " *** variables int  " << endl;
     42     for (k=0; k < idata_.size(); k++) cout << idata_[k] << " ";
     43     cout << endl;
     44     cout << " *** variables string  " << endl;
     45     for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " ";
     46     cout << endl;
     47     cout << " ***************************** " << endl;
     48   }
     49  vector<double> ddata_;
     50  vector<float>  fdata_;
     51  vector<int>    idata_;
     52  vector<string>  cdata_;
     53  vector<string> ColName_;
     54
     55 };
     56
    1457 class FitsFile;
    1558 class FitsInFile;
    1659 class FitsOutFile;
    17 
     60 enum WriteMode {append, clear, unknown};
    1861
    1962
     
    88131calls the method 'WriteToFits' from the inherited  object
    89132
    90 \param <WriteMode>  string , WriteMode = "clear" -> if alreadyy exists, the file will be overwrited (else created) ; WriteMode = "append" -> further objects will be appended to the file if it exists (else : file created). Otherwise, file created if does not exist, else : exception. (the last situation is the default)
    91 
    92 
    93133*/
    94   void   Write(char flnm[], string WriteMode= string("unknown")) ;
     134  void   Write(char flnm[]) ;
    95135
    96136  /*!
     
    106146  friend class FitsInFile;
    107147  friend class FitsOutFile;
    108 
     148  private :
    109149  };
    110150
     
    262302  void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
    263303** cdata) ;
     304  /*!
     305get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     306  */
     307  void GetBinTabLine(long NoLine, BnTblLine& ligne) ;
    264308
    265309  /*!
     
    358402
    359403 public:
     404
     405
    360406   FitsOutFile();
    361    FitsOutFile(char flnm[], string WriteMode= string("unknown"));
     407   /*!
     408\param <WriteMode>  enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default)
     409
     410   */
     411   FitsOutFile(char flnm[], WriteMode wrm = unknown );
    362412   ~FitsOutFile() { ;};
    363413   inline void InitNull() {imageOnPrimary_=false;}
     
    414464\param <taille_des_chaines> vector containing the number of characters of  data  for each char* typed column, with order of appearance in 'fieldType'
    415465   */
    416   void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname,  vector<int> taille_des_chaines) ;
     466   void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname,  vector<int> taille_des_chaines) ;
    417467
    418468  /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE  extension.
     
    430480  /*! same as previous method with char* data */
    431481  void putColToFits(int nocol, int nentries, char** donnees) const;
     482
     483  void putBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const;
     484
    432485
    433486/////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.