/*---------------------------------------------------------------------------- File name : sw_arc.c Author : Y. Jung Created on : Feb. 2001 Description : ISAAC arc recipe in SW mode ---------------------------------------------------------------------------*/ /* $Id: sw_arc.c,v 1.35 2001/11/15 15:53:48 yjung Exp $ $Author: yjung $ $Date: 2001/11/15 15:53:48 $ $Revision: 1.35 $ */ /*---------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include "eclipse.h" #include "isaacp_lib.h" /*--------------------------------------------------------------------------- Function prototypes ---------------------------------------------------------------------------*/ static int sw_arc_engine(char *, char *, char *, int, int, int, int, int) ; /*---------------------------------------------------------------------------- Main code ---------------------------------------------------------------------------*/ int isaac_sw_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 ; } xenon_found = 0 ; argon_found = 0 ; if (lamps[0] == 1) { xenon_found = 1 ; /* Specify the used lines table */ strcpy(lines_table, "Xe") ; e_comment(2, "Xenon lamp: [%s]", lnames_set->name[0]) ; } else if (lamps[0] == 2) { argon_found = 1 ; /* Specify the used lines table */ strcpy(lines_table, "Ar") ; e_comment(2, "Argon lamp: [%s]", lnames_set->name[0]) ; } else if (lamps[0] == 3) { /* Specify the used lines table */ 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) && (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(inname) ; /* 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, 's', 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, inname, 's', 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(1, "there are %d different setting(s)", nsettings) ; /* Get the resolutions of the settings */ if ((resol=get_resolutions(lnames, nsettings)) == NULL) { e_error("in getting the resolutions") ; framelist_del(lnames) ; return -1 ; } /* For each setting */ for (i=0 ; in ; j++) { e_comment(2, "%s", lnames_set->name[j]) ; } /* 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) ; free(resol) ; framelist_del(lnames_set) ; return -1 ; } /* Find the dark */ dark_found = 0 ; for (j=0 ; jn ; j++) { if (lamps[j] == 0) { dark = image_load(lnames_set->name[j]) ; dark_found = 1 ; dark_dit = (double)atof(isaac_get_dit(lnames_set->name[j])); e_comment(2, "Dark image: [%s]", lnames_set->name[j]) ; break ; } } /* Find the xenon */ xenon_found = 0 ; for (j=0 ; jn ; j++) { if (lamps[j] == 1) { xenon = image_load(lnames_set->name[j]) ; xenon_found = 1 ; xenon_dit=(double)atof(isaac_get_dit(lnames_set->name[j])); e_comment(2, "Xenon lamp: [%s]", lnames_set->name[j]) ; break ; } } /* Find the argon */ argon_found = 0 ; for (j=0 ; jn ; j++) { if (lamps[j] == 2) { argon = image_load(lnames_set->name[j]) ; argon_found = 1 ; argon_dit=(double)atof(isaac_get_dit(lnames_set->name[j])); e_comment(2, "Argon lamp: [%s]", lnames_set->name[j]) ; break ; } } /* Find the xenon+argon */ xenon_argon_found = 0 ; for (j=0 ; jn ; j++) { if (lamps[j] == 3) { xenon_argon = image_load(lnames_set->name[j]) ; xenon_argon_found = 1 ; xenon_argon_dit = (double)atof(isaac_get_dit(lnames_set->name[j])) ; e_comment(2, "Xenon+Argon lamp: [%s]",lnames_set->name[j]); break ; } } free(lamps) ; if ((!xenon_found) && (!argon_found) && (!xenon_argon_found)) { e_warning("neither xenon nor argon lamp activated") ; if (dark_found) image_del(dark) ; dark_found = 0 ; framelist_del(lnames_set) ; } else { /* Switch the resolution */ switch(resol[i]) { /* Low resolution */ case 'l': e_comment(2, "low resolution") ; if (xenon_found) { if ((dark_found) && (dark_dit == xenon_dit)) { to_compute = image_sub(xenon, dark) ; } else { to_compute = image_copy(xenon) ; } image_del(xenon) ; /* Specify the used lines table */ strcpy(lines_table, "Xe") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_LR_%s.tfits", outname, i+1, lines_table) ; /* 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, 's', 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], 's', 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 (j=0 ; j<4 ; j++) { free(out_table[j]) ; } free(out_table) ; if (arcs_fwhm != NULL) double3_del(arcs_fwhm) ; } } if (argon_found) { if ((dark_found) && (dark_dit == argon_dit)) { to_compute = image_sub(argon, dark) ; } else { to_compute = image_copy(argon) ; } image_del(argon) ; /* Specify the used lines table */ strcpy(lines_table, "Ar") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_LR_%s.tfits", outname, i+1, lines_table) ; /* 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, 's', out_corrected, &arcs_fwhm)) == NULL) { e_warning("arc reduction computation failed"); if (dark_found) image_del(dark) ; dark_found = 0 ; 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], 's', 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 (j=0 ; j<4 ; j++) { free(out_table[j]) ; } free(out_table) ; if (arcs_fwhm != NULL) double3_del(arcs_fwhm) ; } } if (xenon_argon_found) { if ((dark_found) && (dark_dit == xenon_argon_dit)) { to_compute = image_sub(xenon_argon, dark) ; } else { to_compute = image_copy(xenon_argon) ; } image_del(xenon_argon) ; /* Specify the used lines table */ strcpy(lines_table, "Xe+Ar") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_LR_%s.tfits", outname, i+1, lines_table) ; /* 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, 's', out_corrected, &arcs_fwhm)) == NULL) { e_warning("arc reduction computation failed"); if (dark_found) image_del(dark) ; dark_found = 0 ; 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], 's', 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 (j=0 ; j<4 ; j++) { free(out_table[j]) ; } free(out_table) ; if (arcs_fwhm != NULL) double3_del(arcs_fwhm) ; } } if (dark_found) image_del(dark) ; dark_found = 0 ; break ; /* Medium resolution */ case 'm': e_comment(2, "medium resolution") ; if ((xenon_found) && (argon_found)) { /* Specify the used lines table */ strcpy(lines_table, "Xe+Ar") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_MR_%s.tfits", outname, i+1, lines_table) ; if ((dark_found) && (dark_dit==xenon_dit) && (dark_dit==argon_dit)) { image_sub_local(xenon, dark) ; image_sub_local(argon, dark) ; to_compute = image_add(argon, xenon) ; } else { to_compute = image_add(argon, xenon) ; } } else if (xenon_found) { /* Specify the used lines table */ strcpy(lines_table, "Xe") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_MR_%s.tfits", outname, i+1, lines_table) ; if ((dark_found) && (dark_dit == xenon_dit)) { to_compute = image_sub(xenon, dark) ; } else { to_compute = image_copy(xenon) ; } } else if (argon_found) { /* Specify the used lines table */ strcpy(lines_table, "Ar") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_MR_%s.tfits", outname, i+1, lines_table) ; if ((dark_found) && (dark_dit == argon_dit)) { to_compute = image_sub(argon, dark) ; } else { to_compute = image_copy(argon) ; } } else if (xenon_argon_found) { /* Specify the used lines table */ strcpy(lines_table, "Xe+Ar") ; /* Output file name */ sprintf(outfile_name, "%s_set%d_MR_%s.tfits", outname, i+1, lines_table) ; if ((dark_found) && (dark_dit==xenon_argon_dit)) { to_compute = image_sub(xenon_argon, dark) ; } else { to_compute = image_copy(xenon_argon) ; } } if (xenon_argon_found) image_del(xenon_argon) ; xenon_argon_found = 0 ; if (xenon_found) image_del(xenon) ; xenon_found = 0 ; if (argon_found) image_del(argon) ; argon_found = 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, 's', 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], 's', 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) ; } if (dark_found) image_del(dark) ; dark_found = 0 ; break ; default: if (xenon_found) image_del(xenon) ; if (argon_found) image_del(argon) ; if (dark_found) image_del(dark) ; xenon_found = argon_found = dark_found = 0 ; e_warning("unsupported resolution - no output") ; break ; } framelist_del(lnames_set) ; } } framelist_del(lnames) ; free(resol) ; } else { e_error("input file should be either a fits or an ascii file") ; return -1 ; } return 0 ; }