/**
 *  VOA_RESOLVEFIELD -- Resolve an object field name to a position in decimal
 *  degrees.
 */
static int
voa_resolveField (char *field, double *ra, double *dec)
{
    Sesame sr;

    sr = voc_nameResolver (field);
    *ra = (double) voc_resolverRA (sr);
    *dec = (double) voc_resolverDEC (sr);

    return (0);
}
/************************************************************************
**  PRINT_RESULT --  Print the result table in the requested format.
*/
static int
print_result (char *target, Sesame sr)
{
    register int i, found;
    char     *type = NULL, *ip, *pos, sp;
    double   ra, dec, Era, Edec;


    if (sr == 0)			/* check for no match found	*/
	return (ERR);

    /* Fix the target name so spaces become underscores.
    */
    for (ip=target; *ip; ip++) {
        if (isspace (*ip) || *ip == '+')
    	    *ip = ' ';
    }

    /* First time through, check that the formatting makes sense and print
    ** the header if requested.
    */
    if (delim != ' ')
	format = 0;
    if (header && !invert) 
	print_header ();


    /* Get the information for the object.
    */
    pos = voc_resolverPos(sr);
    if (delim != ' ' && ip) {
        for (ip=pos; *ip; ip++)
            *ip = (isspace(*ip) ? delim : *ip);
    }
    ra   = voc_resolverRA(sr);
    dec  = voc_resolverDEC(sr);
    Era  = voc_resolverRAErr(sr);
    Edec = voc_resolverDECErr(sr);
    type = voc_resolverOtype(sr);
    pos  = voc_resolverPos(sr);

    found = 1;
    if (ra == 0.0 && dec == 0.0 && Era == 0.0 && Edec == 0.0)
	found = 0;


    /* Return if we didn't get any results.
    */
    if (!invert && !found)
	return (ERR);

    /*  Print the output in the order specified by the flags.  The exception
    **  is the '-a' flag to print all information we have, but we do so in a
    **  fixed format
    */
    if (all_flags) {
	char *fmt;


        if (format)
	    fmt = "%12.12s%c%23.23s%c%9.5f%c%9.5f%c%6.1f%c%6.1f%c%s\n"; 
	else
	    fmt = "%s%c%s%c%f%c%f%c%f%c%f%c%s\n"; 

	if (!invert || (!found && invert)) {
            fprintf (out, fmt, target, delim, pos, delim,
		ra, delim, dec, delim,
		Era, delim, Edec, delim,
		type);
	}

    } else if ((found && !invert) || (!found && invert)) {
	for (i=0; i < nflags; i++) {
	    sp = (i < (nflags - 1) ? delim : (char) 0);
	    switch (flags[i]) {
	    case F_DEC:
    		fprintf (out, "%f%c%f", ra, delim, dec);
		break;
	    case F_ERR:
    		fprintf (out, "%f%c%f", Era, delim, Edec);
		break;
	    case F_NAM:
    		fprintf (out, "%s", target);
		break;
	    case F_TYP:
    		fprintf (out, "%s", (type ? type : "Unknown"));
		break;
	    case F_SEX:
                for (ip=pos; *ip; ip++) {
                    if (isspace (*ip))
    	                *ip = delim;
                }
    		fprintf (out, "%s", pos);
		break;
	    }
	    if (sp)
    		fprintf (out, "%c", sp);
	}
    	fprintf (out, "\n");
    }


    return (OK);
}
Beispiel #3
0
Datei: voObj.c Projekt: pkgw/iraf
/****************************************************************************
**  Resolve a service name/list to the proper service URL and store the
**  result in the 'objList' global which we assume is declared in the caller.
*/
static int
vot_parseCmdLineObject (char *idlist)
{
    char    *ip, *op, *id, opos[SZ_LINE];
    double  ra, dec;
    Object *obj;
    Sesame  sesame;
    extern  double sr;


    /* Resolve the (list) of object names/positions and add them to the
    ** service list to be processed.
    */
    ip = idlist; 
    while (*ip) {

	/* Break up the input list into a single ID to resolve.
	*/
	op = &opos[0];
	bzero (opos, SZ_LINE);

	/* We allow positions to be comma-delimited, but objects
	** list are processed individually.
	*/
	while (*ip && *ip != '\n') {
	    if (*ip == ',') {
		if (isDecimal(opos) || isSexagesimal(opos)) {
		    *op++ = ' '; ip++;
		} else {
		    *ip++ = '\0';
		    break;
		}
	    } else
		*op++ = *ip++;
	}
	if (*ip && *(ip-1)) 		/* only advance on a position  	*/
	    ip++;


	/*  Process the name, position or file.
	*/
        if (access (opos, R_OK) == 0) {			/* file 	*/
	    vot_parseObjectList (opos, FALSE);
	    continue;

	} if (isDecimal (opos)) {			/* decimal 	*/
	    for (op=opos; !isspace (*op); op++) 
		;
	    ra  = atof (opos);
	    dec = atof (op);
	    id  = (char *) NULL;
	    all_named = 0;

	} else if (isSexagesimal (opos)) {		/* sexagesimal	*/
	    for (op=opos; !isspace (*op); op++) 
		;
	    ra  = sexa (opos) * 15.0;
	    dec = sexa (op);
	    id  = (char *) NULL;
	    all_named = 0;

	} else {					/* resolve name	*/
	    char *ip = opos;

            /* Clobber the newline and do a poor-man's URL encoding of
            ** embedded spaces.
            */
            for (ip=opos; *ip; ip++) {
                /*  preserve spaces.....  */
                if (*ip == ' ') *ip = '+';
                if (*ip == '\n') *ip = '\0';
            }

	    sesame = voc_nameResolver (opos);
	    ra   = voc_resolverRA (sesame);
	    dec  = voc_resolverDEC (sesame);
	    id = opos;
	    all_named = 1;

	    /* If the positions are zero, make sure the errs are also zero
	    ** before deciding that the resolver failed.  We won't bother
	    ** with this object but will print a warning.
	    */
	    if (ra == 0.0 && dec == 0.0) {
	        if (voc_resolverRAErr (sesame) == 0.0 &&
	            voc_resolverDECErr (sesame) == 0.0) {
			fprintf (stderr,
			    "Warning: Cannot resolve '%s'....skipping\n", opos);
			continue;
	        }
	    }
	}

        if (verbose && id && !quiet)
	    fprintf (stderr,"# Resolver: %-20s -> %-10.10s %.6f %.6f  (%.2f)\n",
		opos, (id ? id : "(none)"), ra, dec, (float)sr);

        /* Save results in the object list.
        */
	obj =  (Object *)calloc (1,sizeof(Object));
        if (!objList)
	    objList = objTail = obj;
	else
	    objTail->next = (Object *)obj;

	strcpy (obj->name, (id ? id : ""));
	obj->ra  = ra;
	obj->dec = dec;
	obj->index = objIndex++;

        objTail  = obj;
    }

    return (0);
}
Beispiel #4
0
Datei: voObj.c Projekt: pkgw/iraf
/****************************************************************************
**  Resolve a service name/list to the proper service URL and store the
**  result in the 'objList' global which we assume is declared in the caller.
*/
static int
vot_objectResolver (char *idlist, int nwords, int isCmdLine)
{
    char    *id = (char *)NULL, *name = (char *)NULL, *ip;
    double  ra, dec;
    Object *obj;
    Sesame  sesame;


    /*  The task was originally written to allow comma-delimieted objects
    **  to be specified on the command line, or as multiple objects in a
    **  file.  To preserve this functionality we'll call the old code when
    **  given a command-line argument, otherwise we'll parse the file
    **  according to more strict rules below.
    */
    if (isCmdLine) {
	return ((int)vot_parseCmdLineObject (idlist));
    }


    /*  If there is only a single item on the line then it can only be either
    **  the name of a file to be processed, or an object to be resolved.
    */
    if (nwords == 1) {

        if (access (idlist, R_OK) == 0) {		/* file 	*/
	    vot_parseObjectList (idlist, FALSE);
    	    return (OK);

	} else {					/* resolve name	*/
            /* Clobber the newline and do a poor-man's URL encoding of
            ** embedded spaces.
            */
            for (ip=idlist; *ip; ip++) {
                /*  preserve spaces.....  */
                if (*ip == ' ') *ip = '+';
                if (*ip == '\n') *ip = '\0';
            }

	    sesame = voc_nameResolver (idlist);
	    ra   = voc_resolverRA (sesame);
	    dec  = voc_resolverDEC (sesame);
	    name = idlist;

	    /* If the positions are zero, make sure the errs are also zero
	    ** before deciding that the resolver failed.  We won't bother
	    ** with this object but will print a warning.
	    */
	    if (ra == 0.0 && dec == 0.0) {
	        if (voc_resolverRAErr (sesame) == 0.0 &&
	            voc_resolverDECErr (sesame) == 0.0) {
			fprintf (stderr,
			    "Warning: Cannot resolve '%s'....skipping\n", name);
			return (ERR);
	        }
	    } else 
	        all_named = 1;
	}

        if (verbose && id && !quiet) {
	    fprintf (stderr,"# Resolver: %-20s -> ", (name ? name : "(none)"));
	    fprintf (stderr," %11.11s", toSexa(ra));
	    fprintf (stderr," %12.12s", toSexa(dec));
	    fprintf (stderr,"\n");
        }

    } else {

	/* The line represents a table of some kind.  In the simplest form
	** this could just be the RA/Dec in a 2-column list but it could
	** also be a CSV file where the 'cols' parameter tell us where to
	** find the values.  The 'id' string may be optional in the table,
	** if not specified we'll make something up.
	*/
	id = vot_parseTableLine (idlist, nwords, &ra, &dec); 

        if (verbose > 1&& id && !quiet) {
	    fprintf (stderr,"# Resolver: %-16.16s", (id ? id : "(none)"));
	    fprintf (stderr," %11.11s", toSexa(ra));
	    fprintf (stderr," %12.12s", toSexa(dec));
	    fprintf (stderr,"\n");
        }

	if (OBJ_DEBUG)
	    fprintf (stderr, "ra=%f dec=%f id='%s'\n", ra, dec, (id?id:"null"));
    }

    /* Save results in the object list.
    */
    obj =  (Object *)calloc (1,sizeof(Object));
    if (!objList)
	objList = objTail = obj;
    else
	objTail->next = (Object *)obj;

    strcpy (obj->name, (name ? name : ""));
    strcpy (obj->id, (id ? id : ""));
    obj->ra  = ra;
    obj->dec = dec;
    obj->index = objIndex++;

    objTail  = obj;


    return (OK);
}