Changeset 1183 in Sophya
- Timestamp:
- Sep 11, 2000, 4:52:35 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1175 r1183 21 21 22 22 23 void FitsIOHandler::Write(char flnm[], bool OldFile)24 25 { 26 27 FitsOutFile of(flnm, OldFile);23 void FitsIOHandler::Write(char flnm[], string WriteMode) 24 25 { 26 27 FitsOutFile of(flnm, WriteMode); 28 28 Write(of); 29 29 } … … 783 783 784 784 strncpy(keyname,card,LEN_KEYWORD-1); 785 786 785 if(strncmp(keyname,comkey,LEN_KEYWORD-1) != 0 && strlen(keyname) != 0 787 786 && strlen(strval) != 0) … … 831 830 } 832 831 833 FitsOutFile::FitsOutFile(char flnm[], bool OldFile)832 FitsOutFile::FitsOutFile(char flnm[], string WriteMode) 834 833 { 835 834 … … 838 837 839 838 // 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 } 856 883 } 857 884 … … 1151 1178 char keyname[10]; 1152 1179 strncpy(keyname,(*it).first.substr(0,64).c_str(),10); 1180 string key(keyname); 1153 1181 char comment[FLEN_COMMENT]; 1154 1182 char strval[FLEN_VALUE]= ""; … … 1157 1185 if (status != 0 || strncmp(keyname,comkey,LEN_KEYWORD-1) == 0 ) 1158 1186 { 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'; 1159 1191 status = 0; 1160 1192 switch (keytype) … … 1162 1194 case 'I' : 1163 1195 { 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); 1167 1198 break; 1168 1199 } 1169 1200 case 'D' : 1170 1201 { 1171 double dval=(*it).second.elval.dv; 1172 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT ); 1202 double dval= (double)dvl.GetD(key); 1173 1203 fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status); 1174 1204 break; … … 1176 1206 case 'S' : 1177 1207 { 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); 1182 1215 break; 1183 1216 } -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1175 r1183 68 68 this method is called from inherited objects : 69 69 70 for writing a new object in a new fits-extension, at the end of 70 for writing a new object in a new fits-extension : 71 72 ??? 73 74 at the end of 71 75 72 76 the existing file (flnm), if OldFile=true. … … 84 88 calls the method 'WriteToFits' from the inherited object 85 89 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 86 93 */ 87 void Write(char flnm[], bool OldFile=false) ;94 void Write(char flnm[], string WriteMode= string("unknown")) ; 88 95 89 96 /*! … … 352 359 public: 353 360 FitsOutFile(); 354 FitsOutFile(char flnm[], bool OldFile=false);361 FitsOutFile(char flnm[], string WriteMode= string("unknown")); 355 362 ~FitsOutFile() { ;}; 356 363 inline void InitNull() {imageOnPrimary_=false;}
Note:
See TracChangeset
for help on using the changeset viewer.