Changeset 2453 in Sophya
- Timestamp:
- Nov 13, 2003, 4:49:45 PM (22 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fabtcolread.cc
r2451 r2453 110 110 } 111 111 112 void FitsOpenFile::printerror(int sta) const 112 ////////////////////////////////////////////////////////////// 113 //// Methodes statiques 114 ////////////////////////////////////////////////////////////// 115 /*! 116 Read a fitsheader key into double 117 \param fitsptr : cfitio pointer to Fits file 118 \param keyname : name of the key 119 \return value into double 120 */ 121 double FitsOpenFile::ReadKey(fitsfile *fitsptr,char *keyname) 122 { 123 if(keyname==NULL) return 0.; 124 int sta=0; double val=0.; 125 if(fits_read_key(fitsptr,TDOUBLE,keyname,&val,NULL,&sta)) 126 printerror(sta); 127 return val; 128 } 129 130 /*! 131 Read a fitsheader key into long 132 \param fitsptr : cfitio pointer to Fits file 133 \param keyname : name of the key 134 \return value into long 135 */ 136 long FitsOpenFile::ReadKeyL(fitsfile *fitsptr,char *keyname) 137 { 138 if(keyname==NULL) return 0; 139 int sta=0; long val=0; 140 if(fits_read_key(fitsptr,TLONG,keyname,&val,NULL,&sta)) 141 printerror(sta); 142 return val; 143 } 144 145 /*! 146 Read a fitsheader key into string 147 \param fitsptr : cfitio pointer to Fits file 148 \param keyname : name of the key 149 \return value into string 150 */ 151 string FitsOpenFile::ReadKeyS(fitsfile *fitsptr,char *keyname) 152 { 153 if(keyname==NULL) return (string)""; 154 int sta=0; char val[FLEN_VALUE]; 155 if(fits_read_key(fitsptr,TSTRING,keyname,val,NULL,&sta)) 156 printerror(sta); 157 string sval = val; 158 return sval; 159 } 160 161 /*! 162 CFitsIO error printing routine 163 \param sta : cfitio error return code 164 */ 165 void FitsOpenFile::printerror(int sta) 113 166 { 114 167 int stat = sta; … … 268 321 if(IHdu<=0 || IHdu>NHdu) 269 322 for(int ihdu=1;ihdu<=NHdu;ihdu++) { 270 if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) printerror(sta);323 if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) FitsOpenFile::printerror(sta); 271 324 if(DbgLevel>1) cout<<"...Init ihdu=" 272 325 <<ihdu<<" HduType="<<HduType<<endl; … … 279 332 } 280 333 if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) { 281 printerror(sta); Delete();334 FitsOpenFile::printerror(sta); Delete(); 282 335 throw RangeCheckError("FitsABTColRd::Init: Error moving to requested HDU\n"); 283 336 } … … 289 342 // Get number of columns 290 343 if(fits_get_num_cols(FitsPtr,&NBcol,&sta)) { 291 printerror(sta); Delete();344 FitsOpenFile::printerror(sta); Delete(); 292 345 throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of columns\n"); 293 346 } … … 300 353 // Get number of rows 301 354 if(fits_get_num_rows(FitsPtr,&NBline,&sta)) { 302 printerror(sta); Delete();355 FitsOpenFile::printerror(sta); Delete(); 303 356 throw NotAvailableOperation("FitsABTColRd::Init: Error getting number of rows\n"); 304 357 } … … 314 367 strcpy(labelcol,ColLabel.c_str()); 315 368 if(fits_get_colnum(FitsPtr,CASESEN,labelcol,&ColNum,&sta)) { 316 printerror(sta); Delete();369 FitsOpenFile::printerror(sta); Delete(); 317 370 throw NotAvailableOperation("FitsABTColRd::Init: Error getting column name\n"); 318 371 } … … 327 380 // Get column type 328 381 if(fits_get_coltype(FitsPtr,ColNum+1,&ColTypeCode,NULL,NULL,&sta)) { 329 printerror(sta); Delete();382 FitsOpenFile::printerror(sta); Delete(); 330 383 throw ParmError("FitsABTColRd::Init: Error getting column type\n"); 331 384 } … … 349 402 } 350 403 if(rc) { 351 printerror(sta); Delete();404 FitsOpenFile::printerror(sta); Delete(); 352 405 throw RangeCheckError("FitsABTColRd::Init: Error getting the column caracteristics\n"); 353 406 } … … 414 467 double FitsABTColRd::ReadKey(char *keyname) 415 468 { 416 if(keyname==NULL) return 0.; 417 int sta=0; double val=0.; 418 if(fits_read_key(FitsPtr,TDOUBLE,keyname,&val,NULL,&sta)) 419 printerror(sta); 420 return val; 469 return FitsOpenFile::ReadKey(FitsPtr,keyname); 421 470 } 422 471 … … 428 477 long FitsABTColRd::ReadKeyL(char *keyname) 429 478 { 430 if(keyname==NULL) return 0; 431 int sta=0; long val=0; 432 if(fits_read_key(FitsPtr,TLONG,keyname,&val,NULL,&sta)) 433 printerror(sta); 434 return val; 479 return FitsOpenFile::ReadKeyL(FitsPtr,keyname); 435 480 } 436 481 … … 442 487 string FitsABTColRd::ReadKeyS(char *keyname) 443 488 { 444 if(keyname==NULL) return 0; 445 int sta=0; char val[FLEN_VALUE]; 446 if(fits_read_key(FitsPtr,TSTRING,keyname,val,NULL,&sta)) 447 printerror(sta); 448 string sval = val; 449 return sval; 489 return FitsOpenFile::ReadKeyS(FitsPtr,keyname); 450 490 } 451 491 … … 476 516 fits_read_col(FitsPtr,TDOUBLE,ColNum+1,n+1,1,1,NULL,&val,NULL,&sta); 477 517 if(sta) { 478 printerror(sta);518 FitsOpenFile::printerror(sta); 479 519 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); 480 520 } … … 511 551 fits_read_col(FitsPtr,TDOUBLE,ColNum+1,row1,1,nrow,NULL,Buffer,NULL,&sta); 512 552 if(sta) { 513 printerror(sta);553 FitsOpenFile::printerror(sta); 514 554 LineDeb = LineFin = -1; 515 555 throw NotAvailableOperation("FitsABTColRd::Read: Error Reading Fits file\n"); … … 569 609 fits_read_col(FitsPtr,TDOUBLE,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 570 610 if(sta) { 571 printerror(sta);611 FitsOpenFile::printerror(sta); 572 612 throw NotAvailableOperation("FitsABTColRd::Read_TVector<double>: Error Reading Fits file\n"); 573 613 } … … 593 633 fits_read_col(FitsPtr,TFLOAT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 594 634 if(sta) { 595 printerror(sta);635 FitsOpenFile::printerror(sta); 596 636 throw NotAvailableOperation("FitsABTColRd::Read_TVector<float>: Error Reading Fits file\n"); 597 637 } … … 616 656 fits_read_col(FitsPtr,TUSHORT,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 617 657 if(sta) { 618 printerror(sta);658 FitsOpenFile::printerror(sta); 619 659 throw NotAvailableOperation("FitsABTColRd::Read_TVector<uint_2>: Error Reading Fits file\n"); 620 660 } … … 641 681 fits_read_col(FitsPtr,T,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 642 682 if(sta) { 643 printerror(sta);683 FitsOpenFile::printerror(sta); 644 684 throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_4>: Error Reading Fits file\n"); 645 685 } … … 665 705 fits_read_col(FitsPtr,TLONGLONG,ColNum+1,n1+1,1,nread,NULL,data.Data(),NULL,&sta); 666 706 if(sta) { 667 printerror(sta);707 FitsOpenFile::printerror(sta); 668 708 throw NotAvailableOperation("FitsABTColRd::Read_TVector<int_8>: Error Reading Fits file\n"); 669 709 } … … 731 771 if(bchange) ChangeBuffer(BuffLen,bsens); 732 772 return row; 733 }734 735 /////////////////////////////////////////////////736 void FitsABTColRd::printerror(int sta) const737 {738 int stat = sta;739 fits_report_error(stdout,stat);740 fflush(stdout);741 return;742 773 } 743 774 … … 857 888 if(FitsOF!=NULL) delete FitsOF; 858 889 } 890 891 /////////////////////////////////////////////////////////////////// 892 //! Class for reading a 2D image from a FITS file 893 894 /*! 895 \class SOPHYA::FitsImg2DRd 896 \ingroup FitsIOServer 897 Class for reading a 2D image from a FITS file 898 */ 899 900 ////////////////////////////////////////////////////////////// 901 /*! 902 Constructor. 903 \param fof : Pointer to the Class for opening the FITS file 904 \param ihdu : number of the HDU where the column is. 905 \param lp : debug level 906 \verbatim 907 - if ihdu=0 or ihdu>nhdu first binary or ASCII table is taken 908 \endverbatim 909 \warning ihdu = [1,nhdu] 910 */ 911 FitsImg2DRd::FitsImg2DRd(FitsOpenFile* fof,int ihdu,int lp) 912 { 913 Init(fof,ihdu,lp); 914 } 915 916 /*! Constructor by copy */ 917 FitsImg2DRd::FitsImg2DRd(FitsImg2DRd& fbt) 918 { 919 Init(fbt.GetFitsOpenFile(),fbt.GetHDU(),fbt.DbgLevel); 920 } 921 922 /*! Constructor by default */ 923 FitsImg2DRd::FitsImg2DRd() 924 { 925 FitsFN = ""; 926 IHdu = 0; NHdu = 0; HduType = 0; 927 Naxis[0] = Naxis[1] = 0; 928 SetNulVal(); SetDebug(0); 929 FitsOF = NULL; FitsPtr = NULL; 930 } 931 932 /*! Init routine called by the constructor */ 933 void FitsImg2DRd::Init(FitsOpenFile* fof,int ihdu,int lp) 934 { 935 // Initialisation des Parametres Generaux 936 FitsFN = ""; 937 IHdu = ihdu; NHdu = 0; HduType = 0; 938 Naxis[0] = Naxis[1] = 0; 939 SetNulVal(); SetDebug(lp); 940 FitsOF = NULL; FitsPtr = NULL; 941 942 // Caracteristiques du FitsOpenFile 943 FitsOF = fof; 944 if(FitsOF==NULL) 945 throw NullPtrError("FitsImg2DRd::Init: FitsOpenFile pointer is NULL\n"); 946 FitsPtr = FitsOF->GetFitsPtr(); 947 if(FitsPtr==NULL) 948 throw NullPtrError("FitsImg2DRd::Init: FitsPtr pointer is NULL\n"); 949 NHdu = FitsOF->GetNHdu(); 950 if(DbgLevel>1) cout<<"FitsImg2DRd::Init NHdu="<<NHdu<<endl; 951 if(NHdu<=0) 952 throw SzMismatchError("FitsImg2DRd::Init: Bad NHdu\n"); 953 FitsFN = FitsOF->GetFileName(); 954 if(FitsFN.size() <= 0 ) 955 throw ParmError("FitsImg2DRd::Init: Fits file name error\n"); 956 957 int sta = 0; 958 959 // Get HDU 2D image 960 // si IHdu <=0 || >NHdu on cherche la 1ere image 961 // sinon on se positionne sur IHdu 962 if(IHdu<=0 || IHdu>NHdu) 963 for(int ihdu=1;ihdu<=NHdu;ihdu++) { 964 if(fits_movabs_hdu(FitsPtr,ihdu,&HduType,&sta)) FitsOpenFile::printerror(sta); 965 if(DbgLevel>1) 966 cout<<"...Init ihdu="<<ihdu<<" HduType="<<HduType<<endl; 967 if(HduType==IMAGE_HDU) {IHdu = ihdu; break;} 968 } 969 if(IHdu<=0 || IHdu>NHdu) { 970 cout<<"NO IMAGE_HDU hdu found"<<endl; 971 IHdu = 0; 972 throw TypeMismatchExc("FitsImg2DRd::Init: NO IMAGE_HDU hdu found\n"); 973 } 974 if(fits_movabs_hdu(FitsPtr,IHdu,&HduType,&sta)) { 975 FitsOpenFile::printerror(sta); 976 throw RangeCheckError("FitsImg2DRd::Init: Error moving to requested HDU\n"); 977 } 978 if(HduType!=IMAGE_HDU) 979 throw TypeMismatchExc("FitsImg2DRd::Init: HDU not IMAGE_HDU\n"); 980 981 // Get NAXIS 1 et 2 982 int nfound=0; 983 if(fits_read_keys_lng(FitsPtr,"NAXIS",1,2,Naxis,&nfound,&sta)) { 984 FitsOpenFile::printerror(sta); 985 throw RangeCheckError("FitsImg2DRd::Init: Error reading NAXIS cards\n"); 986 } 987 if(DbgLevel>1) 988 cout<<"...Init(hdu="<<IHdu<<") NAXIS1="<<Naxis[0]<<" NAXIS2="<<Naxis[1]<<" (nfound="<<nfound<<")"<<endl; 989 if(nfound!=2 || Naxis[0]<=0 || Naxis[1]<=0) 990 throw NotAvailableOperation("FitsImg2DRd::Init: bad Naxis[0-1] value\n"); 991 992 } 993 994 /*! Destructor. */ 995 FitsImg2DRd::~FitsImg2DRd() 996 { 997 //--- Surtout on ne "fits_close_file" pas le fichier FITS !!! 998 Naxis[0] = Naxis[1] = 0; 999 } 1000 1001 ////////////////////////////////////////////////////////////// 1002 /*! 1003 Read a fitsheader key into double 1004 \param keyname : name of the key 1005 \return value into double 1006 */ 1007 double FitsImg2DRd::ReadKey(char *keyname) 1008 { 1009 return FitsOpenFile::ReadKey(FitsPtr,keyname); 1010 } 1011 1012 /*! 1013 Read a fitsheader key into long 1014 \param keyname : name of the key 1015 \return value into long 1016 */ 1017 long FitsImg2DRd::ReadKeyL(char *keyname) 1018 { 1019 return FitsOpenFile::ReadKeyL(FitsPtr,keyname); 1020 } 1021 1022 /*! 1023 Read a fitsheader key into string 1024 \param keyname : name of the key 1025 \return value into string 1026 */ 1027 string FitsImg2DRd::ReadKeyS(char *keyname) 1028 { 1029 return FitsOpenFile::ReadKeyS(FitsPtr,keyname); 1030 } 1031 1032 ////////////////////////////////////////////////////////////// 1033 /* REMARQUE: 1034 * Si une image FITS a NAXIS1=100 et NAXIS2=50 1035 * alors un tableau 2D juste assez grand pour contenir l'image 1036 * doit etre declare array[50][100] (et non pas array[100][50]) 1037 * array[NAXIS2][NAXIS1] 1038 */ 1039 /*! 1040 Read image into a TMatrix<uint_2> 1041 \warning TMatrix data(Naxis2,Naxis1) 1042 */ 1043 long FitsImg2DRd::Read(TMatrix<uint_2>& data) 1044 { 1045 int sta=0; 1046 uint_2* arr = new uint_2[Naxis[0]]; 1047 data.ReSize(Naxis[1],Naxis[0]); 1048 1049 for(int j=0;j<Naxis[1];j++) { 1050 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1051 fits_read_img(FitsPtr,TUSHORT,deb,nel,&NulVal,arr,NULL,&sta); 1052 if(sta) { 1053 FitsOpenFile::printerror(sta); delete [] arr; 1054 throw 1055 NotAvailableOperation("FitsImg2DRd::Read(TMatrix<uint_2>): Error Reading Fits file\n"); 1056 } 1057 for(int i=0;i<Naxis[0];i++) data(j,i) = arr[i]; 1058 } 1059 1060 delete [] arr; 1061 return Naxis[0]*Naxis[1]; 1062 } 1063 1064 /*! Read image into a TMatrix<int_4> */ 1065 long FitsImg2DRd::Read(TMatrix<int_4>& data) 1066 { 1067 int sta=0; 1068 int_4* arr = new int_4[Naxis[0]]; 1069 data.ReSize(Naxis[1],Naxis[0]); 1070 int T = (sizeof(long)==4) ? TLONG: TINT; 1071 1072 for(int j=0;j<Naxis[1];j++) { 1073 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1074 fits_read_img(FitsPtr,T,deb,nel,&NulVal,arr,NULL,&sta); 1075 if(sta) { 1076 FitsOpenFile::printerror(sta); delete [] arr; 1077 throw 1078 NotAvailableOperation("FitsImg2DRd::Read(TMatrix<int_4>): Error Reading Fits file\n"); 1079 } 1080 for(int i=0;i<Naxis[0];i++) data(j,i) = arr[i]; 1081 } 1082 1083 delete [] arr; 1084 return Naxis[0]*Naxis[1]; 1085 } 1086 1087 /*! Read image into a TMatrix<int_8> */ 1088 long FitsImg2DRd::Read(TMatrix<int_8>& data) 1089 { 1090 int sta=0; 1091 int_8* arr = new int_8[Naxis[0]]; 1092 data.ReSize(Naxis[1],Naxis[0]); 1093 1094 for(int j=0;j<Naxis[1];j++) { 1095 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1096 fits_read_img(FitsPtr,TLONGLONG,deb,nel,&NulVal,arr,NULL,&sta); 1097 if(sta) { 1098 FitsOpenFile::printerror(sta); delete [] arr; 1099 throw 1100 NotAvailableOperation("FitsImg2DRd::Read(TMatrix<int_8>): Error Reading Fits file\n"); 1101 } 1102 for(int i=0;i<Naxis[0];i++) data(j,i) = arr[i]; 1103 } 1104 1105 delete [] arr; 1106 return Naxis[0]*Naxis[1]; 1107 } 1108 1109 /*! Read image into a TMatrix<float> */ 1110 long FitsImg2DRd::Read(TMatrix<float>& data) 1111 { 1112 int sta=0; 1113 float* arr = new float[Naxis[0]]; 1114 data.ReSize(Naxis[1],Naxis[0]); 1115 1116 for(int j=0;j<Naxis[1];j++) { 1117 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1118 fits_read_img(FitsPtr,TFLOAT,deb,nel,&NulVal,arr,NULL,&sta); 1119 if(sta) { 1120 FitsOpenFile::printerror(sta); delete [] arr; 1121 throw 1122 NotAvailableOperation("FitsImg2DRd::Read(TMatrix<float>): Error Reading Fits file\n"); 1123 } 1124 for(int i=0;i<Naxis[0];i++) data(j,i) = arr[i]; 1125 } 1126 1127 delete [] arr; 1128 return Naxis[0]*Naxis[1]; 1129 } 1130 1131 /*! Read image into a TMatrix<double> */ 1132 long FitsImg2DRd::Read(TMatrix<double>& data) 1133 { 1134 int sta=0; 1135 double* arr = new double[Naxis[0]]; 1136 data.ReSize(Naxis[1],Naxis[0]); 1137 1138 for(int j=0;j<Naxis[1];j++) { 1139 long deb = j*Naxis[0]+1, nel = Naxis[0]; 1140 fits_read_img(FitsPtr,TDOUBLE,deb,nel,&NulVal,arr,NULL,&sta); 1141 if(sta) { 1142 FitsOpenFile::printerror(sta); delete [] arr; 1143 throw 1144 NotAvailableOperation("FitsImg2DRd::Read(TMatrix<double>): Error Reading Fits file\n"); 1145 } 1146 for(int i=0;i<Naxis[0];i++) data(j,i) = arr[i]; 1147 } 1148 1149 delete [] arr; 1150 return Naxis[0]*Naxis[1]; 1151 } -
trunk/SophyaExt/FitsIOServer/fabtcolread.h
r2451 r2453 28 28 inline fitsfile* GetFitsPtr() {return FitsPtr;} 29 29 30 static double ReadKey(fitsfile *fitsptr,char *keyname); 31 static long ReadKeyL(fitsfile *fitsptr,char *keyname); 32 static string ReadKeyS(fitsfile *fitsptr,char *keyname); 33 static void printerror(int sta); 34 30 35 protected: 31 36 void Init(const char *cfname); 32 37 void Delete(void); 33 void printerror(int sta) const;34 38 35 39 string FitsFN; … … 121 125 ,int ihdu,long blen,long bsens,int lp); 122 126 void Delete(void); 123 void printerror(int sta) const;124 127 125 128 string FitsFN,ColLabel,ColTUnit,ColTForm; … … 158 161 } // namespace SOPHYA 159 162 #endif /* FABTCOLREAD_H_SEEN */ 163 164 /////////////////////////////////////////////////////////////////// 165 //! Class for reading a 2D image from a FITS file 166 class FitsImg2DRd : public AnyDataObj { 167 public: 168 FitsImg2DRd(FitsOpenFile* fof,int ihdu=0,int lp=0); 169 FitsImg2DRd(FitsImg2DRd& fbt); 170 FitsImg2DRd(); 171 virtual ~FitsImg2DRd(); 172 173 double ReadKey(char *keyname); 174 long ReadKeyL(char *keyname); 175 string ReadKeyS(char *keyname); 176 177 long Read(TMatrix<uint_2>& data); 178 long Read(TMatrix<int_4>& data); 179 long Read(TMatrix<int_8>& data); 180 long Read(TMatrix<float>& data); 181 long Read(TMatrix<double>& data); 182 183 //! Set debug level 184 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} 185 //! Set null value to be return when reading null data (0=return the data) 186 inline void SetNulVal(double nulval=0.) {NulVal = nulval;} 187 //! Get the pointer to FitsOpenFile 188 inline FitsOpenFile* GetFitsOpenFile(void) {return FitsOF;} 189 //! Get the number of the HDU read 190 inline int GetHDU(void) {return IHdu;} 191 //! Get the HDU type 192 inline int GetHDUType(void) {return HduType;} 193 //! Get NAXIS1 194 inline long GetNaxis1(void) {return Naxis[0];} 195 //! Get NAXIS2 196 inline long GetNaxis2(void) {return Naxis[1];} 197 198 protected: 199 void Init(FitsOpenFile* fof,int ihdu,int lp); 200 201 string FitsFN; 202 int IHdu,NHdu,HduType; 203 long Naxis[2]; 204 205 double NulVal; 206 unsigned short DbgLevel; 207 208 FitsOpenFile* FitsOF; 209 fitsfile* FitsPtr; 210 }; -
trunk/SophyaExt/FitsIOServer/fabtwriter.cc
r2450 r2453 6 6 #include "fabtwriter.h" 7 7 8 ////////////////////////////////////////////////////////////// 9 ////////////////////////////////////////////////////////////// 10 ////////////////////////////////////////////////////////////// 11 ////////////////////////////////////////////////////////////// 12 /*! 13 \class SOPHYA::FitsWriter 14 \ingroup FitsIOServer 15 Class for writing into a FITS file (DO NOT USE) 16 */ 17 18 /*! Constructor (DO NOT USE). */ 19 FitsWriter::FitsWriter(string fname,int lp) 20 { 21 cr_or_upd_fits(fname.c_str(),false,lp); 22 } 23 24 /*! Constructor (DO NOT USE). */ 25 FitsWriter::FitsWriter(const char* cfname,int lp) 26 { 27 cr_or_upd_fits(cfname,false,lp); 28 } 29 30 /*! Constructor (DO NOT USE). */ 31 FitsWriter::FitsWriter(string fname,bool update,int lp) 32 { 33 cr_or_upd_fits(fname.c_str(),update,lp); 34 } 35 36 /*! Constructor (DO NOT USE). */ 37 FitsWriter::FitsWriter(const char* cfname,bool update,int lp) 38 { 39 cr_or_upd_fits(cfname,update,lp); 40 } 41 42 /*! See FitsWriter() */ 43 void FitsWriter::cr_or_upd_fits(const char *cfname,bool update,int lp) 44 { 45 FitsPtr = NULL; 46 HduType = 0; 47 SetDebug(lp); 48 FitsFN = cfname; 49 NOverFlow = 0; 50 Update = update; 51 // Init key structure 52 DoubleKey.resize(0); 53 LongKey.resize(0); 54 StringKey.resize(0); 55 56 if(DbgLevel) 57 cout<<"FitsWriter::cr_or_upd_fits FitsFN="<<FitsFN<<endl; 58 59 if(FitsFN.size() <= 0 ) 60 throw ParmError("FitsWriter::cr_or_upd_fits: Fits file name error\n"); 61 62 // create or update FITS file 63 int sta=0; 64 if(Update) { 65 if(fits_open_file(&FitsPtr,FitsFN.c_str(),READWRITE,&sta)) { 66 printerror(sta); 67 throw NullPtrError("FitsWriter::cr_or_upd_fits: Error opening Fits file for update\n"); 68 } 69 if(DbgLevel) cout<<"FitsWriter::cr_or_upd_fits: fits file has been opened for update"<<endl; 70 } else { 71 if(fits_create_file(&FitsPtr,FitsFN.c_str(),&sta)) { 72 printerror(sta); 73 throw NullPtrError("FitsWriter::cr_or_upd_fits: Error creating new Fits file\n"); 74 } 75 if(DbgLevel) cout<<"FitsWriter::cr_or_upd_fits: a new fits file has been created"<<endl; 76 } 77 78 // create d'un Primary HDU 79 //long naxes[1] = {0}; 80 //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) { 81 // printerror(sta); 82 // throw NullPtrError("FitsWriter::cr_or_upd_fits: Error creating Primary extension\n"); 83 //} 84 } 85 86 /*! Destructor */ 87 FitsWriter::~FitsWriter() 88 { 89 int sta = 0; 90 writekeys(); 91 if(fits_close_file(FitsPtr,&sta)) printerror(sta); 92 FitsPtr = NULL; 93 } 94 95 /*! Flush the FitsIO buffer to set good Fits file in case of problems */ 96 void FitsWriter::Flush(void) 97 { 98 if(FitsPtr==NULL) return; 99 int sta = 0; 100 if(fits_flush_file(FitsPtr,&sta)) printerror(sta); 101 } 102 103 104 /*! Write a double value into Fits Header */ 105 void FitsWriter::WriteKey(const char *keyname,double val,char* comment) 106 { 107 if(keyname==NULL || strlen(keyname)<=0) return; 108 KeyDouble k; 109 k.keyname=keyname; 110 k.val=val; 111 if(comment) k.comment=comment; else k.comment=""; 112 DoubleKey.push_back(k); 113 } 114 115 /*! Write a long value into Fits Header */ 116 void FitsWriter::WriteKey(const char *keyname,long val,char* comment) 117 { 118 if(keyname==NULL || strlen(keyname)<=0) return; 119 KeyLong k; 120 k.keyname=keyname; 121 k.val=val; 122 if(comment) k.comment=comment; else k.comment=""; 123 LongKey.push_back(k); 124 } 125 126 /*! Write a string value into Fits Header */ 127 void FitsWriter::WriteKey(const char *keyname,string val,char* comment) 128 { 129 if(keyname==NULL || strlen(keyname)<=0) return; 130 KeyString k; 131 k.keyname=keyname; 132 k.val=val; 133 if(comment) k.comment=comment; else k.comment=""; 134 StringKey.push_back(k); 135 } 136 137 void FitsWriter::writekeys(void) 138 // Ecriture effective des clefs 139 { 140 if(FitsPtr==NULL) return; 141 int sta=0; 142 if(DoubleKey.size()>0) 143 for(unsigned int i=0;i<DoubleKey.size();i++) { 144 char* key = const_cast<char*>(DoubleKey[i].keyname.c_str()); 145 char* com = const_cast<char*>(DoubleKey[i].comment.c_str()); 146 double val = DoubleKey[i].val; 147 if(fits_update_key(FitsPtr,TDOUBLE,key,&val,com,&sta)) 148 printerror(sta); 149 } 150 if(LongKey.size()>0) 151 for(unsigned int i=0;i<LongKey.size();i++) { 152 char* key = const_cast<char*>(LongKey[i].keyname.c_str()); 153 char* com = const_cast<char*>(LongKey[i].comment.c_str()); 154 long val = LongKey[i].val; 155 if(fits_update_key(FitsPtr,TLONG,key,&val,com,&sta)) 156 printerror(sta); 157 } 158 if(StringKey.size()>0) 159 for(unsigned int i=0;i<StringKey.size();i++) { 160 char* key = const_cast<char*>(StringKey[i].keyname.c_str()); 161 char* com = const_cast<char*>(StringKey[i].comment.c_str()); 162 char* val = const_cast<char*>(StringKey[i].val.c_str()); 163 if(fits_update_key(FitsPtr,TSTRING,key,val,com,&sta)) 164 printerror(sta); 165 } 166 DoubleKey.resize(0); 167 LongKey.resize(0); 168 StringKey.resize(0); 169 } 170 171 void FitsWriter::printerrorwrite(const char* type,int col,long row,int sta) 172 { 173 if(sta==NUM_OVERFLOW) {NOverFlow++; return;} 174 printerror(sta); 175 char str[256]; 176 sprintf(str,"FitsWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d" 177 ,type,col,row,sta); 178 throw NotAvailableOperation(str); 179 } 180 181 void FitsWriter::printerror(int sta) const 182 { 183 int stat = sta; 184 fits_report_error(stdout,stat); 185 fflush(stdout); 186 return; 187 } 188 189 ////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////// 191 ////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////// 8 193 /*! 9 194 \class SOPHYA::FitsABTWriter … … 117 302 */ 118 303 FitsABTWriter::FitsABTWriter(string fname,int hdutype,int lp) 119 { 120 cr_or_upd_fits(fname.c_str(),false,hdutype,lp); 304 : FitsWriter(fname,lp) 305 { 306 FirstTime = true; 307 HduType = hdutype; 308 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) 309 throw 310 TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n"); 121 311 } 122 312 … … 128 318 */ 129 319 FitsABTWriter::FitsABTWriter(const char* cfname,int hdutype,int lp) 130 { 131 cr_or_upd_fits(cfname,false,hdutype,lp); 320 : FitsWriter(cfname,lp) 321 { 322 FirstTime = true; 323 HduType = hdutype; 324 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) 325 throw 326 TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n"); 132 327 } 133 328 … … 140 335 */ 141 336 FitsABTWriter::FitsABTWriter(string fname,bool update,int hdutype,int lp) 142 { 143 cr_or_upd_fits(fname.c_str(),update,hdutype,lp); 337 : FitsWriter(fname,update,lp) 338 { 339 FirstTime = true; 340 HduType = hdutype; 341 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) 342 throw 343 TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n"); 144 344 } 145 345 … … 152 352 */ 153 353 FitsABTWriter::FitsABTWriter(const char* cfname,bool update,int hdutype,int lp) 154 { 155 cr_or_upd_fits(cfname,update,hdutype,lp); 156 } 157 158 /*! See FitsABTWriter() */ 159 void FitsABTWriter::cr_or_upd_fits(const char *cfname,bool update,int hdutype,int lp) 354 : FitsWriter(cfname,update,lp) 160 355 { 161 356 FirstTime = true; 162 FitsPtr = NULL;163 357 HduType = hdutype; 164 SetDebug(lp);165 FitsFN = cfname;166 NOverFlow = 0;167 Update = update;168 169 if(DbgLevel)170 cout<<"FitsABTWriter::cr_or_upd_fits FitsFN="<<FitsFN171 <<" HduType="<<HduType<<endl;172 173 if(FitsFN.size() <= 0 )174 throw ParmError("FitsABTWriter::cr_or_upd_fits: Fits file name error\n");175 176 358 if(HduType!=BINARY_TBL && HduType!=ASCII_TBL) 177 throw TypeMismatchExc("FitsABTWriter::cr_or_upd_fits: Only BINARY or ASCII table permitted\n"); 178 179 // create or update FITS file 180 int sta=0; 181 if(Update) { 182 if(fits_open_file(&FitsPtr,FitsFN.c_str(),READWRITE,&sta)) { 183 printerror(sta); 184 throw NullPtrError("FitsABTWriter::cr_or_upd_fits: Error opening Fits file for update\n"); 185 } 186 if(DbgLevel) cout<<"FitsABTWriter::cr_or_upd_fits: fits file has been opened for update"<<endl; 187 } else { 188 if(fits_create_file(&FitsPtr,FitsFN.c_str(),&sta)) { 189 printerror(sta); 190 throw NullPtrError("FitsABTWriter::cr_or_upd_fits: Error creating new Fits file\n"); 191 } 192 if(DbgLevel) cout<<"FitsABTWriter::cr_or_upd_fits: a new fits file has been created"<<endl; 193 } 194 195 // create d'un Primary HDU 196 //long naxes[1] = {0}; 197 //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) { 198 // printerror(sta); 199 // throw NullPtrError("FitsABTWriter::cr_or_upd_fits: Error creating Primary extension\n"); 200 //} 201 359 throw 360 TypeMismatchExc("FitsABTWriter::FitsABTWriter: Only BINARY or ASCII table permitted\n"); 202 361 } 203 362 … … 205 364 FitsABTWriter::~FitsABTWriter() 206 365 { 207 int sta = 0;208 writekeys();209 if(fits_close_file(FitsPtr,&sta)) printerror(sta);210 FitsPtr = NULL;211 }212 213 /*! Flush the FitsIO buffer to set good Fits file in case of problems */214 void FitsABTWriter::Flush(void)215 {216 if(FitsPtr==NULL) return;217 int sta = 0;218 if(fits_flush_file(FitsPtr,&sta)) printerror(sta);219 }220 221 /*! Write a double value into Fits Header */222 void FitsABTWriter::WriteKey(const char *keyname,double val,char* comment)223 {224 if(keyname==NULL || strlen(keyname)<=0) return;225 KeyDouble k;226 k.keyname=keyname;227 k.val=val;228 if(comment) k.comment=comment; else k.comment="";229 DoubleKey.push_back(k);230 }231 232 /*! Write a long value into Fits Header */233 void FitsABTWriter::WriteKey(const char *keyname,long val,char* comment)234 {235 if(keyname==NULL || strlen(keyname)<=0) return;236 KeyLong k;237 k.keyname=keyname;238 k.val=val;239 if(comment) k.comment=comment; else k.comment="";240 LongKey.push_back(k);241 }242 243 /*! Write a string value into Fits Header */244 void FitsABTWriter::WriteKey(const char *keyname,string val,char* comment)245 {246 if(keyname==NULL || strlen(keyname)<=0) return;247 KeyString k;248 k.keyname=keyname;249 k.val=val;250 if(comment) k.comment=comment; else k.comment="";251 StringKey.push_back(k);252 }253 254 void FitsABTWriter::writekeys(void)255 // Ecriture effective des clefs256 {257 if(FitsPtr==NULL) return;258 int sta=0;259 if(DoubleKey.size()>0)260 for(unsigned int i=0;i<DoubleKey.size();i++) {261 char* key = const_cast<char*>(DoubleKey[i].keyname.c_str());262 char* com = const_cast<char*>(DoubleKey[i].comment.c_str());263 double val = DoubleKey[i].val;264 if(fits_update_key(FitsPtr,TDOUBLE,key,&val,com,&sta))265 printerror(sta);266 }267 if(LongKey.size()>0)268 for(unsigned int i=0;i<LongKey.size();i++) {269 char* key = const_cast<char*>(LongKey[i].keyname.c_str());270 char* com = const_cast<char*>(LongKey[i].comment.c_str());271 long val = LongKey[i].val;272 if(fits_update_key(FitsPtr,TLONG,key,&val,com,&sta))273 printerror(sta);274 }275 if(StringKey.size()>0)276 for(unsigned int i=0;i<StringKey.size();i++) {277 char* key = const_cast<char*>(StringKey[i].keyname.c_str());278 char* com = const_cast<char*>(StringKey[i].comment.c_str());279 char* val = const_cast<char*>(StringKey[i].val.c_str());280 if(fits_update_key(FitsPtr,TSTRING,key,val,com,&sta))281 printerror(sta);282 }283 DoubleKey.resize(0);284 LongKey.resize(0);285 StringKey.resize(0);286 366 } 287 367 … … 303 383 ,const char* tunit,int datatype) 304 384 { 305 306 385 if(!FirstTime) 386 throw AllocationError("FitsABTWriter::addcol: table already created\n"); 307 387 308 388 // Gestion auto du tform pour les tables binaires avec le datatype (si non-definie) … … 402 482 } 403 483 404 // Append Fits key405 writekeys();406 407 484 // menage 408 485 if(extname) delete [] extname; … … 591 668 } 592 669 593 //////////////////////////////////////////////////////////////594 void FitsABTWriter::printerrorwrite(const char* type,int col,long row,int sta)595 {596 if(sta==NUM_OVERFLOW) {NOverFlow++; return;}597 printerror(sta);598 char str[256];599 sprintf(str,"FitsABTWriter::Write_%s: Error Writing Fits c=%d r=%ld sta=%d"600 ,type,col,row,sta);601 throw NotAvailableOperation(str);602 }603 604 /////////////////////////////////////////////////605 void FitsABTWriter::printerror(int sta) const606 {607 int stat = sta;608 fits_report_error(stdout,stat);609 fflush(stdout);610 return;611 }612 613 670 ///////////////////////////////////////////////// 614 671 void FitsABTWriter::Print(ostream& os,int lp) const … … 621 678 os<<i<<"... Label="<<Label[i]<<" TForm="<<TForm[i]<<" TUnit="<<TUnit[i]<<endl; 622 679 } 680 681 ////////////////////////////////////////////////////////////////// 682 ////////////////////////////////////////////////////////////////// 683 ////////////////////////////////////////////////////////////////// 684 ////////////////////////////////////////////////////////////////// 685 /*! 686 \class SOPHYA::FitsImg2DWriter 687 \ingroup FitsIOServer 688 Class for writing an image into FITS file 689 */ 690 691 /*! 692 Constructor. 693 \param fname : FITS file name to be written (a new fits file is created) 694 \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG) 695 \param lp : debug level 696 */ 697 FitsImg2DWriter::FitsImg2DWriter(string fname,int bitpix,int lp) 698 : FitsWriter(fname,lp) 699 { 700 BitPix = bitpix; 701 HduType = IMAGE_HDU; 702 FirstTime = true; 703 Naxis[0] = Naxis[1] = 0; 704 } 705 706 /*! 707 Constructor. 708 \param cfname : FITS file name to be written (a new fits file is created) 709 \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG) 710 \param lp : debug level 711 */ 712 FitsImg2DWriter::FitsImg2DWriter(const char* cfname,int bitpix,int lp) 713 : FitsWriter(cfname,lp) 714 { 715 BitPix = bitpix; 716 HduType = IMAGE_HDU; 717 FirstTime = true; 718 Naxis[0] = Naxis[1] = 0; 719 } 720 721 /*! 722 Constructor. 723 \param fname : FITS file name to be written (created or updated) 724 \param update : file is created if FALSE, open for update if TRUE 725 \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG) 726 \param lp : debug level 727 */ 728 FitsImg2DWriter::FitsImg2DWriter(string fname,bool update,int bitpix,int lp) 729 : FitsWriter(fname,update,lp) 730 { 731 BitPix = bitpix; 732 HduType = IMAGE_HDU; 733 FirstTime = true; 734 Naxis[0] = Naxis[1] = 0; 735 } 736 737 /*! 738 Constructor. 739 \param cfname : FITS file name to be written (created or updated) 740 \param update : file is created if FALSE, open for update if TRUE 741 \param bitpix : image type (BYTE_IMG,USHORT_IMG,SHORT_IMG,LONG_IMG,FLOAT_IMG,DOUBLE_IMG) 742 \param lp : debug level 743 */ 744 FitsImg2DWriter::FitsImg2DWriter(const char* cfname,bool update,int bitpix,int lp) 745 : FitsWriter(cfname,update,lp) 746 { 747 BitPix = bitpix; 748 HduType = IMAGE_HDU; 749 FirstTime = true; 750 Naxis[0] = Naxis[1] = 0; 751 } 752 753 /*! Destructor */ 754 FitsImg2DWriter::~FitsImg2DWriter() 755 { 756 } 757 758 /*! Create the image. Done at the first write request. */ 759 void FitsImg2DWriter::createimg(void) 760 { 761 if(!FirstTime) 762 throw NotAvailableOperation("FitsImg2DWriter::createimg: already created image\n"); 763 if(Naxis[0]<=0 || Naxis[1]<=0) 764 throw ParmError("FitsImg2DWriter::createimg: bad Naxis 1 or 2 value\n"); 765 766 int sta=0; 767 if(fits_create_img(FitsPtr,BitPix,2,Naxis,&sta)) { 768 printerror(sta); 769 throw NullPtrError("FitsImg2DWriter::createimg: Error creating image extension\n"); 770 } 771 772 FirstTime = false; 773 } 774 775 /*! 776 Write an image to FITS file. 777 \warning TMatrix data(Naxis2,Naxis1) 778 */ 779 void FitsImg2DWriter::Write(TMatrix<uint_2>& data) 780 { 781 Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg(); 782 uint_2* arr = new uint_2[Naxis[0]]; 783 784 for(int j=0;j<Naxis[1];j++) { 785 for(int i=0;i<Naxis[0];i++) arr[i] = data(j,i); 786 long deb = j*Naxis[0]+1, nel = Naxis[0]; int sta=0; 787 fits_write_img(FitsPtr,TUSHORT,deb,nel,arr,&sta); 788 if(sta) { 789 printerror(sta); delete [] arr; 790 throw 791 NotAvailableOperation("FitsImg2DRd::Write(TMatrix<uint_2>): Error Writing Fits file\n"); 792 } 793 } 794 795 delete [] arr; 796 } 797 798 /*! Write an image to FITS file. */ 799 void FitsImg2DWriter::Write(TMatrix<int_4>& data) 800 { 801 int T = (sizeof(long)==4) ? TLONG: TINT; 802 Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg(); 803 int_4* arr = new int_4[Naxis[0]]; 804 805 for(int j=0;j<Naxis[1];j++) { 806 for(int i=0;i<Naxis[0];i++) arr[i] = data(j,i); 807 long deb = j*Naxis[0]+1, nel = Naxis[0]; int sta=0; 808 fits_write_img(FitsPtr,T,deb,nel,arr,&sta); 809 if(sta) { 810 printerror(sta); delete [] arr; 811 throw 812 NotAvailableOperation("FitsImg2DRd::Write(TMatrix<int_4>): Error Writing Fits file\n"); 813 } 814 } 815 816 delete [] arr; 817 } 818 819 /*! Write an image to FITS file. */ 820 void FitsImg2DWriter::Write(TMatrix<float>& data) 821 { 822 Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg(); 823 float* arr = new float[Naxis[0]]; 824 825 for(int j=0;j<Naxis[1];j++) { 826 for(int i=0;i<Naxis[0];i++) arr[i] = data(j,i); 827 long deb = j*Naxis[0]+1, nel = Naxis[0]; int sta=0; 828 fits_write_img(FitsPtr,TFLOAT,deb,nel,arr,&sta); 829 if(sta) { 830 printerror(sta); delete [] arr; 831 throw 832 NotAvailableOperation("FitsImg2DRd::Write(TMatrix<float>): Error Writing Fits file\n"); 833 } 834 } 835 836 delete [] arr; 837 } 838 839 /*! Write an image to FITS file. */ 840 void FitsImg2DWriter::Write(TMatrix<double>& data) 841 { 842 Naxis[0]=data.NCols(); Naxis[1]=data.NRows(); createimg(); 843 double* arr = new double[Naxis[0]]; 844 845 for(int j=0;j<Naxis[1];j++) { 846 for(int i=0;i<Naxis[0];i++) arr[i] = data(j,i); 847 long deb = j*Naxis[0]+1, nel = Naxis[0]; int sta=0; 848 fits_write_img(FitsPtr,TDOUBLE,deb,nel,arr,&sta); 849 if(sta) { 850 printerror(sta); delete [] arr; 851 throw 852 NotAvailableOperation("FitsImg2DRd::Write(TMatrix<double>): Error Writing Fits file\n"); 853 } 854 } 855 856 delete [] arr; 857 } 858 859 /*! Print infos. */ 860 void FitsImg2DWriter::Print(ostream& os) const 861 { 862 os<<"FitsImg2DWriter::Print: FitsFN "<<FitsFN<<endl 863 <<" HduType "<<HduType<<" NOverFlow "<<NOverFlow<<" BitPix "<<BitPix 864 <<" Naxis1 "<<Naxis[0]<<" Naxis2 "<<Naxis[1]<<endl; 865 } -
trunk/SophyaExt/FitsIOServer/fabtwriter.h
r2450 r2453 16 16 namespace SOPHYA { 17 17 18 //! Class for writing a FITS ASCII or BINARY table 19 class FitsABTWriter : public AnyDataObj { 18 /////////////////////////////////////////////////////////////////////////// 19 /////////////////////////////////////////////////////////////////////////// 20 //! Class for writing into a FITS file (DO NOT USE) 21 class FitsWriter : public AnyDataObj { 22 protected: 23 FitsWriter(string fname,int lp=0); 24 FitsWriter(const char* cfname,int lp=0); 25 FitsWriter(string fname,bool update,int lp=0); 26 FitsWriter(const char* cfname,bool update,int lp=0); 27 virtual ~FitsWriter(); 28 20 29 public: 21 FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0);22 FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0);23 FitsABTWriter(string fname,bool update,int hdutype=BINARY_TBL,int lp=0);24 FitsABTWriter(const char* cfname,bool update,int hdutype=BINARY_TBL,int lp=0);25 virtual ~FitsABTWriter();26 27 30 void Flush(void); 28 31 … … 36 39 inline void WriteKey(const char *keyname,char* val,char* comment=NULL) 37 40 {string dum=val; WriteKey(keyname,dum,comment);} 41 //! Set debug level 42 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} 43 44 //! Return the number of overflows managed by cfitsio 45 inline unsigned long GetNOverFlow(void) {return NOverFlow;} 46 47 protected: 48 struct KeyDouble {string keyname; double val; string comment;}; 49 struct KeyLong {string keyname; long val; string comment;}; 50 struct KeyString {string keyname; string val; string comment;}; 51 52 void cr_or_upd_fits(const char *cfname,bool update,int lp); 53 54 void writekeys(void); 55 void printerrorwrite(const char* type,int col,long row,int sta); 56 void printerror(int sta) const; 57 58 string FitsFN,ExtName; 59 bool Update; 60 int HduType; 61 unsigned short DbgLevel; 62 fitsfile *FitsPtr; 63 unsigned long NOverFlow; 64 65 vector<struct KeyDouble> DoubleKey; 66 vector<struct KeyLong> LongKey; 67 vector<struct KeyString> StringKey; 68 }; 69 70 /////////////////////////////////////////////////////////////////////////// 71 /////////////////////////////////////////////////////////////////////////// 72 //! Class for writing a FITS ASCII or BINARY table 73 class FitsABTWriter : public FitsWriter { 74 public: 75 FitsABTWriter(string fname,int hdutype=BINARY_TBL,int lp=0); 76 FitsABTWriter(const char* cfname,int hdutype=BINARY_TBL,int lp=0); 77 FitsABTWriter(string fname,bool update,int hdutype=BINARY_TBL,int lp=0); 78 FitsABTWriter(const char* cfname,bool update,int hdutype=BINARY_TBL,int lp=0); 79 virtual ~FitsABTWriter(); 80 81 //! Set the FITS table extension name 82 inline void SetExtName(string extname=string("")) {ExtName = extname;} 83 //! Set the FITS table extension name 84 inline void SetExtName(char* extname="") {ExtName = extname;} 38 85 39 86 //! Add a new column to the FITS table and return its number (see addcol). … … 45 92 ,const char* tunit="",int datatype=TDOUBLE) 46 93 {return addcol(label,tform,tunit,datatype);} 47 48 //! Set the FITS table extension name49 inline void SetExtName(string extname=string("")) {ExtName = extname;}50 //! Set the FITS table extension name51 inline void SetExtName(char* extname="") {ExtName = extname;}52 //! Set debug level53 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;}54 94 55 95 void Write(int col,long row,uint_1 val); … … 66 106 long Write(int col,long row,TVector<float>& val); 67 107 long Write(int col,long row,TVector<double>& val); 68 //! Return the number of overflows managed by cfitsio69 inline unsigned long GetNOverFlow(void) {return NOverFlow;}70 108 71 109 //! Return the number of created columns … … 78 116 79 117 protected: 80 struct KeyDouble {string keyname; double val; string comment;}; 81 struct KeyLong {string keyname; long val; string comment;}; 82 struct KeyString {string keyname; string val; string comment;}; 118 int addcol(const char* label,const char* tform,const char* tunit,int datatype); 119 void createtbl(void); 83 120 84 void cr_or_upd_fits(const char *cfname,bool update,int hdutype,int lp);85 int addcol(const char* label,const char* tform86 ,const char* tunit,int datatype);87 void createtbl(void);88 void writekeys(void);89 void printerrorwrite(const char* type,int col,long row,int sta);90 void printerror(int sta) const;91 92 string FitsFN,ExtName;93 bool Update;94 int HduType;95 unsigned short DbgLevel;96 fitsfile *FitsPtr;97 121 bool FirstTime; 98 122 vector<string> Label; 99 123 vector<string> TForm; 100 124 vector<string> TUnit; 101 unsigned long NOverFlow;125 }; 102 126 103 vector<struct KeyDouble> DoubleKey; 104 vector<struct KeyLong> LongKey; 105 vector<struct KeyString> StringKey; 127 /////////////////////////////////////////////////////////////////////////// 128 /////////////////////////////////////////////////////////////////////////// 129 //! Class for writing a FITS Image 130 class FitsImg2DWriter : public FitsWriter { 131 public: 132 FitsImg2DWriter(string fname,int bitpix=FLOAT_IMG,int lp=0); 133 FitsImg2DWriter(const char* cfname,int bitpix=FLOAT_IMG,int lp=0); 134 FitsImg2DWriter(string fname,bool update,int bitpix=FLOAT_IMG,int lp=0); 135 FitsImg2DWriter(const char* cfname,bool update,int bitpix=FLOAT_IMG,int lp=0); 136 virtual ~FitsImg2DWriter(); 137 138 void Write(TMatrix<uint_2>& data); 139 void Write(TMatrix<int_4>& data); 140 void Write(TMatrix<float>& data); 141 void Write(TMatrix<double>& data); 142 143 //! Print to os 144 virtual void Print(ostream& os) const; 145 //! Print to stdout 146 inline void Print(void) const {Print(cout);} 147 148 protected: 149 void createimg(void); 150 151 int BitPix; 152 long Naxis[2]; 153 bool FirstTime; 106 154 }; 107 155
Note:
See TracChangeset
for help on using the changeset viewer.