// Show 4 digits prec for dec, 5 for ra void HMS::print_extra_precise_( char *buf ) const { char lbuf[32]; if ( show_sign_ ) { dec2str( lbuf, 32, val_, 4 ); } else { ra2str( lbuf, 32, val_ * 15.0, 5 ); } strncpy( buf, lbuf, 32 ); }
/*! Produces a string of the form hh:mm:ss.sss[+|-]dd:mm:ss.sss, given ra and dec in radians. The number of decimal places in ss.sss is controlled by places. */ int coord2str (char* coordstring, unsigned coordstrlen, double ra, double dec, unsigned places) { int decstart; ra2str (coordstring, coordstrlen, ra, places); decstart = strlen (coordstring); dec2str2 (coordstring+decstart, coordstrlen-decstart, dec, places); return 0; }
/* convert image values to wcs values in a region (see fitshelper.c) */ char *reg2wcsstr(int n, char *regstr){ Info info = getinfo(n); char tbuf[SZ_LINE]; char rbuf1[SZ_LINE]; char rbuf2[SZ_LINE]; char *str = NULL; char *s=NULL, *t=NULL;; char *s1=NULL, *s2=NULL; char *targs=NULL, *targ=NULL; char *mywcssys=NULL; int alwaysdeg = 0; double dval1, dval2, dval3, dval4; double rval1, rval2, rval3, rval4; double sep; if( info->wcs ){ mywcssys = wcssys(n, NULL); if( !strcmp(mywcssys, "galactic") || !strcmp(mywcssys, "ecliptic") || !strcmp(mywcssys, "linear") ){ alwaysdeg = 1; } str = info->str; *str = '\0'; /* start with original input string */ targs = (char *)strdup(regstr); for(targ=(char *)strtok(targs, ";"); targ != NULL; targ=(char *)strtok(NULL,";")){ s = targ; /* look for region type */ t = strchr(s, ' '); if( t ){ s1 = t + 1; *t = '\0'; } else { s = NULL; s1 = ""; } /* these are the coords of the region */ if( (dval1=strtod(s1, &s2)) && (dval2=strtod(s2, &s1)) ){ /* convert image x,y to ra,dec */ pix2wcs(info->wcs, dval1, dval2, &rval1, &rval2); if( s ){ snprintf(tbuf, SZ_LINE, "%s(", s); strncat(str, tbuf, SZ_LINE-1); } /* convert to proper units */ switch(info->wcsunits){ case WCS_DEGREES: snprintf(tbuf, SZ_LINE, "%.6f, %.6f", rval1, rval2); strncat(str, tbuf, SZ_LINE-1); break; case WCS_SEXAGESIMAL: if( alwaysdeg ){ dec2str(rbuf1, SZ_LINE-1, rval1, NDEC); } else { ra2str(rbuf1, SZ_LINE-1, rval1, NDEC); } dec2str(rbuf2, SZ_LINE-1, rval2, NDEC); snprintf(tbuf, SZ_LINE, "%s, %s", rbuf1, rbuf2); strncat(str, tbuf, SZ_LINE-1); break; default: snprintf(tbuf, SZ_LINE, "%.6f, %.6f", rval1, rval2); strncat(str, tbuf, SZ_LINE-1); break; } /* convert more positions */ if( !strcmp(s, "polygon") ){ /* convert successive image values to RA, Dec */ while( (dval1=strtod(s1, &s2)) && (dval2=strtod(s2, &s1)) ){ /* convert image x,y to ra,dec */ pix2wcs(info->wcs, dval1, dval2, &rval1, &rval2); /* convert to proper units */ switch(info->wcsunits){ case WCS_DEGREES: snprintf(tbuf, SZ_LINE, ", %.6f, %.6f", rval1, rval2); strncat(str, tbuf, SZ_LINE-1); break; case WCS_SEXAGESIMAL: if( alwaysdeg ){ dec2str(rbuf1, SZ_LINE-1, rval1, NDEC); } else { ra2str(rbuf1, SZ_LINE-1, rval1, NDEC); } dec2str(rbuf2, SZ_LINE-1, rval2, NDEC); snprintf(tbuf, SZ_LINE, ", %s, %s", rbuf1, rbuf2); strncat(str, tbuf, SZ_LINE-1); break; default: snprintf(tbuf, SZ_LINE, ", %.6f, %.6f", rval1, rval2); strncat(str, tbuf, SZ_LINE-1); break; } } } else { /* use successive x1,y1,x2,y2 to calculate separation (arcsecs) */ while( (dval1=strtod(s1, &s2)) && (dval2=strtod(s2, &s1)) && (dval3=strtod(s1, &s2)) && (dval4=strtod(s2, &s1)) ){ /* convert image x,y to ra,dec */ pix2wcs(info->wcs, dval1, dval2, &rval1, &rval2); /* convert image x,y to ra,dec */ pix2wcs(info->wcs, dval3, dval4, &rval3, &rval4); /* calculate and output separation between the two points */ sep = wcsdist(rval1, rval2, rval3, rval4)*3600.0; if( sep <= 60 ){ snprintf(tbuf, SZ_LINE, ", %.2f\"", sep); strncat(str, tbuf, SZ_LINE-1); } else if( sep <= 3600 ){ snprintf(tbuf, SZ_LINE, ", %.6f'", sep/60.0); strncat(str, tbuf, SZ_LINE-1); } else { snprintf(tbuf, SZ_LINE, ", %.6fd", sep/3600.0); strncat(str, tbuf, SZ_LINE-1); } } } /* output angle, as needed */ if( !strcmp(s, "box") || !strcmp(s, "ellipse") ){ while( dval1 < 0 ) dval1 += (2.0 * PI); snprintf(tbuf, SZ_LINE, ", %.3f", RAD2DEG(dval1)); strncat(str, tbuf, SZ_LINE-1); } /* close region */ if( s ){ snprintf(tbuf, SZ_LINE, ")"); strncat(str, tbuf, SZ_LINE-1); } snprintf(tbuf, SZ_LINE, ";"); strncat(str, tbuf, SZ_LINE-1); } } } if( targs ) free(targs); return str; }