From eac0e1afc7aa0e7711f52fd676b436162eff927a Mon Sep 17 00:00:00 2001 From: William Joye Date: Wed, 13 Dec 2017 18:05:13 -0500 Subject: upgrade AST --- tksao/frame/fitsimage.C | 118 +++++++++++++++++++++++++++++------------------- tksao/frame/fitsimage.h | 5 +- 2 files changed, 76 insertions(+), 47 deletions(-) diff --git a/tksao/frame/fitsimage.C b/tksao/frame/fitsimage.C index 123e559..c2cd60d 100644 --- a/tksao/frame/fitsimage.C +++ b/tksao/frame/fitsimage.C @@ -117,6 +117,7 @@ FitsImage::FitsImage(Context* cx, Tcl_Interp* pp) wcsEqu_ =NULL; wcsCel_ =NULL; wcs3D_ =NULL; + wcsHPX_ =NULL; #endif wcsHeader_ =NULL; altHeader_ =NULL; @@ -206,6 +207,8 @@ FitsImage::~FitsImage() delete [] wcsCel_; if (wcs3D_) delete [] wcs3D_; + if (wcsHPX_) + delete [] wcsHPX_; } #endif @@ -1016,11 +1019,6 @@ char* FitsImage::displayWCS() return display(image_->head()); } -int FitsImage::findKeyword(const char* key) -{ - return fits_->find(key); -} - FitsBound* FitsImage::getDataParams(FrScale::SecMode which) { switch (which) { @@ -1124,6 +1122,9 @@ void FitsImage::initWCS() if (wcs3D_) delete [] wcs3D_; wcs3D_ = NULL; + if (wcsHPX_) + delete [] wcsHPX_; + wcsHPX_ = NULL; } #endif @@ -1151,6 +1152,7 @@ void FitsImage::initWCS() wcsEqu_ = ptr->wcsEqu_; wcsCel_ = ptr->wcsCel_; wcs3D_ = ptr->wcs3D_; + wcsHPX_ = ptr->wcsHPX_; #endif #ifndef NEWWCS @@ -1230,6 +1232,7 @@ void FitsImage::initWCS() wcsEquInit(); wcsCelInit(); wcs3DInit(); + wcsHPXInit(); if (DebugAST && ast_) astShow(ast_); @@ -1453,8 +1456,6 @@ void FitsImage::match(const char* xxname1, const char* yyname1, Coord::DistFormat dist, const char* rrname) { - astClearStatus; - // get lists Tcl_Obj* listxx1 = Tcl_GetVar2Ex(interp_, xxname1, NULL, TCL_LEAVE_ERR_MSG); @@ -3079,28 +3080,31 @@ double FitsImage::getWCSRotation(Coord::CoordSystem sys, Coord::SkyFrame sky) if (!hasWCS(sys)) return 0; - astClearStatus; // just to make sure setWCSSkyFrame(sys, sky); - Vector in[2]; - Vector out[2]; - in[0] = center(); - in[1] = center()+Vector(0,1); - wcsTran(2, in, 1, out); - double ang = wcsAxAngle(out[0], out[1]); - { - // Vector npix = wcsTran(out[0]+Vector(0,.1),0); - // Vector epix = wcsTran(out[0]+Vector(.1,0),0); - // Vector north = (npix-in[0]).normalize(); - // Vector east = (epix-in[0]).normalize(); - // Vector diff = (north-east).abs(); - // double bb = -(north.angle()-M_PI_2); - // double aa = getWCSOrientation(sys,sky) == Coord::NORMAL ? ang : -ang; - // cerr << radToDeg(aa) << '=' << radToDeg(bb) << endl; - } - - if (!(isnan(ang)||isinf(ang)||(ang == -DBL_MAX)||(ang == DBL_MAX))) - return getWCSOrientation(sys,sky) == Coord::NORMAL ? ang : -ang; + if (!hasWCSHPX(sys)) { + Vector in[2]; + Vector out[2]; + in[0] = center(); + in[1] = center()+Vector(0,1); + wcsTran(2, in, 1, out); + double ang = wcsAxAngle(out[0], out[1]); + if (!(isnan(ang)||isinf(ang)||(ang == -DBL_MAX)||(ang == DBL_MAX))) + return getWCSOrientation(sys,sky) == Coord::NORMAL ? ang : -ang; + } + else { // special case for HPX + Vector cc = center(); + Vector wcc = wcsTran(cc, 1); + Vector wup = wcc + Vector(0,.001); + Vector up = wcsTran(wup,0); + + int current = astGetI(ast_,"Current"); + int base = astGetI(ast_,"Base"); + astSetI(ast_,"Current",base); + double ang = wcsAxAngle(cc,up); + astSetI(ast_,"Current",current); + return ang; + } return 0; } @@ -3126,8 +3130,6 @@ const char* FitsImage::getWCSName(Coord::CoordSystem sys) Vector FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, Coord::SkyFrame sky) { - astClearStatus; - int ss = sys-Coord::WCS; if (!(ss>=0 && ast_ && ast_[ss])) return Vector(); @@ -3164,7 +3166,6 @@ char* FitsImage::pix2wcs(const Vector& in, Coord::CoordSystem sys, Coord::SkyFrame sky, Coord::SkyFormat format, char* lbuf) { - astClearStatus; lbuf[0] = '\0'; int ss = sys-Coord::WCS; @@ -3354,8 +3355,6 @@ char* FitsImage::pix2wcs(const Vector3d& in, Coord::CoordSystem sys, Vector FitsImage::wcs2pix(const Vector& vv, Coord::CoordSystem sys, Coord::SkyFrame sky) { - astClearStatus; - int ss = sys-Coord::WCS; if (ss>=0 && ast_ && ast_[ss]) { setWCSSkyFrame(ast_[ss],sky); @@ -3445,8 +3444,6 @@ int FitsImage::hasWCS(Coord::CoordSystem sys) int FitsImage::hasWCSEqu(Coord::CoordSystem sys) { - astClearStatus; - int ss = sys-Coord::WCS; if (ss>=0 && ast_ && ast_[ss]) if (wcsIsASkyFrame(ast_[ss])) { @@ -3477,8 +3474,6 @@ int FitsImage::hasWCSEqu(Coord::CoordSystem sys) int FitsImage::hasWCSCel(Coord::CoordSystem sys) { - astClearStatus; - int ss = sys-Coord::WCS; if (ss>=0 && ast_ && ast_[ss]) if (wcsIsASkyFrame(ast_[ss])) @@ -3512,6 +3507,15 @@ int FitsImage::hasWCSCel(Coord::CoordSystem sys) else return wcsCel_[sys-Coord::WCS]; } + +int FitsImage::hasWCSHPX(Coord::CoordSystem sys) +{ + if (!ast_ || !wcsHPX_ || sysgetKeyword(key); + if (str) + if (!strncmp(str+5,"HPX",3)) + wcsHPX_[ii] =1; + } + } +} + #endif #ifndef NEWWCS @@ -3842,8 +3865,7 @@ void FitsImage::astinit0(int ss, FitsHead* hd, FitsHead* prim) return; // set default skyframe - if (wcsIsASkyFrame(ast_[ss])) - setWCSSkyFrame(ast_[ss],Coord::FK5); + setWCSSkyFrame(ast_[ss],Coord::FK5); } #endif @@ -4046,7 +4068,11 @@ void FitsImage::setWCSSkyFrame(Coord::CoordSystem sys, Coord::SkyFrame sky) #ifndef NEWWCS int FitsImage::wcsIsASkyFrame(AstFrameSet* ast) { - return astIsASkyFrame(astGetFrame(ast,AST__CURRENT)); + astClearStatus; + astBegin; + int rr = astIsASkyFrame(astGetFrame(ast,AST__CURRENT)); + astEnd; + return rr; } #endif diff --git a/tksao/frame/fitsimage.h b/tksao/frame/fitsimage.h index 9352791..2907854 100644 --- a/tksao/frame/fitsimage.h +++ b/tksao/frame/fitsimage.h @@ -121,6 +121,7 @@ class FitsImage { int* wcsEqu_; int* wcsCel_; int* wcs3D_; + int* wcsHPX_; #endif FitsHead* wcsHeader_; // alt wcs header FitsHead* altHeader_; // wcs header for wfpc2 @@ -161,6 +162,7 @@ class FitsImage { void wcsEquInit(); void wcsCelInit(); void wcs3DInit(); + void wcsHPXInit(); #endif void astinit0(int, FitsHead*, FitsHead*); int checkWCS(Vector&); @@ -442,6 +444,7 @@ class FitsImage { int hasWCSEqu(Coord::CoordSystem); int hasWCSCel(Coord::CoordSystem); int hasWCS3D(Coord::CoordSystem); + int hasWCSHPX(Coord::CoordSystem); void updateMatrices(Matrix&, Matrix&, Matrix&, Matrix&, Matrix&); void updateMatrices(Matrix3d&, Matrix3d&, Matrix3d&, Matrix3d&); @@ -526,7 +529,7 @@ class FitsImage { char* displayWCS(); FitsHead* head() {return image_->head();} char* getKeyword(const char* key) {return fits_->getKeyword(key);} - int findKeyword(const char*); + int findKeyword(const char* key) {return fits_->find(key);} int saveFitsPrimHeader(OutFitsStream& str) {return image_ ? image_->saveFitsPrimHeader(str) : 0;} -- cgit v0.12