/** @addtogroup tools */ /**@{*/ /********************************************************************************* * MPIA - MIDI project * * "@(#) $Id: Simbad2StarCat.C,v 1.1 2006/03/05 20:07:39 mathar Exp $" * * who when what * -------- -------- ---------------------------------------------- * mathar 2005-08-29 created from mioSimbad2Fits * * NAME * * Simbad2StarCat - convert SIMBAD e-mail response to PRIMA simulator config file * * SYNOPSIS * cd config ; ../calc/Simbad2StarCat -d Simbad* | sed 's/nan/0./g' > config.xml * cd config ; ../calc/Simbad2StarCat -f -d Simbad* > stars.fits * * Simbad2StarCat -w -- "+HH MM SS.sss +-DD MM SS.sss" theta/deg rho/arcsec * * DESCRIPTION * The program produces an XML file body by parsing the files named in the command line. * The intend of this program is to translate SIMBAD type of information * into the PRIMA simulator XML configuration. * These files ought be an ASCII copy of the response from the * "file query" in http://simbad.u-strasbg.fr using the second * of the formats described in the Simbad User's manual. * * If the -v option is used, the file names are also listed on stdout. * * With the -w option, one may generate two explicit coordinates of two * stars by listing the first star coordinates as indicated in the synopsis above, * and the second star coordinates with a position angle [deg] and a distance * [arcsec] in the style of the WDS catalog. * * If the -d option is used, each star found in the files Simbad* is * duplicated as to mimic a pair of stars. The output in 'config.xml' would * have to be edited to generate a distance between these two cloned stars. * * If the -f option is used, the output is not generated in XML but in FITS * format. * * FILES * * ENVIRONMENT * * CAUTIONS * * EXAMPLES * * SEE ALSO * http://simbad.u-strasbg.fr * Simbad2XmlBin * * NOTES * - The filename syntax sticks to object names that may contain stars (*) in * the common names. These are also reproduced in the operating system files * and often demand proper masking under UNIX to avoid file name globbing. * * TODO * - determine the EPOCH column * * BUGS * ********************************************************************************/ #include #include #include #include #include #include #include #include "slalib.h" #include "units.h" #include "prStarCat.C" using namespace std ; using namespace CCfits ; void usage(char *argv[]) { cerr << "usage: " << argv[0] << " [-v] e-mail-file-name [e-mail-file-name ...]" << endl ; } static void wds2Xml(const double ra, const double dec) { int ihmsf[4], idmsf[4] ; char sign ; slaDr2tf(4, ra, &sign, ihmsf) ; cout << "ra=\"" ; // suppress sign for the RA which is in the 0..24 hrs range if ( sign == '-') cout << sign ; cout << setfill('0') << setw(2) << ihmsf[0] << ":" << setw(2) << ihmsf[1] << ":" << setw(2) << ihmsf[2] << "." << ihmsf[3] << "\" dec=\""; slaDr2af(4, dec, &sign, idmsf) ; cout << sign << setfill('0') << setw(2) << idmsf[0] << ":" << setw(2) << idmsf[1] << ":" << setw(2) << idmsf[2] << "." << idmsf[3] << "\"" << endl ; } int main( int argc, char *argv[]) { if( argc < 2) { usage(argv) ; return 1 ; } char oc ; // extern int optopt, optind ; bool verbose = false ; bool wds = false ; bool duplic = false ; bool fits = false ; while ( (oc=getopt(argc,argv,"vwdf")) != -1 ) { switch(oc) { case 'v' : verbose=true ; break ; case 'd' : duplic=true ; break ; case 'w' : wds=true ; break ; case 'f' : fits= true ; break ; case '?' : cerr << "Invalid command line option " << optopt << endl ; break ; } } if ( wds) { char radec[80] ; strcpy(radec, argv[optind++]) ; double ra, dec, theta, rho ; theta = DEG2RAD(atof(argv[optind++])) ; rho = ARCSEC2RAD(atof(argv[optind++])) ; int raHr, raMin, decDeg, decMin ; double raSec, decSec ; sscanf(radec,"%d %d %lf %d %d %lf",&raHr, &raMin, &raSec, &decDeg, &decMin, &decSec) ; // cout << raHr << " " << raMin << " " << raSec << " " << decDeg << " " << decMin << " " << decSec << endl ; if( raHr < 0.) ra = (raHr - raMin/60. -raSec/3600.)/24. ; else ra = (raHr + raMin/60. +raSec/3600.)/24. ; if( decDeg < 0.) dec = (decDeg - decMin/60. -decSec/3600.)/360. ; else dec = (decDeg + decMin/60. +decSec/3600.)/360. ; // convert to radian ra *= 2.*M_PI ; dec *= 2.*M_PI ; wds2Xml(ra,dec) ; dec += rho*cos(theta) ; ra += rho*sin(theta) ; wds2Xml(ra,dec) ; cout << endl ; return 0 ; } starCat catalog ; /** Loop over all command line arguments and put all stars * into a single large catalogue. */ for(int arg= optind ; arg < argc ; arg++) { Simbad simb(argv[arg]) ; if (duplic) { Star starA(simb,true) ; catalog.add(starA) ; Star starB(simb,true) ; catalog.add(starB) ; } else { Star starA(simb,false) ; catalog.add(starA) ; } } /** Sort the catalog entries according to the stars, using Star::operator<() */ sort(catalog.begin(),catalog.end()) ; if ( fits) { FITS *f = catalog ; catalog.outFits(f) ; delete f ; } else { catalog.xml(cout) ; } return 0 ; } /**@}*/ /* $Log:$ */