int main(int argc, char** args) { int c; char* rdlsfn = NULL; char* wcsfn = NULL; char* xylsfn = NULL; char* xcol = NULL; char* ycol = NULL; anbool forcetan = FALSE; anbool forcewcslib = FALSE; anbool forcewcstools = FALSE; anbool printhms = FALSE; il* fields; int ext = 0; double x, y; int loglvl = LOG_MSG; x = y = HUGE_VAL; fields = il_new(16); while ((c = getopt(argc, args, OPTIONS)) != -1) { switch (c) { case 'v': loglvl++; break; case 's': printhms = TRUE; break; case 'L': forcewcslib = TRUE; break; case 'T': forcewcstools = TRUE; break; case 'x': x = atof(optarg); break; case 'y': y = atof(optarg); break; case 'e': ext = atoi(optarg); break; case 'h': print_help(args[0]); exit(0); case 't': forcetan = TRUE; break; case 'o': rdlsfn = optarg; break; case 'i': xylsfn = optarg; break; case 'w': wcsfn = optarg; break; case 'f': il_append(fields, atoi(optarg)); break; case 'X': xcol = optarg; break; case 'Y': ycol = optarg; break; } } log_init(loglvl); if (optind != argc) { print_help(args[0]); exit(-1); } if (!(wcsfn && ((rdlsfn && xylsfn) || ((x != HUGE_VAL) && (y != HUGE_VAL))))) { print_help(args[0]); exit(-1); } if (!xylsfn) { double ra,dec; anwcs_t* wcs = NULL; // read WCS. if (forcewcslib) { wcs = anwcs_open_wcslib(wcsfn, ext); } else if (forcewcstools) { wcs = anwcs_open_wcstools(wcsfn, ext); } else if (forcetan) { wcs = anwcs_open_tan(wcsfn, ext); } else { wcs = anwcs_open(wcsfn, ext); } if (!wcs) { ERROR("Failed to read WCS file \"%s\", extension %i", wcsfn, ext); exit(-1); } logverb("Read WCS:\n"); if (log_get_level() >= LOG_VERB) { anwcs_print(wcs, log_get_fid()); } // convert immediately. anwcs_pixelxy2radec(wcs, x, y, &ra, &dec); printf("Pixel (%.10f, %.10f) -> RA,Dec (%.10f, %.10f)\n", x, y, ra, dec); if (printhms) { char str[32]; ra2hmsstring(ra, str); printf(" RA,Dec (%20s, ", str); dec2dmsstring(dec, str); printf("%20s)\n", str); } anwcs_free(wcs); exit(0); } if (wcs_xy2rd(wcsfn, ext, xylsfn, rdlsfn, xcol, ycol, forcetan, forcewcslib, fields)) { ERROR("wcs-xy2rd failed"); exit(-1); } return 0; }
int main(int argc, char** args) { int c; char* rdlsfn = NULL; char* wcsfn = NULL; char* xylsfn = NULL; char* rcol = NULL; char* dcol = NULL; anbool forcetan = FALSE; il* fields; int ext = 0; double ra=HUGE_VAL, dec=HUGE_VAL; anbool wcslib = FALSE; int loglvl = LOG_MSG; fields = il_new(16); while ((c = getopt(argc, args, OPTIONS)) != -1) { switch (c) { case 'v': loglvl++; break; case 'L': wcslib = TRUE; break; case 'r': ra = atof(optarg); break; case 'd': dec = atof(optarg); break; case 'e': ext = atoi(optarg); break; case 'h': print_help(args[0]); exit(0); case 't': forcetan = TRUE; break; case 'o': xylsfn = optarg; break; case 'i': rdlsfn = optarg; break; case 'w': wcsfn = optarg; break; case 'f': il_append(fields, atoi(optarg)); break; case 'R': rcol = optarg; break; case 'D': dcol = optarg; break; } } log_init(loglvl); if (optind != argc) { print_help(args[0]); exit(-1); } if (!(wcsfn && ((rdlsfn && xylsfn) || ((ra != HUGE_VAL) && (dec != HUGE_VAL))))) { print_help(args[0]); exit(-1); } if (!rdlsfn) { double x,y; anwcs_t* wcs = NULL; // read WCS. if (wcslib) { wcs = anwcs_open_wcslib(wcsfn, ext); } else if (forcetan) { wcs = anwcs_open_tan(wcsfn, ext); } else { wcs = anwcs_open(wcsfn, ext); } if (!wcs) { ERROR("Failed to read WCS file"); exit(-1); } logverb("Read WCS:\n"); if (log_get_level() >= LOG_VERB) { anwcs_print(wcs, log_get_fid()); } // convert immediately. if (anwcs_radec2pixelxy(wcs, ra, dec, &x, &y)) { ERROR("The given RA,Dec is on the opposite side of the sky."); exit(-1); } printf("RA,Dec (%.10f, %.10f) -> pixel (%.10f, %.10f)\n", ra, dec, x, y); anwcs_free(wcs); exit(0); } if (wcs_rd2xy(wcsfn, ext, rdlsfn, xylsfn, rcol, dcol, forcetan, wcslib, fields)) { ERROR("wcs-rd2xy failed"); exit(-1); } return 0; }
int main(int argc, char** args) { int ext = 0,c; double ra,dec; double sol[2]; const gsl_multiroot_fsolver_type *T; gsl_multiroot_fsolver *s; int status; size_t iter=0; const size_t n=2; gsl_multiroot_function f={&fvec,n,NULL}; gsl_vector *x = gsl_vector_alloc(n); char *wcsfn1=NULL, *wcsfn2=NULL; while ((c = getopt(argc, args, OPTIONS)) != -1) { switch(c) { case 'v': loglvl++; break; case 'h': print_help(args[0]); exit(0); case '1': wcsfn1 = optarg; break; case '2': wcsfn2 = optarg; break; } } log_init(loglvl); if (optind != argc) { print_help(args[0]); exit(-1); } if (!(wcsfn1) || !(wcsfn2)) { print_help(args[0]); exit(-1); } /* open the two wcs systems */ wcs1 = anwcs_open(wcsfn1, ext); if (!wcs1) { ERROR("Failed to read WCS file"); exit(-1); } logverb("Read WCS:\n"); if (log_get_level() >= LOG_VERB) { anwcs_print(wcs1, log_get_fid()); } wcs2 = anwcs_open(wcsfn2, ext); if (!wcs2) { ERROR("Failed to read WCS file"); exit(-1); } logverb("Read WCS:\n"); if (log_get_level() >= LOG_VERB) { anwcs_print(wcs2, log_get_fid()); } /* setup the solver, start in the middle */ gsl_vector_set(x,0,anwcs_imagew(wcs1)/2.0); gsl_vector_set(x,1,anwcs_imageh(wcs1)/2.0); T = gsl_multiroot_fsolver_hybrids; s = gsl_multiroot_fsolver_alloc (T,2); gsl_multiroot_fsolver_set(s,&f,x); print_state(iter,s); do { iter++; status = gsl_multiroot_fsolver_iterate(s); print_state(iter,s); if (status) break; status = gsl_multiroot_test_residual(s->f,1e-7); } while (status == GSL_CONTINUE && iter < 1000); sol[0]=gsl_vector_get(s->x,0); sol[1]=gsl_vector_get(s->x,1); /* write some diagnostics on stderr */ /* transform to ra/dec */ anwcs_pixelxy2radec(wcs1, sol[0], sol[1], &ra, &dec); if (loglvl > LOG_MSG) fprintf(stderr,"Pixel (%.10f, %.10f) -> RA,Dec (%.10f, %.10f)\n", sol[0], sol[1], ra, dec); /* transform to x/y with second wcs center of rotation should stay the same x/y */ anwcs_radec2pixelxy(wcs2, ra, dec, &sol[0], &sol[1]); if (loglvl > LOG_MSG) fprintf(stderr,"RA,Dec (%.10f, %.10f) -> Pixel (%.10f, %.10f) \n", ra, dec, sol[0], sol[1]); /* write the solution */ fprintf(stdout,"%f\n",sol[0]); fprintf(stdout,"%f\n",sol[1]); return(0); }