Changeset 1193 in Sophya for trunk/SophyaExt/FitsIOServer/fitsfile.cc
- Timestamp:
- Sep 19, 2000, 5:08:16 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1183 r1193 21 21 22 22 23 void FitsIOHandler::Write(char flnm[], string WriteMode) 24 25 { 26 27 FitsOutFile of(flnm, WriteMode); 23 void FitsIOHandler::Write(char flnm[]) 24 25 { 26 FitsOutFile of(flnm, unknown); 28 27 Write(of); 29 28 } … … 366 365 return taille_des_chaines_[index]; 367 366 } 368 void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata)367 void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 369 368 { 370 369 int status= 0; … … 396 395 case 'S' : 397 396 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 407 void 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); 398 439 break; 399 440 } … … 827 868 FitsOutFile::FitsOutFile() 828 869 { 829 InitNull(); 830 } 831 832 FitsOutFile::FitsOutFile(char flnm[], string WriteMode)870 InitNull(); 871 } 872 873 FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm) 833 874 { 834 875 … … 841 882 if( status ) 842 883 { 884 885 switch (wrm) 886 { 843 887 // si on veut ecrire a la fin de ce fichier 844 if (WriteMode == string("append")) 845 { 888 case append : 846 889 status = 0; 847 890 fits_open_file(&fptr_,flnm,READWRITE,&status); … … 856 899 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 857 900 if( status ) printerror( status,":FitsFile::WriteF : erreur movabs"); 858 }859 else860 if (WriteMode == string("clear"))901 break; 902 903 case clear : 861 904 { 862 905 status = 0; … … 867 910 strcat(newname, flnm); 868 911 fits_create_file(&fptr_,newname,&status); 912 delete [] newname; 869 913 if (status) 870 914 { … … 872 916 printerror(status, "unable to open file, supposed to exist"); 873 917 } 874 else cout << " file " << flnm << " will be overwrited" << endl;875 918 else cout << " WARNING : file " << flnm << " is overwritten " << endl; 919 break; 876 920 } 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; 881 924 925 } 882 926 } 883 927 } … … 954 998 955 999 956 void FitsOutFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char*extname, vector<int> taille_des_chaines)1000 void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines) 957 1001 { 958 1002 int status = 0; 959 1003 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; 963 1007 throw ParmError("FitsFile:: fields and types don't match"); 964 1008 … … 1002 1046 strcat(format,largeur); 1003 1047 } 1004 ttype[k]= new char[FLEN_VALUE]; 1005 strcpy(ttype[k],Noms[k]); 1048 ttype[k] = const_cast<char*>(Noms[k].c_str()); 1006 1049 tform[k]= new char[FLEN_VALUE]; 1007 1050 strcpy(tform[k],format); 1008 1051 } 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()); 1012 1053 1013 1054 // create a new empty binary table onto the FITS file … … 1023 1064 for(ii = 0; ii < tfields; ii++) 1024 1065 { 1025 delete [] ttype[ii];1026 1066 delete [] tform[ii]; 1027 1067 } … … 1031 1071 // write supplementary keywords 1032 1072 addKeywordsOfDVList(dvl); 1033 1034 1073 } 1035 1074 … … 1134 1173 if( status ) printerror( status,"erreur ecriture du fichier fits" ); 1135 1174 } 1175 1176 void 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 1136 1223 1137 1224 void FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const
Note:
See TracChangeset
for help on using the changeset viewer.