Changeset 1209 in Sophya
- Timestamp:
- Sep 29, 2000, 6:19:40 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1193 r1209 80 80 } 81 81 82 string FitsFile:: getErrStatus(int status)82 string FitsFile::GetErrStatus(int status) 83 83 { 84 84 char text[31]; … … 131 131 } 132 132 133 void FitsInFile:: getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl )133 void FitsInFile::GetBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl ) 134 134 { 135 135 int status = 0; 136 136 fitsfile* fileptr; 137 137 fits_open_file(&fileptr,flnm,READONLY,&status); 138 if( status ) printerror( status, " getBlockType: erreur ouverture fichier" );138 if( status ) printerror( status, "GetBlockType: erreur ouverture fichier" ); 139 139 // move to the specified HDU number 140 140 int hdutype = 0; 141 141 fits_movabs_hdu(fileptr,hdunum,&hdutype,&status); 142 if( status ) printerror( status," getBlockType: erreur movabs");142 if( status ) printerror( status,"GetBlockType: erreur movabs"); 143 143 if(hdutype == IMAGE_HDU) 144 144 { … … 154 154 { 155 155 cout << " bitpix= " << bitpix << endl; 156 throw PException(" FitsFile:: getBlockType : unsupprted FITS data type");156 throw PException(" FitsFile::GetBlockType : unsupprted FITS data type"); 157 157 } 158 158 … … 186 186 { 187 187 cout << " types[0]= " << types[0] << endl; 188 throw PException(" FitsFile:: getBlockType : unsupprted FITS data type");188 throw PException(" FitsFile::GetBlockType : unsupprted FITS data type"); 189 189 } 190 190 } … … 193 193 { 194 194 cout << " hdutype= " << hdutype << endl; 195 throw IOExc("FitsFile:: getBlockType: this HDU type is unknown");195 throw IOExc("FitsFile::GetBlockType: this HDU type is unknown"); 196 196 } 197 197 … … 968 968 969 969 } 970 void FitsOutFile:: putImageToFits(int nbData, double* map) const970 void FitsOutFile::PutImageToFits(int nbData, double* map) const 971 971 { 972 972 int status = 0; 973 973 long npix= nbData; 974 974 fits_write_img(fptr_,TDOUBLE,1,npix,map,&status); 975 if( status ) printerror( status, "erreur ecriture putImageToFits" );975 if( status ) printerror( status, "erreur ecriture PutImageToFits" ); 976 976 // writeSignatureOnFits(); 977 977 } 978 978 979 void FitsOutFile:: putImageToFits(int nbData, float* map) const979 void FitsOutFile::PutImageToFits(int nbData, float* map) const 980 980 { 981 981 int status = 0; 982 982 long npix= nbData; 983 983 fits_write_img(fptr_,TFLOAT,1,npix, map,&status); 984 if( status ) printerror( status, "erreur ecriture putImageToFits" );984 if( status ) printerror( status, "erreur ecriture PutImageToFits" ); 985 985 // writeSignatureOnFits(); 986 986 987 987 } 988 void FitsOutFile:: putImageToFits( int nbData, int* map) const988 void FitsOutFile::PutImageToFits( int nbData, int* map) const 989 989 { 990 990 int status = 0; … … 992 992 long npix= nbData; 993 993 fits_write_img(fptr_,TINT,1,npix,map,&status); 994 if( status ) printerror( status, "erreur ecriture putImageToFits" );994 if( status ) printerror( status, "erreur ecriture PutImageToFits" ); 995 995 // writeSignatureOnFits(); 996 996 } … … 1000 1000 void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines) 1001 1001 { 1002 int k; 1002 1003 int status = 0; 1003 1004 long nrows; 1005 // verifications de coherence 1006 1004 1007 if (fieldType.length() != tfields) 1005 1008 { … … 1007 1010 throw ParmError("FitsFile:: fields and types don't match"); 1008 1011 1012 } 1013 if (tfields > Noms.size()) 1014 { 1015 cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of column names not equal to total number of columns" << endl; 1016 for (k=0; k<(tfields-Noms.size()); k++) Noms.push_back( string(" ")); 1017 } 1018 1019 // nombre de variables "chaines de caracteres" 1020 int nbString = 0; 1021 for (k=0; k<tfields;k++) if (fieldType[k] == 'A') nbString++; 1022 // coherence de la longueur du vecteur des tailles 1023 if (nbString > taille_des_chaines.size()) 1024 { 1025 cout << " WARNING: FitsOutFile::makeHeaderBntblOnFits, length of vector of string lengths not equal to total number of columns" << endl; 1026 int strSz=0; 1027 for (k=0; k<taille_des_chaines.size(); k++) if ( taille_des_chaines[k] > strSz) strSz = taille_des_chaines[k]; 1028 for (k=0; k<(nbString-taille_des_chaines.size()); k++) taille_des_chaines.push_back(strSz); 1009 1029 } 1010 1030 char ** ttype= new char*[tfields]; … … 1012 1032 char largeur[FLEN_VALUE]; 1013 1033 int noColString=0; 1014 int k;1015 1034 for (k=0; k<tfields;k++) 1016 1035 { … … 1073 1092 } 1074 1093 1075 void FitsOutFile:: putColToFits(int nocol, int nentries, double* donnees) const1094 void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const 1076 1095 { 1077 1096 int status = 0; 1078 1097 int hdutype; 1079 1098 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 1080 if( status ) printerror(status," putColToFits: le movabs a foire");1099 if( status ) printerror(status,"PutColToFits: le movabs a foire"); 1081 1100 fits_get_hdu_type(fptr_, &hdutype, &status); 1082 1101 if(hdutype != ASCII_TBL && hdutype != BINARY_TBL) 1083 1102 { 1084 1103 cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl; 1085 throw IOExc("FitsFile:: putColToFits, this HDU is not an ASCII table nor a binary table");1104 throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table"); 1086 1105 } 1087 1106 int code; … … 1090 1109 if( code != TDOUBLE) 1091 1110 { 1092 cout << " WARNING : types don't match ( putColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl;1111 cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " to be written= DOUBLE " << endl; 1093 1112 } 1094 1113 fits_write_col(fptr_,TDOUBLE,nocol+1,1,1,nentries, donnees ,&status); 1095 1114 if( status ) printerror( status,"erreur ecriture du fichier fits" ); 1096 1115 } 1097 void FitsOutFile:: putColToFits(int nocol, int nentries, float* donnees) const1116 void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const 1098 1117 { 1099 1118 int status = 0; 1100 1119 int hdutype; 1101 1120 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 1102 if( status ) printerror(status," putColToFits: le movabs a foire");1121 if( status ) printerror(status,"PutColToFits: le movabs a foire"); 1103 1122 fits_get_hdu_type(fptr_, &hdutype, &status); 1104 1123 if(hdutype != ASCII_TBL && hdutype != BINARY_TBL) 1105 1124 { 1106 1125 cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl; 1107 throw IOExc("FitsFile:: putColToFits, this HDU is not an ASCII table nor a binary table");1126 throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table"); 1108 1127 } 1109 1128 if(hdutype == ASCII_TBL && nocol>0) 1110 1129 { 1111 throw IOExc("FitsFile:: putColToFits, this HDU is an ASCII table, nocol>0 forbidden");1130 throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden"); 1112 1131 } 1113 1132 int code; … … 1116 1135 if( code != TFLOAT) 1117 1136 { 1118 cout << " WARNING : types don't match ( putColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;1137 cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl; 1119 1138 } 1120 1139 fits_write_col(fptr_,TFLOAT,nocol+1,1,1,nentries, donnees ,&status); 1121 1140 if( status ) printerror( status,"erreur ecriture du fichier fits" ); 1122 1141 } 1123 void FitsOutFile:: putColToFits(int nocol, int nentries, int* donnees) const1142 void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const 1124 1143 { 1125 1144 int status = 0; 1126 1145 int hdutype; 1127 1146 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 1128 if( status ) printerror(status," putColToFits: le movabs a foire");1147 if( status ) printerror(status,"PutColToFits: le movabs a foire"); 1129 1148 fits_get_hdu_type(fptr_, &hdutype, &status); 1130 1149 if(hdutype != ASCII_TBL && hdutype != BINARY_TBL) 1131 1150 { 1132 1151 cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl; 1133 throw IOExc("FitsFile:: putColToFits, this HDU is not an ASCII table nor a binary table");1152 throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table"); 1134 1153 } 1135 1154 if(hdutype == ASCII_TBL && nocol>0) 1136 1155 { 1137 throw IOExc("FitsFile:: putColToFits, this HDU is an ASCII table, nocol>0 forbidden");1156 throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden"); 1138 1157 } 1139 1158 int code; … … 1142 1161 if( code != TLONG && code != TINT && code != TSHORT ) 1143 1162 { 1144 cout << " WARNING : types don't match ( putColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl;1163 cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl; 1145 1164 } 1146 1165 fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status); 1147 1166 if( status ) printerror( status," ecriture du fichier fits" ); 1148 1167 } 1149 void FitsOutFile:: putColToFits(int nocol, int nentries, char** donnees) const1168 void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const 1150 1169 { 1151 1170 int status = 0; 1152 1171 int hdutype; 1153 1172 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 1154 if( status ) printerror(status," putColToFits: le movabs a foire");1173 if( status ) printerror(status,"PutColToFits: le movabs a foire"); 1155 1174 fits_get_hdu_type(fptr_, &hdutype, &status); 1156 1175 if(hdutype != ASCII_TBL && hdutype != BINARY_TBL) 1157 1176 { 1158 1177 cout << " hdunum= " << hdunum_ << " hdutype= " << hdutype << endl; 1159 throw IOExc("FitsFile:: putColToFits, this HDU is not an ASCII table nor a binary table");1178 throw IOExc("FitsFile::PutColToFits, this HDU is not an ASCII table nor a binary table"); 1160 1179 } 1161 1180 if(hdutype == ASCII_TBL && nocol>0) 1162 1181 { 1163 throw IOExc("FitsFile:: putColToFits, this HDU is an ASCII table, nocol>0 forbidden");1182 throw IOExc("FitsFile::PutColToFits, this HDU is an ASCII table, nocol>0 forbidden"); 1164 1183 } 1165 1184 int code; … … 1168 1187 if( code != TSTRING) 1169 1188 { 1170 cout << " WARNING : types don't match ( putColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl;1189 cout << " WARNING : types don't match (PutColToFits) : on fits file= " << code << " (FITS code), to be written= char** " << endl; 1171 1190 } 1172 1191 fits_write_col(fptr_,TSTRING,nocol+1,1,1,nentries, donnees ,&status); … … 1174 1193 } 1175 1194 1176 void FitsOutFile::putBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const 1177 { 1195 void FitsOutFile::PutBinTabLine(long NoLine, BnTblLine& ligne) const 1196 { 1197 // on ne fait pas de verification de type, ni de dimension ici, pour 1198 // des raisons de performances 1199 int k; 1178 1200 int status= 0; 1179 1201 int anull; 1180 int dcount = 0.; 1181 int fcount = 0.; 1182 int icount = 0; 1183 int ccount =0; 1184 int ncol; 1202 int ncol=0; 1185 1203 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 } 1204 // int nbcols; 1205 // fits_get_num_cols(fptr_, &nbcols,&status); 1206 for (k=0; k<ligne.ddata_.size(); k++, ncol++) 1207 { 1208 fits_write_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1, &ligne.ddata_[k] ,&status); 1209 if( status ) printerror( status, "PutBinTabLine : erreur ecriture double" ); 1210 } 1211 for (k=0; k<ligne.fdata_.size(); k++, ncol++) 1212 { 1213 fits_write_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1, &ligne.fdata_[k] ,&status); 1214 if( status ) printerror( status, "PutBinTabLine : erreur ecriture float" ); 1215 } 1216 for (k=0; k<ligne.idata_.size(); k++, ncol++) 1217 { 1218 fits_write_col(fptr_,TINT,ncol+1,NoLine+1,1,1, &ligne.idata_[k] ,&status); 1219 if( status ) printerror( status, "PutBinTabLine : erreur ecriture entier" ); 1220 } 1221 1222 for (k=0; k<ligne.cdata_.size(); k++, ncol++) 1223 { 1224 fits_write_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1, strdup(ligne.cdata_[k].c_str()) ,&status); 1225 if( status ) printerror( status, "PutBinTabLine : erreur ecriture caracteres" ); 1220 1226 } 1221 1227 } -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1193 r1209 18 18 { 19 19 int nbcols = dc + fc + ic + cc; 20 int maxName = names.size(); 21 if (nbcols != maxName) 22 { 23 cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl; 24 maxName = nbcols < maxName ? nbcols : maxName; 25 } 20 26 ColName_ = vector<string>(nbcols); 21 for (int k=0; k < nbcols; k++) ColName_ = names;27 for (int k=0; k < maxName; k++) ColName_[k] = names[k]; 22 28 if (dc >0) ddata_ = vector<double>(dc); 23 29 if (fc >0) fdata_ = vector<float>(fc); … … 25 31 if (cc >0) cdata_ = vector<string>(fc); 26 32 } 27 void Print() 33 34 bool sameFormat(const BnTblLine& btl) const 35 { 36 if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size()) return true; 37 else return false; 38 } 39 40 void Print() 28 41 { 29 42 int k; 30 int compt = 0;31 43 cout << " ********* ligne ************* " << endl; 32 44 cout << " *** noms de variables " << endl; 33 for (k=0; k < compt +ColName_.size(); k++) cout << ColName_[k] << " ";45 for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " "; 34 46 cout << endl; 35 47 cout << " *** variables doubles " << endl; … … 162 174 virtual ~FitsFile(); 163 175 164 static string getErrStatus(int status);176 static string GetErrStatus(int status); 165 177 166 178 … … 210 222 211 223 static int NbBlocks(char flnm[]); 212 static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl );224 static void GetBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl ); 213 225 214 226 … … 298 310 299 311 /*! 300 get the NoLine-th 'line' from the current BINTABLE extension on FITS file,312 Get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 301 313 */ 302 314 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char 303 315 ** cdata) ; 304 316 /*! 305 get the NoLine-th 'line' from the current BINTABLE extension on FITS file,317 Get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 306 318 */ 307 319 void GetBinTabLine(long NoLine, BnTblLine& ligne) ; 308 320 309 321 /*! 310 get the NoLine-th 'line' from the current BINTABLE extension on FITS file,322 Get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 311 323 */ 312 324 void GetBinTabLine(int NoLine, float* fdata) ; … … 438 450 439 451 */ 440 void putImageToFits( int nbData, double* map) const;452 void PutImageToFits( int nbData, double* map) const; 441 453 442 454 /*! same as previous method with float data */ 443 void putImageToFits(int nbData, float* map ) const;455 void PutImageToFits(int nbData, float* map ) const; 444 456 445 457 /*! same as previous method with int data */ 446 void putImageToFits(int nbData, int* map) const;458 void PutImageToFits(int nbData, int* map) const; 447 459 448 460 … … 470 482 471 483 */ 472 void putColToFits(int nocol, int nentries, double* donnees) const;484 void PutColToFits(int nocol, int nentries, double* donnees) const; 473 485 474 486 /*! same as previous method with float data */ 475 void putColToFits(int nocol, int nentries, float* donnees) const;487 void PutColToFits(int nocol, int nentries, float* donnees) const; 476 488 477 489 /*! same as previous method with int data */ 478 void putColToFits(int nocol, int nentries, int* donnees) const;490 void PutColToFits(int nocol, int nentries, int* donnees) const; 479 491 480 492 /*! same as previous method with char* data */ 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;493 void PutColToFits(int nocol, int nentries, char** donnees) const; 494 495 void PutBinTabLine(long NoLine, BnTblLine& ligne) const; 484 496 485 497 … … 489 501 490 502 491 /* put keywords from a DVList into the primary header of the fits-file */503 /* Put keywords from a DVList into the primary header of the fits-file */ 492 504 void DVListIntoPrimaryHeader(DVList& dvl) const; 493 505
Note:
See TracChangeset
for help on using the changeset viewer.