IIINSTRUMENT Pipeline Reference Manual  6.2.2
isaac_img_dark.c
1 /* $Id: isaac_img_dark.c,v 1.38 2013-03-12 08:06:48 llundin Exp $
2  *
3  * This file is part of the ISAAC Pipeline
4  * Copyright (C) 2002,2003 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: llundin $
23  * $Date: 2013-03-12 08:06:48 $
24  * $Revision: 1.38 $
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 <cpl.h>
37 #include <math.h>
38 
39 #include "irplib_utils.h"
40 
41 #include "isaac_utils.h"
42 #include "isaac_pfits.h"
43 #include "isaac_dfs.h"
44 
45 /*-----------------------------------------------------------------------------
46  Define
47  -----------------------------------------------------------------------------*/
48 
49 #define ISAAC_DARK_HSIZE_SW_DEF 6
50 #define ISAAC_DARK_HSIZE_LW_DEF 2
51 
52 /*-----------------------------------------------------------------------------
53  Functions prototypes
54  -----------------------------------------------------------------------------*/
55 
56 static int isaac_img_dark_create(cpl_plugin *);
57 static int isaac_img_dark_exec(cpl_plugin *);
58 static int isaac_img_dark_destroy(cpl_plugin *);
59 static int isaac_img_dark(cpl_parameterlist *, cpl_frameset *);
60 
61 static int isaac_img_dark_avg_reduce(cpl_frameset *, cpl_image **);
62 static cpl_matrix * isaac_img_dark_ron_reduce(cpl_frameset *);
63 static int isaac_img_dark_compare(const cpl_frame *, const cpl_frame *);
64 static int isaac_img_dark_save(cpl_image *, cpl_matrix *, int, cpl_frameset *,
65  cpl_parameterlist *, cpl_frameset *);
66 
67 /*-----------------------------------------------------------------------------
68  Static variables
69  -----------------------------------------------------------------------------*/
70 
71 static struct {
72  /* Inputs */
73  int hsize;
74  int nsamples;
75  /* Outputs */
76  double dark_med;
77  double dark_stdev;
78 } isaac_img_dark_config;
79 
80 static char isaac_img_dark_description[] =
81 "isaac_img_dark -- ISAAC imaging dark recipe.\n"
82 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
83 "raw-file.fits "ISAAC_IMG_DARK_RAW"\n";
84 
85 /*-----------------------------------------------------------------------------
86  Functions code
87  -----------------------------------------------------------------------------*/
88 
89 /*----------------------------------------------------------------------------*/
97 /*----------------------------------------------------------------------------*/
98 int cpl_plugin_get_info(cpl_pluginlist * list)
99 {
100  cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe));
101  cpl_plugin * plugin = &recipe->interface;
102 
103  cpl_plugin_init(plugin,
104  CPL_PLUGIN_API,
105  ISAAC_BINARY_VERSION,
106  CPL_PLUGIN_TYPE_RECIPE,
107  "isaac_img_dark",
108  "Dark recipe",
109  isaac_img_dark_description,
110  "Lars Lundin",
111  PACKAGE_BUGREPORT,
113  isaac_img_dark_create,
114  isaac_img_dark_exec,
115  isaac_img_dark_destroy);
116 
117  cpl_pluginlist_append(list, plugin);
118 
119  return 0;
120 }
121 
122 /*----------------------------------------------------------------------------*/
131 /*----------------------------------------------------------------------------*/
132 static int isaac_img_dark_create(cpl_plugin * plugin)
133 {
134  cpl_recipe * recipe;
135  cpl_parameter * p;
136 
137  /* Get the recipe out of the plugin */
138  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
139  recipe = (cpl_recipe *)plugin;
140  else return CPL_ERROR_UNSPECIFIED;
141 
142  /* Create the parameters list in the cpl_recipe object */
143  recipe->parameters = cpl_parameterlist_new();
144 
145  /* Fill the parameters list */
146  /* --nsamples */
147  p = cpl_parameter_new_value("isaac.isaac_img_dark.nsamples",
148  CPL_TYPE_INT, "number of samples for RON computation",
149  "isaac.isaac_img_dark", 100);
150  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "nsamples");
151  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
152  cpl_parameterlist_append(recipe->parameters, p);
153  /* --hsize */
154  p = cpl_parameter_new_value("isaac.isaac_img_dark.hsize",
155  CPL_TYPE_INT, "half size of the window for RON computation",
156  "isaac.isaac_img_dark", -1);
157  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "hsize");
158  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
159  cpl_parameterlist_append(recipe->parameters, p);
160 
161  /* Return */
162  return 0;
163 }
164 
165 /*----------------------------------------------------------------------------*/
171 /*----------------------------------------------------------------------------*/
172 static int isaac_img_dark_exec(cpl_plugin * plugin)
173 {
174  cpl_recipe * recipe;
175 
176  /* Get the recipe out of the plugin */
177  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
178  recipe = (cpl_recipe *)plugin;
179  else return CPL_ERROR_UNSPECIFIED;
180 
181  return isaac_img_dark(recipe->parameters, recipe->frames);
182 }
183 
184 /*----------------------------------------------------------------------------*/
190 /*----------------------------------------------------------------------------*/
191 static int isaac_img_dark_destroy(cpl_plugin * plugin)
192 {
193  cpl_recipe * recipe;
194 
195  /* Get the recipe out of the plugin */
196  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
197  recipe = (cpl_recipe *)plugin;
198  else return CPL_ERROR_UNSPECIFIED;
199 
200  cpl_parameterlist_delete(recipe->parameters);
201  return 0;
202 }
203 
204 /*----------------------------------------------------------------------------*/
211 /*----------------------------------------------------------------------------*/
212 static int isaac_img_dark(
213  cpl_parameterlist * parlist,
214  cpl_frameset * framelist)
215 {
216  cpl_parameter * par;
217  cpl_size nsets;
218  cpl_size * selection;
219  cpl_frameset * f_one;
220  cpl_image * avg;
221  cpl_matrix * rons;
222  cpl_boolean did_reduce = CPL_FALSE;
223  int i;
224 
225  /* Retrieve input parameters */
226  par = cpl_parameterlist_find(parlist, "isaac.isaac_img_dark.hsize");
227  isaac_img_dark_config.hsize = cpl_parameter_get_int(par);
228  par = cpl_parameterlist_find(parlist, "isaac.isaac_img_dark.nsamples");
229  isaac_img_dark_config.nsamples = cpl_parameter_get_int(par);
230 
231  /* Identify the RAW and CALIB frames in the input frameset */
232  if (isaac_dfs_set_groups(framelist)) {
233  cpl_msg_error(cpl_func, "Cannot identify RAW and CALIB frames");
234  return CPL_ERROR_UNSPECIFIED;
235  }
236 
237  /* Labelize all input frames */
238  cpl_msg_info(cpl_func, "Identify the different settings");
239  selection=cpl_frameset_labelise(framelist, isaac_img_dark_compare, &nsets);
240  if (selection == NULL) {
241  cpl_msg_error(cpl_func, "Cannot labelise input frames");
242  return CPL_ERROR_UNSPECIFIED;
243  }
244 
245  /* Extract settings and reduce each of them */
246  for (i=0; i<nsets; i++) {
247  /* Initialise */
248  isaac_img_dark_config.dark_med = -1.0;
249  isaac_img_dark_config.dark_stdev = -1.0;
250  avg = NULL;
251 
252  /* Reduce data set nb i */
253  cpl_msg_info(cpl_func, "Reduce data set no %d out of %d", i+1,
254  (int)nsets);
255  cpl_msg_indent_more();
256  f_one = cpl_frameset_extract(framelist, selection, i);
257 
258  /* At least 2 frames required */
259  if (cpl_frameset_get_size(f_one) < 2) {
260  cpl_msg_warning(cpl_func, "Setting %d skipped (not enough frames)",
261  i+1);
262  } else {
263  /* AVG part */
264  cpl_msg_info(cpl_func, "Compute the master dark");
265  cpl_msg_indent_more();
266  if (isaac_img_dark_avg_reduce(f_one, &avg)) {
267  cpl_msg_warning(cpl_func, "Cannot reduce set number %d", i+1);
268  }
269  cpl_msg_indent_less();
270  /* RON part */
271  cpl_msg_info(cpl_func, "Compute the read-out noise");
272  cpl_msg_indent_more();
273  if ((rons = isaac_img_dark_ron_reduce(f_one)) == NULL) {
274  cpl_msg_warning(cpl_func, "Cannot reduce set number %d", i+1);
275  }
276  cpl_msg_indent_less();
277  /* Save the products */
278  if (isaac_img_dark_save(avg, rons, i+1, f_one, parlist,
279  framelist) !=0 ){
280  cpl_msg_error(cpl_func, "Cannot save the products");
281  if (avg) cpl_image_delete(avg);
282  if (rons) cpl_matrix_delete(rons);
283  return CPL_ERROR_UNSPECIFIED;
284  }
285  if (rons) cpl_matrix_delete(rons);
286  if (!cpl_error_get_code()) did_reduce = CPL_TRUE;
287  }
288  if (avg) cpl_image_delete(avg);
289  cpl_frameset_delete(f_one);
290  cpl_msg_indent_less();
291  }
292 
293  /* Free and return */
294  cpl_free(selection);
295 
296  cpl_ensure_code(did_reduce, CPL_ERROR_ILLEGAL_INPUT);
297 
298  return cpl_error_set_where(cpl_func); /* Propagate error, if any */
299 }
300 
301 /*----------------------------------------------------------------------------*/
308 /*----------------------------------------------------------------------------*/
309 static int isaac_img_dark_avg_reduce(
310  cpl_frameset * framelist,
311  cpl_image ** avg)
312 {
313  cpl_imagelist * iset;
314  cpl_vector * medians;
315  cpl_image * image;
316  int i;
317 
318  /* Test entries */
319  if (framelist == NULL) return CPL_ERROR_UNSPECIFIED;
320 
321  /* Load the image set */
322  if ((iset = cpl_imagelist_load_frameset(framelist, CPL_TYPE_FLOAT, 1,
323  0)) == NULL) {
324  cpl_msg_error(cpl_func, "Cannot load the data");
325  return CPL_ERROR_UNSPECIFIED;
326  }
327 
328  /* Average it to the master dark */
329  if ((*avg = cpl_imagelist_collapse_create(iset)) == NULL) {
330  cpl_msg_error(cpl_func, "Cannot average the data set");
331  cpl_imagelist_delete(iset);
332  return CPL_ERROR_UNSPECIFIED;
333  }
334 
335  /* Compute mean-rms of the median values */
336  medians = cpl_vector_new(cpl_imagelist_get_size(iset));
337  for (i=0; i<cpl_imagelist_get_size(iset); i++) {
338  image = cpl_imagelist_get(iset, i);
339  cpl_vector_set(medians, i, cpl_image_get_median(image));
340  }
341  cpl_imagelist_delete(iset);
342  isaac_img_dark_config.dark_med = cpl_vector_get_mean(medians);
343  isaac_img_dark_config.dark_stdev = cpl_vector_get_stdev(medians);
344 
345  /* Free and Return */
346  cpl_vector_delete(medians);
347  return 0;
348 }
349 
350 /*----------------------------------------------------------------------------*/
361 /*----------------------------------------------------------------------------*/
362 static cpl_matrix * isaac_img_dark_ron_reduce(cpl_frameset * framelist)
363 {
364  cpl_frame * cur_frame;
365  cpl_propertylist * plist;
366  char arm;
367  const char * sval;
368  cpl_imagelist * iset;
369  cpl_matrix * rons;
370  cpl_image * tmp_im;
371  double rms;
372  double norm;
373  int ndit;
374  cpl_size zone_def[4];
375  int i;
376 
377  /* Test entries */
378  if (framelist == NULL) return NULL;
379 
380  /* Initialise */
381  rons = NULL;
382 
383  /* Check the arm used */
384  if (cpl_error_get_code()) return NULL;
385  cur_frame = cpl_frameset_get_position(framelist, 0);
386  plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
387  sval = isaac_pfits_get_arm(plist);
388  if (cpl_error_get_code()) {
389  cpl_msg_error(cpl_func, "Cannot get the used arm");
390  cpl_propertylist_delete(plist);
391  return NULL;
392  }
393  arm = (int)(sval[0]);
394  cpl_propertylist_delete(plist);
395 
396  /* Load the current set */
397  if ((iset = cpl_imagelist_load_frameset(framelist, CPL_TYPE_FLOAT, 1,
398  0)) == NULL) {
399  cpl_msg_error(cpl_func, "Cannot load the data");
400  return NULL;
401  }
402 
403  /* Switch on the arm */
404  switch (arm) {
405  case 'S':
406  /* Create the matrix */
407  rons = cpl_matrix_new(cpl_imagelist_get_size(iset)-1, 4);
408  if (isaac_img_dark_config.hsize < 0)
409  isaac_img_dark_config.hsize = ISAAC_DARK_HSIZE_SW_DEF;
410 
411  /* Loop on all pairs */
412  for (i=0; i<cpl_imagelist_get_size(iset)-1; i++) {
413  cpl_msg_info(cpl_func, "Pair number %d", i+1);
414  /* Get the norm factor */
415  if (cpl_error_get_code()) {
416  cpl_matrix_delete(rons);
417  cpl_imagelist_delete(iset);
418  return NULL;
419  }
420  cur_frame = cpl_frameset_get_position(framelist, i);
421  plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
422  0);
423  ndit = isaac_pfits_get_ndit(plist);
424  cpl_propertylist_delete(plist);
425  if (cpl_error_get_code()) {
426  cpl_msg_error(cpl_func, "Cannot get the NDIT");
427  cpl_matrix_delete(rons);
428  cpl_imagelist_delete(iset);
429  return NULL;
430  }
431  norm = 0.5 * ndit;
432  norm = sqrt(norm);
433 
434  /* Compute the current subtracted image */
435  if ((tmp_im = cpl_image_subtract_create(
436  cpl_imagelist_get(iset, i),
437  cpl_imagelist_get(iset, i+1))) == NULL) {
438  cpl_msg_error(cpl_func, "Cannot subtract the images");
439  cpl_imagelist_delete(iset);
440  cpl_matrix_delete(rons);
441  return NULL;
442  }
443 
444  /* Get measurement for lower-left quadrant */
445  zone_def[0] = 1;
446  zone_def[1] = cpl_image_get_size_x(tmp_im)/2;
447  zone_def[2] = 1;
448  zone_def[3] = cpl_image_get_size_y(tmp_im)/2;
449  cpl_flux_get_noise_window(tmp_im, zone_def,
450  isaac_img_dark_config.hsize,
451  isaac_img_dark_config.nsamples, &rms, NULL);
452  cpl_matrix_set(rons, i, 0, rms * norm);
453  cpl_msg_info(cpl_func, "RON in LL quadrant: %g", rms * norm);
454 
455  /* Get measurement for lower-right quadrant */
456  zone_def[0] = cpl_image_get_size_x(tmp_im)/2 + 1;
457  zone_def[1] = cpl_image_get_size_x(tmp_im);
458  zone_def[2] = 1;
459  zone_def[3] = cpl_image_get_size_y(tmp_im)/2;
460  cpl_flux_get_noise_window(tmp_im, zone_def,
461  isaac_img_dark_config.hsize,
462  isaac_img_dark_config.nsamples, &rms, NULL);
463  cpl_matrix_set(rons, i, 1, rms * norm);
464  cpl_msg_info(cpl_func, "RON in LR quadrant: %g", rms * norm);
465 
466  /* Get measurement for upper-left quadrant */
467  zone_def[0] = 1;
468  zone_def[1] = cpl_image_get_size_x(tmp_im)/2;
469  zone_def[2] = cpl_image_get_size_y(tmp_im)/2 + 1;
470  zone_def[3] = cpl_image_get_size_y(tmp_im);
471  cpl_flux_get_noise_window(tmp_im, zone_def,
472  isaac_img_dark_config.hsize,
473  isaac_img_dark_config.nsamples, &rms, NULL);
474  cpl_matrix_set(rons, i, 2, rms * norm);
475  cpl_msg_info(cpl_func, "RON in UL quadrant: %g", rms * norm);
476 
477  /* Get measurement for upper-right quadrant */
478  zone_def[0] = cpl_image_get_size_x(tmp_im)/2 + 1;
479  zone_def[1] = cpl_image_get_size_x(tmp_im);
480  zone_def[2] = cpl_image_get_size_y(tmp_im)/2 + 1;
481  zone_def[3] = cpl_image_get_size_y(tmp_im);
482  cpl_flux_get_noise_window(tmp_im, zone_def,
483  isaac_img_dark_config.hsize,
484  isaac_img_dark_config.nsamples, &rms, NULL);
485  cpl_matrix_set(rons, i, 3, rms * norm);
486  cpl_msg_info(cpl_func, "RON in UR quadrant: %g", rms * norm);
487  cpl_image_delete(tmp_im);
488  }
489  break;
490  case 'L':
491  /* Create the matrix */
492  rons = cpl_matrix_new(cpl_imagelist_get_size(iset)-1, 1);
493  if (isaac_img_dark_config.hsize < 0)
494  isaac_img_dark_config.hsize = ISAAC_DARK_HSIZE_LW_DEF;
495 
496  /* Loop on all pairs */
497  for (i=0; i<cpl_imagelist_get_size(iset)-1; i++) {
498  cpl_msg_info(cpl_func, "Pair number %d", i+1);
499  /* Get the norm factor */
500  if (cpl_error_get_code()) {
501  cpl_matrix_delete(rons);
502  cpl_imagelist_delete(iset);
503  return NULL;
504  }
505  cur_frame = cpl_frameset_get_position(framelist, i);
506  plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
507  0);
508  ndit = isaac_pfits_get_ndit(plist);
509  cpl_propertylist_delete(plist);
510  if (cpl_error_get_code()) {
511  cpl_msg_error(cpl_func, "Cannot get the NDIT");
512  cpl_matrix_delete(rons);
513  cpl_imagelist_delete(iset);
514  return NULL;
515  }
516  norm = 0.5 * ndit;
517  norm = sqrt(norm);
518 
519  /* Compute the current subtracted image */
520  if ((tmp_im = cpl_image_subtract_create(
521  cpl_imagelist_get(iset, i),
522  cpl_imagelist_get(iset, i+1))) == NULL) {
523  cpl_msg_error(cpl_func, "Cannot subtract the images");
524  cpl_imagelist_delete(iset);
525  cpl_matrix_delete(rons);
526  return NULL;
527  }
528 
529  /* Get measurement */
530  cpl_flux_get_noise_window(tmp_im, NULL,
531  isaac_img_dark_config.hsize,
532  isaac_img_dark_config.nsamples, &rms, NULL);
533  cpl_matrix_set(rons, i, 0, rms * norm);
534  cpl_msg_info(cpl_func, "RON: %g", rms * norm);
535  cpl_image_delete(tmp_im);
536  }
537  break;
538  default:
539  cpl_msg_error(cpl_func, "Unsupported arm");
540  cpl_matrix_delete(rons);
541  rons = NULL;
542  break;
543  }
544 
545  /* Free and return */
546  cpl_imagelist_delete(iset);
547  return rons;
548 }
549 
550 /*----------------------------------------------------------------------------*/
561 /*----------------------------------------------------------------------------*/
562 static int isaac_img_dark_save(
563  cpl_image * avg,
564  cpl_matrix * rons,
565  int set_nb,
566  cpl_frameset * set,
567  cpl_parameterlist * parlist,
568  cpl_frameset * set_tot)
569 {
570  cpl_propertylist * plist;
571  cpl_propertylist * qclist;
572  cpl_propertylist * paflist;
573  const cpl_frame * ref_frame;
574  char * filename;
575  char qc_str[128];
576  int i;
577 
578  /* Get the QC params in qclist */
579  qclist = cpl_propertylist_new();
580  cpl_propertylist_append_double(qclist, "ESO QC DARKMED",
581  isaac_img_dark_config.dark_med);
582  cpl_propertylist_append_double(qclist, "ESO QC DARKSTDEV",
583  isaac_img_dark_config.dark_stdev);
584  if (rons != NULL) {
585  switch (cpl_matrix_get_ncol(rons)) {
586  case 1:
587  for (i=0; i<cpl_matrix_get_nrow(rons); i++) {
588  sprintf(qc_str, "ESO QC RON%d", i+1);
589  cpl_propertylist_append_double(qclist, qc_str,
590  cpl_matrix_get(rons, i, 0));
591  }
592  break;
593  case 4:
594  for (i=0; i<cpl_matrix_get_nrow(rons); i++) {
595  sprintf(qc_str, "ESO QC LL RON%d", i+1);
596  cpl_propertylist_append_double(qclist, qc_str,
597  cpl_matrix_get(rons, i, 0));
598  sprintf(qc_str, "ESO QC LR RON%d", i+1);
599  cpl_propertylist_append_double(qclist, qc_str,
600  cpl_matrix_get(rons, i, 1));
601  sprintf(qc_str, "ESO QC UL RON%d", i+1);
602  cpl_propertylist_append_double(qclist, qc_str,
603  cpl_matrix_get(rons, i, 2));
604  sprintf(qc_str, "ESO QC UR RON%d", i+1);
605  cpl_propertylist_append_double(qclist, qc_str,
606  cpl_matrix_get(rons, i, 3));
607  }
608  break;
609  default:
610  cpl_msg_error(cpl_func, "Invalid RONs matrix format");
611  break;
612  }
613  }
614 
615  /* Write the average image */
616  filename = cpl_sprintf("isaac_img_dark_set%02d_avg.fits", set_nb);
617  irplib_dfs_save_image(set_tot,
618  parlist,
619  set,
620  avg,
621  CPL_BPP_IEEE_FLOAT,
622  "isaac_img_dark",
623  ISAAC_IMG_DARK_AVG,
624  qclist,
625  NULL,
626  PACKAGE "/" PACKAGE_VERSION,
627  filename);
628  cpl_free(filename);
629 
630  /* Get the reference frame */
631  ref_frame = irplib_frameset_get_first_from_group(set, CPL_FRAME_GROUP_RAW);
632 
633  /* Get FITS header from reference file */
634  if ((plist=cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
635  0)) == NULL) {
636  cpl_msg_error(cpl_func, "getting header from reference frame");
637  cpl_propertylist_delete(qclist);
638  return CPL_ERROR_UNSPECIFIED;
639  }
640 
641  /* Get the keywords for the paf file */
642  paflist = cpl_propertylist_new();
643  cpl_propertylist_copy_property_regexp(paflist, plist,
644  "^(ARCFILE|MJD-OBS|ESO TPL ID|ESO DPR TECH|DATE-OBS|ESO DET DIT|"
645  "ESO DET NDIT|ESO DET NCORRS|ESO DET NDSAMPLES|ESO DET MODE NAME)$", 0);
646  cpl_propertylist_delete(plist);
647 
648  /* Copy the QC in paflist */
649  cpl_propertylist_copy_property_regexp(paflist, qclist, ".", 0);
650  cpl_propertylist_delete(qclist);
651 
652  /* PRO.CATG */
653  cpl_propertylist_update_string(paflist, CPL_DFS_PRO_CATG,
654  ISAAC_IMG_DARK_AVG);
655 
656  /* Save the PAF file */
657  filename = cpl_sprintf("isaac_img_dark_set%02d.paf", set_nb);
658  cpl_dfs_save_paf("ISAAC",
659  "isaac_img_dark",
660  paflist,
661  filename);
662  cpl_free(filename);
663  cpl_propertylist_delete(paflist);
664  return 0;
665 }
666 
667 /*----------------------------------------------------------------------------*/
674 /*----------------------------------------------------------------------------*/
675 static int isaac_img_dark_compare(
676  const cpl_frame * frame1,
677  const cpl_frame * frame2)
678 {
679  int comparison;
680  cpl_propertylist * plist1;
681  cpl_propertylist * plist2;
682  double dval1, dval2;
683  int ival1, ival2;
684 
685  /* Test entries */
686  if (frame1==NULL || frame2==NULL) return CPL_ERROR_UNSPECIFIED;
687 
688  /* Get property lists */
689  if ((plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),
690  0)) == NULL) {
691  cpl_msg_error(cpl_func, "getting header from reference frame");
692  return CPL_ERROR_UNSPECIFIED;
693  }
694  if ((plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),
695  0)) == NULL) {
696  cpl_msg_error(cpl_func, "getting header from reference frame");
697  cpl_propertylist_delete(plist1);
698  return CPL_ERROR_UNSPECIFIED;
699  }
700 
701  /* Test status */
702  if (cpl_error_get_code()) {
703  cpl_propertylist_delete(plist1);
704  cpl_propertylist_delete(plist2);
705  return CPL_ERROR_UNSPECIFIED;
706  }
707 
708  /* Compare exposure time */
709  comparison = 1;
710  dval1 = isaac_pfits_get_dit(plist1);
711  dval2 = isaac_pfits_get_dit(plist2);
712  if (cpl_error_get_code()) {
713  cpl_msg_error(cpl_func, "cannot get exposure time");
714  cpl_propertylist_delete(plist1);
715  cpl_propertylist_delete(plist2);
716  return CPL_ERROR_UNSPECIFIED;
717  }
718  if (fabs(dval1-dval2) > 1e-5) comparison = 0;
719 
720  /* Compare NDIT */
721  ival1 = isaac_pfits_get_ndit(plist1);
722  ival2 = isaac_pfits_get_ndit(plist2);
723  if (cpl_error_get_code()) {
724  cpl_msg_error(cpl_func, "cannot get NDIT");
725  cpl_propertylist_delete(plist1);
726  cpl_propertylist_delete(plist2);
727  return CPL_ERROR_UNSPECIFIED;
728  }
729  if (ival1 != ival2) comparison = 0;
730 
731  /* Compare the readout mode */
732  ival1 = isaac_pfits_get_rom(plist1);
733  ival2 = isaac_pfits_get_rom(plist2);
734  if (cpl_error_get_code()) {
735  cpl_msg_error(cpl_func, "cannot get read-out mode");
736  cpl_propertylist_delete(plist1);
737  cpl_propertylist_delete(plist2);
738  return CPL_ERROR_UNSPECIFIED;
739  }
740  if (ival1 != ival2) comparison = 0;
741 
742  /* Free and return */
743  cpl_propertylist_delete(plist1);
744  cpl_propertylist_delete(plist2);
745  return comparison;
746 }
747 
int isaac_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: isaac_dfs.c:60
double isaac_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
Definition: isaac_pfits.c:305
int isaac_pfits_get_rom(const cpl_propertylist *plist)
find out the read out mode
Definition: isaac_pfits.c:790
int isaac_pfits_get_ndit(const cpl_propertylist *plist)
find out the NDIT keyword
Definition: isaac_pfits.c:597
const char * isaac_pfits_get_arm(const cpl_propertylist *plist)
find out the arm which is active
Definition: isaac_pfits.c:106
const char * isaac_get_license(void)
Get the pipeline copyright and license.
Definition: isaac_utils.c:62