1 | #include <duchamp/FitsIO/WriteMomentMaskArray.hh> |
---|
2 | #include <duchamp/FitsIO/WriteArray.hh> |
---|
3 | #include <duchamp/duchamp.hh> |
---|
4 | #include <duchamp/Cubes/cubes.hh> |
---|
5 | #include <fitsio.h> |
---|
6 | #include <string.h> |
---|
7 | |
---|
8 | namespace duchamp { |
---|
9 | |
---|
10 | WriteMomentMaskArray::WriteMomentMaskArray(): |
---|
11 | WriteArray() |
---|
12 | { |
---|
13 | this->itsBitpix=SHORT_IMG; |
---|
14 | this->itsFlag2D=true; |
---|
15 | } |
---|
16 | |
---|
17 | WriteMomentMaskArray::WriteMomentMaskArray(Cube *cube): |
---|
18 | WriteArray(cube,SHORT_IMG) |
---|
19 | { |
---|
20 | this->itsFlag2D=true; |
---|
21 | } |
---|
22 | |
---|
23 | WriteMomentMaskArray::WriteMomentMaskArray(const WriteMomentMaskArray &other) |
---|
24 | { |
---|
25 | this->operator=(other); |
---|
26 | } |
---|
27 | |
---|
28 | WriteMomentMaskArray::WriteMomentMaskArray(const WriteArray &base) |
---|
29 | { |
---|
30 | this->operator=(base); |
---|
31 | } |
---|
32 | |
---|
33 | WriteMomentMaskArray& WriteMomentMaskArray::operator= (const WriteMomentMaskArray& other) |
---|
34 | { |
---|
35 | if(this==&other) return *this; |
---|
36 | ((WriteArray &) *this) = other; |
---|
37 | return *this; |
---|
38 | } |
---|
39 | |
---|
40 | WriteMomentMaskArray& WriteMomentMaskArray::operator= (const WriteArray& base) |
---|
41 | { |
---|
42 | if(this==&base) return *this; |
---|
43 | ((WriteArray &) *this) = base; |
---|
44 | return *this; |
---|
45 | } |
---|
46 | |
---|
47 | OUTCOME WriteMomentMaskArray::writeHeader() |
---|
48 | { |
---|
49 | /// @details |
---|
50 | /// A simple function that writes all the necessary keywords and comments |
---|
51 | /// to the FITS header pointed to by fptr. |
---|
52 | /// The keyword names and comments are taken from duchamp.hh |
---|
53 | |
---|
54 | OUTCOME result=SUCCESS; |
---|
55 | |
---|
56 | int status = 0; |
---|
57 | if(fits_write_history(this->itsFptr, (char *)header_moment0History.c_str(), &status)){ |
---|
58 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
59 | result=FAILURE; |
---|
60 | } |
---|
61 | status = 0; |
---|
62 | if(fits_write_history(this->itsFptr, (char *)header_moment0History_input.c_str(),&status)){ |
---|
63 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
64 | result=FAILURE; |
---|
65 | } |
---|
66 | status = 0; |
---|
67 | if(fits_write_history(this->itsFptr, (char *)this->itsCube->pars().getImageFile().c_str(), &status)){ |
---|
68 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
69 | result=FAILURE; |
---|
70 | } |
---|
71 | |
---|
72 | if(this->itsCube->pars().getFlagSubsection()){ |
---|
73 | status = 0; |
---|
74 | if( fits_write_comment(this->itsFptr,(char *)header_moment0Subsection_comment.c_str(), &status)){ |
---|
75 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
76 | result=FAILURE; |
---|
77 | } |
---|
78 | status = 0; |
---|
79 | if( fits_write_key(this->itsFptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
80 | (char *)this->itsCube->pars().getSubsection().c_str(), |
---|
81 | (char *)comment_subsection.c_str(), &status) ){ |
---|
82 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
83 | result=FAILURE; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | char *comment = new char[FLEN_COMMENT]; |
---|
88 | strcpy(comment,""); |
---|
89 | char *keyword = new char[FLEN_KEYWORD]; |
---|
90 | std::string newunits = "Detection flag"; |
---|
91 | strcpy(keyword,"BUNIT"); |
---|
92 | if(fits_update_key(this->itsFptr, TSTRING, keyword, (char *)newunits.c_str(), comment, &status)){ |
---|
93 | duchampFITSerror(status,"writeMomentMaskArray","Error writing BUNIT header:"); |
---|
94 | result = FAILURE; |
---|
95 | } |
---|
96 | delete [] comment; |
---|
97 | delete [] keyword; |
---|
98 | |
---|
99 | return result; |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | OUTCOME WriteMomentMaskArray::writeData() |
---|
104 | { |
---|
105 | OUTCOME result = SUCCESS; |
---|
106 | size_t size=this->itsCube->getSpatialSize(); |
---|
107 | int *mask = new int[size]; |
---|
108 | for(size_t i=0;i<size;i++) mask[i]=0; |
---|
109 | std::vector<Detection>::iterator obj; |
---|
110 | for(obj=this->itsCube->pObjectList()->begin();obj<this->itsCube->pObjectList()->end();obj++){ |
---|
111 | std::vector<PixelInfo::Voxel> voxlist = obj->getPixelSet(); |
---|
112 | std::vector<PixelInfo::Voxel>::iterator vox; |
---|
113 | for(vox=voxlist.begin();vox<voxlist.end();vox++){ |
---|
114 | size_t pixelpos = vox->getX() + this->itsCube->getDimX()*vox->getY(); |
---|
115 | mask[pixelpos] = 1; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | result = this->writeToFITS_int(size,mask); |
---|
120 | |
---|
121 | delete [] mask; |
---|
122 | |
---|
123 | return result; |
---|
124 | |
---|
125 | } |
---|
126 | |
---|
127 | } |
---|
128 | |
---|