45 #include "gravi_data.h" 46 #include "gravi_pfits.h" 47 #include "gravi_dfs.h" 49 #include "gravi_utils.h" 51 #include "gravi_calib.h" 52 #include "gravi_p2vmred.h" 53 #include "gravi_eop.h" 54 #include "gravi_metrology.h" 56 #include "gravi_signal.h" 57 #include "gravi_vis.h" 60 #include "gravi_preproc.h" 67 static int gravity_piezo_create(cpl_plugin *);
68 static int gravity_piezo_exec(cpl_plugin *);
69 static int gravity_piezo_destroy(cpl_plugin *);
70 static int gravity_piezo(cpl_frameset *,
const cpl_parameterlist *);
76 static char gravity_piezo_short[] =
"Calibrate the response of the piezo actuators.";
77 static char gravity_piezo_description[] =
"This recipe compute the response (open loop transfer function) of the piezo actuators used to fringe-track in GRAVITY.\n" 79 "* Compute the piezo TF QC parameter" 81 GRAVI_RECIPE_INPUT
"\n" 82 GRAVI_PIEZOTF_RAW
" : dedicated observations (DPR.CATG=PIEZOTF)\n" 83 GRAVI_RECIPE_OUTPUT
"\n" 84 GRAVI_PIEZOTF_MAP
" : Response of the piezo\n" 102 int cpl_plugin_get_info(cpl_pluginlist * list)
104 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
105 cpl_plugin * plugin = &recipe->interface;
107 if (cpl_plugin_init(plugin,
109 GRAVI_BINARY_VERSION,
110 CPL_PLUGIN_TYPE_RECIPE,
113 gravity_piezo_description,
114 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
117 gravity_piezo_create,
119 gravity_piezo_destroy)) {
120 cpl_msg_error(cpl_func,
"Plugin initialization failed");
121 (void)cpl_error_set_where(cpl_func);
125 if (cpl_pluginlist_append(list, plugin)) {
126 cpl_msg_error(cpl_func,
"Error adding plugin to list");
127 (void)cpl_error_set_where(cpl_func);
143 static int gravity_piezo_create(cpl_plugin * plugin)
149 if (cpl_error_get_code() != CPL_ERROR_NONE) {
150 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
151 cpl_func, __LINE__, cpl_error_get_where());
152 return (
int)cpl_error_get_code();
155 if (plugin == NULL) {
156 cpl_msg_error(cpl_func,
"Null plugin");
157 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
161 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
162 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
163 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
167 recipe = (cpl_recipe *)plugin;
170 recipe->parameters = cpl_parameterlist_new();
171 if (recipe->parameters == NULL) {
172 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
173 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
180 gravi_parameter_add_static_name (recipe->parameters);
192 static int gravity_piezo_exec(cpl_plugin * plugin)
197 cpl_errorstate initial_errorstate = cpl_errorstate_get();
201 if (cpl_error_get_code() != CPL_ERROR_NONE) {
202 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
203 cpl_func, __LINE__, cpl_error_get_where());
204 return (
int)cpl_error_get_code();
207 if (plugin == NULL) {
208 cpl_msg_error(cpl_func,
"Null plugin");
209 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
213 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
214 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
215 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
219 recipe = (cpl_recipe *)plugin;
222 if (recipe->parameters == NULL) {
223 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
224 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
226 if (recipe->frames == NULL) {
227 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
228 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
232 recipe_status = gravity_piezo(recipe->frames, recipe->parameters);
235 if (cpl_dfs_update_product_header(recipe->frames)) {
237 recipe_status = (int)cpl_error_get_code();
241 if (!cpl_errorstate_is_equal(initial_errorstate)) {
244 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
247 return recipe_status;
257 static int gravity_piezo_destroy(cpl_plugin * plugin)
261 if (plugin == NULL) {
262 cpl_msg_error(cpl_func,
"Null plugin");
263 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
267 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
268 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
269 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
273 recipe = (cpl_recipe *)plugin;
275 cpl_parameterlist_delete(recipe->parameters);
290 static int gravity_piezo(cpl_frameset * frameset,
291 const cpl_parameterlist * parlist)
293 cpl_frameset * recipe_frameset=NULL, *used_frameset=NULL, * current_frameset=NULL;
295 cpl_frame * frame=NULL;
297 gravi_data * data=NULL, * piezo_data=NULL;
302 gravity_print_banner ();
303 cpl_msg_set_time_on();
304 cpl_msg_set_component_on();
305 gravi_msg_function_start(1);
309 cpl_error_get_code()) ;
312 recipe_frameset = gravi_frameset_extract_piezotf_data (frameset);
315 if (cpl_frameset_is_empty (recipe_frameset)) {
316 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
317 "No PIEZOTF file on the frameset") ;
323 used_frameset = cpl_frameset_new();
330 nb_frame = cpl_frameset_get_size (recipe_frameset);
332 for (
int i_file = 0; i_file < nb_frame; i_file++){
333 current_frameset = cpl_frameset_duplicate (used_frameset);
335 cpl_msg_info (cpl_func,
" ***** File %d over %d ***** ", i_file+1, nb_frame);
341 frame = cpl_frameset_get_position (recipe_frameset, i_file);
344 CPLCHECK_CLEAN (
"Cannot compute the piezo TF");
348 current_frameset, frame,
"gravity_piezo",
349 NULL, GRAVI_PIEZOTF_MAP);
351 CPLCHECK_CLEAN (
"Cannot save the PIEZOTF product");
353 cpl_msg_info (cpl_func,
"Free the piezotf");
354 FREE (cpl_frameset_delete, current_frameset);
364 cpl_msg_info(cpl_func,
"Memory cleanup");
368 FREE (cpl_frameset_delete,recipe_frameset);
369 FREE (cpl_frameset_delete,current_frameset);
370 FREE (cpl_frameset_delete,used_frameset);
372 gravi_msg_function_exit(1);
373 return (
int)cpl_error_get_code();
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW 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.
gravi_data * gravi_compute_piezotf(gravi_data *data, const cpl_parameterlist *params)
Create piezo transfer function for Kalman Calibration & monitoring.
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.