[790] | 1 | #include <duchamp/duchamp.hh> |
---|
[788] | 2 | #include <duchamp/FitsIO/DuchampBeam.hh> |
---|
| 3 | #include <duchamp/FitsIO/Beam.hh> |
---|
| 4 | #include <duchamp/param.hh> |
---|
| 5 | #include <sstream> |
---|
| 6 | |
---|
| 7 | namespace duchamp |
---|
| 8 | { |
---|
| 9 | |
---|
| 10 | DuchampBeam::DuchampBeam(): |
---|
| 11 | Beam() |
---|
| 12 | { |
---|
| 13 | this->itsOrigin = EMPTY; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | DuchampBeam::DuchampBeam(float maj, float min, float pa): |
---|
| 17 | Beam(maj,min,pa) |
---|
| 18 | { |
---|
| 19 | this->itsOrigin = EMPTY; |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | DuchampBeam::DuchampBeam(const Beam &b): |
---|
| 23 | Beam(b) |
---|
| 24 | { |
---|
| 25 | this->itsOrigin = EMPTY; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | DuchampBeam::DuchampBeam(const DuchampBeam &b): |
---|
| 29 | Beam(b) |
---|
| 30 | { |
---|
| 31 | operator=(b); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | DuchampBeam& DuchampBeam::operator=(const DuchampBeam &b) |
---|
| 35 | { |
---|
| 36 | ((Beam &) *this) = b; |
---|
| 37 | this->itsOrigin = b.itsOrigin; |
---|
| 38 | return *this; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | void DuchampBeam::define(float maj, float min, float pa, BEAM_ORIGIN origin) |
---|
| 42 | { |
---|
| 43 | this->Beam::define(maj,min,pa); |
---|
| 44 | this->itsOrigin = origin; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void DuchampBeam::setFWHM(float fwhm, BEAM_ORIGIN origin) |
---|
| 48 | { |
---|
| 49 | this->Beam::setFWHM(fwhm); |
---|
| 50 | this->itsOrigin = origin; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | void DuchampBeam::setArea(float area, BEAM_ORIGIN origin) |
---|
| 54 | { |
---|
| 55 | this->Beam::setArea(area); |
---|
| 56 | this->itsOrigin = origin; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void DuchampBeam::empty() |
---|
| 60 | { |
---|
| 61 | this->itsMaj = this->itsMin = this->itsPA = this->itsArea = 0.; |
---|
| 62 | this->itsOrigin = EMPTY; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void DuchampBeam::define(Param &par, bool warn) |
---|
| 66 | { |
---|
| 67 | std::string paramName; |
---|
| 68 | bool doWarning=warn; |
---|
| 69 | if(par.getBeamFWHM()>0.){ |
---|
| 70 | this->setFWHM(par.getBeamFWHM(),PARAM); |
---|
| 71 | par.setBeamSize(this->itsArea); |
---|
| 72 | paramName = "beamFWHM"; |
---|
| 73 | par.setBeamAsUsed(*this); |
---|
| 74 | } |
---|
| 75 | else if(par.getBeamSize()>0.){ |
---|
| 76 | this->setArea(par.getBeamSize(),PARAM); |
---|
| 77 | paramName = "beamArea"; |
---|
| 78 | par.setBeamAsUsed(*this); |
---|
| 79 | } |
---|
| 80 | else{ |
---|
| 81 | this->empty(); |
---|
| 82 | doWarning = false; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | if(doWarning){ |
---|
| 86 | std::stringstream errmsg; |
---|
| 87 | errmsg << "Header beam keywords not present. Using parameter "<< paramName <<" to determine size of beam.\n"; |
---|
| 88 | duchampWarning("Beam definition",errmsg.str()); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | void DuchampBeam::readFromFITS(fitsfile *fptr, Param &par, float pixelScale) // read from file a la headerIO.cc |
---|
| 94 | { |
---|
| 95 | char *comment = new char[80]; |
---|
| 96 | std::string keyword[3]={"BMAJ","BMIN","BPA"}; |
---|
| 97 | float bmaj,bmin,bpa; |
---|
| 98 | |
---|
| 99 | // Read the Keywords. If they are present, read the |
---|
| 100 | // others, and calculate the beam size. |
---|
| 101 | // If it is not, give warning and set beam size to nominal value. |
---|
| 102 | int bstatus[3]={0,0,0}; |
---|
| 103 | fits_read_key(fptr, TFLOAT, (char *)keyword[0].c_str(), &bmaj, comment, &bstatus[0]); |
---|
| 104 | fits_read_key(fptr, TFLOAT, (char *)keyword[1].c_str(), &bmin, comment, &bstatus[1]); |
---|
| 105 | fits_read_key(fptr, TFLOAT, (char *)keyword[2].c_str(), &bpa, comment, &bstatus[2]); |
---|
| 106 | |
---|
| 107 | if(bstatus[0]||bstatus[1]||bstatus[2]){ // error |
---|
| 108 | this->define(par); |
---|
| 109 | } |
---|
| 110 | else{ // all keywords present |
---|
| 111 | this->define(bmaj/pixelScale, bmin/pixelScale, bpa, HEADER); |
---|
| 112 | par.setBeamSize(this->itsArea); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | void DuchampBeam::writeToFITS(fitsfile *fptr) // write to file, but only if itsOrigin==HEADER. Use cfitsio commands directly. |
---|
| 119 | { |
---|
| 120 | |
---|
| 121 | if(this->itsOrigin == HEADER){ |
---|
| 122 | char *keyword = new char[FLEN_KEYWORD]; |
---|
| 123 | int status = 0; |
---|
| 124 | strcpy(keyword,"BMAJ"); |
---|
| 125 | if (fits_update_key(fptr, TFLOAT, keyword, &this->itsMaj, NULL, &status)){ |
---|
| 126 | duchampError("Writing beam","Error writing beam info:"); |
---|
| 127 | fits_report_error(stderr, status); |
---|
| 128 | } |
---|
| 129 | status = 0; |
---|
| 130 | strcpy(keyword,"BMIN"); |
---|
| 131 | if (fits_update_key(fptr, TFLOAT, keyword, &this->itsMin, NULL, &status)){ |
---|
| 132 | duchampError("Writing beam","Error writing beam info:"); |
---|
| 133 | fits_report_error(stderr, status); |
---|
| 134 | } |
---|
| 135 | status = 0; |
---|
| 136 | strcpy(keyword,"BPA"); |
---|
| 137 | if (fits_update_key(fptr, TFLOAT, keyword, &this->itsPA, NULL, &status)){ |
---|
| 138 | duchampError("Writing beam","Error writing beam info:"); |
---|
| 139 | fits_report_error(stderr, status); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | } |
---|
| 147 | |
---|