00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026
00027
00028
00029 #include <string.h>
00030 #include <muse.h>
00031 #include "muse_scipost_correct_dar_z.h"
00032
00033
00034
00035
00036
00037
00046
00047 int
00048 muse_scipost_correct_dar_compute(muse_processing *aProcessing,
00049 muse_scipost_correct_dar_params_t *aParams)
00050 {
00051 cpl_frameset *inframes = muse_frameset_find_tags(aProcessing->inframes,
00052 aProcessing->intags, 0,
00053 CPL_FALSE);
00054 cpl_error_code rc = CPL_ERROR_NONE;
00055 cpl_size iframe, nframes = cpl_frameset_get_size(inframes);
00056 for (iframe = 0; iframe < nframes; iframe++) {
00057 cpl_frame *frame = cpl_frameset_get_position(inframes, iframe);
00058 const char *fn = cpl_frame_get_filename(frame);
00059 muse_pixtable *pixtable = muse_pixtable_load_restricted_wavelength(fn,
00060 aParams->lambdamin,
00061 aParams->lambdamax);
00062 if (pixtable == NULL) {
00063 cpl_msg_error(__func__, "NULL pixel table for %s", fn);
00064 rc = CPL_ERROR_NULL_INPUT;
00065 break;
00066 }
00067 muse_processing_append_used(aProcessing, frame, CPL_FRAME_GROUP_RAW, 1);
00068
00069
00070 cpl_propertylist_erase_regexp(pixtable->header, "ESO QC ", 0);
00071 rc = muse_dar_correct(pixtable, aParams->lambdaref);
00072 if (rc != CPL_ERROR_NONE) {
00073 cpl_msg_error(__func__, "while muse_dar_correct(%s)",
00074 cpl_frame_get_filename(frame));
00075 muse_pixtable_delete(pixtable);
00076 break;
00077 }
00078
00079 if (aParams->darcheck != MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_NONE) {
00080 cpl_boolean dorefine = aParams->darcheck
00081 == MUSE_SCIPOST_CORRECT_DAR_PARAM_DARCHECK_CORRECT;
00082 cpl_msg_info(__func__, "Carrying out DAR %s", dorefine ? "correction" : "check");
00083 double maxshift = 0;
00084 rc = muse_dar_check(pixtable, &maxshift, dorefine, NULL);
00085 if (rc != CPL_ERROR_NONE) {
00086 cpl_msg_error(__func__, "Maximum detected shift %f\'\' (failure for "
00087 "\"%s\"; rc = %d: %s)", maxshift,
00088 cpl_frame_get_filename(frame), rc, cpl_error_get_message());
00089 muse_pixtable_delete(pixtable);
00090 break;
00091 } else {
00092 cpl_msg_info(__func__, "Maximum detected shift %f\'\'", maxshift);
00093 }
00094 }
00095 muse_processing_save_table(aProcessing, 0, pixtable, NULL,
00096 MUSE_TAG_PIXTABLE_REDUCED,
00097 MUSE_TABLE_TYPE_PIXTABLE);
00098 muse_pixtable_delete(pixtable);
00099 }
00100 cpl_frameset_delete(inframes);
00101
00102 return rc;
00103 }