Changeset 1193 in Sophya for trunk/SophyaExt
- Timestamp:
- Sep 19, 2000, 5:08:16 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.cc
r1162 r1193 1 1 #include "pexceptions.h" 2 2 #include "fitsbntbllinereader.h" 3 #include "utils.h" 3 4 /////////////////////////////////////////////////////////// 4 5 // … … 64 65 } 65 66 } 66 ColName_ = new char*[nbcols];67 vector<string> ColN(nbcols); 67 68 int compt=0; 68 69 for (k=0; k<DfitsCol.size(); k++) 69 70 { 70 ColName_[compt] = new char[LONNOM+1]; 71 // strncpy(ColName_[compt], fn->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM); 72 strncpy(ColName_[compt], inFits_->ColNameFromFits(DfitsCol[k]).c_str(), LONNOM); 73 ColName_[compt++][ LONNOM] = '\0'; 71 ColN[compt] = inFits_->ColNameFromFits(DfitsCol[k]); 74 72 } 75 73 for (k=0; k<FfitsCol.size(); k++) 76 74 { 77 ColName_[compt] = new char[LONNOM+1]; 78 // strncpy(ColName_[compt], fn->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM); 79 strncpy(ColName_[compt], inFits_->ColNameFromFits(FfitsCol[k]).c_str(), LONNOM); 80 ColName_[compt++][ LONNOM] = '\0'; 75 ColN[compt] = inFits_->ColNameFromFits(FfitsCol[k]); 81 76 } 82 77 for (k=0; k<IfitsCol.size(); k++) 83 78 { 84 ColName_[compt] = new char[LONNOM+1]; 85 // strncpy(ColName_[compt], fn->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM); 86 strncpy(ColName_[compt], inFits_->ColNameFromFits(IfitsCol[k]).c_str(), LONNOM); 87 ColName_[compt++][ LONNOM] = '\0'; 79 ColN[compt] = inFits_->ColNameFromFits(IfitsCol[k]); 88 80 } 89 81 for (k=0; k<SfitsCol.size(); k++) 90 82 { 91 ColName_[compt] = new char[LONNOM+1]; 92 // strncpy(ColName_[compt], fn->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM); 93 strncpy(ColName_[compt], inFits_->ColNameFromFits(SfitsCol[k]).c_str(), LONNOM); 94 ColName_[compt++][LONNOM] = '\0'; 83 ColN[compt] = inFits_->ColNameFromFits(SfitsCol[k]); 95 84 } 96 85 97 if (DfitsCol.size()>0) 98 { 99 dcount_ = DfitsCol.size(); 100 ddata_ = new double[dcount_]; 101 } 102 if (FfitsCol.size()>0) 103 { 104 fcount_ = FfitsCol.size(); 105 fdata_ = new float[fcount_]; 106 } 107 if (IfitsCol.size()>0) 108 { 109 icount_ = IfitsCol.size(); 110 idata_ = new int[icount_]; 111 } 112 if (SfitsCol.size()>0) 113 { 114 ccount_ = SfitsCol.size(); 115 cdata_ = new char*[ccount_]; 116 taille_des_chaines_ = 0; 117 // for (k=0; k< ccount_; k++) taille_des_chaines_ = max( taille_des_chaines_, fn->ColStringLengthFromFits(SfitsCol[k]) ); 118 for (k=0; k< ccount_; k++) taille_des_chaines_ = max( taille_des_chaines_, inFits_->ColStringLengthFromFits(SfitsCol[k]) ); 119 for (k=0; k<ccount_; k++) cdata_[k]=new char[taille_des_chaines_+1]; 120 } 86 ligne_.setFormat(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(), ColN); 121 87 } 122 88 … … 125 91 { 126 92 if (inFits_ != NULL) delete inFits_; 127 if (ddata_ != NULL) delete [] ddata_;128 if (fdata_ != NULL) delete [] fdata_;129 if (idata_ != NULL) delete [] idata_;130 if (cdata_ != NULL)131 {132 if (ccount_ != 0)133 {134 for (int k=0; k< ccount_; k++)135 {136 delete [] cdata_[k];137 delete [] ColName_[k];138 }139 delete [] cdata_;140 delete [] ColName_;141 }142 else143 {144 cout << "FITS_BntblLineReader, destructeur: bizarre, cdata non vide, avec ccount=0 ?" << endl;; }145 }146 93 } 147 94 95 BnTblLine& FITS_BntblLineReader::ReadNextLine() 96 { 97 inFits_->GetBinTabLine(nextLineToBeRead_++, ligne_); 98 return ligne_; 99 } 148 100 149 XNTuple FITS_BntblLineReader::ReadNextLine()150 {151 inFits_->GetBinTabLine(nextLineToBeRead_++, ddata_, fdata_, idata_, cdata_ );152 XNTuple xnt(dcount_, fcount_, icount_,ccount_, ColName_);153 xnt.Fill(ddata_, fdata_, idata_, cdata_);154 return xnt;155 }156 101 157 102 void FITS_BntblLineReader::ReadFromFits(FitsInFile&) -
trunk/SophyaExt/FitsIOServer/fitsbntbllinereader.h
r1136 r1193 5 5 #define FITSBntblLineReader_SEEN 6 6 #include "fitsfile.h" 7 #include "xntuple.h"7 //#include "xntuple.h" 8 8 9 9 namespace SOPHYA { … … 21 21 ~FITS_BntblLineReader(); 22 22 23 XNTuple ReadNextLine(); 23 //XNTuple ReadNextLineX(); 24 BnTblLine& ReadNextLine(); 24 25 inline long GetNextLineIndex() const {return nextLineToBeRead_;} 25 26 inline void SetStartingLineIndex(long n) { nextLineToBeRead_ = n;} … … 43 44 inFits_ = NULL; 44 45 nextLineToBeRead_= 0; 45 dcount_ = 0;46 fcount_ = 0;47 icount_ = 0;48 ccount_ = 0;49 taille_des_chaines_ = 0;50 ddata_ = NULL;51 fdata_ = NULL;52 idata_ = NULL;53 cdata_ = NULL;54 ColName_ = NULL;55 46 } 56 47 // attributs de classe … … 58 49 FitsInFile* inFits_; 59 50 long nextLineToBeRead_; 60 int dcount_; 61 int fcount_; 62 int icount_; 63 int ccount_; 64 int taille_des_chaines_; 65 double* ddata_; 66 float* fdata_; 67 int* idata_; 68 char** cdata_; 69 char ** ColName_; 51 BnTblLine ligne_; 70 52 }; 53 54 71 55 ////////////////////////////////////////////////////////////////// 72 56 -
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 -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1183 r1193 12 12 namespace SOPHYA { 13 13 14 struct BnTblLine 15 { 16 BnTblLine() {} 17 void setFormat(int dc, int fc, int ic, int cc, vector<string> names) 18 { 19 int nbcols = dc + fc + ic + cc; 20 ColName_ = vector<string>(nbcols); 21 for (int k=0; k < nbcols; k++) ColName_ = names; 22 if (dc >0) ddata_ = vector<double>(dc); 23 if (fc >0) fdata_ = vector<float>(fc); 24 if (ic >0) idata_ = vector<int>(fc); 25 if (cc >0) cdata_ = vector<string>(fc); 26 } 27 void Print() 28 { 29 int k; 30 int compt = 0; 31 cout << " ********* ligne ************* " << endl; 32 cout << " *** noms de variables " << endl; 33 for (k=0; k < compt + ColName_.size(); k++) cout << ColName_[k] << " "; 34 cout << endl; 35 cout << " *** variables doubles " << endl; 36 for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " "; 37 cout << endl; 38 cout << " *** variables float " << endl; 39 for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " "; 40 cout << endl; 41 cout << " *** variables int " << endl; 42 for (k=0; k < idata_.size(); k++) cout << idata_[k] << " "; 43 cout << endl; 44 cout << " *** variables string " << endl; 45 for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " "; 46 cout << endl; 47 cout << " ***************************** " << endl; 48 } 49 vector<double> ddata_; 50 vector<float> fdata_; 51 vector<int> idata_; 52 vector<string> cdata_; 53 vector<string> ColName_; 54 55 }; 56 14 57 class FitsFile; 15 58 class FitsInFile; 16 59 class FitsOutFile; 17 60 enum WriteMode {append, clear, unknown}; 18 61 19 62 … … 88 131 calls the method 'WriteToFits' from the inherited object 89 132 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 93 133 */ 94 void Write(char flnm[] , string WriteMode= string("unknown")) ;134 void Write(char flnm[]) ; 95 135 96 136 /*! … … 106 146 friend class FitsInFile; 107 147 friend class FitsOutFile; 108 148 private : 109 149 }; 110 150 … … 262 302 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char 263 303 ** cdata) ; 304 /*! 305 get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 306 */ 307 void GetBinTabLine(long NoLine, BnTblLine& ligne) ; 264 308 265 309 /*! … … 358 402 359 403 public: 404 405 360 406 FitsOutFile(); 361 FitsOutFile(char flnm[], string WriteMode= string("unknown")); 407 /*! 408 \param <WriteMode> enum , WriteMode = clear -> if alreadyy exists, the file will be overwritten (else created) ; WriteMode = append -> further objects will be appended to the file if it exists (else : file created). WriteMode = unknown -> file created if does not exist, else : exception. (the last situation is the default) 409 410 */ 411 FitsOutFile(char flnm[], WriteMode wrm = unknown ); 362 412 ~FitsOutFile() { ;}; 363 413 inline void InitNull() {imageOnPrimary_=false;} … … 414 464 \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType' 415 465 */ 416 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char*extname, vector<int> taille_des_chaines) ;466 void makeHeaderBntblOnFits ( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines) ; 417 467 418 468 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension. … … 430 480 /*! same as previous method with char* data */ 431 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; 484 432 485 433 486 /////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.