Changeset 605 in Sophya for trunk/SophyaExt
- Timestamp:
- Nov 20, 1999, 9:40:13 PM (26 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsioserver.cc
r603 r605 10 10 //************************************************************************ 11 11 12 #include "machdefs.h" 12 13 #include <iostream.h> 13 14 #include <list> 15 #include <string> 14 16 15 17 #include "fitsioserver.h" 18 #include "pexceptions.h" 16 19 #include "strutil.h" 17 20 … … 49 52 } 50 53 54 void FitsIoServer::load(TMatrix<float>& mat,char flnm[]) 55 { 56 int nbrows=0; 57 int nbcols=0; 58 FITS_tab_typ_ = TFLOAT; 59 long naxis; 60 int n1, n2, n3; 61 DVList dvl; 62 planck_read_img(flnm, naxis, n1, n2, n3, dvl); 63 64 nbrows=n1; 65 nbcols=n2; 66 if (naxis == 1) nbcols=1; 67 if (naxis > 2) 68 { 69 cout<<" FitsIOServer : le fichier fits n'est pas une matrice, naxis= " <<naxis<< endl; 70 } 71 72 // number of components 73 if (mat.NRows() != nbrows || mat.NCols() != nbcols ) 74 { 75 cout << " found " << nbrows << " rows "; 76 cout << " expected " << mat.NRows() << endl; 77 cout << " found " << nbcols << " columns " ; 78 cout << " expected " << mat.NCols() << endl; 79 mat.ReSize(nbrows,nbcols); 80 cout << " resize the vector to nbrows= " << nbrows << " nbcols= " << nbcols << endl; 81 } 82 int ij=0; 83 for (int j=0; j< nbcols; j++) 84 for (int i = 0; i < nbrows; i++) mat(i,j) = (float)r_4tab_[ij++]; 85 } 86 87 void FitsIoServer::load(TMatrix<int_4>& mat,char flnm[]) 88 { 89 int nbrows=0; 90 int nbcols=0; 91 FITS_tab_typ_ = TINT; 92 long naxis; 93 int n1, n2, n3; 94 DVList dvl; 95 planck_read_img(flnm, naxis, n1, n2, n3, dvl); 96 97 nbrows=n1; 98 nbcols=n2; 99 if (naxis == 1) nbcols=1; 100 if (naxis > 2) 101 { 102 cout<<" FitsIOServer : le fichier fits n'est pas une matrice, naxis= " <<naxis<< endl; 103 } 104 105 // number of components 106 if (mat.NRows() != nbrows || mat.NCols() != nbcols ) 107 { 108 cout << " found " << nbrows << " rows "; 109 cout << " expected " << mat.NRows() << endl; 110 cout << " found " << nbcols << " columns " ; 111 cout << " expected " << mat.NCols() << endl; 112 mat.ReSize(nbrows,nbcols); 113 cout << " resize the vector to nbrows= " << nbrows << " nbcols= " << nbcols << endl; 114 } 115 int ij=0; 116 for (int j=0; j< nbcols; j++) 117 for (int i = 0; i < nbrows; i++) mat(i,j) = (int_4)i_4tab_[ij++]; 118 } 119 51 120 void FitsIoServer::load(NTuple& ntpl,char flnm[],int hdunum) 52 121 … … 80 149 { 81 150 printf("Error:: this HDU is not a binary table\n"); 82 exit ( status ); 151 throw IOExc("FitsIoServer::load(NTuple& ," + (string)flnm + ") Error Not a bin table !"); 152 // exit ( status ); 83 153 } 84 154 … … 276 346 { 277 347 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl; 278 exit(0); 348 throw IOExc("FitsIoServer::load(SphericalMap<double>& ," + (string)flnm + ") Error NSide<0 !"); 349 // exit(0); 279 350 } 280 351 if (nside != sph.SizeIndex()) … … 286 357 { 287 358 cout << " FITSIOSERVER : same resolution, surprising ! " << endl; 288 exit(0); 359 // exit(0); $CHECK$ Ca peut etre OK , non ?? Reza 20/11/99 289 360 } 290 361 } … … 320 391 { 321 392 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl; 322 exit(0); 393 throw IOExc("FitsIoServer::load(SphericalMap<float>& ," + (string)flnm + ", ) Error No resolution parameter !"); 394 // exit(0); 323 395 } 324 396 if (nside != sph.SizeIndex()) … … 330 402 { 331 403 cout << " FITSIOSERVER : same resolution, surprising ! " << endl; 332 exit(0); 404 // exit(0); $CHECK$ - Il ne faut pas sortir, me semble-t-il , Reza 20/11/99 333 405 } 334 406 } … … 363 435 { 364 436 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl; 365 exit(0); 437 throw IOExc("FitsIoServer::load(SphereGorski<double>& ," + (string)flnm + ", ) No resol parameter !"); 438 // exit(0); 366 439 } 367 440 if (nside != sph.SizeIndex()) … … 373 446 { 374 447 cout << " FITSIOSERVER : same resolution, surprising ! " << endl; 375 exit(0); 448 // exit(0); $CHECK$ - ne pas sortir , Reza 20/11/99 376 449 } 377 450 } … … 405 478 { 406 479 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl; 407 exit(0); 480 throw IOExc("FitsIoServer::load(SphericalMap<float>& ," + (string)flnm + ") No resolution param !"); 481 // exit(0); 408 482 } 409 483 if (nside != sph.SizeIndex()) … … 415 489 { 416 490 cout << " FITSIOSERVER : same resolution, surprising ! " << endl; 417 exit(0); 491 // exit(0); $CHECK$ - Ne pas sortir , Reza 20/11/99 418 492 } 419 493 } … … 561 635 cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl; 562 636 FITS_tab_typ_ = TDOUBLE; 563 if (r_8tab_ != NULL ) delete[] r_8tab_;637 if (r_8tab_ != NULL ) { delete[] r_8tab_; r_8tab_ = NULL; } 564 638 r_8tab_=new r_8[nbrows*nbcols]; 565 639 … … 572 646 573 647 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); 574 delete[] r_8tab_; 575 } 648 delete[] r_8tab_; r_8tab_ = NULL; 649 } 650 651 void FitsIoServer::save( TMatrix<float>& mat, char filename[]) 652 { 653 int nbrows = mat.NRows(); 654 int nbcols = mat.NCols(); 655 long naxis = nbcols > 1 ? 2 : 1; 656 cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl; 657 FITS_tab_typ_ = TFLOAT; 658 if (r_4tab_ != NULL ) { delete[] r_4tab_; r_4tab_ = NULL; } 659 r_4tab_=new r_4[nbrows*nbcols]; 660 661 662 int ij=0; 663 for (int j=0; j< nbcols; j++) 664 for (int i = 0; i < nbrows; i++) r_4tab_[ij++]= (r_4)mat(i,j); 665 666 DVList dvl; 667 668 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); 669 delete[] r_4tab_; r_4tab_ = NULL; 670 } 671 672 void FitsIoServer::save( TMatrix<int_4>& mat, char filename[]) 673 { 674 int nbrows = mat.NRows(); 675 int nbcols = mat.NCols(); 676 long naxis = nbcols > 1 ? 2 : 1; 677 cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl; 678 FITS_tab_typ_ = TINT; 679 if (i_4tab_ != NULL ) { delete[] i_4tab_; i_4tab_ = NULL; } 680 i_4tab_=new int_4[nbrows*nbcols]; 681 682 683 int ij=0; 684 for (int j=0; j< nbcols; j++) 685 for (int i = 0; i < nbrows; i++) i_4tab_[ij++]= (int_4)mat(i,j); 686 687 DVList dvl; 688 689 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); 690 delete[] i_4tab_; i_4tab_ = NULL; 691 } 692 576 693 577 694 void FitsIoServer::save(NTuple& ntpl,char flnm[]) … … 702 819 int npixels = sph.NbPixels(); 703 820 FITS_tab_typ_ = TDOUBLE; 704 if (r_8tab_ != NULL ) delete[] r_8tab_;821 if (r_8tab_ != NULL ) { delete[] r_8tab_; r_8tab_ = NULL; } 705 822 r_8tab_=new r_8[npixels]; 706 823 … … 754 871 */ 755 872 756 delete[] r_8tab_; 873 delete[] r_8tab_; r_8tab_ = NULL; 757 874 } 758 875 … … 761 878 int npixels = sph.NbPixels(); 762 879 FITS_tab_typ_ = TFLOAT; 763 if (r_4tab_ != NULL ) delete[] r_4tab_;880 if (r_4tab_ != NULL ) { delete[] r_4tab_; r_4tab_ = NULL; } 764 881 r_4tab_=new r_4[npixels]; 765 882 … … 771 888 772 889 planck_write_img(filename, 1, npixels, 0, 0, dvl); 773 delete[] r_4tab_; 890 delete[] r_4tab_; r_4tab_ = NULL; 774 891 775 892 } … … 778 895 int npixels = sph.NbPixels(); 779 896 FITS_tab_typ_ = TFLOAT; 780 if (r_4tab_ != NULL ) delete[] r_4tab_;897 if (r_4tab_ != NULL ) { delete[] r_4tab_; r_4tab_ = NULL; } 781 898 r_4tab_=new r_4[npixels]; 782 899 … … 793 910 char* comment1=" Sky Map Pixelisation Specific Keywords"; 794 911 planck_write_bntbl(filename, npixels, typeOfContent, extname, comment1, dvl); 795 delete[] r_4tab_; 912 delete[] r_4tab_; r_4tab_ = NULL; 796 913 797 914 } … … 800 917 int npixels = sph.NbPixels(); 801 918 FITS_tab_typ_ = TDOUBLE; 802 if (r_8tab_ != NULL ) delete[] r_8tab_;919 if (r_8tab_ != NULL ) { delete[] r_8tab_; r_8tab_ = NULL; } 803 920 r_8tab_=new r_8[npixels]; 804 921 … … 815 932 char* comment1=" Sky Map Pixelisation Specific Keywords"; 816 933 planck_write_bntbl(filename, npixels, typeOfContent, extname, comment1, dvl); 817 delete[] r_8tab_; 934 delete[] r_8tab_; r_8tab_ = NULL; 818 935 819 936 } … … 826 943 cout << " nombre de pts en x : " << nbrows << " en y " << nbcols << endl; 827 944 FITS_tab_typ_ = TDOUBLE; 828 if (r_8tab_ != NULL ) delete[] r_8tab_;945 if (r_8tab_ != NULL ) { delete[] r_8tab_; r_8tab_ = NULL; } 829 946 r_8tab_=new r_8[nbrows*nbcols]; 830 947 … … 853 970 dvl["ANGLEY"] = angley; 854 971 planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); 855 delete[] r_8tab_;} 972 delete[] r_8tab_; r_8tab_ = NULL; 973 } 856 974 857 975 … … 894 1012 895 1013 // get the values of the DpcImage 896 if (r_4tab_ != NULL) delete [] r_4tab_;1014 if (r_4tab_ != NULL) { delete [] r_4tab_; r_4tab_ = NULL; } 897 1015 r_4tab_=new r_4[siz_x*siz_y]; 898 1016 PBaseDataTypes dataT=DataType((r_4)0); … … 901 1019 902 1020 903 delete [] r_4tab_; 1021 delete [] r_4tab_; r_4tab_ = NULL; 904 1022 } 905 1023 … … 954 1072 955 1073 // get the values of the DpcImage 956 if (i_4tab_ != NULL) delete [] i_4tab_;1074 if (i_4tab_ != NULL) { delete [] i_4tab_; i_4tab_ = NULL; } 957 1075 i_4tab_=new int_4[siz_x*siz_y]; 958 1076 PBaseDataTypes dataT=DataType((int_4)0); … … 966 1084 //if( status ) printerror( status ); 967 1085 968 delete [] i_4tab_; 1086 delete [] i_4tab_; i_4tab_ = NULL; 969 1087 } 970 1088 … … 1260 1378 << " conversion to double will be achieved by cfitsio lib " << endl; 1261 1379 } 1262 if (r_8tab_ != NULL) delete [] r_8tab_;1380 if (r_8tab_ != NULL) { delete [] r_8tab_; r_8tab_ = NULL; } 1263 1381 r_8tab_=new r_8[nelements]; 1264 1382 fits_read_img(fptr, TDOUBLE, 1, nelements, &dnullval, r_8tab_, … … 1272 1390 << " conversion to float will be achieved by cfitsio lib " << endl; 1273 1391 } 1274 if (r_4tab_ != NULL) delete [] r_4tab_;1392 if (r_4tab_ != NULL) { delete [] r_4tab_; r_4tab_ = NULL; } 1275 1393 r_4tab_=new r_4[nelements]; 1276 1394 fits_read_img(fptr, TFLOAT, 1, nelements, &fnullval, r_4tab_, … … 1286 1404 << " conversion to long will be achieved by cfitsio lib " << endl; 1287 1405 } 1288 if (i_4tab_ != NULL) delete [] i_4tab_;1406 if (i_4tab_ != NULL) { delete [] i_4tab_; i_4tab_ = NULL; } 1289 1407 i_4tab_=new int_4[nelements]; 1290 1408 fits_read_img(fptr, TINT, 1, nelements, &inullval, i_4tab_, … … 1400 1518 { 1401 1519 cout << "FitsIoServer:: le fichier fits ne contient pas d'extension binary table" << endl; 1402 return; 1520 throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error No bin table extension !"); 1521 // return; 1403 1522 } 1404 1523 fits_movabs_hdu(fptr, hdunum,&hdutype,&status); … … 1407 1526 { 1408 1527 cout << "FitsIoServer:: this HDU is not a binary table " << endl; 1409 exit(status); 1528 throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error Not a bin table (1) !"); 1529 // exit(status); 1410 1530 } 1411 1531 char xtension[FLEN_VALUE]; … … 1418 1538 { 1419 1539 cout << "FitsIoServer:: not a binary table " << endl; 1420 exit(status); 1540 throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error Not a bin table (2) !"); 1541 // exit(status); 1421 1542 } 1422 1543 fits_get_hdrpos(fptr,&nkeys,&keypos,&status); … … 1427 1548 { 1428 1549 cout << "FitsIoServer:: il y a plus d'une colonne" << endl; 1429 return; 1550 throw IOExc("FitsIoServer::planck_read_bntbl(" + (string)flnm + ") Error >1 column !"); 1551 // return; 1430 1552 } 1431 1553 fits_get_num_rows(fptr, &nrows, &status); … … 1461 1583 << " conversion to double will be achieved by cfitsio lib " << endl; 1462 1584 } 1463 if (r_8tab_ != NULL) delete [] r_8tab_;1585 if (r_8tab_ != NULL) { delete [] r_8tab_; r_8tab_ = NULL; } 1464 1586 r_8tab_=new r_8[ npixels]; 1465 1587 fits_read_col(fptr, TDOUBLE, 1, 1, 1, nelements, &dnullval, … … 1475 1597 << " conversion to float will be achieved by cfitsio lib " << endl; 1476 1598 } 1477 if (r_4tab_ != NULL) delete [] r_4tab_;1599 if (r_4tab_ != NULL) { delete [] r_4tab_; r_4tab_ = NULL; } 1478 1600 r_4tab_=new r_4[nelements]; 1479 1601 fits_read_col(fptr, TFLOAT, 1, 1, 1, nelements, &fnullval, … … 1489 1611 << " conversion to long will be achieved by cfitsio lib " << endl; 1490 1612 } 1491 if (i_4tab_ != NULL) delete [] i_4tab_;1613 if (i_4tab_ != NULL) { delete [] i_4tab_; i_4tab_ = NULL; } 1492 1614 i_4tab_=new int_4[nelements]; 1493 1615 fits_read_col(fptr, TLONG, 1, 1, 1, nelements, &inullval, -
trunk/SophyaExt/FitsIOServer/fitsioserver.h
r603 r605 28 28 29 29 void load(TMatrix<double>& mat, char flnm[]); 30 void load(TMatrix<float>& mat, char flnm[]); 31 void load(TMatrix<int_4>& mat, char flnm[]); 30 32 void load(NTuple& ntpl,char flnm[],int hdunum); 31 33 void load(SphericalMap<double>& sph, char flnm[]); … … 34 36 void load(ImageR4& DpcImg,char flnm[]); 35 37 void load(ImageI4& DpcImg,char flnm[]); 36 void load(SphereGorski<float>& sph, char flnm[], int hdunum );37 void load(SphereGorski<double>& sph, char flnm[], int hdunum );38 void load(SphereGorski<float>& sph, char flnm[], int hdunum=2); 39 void load(SphereGorski<double>& sph, char flnm[], int hdunum=2); 38 40 void save(TMatrix<double>& mat, char flnm[]); 41 void save(TMatrix<float>& mat, char flnm[]); 42 void save(TMatrix<int_4>& mat, char flnm[]); 39 43 void save(NTuple& ntpl,char flnm[]); 40 44 void save(SphericalMap<double>& sph, char flnm[]);
Note:
See TracChangeset
for help on using the changeset viewer.