/** @addtogroup tools */ /**@{*/ /** * * @file * * - NAME * Wds2StarCat - convert WDS catalogue entries to FITS catalog file * * - SYNOPSIS * @code * Wds2StarCat [-s] -f wds-ascii-file.txt [-f wds-ascii-file2.txt ...] firststardesig [secondstardesig ...] * Wds2StarCat [-s] -f wds-ascii-file.txt [-f wds-ascii-file2.txt ...] -r starregexp * @endcode * * - DESCRIPTION * Catalogue lines of the txt version of the WDS catalog of http://ad.usno.navy.mil/wds/ * are converted into the PRIMA star catalog FITS format.\n * The arguments of the -f options must be ASCII files containing pieces of the * full input catalog; these files will not be changed and are only * used in read-mode. At least one of these must be provided.\n * All other command line arguments must contain designators * within any of these cataloges, which are the first 10 letters in each of * its lines. Alternatively, the switch -r may be used to provide a * regular expression to match all stars in a name group. To prevent the UNIX * shell from expanding this into a list of files, this argument must * generally be included in simple quotes.\n * A FITS file is written to standard output containing all stars selected by * the command line arguments. If the switch -s is used (recommended), the results * will be sorted according to increasing right ascension.\n * Proper motions that are not found in the WDS catalog are reported as * zero on output. * * - FILES * @c wdsnew[1234].txt are the standard names of the WDS ASCII files * after downloading them from the web page. To search through all of * them at a time, one would first concatenate the pieces to a large * file and continue with this one: * @code * cat wdsnewweb[1-4].txt > wdsnewweb.txt * Wds2StarCat -f wdsnewweb ... > stars.fits * @endcode * or scan them separately * @code * Wds2StarCat -f wdsnewweb1.txt -f wdsnewweb2.txt ... > stars.fits * @endcode * * - EXAMPLES * @code * Wds2StarCat -f wdsnewweb1.txt 00004+5044 00005+3114 * Wds2StarCat -s -f wdsnewweb1.txt -f wdsnewweb2.txt 00005+4556 00005+3114 00005-0342 00002-3623 00003-4417 00017+6309 * Wds2StarCat -s -f wdsnewweb1.txt -r '^00005' * Wds2StarCat -s -f wdsnewweb2.txt -r '^00005.*\+' * @endcode * * @see * WDS * * @remarks * The information on ellptical parameters or the inclination * towards the line of sight is not available by these means. * @remarks * Triple systems and systems of more stars are represented by more than * one line in the original catalog (e.g. 00026+6606). If one of these * is selected by command line argument, each of the source lines generates * two stars in the PRIMA output catalog, and some of these need to be * removed by hand if duplications are to be avoided. * . * * @author Richard J. Mathar * @version $Id: Wds2StarCat.C,v 1.2 2006/03/06 17:48:12 mathar Exp $ * */ #include #include #include #include #include #include #include #include #include // STL headers #include #include #include #include #include "prStarCat.C" using namespace std ; /** * write a short usage hint to the standard error. * @param argv all command line arguments actually used */ void usage(char *argv[]) { cerr << "usage: " << argv[0] << " [-s] -f wdscat-file [-f wdscat-file2 .. ] star1name [star2name ...] > stars.fits" << endl ; cerr << "usage: " << argv[0] << " [-s] -r -f wdscat-file [-f wdscat-file2 .. ] starregexp > stars.fits" << endl ; } // maximum line length of the ASCII input file #define WDSLL 256 /** * Collect the entries for all stars that match the request. * @param ifiles the list of input files, each in the WDS line format * @param allstars a list of star denominators * @param useRege true if @c allstars[0] contains a regular expression */ static vector * wdsSelect(const vector & ifiles, vector &allstars, const bool useRege) { vector * retour = 0 ; regex_t preg ; if ( useRege) if ( regcomp(&preg,allstars[0].c_str(),0) ) { perror("") ; return retour ; } char wdslinebuf[WDSLL] ; // first accumulate all in the 'resul' map resul ; // outer loop over the WDS catalogues for(int c=0 ; c < ifiles.size() ; c++) { ifstream wds(ifiles[c].c_str()) ; if ( !wds || wds.fail() ) { cerr << "Cannot open " << ifiles[c] << endl ; continue ; } // outer loop over the WDS catalogue lines while( wds.getline(wdslinebuf,WDSLL) && wds) { wdsstar bina(wdslinebuf) ; // inner loop over the requested stars if ( useRege) { if( bina.nameMatches(&preg) ) // names match resul.insert( map::value_type(bina,bina.name()) ) ; } else for(int s=0; s < allstars.size(); s++) { if( allstars[s] == bina.name() ) // names match resul.insert( map::value_type(bina,bina.name()) ) ; } } wds.close() ; } if( useRege) regfree(&preg) ; /* debugging * map::iterator ss = resul.begin() ; *for( ; ss != resul.end(); ss++) * cout << __FILE__ << " " << __LINE__ << (*ss).first << endl ; */ retour = new vector(0) ; map::iterator s = resul.begin() ; for( ; s != resul.end(); s++) retour->push_back( (*s).first ) ; return retour ; } #undef WDSLL /** * The main entry to start the program from the UNIX command line. * The command line is parsed for the only supported switch, the * following command line argument is interpreted as the WCS catalog file, * and all the remaining command line arguments are entries in this catalog. * @param argc the number of command line arguments, including a switch * @param argv the command name and command line arguments */ int main( int argc, char *argv[]) { if( argc < 4) { usage(argv) ; return 1 ; } char oc ; vector ifiles ; // extern int optopt, optind ; bool sor = false ; bool useRege = false ; while ( (oc=getopt(argc,argv,"sf:r")) != -1 ) { switch(oc) { case 's' : sor =true ; break ; case 'r' : useRege=true ; break ; case 'f' : ifiles.push_back(optarg) ; break ; case '?' : cerr << "Invalid command line option " << optopt << endl ; break ; } } if ( ifiles.empty() ) { cerr << "No WDS files provided (missing -f options)" << endl ; usage(argv) ; return 1 ; } // put all the remaining command line arguments into a list of stars vector allstars ; for(int c=optind ; c < argc ; c++) allstars.push_back(argv[c]) ; /** Terminate if no requests have actually been put on the command line */ if ( allstars.empty() ) { cerr << "No star names provided" << endl ; usage(argv) ; return 1 ; } if ( useRege && allstars.size() > 1 ) { cerr << "All star patterns other than " << allstars[0] << " will be ignored\n" ; usage(argv) ; } #ifdef DEBUG for(int s=0; s < allstars.size(); s++) cout << "star " << s << " " << allstars[s] << endl ; #endif /** Scan all WDS files for stars that match the designators */ const vector * wdsvec = wdsSelect(ifiles,allstars,useRege) ; /** Convert them into the memory (class) format with the StarCat(vector*) constructor */ starCat catalog(wdsvec) ; /** Sort the catalog if requested */ if ( sor ) sort(catalog.begin(),catalog.end()) ; FITS *f(catalog) ; /** Generate the FITS representation from the internal format with starCat::outFits() */ catalog.outFits(f) ; /* debugging * cerr << __FILE__ << " " << __LINE__ << " " << wdsvec->size() << " stars " << endl ; */ /** Clean up the dynamically created objects */ delete f ; delete wdsvec ; return 0 ; } /**@}*/ /* $Log: Wds2StarCat.C,v $ Revision 1.2 2006/03/06 17:48:12 mathar Implemented sorting option. Revision 1.1 2006/03/05 20:07:39 mathar First version of a coherent suite of CCfits based star catalogue functions. Revision 1.2 2005/09/19 10:30:19 mathar Added more support for more than one WDS catalog file, and for a regular expression as the star designator to match a series of star names. Revision 1.1 2005/09/18 20:29:32 mathar First version of the program (which converts WDS entries to an APES catalog). */