[1123] | 1 | #include <duchamp/FitsIO/WriteMomentMapArray.hh> |
---|
| 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 | |
---|
| 10 | WriteMomentMapArray::WriteMomentMapArray(): |
---|
| 11 | WriteArray() |
---|
| 12 | { |
---|
| 13 | this->itsBitpix=FLOAT_IMG; |
---|
| 14 | this->itsFlag2D=true; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | WriteMomentMapArray::WriteMomentMapArray(Cube *cube): |
---|
| 18 | WriteArray(cube,FLOAT_IMG) |
---|
| 19 | { |
---|
| 20 | this->itsFlag2D=true; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | WriteMomentMapArray::WriteMomentMapArray(const WriteMomentMapArray &other) |
---|
| 24 | { |
---|
| 25 | this->operator=(other); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | WriteMomentMapArray::WriteMomentMapArray(const WriteArray &base) |
---|
| 29 | { |
---|
| 30 | this->operator=(base); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | WriteMomentMapArray& WriteMomentMapArray::operator= (const WriteMomentMapArray& other) |
---|
| 34 | { |
---|
| 35 | if(this==&other) return *this; |
---|
| 36 | ((WriteArray &) *this) = other; |
---|
| 37 | return *this; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | WriteMomentMapArray& WriteMomentMapArray::operator= (const WriteArray& base) |
---|
| 41 | { |
---|
| 42 | if(this==&base) return *this; |
---|
| 43 | ((WriteArray &) *this) = base; |
---|
| 44 | return *this; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | OUTCOME WriteMomentMapArray::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; |
---|
[1135] | 55 | char keyname[9]; |
---|
| 56 | |
---|
[1120] | 57 | int status = 0; |
---|
[1135] | 58 | std::string bunit=this->itsCube->header().getFluxUnits() + " " + this->itsCube->header().getSpectralUnits(); |
---|
| 59 | strcpy(keyname,"BUNIT"); |
---|
| 60 | if(fits_update_key(this->itsFptr, TSTRING, keyname, (char *)bunit.c_str(), NULL, &status)){ |
---|
| 61 | duchampFITSerror(status,"saveImage","Error writing BSCALE header:"); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | status = 0; |
---|
[1120] | 65 | if(fits_write_history(this->itsFptr, (char *)header_moment0History.c_str(), &status)){ |
---|
| 66 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
| 67 | result=FAILURE; |
---|
| 68 | } |
---|
| 69 | status = 0; |
---|
| 70 | if(fits_write_history(this->itsFptr, (char *)header_moment0History_input.c_str(),&status)){ |
---|
| 71 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
| 72 | result=FAILURE; |
---|
| 73 | } |
---|
| 74 | status = 0; |
---|
| 75 | if(fits_write_history(this->itsFptr, (char *)this->itsCube->pars().getImageFile().c_str(), &status)){ |
---|
| 76 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
| 77 | result=FAILURE; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | if(this->itsCube->pars().getFlagSubsection()){ |
---|
| 81 | status = 0; |
---|
| 82 | if( fits_write_comment(this->itsFptr,(char *)header_moment0Subsection_comment.c_str(), &status)){ |
---|
| 83 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
| 84 | result=FAILURE; |
---|
| 85 | } |
---|
| 86 | status = 0; |
---|
| 87 | if( fits_write_key(this->itsFptr, TSTRING, (char *)keyword_subsection.c_str(), |
---|
| 88 | (char *)this->itsCube->pars().getSubsection().c_str(), |
---|
| 89 | (char *)comment_subsection.c_str(), &status) ){ |
---|
| 90 | duchampFITSerror(status,"writeMomentMapArray","Error : header I/O"); |
---|
| 91 | result=FAILURE; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | return result; |
---|
| 96 | |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | OUTCOME WriteMomentMapArray::writeData() |
---|
| 100 | { |
---|
[1354] | 101 | |
---|
| 102 | size_t size = this->itsCube->getSpatialSize(); |
---|
| 103 | float *momentMap = new float[size]; |
---|
| 104 | std::vector<bool> detectionMap = this->itsCube->getMomentMap(momentMap); |
---|
| 105 | OUTCOME result = this->writeToFITS_flt(size, momentMap); |
---|
| 106 | delete [] momentMap; |
---|
| 107 | return result; |
---|
| 108 | |
---|
[1120] | 109 | } |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | |
---|