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