1 | #include <duchamp/Cubes/WriteMomentMapArray.hh> |
---|
2 | #include <duchamp/Cubes/WriteArray.hh> |
---|
3 | #include <duchamp/duchamp.hh> |
---|
4 | #include <duchamp/Cubes/cubes.hh> |
---|
5 | #include <fitsio.h> |
---|
6 | |
---|
7 | namespace duchamp { |
---|
8 | |
---|
9 | WriteMomentMapArray::WriteMomentMapArray(): |
---|
10 | WriteArray() |
---|
11 | { |
---|
12 | this->itsBitpix=FLOAT_IMG; |
---|
13 | this->itsFlag2D=true; |
---|
14 | } |
---|
15 | |
---|
16 | WriteMomentMapArray::WriteMomentMapArray(Cube *cube): |
---|
17 | WriteArray(cube,FLOAT_IMG) |
---|
18 | { |
---|
19 | this->itsFlag2D=true; |
---|
20 | } |
---|
21 | |
---|
22 | WriteMomentMapArray::WriteMomentMapArray(const WriteMomentMapArray &other) |
---|
23 | { |
---|
24 | this->operator=(other); |
---|
25 | } |
---|
26 | |
---|
27 | WriteMomentMapArray::WriteMomentMapArray(const WriteArray &base) |
---|
28 | { |
---|
29 | this->operator=(base); |
---|
30 | } |
---|
31 | |
---|
32 | WriteMomentMapArray& WriteMomentMapArray::operator= (const WriteMomentMapArray& other) |
---|
33 | { |
---|
34 | if(this==&other) return *this; |
---|
35 | ((WriteArray &) *this) = other; |
---|
36 | return *this; |
---|
37 | } |
---|
38 | |
---|
39 | WriteMomentMapArray& WriteMomentMapArray::operator= (const WriteArray& base) |
---|
40 | { |
---|
41 | if(this==&base) return *this; |
---|
42 | ((WriteArray &) *this) = base; |
---|
43 | return *this; |
---|
44 | } |
---|
45 | |
---|
46 | OUTCOME WriteMomentMapArray::writeHeader() |
---|
47 | { |
---|
48 | /// @details |
---|
49 | /// A simple function that writes all the necessary keywords and comments |
---|
50 | /// to the FITS header pointed to by fptr. |
---|
51 | /// The keyword names and comments are taken from duchamp.hh |
---|
52 | |
---|
53 | OUTCOME result=SUCCESS; |
---|
54 | int status = 0; |
---|
55 | if(fits_write_history(this->itsFptr, (char *)header_moment0History.c_str(), &status)){ |
---|
56 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
57 | result=FAILURE; |
---|
58 | } |
---|
59 | status = 0; |
---|
60 | if(fits_write_history(this->itsFptr, (char *)header_moment0History_input.c_str(),&status)){ |
---|
61 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
62 | result=FAILURE; |
---|
63 | } |
---|
64 | status = 0; |
---|
65 | if(fits_write_history(this->itsFptr, (char *)this->itsCube->pars().getImageFile().c_str(), &status)){ |
---|
66 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
67 | result=FAILURE; |
---|
68 | } |
---|
69 | |
---|
70 | if(this->itsCube->pars().getFlagSubsection()){ |
---|
71 | status = 0; |
---|
72 | if( fits_write_comment(this->itsFptr,(char *)header_moment0Subsection_comment.c_str(), &status)){ |
---|
73 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
74 | result=FAILURE; |
---|
75 | } |
---|
76 | status = 0; |
---|
77 | if( fits_write_key(this->itsFptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
78 | (char *)this->itsCube->pars().getSubsection().c_str(), |
---|
79 | (char *)comment_subsection.c_str(), &status) ){ |
---|
80 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
81 | result=FAILURE; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | return result; |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | OUTCOME WriteMomentMapArray::writeData() |
---|
90 | { |
---|
91 | OUTCOME result = SUCCESS; |
---|
92 | long size = this->itsCube->getSpatialSize(); |
---|
93 | float *momentMap = new float[size]; |
---|
94 | std::vector<bool> detectionMap = this->itsCube->getMomentMap(momentMap); |
---|
95 | int status=0; |
---|
96 | long group=0; |
---|
97 | if(this->itsCube->pars().getFlagBlankPix()) |
---|
98 | fits_write_imgnull_flt(this->itsFptr, group, 1, size, momentMap, this->itsCube->pars().getBlankPixVal(), &status); |
---|
99 | else |
---|
100 | fits_write_img_flt(this->itsFptr, group, 1, size, momentMap, &status); |
---|
101 | if(status){ |
---|
102 | duchampFITSerror(status,"writeMomentMapArray","Error writing data"); |
---|
103 | result=FAILURE; |
---|
104 | } |
---|
105 | |
---|
106 | return result; |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | } |
---|
111 | |
---|