source: trunk/src/Cubes/WriteMaskArray.cc @ 1117

Last change on this file since 1117 was 1116, checked in by MatthewWhiting, 12 years ago

Fixing build errors with the previous.

File size: 4.0 KB
Line 
1#include <duchamp/Cubes/WriteMaskArray.hh>
2#include <duchamp/Cubes/WriteArray.hh>
3#include <duchamp/duchamp.hh>
4#include <duchamp/Cubes/cubes.hh>
5#include <fitsio.h>
6
7namespace duchamp {
8
9  WriteMaskArray::WriteMaskArray():
10    WriteArray()
11  {
12    this->itsBitpix=LONG_IMG;
13    this->itsFlag2D=true;
14  }
15 
16  WriteMaskArray::WriteMaskArray(Cube *cube):
17    WriteArray(cube,LONG_IMG)
18  {
19    this->itsFlag2D=true;
20  }
21
22  WriteMaskArray::WriteMaskArray(const WriteMaskArray &other)
23  {
24    this->operator=(other);
25  }
26
27  WriteMaskArray::WriteMaskArray(const WriteArray &base)
28  {
29    this->operator=(base);
30  }
31
32  WriteMaskArray& WriteMaskArray::operator= (const WriteMaskArray& other)
33  {
34    if(this==&other) return *this;
35    ((WriteArray &) *this) = other;
36    return *this;
37  }
38
39  WriteMaskArray& WriteMaskArray::operator= (const WriteArray& base)
40  {
41    if(this==&base) return *this;
42    ((WriteArray &) *this) = base;
43    return *this;
44  }
45
46  OUTCOME WriteMaskArray::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_maskHistory.c_str(), &status)){
56      duchampFITSerror(status,"writeMaskArray","Error : header I/O");
57      result=FAILURE;
58    }
59    status = 0;
60    if(fits_write_history(this->itsFptr, (char *)header_maskHistory_input.c_str(),&status)){
61      duchampFITSerror(status,"writeMaskArray","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,"writeMaskArray","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_maskSubsection_comment.c_str(), &status)){
73        duchampFITSerror(status,"writeMaskArray","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,"writeMaskArray","Error : header I/O");
81        result=FAILURE;
82      }
83    }
84
85    char *comment = new char[FLEN_COMMENT];
86    strcpy(comment,"");
87    char *keyword = new char[FLEN_KEYWORD];
88    std::string newunits = (this->itsCube->pars().getFlagMaskWithObjectNum()) ? "Object ID" : "Detection flag";
89    strcpy(keyword,"BUNIT");
90    if(fits_update_key(this->itsFptr, TSTRING, keyword, (char *)newunits.c_str(), comment, &status)){
91      duchampFITSerror(status,"saveMask","Error writing BUNIT header:");
92      result = FAILURE;
93    }
94    delete [] comment;
95    delete [] keyword;
96
97    return result;
98
99  }
100
101  OUTCOME WriteMaskArray::writeData()
102  {
103    OUTCOME result = SUCCESS;
104    int *mask = new int[this->itsCube->getSize()];
105    for(size_t i=0;i<this->itsCube->getSize();i++) mask[i]=0;
106    std::vector<Detection>::iterator obj;
107    for(obj=this->itsCube->pObjectList()->begin();obj<this->itsCube->pObjectList()->end();obj++){
108      std::vector<PixelInfo::Voxel> voxlist = obj->getPixelSet();
109      std::vector<PixelInfo::Voxel>::iterator vox;
110      for(vox=voxlist.begin();vox<voxlist.end();vox++){
111        size_t pixelpos = vox->getX() + this->itsCube->getDimX()*vox->getY() +
112          this->itsCube->getDimX()*this->itsCube->getDimY()*vox->getZ();
113        if(this->itsCube->pars().getFlagMaskWithObjectNum()) mask[pixelpos] = obj->getID();
114        else mask[pixelpos] = 1;
115      }
116    }
117    int status=0;
118    long group=0;
119    LONGLONG first=1;
120    LONGLONG nelem=LONGLONG(this->itsCube->getSize());
121    if(fits_write_img_int(this->itsFptr, group, first, nelem, mask, &status)){
122      duchampFITSerror(status,"saveMask","Error writing mask array!:");
123      result = FAILURE;
124    }
125
126    return result;
127
128  }
129
130}
131
Note: See TracBrowser for help on using the repository browser.