source: trunk/src/FitsIO/WriteSmoothArray.cc @ 1339

Last change on this file since 1339 was 1123, checked in by MatthewWhiting, 12 years ago

Moving the code that reads from and writes to FITS files containing reconstructed, momentmap, mask etc arrays to the FitsIO directory, away from Cubes. Updating all include statements as well.

File size: 5.0 KB
Line 
1#include <duchamp/FitsIO/WriteSmoothArray.hh>
2#include <duchamp/FitsIO/WriteArray.hh>
3#include <duchamp/duchamp.hh>
4#include <duchamp/Cubes/cubes.hh>
5#include <fitsio.h>
6
7namespace duchamp {
8
9  WriteSmoothArray::WriteSmoothArray():
10    WriteArray()
11  {
12    this->itsBitpix=FLOAT_IMG;
13  }
14 
15  WriteSmoothArray::WriteSmoothArray(Cube *cube):
16    WriteArray(cube,FLOAT_IMG)
17  {
18  }
19
20  WriteSmoothArray::WriteSmoothArray(const WriteSmoothArray &other)
21  {
22    this->operator=(other);
23  }
24
25  WriteSmoothArray::WriteSmoothArray(const WriteArray &base)
26  {
27    this->operator=(base);
28  }
29
30  WriteSmoothArray& WriteSmoothArray::operator= (const WriteSmoothArray& other)
31  {
32    if(this==&other) return *this;
33    ((WriteArray &) *this) = other;
34    return *this;
35  }
36
37  WriteSmoothArray& WriteSmoothArray::operator= (const WriteArray& base)
38  {
39    if(this==&base) return *this;
40    ((WriteArray &) *this) = base;
41    return *this;
42  }
43
44  OUTCOME WriteSmoothArray::writeHeader()
45  {
46    /// @details
47    ///   A simple function that writes all the necessary keywords and comments
48    ///    to the FITS header pointed to by this->itsFptr.
49    ///   The keyword names and comments are taken from duchamp.hh
50
51    OUTCOME result=SUCCESS;
52    int status = 0;
53    if(fits_write_history(this->itsFptr, (char *)header_smoothHistory.c_str(), &status)){
54      duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
55      result=FAILURE;
56    }
57    status = 0;
58    if(fits_write_history(this->itsFptr, (char *)header_smoothHistory_input.c_str(),&status)){
59      duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
60      result=FAILURE;
61    }
62    status = 0;
63    if(fits_write_history(this->itsFptr, (char *)this->itsCube->pars().getImageFile().c_str(), &status)){
64      duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
65      result=FAILURE;
66    }
67
68    if(this->itsCube->pars().getFlagSubsection()){
69      status = 0;
70      if(fits_write_comment(this->itsFptr,(char *)header_smoothSubsection_comment.c_str(),&status)){
71        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
72        result=FAILURE;
73      }
74      status = 0;
75      if(fits_write_key(this->itsFptr, TSTRING, (char *)keyword_subsection.c_str(),
76                        (char *)this->itsCube->pars().getSubsection().c_str(),
77                        (char *)comment_subsection.c_str(), &status)){
78        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
79        result=FAILURE;
80      }
81    }
82   
83    if(this->itsCube->pars().getSmoothType()=="spatial"){
84      // if kernMin is negative (not defined), make it equal to kernMaj
85      float kernMaj=this->itsCube->pars().getKernMaj();
86      float kernMin=this->itsCube->pars().getKernMin();
87      float kernPA=this->itsCube->pars().getKernPA();
88      if(kernMin<0) kernMin=kernMaj;
89
90      status=0;
91      if(fits_write_key(this->itsFptr, TSTRING, (char *)keyword_smoothtype.c_str(),
92                        (char *)header_smoothSpatial.c_str(),
93                        (char *)comment_smoothtype.c_str(), &status)){
94        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
95        result=FAILURE;
96      }
97      status=0;
98      if(fits_write_key(this->itsFptr, TFLOAT, (char *)keyword_kernmaj.c_str(), &kernMaj,
99                        (char *)comment_kernmaj.c_str(), &status)){
100        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
101        result=FAILURE;
102      }
103      status=0;
104      if(fits_write_key(this->itsFptr, TFLOAT, (char *)keyword_kernmin.c_str(), &kernMin,
105                        (char *)comment_kernmin.c_str(), &status)){
106        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
107        result=FAILURE;
108      }
109      status=0;
110      if(fits_write_key(this->itsFptr, TFLOAT, (char *)keyword_kernpa.c_str(), &kernPA,
111                        (char *)comment_kernpa.c_str(), &status)){
112        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
113        result=FAILURE;
114      }
115    }
116    else if(this->itsCube->pars().getSmoothType()=="spectral"){
117      status=0;
118      if(fits_write_key(this->itsFptr, TSTRING, (char *)keyword_smoothtype.c_str(),
119                        (char *)header_smoothSpectral.c_str(),
120                        (char *)comment_smoothtype.c_str(), &status)){
121        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
122        result=FAILURE;
123      }
124      int width = this->itsCube->pars().getHanningWidth();
125      status=0;
126      if(fits_write_key(this->itsFptr, TINT, (char *)keyword_hanningwidth.c_str(), &width,
127                        (char *)comment_hanningwidth.c_str(), &status)){
128        duchampFITSerror(status,"writeSmoothArray","Error : header I/O");
129        result=FAILURE;
130      }
131    }
132
133    return result;
134
135  }
136
137  OUTCOME WriteSmoothArray::writeData()
138  {
139    OUTCOME result = SUCCESS;
140
141    long group=0;
142    int status=0;
143    if(this->itsCube->pars().getFlagBlankPix())
144      fits_write_imgnull_flt(this->itsFptr, group, 1, this->itsCube->getSize(), this->itsCube->getRecon(), this->itsCube->pars().getBlankPixVal(), &status);
145    else
146      fits_write_img_flt(this->itsFptr, group, 1, this->itsCube->getSize(), this->itsCube->getRecon(), &status);
147    if(status){
148      duchampFITSerror(status,"writeSmoothArray","Error writing smoothed array:");
149      result = FAILURE;
150    }
151
152    return result;
153
154  }
155
156}
157
Note: See TracBrowser for help on using the repository browser.