SINFONI Pipeline Reference Manual  2.5.2
sinfo_utl_bp_mask_add.c
1 /* $Id: sinfo_utl_bp_mask_add.c,v 1.18 2008-08-21 09:46:47 amodigli Exp $
2  *
3  * This file is part of the CPL (Common Pipeline Library)
4  * Copyright (C) 2002 European Southern Observatory
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 /*
21  * $Author: amodigli $
22  * $Date: 2008-08-21 09:46:47 $
23  * $Revision: 1.18 $
24  * $Name: not supported by cvs2svn $
25  */
26 
27 /****************************************************************
28  * Bad pixel search (normal method) *
29  ****************************************************************/
30 
31 /* ---------------------------------------------------------------
32  INCLUDES
33  --------------------------------------------------------------- */
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37 
38 /* std libraries */
39 #include <strings.h>
40 #include <string.h>
41 #include <stdio.h>
42 
43 /* cpl */
44 #include <cpl.h>
45 /* irplib */
46 #include <irplib_utils.h>
47 
48 /* sinfoni */
49 #include <sinfo_general_config.h>
50 #include <sinfo_bp_norm_config.h>
51 #include <sinfo_bp_lin_config.h>
52 #include <sinfo_bp_noise_config.h>
53 #include <sinfo_new_add_bp_map.h>
54 #include <sinfo_tpl_utils.h>
55 #include <sinfo_tpl_dfs.h>
56 #include <sinfo_msg.h>
57 #include <sinfo_error.h>
58 #include <sinfo_utils_wrappers.h>
59 
60 /* ---------------------------------------------------------------
61  DEFINES
62  --------------------------------------------------------------- */
63 /* ---------------------------------------------------------------
64  FUNCTIONS PROTOTYPES
65  --------------------------------------------------------------- */
66 
67 const char * sinfoni_get_licence(void);
68 static int sinfo_utl_bp_mask_add_create(cpl_plugin *plugin);
69 static int sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin);
70 static int sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin);
71 static int sinfo_utl_bp_mask_add(cpl_parameterlist *, cpl_frameset *);
72 
73 /* ---------------------------------------------------------------
74  STATIC VARIABLES
75  --------------------------------------------------------------- */
76 
77 static char sinfo_utl_bp_mask_add_description[] =
78  "This recipe performs bad pixel map coaddition.\n"
79  "The input files are several (at least 2) bad pixel masks in the sof file\n"
80  "Their tab should contain the string BP_MAP.\n"
81  "The output is an image resulting from the logical operator OR \n"
82  "applied to all the masks.\n"
83  "\n";
84 
85 
86 /* ---------------------------------------------------------------
87  FUNCTIONS CODE
88  --------------------------------------------------------------- */
89 
90 /*---------------------------------------------------------------------------*/
94 /*---------------------------------------------------------------------------*/
96 /* --------------------------------------------------------------- */
97 
98 int
99 cpl_plugin_get_info(cpl_pluginlist *list)
100 {
101 
102  cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
103  cpl_plugin *plugin = &recipe->interface;
104 
105 
106  cpl_plugin_init(plugin,
107  CPL_PLUGIN_API,
108  SINFONI_BINARY_VERSION,
109  CPL_PLUGIN_TYPE_RECIPE,
110  "sinfo_utl_bp_mask_add",
111  "Add bad pixels masks",
112  sinfo_utl_bp_mask_add_description,
113  "Andrea Modigliani",
114  "Andrea.Modigliani@eso.org",
115  sinfo_get_license(),
116  sinfo_utl_bp_mask_add_create,
117  sinfo_utl_bp_mask_add_exec,
118  sinfo_utl_bp_mask_add_destroy);
119 
120  cpl_pluginlist_append(list, plugin);
121 
122  return 0;
123 
124 }
125 
126 /* --------------------------------------------------------------- */
133 static int
134 sinfo_utl_bp_mask_add_create(cpl_plugin *plugin)
135 {
136 
137  /*
138  * We have to provide the option we accept to the application.
139  * We need to setup our parameter list and hook it into the recipe
140  * interface.
141  */
142  cpl_recipe *recipe = (cpl_recipe *)plugin;
143  recipe->parameters = cpl_parameterlist_new();
144  if(recipe->parameters == NULL) {
145  return 1;
146  }
147  cpl_error_reset();
148  irplib_reset();
149 
150  /*
151  * Fill the parameter list.
152  */
153 
154 
155  return 0;
156 
157 }
158 
159 /* --------------------------------------------------------------- */
165 static int
166 sinfo_utl_bp_mask_add_exec(cpl_plugin *plugin)
167 {
168 
169 
170  cpl_recipe *recipe = (cpl_recipe *) plugin;
171  cpl_errorstate initial_errorstate = cpl_errorstate_get();
172  int code=0;
173 
174  if(recipe->parameters == NULL ) {
175  return 1;
176  }
177  if(recipe->frames == NULL) {
178  return 1;
179  }
180 
181  check_nomsg(code=sinfo_utl_bp_mask_add(recipe->parameters, recipe->frames));
182 
183  if (!cpl_errorstate_is_equal(initial_errorstate)) {
184  /* Dump the error history since recipe execution start.
185  At this point the recipe cannot recover from the error */
186  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
187  }
188  cleanup:
189 
190  return code;
191 
192 }
193 
194 /* --------------------------------------------------------------- */
201 static int
202 sinfo_utl_bp_mask_add_destroy(cpl_plugin *plugin)
203 {
204  cpl_recipe *recipe = (cpl_recipe *) plugin;
205  /*
206  * We just destroy what was created during the plugin initializzation phase
207  * i.e. the parameter list. The frame set is managed by the application which
208  * called us, so that we must not touch it.
209  */
210 
211  cpl_parameterlist_delete(recipe->parameters);
212  return 0;
213 
214 }
215 
216 /*
217  * The actual recipe actually start here.
218  */
219 
220 
221 /* --------------------------------------------------------------- */
235 static int
236 sinfo_utl_bp_mask_add(cpl_parameterlist *config, cpl_frameset *sof)
237 {
238  cpl_frameset* ref_set=NULL;
239  int n=0;
240 
241  sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
242  SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
243 
244  if(sinfo_dfs_set_groups(sof)) {
245  sinfo_msg_error("Cannot indentify RAW and CALIB frames") ;
246  }
247 
248  n=cpl_frameset_get_size(sof);
249  if(n<1) {
250  sinfo_msg_error("Empty input frame list!");
251  goto cleanup ;
252  }
253 
254  check_nomsg(ref_set=cpl_frameset_duplicate(sof));
255  ck0_nomsg(sinfo_new_add_bp_map(cpl_func,config,sof,ref_set));
256 
257  cleanup:
258  sinfo_free_frameset(&ref_set);
259  if (cpl_error_get_code() != CPL_ERROR_NONE) {
260  return -1;
261  } else {
262  return 0;
263  }
264 
265 
266 
267 }