sinfo_utl_bp_mask_add.c

00001 /* $Id: sinfo_utl_bp_mask_add.c,v 1.18 2008/08/21 09:46:47 amodigli Exp $
00002  *
00003  * This file is part of the CPL (Common Pipeline Library)
00004  * Copyright (C) 2002 European Southern Observatory
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2008/08/21 09:46:47 $
00023  * $Revision: 1.18 $
00024  * $Name: sinfo-2_2_5 $
00025  */
00026 
00027  /****************************************************************
00028   *           Bad pixel search  (normal method)                  *
00029   ****************************************************************/
00030 
00031 /* --------------------------------------------------------------- 
00032                          INCLUDES
00033    --------------------------------------------------------------- */
00034 #ifdef HAVE_CONFIG_H
00035 #include <config.h>
00036 #endif
00037 
00038 /* std libraries */
00039 #include <strings.h>
00040 #include <string.h>
00041 #include <stdio.h>
00042 
00043 /* cpl */
00044 #include <cpl.h>     
00045 /* irplib */
00046 #include <irplib_utils.h>
00047 
00048 /* sinfoni */
00049 #include <sinfo_general_config.h>
00050 #include <sinfo_bp_norm_config.h>
00051 #include <sinfo_bp_lin_config.h>
00052 #include <sinfo_bp_noise_config.h>
00053 #include <sinfo_new_add_bp_map.h>
00054 #include <sinfo_tpl_utils.h>
00055 #include <sinfo_tpl_dfs.h>
00056 #include <sinfo_msg.h>
00057 #include <sinfo_error.h>
00058 #include <sinfo_utils_wrappers.h>
00059 
00060 /* --------------------------------------------------------------- 
00061                          DEFINES
00062    --------------------------------------------------------------- */
00063 /* --------------------------------------------------------------- 
00064                          FUNCTIONS PROTOTYPES
00065    --------------------------------------------------------------- */
00066 
00067 const char * sinfoni_get_licence(void);
00068 static int sinfo_utl_bp_mask_add_create(cpl_plugin *plugin);
00069 static int sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin);
00070 static int sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin);
00071 static int sinfo_utl_bp_mask_add(cpl_parameterlist *, cpl_frameset *);
00072 
00073 /* --------------------------------------------------------------- 
00074                          STATIC VARIABLES
00075    --------------------------------------------------------------- */
00076 
00077 static char sinfo_utl_bp_mask_add_description[] =
00078 "This recipe performs bad pixel map coaddition.\n"
00079 "The input files are several (at least 2)  bad pixel masks in the sof file\n"
00080 "Their tab should contain the string BP_MAP.\n"
00081 "The output is an image resulting from the logical operator OR \n"
00082 "applied to all the masks.\n"
00083 "Information on relevant parameters can be found with\n"
00084 "esorex --params sinfo_utl_bp_mask_add\n"
00085 "esorex --help sinfo_utl_bp_mask_add\n"
00086 "\n";
00087 
00088 
00089 /* --------------------------------------------------------------- 
00090                          FUNCTIONS CODE
00091    --------------------------------------------------------------- */
00092 
00093 /*---------------------------------------------------------------------------*/
00097 /*---------------------------------------------------------------------------*/
00099 /* --------------------------------------------------------------- */
00100 
00101 int
00102 cpl_plugin_get_info(cpl_pluginlist *list)
00103 {
00104 
00105   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00106   cpl_plugin *plugin = &recipe->interface;
00107 
00108 
00109   cpl_plugin_init(plugin,
00110           CPL_PLUGIN_API,
00111           SINFONI_BINARY_VERSION,
00112           CPL_PLUGIN_TYPE_RECIPE,
00113           "sinfo_utl_bp_mask_add",
00114           "Add bad pixels masks",
00115           sinfo_utl_bp_mask_add_description,
00116           "Andrea Modigliani",
00117           "Andrea.Modigliani@eso.org",
00118           sinfo_get_license(),
00119           sinfo_utl_bp_mask_add_create,
00120           sinfo_utl_bp_mask_add_exec,
00121           sinfo_utl_bp_mask_add_destroy);
00122 
00123   cpl_pluginlist_append(list, plugin);
00124 
00125   return 0;
00126 
00127 }
00128 
00129 /* --------------------------------------------------------------- */
00136 static int
00137 sinfo_utl_bp_mask_add_create(cpl_plugin *plugin)
00138 {
00139 
00140   /*
00141    * We have to provide the option we accept to the application.
00142    * We need to setup our parameter list and hook it into the recipe
00143    * interface.
00144    */
00145   cpl_recipe *recipe = (cpl_recipe *)plugin;
00146   recipe->parameters = cpl_parameterlist_new();
00147   if(recipe->parameters == NULL) {
00148     return 1;
00149   }
00150   cpl_error_reset();
00151   irplib_reset();
00152 
00153   /*
00154    * Fill the parameter list.
00155    */
00156 
00157 
00158   return 0;
00159 
00160 }
00161 
00162 /* --------------------------------------------------------------- */
00168 static int
00169 sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin)
00170 {
00171  
00172 
00173   cpl_recipe *recipe = (cpl_recipe *) plugin;
00174   cpl_errorstate initial_errorstate = cpl_errorstate_get();
00175   int code=0;
00176   
00177   if(recipe->parameters == NULL ) {
00178     return 1;
00179   }
00180   if(recipe->frames == NULL) {
00181     return 1;
00182   }
00183 
00184   check_nomsg(code=sinfo_utl_bp_mask_add(recipe->parameters, recipe->frames));
00185 
00186   if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
00187     /* Dump the error history since recipe execution start.                
00188        At this point the recipe cannot recover from the error */           
00189     cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
00190   } 
00191   cleanup:
00192 
00193   return code;
00194 
00195 }
00196 
00197 /* --------------------------------------------------------------- */
00204 static int
00205 sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin)
00206 {
00207   cpl_recipe *recipe = (cpl_recipe *) plugin;
00208   /*
00209    * We just destroy what was created during the plugin initializzation phase
00210    * i.e. the parameter list. The frame set is managed by the application which
00211    * called us, so that we must not touch it.
00212    */
00213 
00214   cpl_parameterlist_delete(recipe->parameters);
00215   return 0;
00216 
00217 }
00218 
00219 /*
00220  * The actual recipe actually start here.
00221  */
00222 
00223 
00224 /* --------------------------------------------------------------- */
00238 static int
00239 sinfo_utl_bp_mask_add(cpl_parameterlist *config, cpl_frameset *sof)
00240 {
00241   cpl_frameset* ref_set=NULL;
00242   int n=0;
00243   
00244   sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00245         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00246 
00247    if(sinfo_dfs_set_groups(sof)) {
00248        sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
00249    }
00250 
00251     n=cpl_frameset_get_size(sof);
00252     if(n<1) {
00253       sinfo_msg_error("Empty input frame list!");
00254       goto cleanup ;
00255     }
00256 
00257    check_nomsg(ref_set=cpl_frameset_duplicate(sof));
00258    ck0_nomsg(sinfo_new_add_bp_map(cpl_func,config,sof,ref_set));
00259 
00260  cleanup:
00261    sinfo_free_frameset(&ref_set);
00262   if (cpl_error_get_code() != CPL_ERROR_NONE) {
00263     return -1;
00264   } else {
00265     return 0;
00266   }
00267 
00268 
00269 
00270 }

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1