/*-------------------------------------------------------------------------*/ /** @file refpixel.c @author Y. Jung @date January 2002 @version $Revision: 1.4 $ @brief CONICA reference pixel recipe */ /*--------------------------------------------------------------------------*/ /* $Id: refpixel.c,v 1.4 2002/03/08 15:53:54 yjung Exp $ $Author: yjung $ $Date: 2002/03/08 15:53:54 $ $Revision: 1.4 $ */ /*---------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include #include "eclipse.h" #include "conicap_lib.h" /*---------------------------------------------------------------------------- Private functions ---------------------------------------------------------------------------*/ static int conica_refpixel_save(char *, framelist *, double3 *) ; static int conica_refpixel_engine(char *, char *) ; /*---------------------------------------------------------------------------- Main code ---------------------------------------------------------------------------*/ int conica_refpixel_main(void * dict) { dictionary * d ; char argname[10] ; char * name_i ; char * name_o ; int nfiles ; int errors ; int i ; d = (dictionary*)dict ; /* Get input/output file names */ nfiles = dictionary_getint(d, "arg.n", -1) ; if (nfiles<0) { e_error("missing input file name(s): aborting"); return -1 ; } /* Loop on input file names */ errors = 0 ; for (i=1 ; in) ; /* For each frame */ for (i=0 ; in ; i++) { /* Load the current image */ if ((im = image_load(lnames->name[i])) == NULL) { e_warning("cannot load image: %s", lnames->name[i]) ; continue ; } image_save_fits(im, "before.fits", BPP_32_SIGNED) ; /* Filter the image to solve the 'negative pixels problem' */ filtered = image_threshold(im, 0, 10000, 0, 0) ; image_del(im) ; image_save_fits(filtered, "after.fits", BPP_32_SIGNED) ; extracted = image_getvig(filtered, llx, lly, urx, ury) ; image_del(filtered) ; /* Find the brightest star position */ if ((position = detected_ks_brightest_stars(extracted, 1, 1.0)) == NULL) { e_warning("cannot detect star in %s\n", lnames->name[i]) ; positions->x[i] = -1.0 ; positions->y[i] = -1.0 ; } else { e_comment(1, "Star detected in %s at: %g %g\n", lnames->name[i], position->x[0]+llx-1, position->y[0]+llx-1) ; positions->x[i] = position->x[0] + llx - 1 ; positions->y[i] = position->y[0] + lly - 1 ; double3_del(position) ; } image_del(extracted) ; } /* Output positions in PAF file */ if (conica_refpixel_save(name_o, lnames, positions) == -1) { e_warning("cannot write output paf file") ; } /* Free and return */ double3_del(positions) ; framelist_del(lnames) ; return 0 ; } static int conica_refpixel_save( char * outname, framelist * nameslist, double3 * pos) { char complete_outname[FILENAMESZ]; FILE * refpix_out ; char * sval ; double coef2 ; double coef3 ; double pixscale ; double refzero_x, refzero_y ; int opti7_no ; int i, j ; /* Open output PAF file (formatted ASCII, see fits/pafs.c) */ sprintf(complete_outname, "%s_refpix.paf", outname) ; e_comment(0, "saving results to %s", complete_outname); if ((refpix_out = paf_print_header(complete_outname, "CONICA/refpix", "Reference pixel results")) == NULL) { e_error("cannot open file [%s] for output", complete_outname) ; return -1 ; } /* Add date */ if ((sval = conica_get_date_obs(nameslist->name[0])) != NULL) { fprintf(refpix_out, "DATE-OBS \"%s\" ; #Date\n", sval) ; } /* Add TPL ID */ if ((sval = conica_get_templateid(nameslist->name[0])) != NULL) { fprintf(refpix_out, "TPL.ID \"%s\"; # Template id\n", sval) ; } /* Add ARCFILE */ if ((sval = conica_get_arcfile(nameslist->name[0])) != NULL) fprintf(refpix_out, "ARCFILE \"%s\" ;#\n", sval) ; fprintf(refpix_out,"#\n") ; fprintf(refpix_out,"# Points position measurements\n") ; fprintf(refpix_out,"#\n") ; /* Add MJD-OBS for file classification */ if ((sval = qfits_query_hdr(nameslist->name[0], "MJD-OBS")) == NULL) { fprintf(refpix_out, "MJD-OBS 0.0 ; # could not find\n") ; } else { fprintf(refpix_out, "MJD-OBS %s ; # Obs start\n", sval) ; } /* Add input list of frames */ fprintf(refpix_out, "\n"); fprintf(refpix_out, "FRAMELIST.START\n"); for (i=0 ; in ; i++) { fprintf(refpix_out, "%s\n", get_basename(nameslist->name[i])) ; } fprintf(refpix_out, "FRAMELIST.END\n"); fprintf(refpix_out, "\n"); fprintf(refpix_out, "REFPIX.START\n"); /* Loop over all input frames except the last one */ for (i=0 ; in ; i++) { fprintf(refpix_out, "#--------------------------\n") ; fprintf(refpix_out, "\n") ; /* Get the OPTI7.NO */ if ((sval = conica_get_opti7_no(nameslist->name[i])) == NULL) { e_error("cannot get the OPTI7.NO keyword in %s", nameslist->name[i]) ; continue ; } opti7_no = (int)atoi(sval) ; /* Get the refzero in x and y */ if ((sval = conica_get_refzerox(nameslist->name[i])) == NULL) { e_error("cannot get the reference pixel from %s", nameslist->name[i]) ; continue ; } refzero_x = (double)atof(sval) ; if ((sval = conica_get_refzeroy(nameslist->name[i])) == NULL) { e_error("cannot get the reference pixel from %s", nameslist->name[i]) ; continue ; } refzero_y = (double)atof(sval) ; /* Get the pixel scale */ if ((sval = conica_get_pixscale(nameslist->name[i])) == NULL) { e_error("cannot get the pixscale from %s", nameslist->name[i]) ; continue ; } pixscale = (double)atof(sval) ; /* Compute coef2 and coef3 */ coef2 = 9696.27 * pixscale * (pos->x[i] - refzero_x) ; coef3 = 9696.27 * pixscale * (pos->y[i] - refzero_y) ; /* Print the result out */ fprintf(refpix_out, "INS.OPTI7.Z%d.COEF2\t%g\n", opti7_no, coef2) ; fprintf(refpix_out, "INS.OPTI7.Z%d.COEF3\t%g\n", opti7_no, coef3) ; fprintf(refpix_out, "\n") ; } fprintf(refpix_out, "REFPIX.END\n"); fclose(refpix_out) ; e_comment(1, "end of reference pixel computation") ; return 0 ; }