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

amelioration lecture ligne a ligne

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.