[1142] | 1 | #include <duchamp/FitsIO/WriteMomentMaskArray.hh> |
---|
[1123] | 2 | #include <duchamp/FitsIO/WriteArray.hh> |
---|
[1120] | 3 | #include <duchamp/duchamp.hh> |
---|
| 4 | #include <duchamp/Cubes/cubes.hh> |
---|
| 5 | #include <fitsio.h> |
---|
[1138] | 6 | #include <string.h> |
---|
[1120] | 7 | |
---|
| 8 | namespace duchamp { |
---|
| 9 | |
---|
[1142] | 10 | WriteMomentMaskArray::WriteMomentMaskArray(): |
---|
[1120] | 11 | WriteArray() |
---|
| 12 | { |
---|
[1142] | 13 | this->itsBitpix=LONG_IMG; |
---|
[1120] | 14 | this->itsFlag2D=true; |
---|
| 15 | } |
---|
| 16 | |
---|
[1142] | 17 | WriteMomentMaskArray::WriteMomentMaskArray(Cube *cube): |
---|
| 18 | WriteArray(cube,LONG_IMG) |
---|
[1120] | 19 | { |
---|
| 20 | this->itsFlag2D=true; |
---|
| 21 | } |
---|
| 22 | |
---|
[1142] | 23 | WriteMomentMaskArray::WriteMomentMaskArray(const WriteMomentMaskArray &other) |
---|
[1120] | 24 | { |
---|
| 25 | this->operator=(other); |
---|
| 26 | } |
---|
| 27 | |
---|
[1142] | 28 | WriteMomentMaskArray::WriteMomentMaskArray(const WriteArray &base) |
---|
[1120] | 29 | { |
---|
| 30 | this->operator=(base); |
---|
| 31 | } |
---|
| 32 | |
---|
[1142] | 33 | WriteMomentMaskArray& WriteMomentMaskArray::operator= (const WriteMomentMaskArray& other) |
---|
[1120] | 34 | { |
---|
| 35 | if(this==&other) return *this; |
---|
| 36 | ((WriteArray &) *this) = other; |
---|
| 37 | return *this; |
---|
| 38 | } |
---|
| 39 | |
---|
[1142] | 40 | WriteMomentMaskArray& WriteMomentMaskArray::operator= (const WriteArray& base) |
---|
[1120] | 41 | { |
---|
| 42 | if(this==&base) return *this; |
---|
| 43 | ((WriteArray &) *this) = base; |
---|
| 44 | return *this; |
---|
| 45 | } |
---|
| 46 | |
---|
[1142] | 47 | OUTCOME WriteMomentMaskArray::writeHeader() |
---|
[1120] | 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; |
---|
[1135] | 55 | |
---|
[1120] | 56 | int status = 0; |
---|
| 57 | if(fits_write_history(this->itsFptr, (char *)header_moment0History.c_str(), &status)){ |
---|
[1142] | 58 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
[1120] | 59 | result=FAILURE; |
---|
| 60 | } |
---|
| 61 | status = 0; |
---|
| 62 | if(fits_write_history(this->itsFptr, (char *)header_moment0History_input.c_str(),&status)){ |
---|
[1142] | 63 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
[1120] | 64 | result=FAILURE; |
---|
| 65 | } |
---|
| 66 | status = 0; |
---|
| 67 | if(fits_write_history(this->itsFptr, (char *)this->itsCube->pars().getImageFile().c_str(), &status)){ |
---|
[1142] | 68 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
[1120] | 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)){ |
---|
[1142] | 75 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
[1120] | 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) ){ |
---|
[1142] | 82 | duchampFITSerror(status,"writeMomentMaskArray","Error : header I/O"); |
---|
[1120] | 83 | result=FAILURE; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | |
---|
[1142] | 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 | |
---|
[1120] | 99 | return result; |
---|
| 100 | |
---|
| 101 | } |
---|
| 102 | |
---|
[1142] | 103 | OUTCOME WriteMomentMaskArray::writeData() |
---|
[1120] | 104 | { |
---|
| 105 | OUTCOME result = SUCCESS; |
---|
[1142] | 106 | int *mask = new int[this->itsCube->getSpatialSize()]; |
---|
| 107 | for(size_t i=0;i<this->itsCube->getSpatialSize();i++) mask[i]=0; |
---|
| 108 | std::vector<Detection>::iterator obj; |
---|
| 109 | for(obj=this->itsCube->pObjectList()->begin();obj<this->itsCube->pObjectList()->end();obj++){ |
---|
| 110 | std::vector<PixelInfo::Voxel> voxlist = obj->getPixelSet(); |
---|
| 111 | std::vector<PixelInfo::Voxel>::iterator vox; |
---|
| 112 | for(vox=voxlist.begin();vox<voxlist.end();vox++){ |
---|
| 113 | size_t pixelpos = vox->getX() + this->itsCube->getDimX()*vox->getY(); |
---|
| 114 | mask[pixelpos] = 1; |
---|
| 115 | } |
---|
| 116 | } |
---|
[1120] | 117 | int status=0; |
---|
| 118 | long group=0; |
---|
[1142] | 119 | LONGLONG first=1; |
---|
| 120 | LONGLONG nelem=LONGLONG(this->itsCube->getSpatialSize()); |
---|
| 121 | if(fits_write_img_int(this->itsFptr, group, first, nelem, mask, &status)){ |
---|
| 122 | duchampFITSerror(status,"writeMomentMaskArray","Error writing mask array:"); |
---|
| 123 | result = FAILURE; |
---|
[1120] | 124 | } |
---|
| 125 | |
---|
| 126 | return result; |
---|
| 127 | |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | } |
---|
| 131 | |
---|