42 #include "gravi_utils.h" 43 #include "gravi_pfits.h" 44 #include "gravi_dfs.h" 45 #include "gravi_calib.h" 47 #include "gravi_data.h" 53 static int gravity_nab_create(cpl_plugin *);
54 static int gravity_nab_exec(cpl_plugin *);
55 static int gravity_nab_destroy(cpl_plugin *);
56 static int gravity_nab(cpl_frameset *,
const cpl_parameterlist *);
62 static char gravity_nab_short[] = GRAVI_UNOFFERED
"Calibrate the narrow angle baseline.";
63 static char gravity_nab_description[] = GRAVI_UNOFFERED
"This recipe computes the narrow angle baseline from a set of visibilities obtained on calibration stars. This is only used on DUAL mode." 64 "It is used in dual field mode\n" 65 GRAVI_RECIPE_INPUT
"\n" 66 GRAVI_VIS_DUAL_CALIB
" xN : visibilities on calibration stars\n" 67 GRAVI_RECIPE_OUTPUT
"\n" 68 GRAVI_NAB_CAL
" : model of narrow angle baseline\n" 86 int cpl_plugin_get_info(cpl_pluginlist * list)
88 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
89 cpl_plugin * plugin = &recipe->interface;
91 if (cpl_plugin_init(plugin,
94 CPL_PLUGIN_TYPE_RECIPE,
97 gravity_nab_description,
103 gravity_nab_destroy)) {
104 cpl_msg_error(cpl_func,
"Plugin initialization failed");
105 (void)cpl_error_set_where(cpl_func);
109 if (cpl_pluginlist_append(list, plugin)) {
110 cpl_msg_error(cpl_func,
"Error adding plugin to list");
111 (void)cpl_error_set_where(cpl_func);
127 static int gravity_nab_create(cpl_plugin * plugin)
132 if (cpl_error_get_code() != CPL_ERROR_NONE) {
133 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
134 cpl_func, __LINE__, cpl_error_get_where());
135 return (
int)cpl_error_get_code();
138 if (plugin == NULL) {
139 cpl_msg_error(cpl_func,
"Null plugin");
140 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
144 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
145 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
146 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
150 recipe = (cpl_recipe *)plugin;
153 recipe->parameters = cpl_parameterlist_new();
154 if (recipe->parameters == NULL) {
155 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
156 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
171 static int gravity_nab_exec(cpl_plugin * plugin)
176 cpl_errorstate initial_errorstate = cpl_errorstate_get();
179 if (cpl_error_get_code() != CPL_ERROR_NONE) {
180 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
181 cpl_func, __LINE__, cpl_error_get_where());
182 return (
int)cpl_error_get_code();
185 if (plugin == NULL) {
186 cpl_msg_error(cpl_func,
"Null plugin");
187 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
191 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
192 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
193 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
197 recipe = (cpl_recipe *)plugin;
200 if (recipe->parameters == NULL) {
201 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
202 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
204 if (recipe->frames == NULL) {
205 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
206 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
210 recipe_status = gravity_nab(recipe->frames, recipe->parameters);
213 if (cpl_dfs_update_product_header(recipe->frames)) {
214 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
217 if (!cpl_errorstate_is_equal(initial_errorstate)) {
220 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
223 return recipe_status;
233 static int gravity_nab_destroy(cpl_plugin * plugin)
237 if (plugin == NULL) {
238 cpl_msg_error(cpl_func,
"Null plugin");
239 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
243 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
244 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
245 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
249 recipe = (cpl_recipe *)plugin;
251 cpl_parameterlist_delete(recipe->parameters);
265 static int gravity_nab(cpl_frameset * frameset,
266 const cpl_parameterlist * parlist)
268 cpl_frameset * baseline_frameset = NULL;
272 gravi_data * raw_data, * baseline_data;
277 cpl_msg_set_time_on();
278 cpl_msg_set_component_on();
279 gravi_msg_function_start(1);
283 cpl_error_get_code()) ;
286 baseline_frameset = gravi_frameset_extract_vis_calib (frameset);
287 if (cpl_frameset_is_empty (baseline_frameset)) {
288 return (
int)cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
296 nb_frame = cpl_frameset_get_size (baseline_frameset);
297 for (comp = 0; comp < nb_frame; comp++){
299 cpl_msg_info (cpl_func,
"*** Loop on file %i over %i ***", comp, nb_frame);
301 frame = cpl_frameset_get_position (baseline_frameset, comp);
304 baseline_data = gravi_compute_baseline (raw_data);
308 NULL, frame,
"gravity_nab",
309 NULL, GRAVI_NAB_CAL);
311 CPLCHECK_CLEAN (
"Cannot save the NAB_CAL");
319 cpl_msg_info(cpl_func,
"Memory cleanup");
321 gravi_msg_function_exit(1);
322 return (
int)cpl_error_get_code();
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.