/************************************************************************ ** 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"); } }
/**************************************************************************** ** 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); }