SINFONI Pipeline Reference Manual  2.5.2
sinfo_new_dark.c
1 /*
2  * This file is part of the ESO SINFONI Pipeline
3  * Copyright (C) 2004,2005 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 /*----------------------------------------------------------------------------
20 
21  File name : sinfo_new_dark.c
22  Author : A. Modigliani
23  Created on : Sep 17, 2003
24  Description : Master sinfo_dark creation
25 
26  ---------------------------------------------------------------------------*/
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 /*----------------------------------------------------------------------------
32  Includes
33  ---------------------------------------------------------------------------*/
34 #include "sinfo_new_dark.h"
35 #include "sinfo_utilities.h"
36 #include "sinfo_pro_save.h"
37 #include "sinfo_dark_ini_by_cpl.h"
38 #include "sinfo_dfs.h"
39 #include "sinfo_pfits.h"
40 #include "sinfo_error.h"
41 #include "sinfo_utils_wrappers.h"
42 /*----------------------------------------------------------------------------
43  Defines
44  ---------------------------------------------------------------------------*/
45 static int sinfo_dark_ron_reduce(cpl_frameset * framelist,
46  dark_config* cfg,
47  cpl_table* qclog);
48 
49 
50 static int
51 sinfo_dark_compare(const cpl_frame * frame1, const cpl_frame * frame2);
52 
62 /*----------------------------------------------------------------------------
63  Function Definitions
64  ---------------------------------------------------------------------------*/
65 
66 /*----------------------------------------------------------------------------
67  @name sinfo_new_dark()
68  @param plugin_id recipe id
69  @param config input parameterlist
70  @param sof input set of frames
71  @param dark_name name of output master dark
72  @return integer (0 if it worked, -1 if it doesn't)
73  @doc
74  1) Sorts frames according to integration time
75  2) Take the clean mean of a stack of frames with the
76  same integration time
77 
78  ---------------------------------------------------------------------------*/
79 
80 int sinfo_new_dark (const char* plugin_id, cpl_parameterlist* config,
81  cpl_frameset* sof, char* dark_name)
82 {
83 
84  dark_config * cfg=NULL ;
85  cpl_imagelist * image_list=NULL ;
86  cpl_imagelist * object_list=NULL ;
87 
88 
89  cpl_image * image=NULL ;
90  cpl_image * eclipse_image=NULL ;
91 
92  cpl_image* dark_img=NULL;
93  cpl_frame* first_frame=NULL;
94  cpl_vector* qc_dark_median=NULL;
95  cpl_frameset* raw=NULL;
96  cpl_table* qclog_tbl=NULL;
97  cpl_propertylist* rplist=NULL;
98  cpl_frameset* f_one=NULL;
99  int no=0;
100  float lo_cut=0.;
101  float hi_cut=0.;
102 
103  int i = 0;
104  int j = 0;
105  int n = 0;
106  int count = 0;
107  int* n_times=NULL;
108  double exp_time = 0.;
109  float* int_time=NULL;
110  //float time_val = 0.;
111 
112  char ref_file[MAX_NAME_SIZE];
113  cpl_size zone_def[4];
114  double qc_ron_val=0;
115  double qc_ron_err=0;
116  double qc_darkmed_ave=0;
117  double qc_darkmed_stdev=0;
118  double fpn=0;
119  cpl_size zone[4];
120  int naxis1=0;
121  int naxis2=0;
122 
123  cpl_size* selection=NULL;
124  cpl_size nsets=0;
125  /*
126  -----------------------------------------------------------------
127  1) parse the file names and parameters to the dark_config data
128  structure cfg
129  -----------------------------------------------------------------
130  */
131 
132  check_nomsg(raw=cpl_frameset_new());
133  cknull(cfg = sinfo_parse_cpl_input_dark(config,sof,&raw),
134  "could not parse cpl input!") ;
135 
136  /*
137  -----------------------------------------------------------------
138  2) GET FRAMES AND SORT ACCORDING TO EXPOSURE TIME
139  -----------------------------------------------------------------
140  */
141 
142  /*
143  2.1) get the total integration time from the fits header and
144  store it in an array
145  */
146 
147  /* 2.1.1) get a data cube to stack darks */
148  sinfo_msg("Build data cube");
149  /* take a clean mean of the frames */
150  check_nomsg(image_list = cpl_imagelist_new());
151  int_time = (float*) cpl_calloc(cfg -> nframes, sizeof(float)) ;
152  sinfo_check_rec_status(0);
153 
154  for ( i = 0 ; i < cfg->nframes ; i++ )
155  {
156  if (sinfo_is_fits_file (cfg->inFrameList[i]) != 1) {
157  sinfo_msg_error("Input file %s is not FITS",cfg->inFrameList[i]);
158  goto cleanup;
159  }
160 
161  check_nomsg(cpl_imagelist_set(image_list,
162  cpl_image_load(cfg->inFrameList[i],CPL_TYPE_FLOAT,0,0),i));
163 
164  exp_time = sinfo_pfits_get_exptime(cfg->inFrameList[i]);
165  if(cpl_error_get_code() != CPL_ERROR_NONE) {
166  sinfo_msg_error("could not get exposure time from fits header!\n");
167  goto cleanup;
168  }
169  sinfo_new_array_set_value(int_time, (float)exp_time, i);
170  }
171  no=cfg->nframes;
172 
173 
174  /*
175  2.2) find the number of frames with the same integration time
176  */
177  sinfo_msg("Find frames with same tint");
178  n = 0;
179 
180  n_times = (int*) cpl_calloc(cfg -> nframes, sizeof(int));
181  sinfo_msg("Sort frames with same tint");
182 
183  for ( i = 0 ; i < cfg->nframes-1 ; i++ )
184  {
185  if ( sinfo_new_array_get_value(int_time, i+1) !=
186  sinfo_new_array_get_value(int_time, i)
187  ) {
188 
189  n_times[n] = i+1;
190  n = n+1;
191  }
192 
193  }
194 
195  /*
196  2.3) store the images with the same tint in data cubes and take
197  clean means
198  */
199  sinfo_msg("Do clean mean");
200  if ( n == 0 ) {
201 
202  sinfo_msg("n == 0 ");
203  //time_val = sinfo_new_array_get_value(int_time, 0);
204 
205  cknull(object_list = cpl_imagelist_new(),
206  "could not allocate memory for object_list");
207 
208  /* here we have a leak of 80 bytes */
209 
210 
211  count = 0;
212  /* do also QC log */
213  check_nomsg(qc_dark_median=cpl_vector_new(cfg->nframes));
214 
215  /* AMo here there is a leak */
216  for ( j = 0 ; j < cfg->nframes ; j++ ) {
217  check_nomsg(cpl_imagelist_set(object_list,
218  cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
219  count));
220  check_nomsg(cpl_vector_set(qc_dark_median,j,
221  cpl_image_get_median(cpl_imagelist_get(image_list,j))));
222  count = count + 1;
223  }
224 
225 
226 
227  check_nomsg(qc_darkmed_ave=cpl_vector_get_mean(qc_dark_median));
228  if (cfg->nframes > 1) {
229  check_nomsg(qc_darkmed_stdev=cpl_vector_get_stdev(qc_dark_median));
230  }
231  /*
232  rms = stdev * sqrt(1-1/(double)cpl_vector_get_size(myvector));
233  qc_darkmed_stdev = qc_darkmed_stdev *
234  sqrt(1-1/(double)cpl_vector_get_size(qc_dark_median));
235  */
236 
237  check_nomsg(no=cpl_imagelist_get_size(object_list));
238  lo_cut=(floor)(cfg->lo_reject*no+0.5);
239  hi_cut=(floor)(cfg->hi_reject*no+0.5);
240 
241 
242 
243  cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
244  lo_cut,hi_cut),
245  "sinfo_average_with_rejection failed");
246 
247  sinfo_free_imagelist(&object_list);
248 
249  sinfo_msg("dark_name=%s\n",dark_name);
250 
251  check_nomsg(first_frame = cpl_frameset_get_frame(raw, 0)) ;
252 
253  strcpy(ref_file,cpl_frame_get_filename(first_frame)) ;
254  cknull_nomsg(rplist = cpl_propertylist_load(ref_file, 0));
255 
256  check_nomsg(naxis1=cpl_propertylist_get_int(rplist,"NAXIS1"));
257  check_nomsg(naxis2=cpl_propertylist_get_int(rplist,"NAXIS1"));
258  sinfo_free_propertylist(&rplist);
259 
260  if(cfg->qc_ron_xmin < 1) {
261  sinfo_msg_error("qc_ron_xmin %d < 1",cfg->qc_ron_xmin);
262  goto cleanup;
263  }
264 
265  if(cfg->qc_ron_xmax > naxis1) {
266  sinfo_msg_error("qc_ron_xmax %d > %d",cfg->qc_ron_xmax,naxis1);
267  goto cleanup;
268  }
269 
270  if(cfg->qc_ron_ymin < 1) {
271  sinfo_msg_error("qc_ron_ymin %d < 1",cfg->qc_ron_ymin);
272  goto cleanup;
273  }
274 
275  if(cfg->qc_ron_ymax > naxis2) {
276  sinfo_msg_error("qc_ron_ymax %d > %d",cfg->qc_ron_ymax,naxis2);
277  goto cleanup;
278  }
279 
280  zone_def[0]=cfg->qc_ron_xmin;
281  zone_def[1]=cfg->qc_ron_xmax;
282  zone_def[2]=cfg->qc_ron_ymin;
283  zone_def[3]=cfg->qc_ron_ymax;
284 
285 
286 
287  check(cpl_flux_get_noise_window(image,
288  zone_def,
289  cfg->qc_ron_hsize,
290  cfg->qc_ron_nsamp,
291  &qc_ron_val,
292  &qc_ron_err),
293  "In computation RON on image %s",dark_name);
294 
295 
296 
297  if(cfg->qc_fpn_xmin < 1) {
298  sinfo_msg_error("qc_fpn_xmin %d < 1",cfg->qc_fpn_xmin);
299  goto cleanup;
300  }
301 
302  if(cfg->qc_fpn_xmax > naxis1) {
303  sinfo_msg_error("qc_fpn_xmax %d > %d",cfg->qc_fpn_xmax,naxis1);
304  goto cleanup;
305  }
306 
307  if(cfg->qc_fpn_ymin < 1) {
308  sinfo_msg_error("qc_fpn_ymin %d < 1",cfg->qc_fpn_ymin);
309  goto cleanup;
310  }
311 
312  if(cfg->qc_fpn_ymax > naxis2) {
313  sinfo_msg_error("qc_fpn_ymax %d > %d",cfg->qc_fpn_ymax,naxis2);
314  goto cleanup;
315  }
316 
317  zone[0]=cfg->qc_fpn_xmin;
318  zone[1]=cfg->qc_fpn_xmax;
319  zone[2]=cfg->qc_fpn_ymin;
320  zone[3]=cfg->qc_fpn_ymax;
321  check(cpl_flux_get_noise_window(image, zone, cfg->qc_fpn_hsize,
322  cfg->qc_fpn_nsamp, &fpn, NULL),
323  "Error computing noise in a window");
324 
325  /* QC LOG */
326  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
327 
328  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED AVE",
329  qc_darkmed_ave,"Average of raw darks medians","%f"));
330 
331  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED STDEV",
332  qc_darkmed_stdev,"STDEV of raw darks medians","%f"));
333 
334  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RON",
335  qc_ron_val,"Read Out Noise","%f"));
336 
337  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RONRMS",
338  qc_ron_err,"RMS on Read Out Noise","%f"));
339 
340  ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKFPN",
341  fpn,"Fixed Pattern Noise of combined frames","%g"));
342 
343 
344  /* special way to calculate RON: for each couple */
345 
346  check(selection = cpl_frameset_labelise(raw,sinfo_dark_compare,&nsets),
347  "Error labelizing");
348 
349 
350 
351  for ( i = 0 ; i < nsets ; i++ ) {
352  sinfo_msg("Reduce data set no %d out of %" CPL_SIZE_FORMAT "",
353  i+1, nsets);
354  cpl_msg_indent_more();
355  check_nomsg(f_one = cpl_frameset_extract(raw,selection,i));
356  if (cpl_frameset_get_size(f_one) < 2) {
357  sinfo_msg_warning("Skip %d set. One frame, not enough "
358  "to get ron",i+1);
359  } else {
360  if (sinfo_dark_ron_reduce(f_one,cfg,qclog_tbl) ) {
361  sinfo_msg_warning( "Cannot reduce set number %d", i+1) ;
362  }
363  }
364  sinfo_free_frameset(&f_one);
365  cpl_msg_indent_less();
366 
367  }
368  cpl_free(selection);
369 
370 
371  /* generate a dummy_set with the master dark and a dummy
372  dark=2*master_dark */
373 
374  ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
375  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
376  "cannot save ima %s", dark_name);
377  sinfo_free_table(&qclog_tbl);
378  sinfo_free_image(&image);
379 
380  } else if (n == 1) {
381 
382  sinfo_msg("n == 1");
383  //time_val = sinfo_new_array_get_value(int_time, 0);
384  cknull(object_list = cpl_imagelist_new(),
385  "could not allocate memory");
386 
387  count = 0;
388 
389  for (j =0; j < n_times[0]; j++) {
390 
391  check_nomsg(cpl_imagelist_set(object_list,
392  cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
393  count));
394  count = count + 1;
395  }
396 
397 
398  check_nomsg(no=cpl_imagelist_get_size(object_list));
399  lo_cut=(floor)(cfg->lo_reject*no+0.5);
400  hi_cut=(floor)(cfg->hi_reject*no+0.5);
401  check(image=cpl_imagelist_collapse_minmax_create(object_list,
402  lo_cut,hi_cut),
403  "sinfo_average_with_rejection failed!");
404 
405  sinfo_free_imagelist(&object_list);
406 
407  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
408  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
409  "A description","%d"));
410 
411  ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
412  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
413  "cannot save ima %s", dark_name);
414 
415 
416  sinfo_free_image(&image);
417  sinfo_free_table(&qclog_tbl);
418 
419  //time_val = sinfo_new_array_get_value(int_time, n_times[0]);
420  cknull(object_list = cpl_imagelist_new(),
421  "could not allocate memory");
422  count = 0;
423 
424 
425  for (j = n_times[0]; j < cfg->nframes; j++) {
426 
427  check_nomsg(cpl_imagelist_set(object_list,
428  cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
429  count));
430  count = count + 1;
431  }
432 
433 
434  check_nomsg(no=cpl_imagelist_get_size(object_list));
435  lo_cut=(floor)(cfg->lo_reject*no+0.5);
436  hi_cut=(floor)(cfg->hi_reject*no+0.5);
437  cknull(eclipse_image=cpl_imagelist_collapse_minmax_create(object_list,
438  lo_cut,hi_cut),
439  "sinfo_average_with_rejection failed!");
440 
441  sinfo_free_imagelist(&object_list);
442 
443 
444  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
445  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
446  "A description","%d"));
447 
448  ck0(sinfo_pro_save_ima(eclipse_image,raw,sof,dark_name,
449  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
450  "cannot save ima %s", dark_name);
451 
452  sinfo_free_image(&eclipse_image);
453  sinfo_free_table(&qclog_tbl);
454 
455  } else {
456 
457  sinfo_msg("n==else\n");
458 
459  for (i= 0; i < n+1; i++) {
460  if ( i == 0 ) {
461  //time_val = sinfo_new_array_get_value(int_time, 0);
462  check(object_list = cpl_imagelist_new(),
463  "could not allocate memory");
464 
465  count = 0;
466  for (j = 0; j < n_times[0]; j++) {
467  check_nomsg(cpl_imagelist_set(object_list,
468  cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
469  count));
470  count = count + 1;
471  }
472  check_nomsg(no=cpl_imagelist_get_size(object_list));
473  lo_cut=(floor)(cfg->lo_reject*no+0.5);
474  hi_cut=(floor)(cfg->hi_reject*no+0.5);
475  check(image=cpl_imagelist_collapse_minmax_create(object_list,
476  lo_cut,hi_cut),
477  "Error computing average with rejection");
478  sinfo_free_imagelist(&object_list);
479 
480  sinfo_msg("dark_name-%s\n",dark_name);
481  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
482  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
483  "A description","%d"));
484 
485  ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
486  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
487  "cannot save ima %s", dark_name);
488 
489 
490  sinfo_free_table(&qclog_tbl);
491  sinfo_free_image(&image);
492  } else if ( i == n ) {
493  //time_val = sinfo_new_array_get_value(int_time, n_times[n-1]);
494  cknull(object_list = cpl_imagelist_new(),
495  "could not allocate memory");
496 
497  count = 0;
498  for (j = n_times[n-1]; j < cfg->nframes; j++) {
499  check_nomsg(cpl_imagelist_set(object_list,
500  cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
501  count));
502  count = count + 1;
503  }
504  check_nomsg(no=cpl_imagelist_get_size(object_list));
505  lo_cut=(floor)(cfg->lo_reject*no+0.5);
506  hi_cut=(floor)(cfg->hi_reject*no+0.5);
507  check(image=cpl_imagelist_collapse_minmax_create(object_list,
508  lo_cut,hi_cut),
509  "Error computing average with rejection");
510 
511  sinfo_free_imagelist(&object_list);
512 
513  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
514  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
515  "A description","%d"));
516 
517  ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
518  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
519  "cannot save ima %s", dark_name);
520  sinfo_free_table(&qclog_tbl);
521  sinfo_free_image(&image);
522  } else {
523  //time_val = sinfo_new_array_get_value(int_time, n_times[i-1]);
524  cknull(object_list = cpl_imagelist_new(),
525  "could not allocate memory");
526 
527  count = 0;
528  for (j = n_times[i-1]; j < n_times[i]; j++) {
529  check_nomsg(cpl_imagelist_set(object_list,
530  cpl_image_duplicate(cpl_imagelist_get(image_list,j)),
531  count));
532  count = count + 1;
533  }
534  check_nomsg(no=cpl_imagelist_get_size(object_list));
535  lo_cut=(floor)(cfg->lo_reject*no+0.5);
536  hi_cut=(floor)(cfg->hi_reject*no+0.5);
537  cknull(image=cpl_imagelist_collapse_minmax_create(object_list,
538  lo_cut,hi_cut),
539  "Error computing average with rejection");
540 
541  sinfo_free_imagelist(&object_list);
542 
543  cknull_nomsg(qclog_tbl = sinfo_qclog_init());
544  ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1,
545  "A description","%d"));
546 
547  ck0(sinfo_pro_save_ima(image,raw,sof,dark_name,
548  PRO_MASTER_DARK,qclog_tbl,plugin_id,config),
549  "cannot save ima %s", dark_name);
550 
551  sinfo_free_image(&image);
552  sinfo_free_table(&qclog_tbl);
553  }
554 
555  } /* end for loop */
556  } /* end else over n */
557 
558 
559 
560  sinfo_free_imagelist(&image_list);
561  sinfo_free_my_vector(&qc_dark_median);
562  sinfo_free_int(&n_times);
563  sinfo_free_float(&int_time);
564  sinfo_dark_free(&cfg);
565  sinfo_free_frameset(&raw);
566 
567  return 0;
568 
569  cleanup:
570  sinfo_free_frameset(&f_one);
571  cpl_free(selection);
572  sinfo_free_image(&eclipse_image);
573  sinfo_free_table(&qclog_tbl);
574  sinfo_free_image(&dark_img);
575  sinfo_free_image(&image);
576  sinfo_free_propertylist(&rplist);
577  sinfo_free_my_vector(&qc_dark_median);
578  sinfo_free_imagelist(&object_list);
579  sinfo_free_int(&n_times);
580  sinfo_free_float(&int_time);
581  sinfo_free_imagelist(&image_list);
582  sinfo_dark_free(&cfg);
583  sinfo_free_frameset(&raw);
584 
585  return -1;
586 
587 }
588 
589 
590 
591 
592 
593 
594 /*--------------------------------------------------------------------*/
602 /*--------------------------------------------------------------------*/
603 static int
604 sinfo_dark_ron_reduce(cpl_frameset * framelist,
605  dark_config * cfg,
606  cpl_table * qclog_tbl)
607 {
608  cpl_imagelist * iset =NULL;
609  int i =0;
610  double* ron=NULL;
611  /* int nraw=0; */
612  int niset=0;
613  char key_name[MAX_NAME_SIZE];
614  /* Test entries */
615 
616  cknull_nomsg(framelist);
617 
618  /* Load the current set */
619  if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
620  sinfo_msg_error( "Cannot load the data") ;
621  return -1 ;
622  }
623  /* Loop on all pairs */
624  /* nraw = cpl_table_get_nrow(qclog_tbl); */
625  niset=cpl_imagelist_get_size(iset);
626 
627  ron = cpl_calloc(niset,sizeof(double));
628 
629  sinfo_get_ron(framelist,
630  cfg->qc_ron_xmin,cfg->qc_ron_xmax,
631  cfg->qc_ron_ymin,cfg->qc_ron_ymax,
632  cfg->qc_ron_hsize,cfg->qc_ron_nsamp,
633  &ron);
634 
635  for (i=0 ; i<niset-1 ; i++) {
636 
637  /* Write the paf file on disk */
638  /* Write QC LOG */
639 
640  snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC RON",i+1);
641  sinfo_qclog_add_double(qclog_tbl,key_name,ron[i],
642  "Read Out Noise","%f");
643 
644  }
645 
646  cpl_free(ron);
647  sinfo_free_imagelist(&iset) ;
648 
649  return 0 ;
650  cleanup:
651  cpl_free(ron);
652  ron=NULL;
653  sinfo_free_imagelist(&iset) ;
654 
655  return -1;
656 
657 }
658 
659 
660 /*---------------------------------------------------------------------------*/
667 /*---------------------------------------------------------------------------*/
668 static int sinfo_dark_compare(
669  const cpl_frame * frame1,
670  const cpl_frame * frame2)
671 {
672  int comparison=0 ;
673  cpl_propertylist * plist1=NULL;
674  cpl_propertylist * plist2=NULL;
675 
676  char * sval ;
677  char mode1[512] ;
678  char mode2[512] ;
679  double dval1=0;
680  double dval2=0;
681  int ival1=0;
682  int ival2=0;
683 
684  /* Test entries */
685  if (frame1==NULL || frame2==NULL) return -1 ;
686 
687  /* Get property lists */
688  cknull(plist1=cpl_propertylist_load(cpl_frame_get_filename(frame1),0),
689  "getting header from reference frame");
690 
691  cknull(plist2=cpl_propertylist_load(cpl_frame_get_filename(frame2),0),
692  "getting header from reference frame");
693 
694  /* Compare exposure time */
695  comparison = 1 ;
696  check(dval1=sinfo_pfits_get_exp_time(plist1),"To get exptime");
697  check(dval2=sinfo_pfits_get_exp_time(plist2),"To get exptime");
698 
699  if (fabs(dval1-dval2) > 1e-5) comparison = 0 ;
700 
701  /* Compare the readout mode */
702  check(ival1=sinfo_pfits_get_rom(plist1),"to get read out mode");
703  check(ival2=sinfo_pfits_get_rom(plist2),"to get read out mode");
704  if (ival1 != ival2) comparison = 0 ;
705 
706 
707  /* Compare the detector mode */
708  cknull(sval=sinfo_pfits_get_mode(plist1),"to get detector mode");
709  strcpy(mode1, sval) ;
710 
711  cknull(sval=sinfo_pfits_get_mode(plist2),"to get detector mode");
712  strcpy(mode2, sval) ;
713 
714 
715  if (strcmp(mode1, mode2)) comparison = 0 ;
716 
717  /* Files have to be consequtive */
718  /*
719  check(ival1 = sinfo_pfits_get_expno(plist1),"to get exposure number");
720  check(ival2 = sinfo_pfits_get_expno(plist1),"to get exposure number");
721  if (ival1 != ival2) comparison = 0 ;
722  */
723  sinfo_free_propertylist(&plist1);
724  sinfo_free_propertylist(&plist2);
725 
726  return comparison ;
727  cleanup:
728  sinfo_free_propertylist(&plist1);
729  sinfo_free_propertylist(&plist2);
730  return -1 ;
731 
732 
733 }