Changeset 1657 in Sophya for trunk/SophyaExt
- Timestamp:
- Sep 27, 2001, 7:45:52 PM (24 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fabtcolread.cc
r1654 r1657 98 98 SetNulVal(); 99 99 SetDebug(lp); 100 BuffLen = (blen<=0) ? 1: blen;101 BuffSens = bsens;102 100 NFitsRead = 0; 103 101 FitsPtr = NULL; 104 102 LineDeb = LineFin = -1; 105 103 Buffer = NULL; 106 NBuffer = 0;104 ChangeBuffer(blen,bsens); 107 105 108 106 ////////////////////////// … … 112 110 int sta=0; 113 111 if(FitsFN.size() <= 0 ) { 114 IHdu = -1; 112 IHdu = -1; Delete(); 115 113 throw ParmError("FitsABTColRead::Init: Fits file name error\n"); 116 114 } … … 145 143 } 146 144 if(IHdu<=0 || IHdu>NHdu) { 147 IHdu = 0;148 145 cout<<"NO BINARY or ASCII hdu found"<<endl; 149 Delete();146 IHdu = 0; Delete(); 150 147 throw TypeMismatchExc("FitsABTColRead::Init: NO BINARY or ASCII hdu found\n"); 151 148 } … … 230 227 <<" TUnit="<<ColTUnit<<" TForm="<<ColTForm<<endl; 231 228 232 // Prepare buffer233 NBuffer = (BuffSens==0) ? BuffLen+1: BuffLen;234 Buffer = new double[NBuffer];235 229 } 236 230 … … 246 240 void FitsABTColRead::ChangeBuffer(long blen,long bsens) 247 241 { 242 long oldnbuffer = NBuffer; 243 244 // Compute buffer caracteristics 248 245 BuffLen = (blen<=0)? 1: blen; 249 246 BuffSens = bsens; 250 251 // De-allocate 252 if(Buffer==NULL) return; 253 delete [] Buffer; Buffer=NULL; 247 NBuffer = BuffLen; 248 if(bsens==0 && NBuffer%2==0) NBuffer++; 249 250 // De-allocate if necessary 251 if(Buffer!=NULL && oldnbuffer!=NBuffer) 252 {delete [] Buffer; Buffer=NULL;} 253 254 // Re-allocate 255 if(Buffer==NULL) Buffer = new double[NBuffer]; 254 256 255 257 // Tell program that nothing is into buffer 256 258 LineDeb = LineFin = -1; 257 258 // Re-allocate259 NBuffer = (BuffSens==0) ? BuffLen+1: BuffLen;260 Buffer = new double[NBuffer];261 259 } 262 260 … … 264 262 void FitsABTColRead::Delete() 265 263 { 266 if(Buffer==NULL) return; 267 delete [] Buffer; Buffer=NULL; 264 if(Buffer!=NULL) {delete [] Buffer; Buffer=NULL;} 268 265 LineDeb = LineFin = -1; 269 266 int sta = 0; … … 279 276 \endverbatim 280 277 */ 281 r_8FitsABTColRead::Read(long n)278 double FitsABTColRead::Read(long n) 282 279 // Attention: n=nline [0,NBline[, cfistio veut [1,NBline] 283 280 // Attention: colnum [0,NBcol[ , cfistio veut [1,NBcol] … … 288 285 289 286 // Pas de bufferisation, on lit betement 290 if( BuffLen==1) {287 if(NBuffer==1) { 291 288 NFitsRead++; 292 289 fits_read_col_dbl(FitsPtr,ColNum+1,n+1,1,1,NulVal,Buffer,&anynul,&sta); … … 308 305 if(BuffSens>0) { // Cas remplissage forward 309 306 row1 = n+1; 310 row2 = row1+ BuffLen-1; if(row2>NBline) row2 = NBline;307 row2 = row1+NBuffer-1; if(row2>NBline) row2 = NBline; 311 308 } else if(BuffSens<0) { // Cas remplissage backward 312 309 row2 = n+1; 313 row1 = row2- BuffLen+1; if(row1<1) row1 = 1;310 row1 = row2-NBuffer+1; if(row1<1) row1 = 1; 314 311 } else { // Cas remplissage centre 315 row1 = n+1 - BuffLen/2; if(row1<1) row1 = 1;316 row2 = n+1 + BuffLen/2; if(row2>NBline) row2 = NBline;312 row1 = n+1 - NBuffer/2; if(row1<1) row1 = 1; 313 row2 = n+1 + NBuffer/2; if(row2>NBline) row2 = NBline; 317 314 } 318 315 nrow = row2 - row1 + 1; … … 339 336 \endverbatim 340 337 */ 341 void FitsABTColRead::Read(long n1,long n2,TVector< r_8>& data)338 void FitsABTColRead::Read(long n1,long n2,TVector<double>& data) 342 339 { 343 340 if(n1<0 || n1>=NBline || n2<0 || n2>=NBline || n1>n2) -
trunk/SophyaExt/FitsIOServer/fabtcolread.h
r1654 r1657 30 30 void ChangeBuffer(long blen=100,long bsens=1); 31 31 32 r_8Read(long n);33 void Read(long n1,long n2,TVector< r_8>& data);32 double Read(long n); 33 void Read(long n1,long n2,TVector<double>& data); 34 34 35 35 //! Set debug level 36 inline void SetDebug(int lp=0) {DbgLevel = (u int_2) lp;}36 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} 37 37 //! Set null value to be return when reading null data (0=return the data) 38 inline void SetNulVal( r_8nulval=0.) {NulVal = nulval;}38 inline void SetNulVal(double nulval=0.) {NulVal = nulval;} 39 39 //! Get the FITS file name 40 40 inline string GetFileName(void) {return FitsFN;} … … 59 59 //! Get the columns fits tform that is read 60 60 inline string GetColTForm(void) {return ColTForm;} 61 //! Get the read buffer length61 //! Get the read requested buffer length 62 62 inline long GetBLen(void) {return BuffLen;} 63 63 //! Get the read buffer direction … … 67 67 //! Print to stdout 68 68 inline void Print(int lp=1) const {Print(cout,lp);} 69 //! Get the read buffer effectivelength70 inline long Get BufferLen(void) {return NBuffer;}69 //! Get the read effective buffer length 70 inline long GetNBuffer(void) {return NBuffer;} 71 71 //! Get the read bufferpointer 72 72 inline double* GetBuffer(void) {return Buffer;} … … 82 82 long NBline; 83 83 84 r_8NulVal;85 u int_2DbgLevel;84 double NulVal; 85 unsigned short DbgLevel; 86 86 long BuffLen, BuffSens; 87 87 88 u int_4NFitsRead;88 unsigned long NFitsRead; 89 89 fitsfile *FitsPtr; 90 90 long LineDeb, LineFin; -
trunk/SophyaExt/FitsIOServer/fabtwriter.cc
r1654 r1657 14 14 FitsABTWriter fbtw("myfits.fits",BINARY_TBL,3); 15 15 fbtw.SetExtName("MY_OWN_EXTENSION"); 16 fbtw.AddCol("vars",TSHORT,"","km"); // col=017 fbtw.AddCol("vars2",TSHORT,"","km"); // col=118 fbtw.AddCol("varl",T LONG,"","Degre");// col=219 fbtw.AddCol("varf",TFLOAT,"",""); // col=320 fbtw.AddCol("vard",TDOUBLE,"","arcmin"); // col=416 fbtw.AddCol("vars",TSHORT,"","km"); // col=0 17 fbtw.AddCol("vars2",TSHORT,"","km"); // col=1 18 fbtw.AddCol("varl",TINT32BIT,"","Degre"); // col=2 19 fbtw.AddCol("varf",TFLOAT,"",""); // col=3 20 fbtw.AddCol("vard",TDOUBLE,"","arcmin"); // col=4 21 21 fbtw.SetDebug(3); 22 22 for(long i=0;i<1000;i++) { … … 83 83 } 84 84 85 // create d'un Primary HDU */85 // create d'un Primary HDU 86 86 //long naxes[1] = {0}; 87 87 //if(fits_create_img(FitsPtr,BYTE_IMG,0,naxes,&sta)) { … … 105 105 \verbatim 106 106 label : column label 107 datatype : TSHORT T LONGTFLOAT or TDOUBLE107 datatype : TSHORT TINT32BIT TFLOAT or TDOUBLE 108 108 tform : fits tform definition 109 109 (can be automatically set if BINARY_TBL and tform="") … … 117 117 throw AllocationError("FitsABTWriter::addcol: table already created\n"); 118 118 119 if( datatype!=TSHORT && datatype!=T LONG119 if( datatype!=TSHORT && datatype!=TINT32BIT 120 120 && datatype!=TFLOAT && datatype!=TDOUBLE ) 121 121 throw ParmError("FitsABTWriter::addcol: datatype not allowed\n"); … … 126 126 if(HduType==BINARY_TBL && strlen(tform)<=0) { 127 127 char str[16]; 128 if(datatype==TSHORT) strcpy(str,"1I");129 else if(datatype==T LONG)strcpy(str,"1J");130 else if(datatype==TFLOAT) strcpy(str,"1E");131 else if(datatype==TDOUBLE) strcpy(str,"1D");128 if(datatype==TSHORT) strcpy(str,"1I"); 129 else if(datatype==TINT32BIT) strcpy(str,"1J"); 130 else if(datatype==TFLOAT) strcpy(str,"1E"); 131 else if(datatype==TDOUBLE) strcpy(str,"1D"); 132 132 TForm.push_back(str); 133 133 } else TForm.push_back(tform); … … 217 217 { 218 218 if(FirstTime) createtbl(); 219 short x[1] = {val}; 220 int sta=0; 221 if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,x,&sta)) 219 int sta=0; 220 if(fits_write_col(FitsPtr,TSHORT,col+1,row+1,1,1,&val,&sta)) 222 221 printerrorwrite("short",col,row,sta); 223 222 } 224 223 225 224 /*! Write long data to FITS file (see below) */ 226 void FitsABTWriter::Write(int col,long row,long val) 227 { 228 if(FirstTime) createtbl(); 229 long x[1] = {val}; 230 int sta=0; 231 if(fits_write_col(FitsPtr,TLONG,col+1,row+1,1,1,x,&sta)) 225 void FitsABTWriter::Write(int col,long row,int_4 val) 226 { 227 if(FirstTime) createtbl(); 228 int sta=0; 229 // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ? 230 int T = (sizeof(long)==4) ? TLONG: TINT; 231 if(fits_write_col(FitsPtr,T,col+1,row+1,1,1,&val,&sta)) 232 232 printerrorwrite("long",col,row,sta); 233 233 } … … 237 237 { 238 238 if(FirstTime) createtbl(); 239 float x[1] = {val}; 240 int sta=0; 241 if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,x,&sta)) 239 int sta=0; 240 if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,1,&val,&sta)) 242 241 printerrorwrite("float",col,row,sta); 243 242 } … … 247 246 { 248 247 if(FirstTime) createtbl(); 249 double x[1] = {val}; 250 int sta=0; 251 if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,x,&sta)) 248 int sta=0; 249 if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,1,&val,&sta)) 252 250 printerrorwrite("double",col,row,sta); 253 251 } 254 252 253 ////////////////////////////////////////////////////////////// 254 /*! 255 Write a vector of long data to FITS file. 256 \verbatim 257 col : column number [0,ncol[ 258 row : starting row number [0,nrow[ 259 val : vector to be written 260 Return: number of the last written row (remember row=[0,nrow[) 261 \endverbatim 262 */ 263 /*! Write a vector of long data to FITS file (see below) */ 264 long FitsABTWriter::Write(int col,long row,TVector<int_4>& val) 265 { 266 if(FirstTime) createtbl(); 267 long nel = val.Size(); 268 int sta=0; 269 // Bug ou inconsistence cfitsio sur machine ou long=8Bytes ? 270 int T = (sizeof(long)==4) ? TLONG: TINT; 271 if(fits_write_col(FitsPtr,T,col+1,row+1,1,nel,val.Data(),&sta)) 272 printerrorwrite("long",col,row,sta); 273 return row+nel; 274 } 275 276 /*! Write a vector of float data to FITS file (see below) */ 277 long FitsABTWriter::Write(int col,long row,TVector<float>& val) 278 { 279 if(FirstTime) createtbl(); 280 long nel = val.Size(); 281 int sta=0; 282 if(fits_write_col(FitsPtr,TFLOAT,col+1,row+1,1,nel,val.Data(),&sta)) 283 printerrorwrite("float",col,row,sta); 284 return row+nel; 285 } 286 287 /*! Write a vector of double data to FITS file (see below) */ 288 long FitsABTWriter::Write(int col,long row,TVector<double>& val) 289 { 290 if(FirstTime) createtbl(); 291 long nel = val.Size(); 292 int sta=0; 293 if(fits_write_col(FitsPtr,TDOUBLE,col+1,row+1,1,nel,val.Data(),&sta)) 294 printerrorwrite("double",col,row,sta); 295 return row+nel; 296 } 297 298 ////////////////////////////////////////////////////////////// 255 299 void FitsABTWriter::printerrorwrite(char* type,int col,long row,int sta) 256 300 { -
trunk/SophyaExt/FitsIOServer/fabtwriter.h
r1654 r1657 37 37 inline void SetExtName(char* extname="") {ExtName = extname;} 38 38 //! Set debug level 39 inline void SetDebug(int lp=0) {DbgLevel = (u int_2) lp;}39 inline void SetDebug(int lp=0) {DbgLevel = (unsigned short) lp;} 40 40 41 void Write(int col,long row,short 42 void Write(int col,long row, longval);43 void Write(int col,long row,float 41 void Write(int col,long row,short val); 42 void Write(int col,long row,int_4 val); 43 void Write(int col,long row,float val); 44 44 void Write(int col,long row,double val); 45 long Write(int col,long row,TVector<int_4>& val); 46 long Write(int col,long row,TVector<float>& val); 47 long Write(int col,long row,TVector<double>& val); 45 48 //! Return the number of overflows managed by cfitsio 46 inline u int_4GetNOverFlow(void) {return NOverFlow;}49 inline unsigned long GetNOverFlow(void) {return NOverFlow;} 47 50 48 51 protected: … … 56 59 string FitsFN,ExtName; 57 60 int HduType; 58 u int_2DbgLevel;61 unsigned short DbgLevel; 59 62 fitsfile *FitsPtr; 60 63 bool FirstTime; … … 63 66 vector<string> TForm; 64 67 vector<string> TUnit; 65 u int_4NOverFlow;68 unsigned long NOverFlow; 66 69 }; 67 70
Note:
See TracChangeset
for help on using the changeset viewer.