Changeset 903 in Sophya
- Timestamp:
- Apr 13, 2000, 11:25:15 AM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r867 r903 2 2 #include "pexceptions.h" 3 3 #include "strutil.h" 4 5 4 #include "anydataobj.h" 5 #include "fitsspherehealpix.h" 6 6 FitsFile::FitsFile() 7 7 { … … 17 17 { 18 18 int status = 0; 19 if( fptr_ != NULL) fits_close_file(fptr_,&status); 19 if( fptr_ != NULL) 20 { 21 fits_close_file(fptr_,&status); 22 delete fptr_; 23 } 20 24 if( status ) printerror( status ); 21 25 } 26 27 28 int FitsFile::NbBlocks(char flnm[]) 29 { 30 int status = 0; 31 int nbhdu = 0; 32 fitsfile* fileptr; 33 fits_open_file(&fileptr,flnm,READONLY,&status); 34 if( status ) printerror( status, "NbBlocks: erreur ouverture fichier" ); 35 fits_get_num_hdus(fileptr, &nbhdu, &status); 36 fits_close_file(fileptr,&status); 37 return nbhdu; 38 } 39 40 void FitsFile::getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl ) 41 { 42 int status = 0; 43 fitsfile* fileptr; 44 fits_open_file(&fileptr,flnm,READONLY,&status); 45 if( status ) printerror( status, "getBlockType: erreur ouverture fichier" ); 46 // move to the specified HDU number 47 int hdutype = 0; 48 fits_movabs_hdu(fileptr,hdunum,&hdutype,&status); 49 if( status ) printerror( status,"getBlockType: erreur movabs"); 50 if(hdutype == IMAGE_HDU) 51 { 52 typeOfExtension = "IMAGE"; 53 int bitpix; 54 GetImageParameters (fileptr, bitpix, naxis, naxisn); 55 if(bitpix == DOUBLE_IMG) dataType = "double"; 56 else 57 if(bitpix == FLOAT_IMG) dataType = "float"; 58 else 59 if(bitpix == LONG_IMG || bitpix == SHORT_IMG ) dataType = "int"; 60 else 61 { 62 cout << " bitpix= " << bitpix << endl; 63 throw PException(" FitsFile::getBlockType : unsupprted FITS data type"); 64 } 65 66 } 67 else 68 if(hdutype == ASCII_TBL || hdutype == BINARY_TBL) 69 { 70 int nrows = 0; 71 vector<string> noms; 72 vector<char> types; 73 vector<int> taille_des_chaines; 74 GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines); 75 for (int k=0; k< naxisn.size(); k++) naxisn[k] *= nrows; 76 if(hdutype == ASCII_TBL) 77 { 78 typeOfExtension = "ASCII_TBL"; 79 dataType = "ASCII"; 80 } 81 else 82 { 83 typeOfExtension = "BINARY_TBL"; 84 if(types[0] == 'D') dataType = "double"; 85 else 86 if(types[0] == 'E') dataType = "float"; 87 else 88 if(types[0] == 'I' ) dataType = "int"; 89 else 90 if(types[0] == 'S' ) dataType = "char*"; 91 else 92 { 93 cout << " types[0]= " << types[0] << endl; 94 throw PException(" FitsFile::getBlockType : unsupprted FITS data type"); 95 } 96 } 97 } 98 else 99 { 100 cout << " hdutype= " << hdutype << endl; 101 throw IOExc("FitsFile::getBlockType: this HDU type is unknown"); 102 } 103 104 fits_movabs_hdu(fileptr,hdunum,&hdutype,&status); 105 if( status ) printerror( status,"getBlockType: erreur movabs, pour dvlist"); 106 KeywordsIntoDVList(fileptr, dvl); 107 fits_close_file(fileptr,&status); 108 } 109 22 110 void FitsFile::ReadF(char flnm[],int hdunum) 23 111 { … … 37 125 if(hdutype_ == IMAGE_HDU) 38 126 { 39 read_image(); 127 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 128 nbData_ = 1; 129 for (int k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 130 fits_movabs_hdu(fptr_,hdunum,&hdutype,&status); 131 if( status ) printerror( status); 132 KeywordsIntoDVList(fptr_, dvl_); 40 133 } 41 134 if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL) 42 135 { 43 GetBinTabParameters(); 136 GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_); 137 fits_movabs_hdu(fptr_,hdunum,&hdutype,&status); 138 if( status ) printerror( status); 139 KeywordsIntoDVList(fptr_, dvl_); 44 140 } 45 141 ReadFromFits(*this); … … 199 295 200 296 201 void FitsFile::read_image() 202 { 203 cout << " Reading a FITS image in HDU : " << hdunum_ << endl; 297 298 void FitsFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn) 299 { 300 int hdunum=0; 301 cout << " Reading a FITS image in HDU : " << fits_get_hdu_num(fileptr,&hdunum) << endl; 204 302 int status= 0; 205 303 206 304 // bits per pixels 207 fits_read_key(f ptr_,TINT,"BITPIX",&bitpix_,NULL,&status);305 fits_read_key(fileptr,TINT,"BITPIX",&bitpix,NULL,&status); 208 306 if( status ) printerror( status ); 209 307 210 308 // number of dimensions in the FITS array 211 int naxis= 0; 212 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 213 if( status ) printerror( status ); 214 naxis_ = naxis; 215 216 // read the NAXIS1 and NAXIS2 keyword to get image size 217 long* naxes = new long[naxis_] ; 309 naxis= 0; 310 fits_read_key(fileptr,TINT,"NAXIS",&naxis,NULL,&status); 311 if( status ) printerror( status ); 312 313 // read the NAXISn keywords to get image size 314 long* naxes = new long[naxis] ; 218 315 int nfound; 219 fits_read_keys_lng(fptr_,"NAXIS",1,naxis_,naxes,&nfound,&status); 220 if( status ) printerror( status ); 221 if (nfound != naxis_ ) 222 cout << " WARNING : " << nfound << " axes found, expexted naxis= " << naxis_ << endl; 223 int lastSize = naxes[naxis_-1]; 224 while (lastSize <= 1) 225 { 226 naxis_--; 227 lastSize = naxes[naxis_-1]; 228 } 229 230 nbData_ = 1; 231 for (int k=0; k<naxis_; k++) 232 { 233 naxisn_.push_back( (int)naxes[k] ); 234 if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 235 316 fits_read_keys_lng(fileptr,"NAXIS",1,naxis,naxes,&nfound,&status); 317 if( status ) printerror( status ); 318 if (nfound != naxis ) 319 cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl; 320 for (int k=0; k<naxis; k++) 321 { 322 naxisn.push_back( (int)naxes[k] ); 236 323 } 237 324 delete [] naxes; 238 325 } 239 326 240 241 void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const 242 { 243 int status= 0; 244 int DTYPE; 245 long repeat,width; 246 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 247 if( DTYPE != TDOUBLE) 248 { 249 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double"); 250 } 251 long nels=nentries; 252 // no checking for undefined pixels 253 int anull; 254 float dnull= 0.; 255 fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs, 256 &anull,&status); 257 if( status ) printerror( status,"erreur lecture de colonne" ); 258 } 259 260 void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const 261 { 262 int status= 0; 263 int DTYPE; 264 long repeat,width; 265 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 266 if( DTYPE != TFLOAT) 267 { 268 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float"); 269 } 270 long nels=nentries; 271 // no checking for undefined pixels 272 int anull; 273 float fnull= 0.; 274 fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs, 275 &anull,&status); 276 if( status ) printerror( status,"erreur lecture de colonne" ); 277 } 278 void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const 279 { 280 int status= 0; 281 int DTYPE; 282 long repeat,width; 283 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 284 if( DTYPE != TLONG && DTYPE != TINT && DTYPE != TSHORT ) 285 { 286 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier"); 287 } 288 long nels=nentries; 289 // no checking for undefined pixels 290 int anull; 291 int inull= 0; 292 fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs, 293 &anull,&status); 294 if( status ) printerror( status,"erreur lecture de colonne" ); 295 } 296 void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const 297 { 298 int status= 0; 299 int DTYPE; 300 long repeat,width; 301 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 302 if( DTYPE != TSTRING ) 303 { 304 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float"); 305 } 306 long nels=nentries; 307 // no checking for undefined pixels 308 int anull; 309 char* cnull= " "; 310 long frow=1; 311 long felem=1; 312 fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs, 313 &anull,&status); 314 if( status ) printerror( status,"erreur lecture de colonne" ); 315 } 316 int FitsFile::NbColsFromFits() const 317 { 318 int status= 0; 319 if(hdutype_ == BINARY_TBL) return nbcols_; 320 else 321 if(hdutype_ == ASCII_TBL || hdutype_ == IMAGE_HDU) return 1; 322 else 323 { 324 cout << " hdutype= " << hdutype_ << endl; 325 throw PException("FitsFile::NbColsFromFits, this HDU is unknown"); 326 } 327 } 328 329 char FitsFile::ColTypeFromFits(int nocol) const 330 { 331 int status= 0; 332 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 333 { 334 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); 335 } 336 return types_[nocol]; 337 } 338 int FitsFile::NentriesFromFits(int nocol) const 339 { 340 int status= 0; 341 if(hdutype_ == BINARY_TBL ) return nrows_*repeat_[nocol]; 342 else 343 if(hdutype_ == ASCII_TBL) return nrows_; 344 else 345 if(hdutype_ == IMAGE_HDU) return nbData_; 346 else 347 { 348 cout << "hdutype= " << hdutype_ << endl; 349 throw PException("FitsFile::NentriesFromFits, this HDU is unknown"); 350 } 351 } 352 353 string FitsFile::ColNameFromFits(int nocol) const 354 { 355 int status= 0; 356 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 357 { 358 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); 359 } 360 return noms_[nocol]; 361 } 362 int FitsFile::ColStringLengthFromFits(int nocol) const 363 { 364 int status= 0; 365 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 366 { 367 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); 368 } 369 int index=-1; 370 for (int k=0; k<=nocol; k++) 371 { 372 if (types_[k] == 'S') index++; 373 } 374 return taille_des_chaines_[index]; 375 } 376 377 void FitsFile::GetBinTabParameters() 378 { 379 int status= 0; 380 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 381 { 382 throw IOExc("FitsFile:: this HDU is not an ASCII table nor a binary table"); 383 } 384 if(hdutype_ == ASCII_TBL) 385 cout << " Reading a FITS ascii table in HDU : " << hdunum_ << endl; 386 if(hdutype_ == BINARY_TBL) 387 cout << " Reading a FITS binary table in HDU : " << hdunum_ << endl; 388 389 // get the number of columns 390 int nbcols = 0; 391 fits_get_num_cols(fptr_, &nbcols,&status); 392 if( status ) printerror( status ); 393 nbcols_=nbcols; 394 395 // get the number of rows 396 long naxis2= 0; 397 fits_get_num_rows(fptr_,&naxis2,&status); 398 if( status ) printerror( status ); 399 nrows_= (int)naxis2; 400 401 // get the datatype, names and the repeat count 402 noms_.clear(); 403 noms_.reserve(nbcols); 404 types_.clear(); 405 types_.reserve(nbcols); 406 repeat_.clear(); 407 repeat_.reserve(nbcols); 408 taille_des_chaines_.clear(); 409 char **ttype = new char*[nbcols]; 410 for (int ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE]; 411 int nfound; 412 fits_read_keys_str(fptr_, "TTYPE",1,nbcols,ttype,&nfound, &status); 413 if( status ) printerror( status,"erreur lecture des noms de colonne"); 414 // int nentries = nrows_; 415 int rept=0; 416 for(int ii = 0; ii < nbcols; ii++) 417 { 418 int DTYPE; 419 long width; 420 long repeat = 0; 421 fits_get_coltype(fptr_,ii+1,&DTYPE,&repeat,&width,&status); 422 if( status ) printerror( status,"erreur lecture type de colonne"); 423 rept = repeat; 424 noms_.push_back(string(ttype[ii])); 425 // cout << " getparam: nentries= " << nentries << " rept= " << rept << endl; 426 switch (DTYPE) 427 { 428 case TDOUBLE : 429 types_.push_back('D'); 430 break; 431 case TFLOAT : 432 types_.push_back('E'); 433 break; 434 case TLONG : 435 types_.push_back('I'); 436 break; 437 case TINT : 438 types_.push_back('I'); 439 break; 440 case TSHORT : 441 types_.push_back('I'); 442 break; 443 case TSTRING : 444 types_.push_back('S'); 445 taille_des_chaines_.push_back(width); 446 rept/=width; 447 break; 448 default : 449 cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl; 450 throw IOExc("FitsFile:: unknown type of field"); 451 } 452 // nentries = max(nentries, nrows_*rept); 453 repeat_.push_back(rept); 454 } 327 void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl) 328 { 455 329 // get number of keywords 456 330 int nkeys,keypos; 457 fits_get_hdrpos(fptr_,&nkeys,&keypos,&status); 331 int status = 0; 332 fits_get_hdrpos(fileptr,&nkeys,&keypos,&status); 458 333 if( status ) printerror( status ); 459 334 … … 470 345 for(int j = num+1; j <= nkeys; j++) 471 346 { 472 fits_read_keyn(f ptr_,j,card,strval,NULL,&status);347 fits_read_keyn(fileptr,j,card,strval,NULL,&status); 473 348 if(status) printerror(status); 474 349 … … 488 363 { 489 364 case 'C': 490 dvl _[keyname]= strval;365 dvl[keyname]= strval; 491 366 break; 492 367 case 'I': 493 368 int ival; 494 fits_read_key(f ptr_,TINT,keyname,&ival,NULL,&status);495 dvl _[keyname]= (int_4) ival; // Portage mac DY369 fits_read_key(fileptr,TINT,keyname,&ival,NULL,&status); 370 dvl[keyname]= (int_4) ival; // Portage mac DY 496 371 break; 497 372 case 'L': … … 499 374 if(strncmp(strval,"T",1) == 0) ilog= 1; 500 375 else ilog= 0; 501 dvl _[keyname]= (int_4) ilog;376 dvl[keyname]= (int_4) ilog; 502 377 break; 503 378 case 'F': 504 379 double dval; 505 fits_read_key(f ptr_,TDOUBLE,keyname,&dval,NULL,&status);506 dvl _[keyname]= dval;380 fits_read_key(fileptr,TDOUBLE,keyname,&dval,NULL,&status); 381 dvl[keyname]= dval; 507 382 break; 508 383 } … … 511 386 } 512 387 // dvl_.Print(); 513 } 388 } 389 390 391 392 void FitsFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const 393 { 394 int status= 0; 395 int DTYPE; 396 long repeat,width; 397 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 398 if( DTYPE != TDOUBLE) 399 { 400 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non double"); 401 } 402 long nels=nentries; 403 // no checking for undefined pixels 404 int anull; 405 float dnull= 0.; 406 fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs, 407 &anull,&status); 408 if( status ) printerror( status,"erreur lecture de colonne" ); 409 } 410 411 void FitsFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const 412 { 413 int status= 0; 414 int DTYPE; 415 long repeat,width; 416 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 417 if( DTYPE != TFLOAT) 418 { 419 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float"); 420 } 421 long nels=nentries; 422 // no checking for undefined pixels 423 int anull; 424 float fnull= 0.; 425 fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs, 426 &anull,&status); 427 if( status ) printerror( status,"erreur lecture de colonne" ); 428 } 429 void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const 430 { 431 int status= 0; 432 int DTYPE; 433 long repeat,width; 434 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 435 if( DTYPE != TLONG && DTYPE != TINT && DTYPE != TSHORT ) 436 { 437 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non entier"); 438 } 439 long nels=nentries; 440 // no checking for undefined pixels 441 int anull; 442 int inull= 0; 443 fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs, 444 &anull,&status); 445 if( status ) printerror( status,"erreur lecture de colonne" ); 446 } 447 void FitsFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const 448 { 449 int status= 0; 450 int DTYPE; 451 long repeat,width; 452 fits_get_coltype(fptr_, NoCol+1,&DTYPE,&repeat,&width,&status); 453 if( DTYPE != TSTRING ) 454 { 455 throw IOExc("FitsFile::GetBinTabFCol, tentative de lecture non float"); 456 } 457 long nels=nentries; 458 // no checking for undefined pixels 459 int anull; 460 char* cnull= " "; 461 long frow=1; 462 long felem=1; 463 fits_read_col(fptr_,TSTRING,NoCol+1,frow,felem,nels,cnull,valeurs, 464 &anull,&status); 465 if( status ) printerror( status,"erreur lecture de colonne" ); 466 } 467 int FitsFile::NbColsFromFits() const 468 { 469 int status= 0; 470 if(hdutype_ == BINARY_TBL) return nbcols_; 471 else 472 if(hdutype_ == ASCII_TBL || hdutype_ == IMAGE_HDU) return 1; 473 else 474 { 475 cout << " hdutype= " << hdutype_ << endl; 476 throw PException("FitsFile::NbColsFromFits, this HDU is unknown"); 477 } 478 } 479 480 char FitsFile::ColTypeFromFits(int nocol) const 481 { 482 int status= 0; 483 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 484 { 485 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); 486 } 487 return types_[nocol]; 488 } 489 int FitsFile::NentriesFromFits(int nocol) const 490 { 491 int status= 0; 492 if(hdutype_ == BINARY_TBL ) return nrows_*repeat_[nocol]; 493 else 494 if(hdutype_ == ASCII_TBL) return nrows_; 495 else 496 if(hdutype_ == IMAGE_HDU) return nbData_; 497 else 498 { 499 cout << "hdutype= " << hdutype_ << endl; 500 throw PException("FitsFile::NentriesFromFits, this HDU is unknown"); 501 } 502 } 503 504 string FitsFile::ColNameFromFits(int nocol) const 505 { 506 int status= 0; 507 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 508 { 509 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); 510 } 511 return noms_[nocol]; 512 } 513 int FitsFile::ColStringLengthFromFits(int nocol) const 514 { 515 int status= 0; 516 if(hdutype_ != ASCII_TBL && hdutype_ != BINARY_TBL) 517 { 518 throw IOExc("FitsFile::TypeFromFits, this HDU is not an ASCII table nor a binary table"); 519 } 520 int index=-1; 521 for (int k=0; k<=nocol; k++) 522 { 523 if (types_[k] == 'S') index++; 524 } 525 return taille_des_chaines_[index]; 526 } 527 528 529 530 void FitsFile::GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows, 531 vector<int>& repeat, 532 vector<string>& noms, 533 vector<char>& types, 534 vector<int>& taille_des_chaines) 535 { 536 int status= 0; 537 int hdunum=0; 538 int hdutype=0; 539 fits_get_hdu_num(fileptr,&hdunum); 540 fits_get_hdu_type(fileptr, &hdutype, &status); 541 542 if(hdutype != ASCII_TBL && hdutype != BINARY_TBL) 543 { 544 throw IOExc("FitsFile::GetBinTabParameters this HDU is not an ASCII table nor a binary table"); 545 } 546 if(hdutype == ASCII_TBL) 547 cout << " Reading a FITS ascii table in HDU : " << hdunum << endl; 548 if(hdutype == BINARY_TBL) 549 cout << " Reading a FITS binary table in HDU : " << hdunum << endl; 550 551 // get the number of columns 552 fits_get_num_cols(fileptr, &nbcols,&status); 553 if( status ) printerror( status ); 554 555 // get the number of rows 556 long naxis2= 0; 557 fits_get_num_rows(fileptr,&naxis2,&status); 558 if( status ) printerror( status ); 559 nrows = (int)naxis2; 560 561 // get the datatype, names and the repeat count 562 noms.clear(); 563 noms.reserve(nbcols); 564 types.clear(); 565 types.reserve(nbcols); 566 repeat.clear(); 567 repeat.reserve(nbcols); 568 taille_des_chaines.clear(); 569 char **ttype = new char*[nbcols]; 570 for (int ii=0; ii < nbcols; ii++) ttype[ii]=new char[FLEN_VALUE]; 571 int nfound; 572 fits_read_keys_str(fileptr, "TTYPE",1,nbcols,ttype,&nfound, &status); 573 if( status ) printerror( status,"erreur lecture des noms de colonne"); 574 int rept=0; 575 for(int ii = 0; ii < nbcols; ii++) 576 { 577 int DTYPE; 578 long width; 579 long repete = 0; 580 fits_get_coltype(fileptr,ii+1,&DTYPE,&repete,&width,&status); 581 if( status ) printerror( status,"erreur lecture type de colonne"); 582 rept = repete; 583 noms.push_back(string(ttype[ii])); 584 switch (DTYPE) 585 { 586 case TDOUBLE : 587 types.push_back('D'); 588 break; 589 case TFLOAT : 590 types.push_back('E'); 591 break; 592 case TLONG : 593 types.push_back('I'); 594 break; 595 case TINT : 596 types.push_back('I'); 597 break; 598 case TSHORT : 599 types.push_back('I'); 600 break; 601 case TSTRING : 602 types.push_back('S'); 603 taille_des_chaines.push_back(width); 604 rept/=width; 605 break; 606 default : 607 cout << " field " << ii+1 << " DTYPE= " << DTYPE << endl; 608 throw IOExc("FitsFile:: unknown type of field"); 609 } 610 repeat.push_back(rept); 611 } 612 } 613 614 615 514 616 void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const 515 617 { … … 777 879 } 778 880 779 void FitsFile::printerror(int &status) const 881 882 883 884 void FitsFile::printerror(int &status) 780 885 //*****************************************************/ 781 886 //* Print out cfitsio error messages and exit program */ … … 790 895 } 791 896 792 void FitsFile::printerror(int& status, char* texte) const897 void FitsFile::printerror(int& status, char* texte) 793 898 //*****************************************************/ 794 899 //* Print out cfitsio error messages and exit program */ -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r875 r903 12 12 namespace SOPHYA { 13 13 14 14 // 15 //! Virtual Class for managing Interface for SOPHYA objects to FITS Format Files (uses cfitsio lib) 16 17 /*! 18 19 Each SOPHYA object XXX is associated with a object of class FITS_XXX 20 (inheriting from FitsFile), to which input/output operations with FITS 21 files are delegated. A typical example of use is the following : 22 23 \verbatim 24 int m=... ; 25 SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object 26 .... fill the sphere .... 27 28 FITS_SphereHEALPix<r_8> fits_sph1(sphere1); 29 // delegated object 30 fits_sph.Write("myfile.fits"); // writing on FITS file 31 32 FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits"); 33 // load a delegated object 34 // from FITS file 35 SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2; 36 // casting the delegated object 37 // into a SOPHYA object 38 \endverbatim 39 40 */ 15 41 class FitsFile 16 42 { … … 19 45 20 46 FitsFile(); 21 // FitsFile(char flnm[],int iomode,int hdunum= 0);22 47 virtual ~FitsFile(); 23 48 static int NbBlocks(char flnm[]); 49 static void getBlockType(char flnm[], int hdunum, string& typeOfExtension, int& naxis, vector<int>& naxisn, string& dataType, DVList& dvl ); 50 /*! return true if the current header corresponds to a FITS image extension */ 24 51 inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);} 52 53 /*! return true if the current header corresponds to a FITS ASCII or BINTABLE extension */ 25 54 inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);} 26 void ReadF(char flnm[],int hdunum= 0); 55 56 /*! 57 this method is called from inherited objects : 58 59 moves to header 'hdunum' on file 'flnm' 60 61 gets parameters in header 62 63 calls the method 'ReadFromFits' from the inherited delegated object 64 65 */ 66 void ReadF(char flnm[],int hdunum= 0); 67 68 /*! 69 this method is called from inherited objects : 70 71 opens a file 'flnm' 72 73 gets parameters in header 74 75 calls the method 'ReadFromFits' from the inherited delegated object 76 77 */ 27 78 void WriteF(char flnm[],int hdunum= 0); 79 80 81 /*! 82 fill the array 'map' with double data from the current extension on FITS file. 83 If the extension is BINTABLE, the first column is provided. 84 85 \param <nentries> number of data to be read 86 */ 28 87 void GetSingleColumn(double* map, int nentries) const; 88 89 /*! same as above with float data */ 29 90 void GetSingleColumn(float* map, int nentries) const; 91 92 /*! same as above with int data */ 30 93 void GetSingleColumn(int* map, int nentries) const; 94 95 /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations) 96 */ 31 97 inline int nbDimOfImage() const {return naxis_;} 98 99 /*! 100 total number of data in the current IMAGE extension 101 */ 32 102 inline int nbOfImageData() const { return nbData_; } 103 104 /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc. 105 */ 33 106 inline const vector<int>& dimOfImageAxes() const { return naxisn_;} 107 108 /*! return number of columns (return 1 if IMAGE) */ 34 109 int NbColsFromFits() const; 110 111 /*! return a character denoting data type of column number 'nocol' in a BINTABLE : 112 113 D : double 114 115 E : float 116 117 I : integer 118 119 S : character string 120 121 */ 35 122 char ColTypeFromFits(int nocol) const; 123 124 /*! number of data in the current IMAGE extension on FITS file, or number 125 of data of column number 'nocol' of the current BINTABLE extension 126 */ 36 127 int NentriesFromFits(int nocol) const; 128 129 /*! name of the column number 'nocol' of the current BINTABLE extension 130 */ 37 131 string ColNameFromFits(int nocol) const; 132 133 134 /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension 135 */ 38 136 int ColStringLengthFromFits(int nocol) const; 137 138 /*! return a reference on a DVList containing the keywords from FITS file 139 */ 39 140 inline const DVList& DVListFromFits() const { return dvl_;} 141 142 143 /*! 144 fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol' 145 146 \param <nentries> number of data to be read 147 */ 40 148 void GetBinTabFCol(double* valeurs, int nentries, int NoCol) const; 149 150 /*! same as previous method with float data */ 41 151 void GetBinTabFCol(float* valeurs, int nentries, int NoCol) const; 152 /*! same as previous method with int data */ 42 153 void GetBinTabFCol(int* valeurs, int nentries, int NoCol) const; 154 /*! same as previous method with char* data */ 43 155 void GetBinTabFCol(char** valeurs,int nentries, int NoCol) const; 44 156 // Write elements into the FITS data array 157 158 /*! write double data from array 'map'on an IMAGE extension 159 \param <nbData> number of data to be written 160 161 */ 45 162 void putImageToFits( int nbData, double* map) const; 163 164 /*! same as previous method with float data */ 46 165 void putImageToFits(int nbData, float* map ) const; 166 167 /*! same as previous method with int data */ 47 168 void putImageToFits(int nbData, int* map) const; 169 170 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension. 171 \param <nentries> number of data to be written 172 173 */ 48 174 void putColToFits(int nocol, int nentries, double* donnees) const; 175 176 /*! same as previous method with float data */ 49 177 void putColToFits(int nocol, int nentries, float* donnees) const; 178 179 /*! same as previous method with int data */ 50 180 void putColToFits(int nocol, int nentries, int* donnees) const; 181 182 /*! same as previous method with char* data */ 51 183 void putColToFits(int nocol, int nentries, char** donnees) const; 52 // Write elements into an ASCII or binary table column 184 185 /*! create an IMAGE header on FITS file. 186 \param <type> type of data (see method ColTypeFromFits) 187 \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS 188 \param <naxisn> array containind sizes of the different dimensions 189 */ 53 190 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) const; 191 192 /*! create an BINTABLE header on FITS file. 193 \param <fieldType> array containing characters denoting types of the different column (see method ColTypeFromFits) 194 \param <Noms> array of the names of columns 195 \param <nentries> number of data of each column 196 \param <tfields> number of columns 197 \param <dvl> a SOPHYA DVList containing keywords to be appended 198 \param <extname> keyword EXTNAME for FITS file 199 \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType' 200 */ 54 201 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const; 55 202 56 203 void readheader(); 57 void printerror(int&) const;58 void printerror(int&,char* texte) const;204 static void printerror(int&) ; 205 static void printerror(int&,char* texte) ; 59 206 protected: 60 207 virtual void ReadFromFits(const FitsFile& ff)=0; 61 208 virtual void WriteToFits(const FitsFile& ff)=0; 62 // virtual void* getColFromObj(int colNr)=0;63 209 private: 64 210 65 void read_image (); 66 void GetBinTabParameters(); 211 static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn); 212 static void GetBinTabParameters(fitsfile* fileptr, int& nbcols, int& nrows, 213 vector<int>& repeat, 214 vector<string>& noms, 215 vector<char>& types, 216 vector<int>& taille_des_chaines); 217 static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl); 67 218 void writeSignatureOnFits() const; 68 219 220 //! pointer to the FITS file, defined in fitsio.h 221 fitsfile *fptr_; 69 222 70 fitsfile *fptr_; // pointer to the FITS file, defined in fitsio.h 71 72 int hdutype_; // image or bintable ? 73 int hdunum_; // index of header to read/write 74 75 76 // fits-Image parameters 223 //! image or bintable ? 224 int hdutype_; 225 226 //! index of header to be read/written 227 int hdunum_; 228 229 230 //! fits-Image parameter 77 231 int bitpix_; 232 233 //! fits-Image parameter 78 234 int naxis_; 235 236 //! fits-Image parameters : sizes of dimensions 79 237 vector<int> naxisn_; 238 239 //! fits-Image parameter: number of data 80 240 int nbData_; 81 241 82 // Bintable parameters242 //! Bintable parameter 83 243 int nrows_; 244 245 //! Bintable parameter 84 246 vector<int> repeat_; 85 247 248 //! Bintable parameter 86 249 int nbcols_; 87 vector<string> noms_; // column names 88 vector<char> types_; // types of columns (D: double, E: float, I: integers 89 // A: char*) 90 vector<int> taille_des_chaines_; // length of the char* variables 91 92 250 251 //! Bintable parameter: column names 252 vector<string> noms_; 253 254 //! Bintable parameters: types of columns (D: double, E: float, I: integers, A: char*) 255 vector<char> types_; 256 257 //! Bintable parameters: length of the char* variables 258 vector<int> taille_des_chaines_; 259 260 //! DVList for transferring keywords 93 261 DVList dvl_; 94 262 };
Note:
See TracChangeset
for help on using the changeset viewer.