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; }
// This runs after "astrometry-engine" is run on the file. static void after_solved(augment_xylist_t* axy, solve_field_args_t* sf, anbool makeplots, const char* me, anbool verbose, const char* tempdir, sl* tempdirs, sl* tempfiles, double plotscale, const char* bgfn) { sip_t wcs; double ra, dec, fieldw, fieldh; char rastr[32], decstr[32]; char* fieldunits; // print info about the field. logmsg("Field: %s\n", axy->imagefn ? axy->imagefn : axy->xylsfn); if (file_exists(axy->wcsfn)) { double orient; if (axy->wcs_last_mod) { time_t t = file_get_last_modified_time(axy->wcsfn); if (t == axy->wcs_last_mod) { logmsg("Warning: there was already a WCS file, and its timestamp has not changed.\n"); } } if (!sip_read_header_file(axy->wcsfn, &wcs)) { ERROR("Failed to read WCS header from file %s", axy->wcsfn); exit(-1); } sip_get_radec_center(&wcs, &ra, &dec); sip_get_radec_center_hms_string(&wcs, rastr, decstr); sip_get_field_size(&wcs, &fieldw, &fieldh, &fieldunits); orient = sip_get_orientation(&wcs); logmsg("Field center: (RA,Dec) = (%3.6f, %3.6f) deg.\n", ra, dec); logmsg("Field center: (RA H:M:S, Dec D:M:S) = (%s, %s).\n", rastr, decstr); logmsg("Field size: %g x %g %s\n", fieldw, fieldh, fieldunits); logmsg("Field rotation angle: up is %g degrees E of N\n", orient); } else { logmsg("Did not solve (or no WCS file was written).\n"); } // create new FITS file... if (axy->fitsimgfn && sf->newfitsfn && file_exists(axy->wcsfn)) { logmsg("Creating new FITS file \"%s\"...\n", sf->newfitsfn); if (new_wcs(axy->fitsimgfn, axy->wcsfn, sf->newfitsfn, TRUE)) { ERROR("Failed to create FITS image with new WCS headers"); exit(-1); } } // write list of index stars in image coordinates if (sf->indxylsfn && file_exists(axy->wcsfn) && file_exists(axy->rdlsfn)) { assert(axy->wcsfn); assert(axy->rdlsfn); // index rdls to xyls. if (wcs_rd2xy(axy->wcsfn, 0, axy->rdlsfn, sf->indxylsfn, NULL, NULL, FALSE, FALSE, NULL)) { ERROR("Failed to project index stars into field coordinates using wcs-rd2xy"); exit(-1); } } if (makeplots && file_exists(sf->indxylsfn) && file_readable(axy->matchfn) && file_readable(axy->wcsfn)) { logmsg("Creating index object overlay plot...\n"); if (plot_index_overlay(axy, me, sf->indxylsfn, sf->redgreenfn, plotscale, bgfn)) { ERROR("Plot index overlay failed."); } } if (makeplots && file_readable(axy->wcsfn)) { logmsg("Creating annotation plot...\n"); if (plot_annotations(axy, me, verbose, sf->ngcfn, plotscale, bgfn)) { ERROR("Plot annotations failed."); } } if (axy->imagefn && sf->kmzfn && file_exists(axy->wcsfn)) { logmsg("Writing kmz file...\n"); if (write_kmz(axy, sf->kmzfn, tempdir, tempdirs, tempfiles)) { ERROR("Failed to write KMZ."); exit(-1); } } if (sf->scampfn && file_exists(axy->wcsfn)) { //char* hdrfile = NULL; qfits_header* imageheader = NULL; starxy_t* xy; xylist_t* xyls; xyls = xylist_open(axy->axyfn); if (!xyls) { ERROR("Failed to read xylist to write SCAMP catalog"); exit(-1); } if (axy->xcol) xylist_set_xname(xyls, axy->xcol); if (axy->ycol) xylist_set_yname(xyls, axy->ycol); //xylist_set_include_flux(xyls, FALSE); xylist_set_include_background(xyls, FALSE); xy = xylist_read_field(xyls, NULL); xylist_close(xyls); if (axy->fitsimgfn) { //hdrfile = axy->fitsimgfn; imageheader = anqfits_get_header2(axy->fitsimgfn, 0); } if (axy->xylsfn) { char val[32]; //hdrfile = axy->xylsfn; imageheader = anqfits_get_header2(axy->xylsfn, 0); // Set NAXIS=2, NAXIS1=IMAGEW, NAXIS2=IMAGEH fits_header_mod_int(imageheader, "NAXIS", 2, NULL); sprintf(val, "%i", axy->W); qfits_header_add_after(imageheader, "NAXIS", "NAXIS1", val, "image width", NULL); sprintf(val, "%i", axy->H); qfits_header_add_after(imageheader, "NAXIS1", "NAXIS2", val, "image height", NULL); //fits_header_add_int(imageheader, "NAXIS1", axy->W, NULL); //fits_header_add_int(imageheader, "NAXIS2", axy->H, NULL); logverb("Using NAXIS 1,2 = %i,%i\n", axy->W, axy->H); } if (scamp_write_field(imageheader, &wcs, xy, sf->scampfn)) { ERROR("Failed to write SCAMP catalog"); exit(-1); } starxy_free(xy); if (imageheader) qfits_header_destroy(imageheader); } if (sf->scampconfigfn) { if (scamp_write_config_file(axy->scampfn, sf->scampconfigfn)) { ERROR("Failed to write SCAMP config file snippet to %s", sf->scampconfigfn); exit(-1); } } }