00001
00002
00003
00004
00005
00006
00007 #ifndef RADECBYAST_HXX
00008 #define RADECBYAST_HXX
00009
00010
00011 extern "C"
00012 {
00013 #include "ast.h"
00014 }
00015
00016 #include <cmath>
00017
00018 #include "Converter.h"
00019 #include "FitsFile.h"
00020 #include "Logger.h"
00021 #include "DataMethod.hxx"
00022 #include "StringOps.h"
00023
00026 template<typename DataType>
00027 class RaDecByAst : public DataMethod<DataType>
00028 {
00029 public:
00031 RaDecByAst(const FitsFile& aFile)
00032 : mFile(aFile)
00033 { DataMethod<DataType>::methodName = "RaDecByAst"; }
00034
00036 virtual ~RaDecByAst() { }
00037
00040 void setSource(IntMap& tbls, IntMap& cols, StringMap units)
00041 {
00042 extnumColno = cols[0];
00043 xColno = cols[1];
00044 yColno = cols[2];
00045 extnumTblno = tbls[0];
00046 xTblno = tbls[1];
00047 yTblno = tbls[2];
00048 }
00049
00052 void setTarget(IntMap& cols, StringMap units)
00053 {
00054 raColno = cols[0];
00055 decColno = cols[1];
00056
00057
00058
00059 Converter conv;
00060 raFact = conv.getFactor("RADIANS", units[0]);
00061 decFact = conv.getFactor("RADIANS", units[1]);
00062 }
00063
00065 void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2)
00066 {
00067 double pi = M_PI;
00068 string filename = mFile.getFileName();
00069 double crval1,crval2;
00070
00071
00072 astBegin;
00073
00074
00075 AstFitsChan *fitschan = astFitsChan( NULL, NULL, "" );
00076 AstFrameSet *wcsinfo0 = 0;
00077 AstFrameSet *wcsinfo1 = 0;
00078 AstFrameSet *wcsinfo2 = 0;
00079 AstFrameSet *wcsinfo3 = 0;
00080
00081 for (int hduNo = 2; hduNo <= mFile.getNumHdus(); ++hduNo)
00082 {
00083 int ext = hduNo - 2;
00084
00085
00086 mFile.movabsHdu(hduNo);
00087
00088
00089
00090 int ncards = mFile.getNumCards();
00091 for (int n = 0; n < ncards; ++n) {
00092 char card[80];
00093 mFile.readCard(n, card);
00094 astPutFits(fitschan, card, 0);
00095 }
00096
00097 astClear( fitschan, "Card" );
00098 mFile.readKey(FitsFile::cCRVAL1,crval1);
00099 mFile.readKey(FitsFile::cCRVAL2,crval2);
00100 if (crval1 == 0 && crval2 == 0) {
00101 log.addError("Could not read WCS info for " + filename);
00102 } else {
00103 if (ext == 0) {
00104 wcsinfo0 = (AstFrameSet*)astRead(fitschan);
00105 } else if (ext == 1) {
00106 wcsinfo1 = (AstFrameSet*)astRead(fitschan);
00107 } else if (ext == 2) {
00108 wcsinfo2 = (AstFrameSet*)astRead(fitschan);
00109 } else if (ext == 3) {
00110 wcsinfo3 = (AstFrameSet*)astRead(fitschan);
00111 }
00112 }
00113 }
00114
00115
00116 double xpix[1], ypix[1], xsky[1], ysky[1];
00117
00118 for (int rowNo = row1; rowNo < row2; ++rowNo)
00119 {
00120
00121
00122
00123 Numeric value;
00124 data.value(extnumColno, rowNo, value);
00125
00126 int extNum = (int)value;
00127
00128 if (crval1 != 0 || crval2 != 0)
00129 {
00130
00131
00132 inpData.value(xColno, rowNo, xpix[0]);
00133 inpData.value(yColno, rowNo, ypix[0]);
00134
00135
00136
00137 if (extNum == 2)
00138 {
00139 astTran2(wcsinfo0, 1, xpix, ypix, 1, xsky, ysky);
00140 }
00141 else if (extNum == 3)
00142 {
00143 astTran2(wcsinfo1, 1, xpix, ypix, 1, xsky, ysky);
00144 }
00145 else if (extNum == 4)
00146 {
00147 astTran2(wcsinfo2, 1, xpix, ypix, 1, xsky, ysky);
00148 }
00149 else if (extNum == 5)
00150 {
00151 astTran2(wcsinfo3, 1, xpix, ypix, 1, xsky, ysky);
00152 }
00153
00154
00155 if (xsky[0] < 0) xsky[0] += 2 * pi;
00156
00157 Numeric ra = raFact * xsky[0];
00158 Numeric dec = decFact * ysky[0];
00159
00160 data.assign(raColno, rowNo, ra);
00161 data.assign(decColno, rowNo, dec);
00162 }
00163 }
00164
00165 astEnd;
00166 }
00167
00168
00169 void doit(TableData<DataType>& data, int row1, int row2) { }
00170
00171 private:
00172 FitsFile mFile;
00173 int extnumColno, raColno, decColno, xColno, yColno;
00174 int extnumTblno, xTblno, yTblno;
00175 double decFact, raFact;
00176 Logger log;
00177 };
00178
00179 #endif
00180
00181
00182
00183
00184