Ejemplo n.º 1
0
/**
 *  VOA_RESOLVEPOS -- Resolve a position string to decimal degrees.
 */
static int
voa_resolvePos (char *pos, double *ra, double *dec)
{
    char *ip = NULL, *s1 = NULL, *s2 = NULL;


    if ( (ip = strchr (pos, (int)' '))) {
	*ip = '\0';
	s1 = pos;
	s2 = ip + 1;

	if (strchr (s1, (int)':'))
	    *ra = (15. * (double) sexa (s1));
	else
	    *ra =  (double) atof (s1);
	*dec = (strchr (s2,(int)':') ? (double) sexa (s2) : (double) atof (s2));

	return (0);
    } else
	return (ERR);

}
Ejemplo n.º 2
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.º 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);
}
Ejemplo n.º 4
0
/**
 *  Application entry point.
 */
int 
voatlas (int argc, char **argv, size_t *reslen, void **result)
{
    char **pargv, optval[SZ_FNAME], ch;
    char  *iname = NULL, *oname = NULL, *dlname = NULL;
    char   tmp[SZ_FNAME], buf[SZ_FNAME];
    int    i=0, status = OK, apos = 0, samp = -1, naxis = 512;


    /*  Initialize.
     */
    memset (buf, 0, SZ_FNAME);
    memset (tmp, 0, SZ_FNAME);
    memset (survey, 0, SZ_FNAME);
    memset (svc_url, 0, SZ_URL);

    *reslen = 0;
    *result = NULL;


    /*  Parse the argument list.
     */
    pargv = vo_paramInit (argc, argv);
    while ((ch = vo_paramNext (opts,long_opts,argc,pargv,optval,&apos)) != 0) {
	i++;
        if (ch > 0) {
            switch (ch) {
	    case '%':  Tests (optval);			return (OK);
	    case 'h':  Usage ();			return (OK);
	    case 'r':  do_return++;			break;

	    case 'b':  bpass  = strdup (optval);   	break;
	    case 'g':  graphic++;			break;
	    case 'p':  strcpy (survey, optval);		break;
	    case 'n':  naxis = atoi (optval);		break;

	    case 'F':  field  = strdup (optval);   	break;
	    case 'R':  if (strchr (optval, (int)':'))
	    		  ra = (15. * (double) sexa (optval));
		       else
	    		  ra = (double) atof (optval);
		       break;
	    case 'D':  if (strchr (optval, (int)':'))
	    		  dec = (double) sexa (optval);
		       else
	    		  dec = (double) atof (optval);
		       break;
	    case 'P':  sscanf (optval, "%lf,%lf", &ra, &dec);
		       break;

	    case 's':  size   = voa_getSize (optval); 	break;
	    case 'o':  oname  = strdup (optval);   	break;

	    case 'S':  do_samp = 1;			break;
	    case 'v':  verbose = 1;			break;

	    default:
		fprintf (stderr, "Invalid argument '%c'\n", ch);
		return (ERR);
	    }
	} else {
	    /*  FIXME -- Doesn't handle e.g. 3c273 properly.
	    if (isdigit(optval[0]))
	     */
	    if (i == (argc-2)) {
		sprintf (buf, "%s %s", optval, argv[i+1]);
		pos = strdup (buf);
	    } else
		field = strdup (optval);
	    break;
	}
    }

    /*  Setup the output name.
     */
    if (oname) {
	dlname = oname;			    /* output name specified	*/
    } else if (do_samp) {
	strcpy (tmp, "/tmp/voatlasXXXXXX");    /* temp download name	*/
	mktemp (tmp);
	dlname = tmp;
    } else {
	if (field)
	    sprintf (buf, "%s.%s", field, (graphic ? "jpg" : "fits"));
	else if (pos) {
	    char *ip, *op;

	    memset (buf, 0, SZ_FNAME);
	    for (op=buf, ip=pos; *ip; ip++)
		*op++ = (*ip == ' ' ? '_' : *ip);
	    strcat (buf, ".");
	    strcat (buf, (graphic ? "jpg" : "fits"));
	} else {
	    fprintf (stderr, "Error: no output name specified.\n");
	    status = ERR;
	    goto done_;
	}
	dlname = oname = strdup (buf);
    }

    if (!survey[0]) {
	/*  No survey specified so go by the bandpass.
	 */
        if (!bpass)
	    strcpy (survey, "dss2b");
        else {
	    if (strncasecmp (bpass, "optical", 3) == 0)
	        strcpy (survey, "dss");
	    else if (strncasecmp (bpass, "infrared", 3) == 0 ||
		   strncasecmp (bpass, "ir", 2) == 0)
	        strcpy (survey, "2massk");
	    else if (strncasecmp (bpass, "x-ray", 1) == 0)
	        strcpy (survey, "pspc2int");
	    else if (strncasecmp (bpass, "euv", 3) == 0)
	        strcpy (survey, "euv83");
	    else if (strncasecmp (bpass, "gamma-ray", 5) == 0)
	        strcpy (survey, "egret1000");
	    else if (strncasecmp (bpass, "radio", 3) == 0)
	        strcpy (survey, "4850mhz");
        }
    } else if (strcasecmp (survey, "list") == 0) {
	list_surveys = 1;
	memset (survey, 0, SZ_FNAME);
    }
    

    /*  Initialize the VOClient code.  Error messages are printed by the
     *  interface so we just quit if there is a problem.
     */
    if (voc_initVOClient ("runid=voc.voatlas") == ERR) 
        return (ERR);

    /* Sanity checks
     */
    if (iname == NULL) iname = strdup ("stdin");
    if (oname == NULL) oname = strdup ("stdout");
    if (strcmp (iname, "-") == 0) { free (iname), iname = strdup ("stdin");  }
    if (strcmp (oname, "-") == 0) { free (oname), oname = strdup ("stdout"); }

    if (field && pos) {
	fprintf (stderr, 
	    "Error: only one of 'field' or 'pos' may be specified.\n");
	return (ERR);
    } else if (field) {
	if (voa_resolveField (field, &ra, &dec) != OK) {
	    fprintf (stderr, "Error: cannot resolve object '%s'\n", field);
	    return (ERR);
	}
    } else if (pos) {
	if (voa_resolvePos (pos, &ra, &dec) != OK) {
	    fprintf (stderr, "Error: cannot convert position '%s'\n", pos);
	    return (ERR);
	}
    }


    /*  Form the service URL.
     */
    memset (svc_url, 0, SZ_URL);
    sprintf (svc_url, "%snaxis=%d&", base_url, naxis);
    if (survey[0]) {
	strcat (svc_url, "survey=");
	strcat (svc_url, survey);
	strcat (svc_url, "&");
    }


    /*  Call the SkyView SIA service.
     */
    if (voa_callService (svc_url, ra, dec, size, dlname, 
	(graphic ? "jpeg" : "fits"), 1) == ERR) 
	    return (ERR);

    /*  Broadcast the image as a message if requested.
     */
    if (do_samp) {
	if ((samp = sampInit ("voatlas", "VOClient Task")) >= 0) {
	    char url[SZ_LINE], cwd[SZ_LINE];

	    samp_setASyncMode (samp);	/* use asynchronous mode	*/
	    sampStartup (samp);		/* register w/ Hub		*/

	    memset (url, 0, SZ_LINE);
	    memset (cwd, 0, SZ_LINE);
	    getcwd (cwd, SZ_LINE);
	    if (tmp[0])
	        sprintf (url, "file://%s", dlname);
	    else
	        sprintf (url, "file://%s/%s", cwd, oname);

            (void) samp_imageLoadFITS (samp, "all", url, "", field);

	    sampShutdown (samp);
	}
    }


    /*  See if we're returning the image.
     */
    if (do_return) {
	vo_setResultFromFile (dlname, reslen, result);
        unlink (dlname);
    }


    /*  Clean up and shutdown.
     */
done_:
    if (pos)    free (pos);
    if (field)  free (field);
    if (iname)  free (iname);
    if (oname)  free (oname);

    voc_closeVOClient (1);
    vo_paramFree (argc, pargv);

    return (status);
}
Ejemplo n.º 5
0
Archivo: voObj.c Proyecto: pkgw/iraf
/****************************************************************************
**  PARSETABLELINE --  Parse a line of table input to extract the values for
**  the given ra/dec/id columns.   Values that span multiple columns are
**  concatenated to a single space-delimited string.
*/
static char *
vot_parseTableLine (char *idlist, int nwords, double *ra, double *dec)
{
    char *id = (char *) NULL, *sra = (char *) NULL, *sdec = (char *) NULL;



    if (ecols == (char *)NULL && nwords == 3) {
	/* No user-specified columns, see if we can figure it out.
	*/
	char *c1 = calloc (1, SZ_LINE);
	char *c2 = calloc (1, SZ_LINE);
	char *c3 = calloc (1, SZ_LINE);

	strcpy (c1, vot_getTableCol (idlist, 1, 1));
	strcpy (c2, vot_getTableCol (idlist, 2, 1));
	strcpy (c3, vot_getTableCol (idlist, 3, 1));

	if ( (strchr(c1,(int)'.') && strchr(c2,(int)'.')) ||
	     (strchr(c1,(int)':') && strchr(c2,(int)':')) )  {

	     /* ID is column 3 */
             sra  = strdup (vot_normalizeCoord (c1));
             sdec = strdup (vot_normalizeCoord (c2));
             id   = vot_normalize (c3);

	} else if ( (strchr(c2,(int)'.') && strchr(c3,(int)'.')) ||
	     (strchr(c2,(int)':') && strchr(c3,(int)':')) )  {

	     /* ID is column 1 */
             id   = vot_normalize (c1);
             sra  = strdup (vot_normalizeCoord (c2));
             sdec = strdup (vot_normalizeCoord (c3));

	} else {
	     fprintf (stderr, "ERROR: Unable to parse table colummns\n");
	     *ra = *dec = 0.0;
	     free (c1); free (c2); free (c3);
	     return ((char *)NULL);
	}
        *ra = (strchr (sra, (int)':') ?  (sexa (sra) * 15.) : atof (sra));
        *dec = (strchr (sdec, (int)':') ?  sexa (sdec) : atof (sdec));

	free (c1); free (c2); free (c3);
	free (sra); free (sdec);

    } else {
        sra = vot_normalizeCoord (vot_getTableCol (idlist, ra_col, ra_span));
        *ra = (strchr (sra, (int)':') ?  (sexa (sra) * 15.) : atof (sra));

        sdec = vot_normalizeCoord (vot_getTableCol (idlist, dec_col, dec_span));
        *dec = (strchr (sdec, (int)':') ?  sexa (sdec) : atof (sdec));

        if (nwords == 3 && id_col == 0)
            id  = vot_normalize (vot_getTableCol (idlist, 3, 1));
        else
            id  = vot_normalize (vot_getTableCol (idlist, id_col, id_span));
    }

    return ((char *) id);
}