VISIR Pipeline Reference Manual  4.1.7
visir_util_join.c
1 /* $Id: visir_util_join.c,v 1.13 2013-05-13 16:03:43 jtaylor Exp $
2  *
3  * This file is part of the VISIR Pipeline
4  * Copyright (C) 2011 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jtaylor $
23  * $Date: 2013-05-13 16:03:43 $
24  * $Revision: 1.13 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include "visir_recipe.h"
37 #include <string.h>
38 
39 /*-----------------------------------------------------------------------------
40  Defines
41  -----------------------------------------------------------------------------*/
42 
43 #define RECIPE_STRING "visir_util_join"
44 
45 /*-----------------------------------------------------------------------------
46  Private Functions prototypes
47  -----------------------------------------------------------------------------*/
48 
49 static
50 cpl_error_code visir_util_join_one(cpl_frameset *,
51  const irplib_framelist *,
52  const irplib_framelist *,
53  const irplib_framelist *,
54  const irplib_framelist *,
55  const irplib_framelist *,
56  const irplib_framelist *,
57  int, cpl_boolean, cpl_boolean,
58  cpl_boolean, cpl_boolean,
59  cpl_boolean,
60  const cpl_parameterlist *);
61 
62 #ifdef VISIR_CHAIN
63 #define cpl_plugin_get_info visir_util_join_get_info
64 #endif
65 VISIR_RECIPE_DEFINE(visir_util_join, 0,
66  "Extend the final product with extensions containing its "
67  "error map, bad pixel map and weight or contribution map",
68  "The files listed in the Set Of Frames (SOF-file) "
69  "must be tagged:\n"
70  "VISIR-data.fits " VISIR_UTIL_DATA "\n"
71  "\nOptionally, the SOF may also contain one or more of "
72  "the following:\n"
73  "VISIR-bad-pixel-map.fits " VISIR_CALIB_BPM "\n"
74  "VISIR-error.fits " VISIR_UTIL_WEIGHT2ERROR_PROCATG
75  "\n"
76  "VISIR-contribution-map.fits " VISIR_IMG_CLIPPED_MAP_PROCATG
77  "\n"
78  "VISIR-weight-map.fits " VISIR_UTIL_WEIGHT2ERROR
79  "\n"
80  "\nThe product(s) will have a FITS card\n"
81  "'HIERARCH " CPL_DFS_PRO_CATG "' with a value of:\n"
82  VISIR_UTIL_JOIN_PROCATG);
83 
84 /*----------------------------------------------------------------------------*/
88 /*----------------------------------------------------------------------------*/
89 
90 /*-----------------------------------------------------------------------------
91  Functions code
92  -----------------------------------------------------------------------------*/
93 
94 /*----------------------------------------------------------------------------*/
101 /*----------------------------------------------------------------------------*/
102 static int visir_util_join(cpl_frameset * framelist,
103  const cpl_parameterlist * parlist)
104 {
105  irplib_framelist * allframes = NULL;
106  irplib_framelist * rawframes = NULL;
107  irplib_framelist * bpmframes = NULL;
108  irplib_framelist * errframes = NULL;
109  irplib_framelist * conframes = NULL;
110  irplib_framelist * wgtframes = NULL;
111  irplib_framelist * qcframes = NULL;
112  int n;
113  int nbad = 0, nerr = 0, ncon = 0, nwgt = 0, nqc = 0;
114 
115 
116  /* Identify the RAW and TAB frames in the input frameset */
117  skip_if (visir_dfs_set_groups(framelist));
118  FOR_EACH_FRAMESET(frm, framelist)
119  cpl_frame_set_group(frm, CPL_FRAME_GROUP_RAW);
120 
121  /* Objects observation */
122  allframes = irplib_framelist_cast(framelist);
123  skip_if(allframes == NULL);
124 
125  rawframes =
126  irplib_framelist_extract_regexp(allframes, "^("
127  VISIR_UTIL_DATA
128  "|" VISIR_IMG_PHOT_ONEBEAM_PROCATG
129  "|" VISIR_IMG_PHOT_COMBINED_PROCATG
130  "|COADDED_IMAGE"
131  "|COADDED_IMAGE_COMBINED"
132  ")$",
133  CPL_FALSE);
134 
135  skip_if(rawframes == NULL);
136 
137  n = irplib_framelist_get_size(rawframes);
138 
139  if (cpl_frameset_find_const(framelist, VISIR_CALIB_BPM)) {
140  bpmframes = irplib_framelist_extract(allframes, VISIR_CALIB_BPM);
141  skip_if (bpmframes == NULL);
142 
143  nbad = irplib_framelist_get_size(bpmframes);
144  error_if(nbad != n && nbad != 1, CPL_ERROR_INCOMPATIBLE_INPUT,
145  "%d raw-frames <=> %d bpm frames", n, nbad);
146  }
147 
148  if (cpl_frameset_find_const(framelist, VISIR_UTIL_ERROR_MAP_PROCATG)) {
149  errframes = irplib_framelist_extract(allframes,
150  VISIR_UTIL_ERROR_MAP_PROCATG);
151  skip_if (errframes == NULL);
152 
153  nerr = irplib_framelist_get_size(errframes);
154  error_if(nerr != n && nerr != 1, CPL_ERROR_INCOMPATIBLE_INPUT,
155  "%d raw-frames <=> %d error frames", n, nerr);
156 
157  }
158 
159  if (cpl_frameset_find_const(framelist, VISIR_IMG_CLIPPED_MAP_PROCATG)) {
160  conframes = irplib_framelist_extract(allframes,
161  VISIR_IMG_CLIPPED_MAP_PROCATG);
162  skip_if (conframes == NULL);
163 
164  ncon = irplib_framelist_get_size(conframes);
165  error_if(ncon % n != 0 && ncon != 1, CPL_ERROR_INCOMPATIBLE_INPUT,
166  "%d raw-frames <=> %d contribution frames", n, ncon);
167  }
168 
169  if (cpl_frameset_find_const(framelist, VISIR_UTIL_WEIGHT_MAP_PROCATG)) {
170  wgtframes = irplib_framelist_extract(allframes,
171  VISIR_UTIL_WEIGHT_MAP_PROCATG);
172  skip_if (wgtframes == NULL);
173 
174  nwgt = irplib_framelist_get_size(wgtframes);
175  error_if(nwgt != n && nwgt != 1, CPL_ERROR_INCOMPATIBLE_INPUT,
176  "%d raw-frames <=> %d weight frames", n, nwgt);
177  }
178 
179  if (cpl_frameset_find_const(framelist, VISIR_UTIL_QC_PROCATG)) {
180  qcframes = irplib_framelist_extract(allframes, VISIR_UTIL_QC_PROCATG);
181  skip_if (qcframes == NULL);
182 
183  nqc = irplib_framelist_get_size(qcframes);
184  error_if(nqc != n && nqc != 1, CPL_ERROR_INCOMPATIBLE_INPUT,
185  "%d raw-frames <=> %d qc frames", n, nqc);
186  }
187 
188  for (int i = 0; i < n; i++) {
189  cpl_msg_info(cpl_func, "Joining frame %d/%d", 1+i, n);
190 
191  skip_if (visir_util_join_one(framelist, rawframes, bpmframes, errframes,
192  conframes, wgtframes, qcframes, i, nbad == 1,
193  nerr == 1, ncon == 1, nwgt == 1, nqc == 1,
194  parlist));
195  }
196 
197  end_skip;
198 
199  irplib_framelist_delete(allframes);
200  irplib_framelist_delete(rawframes);
201  irplib_framelist_delete(bpmframes);
202  irplib_framelist_delete(errframes);
203  irplib_framelist_delete(conframes);
204  irplib_framelist_delete(wgtframes);
205  irplib_framelist_delete(qcframes);
206 
207  return cpl_error_get_code();
208 }
209 
210 
211 /*----------------------------------------------------------------------------*/
230 /*----------------------------------------------------------------------------*/
231 static
232 cpl_error_code visir_util_join_one(cpl_frameset * framelist,
233  const irplib_framelist * rawframes,
234  const irplib_framelist * bpmframes,
235  const irplib_framelist * errframes,
236  const irplib_framelist * conframes,
237  const irplib_framelist * wgtframes,
238  const irplib_framelist * qcframes,
239  int i,
240  cpl_boolean bshared, cpl_boolean eshared,
241  cpl_boolean cshared, cpl_boolean wshared,
242  cpl_boolean qcshared,
243  const cpl_parameterlist * parlist)
244 {
245 
246  const int n = irplib_framelist_get_size(rawframes);
247  const cpl_frame * frame;
248  cpl_frameset * products = cpl_frameset_new();
249  cpl_frameset * usedframes = cpl_frameset_new();
250  const char * filename;
251  cpl_propertylist * img_plist = NULL;
252  char * proname = NULL;
253  cpl_image * img = NULL;
254  cpl_image * csum = NULL;
255  const char * bunit = NULL;
256  char * inpcatg = NULL;
257 
258  cpl_image * bpm = NULL;
259  cpl_image * err = NULL;
260  cpl_image * wgt = NULL;
261  cpl_image * con = NULL;
262 
263  cpl_propertylist * bpm_plist = NULL;
264  cpl_propertylist * err_plist = NULL;
265  cpl_propertylist * wgt_plist = NULL;
266  cpl_propertylist * con_plist = NULL;
267  cpl_propertylist * qc_plist = NULL;
268 
269  const char * procatg = VISIR_UTIL_JOIN_PROCATG;
270 
271  bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate
272  (irplib_framelist_get_const(rawframes, i))));
273 
274  /* 1) The data frame */
275  frame = irplib_framelist_get_const(rawframes, i);
276  filename = cpl_frame_get_filename(frame);
277 
278  img_plist = cpl_propertylist_load(filename, 0);
279  skip_if(img_plist == NULL);
280 
281  img = cpl_image_load(filename, CPL_TYPE_UNSPECIFIED, 0, 0);
282  skip_if(img == NULL);
283 
284  if (qcframes) {
285  frame = irplib_framelist_get_const(qcframes, qcshared ? 0 : i);
286  filename = cpl_frame_get_filename(frame);
287  qc_plist = cpl_propertylist_load_regexp(filename, 0,
288  "ESO QC |BUNIT|ESO DRS CATG", CPL_FALSE);
289  skip_if (qc_plist == NULL);
290  if (cpl_propertylist_has(qc_plist, "BUNIT")) {
291  bunit = cpl_propertylist_get_string(qc_plist, "BUNIT");
292  }
293  if (cpl_propertylist_has(qc_plist, "ESO DRS CATG")) {
294  inpcatg =
295  cpl_strdup(cpl_propertylist_get_string(qc_plist, "ESO DRS CATG"));
296  cpl_propertylist_erase(qc_plist, "ESO DRS CATG");
297  }
298  }
299 
300  if (bunit == NULL && cpl_propertylist_has(img_plist, "BUNIT")) {
301  bunit = cpl_propertylist_get_string(img_plist, "BUNIT");
302  }
303  if (inpcatg == NULL && cpl_propertylist_has(img_plist, "ESO DRS CATG")) {
304  inpcatg =
305  cpl_strdup(cpl_propertylist_get_string(img_plist, "ESO DRS CATG"));
306  cpl_propertylist_erase(img_plist, "ESO DRS CATG");
307  }
308  cpl_propertylist_append(img_plist, qc_plist);
309 
310  if (!strcmp(cpl_frame_get_tag(frame), VISIR_IMG_PHOT_ONEBEAM_PROCATG))
311  procatg = VISIR_IMG_PHOT_ONEBEAM_PROCATG;
312  else if (!strcmp(cpl_frame_get_tag(frame), VISIR_IMG_PHOT_COMBINED_PROCATG))
313  procatg = VISIR_IMG_PHOT_COMBINED_PROCATG;
314  else if (!strcmp(cpl_frame_get_tag(frame), "COADDED_IMAGE_COMBINED"))
315  procatg = VISIR_IMG_OBJ_COMBINED_PROCATG;
316  else if (!strcmp(cpl_frame_get_tag(frame), "COADDED_IMAGE"))
317  procatg = VISIR_IMG_OBJ_ONEBEAM_PROCATG;
318 
319  procatg = visir_dfs_output_catg(inpcatg, procatg);
320 
321  if (cpl_propertylist_has(img_plist, "ESO QC BEAMID")) {
322  const char * b = cpl_propertylist_get_string(img_plist,
323  "ESO QC BEAMID");
324  proname = cpl_sprintf(RECIPE_STRING "_b%s_%03d"
325  CPL_DFS_FITS, b, 1+i);
326  }
327  else
328  proname = cpl_sprintf(RECIPE_STRING "_%03d"
329  CPL_DFS_FITS, 1+i);
330 
331  if (bpmframes != NULL) {
332  /* 3) The bpm frame */
333  frame = irplib_framelist_get_const(bpmframes, bshared ? 0 : i);
334 
335  filename = cpl_frame_get_filename(frame);
336 
337  bpm = cpl_image_load(filename, CPL_TYPE_INT, 0, 0);
338  skip_if(bpm == NULL);
339 
340  bpm_plist = cpl_propertylist_load_regexp(filename, 0, " ESO QC | ESO PRO ",
341  0);
342  skip_if(bpm_plist == NULL);
343  cpl_propertylist_append_string(bpm_plist, "EXTNAME", VISIR_EXTN_BPM);
344  }
345 
346  if (errframes != NULL) {
347  /* 3) The error frame */
348 
349  frame = irplib_framelist_get_const(errframes, eshared ? 0 : i);
350 
351  filename = cpl_frame_get_filename(frame);
352 
353  err = cpl_image_load(filename, CPL_TYPE_UNSPECIFIED, 0, 0);
354  skip_if(err == NULL);
355 
356  err_plist = cpl_propertylist_load_regexp(filename, 0, " ESO QC | ESO PRO ",
357  0);
358  skip_if(err_plist == NULL);
359  cpl_propertylist_append_string(err_plist, "EXTNAME", VISIR_EXTN_ERROR);
360  if (bunit) {
361  cpl_propertylist_append_string(err_plist, "BUNIT", bunit);
362  }
363 
364  if (wgtframes == NULL) {
365  wgt = cpl_image_new(cpl_image_get_size_x(err),
366  cpl_image_get_size_y(err),
367  CPL_TYPE_FLOAT);
368  cpl_image_add_scalar(wgt, 1.0);
369  cpl_image_divide(wgt, err);
370  cpl_image_power(wgt, 2);
371  wgt_plist = cpl_propertylist_new();
372  cpl_propertylist_append_string(wgt_plist, "EXTNAME", VISIR_EXTN_WEIGHT);
373  skip_if(0);
374  }
375 
376  }
377 
378  if (conframes != NULL) {
379  /* 4) The contribution frame(s) */
380 
381  if (cshared || irplib_framelist_get_size(conframes) == n) {
382 
383  frame = irplib_framelist_get_const(conframes, cshared ? 0 : i);
384 
385  filename = cpl_frame_get_filename(frame);
386 
387  con = cpl_image_load(filename, CPL_TYPE_INT, 0, 0);
388  skip_if(con == NULL);
389 
390  con_plist = cpl_propertylist_load_regexp(filename, 0, " ESO QC | ESO PRO ",
391  0);
392  skip_if(con_plist == NULL);
393 
394  } else {
395 
396  const int ncon = irplib_framelist_get_size(conframes);
397  const int nz = ncon / n;
398  int j;
399 
400  for (j = i * nz; j < i * nz + nz; j ++) {
401  frame = irplib_framelist_get_const(conframes, j);
402  bug_if(cpl_frameset_insert(usedframes,
403  cpl_frame_duplicate(frame)));
404 
405  filename = cpl_frame_get_filename(frame);
406 
407  if (j == i * nz) {
408 
409  con = cpl_image_load(filename, CPL_TYPE_INT, 0, 0);
410  skip_if(con == NULL);
411 
412  } else {
413  csum = cpl_image_load(filename, CPL_TYPE_INT, 0, 0);
414  skip_if(csum == NULL);
415  skip_if(cpl_image_add(con, csum));
416  }
417  }
418 
419  }
420 
421  if (bpm == NULL) {
422  bpm = cpl_image_duplicate(con);
423 
424  /* FIXME: Find a better way to create a image BPM */
425  bug_if(cpl_image_threshold(bpm, -0.5, 1.0, 0.5, 1.0));
426  bug_if(cpl_image_multiply_scalar(bpm, -1.0));
427  bug_if(cpl_image_add_scalar(bpm, 1.0));
428 
429  bpm_plist = cpl_propertylist_new();
430  cpl_propertylist_append_string(bpm_plist, "EXTNAME", VISIR_EXTN_BPM);
431  }
432  }
433 
434 
435  if (wgtframes != NULL) {
436  /* 5) The weight frame */
437 
438  frame = irplib_framelist_get_const(wgtframes, wshared ? 0 : i);
439 
440  filename = cpl_frame_get_filename(frame);
441 
442  wgt_plist = cpl_propertylist_load_regexp(filename, 0, " ESO QC | ESO PRO ",
443  0);
444  skip_if(wgt_plist == NULL);
445 
446  bug_if(cpl_propertylist_append_string(wgt_plist, "EXTNAME", VISIR_EXTN_WEIGHT));
447 
448  wgt = cpl_image_load(filename, CPL_TYPE_FLOAT, 0, 0);
449  skip_if(wgt == NULL);
450 
451  if (err == NULL) {
452  err = cpl_image_new(cpl_image_get_size_x(wgt),
453  cpl_image_get_size_y(wgt), CPL_TYPE_FLOAT);
454  cpl_image_add_scalar(err, 1.0);
455  cpl_image_divide(err, wgt);
456  cpl_image_power(err, 0.5);
457  cpl_image_fill_rejected(err, INFINITY);
458  err_plist = cpl_propertylist_new();
459  cpl_propertylist_append_string(err_plist, "EXTNAME", VISIR_EXTN_ERROR);
460  if (bunit) {
461  cpl_propertylist_append_string(err_plist, "BUNIT", bunit);
462  }
463  skip_if(0);
464  }
465 
466  }
467 
468  if (err != NULL && con == NULL && bpm == NULL) {
469 
470  /* FIXME: Find a better way to create a image BPM */
471  cpl_mask * mbpm = cpl_mask_threshold_image_create(err, -DBL_EPSILON, 1e8);
472  cpl_mask_not(mbpm);
473  bpm = cpl_image_new_from_mask(mbpm);
474  cpl_mask_delete(mbpm);
475 
476  bpm_plist = cpl_propertylist_new();
477  cpl_propertylist_append_string(bpm_plist, "EXTNAME", VISIR_EXTN_BPM);
478  }
479  skip_if(0);
480 
481  /* try to compute gauss fwhm also for science images, may fail (PIPE-6158) */
482  if (!cpl_propertylist_has(img_plist, "ESO QC GAUSSFIT FWHM_MAX")) {
483  cpl_errorstate cleanstate = cpl_errorstate_get();
484  double fwhm_x = -1., fwhm_y = -1.,
485  peak = -1., peak_err = 0.,
486  major = -1., major_err = 0.,
487  minor = -1., minor_err = 0.,
488  angle = -1., angle_err = 0.;
489  cpl_size x_pos = cpl_propertylist_get_double(img_plist, "CRPIX1");
490  cpl_size y_pos = cpl_propertylist_get_double(img_plist, "CRPIX2");
491  cpl_image * lwgt = wgt;
492 
493  /* Compute the FWHM */
494  cpl_image_get_fwhm(img, (int)x_pos, (int)y_pos, &fwhm_x, &fwhm_y);
495 
496  if (lwgt == NULL) {
497  lwgt = cpl_image_new(cpl_image_get_size_x(img), cpl_image_get_size_y(img), CPL_TYPE_DOUBLE);
498  cpl_image_add_scalar(lwgt, 1);
499  }
500  if (fit_2d_gauss(img, lwgt, (cpl_size)x_pos, (cpl_size)y_pos,
501  fwhm_x, fwhm_y, &peak, &peak_err,
502  &major, &major_err, &minor, &minor_err,
503  &angle, &angle_err) == CPL_ERROR_NONE) {
504  cpl_msg_info(cpl_func, "Peak: %g +- %g, FWHM : %g +- %g major ; %g +- %g minor, "
505  "angle %g +- %g", peak, peak_err,
506  major, major_err, minor, minor_err,
507  angle * CPL_MATH_DEG_RAD,
508  angle_err * CPL_MATH_DEG_RAD);
509  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT FWHM_MAX",
510  major);
511  cpl_propertylist_set_comment(img_plist, "ESO QC GAUSSFIT FWHM_MAX",
512  "major axis [pix]");
513  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT FWHM_MAX_ERR",
514  major_err);
515  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT FWHM_MIN",
516  minor);
517  cpl_propertylist_set_comment(img_plist, "ESO QC GAUSSFIT FWHM_MIN",
518  "minor axis [pix]");
519  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT FWHM_MIN_ERR",
520  minor_err);
521  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT ANGLE",
522  angle * CPL_MATH_DEG_RAD);
523  cpl_propertylist_set_comment(img_plist, "ESO QC GAUSSFIT ANGLE",
524  "[deg]");
525  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT ANGLE_ERR",
526  angle_err * CPL_MATH_DEG_RAD);
527  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT PEAK",
528  peak);
529  cpl_propertylist_append_double(img_plist, "ESO QC GAUSSFIT PEAK_ERR",
530  peak_err);
531  }
532  else {
533  cpl_msg_warning(cpl_func, "2D gauss fit failed, approximate FWHM : %g"
534  "in x ; %g in y ", fwhm_x, fwhm_y);
535  }
536 
537  if (lwgt != wgt) {
538  cpl_image_delete(lwgt);
539  }
540  /* ignore all errors */
541  cpl_errorstate_set(cleanstate);
542  }
543 
544  skip_if(irplib_dfs_save_image(products, parlist, usedframes,
545  img, CPL_TYPE_UNSPECIFIED,
546  RECIPE_STRING,
547  procatg, img_plist,
548  NULL, visir_pipe_id, proname));
549 
550  if (bpm) {
551  if (bpmframes) {
552  frame = irplib_framelist_get_const(bpmframes, bshared ? 0 : i);
553  bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate(frame)));
554  }
555  skip_if(cpl_image_save(bpm, proname, CPL_BPP_8_UNSIGNED,
556  bpm_plist, CPL_IO_EXTEND));
557  }
558  if (err) {
559  if (errframes) {
560  frame = irplib_framelist_get_const(errframes, eshared ? 0 : i);
561  bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate(frame)));
562  }
563  skip_if(cpl_image_save(err, proname, CPL_TYPE_UNSPECIFIED,
564  err_plist, CPL_IO_EXTEND));
565  }
566  if (con) {
567  if (conframes) {
568  frame = irplib_framelist_get_const(conframes, cshared ? 0 : i);
569  bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate(frame)));
570  }
571  skip_if(cpl_image_save(con, proname, CPL_TYPE_UNSPECIFIED,
572  con_plist, CPL_IO_EXTEND));
573  }
574  if (wgt) {
575  if (wgtframes) {
576  frame = irplib_framelist_get_const(wgtframes, wshared ? 0 : i);
577  bug_if(cpl_frameset_insert(usedframes, cpl_frame_duplicate(frame)));
578  }
579  skip_if(cpl_image_save(wgt, proname, CPL_TYPE_UNSPECIFIED,
580  wgt_plist, CPL_IO_EXTEND));
581  }
582 
583  FOR_EACH_FRAMESET_C(frm, products) {
584  cpl_frame * copy = cpl_frame_duplicate(frm);
585  cpl_error_code error = cpl_frameset_insert(framelist, copy);
586 
587  if (error) break;
588  }
589 
590  end_skip;
591 
592  cpl_image_delete(img);
593  cpl_image_delete(err);
594  cpl_image_delete(wgt);
595  cpl_image_delete(con);
596  cpl_image_delete(bpm);
597  cpl_image_delete(csum);
598  cpl_free(proname);
599  cpl_free(inpcatg);
600  cpl_propertylist_delete(img_plist);
601  cpl_propertylist_delete(err_plist);
602  cpl_propertylist_delete(wgt_plist);
603  cpl_propertylist_delete(con_plist);
604  cpl_propertylist_delete(bpm_plist);
605  cpl_propertylist_delete(qc_plist);
606  cpl_frameset_delete(usedframes);
607  cpl_frameset_delete(products);
608 
609  return cpl_error_get_code();
610 }
irplib_framelist * irplib_framelist_extract_regexp(const irplib_framelist *self, const char *regexp, cpl_boolean invert)
Extract the frames with the given tag from a framelist.
cpl_error_code irplib_dfs_save_image(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_image *image, cpl_type_bpp bpp, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save an image as a DFS-compliant pipeline product.
Definition: irplib_utils.c:192
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: visir_dfs.c:72
const cpl_frame * irplib_framelist_get_const(const irplib_framelist *self, int pos)
Get the specified frame from the framelist.
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.