Changeset 1234 in Sophya for trunk/SophyaExt
- Timestamp:
- Oct 13, 2000, 12:34:37 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r1231 r1234 104 104 void FitsIOHandler::Read(FitsInFile& is, int hdunum) 105 105 { 106 if (hdunum == 0) is.moveToFollowingHeader(); 107 else is.ReadFInit(hdunum); 106 // if (hdunum == 0 ) is.moveToFollowingHeader(); 107 // else is.ReadFInit(hdunum); 108 is.ReadFInit(hdunum); 108 109 ReadFromFits(is); 109 110 } … … 115 116 for writing a new object in a new fits-extension : 116 117 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 : 118 \warning By convention, primary header may contain fits-image data. 119 For switching off this convention (i.e. to make sure that all data will be on fits-extensions) use the method : 120 120 121 121 firstImageOnPrimaryHeader() (see below) 122 123 In that case do not forget to precise hdunum=1 when reading data on primary header.124 122 125 123 calls the method 'WriteToFits' from the inherited object … … 330 328 void FitsInFile::ReadFInit(int hdunum) 331 329 { 332 InitNull(); 333 // int status = 0; 334 335 // fits_open_file(&fptr_,flnm,READONLY,&status); 336 // if( status ) printerror( status ); 337 338 int status = 0; 339 340 if (hdunum <= 1) 341 { 342 hdunum_ = 1; 343 // presence of image ? 344 int naxis= 0; 345 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 346 if( status ) printerror( status ); 347 if (naxis > 0 ) // there is an image 348 { 349 hdutype_ = IMAGE_HDU; 350 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 351 nbData_ = 1; 352 int k; 353 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 354 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 355 } 356 else 357 { 358 throw PException(" first header : no image, probably error in hdunum"); 359 } 360 // 361 } 362 else 363 { 364 hdunum_ = hdunum-1; 365 int hdutype; 366 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 367 if( status ) printerror( status,":FitsFile::ReadF : erreur movabs"); 368 moveToFollowingHeader(); 369 } 330 InitNull(); 331 int status = 0; 332 333 if (hdunum != 0 ) hdunum_ = hdunum; 334 335 // si le numero de header non precise 336 else 337 { 338 // si c'est le premier objet a lire 339 if (hdunum_ == 0) 340 { 341 // on calcule le numero de header a lire 342 if (imageOnPrimary_ == true) hdunum_ = 1; 343 else hdunum_ = 2; 344 } 345 // sinon objet suivant 346 else hdunum_++; 347 } 348 getHeader(); 349 370 350 } 371 351 … … 418 398 } 419 399 400 void FitsInFile::getHeader() 401 { 402 int status=0; 403 if (hdunum_ < 1) throw PException(" attempt to read hdunum < 1"); 404 if (hdunum_ == 1) 405 { 406 // presence of image ? 407 int naxis= 0; 408 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 409 if( status ) printerror( status ); 410 if (naxis > 0 ) // there is an image 411 { 412 hdutype_ = IMAGE_HDU; 413 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 414 nbData_ = 1; 415 int k; 416 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 417 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 418 } 419 else 420 { 421 throw PException(" first header : no image, probably error in hdunum"); 422 } 423 } 424 else 425 { 426 int hdutype; 427 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 428 if( status ) printerror( status,":FitsInFile::getHeader : erreur movabs"); 429 hdutype_= hdutype; 430 if(hdutype_ == IMAGE_HDU) 431 { 432 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 433 nbData_ = 1; 434 int k; 435 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 436 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 437 } 438 if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL) 439 { 440 GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_); 441 KeywordsIntoDVList(fptr_, dvl_, hdunum_); 442 } 443 } 444 } 445 420 446 421 447 void FitsInFile::moveToFollowingHeader() 422 448 { 423 449 int status = 0; 424 int hdutype;425 InitNull();426 fits_movrel_hdu(fptr_, 1,&hdutype,&status);427 if( status ) printerror( status," lecture du header suivant" );428 450 hdunum_++; 429 hdutype_= hdutype; 430 if(hdutype_ == IMAGE_HDU) 431 { 432 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 433 nbData_ = 1; 434 int k; 435 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 436 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 437 } 438 if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL) 439 { 440 GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_); 441 KeywordsIntoDVList(fptr_, dvl_, hdunum_); 442 } 451 getHeader(); 443 452 } 444 453 … … 1182 1191 long naxis = nbdim; 1183 1192 long* naxes = new long[nbdim]; 1184 if (hdunum_ == 1) 1193 // if (hdunum_ == 1) 1194 if (hdunum_ == 0) 1185 1195 { 1186 1196 if (imageOnPrimary_ == false) 1187 1197 { 1198 hdunum_ = 1; 1188 1199 fits_create_img(fptr_,FLOAT_IMG,0,naxes,&status); 1189 1200 writeSignatureOnFits(); } 1190 else hdunum_--;1201 // else hdunum_--; 1191 1202 } 1192 1203 int k; -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r1231 r1234 71 71 static string GetErrStatus(int status); 72 72 inline int statusF() const { return fits_status_;} 73 inline void firstImageOnPrimaryHeader(bool choice) {imageOnPrimary_=choice;} 73 74 74 75 … … 78 79 static void printerror(int&) ; 79 80 static void printerror(int&,char* texte) ; 80 inline void InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 1;81 fits_status_ = 0; }81 inline void InitNull() {fptr_ = NULL; hdutype_= 0; hdunum_ = 0; 82 fits_status_ = 0; imageOnPrimary_ = true;} 82 83 83 84 fitsfile *fptr_; /**< pointer to the FITS file, defined in fitsio.h */ … … 85 86 int hdunum_; /**< index of header to be read/written */ 86 87 int fits_status_; /**< last status returned by fitsio library. updated only by several methods */ 88 bool imageOnPrimary_; 87 89 88 90 }; … … 184 186 185 187 void InitNull(); 188 void getHeader(); 186 189 static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum); 187 190 static void GetImageParameters (fitsfile* fileptr,int& bitpix,int& naxis,vector<int>& naxisn); … … 211 214 FitsOutFile(const char * flnm, WriteMode wrm = unknown ); 212 215 ~FitsOutFile() { ;}; 213 inline void InitNull() { imageOnPrimary_=false;}216 inline void InitNull() {;} 214 217 215 218 ////////////////////////////////////////////////////////// … … 224 227 225 228 226 inline void firstImageOnPrimaryHeader() {imageOnPrimary_=true;}227 229 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn, DVList* dvl) ; 228 230 void PutImageToFits( int nbData, double* map) const; … … 261 263 void addKeywordsOfDVList(DVList& dvl) const; 262 264 263 bool imageOnPrimary_;264 265 265 266 }; -
trunk/SophyaExt/FitsIOServer/fitsspherehealpix.cc
r1221 r1234 231 231 } 232 232 FitsOutFile fout(filename); 233 fout.firstImageOnPrimaryHeader( );233 fout.firstImageOnPrimaryHeader(true); 234 234 FITS_TArray<r_4> fta(map); 235 235 fta.Write(fout); … … 262 262 } 263 263 FitsOutFile fout(filename); 264 fout.firstImageOnPrimaryHeader( );264 fout.firstImageOnPrimaryHeader(true); 265 265 FITS_TArray<r_4> fta(map); 266 266 fta.Write(fout);
Note:
See TracChangeset
for help on using the changeset viewer.