Ejemplo n.º 1
0
/************************************************************************
**  PROCUSERCOORD --  Process a user-specified coordinate.  Generate a 
**  fake resolution record and output the requested values.
*/
static void
procUserCoord (char *ra, char *dec)
{
    register int i;
    char *fmt, sp;
    char  s_ra[SZ_FNAME], s_dec[SZ_FNAME], scoords[SZ_FNAME];
    double  dra = 0.0, ddec = 0.0;


    memset (s_ra, 0, SZ_FNAME);		/* initialize		*/
    memset (s_dec, 0, SZ_FNAME);
    memset (scoords, 0, SZ_FNAME);

    if (isDecimal (u_ra)) {
	dra = vot_atof (u_ra);
	sprintf (s_ra, "%s", toSexa (dra / 15.0));
    } else if (isSexagesimal (u_ra)) {
	dra = sexa (u_ra);
	strcpy (s_ra, u_ra);
    } else {
	fprintf (stderr, "Error in RA specification: '%s'\n", u_ra);
	return;
    }

    if (isDecimal (u_dec)) {
	ddec = vot_atof (u_dec);
	sprintf (s_dec, "%s", toSexa (ddec));
    } else if (isSexagesimal (u_dec)) {
	ddec = sexa (u_dec);
	strcpy (s_dec, u_dec);
    } else {
	fprintf (stderr, "Error in Dec specification: '%s'\n", u_dec);
	return;
    }

    sprintf (scoords, "%s %s", s_ra, s_dec);

    /*  Set the default output if we got no commandline flags so far.
    */
    ntargets++;
    if (nflags == 0) 
	flags[nflags++] = F_DEC;


    /*  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) {
        if (format)
	    fmt = "%12.12s%c%23.23s%c%9.5f%c%9.5f%c0.0%c0.0%c%s\n"; 
	else
	    fmt = "%s%c%s%c%f%c%f%c0.0%c0.0%c%s\n"; 

        fprintf (out, fmt, "UserCoord", delim, scoords, delim,
		dra, delim, ddec, delim, delim, delim, "Unknown");

    } else {
	for (i=0; i < nflags; i++) {
	    sp = (i < (nflags - 1) ? delim : (char) 0);
	    switch (flags[i]) {
	    case F_DEC:
    		fprintf (out, "%f%c%f", (float)dra, delim, (float)ddec);
		break;
	    case F_ERR:
    		fprintf (out, "0.0%c0.0", delim);
		break;
	    case F_NAM:
    		fprintf (out, "UserCoord");
		break;
	    case F_TYP:
    		fprintf (out, "Unknown");
		break;
	    case F_SEX:
    		fprintf (out, "%s", scoords);
		break;
	    }
	    if (sp)
    		fprintf (out, "%c", sp);
	}
    	fprintf (out, "\n");
    }
}
Ejemplo n.º 2
0
/**
 *  Application entry point.  All VOApps tasks MUST contain this 
 *  method signature.
 */
int
votopic (int argc, char **argv, size_t *reslen, void **result)
{
    int    i, nres_arg = 0, ndat_arg = 0, status = OK, term = 0;
    char  *res_argv[MAX_ARGS], *dat_argv[MAX_ARGS], *topic = NULL;
    char  *resname;


    memset (res_argv, 0, argc+2);	/* initialize	*/
    memset (dat_argv, 0, argc+2);
    resname = vot_mktemp ("votopic");


    /*  Parse the argument list.
     */
    if ((isDecimal (argv[argc-1]) || isSexagesimal (argv[argc-1])) &&
        (isDecimal (argv[argc-2]) || isSexagesimal (argv[argc-2])) &&
        (isDecimal (argv[argc-3]) || isSexagesimal (argv[argc-3])) )
	    term = argc - 4;
    if ((isDecimal (argv[argc-1]) || isSexagesimal (argv[argc-1])) &&
        !(isDecimal (argv[argc-2]) || isSexagesimal (argv[argc-2])) )
	    term = argc - 3;
    if (!(isDecimal (argv[argc-1]) || isSexagesimal (argv[argc-1])) )
	    term = argc - 2;

    /*  Initialize the VOREGISTRY arguments.
     */
    vot_setArg (res_argv, &nres_arg, "voregistry");

    /*  Initialize the VODATA arguments.
     */
    vot_setArg (dat_argv, &ndat_arg, "vodata");
    for (i=1; i < argc; i++) {
	if (i == term) {
            vot_setArg (dat_argv, &ndat_arg, resname);
	    topic = argv[i];
	} else {
	    if (strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--help")==0) {
		Usage (); return (0);
	    } else if (strcmp(argv[i],"-%")==0 || strcmp(argv[i],"--test")==0) {
		Tests (NULL); return (0);
	    } else if (strcmp(argv[i],"-d")==0 || strcmp(argv[i],"--dbg")==0) {
		debug++;

	    } else if ((strcmp(argv[i],"-b")==0 || 
		        strcmp(argv[i],"--bpass")==0) ||
	               (strcmp(argv[i],"-t")==0 || 
		        strcmp(argv[i],"--type")==0)) {
    		vot_setArg (res_argv, &nres_arg, argv[  i]);	/* -b | -t  */
    		vot_setArg (res_argv, &nres_arg, argv[++i]);	/* val      */
	    } else
                vot_setArg (dat_argv, &ndat_arg, argv[i]);
	}
    }


    /*  Create the list of VOREGISTRY arguments.
     */
    vot_setArg (res_argv, &nres_arg, "-d");		/* dalOnly 	*/
    vot_setArg (res_argv, &nres_arg, "-o");		/* output name	*/
    vot_setArg (res_argv, &nres_arg, resname);
    if (by_subj)
        vot_setArg (res_argv, &nres_arg, "-s");
    vot_setArg (res_argv, &nres_arg, topic);

    if (1||debug) {
	for (i=0; i < nres_arg; i++) 
	    printf ("'%s' ", res_argv[i]);
	printf ("\n");
	for (i=0; i < ndat_arg; i++) 
	    printf ("'%s' ", dat_argv[i]);
	printf ("\n");
    }


    /*  Run the Registry query to get the resource list of topics.
     */
    status = voregistry (nres_arg, res_argv, reslen, result);


    /*  Initialize result object whether we return an object or not.
     */
    *reslen = 0;	
    *result = NULL;

   /*  The VODATA task does all the real work, execute it on the list of
    *  resources we just obtained.
    */
    status = vodata (ndat_arg, dat_argv, reslen, result);


    /*  Clean up.  Rememebr to free whatever pointers were created when
     *  parsing arguments.
     */
    for (i=0; i < nres_arg; i++)
	if (res_argv[i]);
	    free ((void *) res_argv[i]);
    for (i=0; i < ndat_arg; i++)
	if (dat_argv[i]);
	    free ((void *) dat_argv[i]);
    unlink (resname);

    return (status);
}
Ejemplo n.º 3
0
Archivo: voObj.c Proyecto: 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);
}