Changeset 488 in Sophya for trunk/SophyaExt
- Timestamp:
- Oct 21, 1999, 4:03:55 PM (26 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsioserver.cc
r482 r488 1 1 //************************************************************************ 2 2 // Class for loadind and saving from FITS-formatted file to DPC objects 3 // 3 // (G. Le Meur ; Francois Touze) OCT. 99 4 // 4 5 // methods 'load(X& x, char f[])' get from FITS file "f" a DPC object x 5 6 // from DPC class X. … … 28 29 nbcols=n2; 29 30 if (naxis == 1) nbcols=1; 30 //dvl.Print();31 DVList::ValList::const_iterator it;32 for(it = dvl.Begin(); it != dvl.End(); it++)33 {34 char datatype= (*it).second.typ;35 char keyname[]="";36 strcpy(keyname, (*it).first.substr(0,64).c_str());37 int ival=0;38 double dval=0.;39 char strval[]="";40 switch (datatype)41 {42 case 'I' :43 ival=(*it).second.mtv.iv;44 break;45 case 'D' :46 dval=(*it).second.mtv.dv;47 break;48 case 'S' :49 strcpy(strval, (*it).second.mtv.strv);50 break;51 default :52 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;53 break;54 }55 }56 57 31 if (naxis > 2) 58 32 { … … 72 46 int ij=0; 73 47 for (int j=0; j< nbcols; j++) 74 for (int i = 0; i < nbrows; i++) mat(i,j) = dtab_[ij++];48 for (int i = 0; i < nbrows; i++) mat(i,j) = (double)r_8tab_[ij++]; 75 49 } 76 50 … … 100 74 printerror( status ); 101 75 102 /*103 printf("Move to extensions by name and version number: (ffmnhd)\n");104 char* binname= "Test-BINTABLE";105 int extvers = 1;106 fits_movnam_hdu(fptr,ANY_HDU, binname,extvers,&status);107 fits_get_hdu_num(fptr,&hdunum);108 printf(" %s, %ld = hdu %d, %d\n", binname, extvers, hdunum, status);109 */110 76 111 77 if (hdutype == BINARY_TBL) … … 128 94 printerror( status ); 129 95 int nrows= naxis[1]; 130 131 printf("\nInformation about each column:\n");132 96 133 97 //Information about each column … … 151 115 num += nfound; 152 116 153 for(int ii = 0; ii < tfields; ii++)154 printf("\nColumn name & Format %8s %8s", ttype[ii],tform[ii]);117 //for(int ii = 0; ii < tfields; ii++) 118 // printf("\nColumn name & Format %8s %8s", ttype[ii],tform[ii]); 155 119 156 // select the columns with float data values (typecode = 42)120 // select the columns with float data values 157 121 int typecode; 158 122 long repeat,width; … … 162 126 fits_binary_tform(tform[ii],&typecode, &repeat, &width, &status); 163 127 //printf("\n%4s %3d %2ld %2ld", tform[ii], typecode, repeat, width); 164 if(typecode == 42)128 if(typecode == TFLOAT) 165 129 column.push_back(ii+1); 166 130 } … … 176 140 for(itr= column.begin(); itr != column.end(); itr++) 177 141 strcpy(clname[index++],ttype[*itr-1]); 142 143 for( int ii = 0; ii < tfields; ii++) 144 { 145 delete [] ttype[ii]; 146 delete [] tform[ii]; 147 } 148 delete [] ttype; 149 delete [] tform; 150 178 151 179 152 // check if the specified keyword BLK exists … … 184 157 printerror( status ); 185 158 } 186 187 159 // create a NTuple 188 160 NTuple nt0(column.size(),clname,blk); 161 162 for(int ii = 0; ii < column.size(); ii++) 163 delete [] clname[ii]; 164 delete [] clname; 189 165 190 166 float value[1]; … … 278 254 int npixels=0; 279 255 int nside=0; 256 long naxis; 257 int n1, n2, n3; 258 280 259 FITS_tab_typ_ = TDOUBLE; 281 read_sphere(flnm, npixels, nside); 282 260 261 DVList dvl; 262 planck_read_img(flnm, naxis, n1, n2, n3, dvl); 263 if (naxis != 1) 264 { 265 cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl; 266 } 267 npixels=n1; 268 nside= dvl.GetI("NSIDE"); 269 283 270 // number of pixels in the sphere 284 271 if (sph.NbPixels() != npixels) … … 302 289 } 303 290 } 304 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= dtab_[j];291 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (double)r_8tab_[j]; 305 292 } 306 293 void FitsIoServer::load(SphericalMap<float>& sph, char flnm[]) … … 308 295 int npixels=0; 309 296 int nside=0; 297 long naxis; 298 int n1, n2, n3; 299 DVList dvl; 300 310 301 FITS_tab_typ_ = TFLOAT; 311 read_sphere(flnm, npixels, nside); 302 303 planck_read_img(flnm, naxis, n1, n2, n3, dvl); 304 if (naxis != 1) 305 { 306 cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl; 307 } 308 npixels=n1; 309 nside= dvl.GetI("NSIDE"); 310 312 311 // number of pixels in the sphere 313 312 if (sph.NbPixels() != npixels) … … 331 330 } 332 331 } 333 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= ftab_[j];332 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (float)r_4tab_[j]; 334 333 } 335 334 336 335 void FitsIoServer::load(LocalMap<double>& lcm, char flnm[]) 337 336 { 338 int nside;339 337 int nbrows=0; 340 338 int nbcols=0; … … 350 348 { 351 349 cout<<" FitsIOServer : le fichier fits n'est pas une localmap, naxis= "<<naxis<<endl; 352 }353 //dvl.Print();354 DVList::ValList::const_iterator it;355 for(it = dvl.Begin(); it != dvl.End(); it++)356 {357 char datatype= (*it).second.typ;358 char keyname[]="";359 strcpy(keyname, (*it).first.substr(0,64).c_str());360 int ival=0;361 double dval=0.;362 char strval[]="";363 switch (datatype)364 {365 case 'I' :366 ival=(*it).second.mtv.iv;367 break;368 case 'D' :369 dval=(*it).second.mtv.dv;370 break;371 case 'S' :372 strcpy(strval, (*it).second.mtv.strv);373 break;374 default :375 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;376 break;377 }378 if (!strcmp(keyname, "NSIDE") )379 {380 nside = ival;381 }382 //if (!strcmp(keyname, "ORDERING") )383 // {384 // cout << " j'ai trouve ORDERING " << endl;385 // }386 350 } 387 351 float theta0 = dvl.GetD("THETA0"); … … 410 374 int ij=0; 411 375 for (int j=0; j< nbcols; j++) 412 for (int i = 0; i < nbrows; i++) lcm(i,j) = dtab_[ij++];376 for (int i = 0; i < nbrows; i++) lcm(i,j) = (double)r_8tab_[ij++]; 413 377 } 414 378 … … 432 396 DpcImg.Allocate(siz_x, siz_y, 0., 0); 433 397 float* pixelPtr=DpcImg.ImagePtr(); 434 //for (int i=0; i < siz_x*siz_y; i++) pixelPtr[i]=ftab_[i];435 398 // verifications de type 436 399 PBaseDataTypes dataT=DataType((r_4)0); … … 438 401 if (int(dataT) != TypeDonnees) 439 402 { 440 cout << " FitsIOServer : parameter DATATYPE on file is not float " << endl;403 cout << " FitsIOServer : parameter DATATYPE on file " << flnm << " is not float " << endl; 441 404 cout << " eventual conversion to float is achieved by cfitsio lib " << endl; 442 405 } 443 406 444 memcpy(pixelPtr, ftab_, siz_x*siz_y*DataSize(dataT));407 memcpy(pixelPtr, r_4tab_, siz_x*siz_y*DataSize(dataT)); 445 408 const char* nom=dvl.GetS("NAME").c_str(); 446 409 DpcImg.SetNameId(dvl.GetI("IDENT"), nom); … … 489 452 if (int(dataT) != TypeDonnees) 490 453 { 491 cout << " FitsIOServer : parameter DATATYPE on file is not int_4 " << endl;492 cout << " eventual conversion to floatis achieved by cfitsio lib " << endl;454 cout << " FitsIOServer : parameter DATATYPE on file " << flnm << " is not int_4 " << endl; 455 cout << " eventual conversion to int_4 is achieved by cfitsio lib " << endl; 493 456 } 494 457 memcpy(pixelPtr, i_4tab_, siz_x*siz_y*DataSize(dataT)); … … 510 473 cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl; 511 474 FITS_tab_typ_ = TDOUBLE; 512 if ( dtab_ != NULL ) delete[] dtab_;513 dtab_=new double[nbrows*nbcols];475 if (r_8tab_ != NULL ) delete[] r_8tab_; 476 r_8tab_=new r_8[nbrows*nbcols]; 514 477 515 478 516 479 int ij=0; 517 480 for (int j=0; j< nbcols; j++) 518 for (int i = 0; i < nbrows; i++) dtab_[ij++]=mat(i,j);481 for (int i = 0; i < nbrows; i++) r_8tab_[ij++]= (r_8)mat(i,j); 519 482 520 483 DVList dvl; 521 484 522 485 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); 523 486 delete[] r_8tab_; 524 487 } 525 488 … … 568 531 NULL,extname,&status) ) 569 532 printerror( status ); 533 534 for( int ii = 0; ii < tfields; ii++) 535 { 536 delete [] ttype[ii]; 537 delete [] tform[ii]; 538 } 539 delete [] ttype; 540 delete [] tform; 541 570 542 571 543 // first row in table to write … … 642 614 int npixels = sph.NbPixels(); 643 615 FITS_tab_typ_ = TDOUBLE; 644 if ( dtab_ != NULL ) delete[] dtab_;645 dtab_=new double[npixels];646 647 648 for (int j = 0; j < npixels; j++) dtab_[j]=sph(j);616 if (r_8tab_ != NULL ) delete[] r_8tab_; 617 r_8tab_=new r_8[npixels]; 618 619 620 for (int j = 0; j < npixels; j++) r_8tab_[j]= (r_8)sph(j); 649 621 DVList dvl; 650 622 dvl["NSIDE"] = sph.SizeIndex(); … … 694 666 */ 695 667 696 668 delete[] r_8tab_; 697 669 } 698 670 … … 701 673 int npixels = sph.NbPixels(); 702 674 FITS_tab_typ_ = TFLOAT; 703 if ( ftab_ != NULL ) delete[] ftab_;704 ftab_=new float[npixels];705 706 707 for (int j = 0; j < npixels; j++) ftab_[j]=sph(j);675 if (r_4tab_ != NULL ) delete[] r_4tab_; 676 r_4tab_=new r_4[npixels]; 677 678 679 for (int j = 0; j < npixels; j++) r_4tab_[j]= (r_4)sph(j); 708 680 DVList dvl; 709 681 dvl["NSIDE"] = sph.SizeIndex(); … … 711 683 712 684 planck_write_img(filename, 1, npixels, 0, 0, dvl); 713 685 delete[] r_4tab_; 714 686 715 687 } … … 722 694 cout << " nombre de pts en x : " << nbrows << " en y " << nbcols << endl; 723 695 FITS_tab_typ_ = TDOUBLE; 724 if ( dtab_ != NULL ) delete[] dtab_;725 dtab_=new double[nbrows*nbcols];696 if (r_8tab_ != NULL ) delete[] r_8tab_; 697 r_8tab_=new r_8[nbrows*nbcols]; 726 698 727 699 int ij=0; 728 700 for (int j=0; j< nbcols; j++) 729 for (int i = 0; i < nbrows; i++) dtab_[ij++]=locm(i,j);701 for (int i = 0; i < nbrows; i++) r_8tab_[ij++]= (r_8)locm(i,j); 730 702 731 703 DVList dvl; … … 749 721 dvl["ANGLEY"] = angley; 750 722 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); 751 }752 753 754 void FitsIoServer::save( ImageR4& DpcImg,char flnm[])723 delete[] r_8tab_;} 724 725 726 void FitsIoServer::save(const ImageR4& DpcImg,char flnm[]) 755 727 { 756 728 long naxis=2; … … 761 733 762 734 763 // get the values of the DpcImage764 if (ftab_ != NULL) delete [] ftab_;765 ftab_=DpcImg.ImagePtr();766 735 767 736 // write FITS image … … 784 753 dvl["SIGFON"] = DpcImg.sigmaFond; 785 754 786 755 // get the values of the DpcImage 756 if (r_4tab_ != NULL) delete [] r_4tab_; 757 r_4tab_=new r_4[siz_x*siz_y]; 758 PBaseDataTypes dataT=DataType((r_4)0); 759 memcpy( r_4tab_, DpcImg.ImagePtr(), siz_x*siz_y*DataSize(dataT)); 787 760 planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl); 788 761 789 762 790 ftab_=NULL;791 } 792 793 794 void FitsIoServer::save( ImageI4& DpcImg,char flnm[])763 delete [] r_4tab_; 764 } 765 766 767 void FitsIoServer::save(const ImageI4& DpcImg,char flnm[]) 795 768 { 796 769 long naxis=2; … … 813 786 //if( status ) printerror( status ); 814 787 815 // get the values of the DpcImage816 if (i_4tab_ != NULL) delete [] i_4tab_;817 i_4tab_=DpcImg.ImagePtr();818 788 819 789 // write FITS image … … 836 806 dvl["SIGFON"] = DpcImg.sigmaFond; 837 807 808 // get the values of the DpcImage 809 if (i_4tab_ != NULL) delete [] i_4tab_; 810 i_4tab_=new int_4[siz_x*siz_y]; 811 PBaseDataTypes dataT=DataType((int_4)0); 812 memcpy( i_4tab_, DpcImg.ImagePtr(), siz_x*siz_y*DataSize(dataT)); 813 838 814 839 815 planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl); … … 843 819 //if( status ) printerror( status ); 844 820 845 i_4tab_=NULL;821 delete [] i_4tab_; 846 822 } 847 823 … … 852 828 { 853 829 854 cout << " nouveau write_img" << endl;855 830 856 831 // pointer to the FITS file, defined in fitsio.h … … 888 863 { 889 864 case TDOUBLE : 890 fits_write_img(fptr, TDOUBLE, 1, nelements, dtab_, &status);865 fits_write_img(fptr, TDOUBLE, 1, nelements, r_8tab_, &status); 891 866 if( status ) printerror( status ); 892 867 break; 893 868 case TFLOAT : 894 fits_write_img(fptr, TFLOAT, 1, nelements, ftab_, &status);869 fits_write_img(fptr, TFLOAT, 1, nelements, r_4tab_, &status); 895 870 if( status ) printerror( status ); 896 871 break; … … 985 960 if (naxis == 3) nelements*=naxes[2]; 986 961 int anynull; 987 double dnullval=0.; 988 float fnullval=0.; 962 r_8 dnullval=0.; 963 r_4 fnullval=0.; 964 int_4 inullval=0; 989 965 // on laisse a fits le soin de convertir le type du tableau lu vers 990 966 // le type suppose par l'utilisateur de fitsioserver … … 995 971 if (bitpix != DOUBLE_IMG) 996 972 { 997 cout << " FitsIOServer : the data type on fits file is not double, "973 cout << " FitsIOServer : the data type on fits file " << flnm << " is not double, " 998 974 << " conversion to double will be achieved by cfitsio lib " << endl; 999 975 } 1000 if ( dtab_ != NULL) delete [] dtab_;1001 dtab_=new double[nelements];1002 fits_read_img(fptr, TDOUBLE, 1, nelements, &dnullval, dtab_,976 if (r_8tab_ != NULL) delete [] r_8tab_; 977 r_8tab_=new r_8[nelements]; 978 fits_read_img(fptr, TDOUBLE, 1, nelements, &dnullval, r_8tab_, 1003 979 &anynull, &status); 1004 980 if( status ) printerror( status ); … … 1007 983 if (bitpix != FLOAT_IMG) 1008 984 { 1009 cout << " FitsIOServer : the data type on fits file is not float, "985 cout << " FitsIOServer : the data type on fits file " << flnm << " is not float, " 1010 986 << " conversion to float will be achieved by cfitsio lib " << endl; 1011 987 } 1012 if ( ftab_ != NULL) delete [] ftab_;1013 ftab_=new float[nelements];1014 fits_read_img(fptr, TFLOAT, 1, nelements, &fnullval, ftab_,988 if (r_4tab_ != NULL) delete [] r_4tab_; 989 r_4tab_=new r_4[nelements]; 990 fits_read_img(fptr, TFLOAT, 1, nelements, &fnullval, r_4tab_, 1015 991 &anynull, &status); 1016 992 if( status ) printerror( status ); … … 1021 997 if (bitpix != LONG_IMG) 1022 998 { 1023 cout << " FitsIOServer : the data type on fits file is not long, "999 cout << " FitsIOServer : the data type on fits file " << flnm << " is not long, " 1024 1000 << " conversion to long will be achieved by cfitsio lib " << endl; 1025 1001 } 1026 1002 if (i_4tab_ != NULL) delete [] i_4tab_; 1027 1003 i_4tab_=new int_4[nelements]; 1028 fits_read_img(fptr, TINT, 1, nelements, & fnullval, i_4tab_,1004 fits_read_img(fptr, TINT, 1, nelements, &inullval, i_4tab_, 1029 1005 &anynull, &status); 1030 1006 if( status ) printerror( status ); … … 1107 1083 } 1108 1084 1085 1109 1086 // close the file 1110 1087 status=0; … … 1213 1190 } 1214 1191 1215 void FitsIoServer::read_sphere(char flnm[], int& npixels, int& nside)1216 {1217 long naxis;1218 nside=0;1219 int n1, n2, n3;1220 DVList dvl;1221 planck_read_img(flnm, naxis, n1, n2, n3, dvl);1222 1223 npixels=n1;1224 //dvl.Print();1225 DVList::ValList::const_iterator it;1226 for(it = dvl.Begin(); it != dvl.End(); it++)1227 {1228 char datatype= (*it).second.typ;1229 char keyname[]="";1230 strcpy(keyname, (*it).first.substr(0,64).c_str());1231 int ival=0;1232 double dval=0.;1233 char strval[]="";1234 switch (datatype)1235 {1236 case 'I' :1237 ival=(*it).second.mtv.iv;1238 break;1239 case 'D' :1240 dval=(*it).second.mtv.dv;1241 break;1242 case 'S' :1243 strcpy(strval, (*it).second.mtv.strv);1244 break;1245 default :1246 cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl;1247 break;1248 }1249 if (!strcmp(keyname, "NSIDE") )1250 {1251 nside = ival;1252 }1253 //if (!strcmp(keyname, "ORDERING") )1254 // {1255 // cout << " j'ai trouve ORDERING " << endl;1256 // }1257 }1258 1259 if (naxis != 1)1260 {1261 cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl;1262 }1263 }1264 1192 1265 1193 -
trunk/SophyaExt/FitsIOServer/fitsioserver.h
r482 r488 18 18 public : 19 19 20 FitsIoServer() : FITS_tab_typ_(0),i_4tab_(NULL), ftab_(NULL),dtab_(NULL) {;}20 FitsIoServer() : FITS_tab_typ_(0),i_4tab_(NULL),r_4tab_(NULL),r_8tab_(NULL) {;} 21 21 ~FitsIoServer() 22 22 { 23 23 if (i_4tab_ != NULL) delete [] i_4tab_; 24 if ( ftab_ != NULL) delete [] ftab_;25 if ( dtab_ != NULL) delete [] dtab_;24 if (r_4tab_ != NULL) delete [] r_4tab_; 25 if (r_8tab_ != NULL) delete [] r_8tab_; 26 26 } 27 27 … … 38 38 void save(SphericalMap<float>& sph, char flnm[]); 39 39 void save(LocalMap<double>& locm, char flnm[]); 40 void save( ImageR4& DpcImg,char flnm[]);41 void save( ImageI4& DpcImg,char flnm[]);40 void save(const ImageR4& DpcImg,char flnm[]); 41 void save(const ImageI4& DpcImg,char flnm[]); 42 42 void sinus_picture_projection(SphericalMap<double>& sph, char flnm[]); 43 43 void sinus_picture_projection(SphericalMap<float>& sph, char flnm[]); … … 50 50 private : 51 51 52 void read_sphere(char flnm[],int& npixels,int& nside);53 52 54 53 // creer, ecrire une imageformat FITS, a partir des tableaux de donnees … … 81 80 int FITS_tab_typ_; 82 81 int_4* i_4tab_; 83 float* ftab_;84 double* dtab_;82 r_4* r_4tab_; 83 r_8* r_8tab_; 85 84 }; 86 85
Note:
See TracChangeset
for help on using the changeset viewer.