/*---------------------------------------------------------------------------- File name : lw_arc.c Author : Y. Jung Created on : Feb. 2001 Description : ISAAC arc recipei in LW mode ---------------------------------------------------------------------------*/ /* $Id: lw_arc.c,v 1.41 2001/12/19 09:20:49 yjung Exp $ $Author: yjung $ $Date: 2001/12/19 09:20:49 $ $Revision: 1.41 $ */ /*---------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include "eclipse.h" #include "isaacp_lib.h" /*--------------------------------------------------------------------------- Function prototypes ---------------------------------------------------------------------------*/ static int lw_arc_engine(char *, char *, char *, int, int, int, int, int) ; /*---------------------------------------------------------------------------- Main code ---------------------------------------------------------------------------*/ int isaac_lw_arc_main(void * dict) { dictionary * d ; char * catalog ; int rejected_end ; int rej_left ; int rej_right ; int auto_dark_subtraction ; int out_corrected ; char argname[10] ; char * name_i ; char * name_o ; int nfiles ; int errors ; int i ; d = (dictionary*)dict ; /* Get options */ rejected_end = dictionary_getint(d, "arg.rejected_ends", 100) ; rej_left = dictionary_getint(d, "arg.reject_left", -1) ; rej_right = dictionary_getint(d, "arg.reject_right", -1) ; auto_dark_subtraction = dictionary_getint(d, "arg.subdark", 0) ; out_corrected = dictionary_getint(d, "arg.out_corr", 0) ; catalog = dictionary_get(d, "arg.catalog") ; /* 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 ; iname[0] = strdup(inname) ; /* Identify the lines catalog to be used */ if (catalog == NULL) { /* No catalog specified - read the header */ /* Look for each file which lamp is activated */ if ((lamps=find_activated_lamps(lnames_set)) == NULL) { e_error("in finding the activated lamps") ; framelist_del(lnames_set) ; return -1 ; } if (lamps[0] == 1) { xenon_found = 1 ; strcpy(lines_table, "Xe") ; e_comment(2, "Xenon lamp: [%s]", lnames_set->name[0]) ; } else if (lamps[0] == 2) { argon_found = 1 ; strcpy(lines_table, "Ar") ; e_comment(2, "Argon lamp: [%s]", lnames_set->name[0]) ; } else if (lamps[0] == 3) { xenon_argon_found = 1 ; strcpy(lines_table, "Xe+Ar") ; e_comment(2, "Xenon+Argon lamp: [%s]", lnames_set->name[0]) ; } else { e_error("neither argon nor xenon lamp activated") ; free(lamps) ; framelist_del(lnames_set) ; return -1 ; } free(lamps) ; } else { /* Use the specified catalog */ strcpy(lines_table, catalog) ; e_comment(2, "%s catalog used for the lines match", catalog) ; } if ((!xenon_found) && (!argon_found) && (!xenon_argon_found) && (catalog == NULL)) { e_warning("neither xenon nor argon lamp activated in header") ; e_warning("and no lines catalog specified") ; } else { /* Load the input frame */ to_compute = image_load(lnames_set->name[0]) ; /* Compute the arc calibration */ if ((out_table = compute_arc_reduction(to_compute, lnames_set->name[0], lnames_set, &nb_coeffs, rejected_end, rej_left, rej_right, lines_table, auto_dark_subtraction, outfile_name, 'l', out_corrected, &arcs_fwhm)) == NULL) { e_warning("arc reduction computation failed"); image_del(to_compute) ; } else { image_del(to_compute) ; /* Write the fits table */ if (arc_write_outfile(outfile_name, nb_coeffs, out_table, lnames_set->name[0], 'l', lnames_set, lines_table, arcs_fwhm) == -1) { e_warning("cannot write the output FITS file: [%s]", outfile_name) ; } else { e_comment(2, "file [%s] produced", outfile_name) ; e_comment(2, "file [%s.paf] produced", get_rootname(outfile_name)) ; } for (j=0 ; j<4 ; j++) { free(out_table[j]) ; } free(out_table) ; if (arcs_fwhm != NULL) double3_del(arcs_fwhm) ; } } framelist_del(lnames_set) ; } else if (is_ascii_list(inname) == 1) { /* Read the in ascii file */ if ((lnames=framelist_load(inname)) == NULL) { e_error("cannot read the ascii input file") ; return -1 ; } /* Number of different settings */ if ((nsettings=framelist_labelize(lnames, compare_settings)) == -1) { e_error("in getting the number of different settings") ; framelist_del(lnames) ; return -1 ; } e_comment(0, "There are %d different setting(s)", nsettings) ; /* For each setting */ for (i=0 ; in ; j++) { e_comment(1, "%s", lnames_set->name[j]) ; } /* There should be an even number of files */ if (lnames_set->n % 2) { e_warning("The number of frames should be even for each") ; e_warning("setting : [%d]. Next setting...", lnames_set->n) ; } else { /* Look for each file which lamp is activated */ if ((lamps=find_activated_lamps(lnames_set)) == NULL) { e_error("in finding the activated lamps") ; framelist_del(lnames) ; framelist_del(lnames_set) ; return -1 ; } /* For each pair */ for (j=0 ; j<(lnames_set->n)/2 ; j++) { /* Identify the lamp */ e_comment(1, "Pair %d: Lamp and dark identification", j+1) ; lamp_dit = (double)atof(isaac_get_dit(lnames_set->name[2*j])) ; dark_dit = (double)atof(isaac_get_dit(lnames_set->name[2*j+1])); if (lamps[2*j+1] == 0) { dark = image_load(lnames_set->name[2*j+1]) ; e_comment(2, "Dark image: [%s]", lnames_set->name[2*j+1]) ; } else { dark = NULL ; e_comment(2, "No dark frame") ; } switch (lamps[2*j]) { case 1: strcpy(lines_table, "Xe") ; to_compute = image_load(lnames_set->name[2*j]) ; e_comment(2, "Xenon lamp: [%s]", lnames_set->name[2*j]) ; sprintf(outfile_name, "%s_set%d_pair%d_%s.tfits", outname, i+1, j+1, lines_table) ; break ; case 2: strcpy(lines_table, "Ar") ; to_compute = image_load(lnames_set->name[2*j]) ; e_comment(2, "Argon lamp: [%s]", lnames_set->name[2*j]) ; sprintf(outfile_name, "%s_set%d_pair%d_%s.tfits", outname, i+1, j+1, lines_table) ; break ; case 3: strcpy(lines_table, "Xe+Ar") ; to_compute = image_load(lnames_set->name[2*j]) ; e_comment(2, "Xenon+Argon lamp: [%s]", lnames_set->name[2*j]) ; sprintf(outfile_name, "%s_set%d_pair%d_%s.tfits", outname, i+1, j+1, lines_table) ; break ; default : to_compute = NULL ; e_comment(2, "Pair %d: Lamps are off. Next pair...", j+1) ; break ; } if ((dark != NULL) && (to_compute != NULL)) { if (dark_dit-lamp_dit < 1e-4) { image_sub_local(to_compute, dark) ; } else { e_comment(2, "Dark not used (bad DIT)") ; } } if (dark != NULL) image_del(dark) ; dark = NULL ; /* Compute the reduction */ if (to_compute != NULL) { e_comment(1, "Pair %d: Reduction procedure...", j+1) ; if ((out_table = compute_arc_reduction(to_compute, lnames_set->name[2*j], lnames_set, &nb_coeffs, rejected_end, rej_left, rej_right, lines_table, auto_dark_subtraction, outfile_name, 'l', out_corrected, &arcs_fwhm)) == NULL) { e_warning("arc reduction computation failed"); image_del(to_compute) ; } else { image_del(to_compute) ; /* Write the fits table */ if (arc_write_outfile(outfile_name, nb_coeffs, out_table, lnames_set->name[2*j], 'l', lnames_set, lines_table, arcs_fwhm) == -1) { e_warning("cannot write the output file: [%s]", outfile_name) ; } else { e_comment(2, "file [%s] produced", outfile_name) ; e_comment(2, "file [%s.paf] produced", get_rootname(outfile_name)) ; } for (k=0 ; k<4 ; k++) { free(out_table[k]) ; } free(out_table) ; if (arcs_fwhm != NULL) double3_del(arcs_fwhm) ; } } } free(lamps) ; } framelist_del(lnames_set) ; } framelist_del(lnames) ; } else { e_error("input file should be either a fits or an ascii file") ; return -1 ; } return 0 ; }