Changeset 1209 in Sophya


Ignore:
Timestamp:
Sep 29, 2000, 6:19:40 PM (25 years ago)
Author:
ansari
Message:

ecriture ligne a ligne

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 added
2 edited

Legend:

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

    r1193 r1209  
    8080}
    8181
    82 string FitsFile::getErrStatus(int status)
     82string FitsFile::GetErrStatus(int status)
    8383{
    8484  char text[31];
     
    131131}
    132132
    133 void FitsInFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
     133void FitsInFile::GetBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )
    134134{
    135135  int status = 0;
    136136  fitsfile* fileptr;
    137137  fits_open_file(&fileptr,flnm,READONLY,&status);
    138   if( status ) printerror( status, "getBlockType: erreur ouverture fichier" );
     138  if( status ) printerror( status, "GetBlockType: erreur ouverture fichier" );
    139139  // move to the specified HDU number
    140140  int hdutype = 0;
    141141  fits_movabs_hdu(fileptr,hdunum,&hdutype,&status);
    142   if( status ) printerror( status,"getBlockType: erreur movabs");
     142  if( status ) printerror( status,"GetBlockType: erreur movabs");
    143143  if(hdutype == IMAGE_HDU)
    144144    {
     
    154154            {
    155155              cout << " bitpix= " << bitpix << endl;
    156               throw PException(" FitsFile::getBlockType : unsupprted FITS data type");
     156              throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
    157157            }
    158158     
     
    186186                    {
    187187                      cout << " types[0]= " << types[0] << endl;
    188                       throw PException(" FitsFile::getBlockType : unsupprted FITS data type");
     188                      throw PException(" FitsFile::GetBlockType : unsupprted FITS data type");
    189189            }
    190190          }
     
    193193      {
    194194        cout << " hdutype= " << hdutype << endl;
    195         throw IOExc("FitsFile::getBlockType: this HDU type is unknown");
     195        throw IOExc("FitsFile::GetBlockType: this HDU type is unknown");
    196196      }
    197197 
     
    968968
    969969}
    970 void FitsOutFile::putImageToFits(int nbData, double* map) const
     970void FitsOutFile::PutImageToFits(int nbData, double* map) const
    971971{
    972972  int status = 0;
    973973  long npix= nbData;
    974974  fits_write_img(fptr_,TDOUBLE,1,npix,map,&status);
    975   if( status ) printerror( status, "erreur ecriture putImageToFits" );
     975  if( status ) printerror( status, "erreur ecriture PutImageToFits" );
    976976  //  writeSignatureOnFits();
    977977}
    978978
    979 void FitsOutFile::putImageToFits(int nbData, float* map) const
     979void FitsOutFile::PutImageToFits(int nbData, float* map) const
    980980{
    981981  int status = 0;
    982982  long npix= nbData;
    983983  fits_write_img(fptr_,TFLOAT,1,npix, map,&status);
    984   if( status ) printerror( status, "erreur ecriture putImageToFits" );
     984  if( status ) printerror( status, "erreur ecriture PutImageToFits" );
    985985  //  writeSignatureOnFits();
    986986
    987987}
    988 void FitsOutFile::putImageToFits( int nbData, int* map) const
     988void FitsOutFile::PutImageToFits( int nbData, int* map) const
    989989{
    990990  int status = 0;
     
    992992  long npix= nbData;
    993993  fits_write_img(fptr_,TINT,1,npix,map,&status);
    994   if( status ) printerror( status, "erreur ecriture putImageToFits" );
     994  if( status ) printerror( status, "erreur ecriture PutImageToFits" );
    995995  //  writeSignatureOnFits();
    996996}
     
    10001000void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines)
    10011001{
     1002  int k;
    10021003  int status = 0;
    10031004  long nrows;
     1005  // verifications de coherence
     1006
    10041007  if (fieldType.length() != tfields)
    10051008    {
     
    10071010      throw ParmError("FitsFile:: fields and types don't match");
    10081011
     1012    }
     1013  if (tfields >  Noms.size())
     1014    {
     1015      cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of column names not equal to total number of columns" << endl;
     1016      for (k=0; k<(tfields-Noms.size()); k++) Noms.push_back( string(" "));
     1017    }
     1018 
     1019  // nombre de variables "chaines de caracteres"
     1020  int nbString = 0;
     1021  for (k=0; k<tfields;k++) if (fieldType[k] == 'A') nbString++;
     1022  // coherence de la longueur du vecteur des tailles
     1023  if (nbString >  taille_des_chaines.size())
     1024    {
     1025      cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of string lengths  not equal to total number of columns" << endl;
     1026      int strSz=0;
     1027      for (k=0; k<taille_des_chaines.size(); k++) if ( taille_des_chaines[k] > strSz) strSz = taille_des_chaines[k];
     1028      for (k=0; k<(nbString-taille_des_chaines.size()); k++) taille_des_chaines.push_back(strSz);
    10091029    }
    10101030  char ** ttype= new char*[tfields];
     
    10121032  char largeur[FLEN_VALUE];
    10131033  int noColString=0;
    1014   int k;
    10151034  for (k=0; k<tfields;k++)
    10161035    {
     
    10731092}
    10741093
    1075 void FitsOutFile::putColToFits(int nocol, int nentries, double* donnees) const
     1094void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const
    10761095{
    10771096  int status = 0;
    10781097  int hdutype;
    10791098  fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    1080   if( status ) printerror(status,"putColToFits: le movabs a foire");
     1099  if( status ) printerror(status,"PutColToFits: le movabs a foire");
    10811100  fits_get_hdu_type(fptr_, &hdutype, &status);
    10821101    if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
    10831102        {
    10841103            cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
    1085      throw IOExc("FitsFile::putColToFits, this HDU is not an ASCII table nor a binary table");
     1104     throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
    10861105          }
    10871106  int code;
     
    10901109  if( code != TDOUBLE)
    10911110    {
    1092       cout << " WARNING : types don't match (putColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;
     1111      cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;
    10931112    }
    10941113  fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status);
    10951114  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    10961115}
    1097 void FitsOutFile::putColToFits(int nocol, int nentries, float* donnees) const
     1116void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const
    10981117{
    10991118  int status = 0;
    11001119  int hdutype;
    11011120  fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    1102   if( status ) printerror(status,"putColToFits: le movabs a foire");
     1121  if( status ) printerror(status,"PutColToFits: le movabs a foire");
    11031122  fits_get_hdu_type(fptr_, &hdutype, &status);
    11041123  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
    11051124    {
    11061125      cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
    1107       throw IOExc("FitsFile::putColToFits, this HDU is not an ASCII table nor a binary table");
     1126      throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
    11081127    }
    11091128  if(hdutype == ASCII_TBL && nocol>0)
    11101129    {
    1111       throw IOExc("FitsFile::putColToFits, this HDU is an ASCII table, nocol>0  forbidden");
     1130      throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0  forbidden");
    11121131    }
    11131132  int code;
     
    11161135  if( code != TFLOAT)
    11171136    {
    1118       cout << " WARNING : types don't match (putColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;
     1137      cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;
    11191138    }
    11201139  fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status);
    11211140  if( status )  printerror( status,"erreur ecriture du fichier fits" );
    11221141}
    1123 void FitsOutFile::putColToFits(int nocol, int nentries, int* donnees) const
     1142void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const
    11241143{
    11251144  int status = 0;
    11261145  int hdutype;
    11271146  fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    1128   if( status ) printerror(status,"putColToFits: le movabs a foire");
     1147  if( status ) printerror(status,"PutColToFits: le movabs a foire");
    11291148  fits_get_hdu_type(fptr_, &hdutype, &status);
    11301149  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
    11311150    {
    11321151      cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
    1133       throw IOExc("FitsFile::putColToFits, this HDU is not an ASCII table nor a binary table");
     1152      throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
    11341153    }
    11351154  if(hdutype == ASCII_TBL && nocol>0)
    11361155    {
    1137       throw IOExc("FitsFile::putColToFits, this HDU is an ASCII table, nocol>0  forbidden");
     1156      throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0  forbidden");
    11381157    }
    11391158  int code;
     
    11421161  if( code != TLONG &&  code != TINT &&  code != TSHORT )
    11431162    {
    1144       cout << " WARNING : types don't match (putColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;
     1163      cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;
    11451164    }
    11461165  fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status);
    11471166  if( status )  printerror( status," ecriture du fichier fits" );
    11481167}
    1149 void FitsOutFile::putColToFits(int nocol, int nentries, char** donnees) const
     1168void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const
    11501169{
    11511170  int status = 0;
    11521171  int hdutype;
    11531172  fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    1154   if( status ) printerror(status,"putColToFits: le movabs a foire");
     1173  if( status ) printerror(status,"PutColToFits: le movabs a foire");
    11551174  fits_get_hdu_type(fptr_, &hdutype, &status);
    11561175  if(hdutype != ASCII_TBL && hdutype != BINARY_TBL)
    11571176    {
    11581177      cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl;
    1159       throw IOExc("FitsFile::putColToFits, this HDU is not an ASCII table nor a binary table");
     1178      throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table");
    11601179    }
    11611180  if(hdutype == ASCII_TBL && nocol>0)
    11621181    {
    1163       throw IOExc("FitsFile::putColToFits, this HDU is an ASCII table, nocol>0  forbidden");
     1182      throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0  forbidden");
    11641183    }
    11651184  int code;
     
    11681187  if( code != TSTRING)
    11691188    {
    1170       cout << " WARNING : types don't match (putColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;
     1189      cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;
    11711190    }
    11721191  fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status);
     
    11741193}
    11751194
    1176 void FitsOutFile::putBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const
    1177 {
     1195void FitsOutFile::PutBinTabLine(long NoLine,  BnTblLine& ligne) const
     1196{
     1197  // on ne fait pas de verification de type, ni de dimension ici, pour
     1198  // des raisons de performances
     1199  int k;
    11781200  int status= 0;
    11791201  int    anull;
    1180   int dcount = 0.;
    1181   int fcount = 0.;
    1182   int icount = 0;
    1183   int ccount =0;
    1184   int ncol;
     1202  int ncol=0;
    11851203  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         }
     1204  //  int nbcols;
     1205  //  fits_get_num_cols(fptr_, &nbcols,&status);
     1206  for (k=0; k<ligne.ddata_.size(); k++, ncol++)
     1207    {
     1208      fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ligne.ddata_[k] ,&status);
     1209      if( status ) printerror( status, "PutBinTabLine : erreur ecriture double"  );
     1210    }
     1211  for (k=0; k<ligne.fdata_.size(); k++, ncol++)
     1212    {
     1213      fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &ligne.fdata_[k] ,&status);
     1214      if( status ) printerror( status, "PutBinTabLine : erreur ecriture float"  );
     1215    }
     1216  for (k=0; k<ligne.idata_.size(); k++, ncol++)
     1217    {
     1218      fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &ligne.idata_[k] ,&status);
     1219      if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier"  );
     1220    }
     1221 
     1222  for (k=0; k<ligne.cdata_.size(); k++, ncol++)
     1223    {
     1224      fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, strdup(ligne.cdata_[k].c_str()) ,&status);
     1225      if( status ) printerror( status, "PutBinTabLine : erreur ecriture caracteres"  );
    12201226    }
    12211227}
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1193 r1209  
    1818   {
    1919    int nbcols = dc + fc + ic + cc;
     20    int maxName = names.size();
     21    if (nbcols != maxName)
     22      {
     23        cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl;
     24        maxName = nbcols < maxName ? nbcols : maxName;
     25      }
    2026    ColName_ = vector<string>(nbcols);
    21      for (int k=0; k < nbcols; k++) ColName_ = names;
     27     for (int k=0; k < maxName; k++) ColName_[k] = names[k];
    2228    if (dc >0) ddata_ = vector<double>(dc);
    2329    if (fc >0) fdata_ = vector<float>(fc);
     
    2531    if (cc >0) cdata_ = vector<string>(fc);
    2632   }
    27    void Print()
     33
     34bool sameFormat(const BnTblLine& btl) const
     35   {
     36     if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size()) return true;
     37     else return false;
     38   }
     39
     40void Print()
    2841   {
    2942     int k;
    30      int compt = 0;
    3143     cout << " ********* ligne ************* " << endl;
    3244     cout << " *** noms de variables  " << endl;
    33      for (k=0; k < compt + ColName_.size(); k++) cout << ColName_[k] << " ";
     45     for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " ";
    3446     cout << endl;
    3547     cout << " *** variables doubles  " << endl;
     
    162174  virtual ~FitsFile();
    163175
    164   static string getErrStatus(int status);
     176  static string GetErrStatus(int status);
    165177
    166178
     
    210222
    211223  static int NbBlocks(char flnm[]);
    212   static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
     224  static void GetBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl  );
    213225
    214226
     
    298310
    299311  /*!
    300 get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     312Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    301313  */
    302314  void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char
    303315** cdata) ;
    304316  /*!
    305 get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     317Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    306318  */
    307319  void GetBinTabLine(long NoLine, BnTblLine& ligne) ;
    308320
    309321  /*!
    310 get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
     322Get the NoLine-th 'line'  from the current BINTABLE extension on FITS file,
    311323  */
    312324  void GetBinTabLine(int NoLine, float* fdata) ;
     
    438450
    439451   */
    440   void putImageToFits( int nbData, double* map) const;
     452  void PutImageToFits( int nbData, double* map) const;
    441453
    442454  /*! same as previous method with float data */
    443   void putImageToFits(int nbData, float* map ) const;
     455  void PutImageToFits(int nbData, float* map ) const;
    444456
    445457  /*! same as previous method with int data */
    446   void putImageToFits(int nbData, int* map) const;
     458  void PutImageToFits(int nbData, int* map) const;
    447459
    448460
     
    470482
    471483   */
    472   void putColToFits(int nocol, int nentries, double* donnees) const;
     484  void PutColToFits(int nocol, int nentries, double* donnees) const;
    473485
    474486  /*! same as previous method with float data */
    475   void putColToFits(int nocol, int nentries, float* donnees) const;
     487  void PutColToFits(int nocol, int nentries, float* donnees) const;
    476488
    477489  /*! same as previous method with int data */
    478   void putColToFits(int nocol, int nentries, int* donnees) const;
     490  void PutColToFits(int nocol, int nentries, int* donnees) const;
    479491
    480492  /*! same as previous method with char* data */
    481   void putColToFits(int nocol, int nentries, char** donnees) const;
    482 
    483   void putBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const;
     493  void PutColToFits(int nocol, int nentries, char** donnees) const;
     494
     495  void PutBinTabLine(long NoLine,  BnTblLine& ligne) const;
    484496
    485497
     
    489501
    490502
    491 /* put keywords from a DVList into the primary header of the fits-file */
     503/* Put keywords from a DVList into the primary header of the fits-file */
    492504void  DVListIntoPrimaryHeader(DVList& dvl) const;
    493505
Note: See TracChangeset for help on using the changeset viewer.