Changeset 1183 in Sophya


Ignore:
Timestamp:
Sep 11, 2000, 4:52:35 PM (25 years ago)
Author:
ansari
Message:

revu l'ouverture des fichiers

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 edited

Legend:

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

    r1175 r1183  
    2121
    2222
    23 void FitsIOHandler::Write(char flnm[], bool OldFile)
    24 
    25 {
    26 
    27   FitsOutFile of(flnm, OldFile);
     23void FitsIOHandler::Write(char flnm[], string WriteMode)
     24
     25{
     26
     27  FitsOutFile of(flnm,  WriteMode);
    2828  Write(of);
    2929}
     
    783783
    784784      strncpy(keyname,card,LEN_KEYWORD-1);
    785      
    786785      if(strncmp(keyname,comkey,LEN_KEYWORD-1) != 0 && strlen(keyname) != 0
    787786         && strlen(strval) != 0)
     
    831830}
    832831
    833 FitsOutFile::FitsOutFile(char flnm[], bool OldFile)
     832FitsOutFile::FitsOutFile(char flnm[], string WriteMode)
    834833{
    835834
     
    838837
    839838  // create new FITS file
    840   if (!OldFile)
    841     {
    842       fits_create_file(&fptr_,flnm,&status);
    843       if( status ) printerror(status,"file already exists");
    844     }
    845   else
    846     {
    847       fits_open_file(&fptr_,flnm,READWRITE,&status);
    848       if( status ) printerror(status,"file does not exist");
    849       fits_get_num_hdus(fptr_, &hdunum_, &status);
    850       int hdutype;
    851       fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
    852       if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
    853 
    854     }
    855 
     839
     840  fits_create_file(&fptr_,flnm,&status);
     841  if( status )
     842    {
     843      // si on veut ecrire a la fin de ce fichier
     844      if (WriteMode == string("append"))
     845        {
     846          status = 0;
     847          fits_open_file(&fptr_,flnm,READWRITE,&status);
     848          if( status )
     849            {
     850              cout << " error opening file: " << flnm << endl;
     851              printerror(status, "failure opening a file supposed to exist");
     852            }
     853          else cout << " file " << flnm << " opened, new objects will be appended " << endl;
     854          fits_get_num_hdus(fptr_, &hdunum_, &status);
     855          int hdutype;
     856          fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status);
     857          if( status ) printerror( status,":FitsFile::WriteF : erreur movabs");
     858        }
     859      else
     860        if (WriteMode == string("clear"))
     861          {
     862            status = 0;
     863            char* newname = new char[strlen(flnm)+1];
     864            //
     865            newname[0] = '!';
     866            newname[1] = '\0';
     867            strcat(newname, flnm);
     868            fits_create_file(&fptr_,newname,&status);
     869            if (status)
     870              {
     871                cout << " error opening file: " << flnm << endl;
     872                printerror(status, "unable to open file, supposed to exist");
     873              }
     874            else  cout << " file " << flnm << " will be overwrited " << endl;
     875             
     876          }
     877        else
     878          if  (WriteMode == string("unknown")) printerror(status, " file seems already to exist");
     879
     880          else  printerror(status, "open file failed");
     881     
     882    }
    856883}
    857884
     
    11511178      char keyname[10];
    11521179      strncpy(keyname,(*it).first.substr(0,64).c_str(),10);
     1180      string key(keyname);
    11531181      char comment[FLEN_COMMENT];
    11541182      char strval[FLEN_VALUE]= "";
     
    11571185      if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 )
    11581186        {
     1187          string coco = dvl.GetComment(key);
     1188          coco.copy( comment, FLEN_COMMENT-1);
     1189          int bout = (coco.length() < FLEN_COMMENT) ? coco.length() : FLEN_COMMENT-1;
     1190          comment[bout]= '\0';
    11591191          status = 0;
    11601192          switch (keytype)
     
    11621194            case 'I' :
    11631195              {
    1164                 int ival=(*it).second.elval.iv;
    1165                 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
    1166                 fits_write_key(fptr_,TINT,keyname,&ival,comment,&status);
     1196                int ival = (int)dvl.GetI(key);
     1197                fits_write_key(fptr_,TINT,keyname,&ival, comment,&status);
    11671198                break;
    11681199              }
    11691200            case 'D' :
    11701201              {
    1171                 double dval=(*it).second.elval.dv;
    1172                 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
     1202                double dval= (double)dvl.GetD(key);
    11731203                fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status);
    11741204                break;
     
    11761206            case 'S' :
    11771207              {
    1178                 char strval[128];
    1179                 strncpy(strval,(*it).second.elval.strv->c_str(),127);
    1180                 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT );
    1181                 fits_write_key(fptr_,TSTRING,keyname,&strval,comment,&status);
     1208                char strvaleur[FLEN_VALUE]= "";
     1209                string valChaine = dvl.GetS(key);
     1210                valChaine.copy(strvaleur, FLEN_VALUE-1);
     1211                int fin =  (valChaine.length() < FLEN_VALUE) ? valChaine.length() : FLEN_VALUE-1;
     1212                strvaleur[fin]= '\0';
     1213
     1214                fits_write_key(fptr_,TSTRING,keyname,&strvaleur,comment,&status);
    11821215                break;
    11831216              }
  • trunk/SophyaExt/FitsIOServer/fitsfile.h

    r1175 r1183  
    6868this method is called from inherited objects :
    6969
    70 for writing a new object in a new fits-extension, at the end of
     70for writing a new object in a new fits-extension :
     71
     72???
     73
     74 at the end of
    7175
    7276the existing file (flnm), if OldFile=true.
     
    8488calls the method 'WriteToFits' from the inherited  object
    8589
     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
    8693*/
    87   void   Write(char flnm[], bool OldFile=false) ;
     94  void   Write(char flnm[], string WriteMode= string("unknown")) ;
    8895
    8996  /*!
     
    352359 public:
    353360   FitsOutFile();
    354    FitsOutFile(char flnm[], bool OldFile=false);
     361   FitsOutFile(char flnm[], string WriteMode= string("unknown"));
    355362   ~FitsOutFile() { ;};
    356363   inline void InitNull() {imageOnPrimary_=false;}
Note: See TracChangeset for help on using the changeset viewer.