Hero * Hero::constructFromFitsFile(const QString &fname) { FitsParser parser; bool parsedOk = parser.loadFile( FitsFileLocation::fromLocal( fname)); if( ! parsedOk) { dbg(1) << "Parser failed to load " << fname; Hero * heroPtr = new Hero; heroPtr-> addError( "FitsParser failed to load the file"); return heroPtr; } // alias hdr auto & hdr = parser.getHeaderInfo().headerLines; Hero * heroPtr = new Hero; Hero & hero = * heroPtr; AstErrorGuard guard( heroPtr); AstGCGuard gcGuard; // set naxes in case AST fails to read this file hero.m_ast.naxes = parser.getHeaderInfo().naxis; // set up bunit { hero.m_bunit = parser.getHeaderInfo().bunit; } // and the nicer version of bunit { QString u = hero.m_bunit.simplified(); if( u.toLower() == "kelvin") { hero.m_bunitNiceHtml = "K"; } else { hero.m_bunitNiceHtml = u; } } // Create a FitsChan and feed it the fits header AstFitsChan *fitschan; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-zero-length" fitschan = astFitsChan( NULL, NULL, "" ); #pragma GCC diagnostic pop std::cout << "astOK = " << astOK << "\n"; // feed the header lines one by one and check for errors for( const QString & s : hdr) { std::string stdstr = s.toStdString(); astPutFits( fitschan, stdstr.c_str(), 1); if( ! astOK) { astClearStatus; QString ss = s.trimmed(); std::cout << "Skipping bad card: " << ss << "\n"; hero.addError( "Skipping card: " + ss); } } // reposition to the beginning of the channel (ast thing, it's required, hmmmkey) astClear( fitschan, "Card" ); std::cout << "astOK = " << astOK << "\n"; std::cout << "Here\n"; auto encoding = AstWrappers::getC( fitschan, "Encoding" ); std::cout << "Encoding = " << encoding << "\n"; // do we have warnings? AstKeyMap * warnings = static_cast<AstKeyMap *>( astWarnings( fitschan)); if( warnings && astOK ) { std::cout << "Warnings:\n"; int iwarn = 1; while( astOK ) { std::string key = QString("Warning_%1").arg( iwarn).toStdString(); const char * message = nullptr; if( astMapGet0C( warnings, key.c_str(), & message ) ) { printf( "\n- %s\n", message ); hero.addError( QString( "Warning: %1").arg( message)); } else { break; } } } else { std::cout << "No warnings\n"; } // create a frameset for this file AstFrameSet * wcsinfo = static_cast<AstFrameSet *> ( astRead( fitschan )); std::cout << "astOK = " << astOK << "\n"; if ( ! astOK ) { std::cout << "astOK is not ok\n"; hero.addError( "astRead failed"); astClearStatus; return heroPtr; } else if ( wcsinfo == AST__NULL ) { hero.addError( "No WCS found in the fits file"); std::cout << "No WCS found\n"; return heroPtr; } else if ( AstWrappers::getC( wcsinfo, "Class" ) != "FrameSet") { std::cout << "Some other weird error occured\n"; hero.addError( "AstLib returned non-frame-set"); return heroPtr; } // frame was read in OK, save it hero.m_ast.origWcsInfo = wcsinfo; astExempt( hero.m_ast.origWcsInfo); hero.m_ast.currWcsInfo = astClone( hero.m_ast.origWcsInfo); astExempt( hero.m_ast.currWcsInfo); astShow( wcsinfo); // extract the current sky system // TODO: this assumes axis1 is a skycs QString skysys = AstWrappers::getC( wcsinfo, "System(1)"); hero.m_currentSkyCs = string2skycs( skysys); hero.m_originalSkyCs = hero.m_currentSkyCs; // extract the labels/etc for axes hero.m_ast.naxes = AstWrappers::getI( wcsinfo, "Naxes" ); hero.parseAxesInfo(); return heroPtr; }
/* ============== */ int main( int argc, char *argv[] ) { /* *+ * Name: * ast_test * Purpose: * Test installation of the AST library. * Type: * C program. * Description: * This program performs a simple test (without using graphics) of * the AST library, to check that it is correctly installed. It is * not an exhaustive test of the system. * Arguments: * None. * Copyright: * Copyright (C) 1997-2006 Council for the Central Laboratory of the * Research Councils * Licence: * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public Licence as * published by the Free Software Foundation; either version 2 of * the Licence, or (at your option) any later version. * * This program is distributed in the hope that it will be * useful,but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public Licence for more details. * * You should have received a copy of the GNU General Public Licence * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street,Fifth Floor, Boston, MA * 02110-1301, USA * Authors: * RFWS: R.F. Warren-Smith (Starlink) * History: * 19-NOV-1997 (RFWS); * Original version. *- */ /* Local Constants: */ #define NCOORD 10 /* Number of coordinates to transform */ /* Local Variables: */ AstFrameSet *cvt; /* Pointer to conversion FrameSet */ AstSkyFrame *sky1; /* Pointer to first SkyFrame */ AstSkyFrame *sky2; /* Pointer to second SkyFrame */ double xin[ NCOORD ]; /* Input coordinate array */ double xout[ NCOORD ]; /* Output coordinate array */ double yin[ NCOORD ]; /* Input coordinate array */ double yout[ NCOORD ]; /* Output coordinate array */ int i; /* Loop counter for coordinates */ /* Begin an AST context. */ astBegin; /* Create two SkyFrames. */ sky1 = astSkyFrame( "system = FK4_NO_E, equinox = B1920, epoch = B1958" ); sky2 = astSkyFrame( "system = ecliptic, equinox = J2001" ); /* Create a FrameSet describing the conversion between them. */ cvt = astConvert( sky1, sky2, "" ); /* If successful, set up some input coordinates. */ if ( cvt != AST__NULL ) { for ( i = 0; i < NCOORD; i++ ) { xin[ i ] = 0.1 * (double) i; yin[ i ] = 0.2 * (double) i; } /* Display the FrameSet. */ astShow( cvt ); printf( "\n"); /* Activate reporting of coordinate transformations. */ astSet( cvt, "Report = 1" ); /* Perform the forward transformation. */ astTran2( cvt, 10, xin, yin, 1, xout, yout ); printf( "\n"); /* Perform the inverse transformation. */ astTran2( cvt, 10, xout, yout, 0, xin, yin ); } /* End the AST context. */ astEnd; /* Return an error status. */ return astOK ? 0 : 1; /* Undefine local macros. */ #undef NCOORD }