- Timestamp:
- Jun 15, 2000, 12:22:23 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1045 r1047 33 33 nrows_ = 0; 34 34 nbcols_ = 0; 35 fits_status_ = 0; 35 36 naxisn_.clear(); 36 37 repeat_.clear(); … … 125 126 { 126 127 ReadFInit(flnm, hdunum); 127 /* 128 // ReadFromFits(*this); 129 ReadFromFits(); 130 } 131 132 133 //FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum) 134 void FitsFile::ReadFInit(char flnm[],int hdunum) 135 { 128 136 InitNull(); 129 137 int status = 0; … … 163 171 moveToFollowingHeader(); 164 172 } 165 */ 166 ReadFromFits(*this); 167 } 168 169 170 FitsFile* FitsFile::ReadFInit(char flnm[],int hdunum) 171 { 172 InitNull(); 173 int status = 0; 174 // hdutype_= 0; 175 176 fits_open_file(&fptr_,flnm,READONLY,&status); 177 if( status ) printerror( status ); 178 // 179 if (hdunum <= 1) 180 { 181 hdunum_ = 1; 182 // presence of image ? 183 int naxis= 0; 184 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 185 if( status ) printerror( status ); 186 if (naxis > 0 ) // there is an image 187 { 188 hdutype_ = IMAGE_HDU; 189 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 190 nbData_ = 1; 191 int k; 192 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 193 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 194 } 195 else 196 { 197 throw PException(" first header : no image, probably error in hdunum"); 198 } 199 // 200 } 201 else 202 { 203 hdunum_ = hdunum-1; 204 int hdutype; 205 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 206 if( status ) printerror( status,":FitsFile::ReadF : erreur movabs"); 207 moveToFollowingHeader(); 208 } 209 return this; 210 } 211 212 void FitsFile::ReadFFromFits() 213 { 214 ReadFromFits(*this); 215 } 173 // return this; 174 } 175 216 176 void FitsFile::moveToFollowingHeader() 217 177 { … … 261 221 262 222 } 263 WriteToFits(*this); 223 // WriteToFits(*this); 224 WriteToFits(); 264 225 } 265 226 void FitsFile::GetSingleColumn(double* map, int nentries) const … … 636 597 637 598 638 void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) const599 void FitsFile::GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char ** cdata) 639 600 { 640 601 int status= 0; … … 656 617 case 'D' : 657 618 fits_read_col(fptr_,TDOUBLE,ncol+1,NoLine+1,1,1,&dnull,&ddata[dcount++],&anull,&status); 658 if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne double" );659 619 break; 660 620 case 'E' : 661 621 fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[fcount++],&anull,&status); 662 if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" );663 622 break; 664 623 case 'I' : 665 624 fits_read_col(fptr_,TINT,ncol+1,NoLine+1,1,1,&inull,&idata[icount++], 666 625 &anull,&status); 667 if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne tint" );668 626 break; 669 627 case 'S' : 670 628 fits_read_col(fptr_,TSTRING,ncol+1,NoLine+1,1,1,cnull,&cdata[ccount++],&anull,&status); 671 if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" );672 629 break; 673 630 } 674 } 675 } 676 677 void FitsFile::GetBinTabLine(int NoLine, float* fdata) const 631 if (status) 632 { 633 ResetStatus(status); 634 break; 635 } 636 // if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne char" ); 637 } 638 } 639 640 void FitsFile::GetBinTabLine(int NoLine, float* fdata) 678 641 { 679 642 int status= 0; … … 685 648 { 686 649 fits_read_col(fptr_,TFLOAT,ncol+1,NoLine+1,1,1,&fnull,&fdata[ncol],&anull,&status); 687 if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" ); 650 if (status) 651 { 652 ResetStatus(status); 653 break; 654 } 655 // if( status ) printerror( status,"GetBinTabLine : erreur lecture de colonne float" ); 688 656 } 689 657 } … … 1066 1034 1067 1035 1068 void FitsFile::readheader()1069 //*************************************/1070 //* Print out all the header keywords */1071 //*************************************/1072 {1073 // standard string lengths defined in fitsioc.h1074 char card[FLEN_CARD];1075 1076 int status = 0;1077 1078 // get the number of keywords1079 int nkeys, keypos;1080 if( fits_get_hdrpos(fptr_,&nkeys,&keypos,&status) )1081 printerror( status );1082 1083 cout << " Header listing for HDU : " << hdunum_ << endl;1084 int jj;1085 for(jj = 1; jj <= nkeys; jj++)1086 {1087 if( fits_read_record(fptr_,jj,card,&status) )1088 printerror( status );1089 1090 // print the keyword card1091 cout << card << endl;1092 }1093 cout << "END" << endl;1094 }1095 1036 1096 1037 … … 1143 1084 throw IOExc("FitsFile:: error FITSIO status"); 1144 1085 } 1086 1087 int FitsFile::statusF() const 1088 { 1089 return fits_status_; 1090 } 1091 void FitsFile::ResetStatus(int& status) 1092 { 1093 fits_status_ = status; 1094 status = 0; 1095 } 1096 1097 string FitsFile::getErrStatus(int status) 1098 { 1099 char text[31]; 1100 fits_get_errstatus(status, text); 1101 return string(text); 1102 } -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1045 r1047 48 48 static int NbBlocks(char flnm[]); 49 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 */ 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 */ 54 inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);} 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 FitsFile* ReadFInit(char flnm[],int hdunum=0); 68 void ReadFFromFits(); 50 51 protected: 69 52 70 53 /*! 71 54 this method is called from inherited objects : 72 55 56 moves to header 'hdunum' on file 'flnm' 57 58 gets parameters in header 59 60 calls the method 'ReadFromFits' from the inherited object 61 62 */ 63 void ReadF(char flnm[],int hdunum= 0); 64 // FitsFile* ReadFInit(char flnm[],int hdunum=0); 65 void ReadFInit(char flnm[],int hdunum=0); 66 67 /*! 68 this method is called from inherited objects : 69 73 70 opens a file 'flnm' 74 71 75 72 gets parameters in header 76 73 77 calls the method 'ReadFromFits' from the inherited delegatedobject74 calls the method 'ReadFromFits' from the inherited object 78 75 79 76 */ 80 void WriteF(char flnm[], bool OldFile=false); 81 82 83 /*! 84 fill the array 'map' with double data from the current extension on FITS file. 85 If the extension is BINTABLE, the first column is provided. 86 87 \param <nentries> number of data to be read 88 */ 89 void GetSingleColumn(double* map, int nentries) const; 90 91 /*! same as above with float data */ 92 void GetSingleColumn(float* map, int nentries) const; 93 94 /*! same as above with int data */ 95 void GetSingleColumn(int* map, int nentries) const; 77 void WriteF(char flnm[], bool OldFile=false); 78 // virtual void ReadFromFits(FitsFile& ff)=0; 79 80 81 82 virtual void ReadFromFits()=0; 83 virtual void WriteToFits()=0; 84 85 static string getErrStatus(int status); 86 87 88 ////////////////////////////////////////////////////////// 89 /////// methods for managing extensions //////////////// 90 ////////////////////////////////////////////////////////// 91 92 ////////////////////////////////////////////////////////// 93 // methods with general purpose 94 /////////////////////////////////////// 95 96 /*! return a reference on a DVList containing the keywords from FITS file 97 */ 98 inline const DVList& DVListFromFits() const { return dvl_;} 99 100 void moveToFollowingHeader(); 101 int statusF() const; 102 103 104 ///////////////////////////////////////////////////////////// 105 // methods for managing FITS IMAGE extension 106 /////////////////////////////////////////////////// 107 108 109 //read 110 //---- 111 112 /*! return true if the current header corresponds to a FITS image extension */ 113 inline bool IsFitsImage() const { return (hdutype_ == IMAGE_HDU);} 96 114 97 115 /*! number of dimensions of an image extension : NAXIS parameter (in FITS notations) 98 116 */ 99 117 inline int nbDimOfImage() const {return naxis_;} 100 118 /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc. 119 */ 120 inline const vector<int>& dimOfImageAxes() const { return naxisn_;} 101 121 /*! 102 122 total number of data in the current IMAGE extension … … 104 124 inline int nbOfImageData() const { return nbData_; } 105 125 106 /*! a reference on a vector containing sizes of the NAXIS dimensions : NAXIS1, NAXIS2, NAXIS3 wtc. 107 */ 108 inline const vector<int>& dimOfImageAxes() const { return naxisn_;} 109 126 127 //write 128 //----- 129 130 131 /*! create an IMAGE header on FITS file. 132 \param <type> type of data (see method ColTypeFromFits) 133 \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS 134 \param <naxisn> array containind sizes of the different dimensions 135 */ 136 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ; 137 138 /*! write double data from array 'map'on an IMAGE extension 139 \param <nbData> number of data to be written 140 141 */ 142 void putImageToFits( int nbData, double* map) const; 143 144 /*! same as previous method with float data */ 145 void putImageToFits(int nbData, float* map ) const; 146 147 /*! same as previous method with int data */ 148 void putImageToFits(int nbData, int* map) const; 149 150 151 152 ////////////////////////////////////////////////////////////////////////// 153 // methods for managing FITS BINARY TABLE or ASCII TABLE extension 154 //////////////////////////////////////////////////////////////////////// 155 156 157 158 // read 159 //----- 160 161 /*! return true if the current header corresponds to a FITS ASCII or BINTABLE extension */ 162 inline bool IsFitsTable() const {return (hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL);} 110 163 /*! return number of columns (return 1 if IMAGE) */ 111 164 int NbColsFromFits() const; 112 165 /*! number of data in the current IMAGE extension on FITS file, or number 166 of data of column number 'nocol' of the current BINTABLE extension 167 */ 168 int NentriesFromFits(int nocol) const; 113 169 /*! return a character denoting data type of column number 'nocol' in a BINTABLE : 114 170 … … 123 179 */ 124 180 char ColTypeFromFits(int nocol) const; 125 126 /*! number of data in the current IMAGE extension on FITS file, or number127 of data of column number 'nocol' of the current BINTABLE extension128 */129 int NentriesFromFits(int nocol) const;130 131 181 /*! name of the column number 'nocol' of the current BINTABLE extension 132 182 */ 133 183 string ColNameFromFits(int nocol) const; 134 184 135 136 185 /*! number of characters of each data for the column number 'nocol' (if char* typed) of the current BINTABLE extension 137 186 */ 138 187 int ColStringLengthFromFits(int nocol) const; 139 188 140 /*! return a reference on a DVList containing the keywords from FITS file 141 */ 142 inline const DVList& DVListFromFits() const { return dvl_;} 189 190 191 /*! 192 get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 193 */ 194 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char 195 ** cdata) ; 196 197 /*! 198 get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 199 */ 200 void GetBinTabLine(int NoLine, float* fdata) ; 201 202 203 143 204 144 205 … … 158 219 // Write elements into the FITS data array 159 220 160 /*! 161 get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 162 */ 163 void GetBinTabLine(int NoLine, double* ddata, float* fdata, int* idata, char 164 ** cdata) const; 165 /*! 166 get the NoLine-th 'line' from the current BINTABLE extension on FITS file, 167 */ 168 void GetBinTabLine(int NoLine, float* fdata) const; 169 170 171 172 173 /*! write double data from array 'map'on an IMAGE extension 174 \param <nbData> number of data to be written 175 176 */ 177 void putImageToFits( int nbData, double* map) const; 178 179 /*! same as previous method with float data */ 180 void putImageToFits(int nbData, float* map ) const; 181 182 /*! same as previous method with int data */ 183 void putImageToFits(int nbData, int* map) const; 184 185 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension. 186 \param <nentries> number of data to be written 187 188 */ 189 void putColToFits(int nocol, int nentries, double* donnees) const; 190 191 /*! same as previous method with float data */ 192 void putColToFits(int nocol, int nentries, float* donnees) const; 193 194 /*! same as previous method with int data */ 195 void putColToFits(int nocol, int nentries, int* donnees) const; 196 197 /*! same as previous method with char* data */ 198 void putColToFits(int nocol, int nentries, char** donnees) const; 199 200 /*! create an IMAGE header on FITS file. 201 \param <type> type of data (see method ColTypeFromFits) 202 \param <nbdim> number of dimensions : 1D, 2D, 3D etc. = NAXIS 203 \param <naxisn> array containind sizes of the different dimensions 204 */ 205 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ; 221 222 223 //write 224 //----- 206 225 207 226 /*! create an BINTABLE header on FITS file. … … 216 235 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) ; 217 236 218 void moveToFollowingHeader(); 219 void readheader(); 220 static void printerror(int&) ; 221 static void printerror(int&,char* texte) ; 222 protected: 223 virtual void ReadFromFits(FitsFile& ff)=0; 224 virtual void WriteToFits(FitsFile& ff)=0; 237 /*! write double data from array 'donnees ' on column number 'nocol' of a BINTABLE extension. 238 \param <nentries> number of data to be written 239 240 */ 241 void putColToFits(int nocol, int nentries, double* donnees) const; 242 243 /*! same as previous method with float data */ 244 void putColToFits(int nocol, int nentries, float* donnees) const; 245 246 /*! same as previous method with int data */ 247 void putColToFits(int nocol, int nentries, int* donnees) const; 248 249 /*! same as previous method with char* data */ 250 void putColToFits(int nocol, int nentries, char** donnees) const; 251 252 253 ///////////////////////////////////////////////////////////// 254 // methods for managing any type of FITS extension 255 //////////////////////////////////////////////////////// 256 257 258 /*! 259 fill the array 'map' with double data from the current extension on FITS file. 260 If the extension is BINTABLE, the first column is provided. 261 262 \param <nentries> number of data to be read 263 */ 264 void GetSingleColumn(double* map, int nentries) const; 265 266 /*! same as above with float data */ 267 void GetSingleColumn(float* map, int nentries) const; 268 269 /*! same as above with int data */ 270 void GetSingleColumn(int* map, int nentries) const; 271 272 273 225 274 private: 226 275 227 276 void InitNull(); 277 void ResetStatus(int& status) ; 278 static void printerror(int&) ; 279 static void printerror(int&,char* texte) ; 228 280 229 281 static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn); … … 279 331 DVList dvl_; 280 332 333 334 335 //! last status returned by fitsio library. updated only by several methods 336 int fits_status_; 281 337 }; 282 338 -
trunk/SophyaExt/FitsIOServer/fitsntuple.cc
r972 r1047 15 15 { 16 16 dobj_ = new NTuple; 17 column_ = NULL;18 ownobj =true;17 InitNull(); 18 ownobj_ = true; 19 19 } 20 20 … … 22 22 { 23 23 dobj_ = new NTuple; 24 column_ = NULL;25 ownobj =true;24 InitNull(); 25 ownobj_ = true; 26 26 27 27 ReadF(inputfile,hdunum); … … 32 32 { 33 33 dobj_ = new NTuple(obj); 34 column_ = NULL; 35 ownobj=true; 34 InitNull(); 35 ownobj_ = true; 36 } 37 FITS_NTuple::FITS_NTuple(NTuple* obj) 38 { 39 dobj_ = obj; 40 InitNull(); 41 ownobj_ = false; 36 42 } 37 43 … … 39 45 FITS_NTuple::~FITS_NTuple() 40 46 { 41 if (ownobj && dobj_ != NULL) delete dobj_;47 if (ownobj_ && dobj_ != NULL) delete dobj_; 42 48 if (column_ != NULL) delete [] column_; 43 49 } 44 50 51 void FITS_NTuple::Read(char inputfile[],int hdunum) 52 { 53 ReadF(inputfile,hdunum); 54 } 55 void FITS_NTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum) 56 { 57 fistLineToBeRead_ = firstLine; 58 numberOfLinesToBeRead_ = numberOfLines; 59 ReadF(inputfile,hdunum); 60 } 61 62 63 45 64 void FITS_NTuple::Write(char outputfile[], bool OldFile) 46 65 { … … 48 67 } 49 68 50 void FITS_NTuple::ReadFromFits(FitsFile& fn) 51 { 52 if (!fn.IsFitsTable()) 69 void FITS_NTuple::ReadFromFits() 70 { 71 // if (!fn.IsFitsTable()) 72 if (!IsFitsTable()) 53 73 { 54 74 throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table"); 55 75 } 56 76 int nbcols, nbentries; 57 nbcols = fn.NbColsFromFits(); 77 // nbcols = fn.NbColsFromFits(); 78 nbcols = NbColsFromFits(); 58 79 nbentries = 0; 59 80 int k; 60 for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) ); 81 // for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) ); 82 for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) ); 61 83 62 84 char ** ColName = new char*[nbcols]; … … 65 87 { 66 88 ColName[k] = new char[LONNOM1]; 67 strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM); 89 // strncpy(ColName[k], fn.ColNameFromFits(k).c_str(),LONNOM); 90 strncpy(ColName[k], ColNameFromFits(k).c_str(),LONNOM); 68 91 ColName[k][LONNOM] = '\0'; 69 92 } 70 93 for (k=0; k<nbcols;k++) 71 94 { 72 char ss= fn.ColTypeFromFits(k); 95 // char ss= fn.ColTypeFromFits(k); 96 char ss= ColTypeFromFits(k); 73 97 string type; 74 98 if (ss != 'E') … … 87 111 { 88 112 dobj_= new NTuple(nbcols,ColName); 89 ownobj = true;113 ownobj_ = true; 90 114 } 91 115 else … … 99 123 } 100 124 delete [] ColName; 101 if (column_ != NULL) delete [] column_;102 column_ = new float[nbentries];125 // if (column_ != NULL) delete [] column_; 126 // column_ = new float[nbentries]; 103 127 104 128 // j'initialise le NTuple a zero, pour le dimensionner 105 129 // (SetVal suppose que le ntuple est deja dimensionne) 106 130 r_4* ligne = new r_4[nbcols]; 107 for (k=0; k<nbcols; k++) ligne[k]=0.; 108 for (k=0; k<nbentries;k++) dobj_->Fill(ligne); 131 // for (k=0; k<nbcols; k++) ligne[k]=0.; 132 // for (k=0; k<nbentries;k++) dobj_->Fill(ligne); 133 // delete [] ligne; 134 135 //%%%%%% 136 int firstln, lastln; 137 if (numberOfLinesToBeRead_ > 0) 138 { 139 firstln = fistLineToBeRead_; 140 lastln = firstln + numberOfLinesToBeRead_; 141 } 142 else 143 { 144 firstln = 0; 145 lastln = nbentries; 146 } 147 int numLigne; 148 for (numLigne=firstln; numLigne < lastln; numLigne++) 149 { 150 // fn.GetBinTabLine(numLigne, ligne); 151 GetBinTabLine(numLigne, ligne); 152 dobj_->Fill(ligne); 153 } 109 154 delete [] ligne; 110 for (k=0; k<nbcols;k++) 111 { 112 fn.GetBinTabFCol(column_, nbentries, k); 113 for (int nent=0; nent<nbentries; nent++) dobj_->SetVal(nent,k, column_[nent]); 114 } 115 dobj_->Info()=fn.DVListFromFits(); 116 } 117 void FITS_NTuple::WriteToFits(FitsFile& fn) 155 156 //%%%%%%% 157 158 159 // for (k=0; k<nbcols;k++) 160 // { 161 // fn.GetBinTabFCol(column_, nbentries, k); 162 // for (int nent=0; nent<nbentries; nent++) dobj_->SetVal(nent,k, column_[nent]); 163 // } 164 // dobj_->Info()=fn.DVListFromFits(); 165 dobj_->Info()=DVListFromFits(); 166 } 167 void FITS_NTuple::WriteToFits() 118 168 { 119 169 if(dobj_ == NULL) … … 147 197 type[ncols]='\0'; 148 198 vector<int> dummy; 149 fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy); 199 // fn.makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy); 200 makeHeaderBntblOnFits(type,Noms, nentries, ncols, dvl, extname, dummy); 150 201 for (k=0; k< ncols; k++) 151 202 { -
trunk/SophyaExt/FitsIOServer/fitsntuple.h
r972 r1047 22 22 FITS_NTuple(char inputfile[],int hdunum=2); 23 23 FITS_NTuple(const NTuple & obj); 24 FITS_NTuple(NTuple* obj); 24 25 virtual ~FITS_NTuple(); 26 void Read(char inputfile[],int hdunum=2); 27 /*! 28 fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile. 29 \param <firstLine> first line to be read (the first line of the file is numbered 0) 30 \param <numberOfLines> number of lines to be read 31 */ 32 void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2); 25 33 void Write(char outputfile[], bool OldFile=false); 26 34 inline operator NTuple() { return(*dobj_); } … … 29 37 30 38 // implementation de FitsFile 31 virtual void ReadFromFits(FitsFile& fn); 32 virtual void WriteToFits(FitsFile& fn); 39 //virtual void ReadFromFits(FitsFile& fn); 40 virtual void ReadFromFits(); 41 virtual void WriteToFits(); 33 42 34 43 float* getColFromObj(int colNr); 35 44 45 private : 46 47 inline void InitNull() 48 { 49 fistLineToBeRead_= -1; 50 numberOfLinesToBeRead_= -1; 51 column_ = NULL; 52 } 53 54 36 55 // attributs de classe 37 56 NTuple* dobj_; 38 bool ownobj; 57 bool ownobj_; 58 int fistLineToBeRead_; 59 int numberOfLinesToBeRead_; 39 60 float* column_; 40 61 }; -
trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
r1004 r1047 80 80 81 81 template <class T> 82 void FITS_SphereHEALPix<T>::WriteToFits( FitsFile& fn)82 void FITS_SphereHEALPix<T>::WriteToFits() 83 83 { 84 84 if(dobj_ == NULL) … … 130 130 Type[1]='\0'; 131 131 vector<int> dummy; 132 fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy); 132 // fn.makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy); 133 makeHeaderBntblOnFits(Type, Noms, nPix, 1, dvl, extname, dummy); 133 134 delete [] Noms[0]; 134 135 delete [] Noms; … … 137 138 138 139 template <class T> 139 void FITS_SphereHEALPix<T>::ReadFromFits( FitsFile& fn)140 void FITS_SphereHEALPix<T>::ReadFromFits() 140 141 { 141 142 if(dobj_ == NULL) … … 148 149 149 150 int nbcols, nbentries; 150 nbcols = fn.NbColsFromFits(); 151 // nbcols = fn.NbColsFromFits(); 152 nbcols = NbColsFromFits(); 151 153 if (nbcols != 1) 152 154 { … … 154 156 } 155 157 // const DVList* dvl = &fn.DVListFromFits(); 156 DVList dvl=fn.DVListFromFits(); 158 // DVList dvl=fn.DVListFromFits(); 159 DVList dvl=DVListFromFits(); 157 160 // dvl.Print(); 158 nbentries = fn.NentriesFromFits(0); 161 // nbentries = fn.NentriesFromFits(0); 162 nbentries = NentriesFromFits(0); 159 163 int lastpix=dvl.GetI("LASTPIX"); 160 164 if (lastpix>0) … … 207 211 // On lit les DataBlocks; 208 212 dobj_->pixels_.ReSize(nPix); 209 fn.GetSingleColumn(dobj_->pixels_.Data(),nPix); 213 // fn.GetSingleColumn(dobj_->pixels_.Data(),nPix); 214 GetSingleColumn(dobj_->pixels_.Data(),nPix); 210 215 211 216 // on effectue le decoupage en tranches 212 217 dobj_->SetThetaSlices(); 213 dobj_->Info()=fn.DVListFromFits(); 218 // dobj_->Info()=fn.DVListFromFits(); 219 dobj_->Info()=DVListFromFits(); 214 220 215 221 -
trunk/SophyaExt/FitsIOServer/fitsspherehealpix.h
r1011 r1047 35 35 protected: 36 36 37 virtual void ReadFromFits(FitsFile& fn); 38 virtual void WriteToFits(FitsFile& fn); 37 //virtual void ReadFromFits(FitsFile& fn); 38 virtual void ReadFromFits(); 39 virtual void WriteToFits(); 39 40 SphereHEALPix<T>* dobj_; 40 41 bool ownobj; -
trunk/SophyaExt/FitsIOServer/fitstarray.cc
r972 r1047 60 60 61 61 template <class T> 62 void FITS_TArray<T>::ReadFromFits( FitsFile& fn)62 void FITS_TArray<T>::ReadFromFits() 63 63 { 64 64 65 if (!fn.IsFitsImage()) 65 // if (!fn.IsFitsImage()) 66 if (!IsFitsImage()) 66 67 { 67 68 throw PException("ReadFromFits: the fits file seems not to be an image"); 68 69 } 69 int dimension = fn.nbDimOfImage(); 70 // int dimension = fn.nbDimOfImage(); 71 int dimension = nbDimOfImage(); 70 72 cout << " dimension de l'image a lire: " << dimension << endl; 71 73 72 74 uint_4* siz = new uint_4[dimension]; 73 for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k]; 75 // for (int k=0; k< dimension; k++) siz[k] = fn.dimOfImageAxes()[k]; 76 for (int k=0; k< dimension; k++) siz[k] = dimOfImageAxes()[k]; 74 77 if(dobj_ == NULL) 75 78 dobj_ = new TArray<T>(dimension,siz); … … 78 81 79 82 delete [] siz; 80 if (dobj_->Size() != fn.nbOfImageData() ) 83 // if (dobj_->Size() != fn.nbOfImageData() ) 84 if (dobj_->Size() != nbOfImageData() ) 81 85 { 82 86 cout << " total size of TArray: " << dobj_->Size() << endl; 83 cout << " total size from fits file: " << fn.nbOfImageData() << endl;87 cout << " total size from fits file: " << nbOfImageData() << endl; 84 88 throw PException("ReadFromFits: size conflict"); 85 89 } 86 90 // On lit le tableau 87 fn.GetSingleColumn( dobj_->Data(),dobj_->Size()); 91 // fn.GetSingleColumn( dobj_->Data(),dobj_->Size()); 92 GetSingleColumn( dobj_->Data(),dobj_->Size()); 88 93 89 94 } … … 91 96 92 97 template <class T> 93 void FITS_TArray<T>::WriteToFits( FitsFile& fn)98 void FITS_TArray<T>::WriteToFits() 94 99 { 95 100 if(dobj_ == NULL) return; … … 125 130 } 126 131 cout << " nombre total d'elements a copier " << nbels << endl; 127 fn.makeHeaderImageOnFits(type, nbdim, naxisn); 132 // fn.makeHeaderImageOnFits(type, nbdim, naxisn); 133 makeHeaderImageOnFits(type, nbdim, naxisn); 128 134 if (!dobj_->IsPacked()) 129 135 { … … 138 144 139 145 } 140 fn.putImageToFits(nbels, dobj_->Data()); 146 // fn.putImageToFits(nbels, dobj_->Data()); 147 putImageToFits(nbels, dobj_->Data()); 141 148 142 149 delete [] naxisn; -
trunk/SophyaExt/FitsIOServer/fitstarray.h
r1044 r1047 35 35 protected : 36 36 37 void ReadFromFits(FitsFile& fn); 38 void WriteToFits(FitsFile& fn); 37 //void ReadFromFits(FitsFile& fn); 38 void ReadFromFits(); 39 void WriteToFits(); 39 40 40 41 TArray<T> * dobj_; -
trunk/SophyaExt/FitsIOServer/fitsxntuple.cc
r972 r1047 13 13 { 14 14 dobj_ = new XNTuple; 15 dcolumn_ = NULL; 16 fcolumn_ = NULL; 17 icolumn_ = NULL; 18 ccolumn_ = NULL; 19 ownobj=true; 15 InitNull(); 16 ownobj_ = true; 20 17 } 21 18 … … 23 20 { 24 21 dobj_ = new XNTuple; 25 dcolumn_ = NULL; 26 fcolumn_ = NULL; 27 icolumn_ = NULL; 28 ccolumn_ = NULL; 29 ownobj=true; 22 InitNull(); 23 ownobj_ = true; 30 24 31 25 ReadF(inputfile,hdunum); … … 36 30 { 37 31 dobj_ = new XNTuple(obj); 38 dcolumn_ = NULL; 39 fcolumn_ = NULL; 40 icolumn_ = NULL; 41 ccolumn_ = NULL; 42 ownobj=true; 32 InitNull(); 33 ownobj_ = true; 34 } 35 FITS_XNTuple::FITS_XNTuple(XNTuple* obj) 36 { 37 dobj_ = obj; 38 InitNull(); 39 ownobj_ = false; 43 40 } 44 41 FITS_XNTuple::~FITS_XNTuple() 42 { 43 Clean(); 44 } 45 46 void FITS_XNTuple::Clean() 45 47 { 46 48 if (dcolumn_ != NULL) delete [] dcolumn_; … … 58 60 cout << "FITS_XNTuple, destructeur: bizarre, ccolumn non vide, sans objet?" << endl;; } 59 61 } 60 if (ownobj && dobj_ != NULL) delete dobj_; 61 } 62 if (ownobj_ && dobj_ != NULL) delete dobj_; 63 } 64 65 void FITS_XNTuple::Read(char inputfile[],int hdunum) 66 { 67 ReadF(inputfile,hdunum); 68 } 69 70 void FITS_XNTuple::ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum) 71 { 72 fistLineToBeRead_ = firstLine; 73 numberOfLinesToBeRead_ = numberOfLines; 74 ReadF(inputfile,hdunum); 75 // return dobj_; 76 } 77 78 62 79 void FITS_XNTuple::Write(char outputfile[], bool OldFile) 63 80 { … … 65 82 } 66 83 67 void FITS_XNTuple::ReadFromFits( FitsFile& fn)84 void FITS_XNTuple::ReadFromFits() 68 85 { 69 if (!fn.IsFitsTable()) 86 // if (!fn.IsFitsTable()) 87 if (!IsFitsTable()) 70 88 { 71 89 throw PException("ReadFromFits: the fits file seems not to be a bintable nor ASCII table"); 72 90 } 73 91 int nbcols, nbentries; 74 nbcols = fn.NbColsFromFits(); 92 // nbcols = fn.NbColsFromFits(); 93 nbcols = NbColsFromFits(); 75 94 nbentries = 0; 76 95 int k; 77 for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) ); 96 // for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn.NentriesFromFits(k) ); 97 for (k=0; k<nbcols; k++) nbentries=max( nbentries, NentriesFromFits(k) ); 78 98 79 99 // … … 91 111 for (k=0; k<nbcols;k++) 92 112 { 93 char ss= fn.ColTypeFromFits(k); 113 // char ss= fn.ColTypeFromFits(k); 114 char ss= ColTypeFromFits(k); 94 115 if (ss == 'D') DfitsCol.push_back(k); 95 116 else if (ss == 'E') FfitsCol.push_back(k); … … 106 127 { 107 128 ColName[compt] = new char[LONNOM+1]; 108 strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM); 129 // strncpy(ColName[compt], fn.ColNameFromFits(DfitsCol[k]).c_str(), LONNOM); 130 strncpy(ColName[compt], ColNameFromFits(DfitsCol[k]).c_str(), LONNOM); 109 131 ColName[compt++][ LONNOM] = '\0'; 110 132 } … … 112 134 { 113 135 ColName[compt] = new char[LONNOM+1]; 114 strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM); 136 // strncpy(ColName[compt], fn.ColNameFromFits(FfitsCol[k]).c_str(), LONNOM); 137 strncpy(ColName[compt], ColNameFromFits(FfitsCol[k]).c_str(), LONNOM); 115 138 ColName[compt++][ LONNOM] = '\0'; 116 139 } … … 118 141 { 119 142 ColName[compt] = new char[LONNOM+1]; 120 strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM); 143 // strncpy(ColName[compt], fn.ColNameFromFits(IfitsCol[k]).c_str(), LONNOM); 144 strncpy(ColName[compt], ColNameFromFits(IfitsCol[k]).c_str(), LONNOM); 121 145 ColName[compt++][ LONNOM] = '\0'; 122 146 } … … 124 148 { 125 149 ColName[compt] = new char[LONNOM+1]; 126 strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM); 150 // strncpy(ColName[compt], fn.ColNameFromFits(SfitsCol[k]).c_str(), LONNOM); 151 strncpy(ColName[compt], ColNameFromFits(SfitsCol[k]).c_str(), LONNOM); 127 152 ColName[compt++][LONNOM] = '\0'; 128 153 } 129 130 154 131 155 if(dobj_ == NULL) 132 156 { 133 157 dobj_= new XNTuple(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(),ColName); 134 ownobj = true;158 ownobj_ = true; 135 159 } 136 160 else 137 161 { 138 dobj_->clean(); 162 if (ownobj_) 163 { 139 164 (*dobj_)= XNTuple(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(),ColName); 140 } 165 } 166 else 167 { 168 if (DfitsCol.size() != dobj_->NDVar() || FfitsCol.size() != dobj_->NFVar() || IfitsCol.size() != dobj_->NIVar() || SfitsCol.size() != dobj_->NSVar()) 169 170 throw SzMismatchError("FITS_XNTuple : structure incorrecte du ntuple"); 171 } 172 } 173 141 174 for (k=0; k<nbcols;k++) 142 175 { … … 145 178 delete [] ColName; 146 179 147 // j'initialise le NTuple a zero, pour le dimensionner 148 // (SetXVal suppose que le ntuple est deja dimensionne) 149 r_8* dligne; 150 r_4* fligne; 151 int_4* iligne; 152 char** cligne; 153 if (DfitsCol.size()>0) 154 { 155 if (dcolumn_ != NULL) delete [] dcolumn_; 156 dcolumn_ = new double[nbentries]; 157 dligne = new r_8[DfitsCol.size()]; 158 for (k=0; k<DfitsCol.size(); k++) dligne[k]=0.; 159 } 180 r_8* dligne; 181 r_4* fligne; 182 int_4* iligne; 183 char** cligne; 184 185 if (DfitsCol.size()>0) dligne = new r_8[DfitsCol.size()]; 160 186 else dligne=NULL; 161 if (FfitsCol.size()>0) 162 { 163 if (fcolumn_ != NULL) delete [] fcolumn_; 164 fcolumn_ = new float[nbentries]; 165 fligne = new r_4[FfitsCol.size()]; 166 for (k=0; k<FfitsCol.size(); k++) fligne[k]=0.; 167 } 187 if (FfitsCol.size()>0) fligne = new r_4[FfitsCol.size()]; 168 188 else fligne=NULL; 169 if (IfitsCol.size()>0) 170 { 171 if (icolumn_ != NULL) delete [] icolumn_; 172 icolumn_ = new int[nbentries]; 173 iligne = new int_4[IfitsCol.size()]; 174 for (k=0; k<IfitsCol.size(); k++) iligne[k]=0; 175 } 189 if (IfitsCol.size()>0) iligne = new int_4[IfitsCol.size()]; 176 190 else iligne=NULL; 177 191 if (SfitsCol.size()>0) 178 192 { 179 if (ccolumn_ != NULL) 180 { 181 for (k=0; k<dobj_->NEntry(); k++) delete [] ccolumn_[k]; 182 delete [] ccolumn_; 183 ccolumn_ = NULL; 184 } 185 ccolumn_ = new char*[nbentries]; 193 cligne = new char*[SfitsCol.size()]; 186 194 int taille_des_chaines=0; 187 for (k=0; k< SfitsCol.size(); k++) taille_des_chaines = max( taille_des_chaines, fn.ColStringLengthFromFits(SfitsCol[k]) ); 188 for (k=0; k<nbentries;k++) ccolumn_[k]= new char[taille_des_chaines+1]; 189 cligne = new char*[SfitsCol.size()]; 190 for (k=0; k<SfitsCol.size(); k++) cligne[k]=" "; 195 // for (k=0; k< SfitsCol.size(); k++) taille_des_chaines = max( taille_des_chaines, fn.ColStringLengthFromFits(SfitsCol[k]) ); 196 for (k=0; k< SfitsCol.size(); k++) taille_des_chaines = max( taille_des_chaines, ColStringLengthFromFits(SfitsCol[k]) ); 197 for (k=0; k<SfitsCol.size(); k++) cligne[k]=new char[taille_des_chaines+1]; 191 198 } 192 199 else cligne=NULL; 193 194 for (k=0; k<nbentries;k++) dobj_->Fill(dligne, fligne, iligne, cligne); 195 delete [] dligne; 196 delete [] fligne; 197 delete [] iligne; 198 for (k=0; k< SfitsCol.size(); k++) delete [] cligne[k]; 199 delete [] cligne; 200 201 compt=0; 202 for (k=0; k<DfitsCol.size(); k++) 203 { 204 fn.GetBinTabFCol(dcolumn_, nbentries, DfitsCol[k]); 205 for (int nent=0; nent<nbentries; nent++) dobj_->SetDVal(nent,compt, dcolumn_[nent]); 206 compt++; 207 } 208 209 for (k=0; k<FfitsCol.size(); k++) 210 { 211 fn.GetBinTabFCol(fcolumn_,nbentries, FfitsCol[k]); 212 for (int nent=0; nent<nbentries; nent++) dobj_->SetFVal(nent,compt, fcolumn_[nent]); 213 compt++; 214 } 215 216 for (k=0; k<IfitsCol.size(); k++) 217 { 218 fn.GetBinTabFCol(icolumn_,nbentries, IfitsCol[k]); 219 for (int nent=0; nent<nbentries; nent++) dobj_->SetIVal(nent,compt, icolumn_[nent]); 220 compt++; 221 } 222 223 for (k=0; k<SfitsCol.size(); k++) 224 { 225 fn.GetBinTabFCol(ccolumn_,nbentries, SfitsCol[k]); 226 for (int nent=0; nent<nbentries; nent++) dobj_->SetSVal(nent,compt, ccolumn_[nent]); 227 compt++; 228 } 229 dobj_->Info()=fn.DVListFromFits(); 230 231 } 232 void FITS_XNTuple::WriteToFits(FitsFile& fn) 200 int firstln, lastln; 201 if (numberOfLinesToBeRead_ > 0) 202 { 203 firstln = fistLineToBeRead_; 204 lastln = firstln + numberOfLinesToBeRead_; 205 } 206 else 207 { 208 firstln = 0; 209 lastln = nbentries; 210 } 211 int numLigne; 212 for (numLigne=firstln; numLigne < lastln; numLigne++) 213 { 214 // fn.GetBinTabLine(numLigne, dligne, fligne, iligne, cligne ); 215 GetBinTabLine(numLigne, dligne, fligne, iligne, cligne ); 216 dobj_->Fill(dligne, fligne, iligne, cligne); 217 } 218 delete [] dligne; 219 delete [] fligne; 220 delete [] iligne; 221 for (k=0; k< SfitsCol.size(); k++) delete [] cligne[k]; 222 delete [] cligne; 223 // dobj_->Info()=fn.DVListFromFits(); 224 dobj_->Info()=DVListFromFits(); 225 226 } 227 void FITS_XNTuple::WriteToFits() 233 228 { 234 229 if(dobj_ == NULL) … … 276 271 for (k=0; k< StringSizes.size(); k++) StringSizes[k]=dobj_->mStrSz; 277 272 // la librairie fitsio ecrit colonne par colonne 278 fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 273 // fn.makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 274 makeHeaderBntblOnFits(types, Noms, nrows, ncols, dvl, extname,StringSizes); 279 275 for (k=0; k< ncols; k++) 280 276 { -
trunk/SophyaExt/FitsIOServer/fitsxntuple.h
r972 r1047 22 22 FITS_XNTuple(char inputfile[],int hdunum=2); 23 23 FITS_XNTuple(const XNTuple & obj); 24 FITS_XNTuple(XNTuple* obj); 24 25 ~FITS_XNTuple(); 26 void Read(char inputfile[],int hdunum=2); 27 28 /*! 29 fill the XNTuple only with lines from firstLine-th to (firstLine+numberOfLines-1)-th of the FITS-file inputfile. 30 \param <firstLine> first line to be read (the first line of the file is numbered 0) 31 \param <numberOfLines> number of lines to be read 32 */ 33 void ReadLines(char inputfile[],int firstLine, int numberOfLines,int hdunum=2); 25 34 void Write(char outputfile[], bool OldFile=false); 26 35 inline operator XNTuple() { return(*dobj_); } … … 29 38 30 39 // implementation de FitsFile 31 virtual void ReadFromFits(FitsFile& fn); 32 virtual void WriteToFits(FitsFile& fn); 40 // virtual void ReadFromFits(FitsFile& fn); 41 virtual void ReadFromFits(); 42 virtual void WriteToFits(); 33 43 void* getColFromObj(int colNr); 34 44 double* getColDFromObj(int colNr); … … 37 47 char** getColSFromObj(int colNr); 38 48 49 private : 50 51 void Clean(); 52 53 inline void InitNull() 54 { 55 fistLineToBeRead_= -1; 56 numberOfLinesToBeRead_= -1; 57 dcolumn_ = NULL; 58 fcolumn_ = NULL; 59 icolumn_ = NULL; 60 ccolumn_ = NULL; 61 } 62 39 63 // attributs de classe 40 64 XNTuple* dobj_; 41 bool ownobj; 65 bool ownobj_; 66 int fistLineToBeRead_; 67 int numberOfLinesToBeRead_; 42 68 double* dcolumn_; 43 69 float* fcolumn_;
Note:
See TracChangeset
for help on using the changeset viewer.