vircam_dome_flat_combine.c

00001 /* $Id: vircam_dome_flat_combine.c,v 1.56 2010/09/09 12:15:01 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2010/09/09 12:15:01 $
00024  * $Revision: 1.56 $
00025  * $Name: v1-1-0 $
00026  */
00027 
00028 /* Includes */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include <stdio.h>
00035 #include <cpl.h>
00036 #include <math.h>
00037 
00038 #include "vircam_utils.h"
00039 #include "vircam_mask.h"
00040 #include "vircam_pfits.h"
00041 #include "vircam_dfs.h"
00042 #include "vircam_mods.h"
00043 #include "vircam_stats.h"
00044 #include "vircam_fits.h"
00045 #include "vircam_tfits.h"
00046 #include "vircam_channel.h"
00047 #include "vircam_paf.h"
00048 #include "vircam_wcsutils.h"
00049 
00050 /* Define values for bit mask that flags dummy results */
00051 
00052 #define MEANDOME    1
00053 #define RATIMG      2
00054 #define STATS_TAB   4
00055 
00056 /* Function prototypes */
00057 
00058 static int vircam_dome_flat_combine_create(cpl_plugin *) ;
00059 static int vircam_dome_flat_combine_exec(cpl_plugin *) ;
00060 static int vircam_dome_flat_combine_destroy(cpl_plugin *) ;
00061 static int vircam_dome_flat_combine(cpl_parameterlist *, cpl_frameset *) ;
00062 static int vircam_dome_flat_combine_save(cpl_frameset *framelist, 
00063                                          cpl_parameterlist *parlist);
00064 static void vircam_dome_flat_combine_dummy_products(void);
00065 static void vircam_dome_flat_combine_normal(int jext);
00066 static int vircam_dome_flat_combine_lastbit(int jext, cpl_frameset *framelist,
00067                                             cpl_parameterlist *parlist);
00068 static void vircam_dome_flat_combine_init(void);
00069 static void vircam_dome_flat_combine_tidy(int level);
00070 
00071 /* Static global variables */
00072 
00073 static struct {
00074 
00075     /* Input */
00076 
00077     float       lthr;
00078     float       hthr;
00079     int         combtype;
00080     int         scaletype;
00081     int         xrej;
00082     float       thresh;
00083     int         ncells;
00084     int         extenum;
00085 
00086     /* Output */
00087 
00088     float       flatrms;
00089     float       flatratio_med;
00090     float       flatratio_rms;
00091     float       minv;
00092     float       maxv;
00093     float       avev;
00094 
00095 } vircam_dome_flat_combine_config;
00096 
00097 
00098 static struct {
00099     int              *labels;
00100     cpl_frameset     *domelist;
00101     cpl_frame        *master_dark;
00102     cpl_frame        *master_dome_flat;
00103     cpl_frame        *chantab;
00104     vir_fits         **good;
00105     int              ngood;
00106     vir_mask         *master_mask;
00107     cpl_image        *outimage;
00108     vir_fits         **domes;
00109     int              ndomes;
00110     cpl_propertylist *drs;
00111     unsigned char    *rejmask;
00112     unsigned char    *rejplus;
00113     vir_tfits        *ctable;
00114     vir_fits         *mfimage;
00115     vir_fits         *mdark;
00116     cpl_image        *ratioimg;
00117     cpl_table        *ratioimstats;
00118     cpl_propertylist *phupaf;
00119 } ps;
00120 
00121 static int isfirst;
00122 static cpl_frame *product_frame_mean_dome = NULL;
00123 static cpl_frame *product_frame_ratioimg = NULL;
00124 static cpl_frame *product_frame_ratioimg_stats = NULL;
00125 static int we_expect;
00126 static int we_get;
00127 
00128 static char vircam_dome_flat_combine_description[] =
00129 "vircam_dome_flat_combine -- VIRCAM dome flat combine recipe.\n\n"
00130 "Combine a list of dome flat frames into a mean frame. Optionally compare \n"
00131 "the output frame to a master dome flat frame\n\n"
00132 "The program accepts the following files in the SOF:\n\n"
00133 "    Tag                   Description\n"
00134 "    -----------------------------------------------------------------------\n"
00135 "    %-21s A list of raw dome flat images\n"
00136 "    %-21s A master dark frame\n"
00137 "    %-21s Optional reference dome flat frame\n"
00138 "    %-21s Optional channel table or\n"
00139 "    %-21s Optional initial channel table\n"
00140 "    %-21s Optional master bad pixel map or\n"
00141 "    %-21s Optional master confidence map\n"
00142 "If no master dome flat is made available, then no comparison will be done\n"
00143 "This means there will be no output ratio image. If a master dome is\n"
00144 "available, but no channel table is, then a ratio image will be formed\n"
00145 "but no stats will be written."
00146 "\n";
00147 
00281 /* Function code */
00282 
00283 /*---------------------------------------------------------------------------*/
00291 /*---------------------------------------------------------------------------*/
00292 
00293 int cpl_plugin_get_info(cpl_pluginlist *list) {
00294     cpl_recipe  *recipe = cpl_calloc(1,sizeof(*recipe));
00295     cpl_plugin  *plugin = &recipe->interface;
00296     char alldesc[SZ_ALLDESC];
00297     (void)snprintf(alldesc,SZ_ALLDESC,vircam_dome_flat_combine_description,
00298                    VIRCAM_DOME_RAW,VIRCAM_CAL_DARK,VIRCAM_REF_DOME_FLAT,
00299                    VIRCAM_CAL_CHANTAB,VIRCAM_CAL_CHANTAB_INIT,VIRCAM_CAL_BPM,
00300                    VIRCAM_CAL_CONF);
00301 
00302     cpl_plugin_init(plugin,
00303                     CPL_PLUGIN_API,
00304                     VIRCAM_BINARY_VERSION,
00305                     CPL_PLUGIN_TYPE_RECIPE,
00306                     "vircam_dome_flat_combine",
00307                     "VIRCAM dome flat combination recipe",
00308                     alldesc,
00309                     "Jim Lewis",
00310                     "jrl@ast.cam.ac.uk",
00311                     vircam_get_license(),
00312                     vircam_dome_flat_combine_create,
00313                     vircam_dome_flat_combine_exec,
00314                     vircam_dome_flat_combine_destroy);
00315 
00316     cpl_pluginlist_append(list,plugin);
00317 
00318     return(0);
00319 }
00320 
00321 /*---------------------------------------------------------------------------*/
00330 /*---------------------------------------------------------------------------*/
00331 
00332 static int vircam_dome_flat_combine_create(cpl_plugin *plugin) {
00333     cpl_recipe      *recipe;
00334     cpl_parameter   *p;
00335 
00336     /* Get the recipe out of the plugin */
00337 
00338     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00339         recipe = (cpl_recipe *)plugin;
00340     else 
00341         return(-1);
00342 
00343     /* Create the parameters list in the cpl_recipe object */
00344 
00345     recipe->parameters = cpl_parameterlist_new();
00346 
00347     /* Lower threshold for rejecting underexposed images */
00348 
00349     p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.lthr",
00350                                 CPL_TYPE_DOUBLE,
00351                                 "Low rejection threshold for underexpsed images",
00352                                 "vircam.vircam_dome_flat_combine",
00353                                 0.0);
00354     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"lthr");
00355     cpl_parameterlist_append(recipe->parameters,p);
00356 
00357     /* Upper threshold for rejecting overexposed images */
00358 
00359     p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.hthr",
00360                                 CPL_TYPE_DOUBLE,
00361                                 "High rejection threshold for overexposed images",
00362                                 "vircam.vircam_dome_flat_combine",
00363                                 65535.0);
00364     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"hthr");
00365     cpl_parameterlist_append(recipe->parameters,p);
00366 
00367     /* Fill in the parameters. First the combination type */
00368 
00369     p = cpl_parameter_new_range("vircam.vircam_dome_flat_combine.combtype",
00370                                 CPL_TYPE_INT,
00371                                 "1 == Median,\n 2 == Mean",
00372                                 "vircam.vircam_dome_flat_combine",
00373                                 1,1,2);
00374     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"combtype");
00375     cpl_parameterlist_append(recipe->parameters,p);
00376 
00377     /* The requested scaling */
00378 
00379     p = cpl_parameter_new_range("vircam.vircam_dome_flat_combine.scaletype",
00380                                 CPL_TYPE_INT,
00381                                 "0 == none,\n 1 == additive offset,\n 2 == multiplicative offset,\n 3 == exposure time scaling + additive offset",
00382                                 "vircam.vircam_dome_flat_combine",
00383                                 1,0,3);
00384     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"scaletype");
00385     cpl_parameterlist_append(recipe->parameters,p);
00386     
00387     /* Extra rejection cycle */
00388 
00389     p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.xrej",
00390                                 CPL_TYPE_BOOL,
00391                                 "True if using extra rejection cycle",
00392                                 "vircam.vircam_dome_flat_combine",
00393                                 TRUE);
00394     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"xrej");
00395     cpl_parameterlist_append(recipe->parameters,p);
00396 
00397     /* Rejection threshold */
00398 
00399     p = cpl_parameter_new_value("vircam.vircam_dome_flat_combine.thresh",
00400                                 CPL_TYPE_DOUBLE,
00401                                 "Rejection threshold in sigma above background",
00402                                 "vircam.vircam_dome_flat_combine",5.0);
00403     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"thresh");
00404     cpl_parameterlist_append(recipe->parameters,p);
00405 
00406     /* How many cells to divide each data channel */
00407 
00408     p = cpl_parameter_new_enum("vircam.vircam_dome_flat_combine.ncells",
00409                                CPL_TYPE_INT,
00410                                "Number of cells for data channel stats",
00411                                "vircam.vircam_dome_flat_combine",8,7,1,2,4,8,
00412                                16,32,64);
00413     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ncells");
00414     cpl_parameterlist_append(recipe->parameters,p);     
00415 
00416     /* Extension number of input frames to use */
00417 
00418     p = cpl_parameter_new_range("vircam.vircam_dome_flat_combine.extenum",
00419                                 CPL_TYPE_INT,
00420                                 "Extension number to be done, 0 == all",
00421                                 "vircam.vircam_dome_flat_combine",
00422                                 1,0,16);
00423     cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ext");
00424     cpl_parameterlist_append(recipe->parameters,p);
00425         
00426     /* Get out of here */
00427 
00428     return(0);
00429 }
00430     
00431     
00432 /*---------------------------------------------------------------------------*/
00438 /*---------------------------------------------------------------------------*/
00439 
00440 static int vircam_dome_flat_combine_exec(cpl_plugin *plugin) {
00441     cpl_recipe  *recipe;
00442 
00443     /* Get the recipe out of the plugin */
00444 
00445     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00446         recipe = (cpl_recipe *)plugin;
00447     else 
00448         return(-1);
00449 
00450     return(vircam_dome_flat_combine(recipe->parameters,recipe->frames));
00451 }
00452                                 
00453 /*---------------------------------------------------------------------------*/
00459 /*---------------------------------------------------------------------------*/
00460 
00461 static int vircam_dome_flat_combine_destroy(cpl_plugin *plugin) {
00462     cpl_recipe *recipe ;
00463 
00464     /* Get the recipe out of the plugin */
00465 
00466     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00467         recipe = (cpl_recipe *)plugin;
00468     else 
00469         return(-1);
00470 
00471     cpl_parameterlist_delete(recipe->parameters);
00472     return(0);
00473 }
00474 
00475 /*---------------------------------------------------------------------------*/
00482 /*---------------------------------------------------------------------------*/
00483 
00484 static int vircam_dome_flat_combine(cpl_parameterlist *parlist, 
00485                                     cpl_frameset *framelist) {
00486     const char *fctid="vircam_dome_flat_combine";
00487     int nlab,j,jst,jfn,retval,status,live,nx,ny,ndit;
00488     long i;
00489     cpl_parameter *p;
00490     cpl_propertylist *pp;
00491     vir_fits *ff;
00492 
00493     /* Check validity of input frameset */
00494 
00495     if (framelist == NULL || cpl_frameset_get_size(framelist) <= 0) {
00496         cpl_msg_error(fctid,"Input framelist NULL or has no input data\n");
00497         return(-1);
00498     }
00499 
00500     /* Check the files in the frameset */
00501 
00502     if (vircam_frameset_fexists(framelist) != VIR_OK) {
00503         cpl_msg_error(fctid,"Input frameset is missing files. Check SOF");
00504         return(-1);
00505     }
00506 
00507     /* Initialise some things */
00508 
00509     vircam_dome_flat_combine_init();
00510     we_expect = MEANDOME;
00511 
00512     /* Get the parameters */
00513 
00514     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.lthr");
00515     vircam_dome_flat_combine_config.lthr = (float)cpl_parameter_get_double(p);
00516     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.hthr");
00517     vircam_dome_flat_combine_config.hthr = (float)cpl_parameter_get_double(p);
00518     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.combtype");
00519     vircam_dome_flat_combine_config.combtype = cpl_parameter_get_int(p);
00520     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.scaletype");
00521     vircam_dome_flat_combine_config.scaletype = cpl_parameter_get_int(p);
00522     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.xrej");
00523     vircam_dome_flat_combine_config.xrej = cpl_parameter_get_bool(p);
00524     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.thresh");
00525     vircam_dome_flat_combine_config.thresh = (float)cpl_parameter_get_double(p);
00526     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.ncells");
00527     vircam_dome_flat_combine_config.ncells = cpl_parameter_get_int(p);
00528     p = cpl_parameterlist_find(parlist,"vircam.vircam_dome_flat_combine.extenum");
00529     vircam_dome_flat_combine_config.extenum = cpl_parameter_get_int(p);
00530 
00531     /* Sort out raw from calib frames */
00532 
00533     if (vircam_dfs_set_groups(framelist) != VIR_OK) {
00534         cpl_msg_error(fctid,"Cannot identify RAW and CALIB frames");
00535         vircam_dome_flat_combine_tidy(2);
00536         return(-1);
00537     }
00538 
00539     /* Get the dome frames */
00540 
00541     if ((ps.labels = cpl_frameset_labelise(framelist,vircam_compare_tags,
00542                                            &nlab)) == NULL) {
00543         cpl_msg_error(fctid,"Cannot labelise the input frames");
00544         vircam_dome_flat_combine_tidy(2);
00545         return(-1);
00546     }
00547     if ((ps.domelist = vircam_frameset_subgroup(framelist,ps.labels,nlab,
00548                                                 VIRCAM_DOME_RAW)) == NULL) {
00549         cpl_msg_error(fctid,"Cannot find dome frames in input frameset");
00550         vircam_dome_flat_combine_tidy(2);
00551         return(-1);
00552     }
00553     ps.ndomes = cpl_frameset_get_size(ps.domelist);
00554 
00555     /* Check to see if there is a master dark frame */
00556 
00557     if ((ps.master_dark = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00558                                                      VIRCAM_CAL_DARK)) == NULL) {
00559         cpl_msg_error(fctid,"No master dark found");
00560         vircam_dome_flat_combine_tidy(2);
00561         return(-1);
00562     }
00563         
00564     /* Check to see if there is a master dome flat frame */
00565 
00566     if ((ps.master_dome_flat = vircam_frameset_subgroup_1(framelist,ps.labels,
00567                                                           nlab,VIRCAM_REF_DOME_FLAT)) == NULL)
00568         cpl_msg_info(fctid,"No master dome flat found -- no ratio image will be formed");
00569     else 
00570         we_expect |= RATIMG;
00571         
00572     /* Check to see if there is a master bad pixel map. If there isn't one 
00573        then look for a confidence map */
00574 
00575     ps.master_mask = vircam_mask_define(framelist,ps.labels,nlab);
00576 
00577     /* Check to see if there is a channel table */
00578 
00579     if ((ps.chantab = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00580                                                  VIRCAM_CAL_CHANTAB)) == NULL) {
00581         if ((ps.chantab = vircam_frameset_subgroup_1(framelist,ps.labels,nlab,
00582                                                      VIRCAM_CAL_CHANTAB_INIT)) == NULL) {
00583             cpl_msg_info(fctid,"No channel table found -- no ratio image stats and no linearisation will be done");
00584         } else {
00585             cpl_msg_info(fctid,"Channel table is labelled INIT -- no linearisation will be done");
00586             if (we_expect & RATIMG)
00587                 we_expect |= STATS_TAB;
00588         }
00589     } else if (we_expect & RATIMG) {
00590         we_expect |= STATS_TAB;
00591     }
00592 
00593     /* Now, how many image extensions do we want to do? If the extension
00594        number is zero, then we loop for all possible extensions. If it
00595        isn't then we just do the extension specified */
00596 
00597     vircam_exten_range(vircam_dome_flat_combine_config.extenum,
00598                        (const cpl_frame *)cpl_frameset_get_frame(ps.domelist,0),
00599                        &jst,&jfn);
00600     if (jst == -1 || jfn == -1) {
00601         cpl_msg_error(fctid,"Unable to continue");
00602         vircam_dome_flat_combine_tidy(2);
00603         return(-1);
00604     }
00605 
00606     /* Get the number of DITs */
00607 
00608     pp = cpl_propertylist_load(cpl_frame_get_filename(cpl_frameset_get_frame(ps.domelist,0)),0);
00609     if (vircam_pfits_get_ndit(pp,&ndit) != VIR_OK) {
00610         cpl_msg_error(fctid,"No value for NDIT available");
00611         freepropertylist(pp);
00612         vircam_dome_flat_combine_tidy(2);
00613         return(-1);
00614     }
00615     cpl_propertylist_delete(pp);
00616 
00617     /* Get some space for the good frames */
00618 
00619     ps.good = cpl_malloc(ps.ndomes*sizeof(vir_fits *));
00620 
00621     /* Now loop for all the extension... */
00622 
00623     for (j = jst; j <= jfn; j++) {
00624         status = VIR_OK;
00625         we_get = 0;
00626         isfirst = (j == jst);
00627 
00628         /* Load the images and the master dark. */
00629 
00630         ps.domes = vircam_fits_load_list(ps.domelist,CPL_TYPE_FLOAT,j);
00631         if (ps.domes == NULL) {
00632             cpl_msg_info(fctid,"Extension %d domes wouldn't load",j);
00633             retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
00634             if (retval != 0)
00635                 return(-1);
00636             continue;
00637         }
00638 
00639         /* Are any of these dome flats any good? */
00640         
00641         ps.ngood = 0;
00642         for (i = 0; i < ps.ndomes; i++) {
00643             ff = ps.domes[i];
00644             vircam_pfits_get_detlive(vircam_fits_get_ehu(ff),&live);
00645             if (! live) {
00646                 cpl_msg_info(fctid,"Detector flagged dead %s",
00647                              vircam_fits_get_fullname(ff));
00648                 vircam_fits_set_error(ff,VIR_FATAL);
00649             } else {
00650                 ps.good[ps.ngood] = ff;
00651                 ps.ngood += 1;
00652             }
00653         }
00654 
00655         /* If there are no good images, then signal that we need to create 
00656            dummy products and move on */
00657 
00658         if (ps.ngood == 0) {
00659             cpl_msg_info(fctid,"All images flagged bad for this extension");
00660             retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
00661             if (retval != 0)
00662                 return(-1);
00663             continue;
00664         }
00665 
00666         /* Load the mask */
00667 
00668         nx = cpl_image_get_size_x(vircam_fits_get_image(ps.good[0]));
00669         ny = cpl_image_get_size_y(vircam_fits_get_image(ps.good[0]));
00670         if (vircam_mask_load(ps.master_mask,j,nx,ny) == VIR_FATAL) {
00671             cpl_msg_info(fctid,"Unable to load mask image %s[%d]",
00672                          vircam_mask_get_filename(ps.master_mask),j);
00673             cpl_msg_info(fctid,"Forcing all pixels to be good from now on");
00674             vircam_mask_force(ps.master_mask,nx,ny);
00675         }
00676 
00677         /* Sort out the images that are either over or under exposed */
00678 
00679         vircam_overexp(ps.good,&(ps.ngood),ndit,
00680                        vircam_dome_flat_combine_config.lthr,
00681                        vircam_dome_flat_combine_config.hthr,0,
00682                        &(vircam_dome_flat_combine_config.minv),
00683                        &(vircam_dome_flat_combine_config.maxv),
00684                        &(vircam_dome_flat_combine_config.avev));
00685 
00686         /* Check to see how many are left. If there aren't any, then
00687            signal a major error */
00688 
00689         if (ps.ngood == 0) {
00690             cpl_msg_info(fctid,"All images either under or overexposed");
00691             retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
00692             if (retval != 0)
00693                 return(-1);
00694             continue;
00695         }
00696 
00697         /* Right, we want to dark correct, so we need to load the mean 
00698            dark and make sure it isn't a dummy */
00699 
00700         ps.mdark = vircam_fits_load(ps.master_dark,CPL_TYPE_FLOAT,j);
00701         if (ps.mdark == NULL) {
00702             cpl_msg_info(fctid,"Can't load master dark for extension %d",j);
00703             retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
00704             if (retval != 0)
00705                 return(-1);
00706             continue;
00707         } else if (vircam_is_dummy(vircam_fits_get_ehu(ps.mdark))) {
00708             cpl_msg_info(fctid,"Can't master dark extension %d is a dummy",j);
00709             retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
00710             if (retval != 0)
00711                 return(-1);
00712             continue;
00713         }
00714 
00715         /* Loop for each image and dark correct */
00716 
00717         cpl_msg_info(fctid,"Dark correcting extension %d\n",j);
00718         for (i = 0; i < ps.ngood; i++)
00719             vircam_darkcor((ps.good)[i],ps.mdark,1.0,&status);
00720 
00721         /* We need to load the channel table (if it exists) for linearisation
00722            and for the ratio image stats table */
00723 
00724         if (ps.chantab != NULL) {
00725             ps.ctable = vircam_tfits_load(ps.chantab,j);
00726             if (ps.ctable == NULL) {
00727                 cpl_msg_info(fctid,"Channel table extension %d won't load",j);
00728             } else if (vircam_chantab_verify(vircam_tfits_get_table(ps.ctable)) != VIR_OK) {
00729                 cpl_msg_info(fctid,"Channel table extension %d has errors",j);
00730                 freetfits(ps.ctable);
00731             } else { 
00732                 pp = cpl_propertylist_load(cpl_frame_get_filename(ps.chantab),
00733                                            j);
00734                 if (vircam_is_dummy(pp)) {
00735                     cpl_msg_info(fctid,
00736                                  "Channel table extensions %d is a dummy",j);
00737                     freetfits(ps.ctable);
00738                 }
00739                 freepropertylist(pp);
00740             }
00741         } else 
00742             ps.ctable = NULL;
00743                 
00744         /* Loop for each of the input images and linearise it if there
00745            is a channel table */
00746 
00747         if (ps.ctable != NULL) {
00748             cpl_msg_info(fctid,"Linearising extension %d\n",j);
00749             for (i = 0; i < ps.ngood; i++)
00750                 (void)vircam_lincor((ps.good)[i],ps.ctable,1,ndit,&status);
00751         }
00752 
00753         /* Correct for ndit */
00754 
00755         for (i = 0; i < ps.ngood; i++) 
00756             (void)vircam_nditcor((ps.good)[i],ndit,&status);
00757 
00758         /* Call the combine module */
00759 
00760         cpl_msg_info(fctid,"Doing combination for extension %d\n",j);
00761         (void)vircam_imcombine(ps.good,ps.ngood,
00762                                vircam_dome_flat_combine_config.combtype,
00763                                vircam_dome_flat_combine_config.scaletype,
00764                                vircam_dome_flat_combine_config.xrej,
00765                                vircam_dome_flat_combine_config.thresh,
00766                                &(ps.outimage),&(ps.rejmask),&(ps.rejplus),
00767                                &(ps.drs),&status);
00768 
00769         /* If these correction and combination routines failed at any stage
00770            then get out of here */
00771 
00772         if (status == VIR_OK) {
00773             we_get |= MEANDOME;
00774             vircam_dome_flat_combine_normal(j);
00775         } else {
00776             cpl_msg_info(fctid,"A processing step failed");
00777         }
00778 
00779         /* Create any dummies and save the products */
00780         
00781         retval = vircam_dome_flat_combine_lastbit(j,framelist,parlist);
00782         if (retval != 0)
00783             return(-1);
00784 
00785     }
00786     vircam_dome_flat_combine_tidy(2);
00787     return(0);
00788 }
00789 
00790 
00791 /*---------------------------------------------------------------------------*/
00798 /*---------------------------------------------------------------------------*/
00799 
00800 static int vircam_dome_flat_combine_save(cpl_frameset *framelist, 
00801                                          cpl_parameterlist *parlist) {
00802     cpl_propertylist *plist,*elist,*p,*paf;
00803     int status;
00804     float val;
00805     const char *fctid = "vircam_dome_flat_combine_save";
00806     const char *outfile = "domecomb.fits";
00807     const char *outdiff = "domeratio.fits";
00808     const char *outdimst = "domeratiotab.fits";
00809     const char *outpaf = "domecomb";
00810     const char *outdpaf = "domeratio";
00811     const char *recipeid = "vircam_dome_flat_combine";
00812 
00813     /* If we need to make a PHU then do that now based on the first frame
00814        in the input frame list */
00815 
00816     if (isfirst) {
00817 
00818         /* Create a new product frame object and define some tags */
00819 
00820         product_frame_mean_dome = cpl_frame_new();
00821         cpl_frame_set_filename(product_frame_mean_dome,outfile);
00822         cpl_frame_set_tag(product_frame_mean_dome,VIRCAM_PRO_DOME_FLAT);
00823         cpl_frame_set_type(product_frame_mean_dome,CPL_FRAME_TYPE_IMAGE);
00824         cpl_frame_set_group(product_frame_mean_dome,CPL_FRAME_GROUP_PRODUCT);
00825         cpl_frame_set_level(product_frame_mean_dome,CPL_FRAME_LEVEL_FINAL);
00826 
00827         /* Set up the PHU header */
00828 
00829         plist = vircam_fits_get_phu(ps.domes[0]);
00830         ps.phupaf = vircam_paf_phu_items(plist);
00831         if (ps.master_dome_flat != NULL) {
00832             cpl_propertylist_update_string(ps.phupaf,"REF_DOME",
00833                                            cpl_frame_get_filename(ps.master_dome_flat));
00834             cpl_propertylist_set_comment(ps.phupaf,"REF_DOME",
00835                                          "Reference dome flat used");
00836         }
00837         vircam_dfs_set_product_primary_header(plist,product_frame_mean_dome,
00838                                               framelist,parlist,
00839                                               (char *)recipeid,
00840                                               "PRO-1.15",NULL,0);
00841 
00842         /* 'Save' the PHU image */                       
00843 
00844         if (cpl_image_save(NULL,outfile,CPL_BPP_8_UNSIGNED,plist,
00845                            CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00846             cpl_msg_error(fctid,"Cannot save product PHU");
00847             cpl_frame_delete(product_frame_mean_dome);
00848             return(-1);
00849         }
00850         cpl_frameset_insert(framelist,product_frame_mean_dome);
00851 
00852         /* Create a new product frame object for the ratio image */
00853 
00854         if (we_expect & RATIMG) {
00855             product_frame_ratioimg = cpl_frame_new();
00856             cpl_frame_set_filename(product_frame_ratioimg,outdiff);
00857             cpl_frame_set_tag(product_frame_ratioimg,
00858                               VIRCAM_PRO_RATIOIMG_DOME_FLAT);
00859             cpl_frame_set_type(product_frame_ratioimg,CPL_FRAME_TYPE_IMAGE);
00860             cpl_frame_set_group(product_frame_ratioimg,
00861                                 CPL_FRAME_GROUP_PRODUCT);
00862             cpl_frame_set_level(product_frame_ratioimg,CPL_FRAME_LEVEL_FINAL);
00863 
00864             /* Set up the PHU header */
00865 
00866             plist = vircam_fits_get_phu(ps.domes[0]);
00867             vircam_dfs_set_product_primary_header(plist,product_frame_ratioimg,
00868                                                   framelist,parlist,
00869                                                   (char *)recipeid,
00870                                                   "PRO-1.15",NULL,0);
00871 
00872             /* 'Save' the PHU image */                   
00873 
00874             if (cpl_image_save(NULL,outdiff,CPL_BPP_8_UNSIGNED,plist,
00875                                CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00876                 cpl_msg_error(fctid,"Cannot save product PHU");
00877                 cpl_frame_delete(product_frame_ratioimg);
00878                 return(-1);
00879             }
00880             cpl_frameset_insert(framelist,product_frame_ratioimg);
00881         }
00882 
00883         /* Create a new product frame object for the difference image stats 
00884            table */
00885 
00886         if (we_expect & STATS_TAB) {
00887             product_frame_ratioimg_stats = cpl_frame_new();
00888             cpl_frame_set_filename(product_frame_ratioimg_stats,outdimst);
00889             cpl_frame_set_tag(product_frame_ratioimg_stats,
00890                               VIRCAM_PRO_RATIOIMG_DOME_FLAT_STATS);
00891             cpl_frame_set_type(product_frame_ratioimg_stats,
00892                                CPL_FRAME_TYPE_TABLE);
00893             cpl_frame_set_group(product_frame_ratioimg_stats,
00894                                 CPL_FRAME_GROUP_PRODUCT);
00895             cpl_frame_set_level(product_frame_ratioimg_stats,
00896                                 CPL_FRAME_LEVEL_FINAL);
00897 
00898             /* Set up the PHU header */
00899 
00900             plist = vircam_fits_get_phu(ps.domes[0]);
00901             vircam_dfs_set_product_primary_header(plist,
00902                                                   product_frame_ratioimg_stats,
00903                                                   framelist,parlist,
00904                                                   (char *)recipeid,
00905                                                   "PRO-1.15",NULL,0);
00906 
00907             /* Fiddle with the extension header now */
00908 
00909             elist = vircam_fits_get_ehu(ps.domes[0]);
00910             p = cpl_propertylist_duplicate(elist);
00911             vircam_merge_propertylists(p,ps.drs);
00912             vircam_paf_append(p,vircam_fits_get_phu(ps.domes[0]),
00913                               "ESO INS FILT1 NAME");
00914             if (! (we_get & STATS_TAB)) 
00915                 vircam_dummy_property(p);
00916             vircam_dfs_set_product_exten_header(p,product_frame_ratioimg_stats,
00917                                                 framelist,parlist,
00918                                                 (char *)recipeid,
00919                                                 "PRO-1.15",NULL);
00920             status = VIR_OK;
00921             vircam_removewcs(p,&status);
00922 
00923             /* And finally the difference image stats table */
00924 
00925             if (cpl_table_save(ps.ratioimstats,plist,p,outdimst,
00926                                CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00927                 cpl_msg_error(fctid,"Cannot save product table extension");
00928                 cpl_propertylist_delete(p);
00929                 return(-1);
00930             }
00931             cpl_propertylist_delete(p);
00932             cpl_frameset_insert(framelist,product_frame_ratioimg_stats);
00933         }
00934     }
00935 
00936     /* Get the extension property list */
00937 
00938     plist = vircam_fits_get_ehu(ps.domes[0]);
00939     cpl_propertylist_update_int(plist,"ESO PRO DATANCOM",ps.ngood);
00940 
00941     /* Fiddle with the header now. */
00942 
00943     vircam_merge_propertylists(plist,ps.drs);
00944     p = cpl_propertylist_duplicate(plist);
00945     if (! (we_get & MEANDOME))
00946         vircam_dummy_property(p);
00947     vircam_dfs_set_product_exten_header(p,product_frame_mean_dome,
00948                                         framelist,parlist,
00949                                         (char *)recipeid,
00950                                         "PRO-1.15",NULL);
00951                 
00952     /* Now save the mean dome flat image extension */
00953 
00954     cpl_propertylist_update_float(p,"ESO QC FLATRMS",
00955                                   vircam_dome_flat_combine_config.flatrms);
00956     cpl_propertylist_set_comment(p,"ESO QC FLATRMS","RMS of output flat");
00957     cpl_propertylist_update_float(p,"ESO QC FLATMIN",
00958                                   vircam_dome_flat_combine_config.minv);
00959     cpl_propertylist_set_comment(p,"ESO QC FLATMIN","Ensemble minimum");
00960     cpl_propertylist_update_float(p,"ESO QC FLATMAX",
00961                                   vircam_dome_flat_combine_config.maxv);
00962     cpl_propertylist_set_comment(p,"ESO QC FLATMAX","Ensemble maximum");
00963     cpl_propertylist_update_float(p,"ESO QC FLATAVG",
00964                                   vircam_dome_flat_combine_config.avev);
00965     cpl_propertylist_set_comment(p,"ESO QC FLATAVG","Ensemble average");
00966     val = vircam_dome_flat_combine_config.maxv - 
00967         vircam_dome_flat_combine_config.minv;
00968     cpl_propertylist_update_float(p,"ESO QC FLATRNG",val);
00969     cpl_propertylist_set_comment(p,"ESO QC FLATRNG","Ensemble range");
00970     if (cpl_image_save(ps.outimage,outfile,CPL_BPP_IEEE_FLOAT,p,
00971                        CPL_IO_EXTEND) != CPL_ERROR_NONE) {
00972         cpl_propertylist_delete(p);
00973         cpl_msg_error(fctid,"Cannot save product image extension");
00974         return(-1);
00975     }
00976 
00977     /* Write the PAF */
00978 
00979     paf = vircam_paf_req_items(p);
00980     vircam_merge_propertylists(paf,ps.phupaf);
00981     vircam_paf_append(paf,vircam_fits_get_phu(ps.domes[0]),
00982                       "ESO INS FILT1 NAME");
00983     vircam_paf_append(paf,p,"ESO PRO CATG");
00984     vircam_paf_append(paf,p,"ESO PRO DATANCOM");
00985     if (vircam_paf_print((char *)outpaf,"VIRCAM/vircam_dome_flat_combine",
00986                          "QC file",paf) != VIR_OK)
00987         cpl_msg_warning(fctid,"Unable to save PAF for mean dome");
00988     cpl_propertylist_delete(paf);    
00989     cpl_propertylist_delete(p);
00990 
00991     /* Now save the dome ratio image extension */
00992 
00993     if (we_expect & RATIMG) {
00994         p = cpl_propertylist_duplicate(plist);
00995         if (! (we_get & RATIMG))
00996             vircam_dummy_property(p);
00997         cpl_propertylist_update_float(p,"ESO QC FLATRATIO_MED",
00998                                       vircam_dome_flat_combine_config.flatratio_med);
00999         cpl_propertylist_set_comment(p,"ESO QC FLATRATIO_MED",
01000                                      "Median of ratio map");
01001         cpl_propertylist_update_float(p,"ESO QC FLATRATIO_RMS",
01002                                       vircam_dome_flat_combine_config.flatratio_rms);
01003         cpl_propertylist_set_comment(p,"ESO QC FLATRATIO_RMS",
01004                                      "RMS of ratio map");
01005         vircam_dfs_set_product_exten_header(p,product_frame_ratioimg,
01006                                             framelist,parlist,
01007                                             (char *)recipeid,
01008                                             "PRO-1.15",NULL);
01009         if (cpl_image_save(ps.ratioimg,outdiff,CPL_BPP_IEEE_FLOAT,p,
01010                            CPL_IO_EXTEND) != CPL_ERROR_NONE) {
01011             cpl_propertylist_delete(p);
01012             cpl_msg_error(fctid,"Cannot save product image extension");
01013             return(-1);
01014         }
01015 
01016         /* Write the PAF */
01017 
01018         paf = vircam_paf_req_items(p);
01019         vircam_merge_propertylists(paf,ps.phupaf);
01020         vircam_paf_append(paf,vircam_fits_get_phu(ps.domes[0]),
01021                           "ESO INS FILT1 NAME");
01022         vircam_paf_append(paf,p,"ESO PRO CATG");
01023         if (vircam_paf_print((char *)outdpaf,"VIRCAM/vircam_dome_flat_combine",
01024                              "QC file",paf) != VIR_OK)
01025             cpl_msg_warning(fctid,"Unable to save PAF for ratio image");
01026         cpl_propertylist_delete(paf);    
01027         cpl_propertylist_delete(p);
01028     }
01029 
01030     /* Now any further ratio image stats tables */
01031 
01032     if (! isfirst && (we_expect & STATS_TAB)) {
01033         p = cpl_propertylist_duplicate(plist);
01034         if (! (we_get & STATS_TAB)) 
01035             vircam_dummy_property(p);
01036         vircam_dfs_set_product_exten_header(p,product_frame_ratioimg_stats,
01037                                             framelist,parlist,
01038                                             (char *)recipeid,
01039                                             "PRO-1.15",NULL);
01040         status = VIR_OK;
01041         vircam_removewcs(p,&status);
01042         if (cpl_table_save(ps.ratioimstats,NULL,p,outdimst,CPL_IO_EXTEND)
01043                            != CPL_ERROR_NONE) {
01044             cpl_propertylist_delete(p);
01045             cpl_msg_error(fctid,"Cannot save product table extension");
01046             return(-1);
01047         }       
01048         cpl_propertylist_delete(p);
01049     }
01050 
01051     /* Get out of here */
01052 
01053     return(0);
01054 }
01055 
01056 /*---------------------------------------------------------------------------*/
01060 /*---------------------------------------------------------------------------*/
01061 
01062 static void vircam_dome_flat_combine_dummy_products(void) {
01063 
01064     /* See if you even need to be here */
01065 
01066     if (we_get == we_expect)
01067         return;
01068 
01069     /* First an output combined dome  frame */
01070 
01071     if (! (we_get & MEANDOME)) {
01072         ps.outimage = vircam_dummy_image(ps.domes[0]);
01073         vircam_dome_flat_combine_config.flatrms = 0.0;
01074     }
01075 
01076     /* Do a ratio image */
01077 
01078     if ((we_expect & RATIMG) && ! (we_get & RATIMG)) {
01079         vircam_dome_flat_combine_config.flatratio_med = 0.0;
01080         vircam_dome_flat_combine_config.flatratio_rms = 0.0;
01081         ps.ratioimg = vircam_dummy_image(ps.domes[0]);
01082     }
01083 
01084     /* If a ratio image stats table is required, then do that now */
01085    
01086     if ((we_expect & STATS_TAB) && ! (we_get & STATS_TAB)) 
01087         ps.ratioimstats = vircam_create_diffimg_stats(0);
01088 
01089     return;
01090 }
01091 
01092 /*---------------------------------------------------------------------------*/
01097 /*---------------------------------------------------------------------------*/
01098 
01099 static void vircam_dome_flat_combine_normal(int jext) {
01100     int nx,ny,ncells;
01101     long npi;
01102     unsigned char *bpm;
01103     float *idata,med,sig,gdiff,grms;
01104     const char *fctid="vircam_dome_flat_combine_normal";
01105 
01106     /* Load up a bad pixel mask */
01107 
01108     nx = cpl_image_get_size_x(ps.outimage);
01109     ny = cpl_image_get_size_y(ps.outimage);
01110     npi = nx*ny;
01111     bpm = vircam_mask_get_data(ps.master_mask);
01112 
01113     /* Work out the RMS of the mean dome frame */
01114 
01115     idata = cpl_image_get_data(ps.outimage);
01116     vircam_medsig(idata,bpm,npi,&med,&sig);
01117 
01118     /* Divide through by the median */
01119 
01120     cpl_image_divide_scalar(ps.outimage,med);
01121     vircam_medmad(idata,bpm,npi,&med,&sig);
01122     sig *= 1.48;
01123     vircam_dome_flat_combine_config.flatrms = sig;
01124 
01125     /* Load up the master dome flat */
01126 
01127     if (ps.master_dome_flat != NULL) {
01128         ps.mfimage = vircam_fits_load(ps.master_dome_flat,CPL_TYPE_FLOAT,jext);
01129         if (ps.mfimage == NULL) {
01130             cpl_msg_error(fctid,"Master dome extension %d won't load",jext);
01131         } else if (vircam_is_dummy(vircam_fits_get_ehu(ps.mfimage))) {
01132             cpl_msg_error(fctid,"Master dome extension %d is a dummy",jext);
01133             freefits(ps.mfimage);
01134         }
01135     } else
01136         ps.mfimage = NULL;
01137 
01138 
01139     /* Create a ratio image. NB: the difference image routine copes if the 
01140        input mean image or the channel tables are null.  Thus if either or
01141        both are null because of a failure to load, then the routine will do
01142        as  much as it can and return, allowing you to fill in the rest with
01143        dummy products */
01144 
01145     vircam_dome_flat_combine_config.flatratio_med = 0.0;
01146     vircam_dome_flat_combine_config.flatratio_rms = 0.0;
01147     ncells = vircam_dome_flat_combine_config.ncells;
01148     vircam_difference_image(vircam_fits_get_image(ps.mfimage),ps.outimage,bpm,
01149                             vircam_tfits_get_table(ps.ctable),ncells,2,
01150                             &gdiff,&grms,&(ps.ratioimg),
01151                             &(ps.ratioimstats));
01152     vircam_mask_clear(ps.master_mask);
01153     vircam_dome_flat_combine_config.flatratio_med = gdiff;
01154     vircam_dome_flat_combine_config.flatratio_rms = grms;
01155     if (ps.ratioimg != NULL)
01156         we_get |= RATIMG;
01157     if (ps.ratioimstats != NULL)
01158         we_get |= STATS_TAB;
01159     return;
01160 }
01161 
01162 /*---------------------------------------------------------------------------*/
01170 /*---------------------------------------------------------------------------*/
01171 
01172 static int vircam_dome_flat_combine_lastbit(int jext, cpl_frameset *framelist,
01173                                             cpl_parameterlist *parlist) {
01174     int retval;
01175     const char *fctid="vircam_dome_flat_combine_lastbit";
01176 
01177     /* Make whatever dummy products you need */
01178 
01179     vircam_dome_flat_combine_dummy_products();
01180 
01181     /* Save everything */
01182 
01183     cpl_msg_info(fctid,"Saving products for extension %d",jext);
01184     retval = vircam_dome_flat_combine_save(framelist,parlist);
01185     if (retval != 0) {
01186         vircam_dome_flat_combine_tidy(2);
01187         return(-1);
01188     }
01189 
01190     /* Free some stuff up */
01191 
01192     vircam_dome_flat_combine_tidy(1);
01193     return(0);
01194 }
01195 
01196 /*---------------------------------------------------------------------------*/
01200 /*---------------------------------------------------------------------------*/
01201 
01202 static void vircam_dome_flat_combine_init(void) {
01203     ps.labels = NULL;
01204     ps.domelist = NULL;
01205     ps.domes = NULL;
01206     ps.good = NULL;
01207     ps.master_dark = NULL;
01208     ps.master_dome_flat = NULL;
01209     ps.master_mask = NULL;
01210     ps.chantab = NULL;
01211     ps.ctable = NULL;
01212     ps.outimage = NULL;
01213     ps.drs = NULL;
01214     ps.rejmask = NULL;
01215     ps.rejplus = NULL;
01216     ps.mfimage = NULL;
01217     ps.ratioimg = NULL;
01218     ps.ratioimstats = NULL;
01219     ps.phupaf = NULL;
01220 }
01221 
01222 /*---------------------------------------------------------------------------*/
01226 /*---------------------------------------------------------------------------*/
01227 
01228 static void vircam_dome_flat_combine_tidy(int level) {
01229     freeimage(ps.outimage);
01230     freefitslist(ps.domes,ps.ndomes);
01231     freepropertylist(ps.drs);
01232     freespace(ps.rejmask);
01233     freespace(ps.rejplus);
01234     freetfits(ps.ctable);
01235     freefits(ps.mfimage);
01236     freefits(ps.mdark);
01237     freeimage(ps.ratioimg);
01238     freetable(ps.ratioimstats);
01239     if (level == 1)
01240         return;
01241 
01242     freespace(ps.labels);
01243     freeframeset(ps.domelist);
01244     freeframe(ps.master_dark);
01245     freeframe(ps.master_dome_flat);
01246     freeframe(ps.chantab);
01247     freespace(ps.good);
01248     freemask(ps.master_mask);
01249     freepropertylist(ps.phupaf);
01250 
01251 }
01252 
01255 /*
01256 
01257 $Log: vircam_dome_flat_combine.c,v $
01258 Revision 1.56  2010/09/09 12:15:01  jim
01259 Added QC parameters to give ensemble min, max, ave and range flats
01260 
01261 Revision 1.55  2010/03/21 06:48:21  jim
01262 Fixed bug where DATANCOM wasn't being updated in all products
01263 
01264 Revision 1.54  2010/03/09 14:27:40  jim
01265 Now updates ESO PRO DATANCOM to reflect the number of images used
01266 
01267 Revision 1.53  2010/02/05 09:42:22  jim
01268 Fixed call to non-existent cpl routine
01269 
01270 Revision 1.52  2010/01/31 18:53:41  jim
01271 Reference flat included in paf
01272 
01273 Revision 1.51  2009/09/21 11:59:06  jim
01274 modified to use new version of vircam_overexp
01275 
01276 Revision 1.50  2009/09/09 09:50:21  jim
01277 Modified to try and get headers right
01278 
01279 Revision 1.49  2008/12/05 13:28:32  jim
01280 Fixed save routine so that the correct version of PRO CATG is written to the
01281 paf file
01282 
01283 Revision 1.48  2008/10/01 04:59:13  jim
01284 Added call to vircam_frameset_fexists to check input frameset
01285 
01286 Revision 1.47  2008/09/30 11:33:23  jim
01287 Added PRO CATG to pafs
01288 
01289 Revision 1.46  2008/09/29 11:23:47  jim
01290 Defaults to form median flat now. Also fixed header writing bug
01291 
01292 Revision 1.45  2007/11/26 09:59:06  jim
01293 Recipe now takes ndit into account when doing linearity correction
01294 
01295 Revision 1.44  2007/10/19 09:25:09  jim
01296 Fixed problems with missing includes
01297 
01298 Revision 1.43  2007/10/15 12:53:26  jim
01299 Modified for compatibiliity with cpl_4.0
01300 
01301 Revision 1.42  2007/07/18 15:35:42  jim
01302 Added better error handling for missing or corrupt mask extensions
01303 
01304 Revision 1.41  2007/07/09 13:21:55  jim
01305 Modified to use new version of vircam_exten_range
01306 
01307 Revision 1.40  2007/04/30 09:40:17  jim
01308 Added more stuff to paf files
01309 
01310 Revision 1.39  2007/04/04 10:36:18  jim
01311 Modified to use new dfs tags
01312 
01313 Revision 1.38  2007/03/29 12:19:38  jim
01314 Little changes to improve documentation
01315 
01316 Revision 1.37  2007/03/02 12:37:16  jim
01317 Removed WCS stuff from table headers
01318 
01319 Revision 1.36  2007/03/01 12:41:49  jim
01320 Modified slightly after code checking
01321 
01322 Revision 1.35  2007/02/25 06:27:41  jim
01323 plugged a few memory leaks
01324 
01325 Revision 1.34  2007/02/15 11:54:09  jim
01326 Modified to make a distinction between initial channel table and one that
01327 has the proper linearity information
01328 
01329 Revision 1.33  2007/02/15 06:59:37  jim
01330 Added ability to write QC paf files
01331 
01332 Revision 1.32  2007/02/07 10:12:39  jim
01333 Removed calls to vircam_ndit_correct as this is now no longer necessary
01334 
01335 Revision 1.31  2007/02/06 13:11:12  jim
01336 Fixed entry for PRO dictionary in cpl_dfs_set_product_header
01337 
01338 Revision 1.30  2007/02/05 14:14:05  jim
01339 Input master frame is now tagged as REFERENCE. QC removed from stats table
01340 headers
01341 
01342 Revision 1.29  2007/01/08 19:09:11  jim
01343 Fixed memory leak
01344 
01345 Revision 1.28  2006/12/13 13:26:09  jim
01346 Fxied bad sigma estimate
01347 
01348 Revision 1.27  2006/11/27 12:13:21  jim
01349 Swapped calls to cpl_propertylist_append to cpl_propertylist_update
01350 
01351 Revision 1.26  2006/11/10 09:21:48  jim
01352 Fixed bug in save routine to get the correct propertylist written to product
01353 header. Also fixed memory deallocation error in tidy routine
01354 
01355 Revision 1.25  2006/09/29 11:19:31  jim
01356 changed aliases on parameter names
01357 
01358 Revision 1.24  2006/09/09 16:49:39  jim
01359 Header comment update
01360 
01361 Revision 1.23  2006/08/27 20:30:02  jim
01362 Major mods to structure of the main processing routine to deal with missing
01363 and dummy frames. Deals better with lower level failures too
01364 
01365 Revision 1.22  2006/07/11 14:55:12  jim
01366 Now checks for zeros in the output flat and replaces them
01367 
01368 Revision 1.21  2006/06/20 19:07:01  jim
01369 Corrects for ndit != 1
01370 
01371 Revision 1.20  2006/06/15 09:58:58  jim
01372 Minor changes to docs
01373 
01374 Revision 1.19  2006/06/09 11:26:25  jim
01375 Small changes to keep lint happy
01376 
01377 Revision 1.18  2006/06/06 13:01:39  jim
01378 Fixed so that the QC parameters go into the correct headers
01379 
01380 Revision 1.17  2006/05/26 19:38:20  jim
01381 Fixed recipe so that the output flat is normalised as it should be
01382 
01383 Revision 1.16  2006/05/17 14:43:58  jim
01384 Fixed problem in save routine which messed up the PRO CATG keywords
01385 
01386 Revision 1.15  2006/05/16 13:58:47  jim
01387 Fixed memory leaks that occur from not closing images at the end of
01388 the image extension loop
01389 
01390 Revision 1.14  2006/05/10 14:30:13  jim
01391 deleted ps.domes twice
01392 
01393 Revision 1.13  2006/05/04 11:53:15  jim
01394 Fixed the way the _save routine works to be more consistent with the
01395 standard CPL way of doing things
01396 
01397 Revision 1.12  2006/04/27 09:34:48  jim
01398 Fixed data type bug in parameter lthr and hthr. Modified headers to change the
01399 dfs keywords to the latest values. Removed confidence map part.
01400 
01401 Revision 1.11  2006/04/25 14:01:37  jim
01402 fixed bug in docs
01403 
01404 Revision 1.10  2006/04/25 13:45:56  jim
01405 Fixed to adhere to new calling sequence for vircam_dfs routines
01406 
01407 Revision 1.9  2006/04/20 11:32:10  jim
01408 Added new parameters to cull out over or under exposed images
01409 
01410 Revision 1.8  2006/03/23 21:18:45  jim
01411 Minor changes mainly to comment headers
01412 
01413 Revision 1.7  2006/03/22 14:02:51  jim
01414 cosmetic changes to keep lint happy
01415 
01416 Revision 1.6  2006/03/22 13:19:59  jim
01417 Added confidence map generation
01418 
01419 Revision 1.5  2006/03/22 12:13:51  jim
01420 Modified to use new vircam_mask capability
01421 
01422 Revision 1.4  2006/03/15 10:43:40  jim
01423 Fixed a few things
01424 
01425 Revision 1.3  2006/03/08 14:32:35  jim
01426 Lots of little mods
01427 
01428 Revision 1.2  2006/03/03 14:29:06  jim
01429 Now calls routines with vir_fits.
01430 
01431 Revision 1.1  2006/02/27 13:51:17  jim
01432 new routine
01433 
01434 
01435 */
01436 

Generated on 7 Feb 2011 for VIRCAM Pipeline by  doxygen 1.6.1