Changeset 971 in Sophya
- Timestamp:
- Apr 27, 2000, 6:09:34 PM (25 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsfile.cc
r949 r971 74 74 vector<char> types; 75 75 vector<int> taille_des_chaines; 76 GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines); 77 for (int k=0; k< naxisn.size(); k++) naxisn[k] *= nrows; 76 GetBinTabParameters(fileptr, naxis, nrows, naxisn, noms, types, taille_des_chaines); 77 int k; 78 for (k=0; k< naxisn.size(); k++) naxisn[k] *= nrows; 78 79 if(hdutype == ASCII_TBL) 79 80 { … … 104 105 } 105 106 106 fits_movabs_hdu(fileptr,hdunum,&hdutype,&status); 107 if( status ) printerror( status,"getBlockType: erreur movabs, pour dvlist"); 108 KeywordsIntoDVList(fileptr, dvl); 107 KeywordsIntoDVList(fileptr, dvl, hdunum); 109 108 fits_close_file(fileptr,&status); 110 109 } … … 114 113 int status = 0; 115 114 hdutype_= 0; 116 hdunum_ = 0;115 117 116 fits_open_file(&fptr_,flnm,READONLY,&status); 118 117 if( status ) printerror( status ); 119 120 // move to the specified HDU number 118 // 119 if (hdunum <= 1) 120 { 121 hdunum_ = 1; 122 // presence of image ? 123 int naxis= 0; 124 fits_read_key(fptr_,TINT,"NAXIS",&naxis,NULL,&status); 125 if( status ) printerror( status ); 126 if (naxis > 0 ) // there is an image 127 { 128 hdutype_ == IMAGE_HDU; 129 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 130 nbData_ = 1; 131 int k; 132 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 133 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 134 } 135 else 136 { 137 throw PException(" first header : no image, probably error in hdunum"); 138 } 139 // 140 } 141 else 142 { 143 hdunum_ = hdunum-1; 144 int hdutype; 145 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 146 if( status ) printerror( status,":FitsFile::ReadF : erreur movabs"); 147 moveToFollowingHeader(); 148 } 149 ReadFromFits(*this); 150 } 151 152 153 void FitsFile::moveToFollowingHeader() 154 { 155 int status = 0; 121 156 int hdutype; 122 fits_mov abs_hdu(fptr_,hdunum,&hdutype,&status);123 if( status ) printerror( status );124 157 fits_movrel_hdu(fptr_, 1,&hdutype,&status); 158 if( status ) printerror( status," lecture du header suivant" ); 159 hdunum_++; 125 160 hdutype_= hdutype; 126 hdunum_ = hdunum;127 161 if(hdutype_ == IMAGE_HDU) 128 162 { 129 163 GetImageParameters (fptr_, bitpix_, naxis_, naxisn_); 130 164 nbData_ = 1; 131 for (int k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 132 fits_movabs_hdu(fptr_,hdunum,&hdutype,&status); 133 if( status ) printerror( status); 134 KeywordsIntoDVList(fptr_, dvl_); 165 int k; 166 for (k=0; k<naxis_; k++) if (naxisn_[k] > 0) nbData_ *= naxisn_[k]; 167 KeywordsIntoDVList(fptr_, dvl_,hdunum_); 135 168 } 136 169 if(hdutype_ == ASCII_TBL || hdutype_ == BINARY_TBL) 137 170 { 138 171 GetBinTabParameters(fptr_,nbcols_, nrows_,repeat_, noms_, types_, taille_des_chaines_); 139 fits_movabs_hdu(fptr_,hdunum,&hdutype,&status); 140 if( status ) printerror( status); 141 KeywordsIntoDVList(fptr_, dvl_); 142 } 143 ReadFromFits(*this); 144 145 } 146 void FitsFile::WriteF(char flnm[],int hdunum) 172 KeywordsIntoDVList(fptr_, dvl_, hdunum_); 173 } 174 } 175 176 177 void FitsFile::WriteF(char flnm[], bool OldFile) 147 178 { 148 179 int status = 0; 149 180 hdutype_= 0; 150 hdunum_ = hdunum; 181 hdunum_ = 0; 182 183 151 184 // create new FITS file 152 fits_create_file(&fptr_,flnm,&status); 153 if( status ) printerror(status,"file already exists"); 185 if (!OldFile) 186 { 187 fits_create_file(&fptr_,flnm,&status); 188 if( status ) printerror(status,"file already exists"); 189 } 190 else 191 { 192 fits_open_file(&fptr_,flnm,READWRITE,&status); 193 if( status ) printerror(status,"file does not exist"); 194 fits_get_num_hdus(fptr_, &hdunum_, &status); 195 int hdutype; 196 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 197 if( status ) printerror( status,":FitsFile::WriteF : erreur movabs"); 198 199 } 154 200 WriteToFits(*this); 155 201 } … … 245 291 } 246 292 } 247 void FitsFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn) const293 void FitsFile::makeHeaderImageOnFits(char type, int nbdim, int* naxisn) 248 294 { 249 295 int status = 0; 250 296 long naxis = nbdim; 251 297 long* naxes = new long[nbdim]; 252 for (int k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k]; 298 int k; 299 for (k=0; k< nbdim; k++) naxes[k] = (long)naxisn[k]; 253 300 if (type == 'D') 254 301 fits_create_img(fptr_,DOUBLE_IMG,naxis,naxes,&status); … … 264 311 throw PException("FitsFile:::makeHeaderImageOnFits:unprogrammed type of data "); 265 312 } 313 314 hdunum_++; 266 315 delete [] naxes; 267 316 if( status ) printerror( status ); … … 320 369 if (nfound != naxis ) 321 370 cout << " WARNING : " << nfound << " axes found, expected naxis= " << naxis << endl; 322 for (int k=0; k<naxis; k++) 371 int k; 372 for (k=0; k<naxis; k++) 323 373 { 324 374 naxisn.push_back( (int)naxes[k] ); … … 327 377 } 328 378 329 void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl) 330 { 379 void FitsFile::KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum) 380 { 381 int status = 0; 382 int hdutype; 383 fits_movabs_hdu(fileptr,hdunum,&hdutype,&status); 384 if( status ) printerror( status,":KeywordsIntoDVList : erreur movabs"); 331 385 // get number of keywords 332 386 int nkeys,keypos; 333 int status = 0;334 387 fits_get_hdrpos(fileptr,&nkeys,&keypos,&status); 335 388 if( status ) printerror( status ); … … 345 398 int num= 8; 346 399 347 for(int j = num+1; j <= nkeys; j++) 400 int j; 401 for(j = num+1; j <= nkeys; j++) 348 402 { 349 403 fits_read_keyn(fileptr,j,card,strval,NULL,&status); … … 403 457 } 404 458 long nels=nentries; 459 int anull; 405 460 // no checking for undefined pixels 406 int anull; 407 float dnull= 0.; 461 double dnull= 0.; 462 // fits_read_key(fptr_,TDOUBLE,"BAD_DATA",&dnull,NULL,&status); 463 // if (status != 0) 464 // { 465 // dnull = -1.6375e30; // default value 466 // status = 0; 467 // } 468 if (nentries != nrows_*repeat) 469 { 470 cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl; 471 throw PException(" FitsFile:::GetBinTabFCol "); 472 } 408 473 fits_read_col(fptr_,TDOUBLE,NoCol+1,1,1,nels,&dnull,valeurs, 409 474 &anull,&status); 410 475 if( status ) printerror( status,"erreur lecture de colonne" ); 476 411 477 } 412 478 … … 422 488 } 423 489 long nels=nentries; 490 int anull; 424 491 // no checking for undefined pixels 425 int anull;426 492 float fnull= 0.; 493 // fits_read_key(fptr_,TFLOAT,"BAD_DATA",&fnull,NULL,&status); 494 // if (status != 0) 495 // { 496 // fnull = -1.6375e30; // default value 497 // status = 0; 498 // } 499 if (nentries != nrows_*repeat) 500 { 501 cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl; 502 throw PException(" FitsFile:::GetBinTabFCol "); 503 } 427 504 fits_read_col(fptr_,TFLOAT,NoCol+1,1,1,nels,&fnull,valeurs, 428 505 &anull,&status); … … 431 508 void FitsFile::GetBinTabFCol(int* valeurs,int nentries, int NoCol) const 432 509 { 510 cout <<" entree GetBinTabFCol " << endl; 433 511 int status= 0; 434 512 int DTYPE; … … 443 521 int anull; 444 522 int inull= 0; 523 // fits_read_key(fptr_,TINT,"BAD_DATA",&inull,NULL,&status); 524 // if (status != 0) 525 // { 526 // inull = -999999; // default value 527 // status = 0; 528 // } 529 if (nentries != nrows_*repeat) 530 { 531 cout << " found " << nentries << " pixels, expected: " << nrows_*repeat << endl; 532 throw PException(" FitsFile:::GetBinTabFCol "); 533 } 445 534 fits_read_col(fptr_,TINT,NoCol+1,1,1,nels,&inull,valeurs, 446 535 &anull,&status); … … 460 549 // no checking for undefined pixels 461 550 int anull; 462 char* cnull= " "; 551 char* cnull= ""; 552 if (nentries != nrows_*repeat/width) 553 { 554 cout << " found " << nentries << " pixels, expected: " << nrows_*repeat/width << endl; 555 throw PException(" FitsFile:::GetBinTabFCol "); 556 } 463 557 long frow=1; 464 558 long felem=1; … … 521 615 } 522 616 int index=-1; 523 for (int k=0; k<=nocol; k++) 617 int k; 618 for (k=0; k<=nocol; k++) 524 619 { 525 620 if (types_[k] == 'S') index++; … … 617 712 618 713 619 void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const714 void FitsFile::makeHeaderBntblOnFits( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) 620 715 { 621 716 int status = 0; … … 633 728 634 729 635 for (int k=0; k<tfields;k++) 730 int k; 731 for (k=0; k<tfields;k++) 636 732 { 637 733 char format[FLEN_VALUE]; … … 671 767 strcpy(tform[k],format); 672 768 } 673 const char* TypeOfContent= dvl.GetS("TypeOfContent").c_str();674 769 // value of the EXTNAME keyword 675 770 char extn[FLEN_VALUE]; … … 684 779 if( status ) printerror( status ); 685 780 686 for(int ii = 0; ii < tfields; ii++) 781 hdunum_++; 782 int ii; 783 for(ii = 0; ii < tfields; ii++) 687 784 { 688 785 delete [] ttype[ii]; … … 696 793 // get names and values from the join DVList object 697 794 // dvl.Print(); 795 fits_write_comment(fptr_,"--------------------------------------", &status); 698 796 DVList::ValList::const_iterator it; 699 797 for(it = dvl.Begin(); it != dvl.End(); it++) … … 708 806 { 709 807 int ival=(*it).second.elval.mtv.iv; 710 str cpy(comment,"I entier");808 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT ); 711 809 fits_write_key(fptr_,TINT,keyname,&ival,comment,&status); 712 810 break; … … 715 813 { 716 814 double dval=(*it).second.elval.mtv.dv; 717 str cpy(comment,"D double");815 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT ); 718 816 fits_write_key(fptr_,TDOUBLE,keyname,&dval,comment,&status); 719 817 break; … … 723 821 char strval[128]; 724 822 strncpy(strval,(*it).second.elval.mtv.strv,127); 725 str cpy(comment,"S character string");823 strncpy(comment,(*it).second.elcomm.c_str(),FLEN_COMMENT ); 726 824 fits_write_key(fptr_,TSTRING,keyname,&strval,comment,&status); 727 825 break; … … 730 828 if( status ) printerror( status,"fitsfile: probleme ecriture mot-cle du dvlist" ); 731 829 } 830 fits_write_comment(fptr_,"--------------------------------------", &status); 732 831 733 832 } … … 736 835 { 737 836 int status = 0; 738 int hdutype , hdunum;837 int hdutype; 739 838 fits_movabs_hdu(fptr_,hdunum_,&hdutype,&status); 740 839 if( status ) printerror(status,"putColToFits: le movabs a foire"); … … 745 844 throw IOExc("FitsFile::putColToFits, this HDU is not an ASCII table nor a binary table"); 746 845 } 747 // if(hdutype == ASCII_TBL && nocol>0)748 // {749 // throw IOExc("FitsFile::putColToFits, this HDU is an ASCII table, nocol>0 forbidden");750 // }751 846 int code; 752 847 long repeat, width; … … 806 901 if( code != TLONG && code != TINT && code != TSHORT ) 807 902 { 808 cout << " WARNING : types don't match (putColToFits) : on fits file= " << code << " (FITS code), to be written= FLOAT " << endl;903 cout << " WARNING : types don't match (putColToFits) : on fits file= " << code << " (FITS code), to be written= INT " << endl; 809 904 } 810 905 fits_write_col(fptr_,TINT,nocol+1,1,1,nentries, donnees ,&status); 811 if( status ) printerror( status," erreurecriture du fichier fits" );906 if( status ) printerror( status," ecriture du fichier fits" ); 812 907 } 813 908 void FitsFile::putColToFits(int nocol, int nentries, char** donnees) const … … 857 952 858 953 cout << " Header listing for HDU : " << hdunum_ << endl; 859 for(int jj = 1; jj <= nkeys; jj++) 954 int jj; 955 for(jj = 1; jj <= nkeys; jj++) 860 956 { 861 957 if( fits_read_record(fptr_,jj,card,&status) ) … … 875 971 char strval[FLEN_VALUE]; 876 972 char comment[FLEN_COMMENT]; 877 878 strcpy(keyname,"CREATOR"); 879 strcpy(strval,"SOPHYA"); 880 strcpy(comment,"SOPHYA Package - FitsFile"); 881 fits_write_key(fptr_,TSTRING,keyname,&strval,comment,&status); 973 strncpy(keyname, "CREATOR", LEN_KEYWORD); 974 keyname[LEN_KEYWORD-1] = '\0'; 975 strcpy(strval, "SOPHYA"); 976 strcpy(comment," SOPHYA Package - FITSIOServer "); 977 fits_write_key(fptr_, TSTRING, keyname, &strval, comment, &status); 978 if( status ) printerror( status ); 979 980 fits_write_comment(fptr_,"..............................................", &status); 981 fits_write_comment(fptr_, " SOPHYA package - FITSIOSever ", &status); 982 fits_write_comment(fptr_, " (C) LAL/IN2P3-CNRS Orsay, FRANCE 2000", &status); 983 fits_write_comment(fptr_, " (C) DAPNIA/CEA Saclay, FRANCE 2000", &status); 984 fits_write_comment(fptr_,"..............................................", &status); 985 if( status ) printerror( status ); 882 986 } 883 987 -
trunk/SophyaExt/FitsIOServer/fitsfile.h
r903 r971 76 76 77 77 */ 78 void WriteF(char flnm[], int hdunum= 0);78 void WriteF(char flnm[], bool OldFile=false); 79 79 80 80 … … 188 188 \param <naxisn> array containind sizes of the different dimensions 189 189 */ 190 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) const;190 void makeHeaderImageOnFits(char type, int nbdim, int* naxisn) ; 191 191 192 192 /*! create an BINTABLE header on FITS file. … … 199 199 \param <taille_des_chaines> vector containing the number of characters of data for each char* typed column, with order of appearance in 'fieldType' 200 200 */ 201 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) const; 202 201 void makeHeaderBntblOnFits ( char* fieldType, char** Noms, int nentries, int tfields, DVList &dvl, char* extname, vector<int> taille_des_chaines) ; 202 203 void moveToFollowingHeader(); 203 204 void readheader(); 204 205 static void printerror(int&) ; 205 206 static void printerror(int&,char* texte) ; 206 207 protected: 207 virtual void ReadFromFits( constFitsFile& ff)=0;208 virtual void WriteToFits( constFitsFile& ff)=0;208 virtual void ReadFromFits(FitsFile& ff)=0; 209 virtual void WriteToFits(FitsFile& ff)=0; 209 210 private: 210 211 … … 215 216 vector<char>& types, 216 217 vector<int>& taille_des_chaines); 217 static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl );218 static void KeywordsIntoDVList(fitsfile* fileptr, DVList& dvl, int hdunum); 218 219 void writeSignatureOnFits() const; 219 220
Note:
See TracChangeset
for help on using the changeset viewer.