Ignore:
Timestamp:
Nov 20, 1999, 9:40:13 PM (26 years ago)
Author:
ansari
Message:

Extension + Bugs FitsIO - Reza 20/11/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitsioserver.cc

    r603 r605  
    1010//************************************************************************
    1111
     12#include "machdefs.h"
    1213#include <iostream.h>
    1314#include <list>
     15#include <string>
    1416
    1517#include "fitsioserver.h"
     18#include "pexceptions.h"
    1619#include "strutil.h"
    1720
     
    4952}
    5053
     54void 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
     87void 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
    51120void FitsIoServer::load(NTuple& ntpl,char flnm[],int hdunum)
    52121
     
    80149    {
    81150      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 );
    83153    }
    84154
     
    276346        {
    277347          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);
    279350        }
    280351      if (nside != sph.SizeIndex())
     
    286357        {
    287358          cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
    288           exit(0);
     359//        exit(0);   $CHECK$   Ca peut etre OK , non ??  Reza 20/11/99
    289360        }
    290361    }
     
    320391        {
    321392          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);
    323395        }
    324396      if (nside != sph.SizeIndex())
     
    330402        {
    331403          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
    333405        }
    334406    }
     
    363435        {
    364436          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);
    366439        }
    367440      if (nside != sph.SizeIndex())
     
    373446        {
    374447          cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
    375           exit(0);
     448//        exit(0);   $CHECK$ - ne pas sortir , Reza 20/11/99
    376449        }
    377450    }
     
    405478        {
    406479          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);
    408482        }
    409483      if (nside != sph.SizeIndex())
     
    415489        {
    416490          cout << " FITSIOSERVER : same resolution, surprising ! " << endl;
    417           exit(0);
     491//        exit(0);  $CHECK$ - Ne pas sortir , Reza 20/11/99
    418492        }
    419493    }
     
    561635  cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl;
    562636  FITS_tab_typ_ = TDOUBLE;
    563   if (r_8tab_ != NULL ) delete[] r_8tab_;
     637  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
    564638  r_8tab_=new r_8[nbrows*nbcols];
    565639
     
    572646
    573647  planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
    574   delete[] r_8tab_;
    575 }
     648  delete[] r_8tab_;  r_8tab_ = NULL;
     649}
     650
     651void 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
     672void 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
    576693
    577694void FitsIoServer::save(NTuple& ntpl,char flnm[])
     
    702819  int npixels = sph.NbPixels();
    703820  FITS_tab_typ_ = TDOUBLE;
    704   if (r_8tab_ != NULL ) delete[] r_8tab_;
     821  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
    705822  r_8tab_=new r_8[npixels];
    706823
     
    754871  */
    755872
    756  delete[] r_8tab_;
     873 delete[] r_8tab_;  r_8tab_ = NULL;
    757874}
    758875
     
    761878  int npixels = sph.NbPixels();
    762879  FITS_tab_typ_ = TFLOAT;
    763   if (r_4tab_ != NULL ) delete[] r_4tab_;
     880  if (r_4tab_ != NULL ) { delete[] r_4tab_;  r_4tab_ = NULL; }
    764881  r_4tab_=new r_4[npixels];
    765882
     
    771888
    772889  planck_write_img(filename, 1, npixels, 0, 0, dvl);
    773   delete[] r_4tab_;
     890  delete[] r_4tab_;  r_4tab_ = NULL;
    774891
    775892}
     
    778895  int npixels = sph.NbPixels();
    779896  FITS_tab_typ_ = TFLOAT;
    780   if (r_4tab_ != NULL ) delete[] r_4tab_;
     897  if (r_4tab_ != NULL ) { delete[] r_4tab_;  r_4tab_ = NULL; }
    781898  r_4tab_=new r_4[npixels];
    782899
     
    793910  char* comment1="     Sky Map Pixelisation Specific Keywords";
    794911  planck_write_bntbl(filename, npixels, typeOfContent, extname, comment1, dvl);
    795   delete[] r_4tab_;
     912  delete[] r_4tab_;  r_4tab_ = NULL;
    796913
    797914}
     
    800917  int npixels = sph.NbPixels();
    801918  FITS_tab_typ_ = TDOUBLE;
    802   if (r_8tab_ != NULL ) delete[] r_8tab_;
     919  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
    803920  r_8tab_=new r_8[npixels];
    804921
     
    815932  char* comment1="     Sky Map Pixelisation Specific Keywords";
    816933  planck_write_bntbl(filename, npixels, typeOfContent, extname, comment1, dvl);
    817   delete[] r_8tab_;
     934  delete[] r_8tab_;  r_8tab_ = NULL;
    818935
    819936}
     
    826943  cout << " nombre de pts en x : " << nbrows << " en y  " << nbcols << endl;
    827944  FITS_tab_typ_ = TDOUBLE;
    828   if (r_8tab_ != NULL ) delete[] r_8tab_;
     945  if (r_8tab_ != NULL ) { delete[] r_8tab_;  r_8tab_ = NULL; }
    829946  r_8tab_=new r_8[nbrows*nbcols];
    830947
     
    853970  dvl["ANGLEY"] = angley;
    854971  planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl);
    855   delete[] r_8tab_;}
     972  delete[] r_8tab_;  r_8tab_ = NULL;
     973}
    856974
    857975
     
    8941012
    8951013  // 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; }
    8971015  r_4tab_=new r_4[siz_x*siz_y];
    8981016  PBaseDataTypes  dataT=DataType((r_4)0);
     
    9011019
    9021020
    903    delete [] r_4tab_;
     1021   delete [] r_4tab_;  r_4tab_ = NULL;
    9041022}
    9051023
     
    9541072
    9551073  // 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; }
    9571075  i_4tab_=new int_4[siz_x*siz_y];
    9581076  PBaseDataTypes  dataT=DataType((int_4)0);
     
    9661084  //if( status )  printerror( status );
    9671085
    968    delete [] i_4tab_;
     1086   delete [] i_4tab_;  i_4tab_ = NULL;
    9691087}
    9701088
     
    12601378               << " conversion to double will be achieved by cfitsio lib " << endl;
    12611379        }
    1262       if (r_8tab_ != NULL) delete [] r_8tab_;
     1380      if (r_8tab_ != NULL) { delete [] r_8tab_;  r_8tab_ = NULL; }
    12631381      r_8tab_=new r_8[nelements];
    12641382      fits_read_img(fptr, TDOUBLE, 1, nelements,  &dnullval, r_8tab_,
     
    12721390               << " conversion to float will be achieved by cfitsio lib " << endl;
    12731391        }
    1274       if (r_4tab_ != NULL) delete [] r_4tab_;
     1392      if (r_4tab_ != NULL) { delete [] r_4tab_;  r_4tab_ = NULL; }
    12751393      r_4tab_=new r_4[nelements];
    12761394      fits_read_img(fptr, TFLOAT, 1, nelements,  &fnullval, r_4tab_,
     
    12861404               << " conversion to long will be achieved by cfitsio lib " << endl;
    12871405        }
    1288       if (i_4tab_ != NULL) delete [] i_4tab_;
     1406      if (i_4tab_ != NULL) { delete [] i_4tab_;  i_4tab_ = NULL; }
    12891407      i_4tab_=new int_4[nelements];
    12901408      fits_read_img(fptr, TINT, 1, nelements,  &inullval, i_4tab_,
     
    14001518    {
    14011519      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;
    14031522    }
    14041523  fits_movabs_hdu(fptr, hdunum,&hdutype,&status);
     
    14071526    {
    14081527      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);
    14101530    }
    14111531   char xtension[FLEN_VALUE];
     
    14181538     {
    14191539      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);
    14211542     }
    14221543   fits_get_hdrpos(fptr,&nkeys,&keypos,&status);
     
    14271548    {
    14281549      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;
    14301552    }
    14311553  fits_get_num_rows(fptr, &nrows, &status);
     
    14611583               << " conversion to double will be achieved by cfitsio lib " << endl;
    14621584        }
    1463       if (r_8tab_ != NULL) delete [] r_8tab_;
     1585      if (r_8tab_ != NULL) { delete [] r_8tab_;  r_8tab_ = NULL; }
    14641586      r_8tab_=new r_8[ npixels];
    14651587      fits_read_col(fptr, TDOUBLE, 1, 1, 1, nelements,  &dnullval,
     
    14751597               << " conversion to float will be achieved by cfitsio lib " << endl;
    14761598        }
    1477       if (r_4tab_ != NULL) delete [] r_4tab_;
     1599      if (r_4tab_ != NULL) { delete [] r_4tab_;  r_4tab_ = NULL; }
    14781600      r_4tab_=new r_4[nelements];
    14791601      fits_read_col(fptr, TFLOAT, 1, 1, 1, nelements,  &fnullval,
     
    14891611               << " conversion to long will be achieved by cfitsio lib " << endl;
    14901612        }
    1491       if (i_4tab_ != NULL) delete [] i_4tab_;
     1613      if (i_4tab_ != NULL) { delete [] i_4tab_;  i_4tab_ = NULL; }
    14921614      i_4tab_=new int_4[nelements];
    14931615      fits_read_col(fptr, TLONG, 1, 1, 1, nelements,  &inullval,
Note: See TracChangeset for help on using the changeset viewer.