source: trunk/src/FitsIO/WriteReconArray.cc

Last change on this file was 1354, checked in by MatthewWhiting, 10 years ago

#209 - Changing default bitpix for masks to SHORT_IMG. Also making front-end functions to the writing of arrays. These reside in WriteArray?, and cover float (with blank pixel handling), int and long. Masks can use long if there are lots (>32K) of objects.

File size: 5.4 KB
Line 
1#include <duchamp/FitsIO/WriteReconArray.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  WriteReconArray::WriteReconArray():
10    WriteArray()
11  {
12    this->itsBitpix=FLOAT_IMG;
13    this->itsIsRecon = true;
14  }
15 
16  WriteReconArray::WriteReconArray(Cube *cube):
17    WriteArray(cube,FLOAT_IMG)
18  {
19    this->itsIsRecon = true;
20  }
21
22  WriteReconArray::WriteReconArray(const WriteReconArray &other)
23  {
24    this->operator=(other);
25  }
26
27  WriteReconArray::WriteReconArray(const WriteArray &base)
28  {
29    this->operator=(base);
30  }
31
32  WriteReconArray& WriteReconArray::operator= (const WriteReconArray& other)
33  {
34    if(this==&other) return *this;
35    ((WriteArray &) *this) = other;
36    this->itsIsRecon = other.itsIsRecon;
37    return *this;
38  }
39
40  WriteReconArray& WriteReconArray::operator= (const WriteArray& base)
41  {
42    if(this==&base) return *this;
43    ((WriteArray &) *this) = base;
44    this->itsIsRecon = true;
45    return *this;
46  }
47
48  OUTCOME WriteReconArray::writeHeader()
49  {
50    /// @details
51    ///   A simple function that writes all the necessary keywords and comments
52    ///    to the FITS header pointed to by fptr.
53    ///   The keyword names and comments are taken from duchamp.hh
54
55    OUTCOME result=SUCCESS;
56    int status = 0;
57    if(fits_write_history(this->itsFptr, (char *)header_reconHistory1.c_str(), &status)){
58      duchampFITSerror(status,"writeReconArray","Error : header I/O");
59      result=FAILURE;
60    }
61    status = 0;
62    if(fits_write_history(this->itsFptr, (char *)header_reconHistory2.c_str(), &status)){
63      duchampFITSerror(status,"writeReconArray","Error : header I/O");
64      result=FAILURE;
65    }
66    status = 0;
67    if(fits_write_history(this->itsFptr, (char *)header_reconHistory_input.c_str(),&status)){
68      duchampFITSerror(status,"writeReconArray","Error : header I/O");
69      result=FAILURE;
70    }
71    status = 0;
72    if(fits_write_history(this->itsFptr, (char *)this->itsCube->pars().getImageFile().c_str(), &status)){
73      duchampFITSerror(status,"writeReconArray","Error : header I/O");
74      result=FAILURE;
75    }
76
77    if(this->itsCube->pars().getFlagSubsection()){
78      status = 0;
79      if(fits_write_comment(this->itsFptr,(char *)header_reconSubsection_comment.c_str(),&status)){
80        duchampFITSerror(status,"writeReconArray","Error : header I/O");
81        result=FAILURE;
82      }
83      status = 0;
84      if(fits_write_key(this->itsFptr, TSTRING, (char *)keyword_subsection.c_str(),
85                        (char *)this->itsCube->pars().getSubsection().c_str(),
86                        (char *)comment_subsection.c_str(), &status)){
87        duchampFITSerror(status,"writeReconArray","Error : header I/O");
88        result=FAILURE;
89      }
90    }
91
92    status=0;
93    if(fits_write_comment(this->itsFptr, (char *)header_atrous_comment.c_str(), &status)){
94      duchampFITSerror(status,"writeReconArray","Error : header I/O");
95      result=FAILURE;
96    }
97
98    float valf = this->itsCube->pars().getAtrousCut();
99    status=0;
100    if(fits_write_key(this->itsFptr, TFLOAT, (char *)keyword_snrRecon.c_str(), &valf,
101                      (char *)comment_snrRecon.c_str(), &status)){
102      duchampFITSerror(status,"writeReconArray","Error : header I/O");
103      result=FAILURE;
104    }
105
106    int vali = this->itsCube->pars().getReconDim();
107    status=0;
108    if(fits_write_key(this->itsFptr, TINT, (char *)keyword_reconDim.c_str(), &vali,
109                      (char *)comment_reconDim.c_str(), &status)){
110      duchampFITSerror(status,"writeReconArray","Error : header I/O");
111      result=FAILURE;
112    }
113
114    vali = this->itsCube->pars().getMinScale();
115    status=0;
116    if(fits_write_key(this->itsFptr, TINT, (char *)keyword_scaleMin.c_str(), &vali,
117                      (char *)comment_scaleMin.c_str(), &status)){
118      duchampFITSerror(status,"writeReconArray","Error : header I/O");
119      result=FAILURE;
120    }
121
122    vali = this->itsCube->pars().getFilterCode();
123    status=0;
124    if(fits_write_key(this->itsFptr, TINT, (char *)keyword_filterCode.c_str(), &vali,
125                      (char *)comment_filterCode.c_str(), &status)){
126      duchampFITSerror(status,"writeReconArray","Error : header I/O");
127      result=FAILURE;
128    }
129
130    std::string explanation,ReconResid;
131    if(this->itsIsRecon){
132      explanation = "Duchamp: This is the RECONSTRUCTED cube";
133      ReconResid = "RECON";
134    }
135    else{
136      explanation = "Duchamp: This is the RESIDUAL cube";
137      ReconResid = "RESID";
138    }
139    status=0;
140    if(fits_write_comment(this->itsFptr, (char *)explanation.c_str(), &status)){
141      duchampFITSerror(status,"writeReconArray","Error : header I/O");
142      result=FAILURE;
143    }
144    status=0;
145    if(fits_write_key(this->itsFptr, TSTRING, (char *)keyword_ReconResid.c_str(),
146                      (char *)ReconResid.c_str(),
147                      (char *)comment_ReconResid.c_str(), &status)){
148      duchampFITSerror(status,"writeReconArray","Error : header I/O");
149      result=FAILURE;
150    }
151 
152    return result;
153
154  }
155
156  OUTCOME WriteReconArray::writeData()
157  {
158      OUTCOME result = SUCCESS;
159     
160      float *array;
161     
162      if(this->itsIsRecon){
163          array = this->itsCube->getRecon();
164      }
165      else{
166         
167          array = new float[this->itsCube->getSize()];
168          for(size_t i=0;i<this->itsCube->getSize();i++)
169          array[i] = this->itsCube->getPixValue(i) - this->itsCube->getReconValue(i);
170         
171      }
172     
173      result = this->writeToFITS_flt(this->itsCube->getSize(), array);
174     
175      if(!this->itsIsRecon) delete [] array;
176     
177      return result;
178
179  }
180
181}
182
Note: See TracBrowser for help on using the repository browser.