Changeset 352 in Sophya for trunk/Poubelle/archTOI.old
- Timestamp:
- Aug 5, 1999, 3:34:11 PM (26 years ago)
- Location:
- trunk/Poubelle/archTOI.old
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Poubelle/archTOI.old/archtoi.cc
r350 r352 34 34 undef = "#"; 35 35 allBolos = false; 36 fptr = NULL; 37 ostr = NULL; 36 38 } 37 39 … … 54 56 // find TOI kind, index and options 55 57 TOIKind kind= (TOIKind)-1; 56 int index= 0;58 int index=-1; 57 59 bool interp=false; 58 60 bool repet =false; … … 108 110 } 109 111 headertoi.push_back(line); 112 string toiname = key.substr(1); 113 if (index>=0) { 114 char idx[10]; 115 sprintf(idx,"_%d",index); 116 toiname += idx; 117 } 118 if (flag) { 119 toinames.push_back("flg_"+toiname); 120 } 121 toinames.push_back(toiname); 110 122 toiflags.push_back(flg((flag?hasflag:0)+((!repet&&!interp)?useNA:0))); 123 if (index<0) index=0; 111 124 svr.AddInfo(kind, index, !notrig, interp); 112 125 } … … 158 171 159 172 160 void ArchTOI::run(string const& filename) 161 { 162 ofstream str(filename.c_str()); 163 run(str); 164 } 165 166 void ArchTOI::run(ostream& str) 167 { 168 // output header 169 for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++) 170 str << (*i) << '\n'; 171 for (list<string>::iterator i = headeropt.begin(); i != headeropt.end(); i++) 172 str << (*i) << '\n';; 173 void ArchTOI::run(string const& outfilename) 174 { 175 if (format == ascii_fmt) { 176 openFile = &openFile_A; 177 outHeader = &outHeader_A; 178 outValue = &outValue_A; 179 endLine = &endLine_A; 180 closeFile = &closeFile_A; 181 } else { // fits_fmt 182 openFile = &openFile_F; 183 outHeader = &outHeader_F; 184 outValue = &outValue_F; 185 endLine = &endLine_F; 186 closeFile = &closeFile_F; 187 } 173 188 174 189 cout << "starting query" << endl; 175 190 TOIIter iter = svr.DoQuery(); 176 // Normalement, on a un bloc param... 177 block_type_param* blk = iter.lastParam(); 178 if (blk) { 179 int nb = blk->param.nb_bolo; 180 for (int i=0; i<nb; i++) { 181 #if version_num > 25 182 if (allBolos) { 183 str << "$BOLO " << i << " " 184 << blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom << " " 185 << blk->param.bolo[i].bolo_code_util << '\n'; 186 } else if (blk->param.bolo[i].bolo_code_util != bolo_hors_service && 187 blk->param.bolo[i].bolo_code_util != bolo_normal_non_transmis) { 188 str << "$BOLO " << i << " " 189 << blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom << "\n"; 190 } 191 #else 192 str << "$BOLO " << i << " " << 193 blk->param.bolo[i].bolo_nom << '\n'; 194 #endif 195 } 196 } 197 str << "#END" << endl; 191 (this->*openFile)(outfilename); 192 (this->*outHeader)(iter); 193 198 194 cout << "processing" << endl; 199 string ofn;200 195 while (iter.Next()) { 201 196 int nn = iter.getSampleIndex(); … … 211 206 } 212 207 if (!hasValue) continue; 208 int icol=0; 213 209 for (int i=0; i<toiflags.size(); i++) { 214 210 double value = iter.getValue(i); … … 216 212 bool isnew = iter.newValue(i); 217 213 flg flag = toiflags[i]; 218 if (flag & hasflag) str << (ok && isnew ? 1 : 0) << " \t"; 214 if (flag & hasflag) { 215 (this->*outValue)(icol, (ok && isnew ? 1 : 0)); 216 icol++; 217 } 219 218 if (((flag & useNA)!=0 && !isnew) || !ok) 220 str << undef << "\t";219 (this->*outValue)(icol, 0, true); 221 220 else 222 str << setprecision(11) << value << " \t"; 223 } 224 str << '\n'; 225 } 226 str.flush(); 221 (this->*outValue)(icol, value); 222 icol++; 223 } 224 (this->*endLine)(); 225 } 226 (this->*closeFile)(); 227 227 cout << "\nDone." << endl; 228 228 } 229 229 230 231 void ArchTOI::openFile_A(string const& filename) { 232 ostr = new ofstream(filename.c_str()); 233 } 234 235 void ArchTOI::outHeader_A(TOIIter& iter) { 236 if (!ostr) return; 237 for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++) 238 *ostr << (*i) << '\n'; 239 for (list<string>::iterator i = headeropt.begin(); i != headeropt.end(); i++) 240 *ostr << (*i) << '\n';; 241 block_type_param* blk = iter.lastParam(); 242 if (blk) { 243 int nb = blk->param.nb_bolo; 244 for (int i=0; i<nb; i++) { 245 #if version_num > 25 246 if (allBolos) { 247 *ostr << "$BOLO " << i << " " 248 << blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom << " " 249 << blk->param.bolo[i].bolo_code_util << '\n'; 250 } else if (blk->param.bolo[i].bolo_code_util != bolo_hors_service && 251 blk->param.bolo[i].bolo_code_util != bolo_normal_non_transmis) { 252 *ostr << "$BOLO " << i << " " 253 << blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom << "\n"; 254 } 255 #else 256 *ostr << "$BOLO " << i << " " << 257 blk->param.bolo[i].bolo_nom << '\n'; 258 #endif 259 } 260 } 261 *ostr << "#END" << endl; 262 } 263 264 void ArchTOI::outValue_A(int icolumn, double value, bool notdef) { 265 if (!ostr) return; 266 if (icolumn > 0) *ostr << '\t'; 267 if (notdef) { 268 *ostr << undef ; 269 } else { 270 *ostr << setprecision(11) << value ; 271 } 272 } 273 274 void ArchTOI::endLine_A() { 275 if (!ostr) return; 276 *ostr << '\n'; 277 } 278 279 void ArchTOI::closeFile_A() { 280 delete ostr; 281 ostr = NULL; 282 } 283 284 285 void ArchTOI::openFile_F(string const& filename) { 286 fitsStatus=0; 287 remove(filename.c_str()); 288 if (fits_create_file(&fptr, filename.c_str(), &fitsStatus)) { 289 fits_report_error(stderr, fitsStatus); 290 exit(-1); 291 } 292 } 293 294 void ArchTOI::outHeader_F(TOIIter& iter) { 295 int ncols=toinames.size(); 296 297 char** colnames = new (char*[ncols]); 298 char** coltypes = new (char*[ncols]); 299 char** colunits = new (char*[ncols]); 300 int j=0; 301 for (list<string>::iterator i = toinames.begin(); i != toinames.end(); i++,j++) { 302 colnames[j] = const_cast<char*>((*i).c_str()); // should work for most STL implementations... Check... 303 coltypes[j] = "1D"; 304 colunits[j] = " "; 305 } 306 307 fits_create_tbl(fptr, BINARY_TBL, 0, ncols, colnames, coltypes, colunits, NULL, &fitsStatus); 308 fits_write_date(fptr, &fitsStatus); 309 310 delete[] colunits; 311 delete[] coltypes; 312 delete[] colnames; 313 314 j=1; 315 // Rappel dans le header des requetes... 316 int ntoireq = headertoi.size(); 317 fits_write_key(fptr, TINT, "TOIREQ", &ntoireq, NULL, &fitsStatus); 318 for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++,j++) { 319 char line[80]; 320 strcpy(line, (*i).c_str()); 321 char* pline = line; 322 fits_write_keys_str(fptr, "TOIREQ", j, 1, &pline, (char**) NULL, &fitsStatus); 323 } 324 j=1; 325 int noptreq = headeropt.size(); 326 fits_write_key(fptr, TINT, "OPTREQ", &noptreq, NULL, &fitsStatus); 327 for (list<string>::iterator i = headeropt.begin(); i != headeropt.end(); i++,j++) { 328 char line[80]; 329 strcpy(line, (*i).c_str()); 330 char* pline = line; 331 fits_write_keys_str(fptr, "OPTREQ", j, 1, &pline, (char**) NULL, &fitsStatus); 332 } 333 334 // Noms des bolos 335 block_type_param* blk = iter.lastParam(); 336 if (blk) { 337 int nb = blk->param.nb_bolo; 338 j=0; 339 for (int i=0; i<nb; i++) { 340 #if version_num > 25 341 if (allBolos || 342 (blk->param.bolo[i].bolo_code_util != bolo_hors_service && 343 blk->param.bolo[i].bolo_code_util != bolo_normal_non_transmis)) { 344 j++; 345 char line[80]; 346 strcpy(line, blk->param.nom_coef[blk->param.bolo[i].numero_nom_coef].bolo_nom); 347 char* pline = line; 348 fits_write_keys_str(fptr, "BOLO", j, 1, &pline, (char**) NULL, &fitsStatus); 349 } 350 #else 351 j++; 352 char line[80]; 353 strcpy(line, blk->param.bolo[i].bolo_nom); 354 char* pline = line; 355 fits_write_keys_str(fptr, "BOLO", j, 1, &pline, (char**) NULL, &fitsStatus); 356 #endif 357 } 358 fits_write_key(fptr, TINT, "BOLO", &j, NULL, &fitsStatus); 359 } 360 fitsLine = 1; 361 } 362 363 void ArchTOI::outValue_F(int icolumn, double value, bool notdef) { 364 if (notdef) { 365 fits_write_col_null(fptr, icolumn+1, fitsLine, 1, 1, &fitsStatus); 366 } else { 367 fits_write_col_dbl(fptr, icolumn+1, fitsLine, 1, 1, &value, &fitsStatus); 368 } 369 } 370 371 void ArchTOI::endLine_F() { 372 fitsLine++; 373 } 374 375 void ArchTOI::closeFile_F() { 376 fits_close_file(fptr, &fitsStatus); 377 fits_report_error(stderr, fitsStatus); /* print out any error messages */ 378 } -
trunk/Poubelle/archTOI.old/archtoi.h
r350 r352 10 10 #include <vector> 11 11 #include "toisvr.h" 12 #include "fitsio.h" 12 13 13 14 using namespace std; … … 18 19 ArchTOI(string const& filename); 19 20 20 void run(ostream& str); 21 void run(string const& filename); 21 void run(string const& outfilename); 22 22 23 23 enum fmt {ascii_fmt, fits_fmt}; … … 33 33 list<string> headertoi; 34 34 list<string> headeropt; 35 list<string> toinames; 35 36 vector<flg> toiflags; 36 37 fmt format; 37 38 string undef; 38 39 bool allBolos; // tous les bolos dans le header. Sinon seulement bolos transmis. 40 41 void (ArchTOI::*openFile)(string const& filename); 42 void (ArchTOI::*outHeader)(TOIIter& iter); 43 void (ArchTOI::*outValue)(int icolumn, double value, bool notdef=false); 44 void (ArchTOI::*endLine)(); 45 void (ArchTOI::*closeFile)(); 46 47 void openFile_A(string const& filename); 48 void outHeader_A(TOIIter& iter); 49 void outValue_A(int icolumn, double value, bool notdef=false); 50 void endLine_A(); 51 void closeFile_A(); 52 53 void openFile_F(string const& filename); 54 void outHeader_F(TOIIter& iter); 55 void outValue_F(int icolumn, double value, bool notdef=false); 56 void endLine_F(); 57 void closeFile_F(); 58 59 fitsfile* fptr; 60 int fitsStatus; 61 int fitsLine; 62 ofstream* ostr; 39 63 }; 40 64
Note:
See TracChangeset
for help on using the changeset viewer.