Changeset 1218 in Sophya for trunk/SophyaExt/FitsIOServer/fitsfile.cc
- Timestamp:
- Oct 3, 2000, 2:14:14 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1209 r1218 8 8 9 9 10 void BnTblLine::setFormat(int dc, int fc, int ic, int cc, vector<string> names) 11 { 12 int nbcols = dc + fc + ic + cc; 13 int maxName = names.size(); 14 if (nbcols != maxName) 15 { 16 cout << " WARNING: BnTblLine:: length of vector of column names not equal to total number of columns" << endl; 17 maxName = nbcols < maxName ? nbcols : maxName; 18 } 19 ColName_ = vector<string>(nbcols); 20 for (int k=0; k < maxName; k++) ColName_[k] = names[k]; 21 if (dc >0) ddata_ = vector<double>(dc); 22 if (fc >0) fdata_ = vector<float>(fc); 23 if (ic >0) idata_ = vector<int>(fc); 24 if (cc >0) cdata_ = vector<string>(fc); 25 } 26 27 bool BnTblLine::sameFormat(const BnTblLine& btl) const 28 { 29 if (btl.ddata_.size() == ddata_.size() && btl.fdata_.size() == fdata_.size() && btl.idata_.size() == idata_.size() && btl.cdata_.size() == cdata_.size()) return true; 30 else return false; 31 } 32 33 void BnTblLine::Print() 34 { 35 int k; 36 cout << " ********* ligne ************* " << endl; 37 cout << " *** noms de variables " << endl; 38 for (k=0; k < ColName_.size(); k++) cout << ColName_[k] << " "; 39 cout << endl; 40 cout << " *** variables doubles " << endl; 41 for (k=0; k < ddata_.size(); k++) cout << ddata_[k] << " "; 42 cout << endl; 43 cout << " *** variables float " << endl; 44 for (k=0; k < fdata_.size(); k++) cout << fdata_[k] << " "; 45 cout << endl; 46 cout << " *** variables int " << endl; 47 for (k=0; k < idata_.size(); k++) cout << idata_[k] << " "; 48 cout << endl; 49 cout << " *** variables string " << endl; 50 for (k=0; k < cdata_.size(); k++) cout << cdata_[k] << " "; 51 cout << endl; 52 cout << " ***************************** " << endl; 53 } 54 55 56 57 /*! 58 \class SOPHYA::FitsIOHandler 59 The class structure is analogous to Sophya-PPersist system : 60 Each SOPHYA object XXX is associated with a object of class FITS_XXX 61 (inheriting from FitsFileHandler), to which input/output operations with FITS 62 files are delegated (through a class Hierarchy : FitsFile (virtual), 63 FitsInFile, FitsOutFile) . A typical example of use is the following : 64 65 \verbatim 66 int m=... ; 67 SphereHEALPix<r_8> sphere1(m); // definition of the SOPHYA object 68 .... fill the sphere .... 69 70 FITS_SphereHEALPix<r_8> fits_sph1(sphere1); 71 // delegated object 72 fits_sph.Write("myfile.fits"); // writing on FITS file 73 74 FITS_SphereHEALPix<r_8> fits_sph2("myfile.fits"); 75 // load a delegated object 76 // from FITS file 77 SphereHEALPix<r_8> sphere2=(SphereHEALPix<r_8>)fits_sph2; 78 // casting the delegated object 79 // into a SOPHYA object 80 \endverbatim 81 82 83 */ 84 85 /*! \fn void SOPHYA::FitsIOHandler::Read(char flnm[],int hdunum) 86 87 this method is called from inherited objects : 88 89 opens a file 'flnm' 90 91 gets parameters in extension-header (hdunum) 92 93 calls the method 'ReadFromFits' from the inherited object 94 */ 10 95 void FitsIOHandler::Read(char flnm[],int hdunum) 11 96 { … … 13 98 Read(ifts, hdunum); 14 99 } 100 101 /*! \fn void SOPHYA::FitsIOHandler::Read(FitsInFile& is, int hdunum) 102 Read the data on extension hdunum (or primary header, if hdunum=1) from FitsInFIle. If hdunum is not addressed, , one reads the next extension, with respect to the current position. 103 */ 15 104 void FitsIOHandler::Read(FitsInFile& is, int hdunum) 16 105 { … … 21 110 22 111 112 /*! \fn void SOPHYA::FitsIOHandler::Write(char flnm[]) 113 this method is called from inherited objects. 114 115 for writing a new object in a new fits-extension : 116 117 \warning By convention, primary header does not contain fits-image data : i.e. 118 all data are fits-extensions. The first relevant header will have hdunum=2. 119 For switching off this convention use the method : 120 121 firstImageOnPrimaryHeader() (see below) 122 123 In that case do not forget to precise hdunum=1 when reading data on primary header. 124 125 calls the method 'WriteToFits' from the inherited object 126 127 */ 23 128 void FitsIOHandler::Write(char flnm[]) 24 129 … … 33 138 } 34 139 140 141 /*! 142 \class SOPHYA::FitsIOHandler 143 Class (virtual) for managing FITS format files 144 */ 35 145 36 146 … … 87 197 } 88 198 199 /*! 200 \class SOPHYA::FitsInFile 201 202 class for saving SOPHYA objects on FITS Format Files (uses cfitsio lib) 203 */ 204 89 205 FitsInFile::FitsInFile() 90 206 { 91 207 InitNull(); 92 208 } 93 //FitsInFile::FitsInFile(char flnm[], int hdunum) 209 94 210 FitsInFile::FitsInFile(char flnm[]) 95 211 { … … 118 234 } 119 235 236 ////////////////////////////////////////////////////////// 237 // methods with general purpose 238 ///////////////////////////////////////////////////////// 120 239 121 240 int FitsInFile::NbBlocks(char flnm[]) … … 200 319 } 201 320 321 322 void FitsInFile::ReadFInit(int hdunum) 323 { 324 InitNull(); 325 // int status = 0; 326 327 // fits_open_file(&fptr_,flnm,READONLY,&status); 328 // if( status ) printerror( status ); 329 330 int status = 0; 331 332 if (hdunum <= 1) 333 { 334 hdunum_ = 1; 335 // presence of image ? 336 int naxis= 0; 337 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 338 if( status ) printerror( status ); 339 if (naxis > 0 ) // there is an image 340 { 341 hdutype_ = IMAGE_HDU; 342 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 343 nbData_ = 1; 344 int k; 345 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 346 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 347 } 348 else 349 { 350 throw PException(" first header : no image, probably error in hdunum"); 351 } 352 // 353 } 354 else 355 { 356 hdunum_ = hdunum-1; 357 int hdutype; 358 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 359 if( status ) printerror( status,":FitsFile::ReadF : erreur movabs"); 360 moveToFollowingHeader(); 361 } 362 } 363 364 202 365 void FitsInFile::GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn) 203 366 { … … 230 393 231 394 232 void FitsInFile::ReadFInit(int hdunum) 233 { 234 InitNull(); 235 // int status = 0; 236 237 // fits_open_file(&fptr_,flnm,READONLY,&status); 238 // if( status ) printerror( status ); 239 240 int status = 0; 241 242 if (hdunum <= 1) 243 { 244 hdunum_ = 1; 245 // presence of image ? 246 int naxis= 0; 247 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 248 if( status ) printerror( status ); 249 if (naxis > 0 ) // there is an image 250 { 251 hdutype_ = IMAGE_HDU; 252 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 253 nbData_ = 1; 254 int k; 255 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 256 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 257 } 258 else 259 { 260 throw PException(" first header : no image, probably error in hdunum"); 261 } 262 // 263 } 264 else 265 { 266 hdunum_ = hdunum-1; 267 int hdutype; 268 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 269 if( status ) printerror( status,":FitsFile::ReadF : erreur movabs"); 270 moveToFollowingHeader(); 271 } 272 } 273 395 396 397 /*! \fn DVList SOPHYA::FitsInFile::DVListFromPrimaryHeader() const 398 399 \return the keywords of primary header in a DVList 400 401 */ 274 402 DVList FitsInFile::DVListFromPrimaryHeader() const 275 403 { … … 308 436 309 437 438 439 440 441 /*! \fn int SOPHYA::FitsInFile::NbColsFromFits() const 442 \return number of columns (return 1 if IMAGE) 443 */ 310 444 int FitsInFile::NbColsFromFits() const 311 445 { … … 320 454 } 321 455 456 /*! \fn int SOPHYA::FitsInFile::NentriesFromFits(int nocol) const 457 \return number of data in the current IMAGE extension on FITS file, or number 458 of data of column number 'nocol' of the current BINTABLE extension 459 */ 322 460 int FitsInFile::NentriesFromFits(int nocol) const 323 461 { … … 334 472 } 335 473 474 /*! \fn char SOPHYA::FitsInFile::ColTypeFromFits(int nocol) const 475 476 return a character denoting data type of column number 'nocol' in a BINTABLE : 477 478 D : double 479 480 E : float 481 482 I : integer 483 484 S : character string 485 486 */ 487 336 488 char FitsInFile::ColTypeFromFits(int nocol) const 337 489 { … … 342 494 return types_[nocol]; 343 495 } 496 497 498 /*! \fn string SOPHYA::FitsInFile::ColNameFromFits(int nocol) const 499 500 \return name of the column number 'nocol' of the current BINTABLE extension 501 */ 502 344 503 string FitsInFile::ColNameFromFits(int nocol) const 345 504 { … … 350 509 return noms_[nocol]; 351 510 } 511 512 /*! \fn int DSOPHYA::FitsInFile::ColStringLengthFromFits(int nocol) const 513 514 \return number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension 515 */ 352 516 353 517 int FitsInFile::ColStringLengthFromFits(int nocol) const … … 365 529 return taille_des_chaines_[index]; 366 530 } 531 532 533 534 /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 535 536 Get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 537 */ 538 367 539 void FitsInFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 368 540 { … … 405 577 } 406 578 579 /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne) 580 Get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 581 */ 407 582 void FitsInFile::GetBinTabLine(long NoLine, BnTblLine& ligne) 408 583 { … … 447 622 } 448 623 624 /*! \fn void SOPHYA::FitsInFile::GetBinTabLine(int NoLine, float* fdata) 625 626 Get the NoLine-th float 'line' from the current BINTABLE extension on FITS file, 627 */ 449 628 void FitsInFile::GetBinTabLine(int NoLine, float* fdata) 450 629 { … … 466 645 467 646 647 /*! \fn void SPOPHYA::FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const 648 649 fill the array 'valeurs' with double data from the current BINTABLE extension on FITS file, from column number 'NoCol' 650 651 \param <nentries> number of data to be read 652 */ 468 653 void FitsInFile::GetBinTabFCol(double* valeurs,int nentries, int NoCol) const 469 654 { … … 499 684 } 500 685 686 /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const 687 688 same as previous method with float data 689 */ 501 690 void FitsInFile::GetBinTabFCol(float* valeurs,int nentries, int NoCol) const 502 691 { … … 531 720 } 532 721 722 /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const 723 724 same as previous method with int data 725 */ 726 533 727 void FitsInFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const 534 728 { … … 561 755 } 562 756 757 /*! \fn void SOPHYA::FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const 758 759 same as previous method with char* data 760 */ 761 563 762 void FitsInFile::GetBinTabFCol(char** valeurs, int nentries, int NoCol) const 564 763 { … … 587 786 } 588 787 788 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(double* map, int nentries) const 789 fill the array 'map' with double data from the current extension on FITS file. 790 If the extension is BINTABLE, the first column is provided. 791 792 \param <nentries> number of data to be read 793 */ 589 794 void FitsInFile::GetSingleColumn(double* map, int nentries) const 590 795 { … … 619 824 } 620 825 826 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn(float* map, int nentries) const 827 same as above with float data 828 */ 621 829 void FitsInFile::GetSingleColumn(float* map, int nentries) const 622 830 { … … 649 857 } 650 858 859 /*! \fn void SOPHYA::FitsInFile::GetSingleColumn( int* map, int nentries) const 860 same as above with int data 861 */ 651 862 void FitsInFile::GetSingleColumn( int* map, int nentries) const 652 863 { … … 866 1077 } 867 1078 1079 1080 /*! 1081 \class SOPHYA::FitsOutFile 1082 Class for loading SOPHYA objects from FITS Format Files (uses cfitsio lib) 1083 */ 1084 868 1085 FitsOutFile::FitsOutFile() 869 1086 { … … 871 1088 } 872 1089 1090 /*! \fn SOPHYA::FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm) 1091 1092 \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) 1093 1094 */ 873 1095 FitsOutFile::FitsOutFile(char flnm[], WriteMode wrm) 874 1096 { … … 929 1151 930 1152 1153 /*! \fn void SOPHYA::FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl) 1154 1155 create an IMAGE header on FITS file. 1156 \param <type> type of data (see method ColTypeFromFits) 1157 \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS 1158 \param <naxisn> array containind sizes of the different dimensions 1159 */ 931 1160 void FitsOutFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList &dvl) 932 1161 { … … 968 1197 969 1198 } 1199 1200 1201 /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, double* map) const 1202 1203 write double data from array 'map'on an IMAGE extension 1204 \param <nbData> number of data to be written 1205 */ 970 1206 void FitsOutFile::PutImageToFits(int nbData, double* map) const 971 1207 { … … 977 1213 } 978 1214 1215 /*! \fn void SOPHYA::FitsOutFile::PutImageToFits(int nbData, float* map) const 1216 1217 same as previous method with float data 1218 */ 979 1219 void FitsOutFile::PutImageToFits(int nbData, float* map) const 980 1220 { … … 986 1226 987 1227 } 1228 1229 /*! \fn void SOPHYA::FitsOutFile::PutImageToFits( int nbData, int* map) const 1230 1231 same as previous method with int data */ 988 1232 void FitsOutFile::PutImageToFits( int nbData, int* map) const 989 1233 { … … 998 1242 999 1243 1244 /*! \fn void SOPHYA::FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines) 1245 1246 create an BINTABLE header on FITS file. 1247 \param <fieldType> array conta 1248 ining characters denoting types of the different column (see method ColTypeFromFits) 1249 \param <Noms> array of the names of columns 1250 \param <nentries> number of data of each column 1251 \param <tfields> number of columns 1252 \param <dvl> a SOPHYA DVList containing keywords to be appended 1253 \param <extname> keyword EXTNAME for FITS file 1254 \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType' 1255 */ 1000 1256 void FitsOutFile::makeHeaderBntblOnFits( string fieldType, vector<string> Noms, int nentries, int tfields, DVList &dvl, string extname, vector<int> taille_des_chaines) 1001 1257 { … … 1092 1348 } 1093 1349 1350 /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const 1351 1352 write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension. 1353 \param <nentries> number of data to be written 1354 */ 1094 1355 void FitsOutFile::PutColToFits(int nocol, int nentries, double* donnees) const 1095 1356 { … … 1114 1375 if( status ) printerror( status,"erreur ecriture du fichier fits" ); 1115 1376 } 1377 1378 1379 1380 /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const 1381 1382 same as previous method with float data 1383 */ 1116 1384 void FitsOutFile::PutColToFits(int nocol, int nentries, float* donnees) const 1117 1385 { … … 1140 1408 if( status ) printerror( status,"erreur ecriture du fichier fits" ); 1141 1409 } 1410 1411 1412 /*! \fn void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const 1413 1414 same as previous method with int data 1415 */ 1142 1416 void FitsOutFile::PutColToFits(int nocol, int nentries, int* donnees) const 1143 1417 { … … 1166 1440 if( status ) printerror( status," ecriture du fichier fits" ); 1167 1441 } 1442 1443 1444 /*! \fn void SOPHYA::FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const 1445 same as previous method with char* data 1446 */ 1168 1447 void FitsOutFile::PutColToFits(int nocol, int nentries, char** donnees) const 1169 1448 { … … 1228 1507 1229 1508 1509 /* \fn void SOPHYA::FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const 1510 1511 Put keywords from a DVList into the primary header of the fits-file 1512 */ 1230 1513 void FitsOutFile::DVListIntoPrimaryHeader(DVList& dvl) const 1231 1514 {
Note:
See TracChangeset
for help on using the changeset viewer.