Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

fits_header_data.h

Go to the documentation of this file.
00001 /*
00002 Arroyo - software for the simulation of electromagnetic wave propagation
00003 through turbulence and optics.
00004 
00005 Copyright (c) 2000-2004 California Institute of Technology.  Written by
00006 Dr. Matthew Britton.  For comments or questions about this software,
00007 please contact the author at mbritton@astro.caltech.edu.
00008 
00009 This program is free software; you can redistribute it and/or modify it
00010 under the terms of the GNU General Public License as  published by the
00011 Free Software Foundation; either version 2 of the License, or (at your
00012 option) any later version.
00013 
00014 This program is provided "as is" and distributed in the hope that it
00015 will be useful, but WITHOUT ANY WARRANTY; without even the implied
00016 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  In no
00017 event shall California Institute of Technology be liable to any party
00018 for direct, indirect, special, incidental or consequential damages,
00019 including lost profits, arising out of the use of this software and its
00020 documentation, even if the California Institute of Technology has been
00021 advised of the possibility of such damage.   The California Institute of
00022 Technology has no obligation to provide maintenance, support, updates,
00023 enhancements or modifications.  See the GNU General Public License for
00024 more details.
00025 
00026 You should have received a copy of the GNU General Public License along
00027 with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00029 */
00030 
00031 #ifndef FITS_HEADER_DATA_H
00032 #define FITS_HEADER_DATA_H
00033 
00034 #include <vector>
00035 #include <string>
00036 #include <iomanip>
00037 #include "iofits.h"
00038 
00039 namespace Arroyo {
00040 
00041   using std::string;
00042   using std::vector;
00043   using std::ostream;
00044 
00048 
00049   class fits_scale_factor {
00050 
00051   protected:
00053     double bscale;      
00054  
00056     string bscale_comment;    
00057    
00059     double bzero;    
00060    
00062     string bzero_comment;        
00063 
00064   public:
00065 
00068     fits_scale_factor();
00069 
00072     fits_scale_factor(const iofits & iof);
00073 
00076     fits_scale_factor(const fits_scale_factor & fsf){
00077       fits_scale_factor::operator=(fsf);
00078     };
00079 
00082     ~fits_scale_factor(){};
00083 
00086     fits_scale_factor & operator= (const fits_scale_factor & fsf);
00087  
00090     void read(const iofits & iof){
00091       operator=(fits_scale_factor(iof));
00092     };
00093 
00096     void write(iofits & iof) const;
00097 
00100     void print(ostream & os, const char * prefix = "") const;
00101   };
00102 
00106 
00107   template<class T>
00108     class fits_header_data {
00109 
00110     private:
00111 
00114     iofits::imagetype get_image_type() const;
00115     
00116     protected:
00117 
00119     string bitpix_comment;       
00120 
00122     string naxis_comment;        
00123 
00125     vector <long> axes;  
00126 
00128     vector<string> axes_comment; 
00129 
00130     public:
00133     fits_header_data();
00134 
00137     fits_header_data(const iofits & iof);
00138 
00141     fits_header_data(const fits_header_data & fhd){
00142       fits_header_data::operator=(fhd);
00143     };
00144 
00147     fits_header_data(const vector<long> & in_axes, 
00148                      const vector<string> & in_axes_comment = vector<string>());
00149 
00152     virtual ~fits_header_data(){};
00153 
00156     fits_header_data & operator= (const fits_header_data & fhd);
00157  
00160     void read(const iofits & iof);
00161 
00164     void write(iofits & iof) const;
00165 
00168     virtual void print(ostream & os, const char * prefix = "") const;
00169 
00172     vector<long> get_axes() const {
00173       return(axes);
00174     };
00175 
00178     void print_axes(ostream & os) const;
00179 
00182     virtual void set_axes(const vector<long> & in_axes, 
00183                           const vector<long> & in_axes_comment = vector<long>(0));
00184 
00187     long total_space() const;
00188 
00191     template<class U, class V>
00192     friend bool operator==(const fits_header_data<U> & fhd1,
00193                                 const fits_header_data<V> & fhd2);
00194 
00195   };
00196 
00199   template<class U, class V>
00200   bool operator==(const fits_header_data<U> & fhd1,
00201                                 const fits_header_data<V> & fhd2) {
00202     if(fhd1.get_image_type()!=fhd2.get_image_type()) return(false);
00203     if(fhd1.axes!=fhd2.axes) return(false);
00204     return(true);
00205   }
00206 
00209   template<class U, class V>
00210     bool operator !=(const fits_header_data<U> &fhd1,
00211                         const fits_header_data<V> &fhd2){
00212     return(!operator==(fhd1,fhd2));
00213   }
00214 
00215   template<class T>
00216     fits_header_data<T>::fits_header_data(){
00217     bitpix_comment = "number of bits per data pixel";
00218     naxis_comment  = "number of data axes";
00219   }
00220 
00221   template<class T>
00222     fits_header_data<T>::fits_header_data(const iofits & iof){
00223     this->read(iof);
00224   }
00225 
00226   template<class T>
00227     fits_header_data<T>::fits_header_data(const vector<long> & in_axes,
00228                                const vector<string> & in_axes_comment){
00229     bitpix_comment = "number of bits per data pixel";
00230     naxis_comment  = "number of data axes";
00231     axes = in_axes;
00232     if(in_axes_comment.size()!=in_axes.size()){
00233       char tmp[64];
00234       axes_comment.resize(in_axes.size());
00235       for(int i=0; i<in_axes.size(); i++){
00236         sprintf(tmp, "length of data axis %d", i+1);
00237         axes_comment[i] = tmp;
00238       }
00239     } else 
00240       axes_comment = in_axes_comment;
00241   }
00242 
00243   template<class T>
00244     fits_header_data<T> & fits_header_data<T>::operator= (
00245                                 const fits_header_data & fhd){
00246     if(this == &fhd) 
00247       return(*this);
00248     int i;
00249     bitpix_comment     = fhd.bitpix_comment;    
00250     naxis_comment      = fhd.naxis_comment;     
00251     axes               = fhd.axes;        
00252     axes_comment       = fhd.axes_comment;
00253     return(*this);
00254   }
00255 
00256   template<class T>
00257     void fits_header_data<T>::read(const iofits & iof) {
00258     int bitpix;
00259     iof.read_image_header(bitpix, axes);
00260     if(bitpix!=this->get_image_type()) {
00261       if(this->get_image_type()==20 && bitpix==16){
00262       } else {
00263         cerr << "fits_header_data::read error - mismatch between native bitpix "
00264              << this->get_image_type() << " and iofits bitpix " << bitpix << endl;
00265         throw(string("fits_header_data::read"));
00266       }
00267     }
00268     axes_comment.resize(axes.size());
00269     char tmp[64];
00270     for(int i=0; i<axes.size(); i++){
00271       sprintf(tmp, "length of data axis %d", i+1);
00272       axes_comment[i] = tmp;
00273     }  
00274   }
00275 
00276   template<class T>
00277     void fits_header_data<T>::write(iofits & iof) const {
00278     iof.create_image(axes, (Arroyo::iofits::imagetype)(this->get_image_type()));
00279   }
00280 
00281   template<class T>
00282     void fits_header_data<T>::print(ostream & os, const char * prefix) const {
00283     int vlspc = 30;
00284     int i;
00285     os.setf(std::ios::left, std::ios::adjustfield); 
00286     os << prefix << "BITPIX     = " << std::setw(vlspc) << this->get_image_type()
00287        << "/" << bitpix_comment     << std::endl;
00288     os << prefix << "NAXIS      = " << std::setw(vlspc) << axes.size()      
00289        << "/" << naxis_comment      << std::endl;
00290     for(i=0; i<(int)axes.size(); i++)
00291       os << prefix << "NAXIS" << i+1 << "     = " << std::setw(vlspc) << axes[i] 
00292          << "/" << axes_comment[i] << std::endl;
00293   }
00294 
00295   template<class T>
00296     void fits_header_data<T>::print_axes(ostream & os) const {
00297     os << "fits_header_data::print_axes - axes size " << axes.size() << endl;
00298     for(int i=0; i<axes.size(); i++) {
00299       os << "fits_header_data::print_axes - axis "
00300          << i << " size " << axes[i] << endl;
00301     }
00302   }
00303 
00304   template<class T>
00305     long fits_header_data<T>::total_space() const {
00306     if(axes.size()==0) return(0);
00307     long nelem = 1;
00308     for(int i=0; i<axes.size(); i++) nelem *= axes[i];
00309     return(nelem);
00310   }
00311 
00312   template<class T>
00313     void fits_header_data<T>::set_axes(const vector<long> & in_axes, 
00314                                const vector<long> & in_axes_comment) {
00315     int naxis = in_axes.size();
00316     axes.resize(naxis);
00317     axes_comment.resize(naxis);
00318     for(int i=0; i<naxis; i++)
00319       axes[i] = in_axes[i];
00320 
00321     if(in_axes_comment.size()!=naxis){
00322       char comment[64];
00323       for(int i=0; i<naxis; i++){
00324         sprintf(comment, "length of data axis %d", i);
00325         axes_comment[i] = comment;
00326       }
00327     } else {
00328       for(int i=0; i<naxis; i++)
00329         axes_comment[i] = in_axes_comment[i];
00330     }
00331   }
00332 }
00333 
00334 #endif

Generated on Thu Nov 29 17:16:29 2007 for arroyo by  doxygen 1.3.9.1