int GetWPos(int nnaxes, float pix[3], double ref[3], float refpix[3], float inc[3], float rot[3], char type[3][9], double pos[3]) /* Determines World coordinates for a position of the first three axes */ /* takes pixel location (pix), FITS header info (ref, refpix, inc, rot */ /* type and returns coordinates as pos */ /* returns 0 if successful otherwise: */ /* 1 = angle too large for projection; */ { int i, j, naxes, iRet, Lonaxis=-1, Lataxis=-1, Othaxis[3]={1,1,1}; char Lontypes[4][5]={"RA ", "GLON", "ELON", "LL "}; int Loncheck[4] = {2, 4, 4, 2}; char Lattypes[4][5]={"DEC ", "GLAT", "ELAT", "MM "}; int Latcheck[4] = {3, 4, 4, 2}; naxes = nnaxes; if (naxes>3) naxes = 3; /* find any Long axis */ for (i=0;i<naxes;i++) { for (j=0;j<4;j++) if (!strncmp (type[i], Lontypes[j], Loncheck[j])) Lonaxis = i;} /* find any Lat axis */ for (i=0;i<naxes;i++) { for (j=0;j<4;j++) if (!strncmp (type[i], Lattypes[j], Latcheck[j])) Lataxis = i;} /* get World coordinates for any position pair */ if ((Lonaxis>=0) && (Lataxis>=0)) { iRet = worldpos(pix[Lonaxis], pix[Lataxis], ref[Lonaxis], ref[Lataxis], refpix[Lonaxis], refpix[Lataxis], inc[Lonaxis], inc[Lataxis], rot[Lataxis], &type[Lonaxis][4], &pos[Lonaxis], &pos[Lataxis]);} else { /* no position pair */ Lonaxis = -1; Lataxis = -1; iRet = 0;} if (Lonaxis>=0) Othaxis[Lonaxis] = 0; if (Lataxis>=0) Othaxis[Lataxis] = 0; /* do Other axes */ for (i=0;i<naxes;i++){ if (Othaxis[i]) pos[i] = ref[i] + inc[i] * (pix[i] - refpix[i]); } return iRet; } /* end of GetWPos */
void nemo_main() { int i,j,nentries,ncol,nsp; FILE *fp; /* File pointer for output file */ string outfile; /* name of output file */ string *sp; /* used to read the command line argument "col" */ string wcs_type; /* WCS projection type (can be XXX or -XXX) */ char type[5]; /* the real WCS for worldpos() ; needs to be '-XXX' */ int nx,ny; /* size of map in pixels for x,y directions */ double index,rzero; /* parameters for powerlaw */ double crval1,crval2; /* center RA and DEC */ double cdelt1,cdelt2; /* delta RA and delta DEC for pixels */ double crpix1,crpix2; /* reference pixel */ double xpix, ypix; /* current x and y pixel position in map */ double ra,dec; /* ra,dec of current pixel position in map */ double flux; /* computed flux for each pixel */ double radius; /* radius, in pixels */ /* Read command line */ index = getdparam("index"); rzero = getdparam("rzero"); outfile = getparam("out"); wcs_type = getparam("type"); if (strlen(wcs_type)==3) { /* make sure type is '-XXX' */ type[0] = '-'; strcpy(&type[1],wcs_type); } else if (strlen(wcs_type)==4) { if (*wcs_type == '-') strcpy(type,wcs_type); else error("type=%s probably not legal, should be -XXX",wcs_type); } else error("type=%s must be a valid -XXX or XXX WCS descriptor",wcs_type); sp = burststring(getparam("crval")," ,"); nsp = xstrlen(sp,sizeof(string))-1; if (nsp != 2) error("You must specify two values for the crval keyword!"); crval1 = natof(sp[0]); crval2 = natof(sp[1]); freestrings(sp); sp = burststring(getparam("naxis")," ,"); nsp = xstrlen(sp,sizeof(string))-1; if (nsp != 2) error("You must specify two values for the naxis keyword!"); nx = natoi(sp[0]); ny = natoi(sp[1]); freestrings(sp); crpix1 = nx/2.0+1; crpix2 = ny/2.0+1; cdelt2 = getdparam("cdelt")/3600.; cdelt1 = -cdelt2; /* Test to make sure we can write to output file */ fp = stropen(outfile,"w"); strclose(fp); fprintf(stderr,"nx,ny = %d,%d\n",nx,ny); fprintf(stderr,"crval1,crval2=%lf,%lf\n",crval1,crval2); fprintf(stderr,"crpix1,crpix2=%lf,%lf\n",crpix1,crpix2); fprintf(stderr,"wcs: %s\n",type); xpix=1.0; ypix=1.0; worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec); dprintf(1,"LL corner: %g %g\n",ra,dec); xpix=nx; worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec); dprintf(1,"LR corner: %g %g\n",ra,dec); ypix=ny; worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec); dprintf(1,"UR corner: %g %g\n",ra,dec); xpix=1.0; worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0,type,&ra,&dec); dprintf(1,"UL corner: %g %g\n",ra,dec); /* Write header for TABFITS to file */ fp = stropen(getparam("out"),"w!"); fprintf(fp,"# NAXIS1 = %d\n",nx); fprintf(fp,"# NAXIS2 = %d\n",ny); fprintf(fp,"# NAXIS3 = 1\n"); fprintf(fp,"# CDELT1 = %lf\n",cdelt1); fprintf(fp,"# CDELT2 = %lf\n",cdelt2); fprintf(fp,"# CRVAL1 = %lf\n",crval1); fprintf(fp,"# CRVAL2 = %lf\n",crval2); fprintf(fp,"# CRPIX1 = %f\n",crpix1); fprintf(fp,"# CRPIX2 = %f\n",crpix2); fprintf(fp,"# CTYPE1 = 'RA--%s'\n",type); fprintf(fp,"# CTYPE2 = 'DEC-%s'\n",type); fprintf(fp,"# COMMENT index=%g / powerlaw index\n",index); fprintf(fp,"# COMMENT rzero=%g / rzero parameter\n",rzero); fprintf(fp,"# COMMENT out=%s / output table\n",outfile); fprintf(fp,"# COMMENT crval=%f,%f / Center WCS coordinates\n",crval1,crval2); fprintf(fp,"# COMMENT naxis=%d,%d / Image size in pixels\n",nx,ny); fprintf(fp,"# COMMENT cdelt=%f / pixel size in arcseconds\n",cdelt2*3600); fprintf(fp,"# COMMENT type=%s / Projection type\n",type); fprintf(fp,"# COMMENT VERSION=%s / Version number\n",getparam("VERSION")); for (i=0; i< ny; i++){ ypix = i + 1.0; for (j=0; j< nx; j++){ xpix = j + 1.0; worldpos(xpix,ypix,crval1,crval2,crpix1,crpix2,cdelt1,cdelt2,0.0, type,&ra,&dec); radius = sqrt((xpix-crpix1)*(xpix-crpix1) + (ypix-crpix2)*(ypix-crpix2)); flux = 1.0/(1.0 + pow(radius/rzero,index)); /* if (radius <= 4) flux = 1.0; else flux = 1.0/(1.0 + pow(radius-4,index)); */ fprintf(fp,"%lf %lf %4.2e\n",ra,dec,flux); } } strclose(fp); }
void yse_line_print(yse_line_list *line, yse_field_t *field, const char *filename, float flatness, int idx, double *keyval, int foutid) { FILE *fp, *fpix, *fsky; // If you want to get xyfile, remove // int n=0, i=0, j=0, max_i, max_j; double a; // xy slope double asky; // sky slope float xmax, xmin; float ymax, ymin; int xpix, ypix; int rc=0; float max_length_xy=-1000.0, length; float max_length_sky; char buf[80]; char fname[80], outnamexy[80], outnamesky[80], outnameskycen[80], outnamexycen[80]; char fnamepix[80], fnamesky[80]; type = "-TAN"; xrefsky = keyval[0]; yrefsky = keyval[1]; xrefpix = keyval[2]; yrefpix = keyval[3]; xinc = keyval[4]; yinc = keyval[5]; rot = keyval[6]; /* printf("xrefsky = %.10f\n", keyval[0]); printf("yrefsky = %.10f\n", keyval[1]); printf("xrefpix = %.10f\n", keyval[2]); printf("yrefpix = %.10f\n", keyval[3]); printf("cdelt1 = %.10f\n", keyval[4]); printf("cdelt2 = %.10f\n", keyval[5]); printf("rot = %.10f\n", keyval[6]); */ if ( foutid==1 ) sprintf(fname, "LP%05d", idx); // If you want to get xyfile, remove // if ( foutid==1 ) fp = fopen(fname, "w"); // If you want to get xyfile, remove // while(line != NULL) { x[n] = line->x; y[n] = line->y; if ( foutid==1 ) fprintf(fp, "%f %f\n", x[n], y[n]); // If you want to get xyfile, remove // rc = worldpos(x[n], y[n], xrefsky, yrefsky, xrefpix, yrefpix, xinc, yinc, rot, type, &tmpxsky, &tmpysky); xsky[n] = tmpxsky; ysky[n] = tmpysky; line = line->next; n++; } if ( foutid==1 ) fclose(fp); // If you want to get xyfile, remove // if ( n<MIN_NPIXEL ){ if ( foutid==1 ) remove(fname); // If you want to get xyfile, remove // return ; } for ( i=0 ; i<(n-1) ; i++ ){ for ( j=(i+1) ; j<n ; j++ ){ length = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); if ( length>max_length_xy ){ max_length_xy = length; max_i = i; max_j = j; } } } a = (y[max_j]-y[max_i])/(x[max_j]-x[max_i]); xmin = ( x[max_i]>x[max_j] ) ? x[max_j] : x[max_i]; xmax = ( x[max_i]>x[max_j] ) ? x[max_i] : x[max_j]; ymin = ( y[max_i]>y[max_j] ) ? y[max_j] : y[max_i]; ymax = ( y[max_i]>y[max_j] ) ? y[max_i] : y[max_j]; asky = (ysky[max_j]-ysky[max_i])/(xsky[max_j]-xsky[max_i])*cos((ysky[max_i]*D2R+ysky[max_j]*D2R)/2.0); xskymin = ( xsky[max_i]>xsky[max_j] ) ? xsky[max_j] : xsky[max_i]; xskymax = ( xsky[max_i]>xsky[max_j] ) ? xsky[max_i] : xsky[max_j]; yskymin = ( ysky[max_i]>ysky[max_j] ) ? ysky[max_j] : ysky[max_i]; yskymax = ( ysky[max_i]>ysky[max_j] ) ? ysky[max_i] : ysky[max_j]; if ( max_length_xy>MIN_STREAK_LENGTH ){ max_length_sky = angular_sep(xskymin, yskymin, xskymax, yskymax); sprintf(fnamepix, "%s.sxy", filename); sprintf(fnamesky, "%s.ssky", filename); fpix = fopen(fnamepix, "a+"); fsky = fopen(fnamesky, "a+"); for ( i=0 ; i<n ; i++ ){ xpix = (int)x[i]; ypix = (int)y[i]; fprintf(fpix, "%d %d 16000\n", xpix, ypix); fprintf(fsky, "%11.6f %11.6f 16000\n", xsky[i], ysky[i]); } fclose(fpix); fclose(fsky); sprintf(outnamexy, "%s.strxy", filename); fp = fopen(outnamexy, "a+"); if ( foutid==1 ){ printf("XY %s flatness= %11.6f a= %11.6f %7.1f %7.1f %7.1f %7.1f L= %11.6f\n", fname, flatness, a, xmin, ymin, xmax, ymax, max_length_xy); fprintf(fp, "%11.6f %11.6f %7.1f %7.1f %7.1f %7.1f %11.6f\n", flatness, a, xmin, ymin, xmax, ymax, max_length_xy); }else{ printf("XY flatness= %11.6f a= %11.6f %7.1f %7.1f %7.1f %7.1f L= %11.6f\n", flatness, a, xmin, ymin, xmax, ymax, max_length_xy); fprintf(fp, "%11.6f %11.6f %7.1f %7.1f %7.1f %7.1f %11.6f\n", flatness, a, xmin, ymin, xmax, ymax, max_length_xy); } fclose(fp); sprintf(outnamesky, "%s.strsky", filename); fp = fopen(outnamesky, "a+"); if ( foutid==1 ){ printf("SKY %s flatness= %11.6f a= %11.6f %11.6f %11.6f %11.6f %11.6f L= %11.6f\n", fname, flatness, asky, xskymin, yskymin, xskymax, yskymax, max_length_sky); fprintf(fp, "%11.6f %11.6f %11.6f %11.6f %11.6f %11.6f %11.6f\n", flatness, asky, xskymin, yskymin, xskymax, yskymax, max_length_sky); }else{ printf("SKY flatness= %11.6f a= %11.6f %11.6f %11.6f %11.6f %11.6f L= %11.6f\n", flatness, asky, xskymin, yskymin, xskymax, yskymax, max_length_sky); fprintf(fp, "%11.6f %11.6f %11.6f %11.6f %11.6f %11.6f %11.6f\n", flatness, asky, xskymin, yskymin, xskymax, yskymax, max_length_sky); } fclose(fp); sprintf(outnameskycen, "%s.strskycen", filename); fp = fopen(outnameskycen, "a+"); fprintf(fp, "%11.6f %11.6f %11.6f %11.6f %11.6f\n", flatness, asky, (xskymin+xskymax)/2.0, (yskymin+yskymax)/2.0, max_length_sky); //flatness, asky, (xmin+xmax)/2.0, (ymin+ymax)/2.0, max_length_sky); fclose(fp); sprintf(outnamexycen, "%s.strxycen", filename); fp = fopen(outnamexycen, "a+"); fprintf(fp, "%11.6f %11.6f %11.6f %11.6f %11.6f\n", //flatness, asky, (xskymin+xskymax)/2.0, (yskymin+yskymax)/2.0, max_length_sky); flatness, asky, (xmin+xmax)/2.0, (ymin+ymax)/2.0, max_length_sky); fclose(fp); }else{ remove(fname); } return ; }