SINFONI Pipeline Reference Manual  2.6.0
sinfo_dfs.c
1 /* $Id: sinfo_dfs.c,v 1.44 2013-09-17 08:11:22 amodigli Exp $
2  *
3  * This file is part of the SINFONI 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2013-09-17 08:11:22 $
24  * $Revision: 1.44 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 /*----------------------------------------------------------------------------
32  Macros
33  ----------------------------------------------------------------------------*/
34 
35 
36 /*----------------------------------------------------------------------------
37  Private to this module
38  ----------------------------------------------------------------------------*/
39 
40 
41 /*-----------------------------------------------------------------------------
42  Includes
43  ----------------------------------------------------------------------------*/
44 #include "sinfo_dfs.h"
45 #include <cpl.h>
46 #include <math.h>
47 #include "sinfo_error.h"
48 #include "sinfo_utilities.h"
49 #include "sinfo_utils_wrappers.h"
50 #include "sinfo_msg.h"
51 #include "sinfo_globals.h"
52 #include "sinfo_pro_save.h"
53 #include "sinfo_skycor.h"
54 #include "sinfo_file_handling.h"
55 #include <unistd.h>
56 #include <stdio.h>
58 /*---------------------------------------------------------------------------*/
64 /*---------------------------------------------------------------------------*/
65 
66 /* defines */
67 
68 #define FITS_MAGIC_SZ 6
69 
70 int
71 sinfo_frame_is_raw_dark(char * tag);
72 
75 /*---------------------------------------------------------------------------*/
82 /*---------------------------------------------------------------------------*/
83 cpl_frameset *
84 sinfo_frameset_extract(const cpl_frameset *frames,
85  const char *tag)
86 {
87  cpl_frameset *subset = NULL;
88  const cpl_frame *f;
89 
90 
91 
92  assure( frames != NULL, CPL_ERROR_ILLEGAL_INPUT, "Null frameset" );
93  assure( tag != NULL, CPL_ERROR_ILLEGAL_INPUT, "Null tag" );
94 
95  subset = cpl_frameset_new();
96 
97  for (f = cpl_frameset_find_const(frames, tag);
98  f != NULL;
99  f = cpl_frameset_find_const(frames, NULL)) {
100 
101  cpl_frameset_insert(subset, cpl_frame_duplicate(f));
102  }
103  cleanup:
104  return subset;
105 }
106 
107 
108 
114 int sinfo_print_rec_status(const int val) {
115  if(cpl_error_get_code() != CPL_ERROR_NONE) {
116  sinfo_msg_error("Recipe status at %d",val);
117  sinfo_msg_error("%s",(const char*) cpl_error_get_message());
118  sinfo_msg_error("%s",(const char*) cpl_error_get_where());
119  return -1;
120  }
121  return 0;
122 }
123 
124 
141 cpl_vector*
142 sinfo_vector_clip(const cpl_vector* vinp,
143  const double kappa,
144  const int n,
145  const int method)
146 {
147  cpl_vector* vout=NULL;
148  cpl_vector* vtmp=NULL;
149  int size=0;
150  int j=0;
151  register int i=0;
152 
153  double mean=0;
154  double median=0;
155  double stdev=0;
156  double* pt=NULL;
157  double* po=NULL;
158 
159  cknull(vinp,"Null input vector");
160  check_nomsg(vout=cpl_vector_duplicate(vinp));
161  check_nomsg(mean=cpl_vector_get_mean(vout));
162  check_nomsg(median=cpl_vector_get_median_const(vout));
163  check_nomsg(stdev=cpl_vector_get_stdev(vout));
164  check_nomsg(pt=cpl_vector_get_data(vtmp));
165 
166  if(method == 0) {
167  /*
168  are rejected
169  values ||val-mean|| > kappa*sigma
170  */
171  for(j=0;j<n;j++) {
172 
173  check_nomsg(cpl_vector_sort(vout,1)); /* sort by increasing data */
174  check_nomsg(po=cpl_vector_get_data(vout));
175 
176  if( (size > 1) && (fabs(po[size-1]-mean) > kappa*stdev)) {
177 
178  size--;
179  check_nomsg(vtmp=cpl_vector_new(size));
180  check_nomsg(pt=cpl_vector_get_data(vtmp));
181  for(i=0;i<size;i++) {
182  pt[i]=po[i];
183  }
184  check_nomsg(cpl_vector_delete(vout));
185  check_nomsg(vout=cpl_vector_duplicate(vtmp));
186  check_nomsg(cpl_vector_delete(vtmp));
187 
188  check_nomsg(mean=cpl_vector_get_mean(vout));
189  check_nomsg(stdev=cpl_vector_get_stdev(vout));
190 
191  }
192 
193  }
194 
195  } else {
196  /*
197  are rejected
198  values ||val-median|| > kappa*sigma
199  */
200 
201 
202  for(j=0;j<n;j++) {
203 
204  check_nomsg(cpl_vector_sort(vout,1)); /* sort by increasing data */
205  check_nomsg(po=cpl_vector_get_data(vout));
206 
207  if( (size > 1) && (fabs(po[size-1]-median) > kappa*stdev)) {
208 
209  size--;
210  check_nomsg(vtmp=cpl_vector_new(size));
211  check_nomsg(pt=cpl_vector_get_data(vtmp));
212  for(i=0;i<size;i++) {
213  pt[i]=po[i];
214  }
215  check_nomsg(cpl_vector_delete(vout));
216  check_nomsg(vout=cpl_vector_duplicate(vtmp));
217  check_nomsg(cpl_vector_delete(vtmp));
218 
219  check_nomsg(median=cpl_vector_get_median_const(vout));
220  check_nomsg(stdev=cpl_vector_get_stdev(vout));
221 
222  }
223 
224  }
225 
226 
227 
228 
229  }
230  return vout;
231  cleanup:
232  return NULL;
233 
234 
235 }
236 
237 /*-------------------------------------------------------------------------*/
238 /*-------------------------------------------------------------------------*/
248 /*--------------------------------------------------------------------------*/
249 
250 int sinfo_vector_dindgen(cpl_vector** v)
251 {
252 
253  int sz=0;
254  int i=0;
255 
256  cknull(*v,"Null input vector");
257  check(sz=cpl_vector_get_size(*v),"Getting size of a vector");
258 
259  for(i=0;i<sz;i++) {
260  cpl_vector_set(*v,i,(double)i);
261  }
262 
263  return 0;
264  cleanup:
265  return -1;
266 
267 }
268 
269 /*-------------------------------------------------------------------------*/
280 /*--------------------------------------------------------------------------*/
281 
282 int sinfo_is_fits_file(const char *filename)
283 {
284  FILE *fp ;
285  char *magic ;
286  int isfits ;
287 
288  if ((fp = fopen(filename, "r"))==NULL) {
289  sinfo_msg_error("cannot open file [%s]", filename) ;
290  return -1 ;
291  }
292 
293  magic = cpl_calloc(FITS_MAGIC_SZ+1, sizeof(char)) ;
294  (void)fread(magic, 1, FITS_MAGIC_SZ, fp) ;
295  (void)fclose(fp) ;
296  magic[FITS_MAGIC_SZ] = (char)0 ;
297  if (strstr(magic, "SIMPLE")!=NULL)
298  isfits = 1 ;
299  else
300  isfits = 0 ;
301  cpl_free(magic) ;
302  return isfits ;
303 }
304 
305 /*---------------------------------------------------------------------------*/
311 /*---------------------------------------------------------------------------*/
312 cpl_error_code
313 sinfo_table_correl(cpl_table * t1, cpl_table* t2, cpl_table* range,double* xcor)
314 {
315 
316  double wsr=0;
317  double wer=0;
318  int nr=0;
319  int i=0;
320  int status=0;
321  int nrows=0;
322  double mean=0;
323  double prod=0;
324 
325  cpl_table* tmp_t1=NULL;
326  cpl_table* tmp_t2=NULL;
327 
328  check_nomsg(nr=cpl_table_get_nrow(range));
329  for(i=0;i<nr;i++) {
330  wsr=cpl_table_get_double(range,"WSTART",i,&status);
331  wer=cpl_table_get_double(range,"WEND",i,&status);
332  cpl_table_and_selected_double(t1,"WAVE",CPL_NOT_LESS_THAN,wsr);
333  cpl_table_and_selected_double(t1,"WAVE",CPL_NOT_GREATER_THAN,wer);
334  tmp_t1=cpl_table_extract_selected(t1);
335  cpl_table_and_selected_double(t2,"WAVE",CPL_NOT_LESS_THAN,wsr);
336  cpl_table_and_selected_double(t2,"WAVE",CPL_NOT_GREATER_THAN,wer);
337  tmp_t2=cpl_table_extract_selected(t2);
338  cpl_table_duplicate_column(tmp_t1,"INT1",tmp_t1,"INT");
339  cpl_table_duplicate_column(tmp_t1,"INT2",tmp_t2,"INT");
340  cpl_table_multiply_columns(tmp_t1,"INT1","INT2");
341  mean=cpl_table_get_column_mean(tmp_t1,"INT1");
342  nrows=cpl_table_get_nrow(tmp_t1);
343  prod=mean*nrows;
344  *xcor+=prod;
345  }
346 
347  cleanup:
348  return cpl_error_get_code();
349 }
355 /*----------------------------------------------------------------------------*/
356 cpl_error_code
357 sinfo_frameset_merge(cpl_frameset * set1, cpl_frameset* set2)
358 {
359 
360  cpl_frame* frm_dup=NULL;
361 
362  passure(set1 != NULL, "Wrong input set");
363 
364  cpl_frameset_iterator* it = cpl_frameset_iterator_new(set2);
365  cpl_frame *frm_tmp = cpl_frameset_iterator_get(it);
366 
367  while (frm_tmp != NULL)
368  {
369  frm_dup=cpl_frame_duplicate(frm_tmp);
370  cpl_frameset_insert(set1,frm_dup);
371 
372  cpl_frameset_iterator_advance(it, 1);
373  frm_tmp = cpl_frameset_iterator_get(it);
374 
375  }
376  cpl_frameset_iterator_delete(it);
377 
378  cleanup:
379  return cpl_error_get_code();
380 }
381 
382 /*----------------------------------------------------------------------------*/
390 /*----------------------------------------------------------------------------*/
391 
392 cpl_error_code
393 sinfo_extract_frames_group_type(const cpl_frameset * set,
394  cpl_frameset** ext,
395  cpl_frame_group type)
396 {
397 
398  cpl_frame* frm_dup=NULL;
399  cpl_frame_group g;
400 
401  check_nomsg(*ext = cpl_frameset_new());
402 
403  cpl_frameset_iterator* it = cpl_frameset_iterator_new(set);
404  const cpl_frame *frm_tmp = cpl_frameset_iterator_get_const(it);
405 
406  while (frm_tmp != NULL)
407  {
408  g=cpl_frame_get_group(frm_tmp);
409  if(g == type) {
410  frm_dup=cpl_frame_duplicate(frm_tmp);
411  cpl_frameset_insert(*ext,frm_dup);
412  sinfo_msg_debug("group %d insert file %s ",
413  type,cpl_frame_get_filename(frm_dup));
414  }
415 
416  cpl_frameset_iterator_advance(it, 1);
417  frm_tmp = cpl_frameset_iterator_get_const(it);
418 
419  }
420  cpl_frameset_iterator_delete(it);
421 
422  cleanup:
423  return cpl_error_get_code();
424 }
425 
434 int
435 sinfo_get_pupil_shift(cpl_imagelist* iml,const int n,cpl_table** qclog_tbl)
436 {
437  cpl_size max_ima_x=0;
438  cpl_size max_ima_y=0;
439  int nx=0;
440  int ny=0;
441 
442  double xshift=0;
443  double yshift=0;
444 
445  double max_ima_cx=0;
446  double max_ima_cy=0;
447 
448  cpl_image* img=NULL;
449  cpl_image* img_dup=NULL;
450 
451  char key_name[FILE_NAME_SZ];
452 
453  sinfo_imagelist_reject_value(iml,CPL_VALUE_NAN);
454  img=cpl_imagelist_collapse_median_create(iml);
455  nx=cpl_image_get_size_x(img);
456  ny=cpl_image_get_size_y(img);
457 
458  img_dup=cpl_image_duplicate(img);
459  //sinfo_clean_nan(&img_dup);
460  cpl_image_get_maxpos(img_dup,&max_ima_x,&max_ima_y);
461  max_ima_cx=cpl_image_get_centroid_x_window(img_dup,1,1,nx,ny);
462  max_ima_cy=cpl_image_get_centroid_y_window(img_dup,1,1,nx,ny);
463  cpl_image_delete(img_dup);
464 
465 
466  xshift=max_ima_cx-(double)nx/2;
467  yshift=max_ima_cy-(double)ny/2;
468 
469  snprintf(key_name,sizeof(key_name),"%s%d%s","QC PUPIL",n," SHIFTX");
470  sinfo_qclog_add_double(*qclog_tbl,key_name,xshift,
471  "X shift centroid - center image","%f");
472 
473  snprintf(key_name,sizeof(key_name),"%s%d%s","QC PUPIL",n," SHIFTY");
474  sinfo_qclog_add_double(*qclog_tbl,key_name,yshift,
475  "Y shift centroid - center image","%f");
476  cpl_image_delete(img);
477 
478  return 0;
479 }
480 
481 
482 
489 int sinfo_get_strehl_type(cpl_frameset* sof)
490 {
491  int strehl_sw=0;
492  int nobs=0;
493 
494  cpl_frameset* obs=NULL;
495 
496  obs = cpl_frameset_new();
497 
498  sinfo_contains_frames_kind(sof,obs,PRO_OBS_PSF);
499 
500  nobs=cpl_frameset_get_size(obs);
501  if (nobs < 1) {
502  sinfo_contains_frames_kind(sof,obs,PRO_OBS_STD);
503  nobs=cpl_frameset_get_size(obs);
504  }
505 
506  nobs=cpl_frameset_get_size(obs);
507 
508  if (nobs < 1) {
509  return 0;
510  } else {
511  float* pix_scale=cpl_calloc(nobs,sizeof(float));
512 
513  for(int i=0;i<nobs;i++) {
514  cpl_frame* frame=cpl_frameset_get_frame(obs,i);
515  cpl_propertylist* plist=cpl_propertylist_load(cpl_frame_get_filename(frame),0);
516  pix_scale[i]=sinfo_pfits_get_pixscale(plist);
517  cpl_propertylist_delete(plist);
518  }
519  if(sinfo_pix_scale_isnot_const(pix_scale,nobs)) {
520  strehl_sw=1;
521  }
522  cpl_free(pix_scale);
523  }
524  cpl_frameset_delete(obs);
525 
526  return strehl_sw;
527 
528 }
529 
536 double sinfo_get_wave_cent(const char* band)
537 {
538  double lam=0.;
539  if (strcmp(band,"H+K") == 0) {
540  lam=1.950;
541  } else if (strcmp(band,"K") == 0) {
542  lam=2.175;
543  } else if (strcmp(band,"J") == 0) {
544  lam=1.225;
545  } else if (strcmp(band,"H") == 0) {
546  lam=1.675;
547  }
548  return lam;
549 
550 }
551 
560 int sinfo_pix_scale_isnot_const(float* pix_scale, const int n) {
561  int i=0;
562  float eps=0.0001;
563  float ref=pix_scale[0];
564 
565  for(i=1;i<n;i++) {
566  if(fabs(pix_scale[i]-ref) > eps) return 1;
567  }
568  return 0;
569 }
570 
571 
579 const char* sinfo_get_pix_scale(float ps) {
580 
581  const char* key_value;
582  float eps=0.0001;
583 
584  if(fabs(ps - 0.025) < eps) {
585  key_value="0.025";
586  }
587  else if (fabs(ps - 0.1) < eps) {
588  key_value="0.1";
589  }
590  else if (fabs(ps - 0.25) < eps) {
591  key_value="0.25";
592  }
593  else if (fabs(ps - 1.0) < eps) {
594  key_value="pupil";
595  } else {
596  sinfo_msg_error("ps=%f. Failed to set pixel scale",ps);
597  return NULL;
598  }
599 
600  return key_value;
601 }
602 
603 
619 int sinfo_get_clean_mean_window(cpl_image* img,
620  int llx, int lly, int urx, int ury,
621  const int kappa, const int nclip,
622  double* local_clean_mean,
623  double* clean_stdev)
624 {
625 
626  double mean=0;
627  double stdev=0;
628 
629  cpl_image* tmp=NULL;
630  cpl_stats* stats=NULL;
631  int i=0;
632 
633  tmp=cpl_image_extract(img,llx,lly,urx,ury);
634  cpl_image_accept_all(tmp);
635  for(i=0;i<nclip;i++) {
636 
637 
638  cpl_stats_delete(stats);
639  stats = cpl_stats_new_from_image(tmp, CPL_STATS_MEAN | CPL_STATS_STDEV);
640  mean = cpl_stats_get_mean(stats);
641  stdev = cpl_stats_get_stdev(stats);
642 
643  double threshold=kappa*stdev;
644  double lo_cut=mean-threshold;
645  double hi_cut=mean+threshold;
646  cpl_image_accept_all(tmp);
647  cpl_mask* mask=cpl_mask_threshold_image_create(tmp,lo_cut,hi_cut);
648 
649  cpl_mask_not(mask);
650  cpl_image_reject_from_mask(tmp,mask);
651  cpl_mask_delete(mask);
652 
653 
654  }
655  *local_clean_mean=mean;
656  *clean_stdev=stdev;
657  cpl_image_delete(tmp);
658  cpl_stats_delete(stats);
659 
660 
661  return 0;
662 
663 
664 }
670 int sinfo_check_rec_status(const int val) {
671  if(cpl_error_get_code() != CPL_ERROR_NONE) {
672  sinfo_msg_error("error before %d",val);
673  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
674  sinfo_msg_error("%s", (char* ) cpl_error_get_where());
675  return -1;
676  }
677  return 0;
678 }
679 
686 int
687 sinfo_clean_nan(cpl_image** im)
688 {
689  int i=0;
690  int j=0;
691 
692  int nx=cpl_image_get_size_x(*im);
693  int ny=cpl_image_get_size_y(*im);
694  float* data=cpl_image_get_data_float(*im);
695 
696  for(j=0;j<ny;j++) {
697  for(i=0;i<nx;i++) {
698  if(isnan(data[j*nx+i]) != 0) {
699  data[j*nx+i] = 0;
700  }
701  }
702  }
703  return 0;
704 }
705 
715 void
716 sinfo_add_pro_fits_key(cpl_propertylist * plist,
717  char* pro_catg,
718  char* file_name,
719  char* out_name)
720 {
721 
722  char* date=NULL;
723  date = sinfo_get_datetime_iso8601() ;
724 
725  cpl_propertylist_insert_after_string(plist, "EXPTIME",
726  KEY_NAME_PIPEFILE, out_name) ;
727  cpl_propertylist_set_comment(plist, KEY_NAME_PIPEFILE,KEY_HELP_PIPEFILE) ;
728 
729  cpl_propertylist_insert_after_string(plist, "EXPTIME",
730  KEY_NAME_HPRO_DID, KEY_VALUE_HPRO_DID) ;
731  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DID,KEY_HELP_HPRO_DID) ;
732 
733  cpl_propertylist_insert_after_string(plist, "EXPTIME",
734  KEY_NAME_HPRO_TYPE, "REDUCED") ;
735  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_TYPE, KEY_HELP_HPRO_TYPE) ;
736 
737  cpl_propertylist_insert_after_string(plist, "EXPTIME",
738  KEY_NAME_HPRO_CATG, pro_catg) ;
739  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_CATG, KEY_HELP_HPRO_CATG);
740 
741  cpl_propertylist_insert_after_string(plist, "EXPTIME",
742  KEY_NAME_HPRO_STATUS, "OK") ;
743  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_STATUS,KEY_HELP_HPRO_CATG);
744 
745  cpl_propertylist_insert_after_string(plist, "EXPTIME",
746  KEY_NAME_HPRO_DATE, date) ;
747  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DATE, KEY_HELP_HPRO_DATE);
748 
749  cpl_propertylist_insert_after_string(plist, "EXPTIME",
750  KEY_NAME_HPRO_RECID, file_name) ;
751  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_RECID,KEY_HELP_HPRO_RECID);
752 
753  cpl_propertylist_insert_after_string(plist, "EXPTIME",
754  KEY_NAME_HPRO_DRSID, PACKAGE_VERSION);
755  cpl_propertylist_set_comment(plist, KEY_NAME_HPRO_DRSID,KEY_HELP_HPRO_DRSID);
756 
757 
758 }
759 /*---------------------------------------------------------------------------*/
766 /*---------------------------------------------------------------------------*/
767 int sinfo_compare_tags(
768  const cpl_frame * frame1,
769  const cpl_frame * frame2)
770 {
771  char * v1 ;
772  char * v2 ;
773 
774  /* Test entries */
775  if (frame1==NULL || frame2==NULL) return -1 ;
776 
777  /* Get the tags */
778  if ((v1 = (char*)cpl_frame_get_tag(frame1)) == NULL) return -1 ;
779  if ((v2 = (char*)cpl_frame_get_tag(frame2)) == NULL) return -1 ;
780 
781  /* Compare the tags */
782  if (strcmp(v1, v2)) return 0 ;
783  else return 1 ;
784 }
785 
794 int sinfo_extract_raw_pinhole_frames(cpl_frameset * sof, cpl_frameset** raw)
795 {
796 
797 
798 
799  int nsof=0;
800  int i=0;
801  nsof = cpl_frameset_get_size(sof);
802  for (i=0 ; i<nsof ; i++) {
803  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
804  char* name= (char*) cpl_frame_get_filename(frame);
805  if(sinfo_is_fits_file(name) == 1) {
806  /* to go on the file must exist */
807  if(cpl_frame_get_tag(frame) != NULL) {
808  /* If the frame has a tag we process it. Else it is an object */
809  char* tag= (char*) cpl_frame_get_tag(frame);
810  if(sinfo_frame_is_pinhole_lamp(tag) == 1) {
811  cpl_frameset_insert(*raw,frame);
812  }
813  }
814  }
815  }
816  return 0;
817 }
818 
819 
820 int sinfo_get_ins_set(char* band,int* ins_set){
821 
822  if (strcmp(band,"H") == 0) {
823  *ins_set = 0;
824  }
825  else if (strcmp(band,"H+K") == 0) {
826  *ins_set = 1;
827  }
828  else if (strcmp(band,"K") == 0) {
829  *ins_set = 2;
830  }
831  else if (strcmp(band,"J") == 0) {
832  *ins_set = 3;
833  }
834  return 0;
835 
836 
837 }
838 
839 
840 int sinfo_remove_qc_frames(cpl_frameset* sof,cpl_frameset** raw)
841 {
842 
843  int i=0;
844 
845  int nsof = cpl_frameset_get_size(sof);
846  for (i=0 ; i<nsof ; i++) {
847  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
848  char* name= (char*) cpl_frame_get_filename(frame);
849  /* sinfo_msg("name=%s",name); */
850  if(sinfo_is_fits_file(name) == 1) {
851  /* sinfo_msg("\t exist "); */
852  /* to go on the file must exist */
853  if(cpl_frame_get_tag(frame) != NULL) {
854  /* If the frame has a tag we process it. Else it is an object */
855  char* tag= (char*) cpl_frame_get_tag(frame);
856  /* sinfo_msg("\t tag %s\n ",tag); */
857  if(strstr(tag,"QC") != NULL) {
858  /* sinfo_msg("remove frame %s\n",name); */
859  cpl_frameset_erase(*raw,tag);
860  }
861  }
862  } else {
863  /* sinfo_msg("remove frame\n"); */
864  cpl_frameset_erase_frame(*raw,frame);
865  }
866  }
867  return 0;
868 
869 }
870 
871 
872 int sinfo_contains_frames_kind(cpl_frameset * sof,
873  cpl_frameset* raw,
874  const char* type)
875 {
876 
877  int i=0;
878  int nsof = cpl_frameset_get_size(sof);
879  for (i=0 ; i<nsof ; i++) {
880  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
881  char* name= (char*) cpl_frame_get_filename(frame);
882  if(sinfo_is_fits_file(name) == 1) {
883  /* to go on the file must exist */
884  if(cpl_frame_get_tag(frame) != NULL) {
885  /* If the frame has a tag we process it. Else it is an object */
886  char* tag= (char*) cpl_frame_get_tag(frame);
887  /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
888  if(strstr(tag,type) != NULL) {
889  /* sinfo_msg("Match name=%s tag=%s type=%s\n",name,tag,type); */
890  cpl_frame* frame_dup = cpl_frame_duplicate(frame);
891  cpl_frameset_insert(raw,frame_dup);
892  /* sinfo_msg("inserted\n"); */
893  }
894  }
895  }
896  }
897  return 0;
898 }
899 
900 
901 
902 
903 int sinfo_is_fibres_on_off(cpl_frameset * sof,
904  cpl_frameset* raw)
905 {
906 
907  int i=0;
908  int nsof = cpl_frameset_get_size(sof);
909 
910  for (i=0 ; i<nsof ; i++) {
911  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
912  char* name= (char*) cpl_frame_get_filename(frame);
913  if(sinfo_is_fits_file(name) == 1) {
914  /* to go on the file must exist */
915  if(cpl_frame_get_tag(frame) != NULL) {
916  /* If the frame has a tag we process it. Else it is an object */
917  char* tag= (char*) cpl_frame_get_tag(frame);
918  /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
919  if( strcmp(tag,PRO_FIBRE_NS_STACKED ) == 0) {
920  /* sinfo_msg("Match name=%s tag=%s type=%s\n",name,tag); */
921  cpl_frame* frame_dup = cpl_frame_duplicate(frame);
922  cpl_frameset_insert(raw,frame_dup);
923  /* sinfo_msg("inserted\n"); */
924  }
925  }
926  }
927  }
928  return 0;
929 }
930 
931 
932 int sinfo_contains_frames_type(cpl_frameset * sof,
933  cpl_frameset** raw,
934  const char* type)
935 {
936  int i=0;
937  int nsof = cpl_frameset_get_size(sof);
938  for (i=0 ; i<nsof ; i++) {
939  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
940  char* name= (char*) cpl_frame_get_filename(frame);
941  if(sinfo_is_fits_file(name) == 1) {
942  /* to go on the file must exist */
943  if(cpl_frame_get_tag(frame) != NULL) {
944  /* If the frame has a tag we process it. Else it is an object */
945  char* tag= (char*) cpl_frame_get_tag(frame);
946  if(strstr(tag,type) != NULL) {
947  /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
948  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
949  cpl_frameset_insert(*raw,frame_dup);
950  }
951  }
952  }
953  }
954  return 0;
955 }
956 
957 int sinfo_extract_raw_frames_type2(cpl_frameset * sof,
958  cpl_frameset** raw,
959  const char* type)
960 {
961 
962 
963  cpl_frame* frame = cpl_frameset_find(sof,type);
964  while(frame) {
965  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
966  cpl_frameset_insert(*raw,frame_dup);
967  frame = cpl_frameset_find(sof,NULL);
968  }
969  return 0;
970 
971 }
972 
973 
974 int sinfo_extract_raw_frames_type1(cpl_frameset * sof,
975  cpl_frameset* raw,
976  const char* type)
977 {
978 
979  cpl_frame* frame = cpl_frameset_find(sof,type);
980  while(frame) {
981  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
982  cpl_frameset_insert(raw,frame_dup);
983  frame = cpl_frameset_find(sof,NULL);
984  }
985  return 0;
986 
987 }
988 
989 int sinfo_extract_raw_frames_type(cpl_frameset * sof,
990  cpl_frameset** raw,
991  const char* type)
992 {
993  char tag[FILE_NAME_SZ];
994  char name[FILE_NAME_SZ];
995  int i=0;
996  int nsof = cpl_frameset_get_size(sof);
997  for (i=0 ; i<nsof ; i++) {
998  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
999  strcpy(name, cpl_frame_get_filename(frame));
1000  if(sinfo_is_fits_file(name) == 1) {
1001  /* to go on the file must exist */
1002  if(cpl_frame_get_tag(frame) != NULL) {
1003  /* If the frame has a tag we process it. Else it is an object */
1004  strcpy(tag,cpl_frame_get_tag(frame));
1005  if(strcmp(tag,type) == 0) {
1006  /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
1007  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1008 
1009  cpl_frameset_insert(*raw,frame_dup);
1010  }
1011  }
1012  }
1013  }
1014  return 0;
1015 }
1016 
1017 int sinfo_extract_frames_type(cpl_frameset * sof,
1018  cpl_frameset * raw,
1019  const char* type)
1020 {
1021 
1022  int i=0;
1023  int nsof = cpl_frameset_get_size(sof);
1024  for (i=0 ; i<nsof ; i++) {
1025  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1026  char* name= (char*) cpl_frame_get_filename(frame);
1027  if(sinfo_is_fits_file(name) == 1) {
1028  /* to go on the file must exist */
1029  if(cpl_frame_get_tag(frame) != NULL) {
1030  /* If the frame has a tag we process it. Else it is an object */
1031  char* tag= (char*) cpl_frame_get_tag(frame);
1032  if(strcmp(tag,type) == 0) {
1033  /* sinfo_msg("name=%s tag=%s type=%s\n",name,tag,type); */
1034  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1035  cpl_frameset_insert(raw,frame_dup);
1036  }
1037  }
1038  }
1039  }
1040  return 0;
1041 }
1042 
1043 
1044 int sinfo_extract_obj_frames(cpl_frameset * sof, cpl_frameset* obj)
1045 {
1046 
1047  int i=0;
1048  int nsof = cpl_frameset_get_size(sof);
1049  for (i=0 ; i<nsof ; i++) {
1050  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1051  char* name= (char*) cpl_frame_get_filename(frame);
1052  if(sinfo_is_fits_file(name) ==1) {
1053  /* to go on the file must exist */
1054  if(cpl_frame_get_tag(frame) != NULL) {
1055  /* If the frame has a tag we process it. Else it is an object */
1056  char* tag= (char*) cpl_frame_get_tag(frame);
1057  if(sinfo_tag_is_obj(tag) == 1) {
1058  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1059  cpl_frameset_insert(obj,frame_dup);
1060  }
1061  }
1062  }
1063  }
1064 
1065  return 0;
1066 }
1067 
1068 
1069 int sinfo_extract_obj_products(cpl_frameset * sof, cpl_frameset* obj)
1070 {
1071 
1072  int i=0;
1073  int nsof = cpl_frameset_get_size(sof);
1074  for (i=0 ; i<nsof ; i++) {
1075  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1076  char* name= (char*) cpl_frame_get_filename(frame);
1077  if(sinfo_is_fits_file(name) ==1) {
1078  /* to go on the file must exist */
1079  if(cpl_frame_get_tag(frame) != NULL) {
1080  /* If the frame has a tag we process it. Else it is an object */
1081  char* tag= (char*) cpl_frame_get_tag(frame);
1082  if(sinfo_tag_is_objpro(tag) == 1) {
1083  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1084  cpl_frameset_insert(obj,frame_dup);
1085  }
1086  }
1087  }
1088  }
1089 
1090  return 0;
1091 }
1092 
1093 int sinfo_extract_on_frames(cpl_frameset * sof, cpl_frameset* on)
1094 {
1095 
1096 
1097  int i=0;
1098  int nsof = cpl_frameset_get_size(sof);
1099  for (i=0 ; i<nsof ; i++) {
1100  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1101  if(sinfo_frame_is_on(frame) ==1) {
1102  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1103  cpl_frameset_insert(on,frame_dup);
1104  }
1105  }
1106 
1107  return 0;
1108 }
1109 
1110 int sinfo_extract_sky_frames(cpl_frameset * sof, cpl_frameset* sky)
1111 {
1112  int i=0;
1113  int nsof = cpl_frameset_get_size(sof);
1114  for (i=0 ; i<nsof ; i++) {
1115  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1116  char* name= (char*) cpl_frame_get_filename(frame);
1117  if(sinfo_is_fits_file(name) ==1) {
1118  /* to go on the file must exist */
1119  if(cpl_frame_get_tag(frame) != NULL) {
1120  /* If the frame has a tag we process it. Else it is an object */
1121  char* tag= (char*) cpl_frame_get_tag(frame);
1122  if(sinfo_tag_is_sky(tag) == 1) {
1123  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1124  cpl_frameset_insert(sky,frame_dup);
1125  }
1126  }
1127  }
1128  }
1129 
1130  return 0;
1131 }
1132 
1133 
1134 
1135 int sinfo_extract_off_frames(cpl_frameset * sof, cpl_frameset* off)
1136 {
1137 
1138  int i=0;
1139  int nsof = cpl_frameset_get_size(sof);
1140  for (i=0 ; i<nsof ; i++) {
1141  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1142  if(sinfo_frame_is_on(frame)) {
1143  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1144  cpl_frameset_insert(off,frame_dup);
1145  }
1146  }
1147 
1148  return 0;
1149 }
1150 
1151 int sinfo_extract_mst_frames(cpl_frameset * sof, cpl_frameset* cdb)
1152 {
1153 
1154  int i=0;
1155  int nsof = cpl_frameset_get_size(sof);
1156  for (i=0 ; i<nsof ; i++) {
1157  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1158  char* name= (char*) cpl_frame_get_filename(frame);
1159  if(sinfo_is_fits_file(name) ==1) {
1160  /* to go on the file must exist */
1161  if(cpl_frame_get_tag(frame) != NULL) {
1162  /* If the frame has a tag we process it. Else it is an object */
1163  char* tag= (char*) cpl_frame_get_tag(frame);
1164  if(sinfo_frame_is_cdb(tag) == 1) {
1165  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1166  cpl_frameset_insert(cdb,frame_dup);
1167  }
1168  }
1169  }
1170  }
1171 
1172  return 0;
1173 }
1174 /* TODO: is the following (not used) function really needed, considering that
1175  * cpl offers cpl_frameset_join()?
1176  */
1177 
1178 cpl_frameset* sinfo_frameset_join(cpl_frameset* fs1,cpl_frameset* fs2) {
1179 
1180  cpl_frameset* join=cpl_frameset_duplicate(fs1);
1181  cpl_frameset_join(join,fs2);
1182 
1183  return join;
1184 
1185 }
1186 
1187 
1188 int sinfo_extract_stk_frames(cpl_frameset * sof,
1189  cpl_frameset* res)
1190 {
1191 
1192  int i=0;
1193  int nsof = cpl_frameset_get_size(sof);
1194  for (i=0 ; i<nsof ; i++) {
1195  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1196  char* name= (char*) cpl_frame_get_filename(frame);
1197  if(sinfo_is_fits_file(name) ==1) {
1198  /* to go on the file must exist */
1199  if(cpl_frame_get_tag(frame) != NULL) {
1200  /* If the frame has a tag we process it. Else it is an object */
1201  char* tag= (char*) cpl_frame_get_tag(frame);
1202  if(sinfo_frame_is_stk(tag) == 1) {
1203  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1204  cpl_frameset_insert(res,frame_dup);
1205  }
1206  }
1207  }
1208  }
1209 
1210  return 0;
1211 }
1212 
1213 
1214 int
1215 sinfo_extract_preoptic_frames(cpl_frameset * sof,
1216  cpl_frameset** res,
1217  const char* val)
1218 {
1219 
1220 
1221  int nsof = cpl_frameset_get_size(sof);
1222  for (int i=0 ; i<nsof ; i++) {
1223  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1224  char* name= (char*) cpl_frame_get_filename(frame);
1225  if(sinfo_is_fits_file(name) ==1) {
1226  if(sinfo_frame_is_preoptic(frame,val) == 1) {
1227  cpl_frame* frame_dup=cpl_frame_duplicate(frame);
1228  cpl_frameset_insert(*res,frame_dup);
1229  }
1230  }
1231  }
1232 
1233  return 0;
1234 }
1235 
1236 int sinfo_extract_raw_stack_frames(cpl_frameset * sof, cpl_frameset** pro)
1237 {
1238 
1239  int i=0;
1240  int nsof = cpl_frameset_get_size(sof);
1241 
1242  for (i=0 ; i<nsof ; i++) {
1243  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1244  char* name= (char*) cpl_frame_get_filename(frame);
1245  if(sinfo_is_fits_file(name) ==1) {
1246  /* to go on the file must exist */
1247  if(cpl_frame_get_tag(frame) != NULL) {
1248  /* If the frame has a tag we process it. Else it is an object */
1249  char* tag= (char*) cpl_frame_get_tag(frame);
1250  /* sinfo_msg("tag=%s\n",tag); */
1251  if(sinfo_frame_is_raw_stack(tag) == 1) {
1252  cpl_frame* frame_dup = cpl_frame_duplicate(frame);
1253  cpl_frameset_insert(*pro,frame_dup);
1254  }
1255  }
1256  }
1257  }
1258 
1259  return 0;
1260 }
1261 
1262 
1263 int sinfo_extract_raw_slit_frames(cpl_frameset * sof, cpl_frameset** pro)
1264 {
1265 
1266  int i=0;
1267  int nsof = cpl_frameset_get_size(sof);
1268  for (i=0 ; i<nsof ; i++) {
1269  cpl_frame* frame = cpl_frameset_get_frame(sof,i);
1270  char* name= (char*) cpl_frame_get_filename(frame);
1271  if(sinfo_is_fits_file(name) ==1) {
1272  /* to go on the file must exist */
1273  if(cpl_frame_get_tag(frame) != NULL) {
1274  /* If the frame has a tag we process it. Else it is an object */
1275  char* tag= (char*) cpl_frame_get_tag(frame);
1276  if(sinfo_frame_is_slit_lamp(tag) == 1) {
1277  cpl_frameset_insert(*pro,frame);
1278  }
1279  }
1280  }
1281  }
1282 
1283  return 0;
1284 }
1285 
1286 /*---------------------------------------------------------------------------*/
1292 /*---------------------------------------------------------------------------*/
1293 int sinfo_frame_is_raw(char * tag)
1294 {
1295  /* Test entries */
1296  if (tag == NULL) return -1 ;
1297 
1298 
1299  if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
1300  if (!strcmp(tag, RAW_DARK)) return 1 ;
1301 
1302  if (!strcmp(tag, RAW_FLAT_LAMP)) return 1 ;
1303  if (!strcmp(tag, RAW_FLAT_LAMP_DITHER)) return 1 ;
1304 
1305  if (!strcmp(tag, RAW_WAVE_LAMP)) return 1 ;
1306  if (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) return 1 ;
1307 
1308  if (!strcmp(tag, RAW_PINHOLE_LAMP)) return 1 ;
1309 
1310  if (!strcmp(tag, RAW_SLIT_LAMP)) return 1 ;
1311 
1312 
1313  if (!strcmp(tag, RAW_WAVE_NS)) return 1 ;
1314  if (!strcmp(tag, RAW_FLAT_NS)) return 1 ;
1315  if (!strcmp(tag, RAW_FIBRE_LAMP)) return 1 ;
1316  if (!strcmp(tag, RAW_FIBRE_EW)) return 1 ;
1317  if (!strcmp(tag, RAW_FIBRE_NS)) return 1 ;
1318 
1319 
1320  if (!strcmp(tag, RAW_FLAT_SKY)) return 1 ;
1321  if (!strcmp(tag, RAW_FLUX_LAMP)) return 1 ;
1322  if (!strcmp(tag, RAW_PSF_CALIBRATOR)) return 1 ;
1323  if (!strcmp(tag, RAW_FOCUS)) return 1 ;
1324 
1325  if (!strcmp(tag, RAW_STD)) return 1 ;
1326  if (!strcmp(tag, RAW_STD_STAR)) return 1 ;
1327  if (!strcmp(tag, RAW_STD_STAR_DITHER)) return 1 ;
1328  if (!strcmp(tag, RAW_SKY_STD)) return 1 ;
1329  if (!strcmp(tag, RAW_SKY_OH)) return 1 ;
1330  if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) return 1 ;
1331 
1332  if (!strcmp(tag, RAW_PUPIL_LAMP)) return 1 ;
1333  if (!strcmp(tag, RAW_OBJECT_JITTER)) return 1 ;
1334  if (!strcmp(tag, RAW_SKY_JITTER)) return 1 ;
1335  if (!strcmp(tag, RAW_OBJECT_NODDING)) return 1 ;
1336  if (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) return 1 ;
1337  if (!strcmp(tag, RAW_SKY_NODDING)) return 1 ;
1338 
1339 
1340  if (!strcmp(tag, RAW_STD_STAR_DITHER)) return 1 ;
1341  if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) return 1 ;
1342  if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) return 1 ;
1343  if (!strcmp(tag, RAW_SKY_NODDING_DITHER)) return 1 ;
1344 
1345 
1346  return 0 ;
1347 }
1348 
1349 /*---------------------------------------------------------------------------*/
1357 /*---------------------------------------------------------------------------*/
1358 int sinfo_frame_is_raw_stack(char * tag)
1359 {
1360  /* Test entries */
1361  if (tag == NULL) return -1 ;
1362 
1363 
1364  if (!strcmp(tag, PRO_SKY_DUMMY)) return 1 ;
1365 
1366 
1367  if (!strcmp(tag, RAW_WAVE_LAMP)) return 1 ;
1368  if (!strcmp(tag, RAW_WAVE_LAMP_DITHER)) return 1 ;
1369 
1370  if (!strcmp(tag, RAW_WAVE_NS)) return 1 ;
1371  if (!strcmp(tag, RAW_WAVE_NS_DITHER)) return 1 ;
1372 
1373 
1374  if (!strcmp(tag, RAW_FIBRE_NS)) return 1 ;
1375  if (!strcmp(tag, RAW_FIBRE_EW)) return 1 ;
1376 
1377  if (!strcmp(tag, RAW_PSF_CALIBRATOR)) return 1 ;
1378  if (!strcmp(tag, RAW_FIBRE_PSF)) return 1 ;
1379  if (!strcmp(tag, RAW_FIBRE_DARK)) return 1 ;
1380 
1381  if (!strcmp(tag, RAW_FLUX_LAMP)) return 1 ;
1382  if (!strcmp(tag, RAW_FOCUS)) return 1 ;
1383 
1384  if (!strcmp(tag, RAW_PUPIL_LAMP)) return 1 ;
1385  if (!strcmp(tag, RAW_OBJECT_JITTER)) return 1 ;
1386  if (!strcmp(tag, RAW_SKY_JITTER)) return 1 ;
1387  if (!strcmp(tag, RAW_OBJECT_NODDING)) return 1 ;
1388  if (!strcmp(tag, RAW_OBJECT_SKYSPIDER)) return 1 ;
1389  if (!strcmp(tag, RAW_SKY_NODDING)) return 1 ;
1390 
1391  if (!strcmp(tag, RAW_OBJECT_NODDING_DITHER)) return 1 ;
1392  if (!strcmp(tag, RAW_OBJECT_SKYSPIDER_DITHER)) return 1 ;
1393  if (!strcmp(tag, RAW_SKY_NODDING_DITHER)) return 1 ;
1394 
1395 
1396  if (!strcmp(tag, RAW_IMAGE_PRE_OBJECT)) return 1 ;
1397  if (!strcmp(tag, RAW_IMAGE_PRE_SKY)) return 1 ;
1398  if (!strcmp(tag, RAW_STD)) return 1 ;
1399  if (!strcmp(tag, RAW_SKY_STD)) return 1 ;
1400  if (!strcmp(tag, RAW_SKY_OH)) return 1 ;
1401  if (!strcmp(tag, RAW_SKY_PSF_CALIBRATOR)) return 1 ;
1402  if (!strcmp(tag, RAW_STD_STAR)) return 1 ;
1403  if (!strcmp(tag, RAW_SKY)) return 1 ;
1404 
1405  return 0 ;
1406 }
1407 
1408 
1409 /*---------------------------------------------------------------------------*/
1415 /*---------------------------------------------------------------------------*/
1416 int sinfo_frame_is_raw_dark(char * tag)
1417 {
1418  /* Test entries */
1419  if (tag == NULL) return -1 ;
1420 
1421  if (!strcmp(tag, RAW_DARK)) return 1 ;
1422 
1423  return 0 ;
1424 }
1425 
1426 /*---------------------------------------------------------------------------*/
1432 /*---------------------------------------------------------------------------*/
1433 int sinfo_frame_is_slit_lamp(char * tag)
1434 {
1435  /* Test entries */
1436  if (tag == NULL) return -1 ;
1437 
1438  if (!strcmp(tag, RAW_SLIT_LAMP)) return 1 ;
1439 
1440  return 0 ;
1441 }
1442 
1443 
1444 /*---------------------------------------------------------------------------*/
1450 /*---------------------------------------------------------------------------*/
1451 int sinfo_frame_is_pinhole_lamp(char * tag)
1452 {
1453  /* Test entries */
1454  if (tag == NULL) return -1 ;
1455 
1456  if (!strcmp(tag, RAW_PINHOLE_LAMP)) return 1 ;
1457 
1458  return 0 ;
1459 }
1460 
1461 
1462 int sinfo_frame_is_cdb(char * tag)
1463 {
1464  /* Test entries */
1465  if (tag == NULL) return -1 ;
1466  /* For the moment not checked the following:
1467 
1468  PRO_STACKED
1469  PRO_SLIT_ON
1470  PRO_FLUX_LAMP_STACKED
1471  PRO_WAVE_LAMP_STACKED
1472  PRO_PSF_CALIBRATOR_STACKED
1473  PRO_FOCUS_STACKED
1474  PRO_OBJECT_NODDING_STACKED
1475  PRO_OBJECT_SKYSPIDER_STACKED
1476  PRO_SKY_NODDING_STACKED
1477  PRO_STD_NODDING_STACKED
1478  PRO_MASK_CUBE
1479  PRO_PSF
1480  TMP_FOCUS
1481  TMP_FOCUS_ON
1482  TMP_FOCUS_OFF
1483  PRO_FOCUS
1484  PRO_FOCUS_GAUSS
1485  PRO_SPECTRA
1486  PRO_CUBE
1487  PRO_CUBE_COLL
1488  PRO_SLOPEX
1489  PRO_SLOPEY
1490  PRO_MASK_CUBE
1491  PRO_OBJ_CUBE
1492  PRO_BP_COEFF
1493  */
1494 
1495  if (!strcmp(tag, REF_LINE_ARC)) return 1 ;
1496  if (!strcmp(tag, REF_LINE_OH)) return 1 ;
1497  if (!strcmp(tag, PRO_BP_MAP)) return 1 ;
1498  if (!strcmp(tag, PRO_BP_MAP_HP)) return 1 ;
1499  if (!strcmp(tag, PRO_BP_MAP_DI)) return 1 ;
1500  if (!strcmp(tag, PRO_BP_MAP_NO)) return 1 ;
1501  if (!strcmp(tag, PRO_BP_MAP_NL)) return 1 ;
1502  if (!strcmp(tag, PRO_MASTER_BP_MAP)) return 1 ;
1503  if (!strcmp(tag, PRO_MASTER_DARK)) return 1 ;
1504  if (!strcmp(tag, PRO_SLOPE)) return 1 ;
1505  if (!strcmp(tag, PRO_DISTORTION)) return 1 ;
1506  if (!strcmp(tag, PRO_SLITLETS_DISTANCE)) return 1 ;
1507  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
1508  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
1509  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
1510  if (!strcmp(tag, PRO_SLIT_POS)) return 1 ;
1511  if (!strcmp(tag, PRO_SLIT_POS_GUESS)) return 1 ;
1512  if (!strcmp(tag, PRO_WAVE_PAR_LIST)) return 1 ;
1513  if (!strcmp(tag, PRO_WAVE_COEF_SLIT)) return 1 ;
1514  if (!strcmp(tag, PRO_MASTER_LAMP_SPEC)) return 1 ;
1515  if (!strcmp(tag, PRO_MASTER_TWIFLAT)) return 1 ;
1516  if (!strcmp(tag, PRO_COEFF_LIST)) return 1 ;
1517  if (!strcmp(tag, PRO_INDEX_LIST)) return 1 ;
1518  if (!strcmp(tag, PRO_HALO_SPECT)) return 1 ;
1519  if (!strcmp(tag, PRO_FIRST_COL)) return 1 ;
1520  if (!strcmp(tag, PRO_FOCUS)) return 1 ;
1521  if (!strcmp(tag, PRO_WAVE_MAP)) return 1 ;
1522  if (!strcmp(tag, PRO_REF_ATM_REF_CORR)) return 1 ;
1523 
1524  return 0;
1525 
1526 }
1527 
1528 
1529 
1530 
1531 int sinfo_frame_is_stk(char * tag)
1532 {
1533  /* Test entries */
1534  if (tag == NULL) return -1 ;
1535  /* For the moment not checked the following: */
1536 
1537 
1538  if (!strcmp(tag, PRO_SKY_STACKED_DUMMY)) return 1 ;
1539  if (!strcmp(tag, PRO_STACK_SKY_DIST)) return 1 ;
1540  if (!strcmp(tag, PRO_STACK_MFLAT_DIST)) return 1 ;
1541  if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) return 1 ;
1542 
1543 
1544  return 0;
1545 
1546 }
1547 
1548 int sinfo_frame_is_preoptic(cpl_frame* frame,const char* val)
1549 {
1550 
1551  char* file=NULL;
1552  char popt[FILE_NAME_SZ];
1553  cpl_propertylist* plist=NULL;
1554 
1555 
1556  file = cpl_strdup(cpl_frame_get_filename(frame)) ;
1557  if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
1558  sinfo_msg_error( "getting header from reference frame %s",file);
1559  cpl_propertylist_delete(plist) ;
1560  cpl_free(file);
1561  return -1 ;
1562  }
1563 
1564  if (cpl_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
1565  strcpy(popt,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
1566  } else {
1567  sinfo_msg_error("keyword %s does not exist",KEY_NAME_PREOPTICS);
1568  cpl_free(file);
1569  return -1;
1570  }
1571  cpl_propertylist_delete(plist) ;
1572  cpl_free(file);
1573 
1574  if (strstr(val,popt) != NULL) return 1 ;
1575 
1576 
1577  return 0;
1578 
1579 }
1580 
1581 
1582 int sinfo_get_preoptic(const char* file, const char* val)
1583 {
1584 
1585  cpl_propertylist* plist=NULL;
1586 
1587 
1588  if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
1589  sinfo_msg_error( "getting header from reference frame %s",file);
1590  cpl_propertylist_delete(plist) ;
1591  return -1 ;
1592  }
1593 
1594  if (cpl_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
1595  strcpy((char*)val,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
1596  } else {
1597  sinfo_msg_error("keyword %s does not exist",KEY_NAME_PREOPTICS);
1598  return -1;
1599  }
1600  cpl_propertylist_delete(plist) ;
1601 
1602  return 0;
1603 
1604 }
1605 
1606 /*
1607  static int
1608  sinfo_stat_rectangle(cpl_image* img,
1609  const int kappa,
1610  const int nclip,
1611  double *mean,
1612  double *stdev)
1613  {
1614 
1615  double sum=0;
1616  double sum2=0;
1617  double noise=0;
1618 
1619  double* pim=NULL;
1620  int i=0;
1621  int j=0;
1622  int kk=0;
1623  int sx=0;
1624  int sy=0;
1625 
1626  *mean=0;
1627  pim=cpl_image_get_data(img);
1628  kk=0;
1629  for(i=0;i<sx*sy;i++) {
1630  *mean+=pim[i];
1631  }
1632  *mean/=(sx*sy);
1633 
1634  for(i=0;i<sx*sy;i++) {
1635  sum+=(pim[i]-*mean)*(pim[i]-*mean);
1636  }
1637  noise=sqrt(sum/(sx*sy));
1638 
1639 
1640  //clean a bit the bad pixels
1641  for(j=0;j<nclip;j++) {
1642  sum=0;
1643  sum2=0;
1644  kk=0;
1645  for(i=0;i<sx*sy;i++) {
1646  if(fabs(pim[i]-*mean)<kappa*noise) {
1647 
1648  sum +=(pim[i]-*mean)*(pim[i]-*mean);
1649  sum2 += pim[i];
1650  kk+=1;
1651  }
1652  noise=sqrt(sum/kk);
1653  *mean=sum2/kk;
1654 
1655  }
1656 
1657  }
1658  *stdev=noise;
1659 
1660  return 0;
1661 
1662  }
1663  */
1664 
1665 cpl_table* sinfo_compute_gain(cpl_frameset* son, cpl_frameset* sof)
1666 {
1667 
1668 
1669  cpl_frame* frm=NULL;
1670 
1671  cpl_image* img_on1=NULL;
1672  cpl_image* img_on2=NULL;
1673  cpl_image* img_on_dif=NULL;
1674  cpl_image* img_on_sub=NULL;
1675 
1676 
1677  cpl_image* img_of1=NULL;
1678  cpl_image* img_of2=NULL;
1679  cpl_image* img_of_dif=NULL;
1680  cpl_image* img_of_sub=NULL;
1681 
1682  cpl_table* res_tbl=NULL;
1683  cpl_vector* dit_on=NULL;
1684  cpl_vector* dit_of=NULL;
1685  cpl_vector* exptime_on=NULL;
1686  cpl_vector* exptime_of=NULL;
1687  cpl_propertylist* plist=NULL;
1688 
1689  int non=0;
1690  int nof=0;
1691  int nfr=0;
1692  double avg_on1=0;
1693  double avg_on2=0;
1694  double avg_of1=0;
1695  double avg_of2=0;
1696  double std=0;
1697 
1698  double sig_on_dif=0;
1699  double sig_of_dif=0;
1700  char* name=NULL;
1701  int i=0;
1702  int m=0;
1703 
1704  int llx=270;
1705  int lly=1000;
1706  int urx=320;
1707  int ury=1050;
1708  //int zone[4];
1709  double gain=0;
1710  double dit_ref=0;
1711  double dit_tmp=0;
1712  double exptime_ref=0;
1713  double exptime_tmp=0;
1714  int kappa=5;
1715  int nclip=25;
1716  double centre=0;
1717 
1718  non = cpl_frameset_get_size(son);
1719  nof = cpl_frameset_get_size(sof);
1720  nfr = (non <= nof) ? non : nof;
1721 
1722  dit_on=cpl_vector_new(nfr);
1723  dit_of=cpl_vector_new(nfr);
1724  exptime_on=cpl_vector_new(nfr);
1725  exptime_of=cpl_vector_new(nfr);
1726 
1727  for(i=0;i<nfr;i++) {
1728 
1729  frm=cpl_frameset_get_frame(son,i);
1730  name=(char*)cpl_frame_get_filename(frm);
1731  plist=cpl_propertylist_load(name,0);
1732  dit_ref=sinfo_pfits_get_dit(plist);
1733  exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
1734  cpl_propertylist_delete(plist);
1735  cpl_vector_set(dit_on,i,dit_ref);
1736  cpl_vector_set(exptime_on,i,exptime_ref);
1737 
1738  frm=cpl_frameset_get_frame(sof,i);
1739  name=(char*)cpl_frame_get_filename(frm);
1740  plist=cpl_propertylist_load(name,0);
1741  dit_ref=sinfo_pfits_get_dit(plist);
1742  exptime_ref=(double)sinfo_pfits_get_exp_time(plist);
1743  cpl_propertylist_delete(plist);
1744  cpl_vector_set(dit_of,i,dit_ref);
1745  cpl_vector_set(exptime_of,i,exptime_ref);
1746 
1747  }
1748 
1749 
1750  /*
1751  zone[0]=270;
1752  zone[1]=1030;
1753  zone[2]=310;
1754  zone[3]=1060;
1755 
1756 
1757 
1758  zone[0]=20;
1759  zone[1]=2028;
1760  zone[2]=20;
1761  zone[3]=2028;
1762  */
1763 
1764 
1765  check_nomsg(res_tbl=cpl_table_new(nfr));
1766  cpl_table_new_column(res_tbl,"adu", CPL_TYPE_DOUBLE);
1767  cpl_table_new_column(res_tbl,"gain", CPL_TYPE_DOUBLE);
1768 
1769  for(i=0;i<nfr;i++) {
1770  frm=cpl_frameset_get_frame(son,i);
1771  name=(char*)cpl_frame_get_filename(frm);
1772  img_on1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
1773 
1774  frm=cpl_frameset_get_frame(sof,i);
1775  name=(char*)cpl_frame_get_filename(frm);
1776  img_of1=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
1777 
1778 
1779  dit_ref=cpl_vector_get(dit_on,i);
1780  exptime_ref=cpl_vector_get(exptime_on,i);
1781 
1782 
1783  for(m=0;m<nfr; m++) {
1784  if(m != i) {
1785  frm=cpl_frameset_get_frame(son,m);
1786  name=(char*)cpl_frame_get_filename(frm);
1787  dit_tmp=cpl_vector_get(dit_on,m);
1788  exptime_tmp=cpl_vector_get(exptime_on,m);
1789  if(dit_tmp == dit_ref && exptime_tmp == exptime_ref) {
1790  /* sinfo_msg("m=%d i=%d\n",m,i); */
1791  img_on2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
1792  frm=cpl_frameset_get_frame(sof,m);
1793  name=(char*)cpl_frame_get_filename(frm);
1794  img_of2=cpl_image_load(name,CPL_TYPE_DOUBLE,0,0);
1795 
1796  img_on_dif=cpl_image_subtract_create(img_on1,img_on2);
1797  img_of_dif=cpl_image_subtract_create(img_of1,img_of2);
1798 
1799  img_on_sub=cpl_image_extract(img_on_dif,llx,lly,urx,ury);
1800  img_of_sub=cpl_image_extract(img_of_dif,llx,lly,urx,ury);
1801 
1802  sinfo_get_clean_mean_window(img_on1,llx,lly,urx,ury,kappa,
1803  nclip,&avg_on1,&std);
1804  sinfo_get_clean_mean_window(img_on2,llx,lly,urx,ury,kappa,
1805  nclip,&avg_on2,&std);
1806  sinfo_get_clean_mean_window(img_of1,llx,lly,urx,ury,kappa,
1807  nclip,&avg_of1,&std);
1808  sinfo_get_clean_mean_window(img_of2,llx,lly,urx,ury,kappa,
1809  nclip,&avg_of2,&std);
1810  /*
1811  cpl_image_save(img_on_sub,"ima_on_sub.fits",
1812  CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
1813  cpl_image_save(img_of_sub,"ima_of_sub.fits",
1814  CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT);
1815  */
1816  /*
1817  //worse accuracy
1818  sinfo_stat_rectangle(img_on_dif,kappa,nclip,
1819  &centre,&sig_on_dif);
1820  sinfo_stat_rectangle(img_of_dif,kappa,nclip,
1821  &centre,&sig_of_dif);
1822  */
1823 
1824 
1825  //better accuracy
1826  sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
1827  nclip,&centre,&sig_on_dif);
1828  sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
1829  nclip,&centre,&sig_of_dif);
1846  cpl_image_delete(img_on2);
1847  cpl_image_delete(img_of2);
1848  cpl_image_delete(img_on_dif);
1849  cpl_image_delete(img_of_dif);
1850  cpl_image_delete(img_on_sub);
1851  cpl_image_delete(img_of_sub);
1852 
1853  gain=((avg_on1+avg_on2)-(avg_of1+avg_of2))/
1854  ((sig_on_dif*sig_on_dif)-(sig_of_dif*sig_of_dif));
1855 
1856  cpl_table_set_double(res_tbl,"gain",m,gain);
1857  cpl_table_set_double(res_tbl,"adu",m,
1858  ((avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2));
1859  /* sinfo_msg("gain=%f ADU=%f\n",gain,
1860  (avg_on1+avg_on2)/2-(avg_of1+avg_of2)/2);
1861  sinfo_msg("g=%f avg_on1=%f avg_on2=%f",gain,avg_on1,avg_on2);
1862  sinfo_msg("avg_of1=%f avg_of2=%f sig_on_dif=%f sig_of_dif=%f",
1863  avg_of1,avg_of2,sig_on_dif,sig_of_dif);
1864  */
1865 
1866  }
1867  }
1868  }
1869  cpl_image_delete(img_on1);
1870  cpl_image_delete(img_of1);
1871  }
1872 
1873 
1874  /*
1875  sinfo_get_clean_mean_window(img_on_dif,llx,lly,urx,ury,kappa,
1876  nclip,&avg,&sig_on_dif);
1877  sinfo_get_clean_mean_window(img_of_dif,llx,lly,urx,ury,kappa,
1878  nclip,&avg,&sig_of_dif);
1879  */
1880 
1881  cpl_vector_delete(dit_on);
1882  cpl_vector_delete(dit_of);
1883  cpl_vector_delete(exptime_on);
1884  cpl_vector_delete(exptime_of);
1885 
1886  return res_tbl;
1887 
1888  cleanup:
1889  cpl_vector_delete(dit_on);
1890  cpl_vector_delete(dit_of);
1891  cpl_vector_delete(exptime_on);
1892  cpl_vector_delete(exptime_of);
1893  return NULL;
1894 
1895 }
1896 
1897 
1898 /*-------------------------------------------------------------------------*/
1910 /*--------------------------------------------------------------------------*/
1911 
1912 int
1913 sinfo_image_estimate_noise(cpl_image* img,
1914  const int noise_fit,
1915  double* centre,
1916  double* noise)
1917 {
1918 
1919  int nbins=0;
1920 
1921  int xsz=0;
1922  int ysz=0;
1923  int n=0;
1924  int i=0;
1925  int r=0;
1926 
1927  int ndist=0;
1928  double min_fct=HISTO_DIST_TEMPC_MIN_FCT;
1929  double max_fct=HISTO_DIST_TEMPC_MAX_FCT;
1930  double avg_d=0;
1931  double std_d=0;
1932  double hmin=0;
1933  double hmax=0;
1934  double kappa=3;
1935 
1936  double* pdata=NULL;
1937  double* disth=NULL;
1938  double* distx=NULL;
1939 
1940  double peak=0;
1941  double tempc=0;
1942  //double value=0;
1943  double x0=0;
1944  double sigma=0;
1945  double area=0;
1946  double offset=0;
1947  //double mse=0;
1948  //double chired=0;
1949 
1950  cpl_table* data_tbl=NULL;
1951  cpl_table* histo=NULL;
1952  cpl_table* dist=NULL;
1953  cpl_table* min_xi=NULL;
1954  cpl_table* tmp_tbl1=NULL;
1955  cpl_table* tmp_tbl2=NULL;
1956  cpl_vector* vx=NULL;
1957  cpl_vector* vy=NULL;
1958  cpl_vector* sx=NULL;
1959  cpl_vector* sy=NULL;
1960 
1961  // Get Object relevant information
1962  check_nomsg(xsz=cpl_image_get_size_x(img));
1963  check_nomsg(ysz=cpl_image_get_size_y(img));
1964  n=xsz*ysz;
1965  nbins=sqrt(n);
1966  check_nomsg(data_tbl=cpl_table_new(n));
1967  check_nomsg(cpl_table_new_column(data_tbl,"DATA",CPL_TYPE_DOUBLE));
1968 
1969  check_nomsg(pdata=cpl_image_get_data(img));
1970  for(i=0;i<n;i++) {
1971  if(!isnan(pdata[i])) {
1972  cpl_table_set_double(data_tbl,"DATA",r,pdata[i]);
1973  r++;
1974  }
1975  }
1976 
1977  check_nomsg(cpl_table_erase_invalid(data_tbl));
1978  check_nomsg(avg_d=cpl_table_get_column_mean(data_tbl,"DATA"));
1979  check_nomsg(std_d=cpl_table_get_column_stdev(data_tbl,"DATA"));
1980 
1981  cpl_table_save(data_tbl, NULL, NULL, "out_data.fits", CPL_IO_DEFAULT);
1982 
1983  hmin=avg_d-kappa*std_d;
1984  hmax=avg_d+kappa*std_d;
1985  //sinfo_msg("mean=%g stdv=%g",avg_d,std_d);
1986  //sinfo_msg("hmin=%g hmax=%g",hmin,hmax);
1987  //sinfo_msg("Computes histogram");
1988  ck0(sinfo_histogram(data_tbl,nbins,hmin,hmax,&histo),"building histogram");
1989 
1990  //value=(double)(hmax-hmin)/nbins/2.;
1991  //sinfo_msg("value=%10.8f",value);
1992  //cpl_table_save(histo, NULL, NULL, "out_pippo.fits", CPL_IO_DEFAULT0);
1993 
1994  check_nomsg(peak=cpl_table_get_column_max(histo,"HY"));
1995  //sinfo_msg("peak=%f",peak);
1996  sinfo_free_table(&tmp_tbl1);
1997 
1998  check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HY",CPL_EQUAL_TO,peak));
1999 
2000  //cpl_table_save(tmp_tbl1, NULL, NULL, "out_tmp_tbl1.fits", CPL_IO_DEFAULT);
2001 
2002 
2003  check_nomsg(*centre=cpl_table_get_column_mean(tmp_tbl1,"HL"));
2004  //sinfo_msg("Background level=%f",*centre);
2005 
2006  sinfo_free_table(&tmp_tbl1);
2007  check_nomsg(tmp_tbl1=sinfo_extract_table_rows(histo,"HY",
2008  CPL_GREATER_THAN,
2009  peak/HISTO_Y_CUT));
2010  sinfo_free_table(&tmp_tbl2);
2011  check_nomsg(tmp_tbl2=sinfo_extract_table_rows(tmp_tbl1,"HY",
2012  CPL_LESS_THAN,peak));
2013  sinfo_free_table(&tmp_tbl1);
2014 
2015  check_nomsg(tempc=*centre-cpl_table_get_column_min(tmp_tbl2,"HL"));
2016  //sinfo_msg("min HX %f",cpl_table_get_column_min(tmp_tbl2,"HL"));
2017  sinfo_free_table(&tmp_tbl2);
2018  //sinfo_msg("Tempc=%f",tempc);
2019  check_nomsg(dist=sinfo_where_tab_min_max(histo,"HL",
2020  CPL_GREATER_THAN,
2021  *centre-min_fct*tempc,
2022  CPL_NOT_GREATER_THAN,
2023  *centre+max_fct*tempc));
2024 
2025  offset=cpl_table_get_column_min(histo,"HY");
2026  sinfo_free_table(&histo);
2027 
2028 
2029  check_nomsg(ndist=cpl_table_get_nrow(dist));
2030  check_nomsg(cpl_table_cast_column(dist,"HY","HYdouble",CPL_TYPE_DOUBLE));
2031  check_nomsg(disth=cpl_table_get_data_double(dist,"HYdouble"));
2032  check_nomsg(distx=cpl_table_get_data_double(dist,"HL"));
2033  cpl_table_save(dist, NULL, NULL, "out_dist.fits", CPL_IO_DEFAULT);
2034 
2035  //TODO
2036  //gaussfit(distx,disty,dista,nterms=3);
2037  //*noise=dista[2];
2038  *noise=tempc/2;
2039  /* THIS DOES NOT WORK */
2040  //sinfo_msg("FWHM/2=%f",*noise);
2041 
2042  if(noise_fit == 1) {
2043  check_nomsg(vy=cpl_vector_wrap(ndist,disth));
2044  check_nomsg(vx=cpl_vector_wrap(ndist,distx));
2045  check_nomsg(sx=cpl_vector_new(ndist));
2046  check_nomsg(cpl_vector_fill(sx,1.));
2047  check_nomsg(sy=cpl_vector_duplicate(sx));
2048  x0=*centre;
2049  sigma=tempc/2;
2050 
2051  if(CPL_ERROR_NONE != cpl_vector_fit_gaussian(vx,NULL,
2052  vy,NULL,
2053  CPL_FIT_ALL,
2054  &x0,&sigma,&area,&offset,
2055  NULL,NULL,NULL)) {
2056  cpl_error_reset();
2057  }
2058  //sinfo_msg("Gauss fit parameters:"
2059  // "x0=%f sigma=%f area=%f offset=%f mse=%f chired=%f",
2060  // x0,sigma,area,offset,mse,chired);
2061  //sinfo_msg("Background level=%f",*centre);
2062  //sinfo_msg("Noise=%f",sigma);
2063  *noise=sigma;
2064  sinfo_unwrap_vector(&vx);
2065  sinfo_unwrap_vector(&vy);
2066  sinfo_free_my_vector(&sx);
2067  sinfo_free_my_vector(&sy);
2068  }
2069  sinfo_free_table(&dist);
2070 
2071  return 0;
2072 
2073  cleanup:
2074  sinfo_free_table(&min_xi);
2075  sinfo_free_table(&tmp_tbl1);
2076  sinfo_free_table(&tmp_tbl2);
2077  sinfo_free_table(&histo);
2078  sinfo_free_table(&dist);
2079  sinfo_free_table(&data_tbl);
2080  sinfo_free_my_vector(&sx);
2081  sinfo_free_my_vector(&sy);
2082  sinfo_unwrap_vector(&vx);
2083  sinfo_unwrap_vector(&vy);
2084 
2085  return -1;
2086 
2087 }
2088 
2089 
2090 
2091 
2092 
2093 cpl_table* sinfo_compute_linearity(cpl_frameset* son, cpl_frameset* sof)
2094 {
2095 
2096 
2097 
2098  int* status=0;
2099  int non=0;
2100  int nof=0;
2101  int nfr=0;
2102  int i=0;
2103 
2104 
2105  cpl_vector* vec_adl=NULL;
2106  cpl_vector* vec_dit=NULL;
2107  cpl_vector* vec_avg=NULL;
2108  cpl_vector* vec_med=NULL;
2109  cpl_vector* vec_avg_dit=NULL;
2110  cpl_vector* vec_med_dit=NULL;
2111 
2112  double dit=0;
2113  cpl_table* lin_tbl=NULL;
2114 
2115 
2116  non = cpl_frameset_get_size(son);
2117  nof = cpl_frameset_get_size(sof);
2118  nfr = (non <= nof) ? non : nof;
2119 
2120  lin_tbl=cpl_table_new(nfr);
2121  cpl_table_new_column(lin_tbl,"med", CPL_TYPE_DOUBLE);
2122  cpl_table_new_column(lin_tbl,"avg", CPL_TYPE_DOUBLE);
2123  cpl_table_new_column(lin_tbl,"med_dit", CPL_TYPE_DOUBLE);
2124  cpl_table_new_column(lin_tbl,"avg_dit", CPL_TYPE_DOUBLE);
2125  cpl_table_new_column(lin_tbl,"dit", CPL_TYPE_DOUBLE);
2126  vec_med=cpl_vector_new(nfr);
2127  vec_avg=cpl_vector_new(nfr);
2128  vec_med_dit=cpl_vector_new(nfr);
2129  vec_avg_dit=cpl_vector_new(nfr);
2130  vec_dit=cpl_vector_new(nfr);
2131  vec_adl=cpl_vector_new(nfr);
2132  double med_dit=0;
2133  for(i=0;i<nfr;i++) {
2134  cpl_frame* frm=cpl_frameset_get_frame(son,i);
2135  char* name=(char*)cpl_frame_get_filename(frm);
2136  cpl_image* img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
2137  double med_on=cpl_image_get_median(img);
2138  double avg_on=cpl_image_get_mean(img);
2139  cpl_image_delete(img);
2140 
2141  frm=cpl_frameset_get_frame(sof,i);
2142  name=(char*)cpl_frame_get_filename(frm);
2143  img=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
2144  double med_of=cpl_image_get_median(img);
2145  double avg_of=cpl_image_get_mean(img);
2146  cpl_image_delete(img);
2147 
2148  double med=med_on-med_of;
2149  double avg=avg_on-avg_of;
2150  cpl_propertylist* plist=cpl_propertylist_load(name,0);
2151  dit=(double)sinfo_pfits_get_dit(plist);
2152  cpl_propertylist_delete(plist);
2153  double avg_dit=avg/dit;
2154  med_dit=med/dit;
2155 
2156  cpl_vector_set(vec_dit,i,dit);
2157  cpl_vector_set(vec_avg,i,avg);
2158  cpl_vector_set(vec_med,i,med);
2159  cpl_vector_set(vec_avg_dit,i,avg_dit);
2160  cpl_vector_set(vec_med_dit,i,med_dit);
2161 
2162  cpl_table_set_double(lin_tbl,"dit",i,dit);
2163  cpl_table_set_double(lin_tbl,"med",i,med);
2164  cpl_table_set_double(lin_tbl,"avg",i,avg);
2165  cpl_table_set_double(lin_tbl,"med_dit",i,med_dit);
2166  cpl_table_set_double(lin_tbl,"avg_dit",i,avg_dit);
2167 
2168  }
2169  cpl_table_new_column(lin_tbl,"adl", CPL_TYPE_DOUBLE);
2170  med_dit=cpl_vector_get_mean(vec_med_dit);
2171  //avg_dit=cpl_vector_get_mean(vec_avg_dit);
2172 
2173  for(i=0;i<nfr;i++) {
2174  dit = cpl_table_get_double(lin_tbl,"dit",i,status);
2175  cpl_vector_set(vec_adl,i,dit*med_dit);
2176  cpl_table_set_double(lin_tbl,"adl",i,dit*med_dit);
2177  }
2178 
2179  cpl_vector_delete(vec_dit);
2180  cpl_vector_delete(vec_adl);
2181  cpl_vector_delete(vec_avg);
2182  cpl_vector_delete(vec_med);
2183  cpl_vector_delete(vec_avg_dit);
2184  cpl_vector_delete(vec_med_dit);
2185 
2186 
2187  return lin_tbl;
2188 
2189 }
2190 
2191 /*--------------------------------------------------------------------*/
2198 /*--------------------------------------------------------------------*/
2199 int
2200 sinfo_get_ron(cpl_frameset * framelist,
2201  const int ron_xmin,
2202  const int ron_xmax,
2203  const int ron_ymin,
2204  const int ron_ymax,
2205  const int ron_hsize,
2206  const int ron_nsamp,
2207  double** ron)
2208 {
2209  cpl_imagelist * iset =NULL;
2210  cpl_image * tmp_im =NULL;
2211  cpl_size zone[4] ;
2212  double rms =0;
2213  double ndit =0;
2214  cpl_frame * frame =NULL;
2215  int i;
2216  cpl_propertylist* plist=NULL;
2217 
2218  /* Test entries */
2219 
2220  if (framelist == NULL) return -1 ;
2221 
2222  /* Load the current set */
2223  if ((iset = sinfo_new_frameset_to_iset(framelist)) == NULL) {
2224  sinfo_msg_error( "Cannot load the data") ;
2225  return -1 ;
2226  }
2227 
2228  /* Initialise */
2229  zone[0]=ron_xmin;
2230  zone[1]=ron_xmax;
2231  zone[2]=ron_ymin;
2232  zone[3]=ron_ymax;
2233 
2234  /* Loop on all pairs */
2235  for (i=0 ; i<cpl_imagelist_get_size(iset)-1 ; i++) {
2236 
2237  /* Compute the current subtracted image */
2238  if ((tmp_im=cpl_image_subtract_create(cpl_imagelist_get(iset,i),
2239  cpl_imagelist_get(iset, i+1)))
2240  == NULL) {
2241  sinfo_msg_error( "Cannot subtract the images") ;
2242  sinfo_free_imagelist(&iset) ;
2243  return -1 ;
2244  }
2245 
2246  /* Compute the read-out noise */
2247  if (cpl_flux_get_noise_window(tmp_im, zone, ron_hsize,
2248  ron_nsamp, &rms, NULL) != CPL_ERROR_NONE) {
2249  sinfo_msg_error( "Cannot compute the RON") ;
2250  sinfo_free_image(&tmp_im) ;
2251  sinfo_free_imagelist(&iset) ;
2252  return -1 ;
2253  }
2254  sinfo_free_image(&tmp_im) ;
2255  /* Normalise the RON with NDIT */
2256  frame = cpl_frameset_get_frame(framelist, i) ;
2257  cknull_nomsg(plist=cpl_propertylist_load(cpl_frame_get_filename(frame),
2258  0));
2259  ndit=sinfo_pfits_get_ndit(plist);
2260  sinfo_free_propertylist(&plist);
2261 
2262  (*ron)[i] = rms * sqrt(ndit/2.0) ;
2263 
2264  }
2265 
2266  /* Free and return */
2267  sinfo_free_imagelist(&iset) ;
2268  return 0 ;
2269 
2270  cleanup:
2271  sinfo_free_image(&tmp_im);
2272  sinfo_free_imagelist(&iset);
2273  sinfo_free_propertylist(&plist);
2274  return -1;
2275 
2276 }
2277 
2278 
2279 
2280 /*---------------------------------------------------------------------------*/
2286 /*---------------------------------------------------------------------------*/
2287 int sinfo_stack_get_pro_tag(char * tag_in, char* tag_out)
2288 {
2289  /* Test entries */
2290  if (tag_in == NULL) return -1 ;
2291  /* here for the moment we set the same PRO ID as a non stacked frame */
2292  if (strcmp(tag_in,RAW_WAVE_LAMP_DITHER) == 0 ) {
2293  strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
2294  return 0 ;
2295  }
2296 
2297 
2298  if (strcmp(tag_in,RAW_WAVE_LAMP) == 0 ) {
2299  strcpy(tag_out,PRO_WAVE_LAMP_STACKED);
2300  return 0 ;
2301  }
2302 
2303  if (strcmp(tag_in,RAW_WAVE_NS_DITHER) == 0 ) {
2304  strcpy(tag_out,PRO_WAVE_NS_STACKED);
2305  return 0 ;
2306  }
2307 
2308 
2309  if (strcmp(tag_in,RAW_WAVE_NS) == 0 ) {
2310  strcpy(tag_out,PRO_WAVE_NS_STACKED);
2311  return 0 ;
2312  }
2313 
2314 
2315  if (strcmp(tag_in,RAW_FIBRE_LAMP) == 0 ) {
2316  strcpy(tag_out,PRO_FIBRE_LAMP_STACKED);
2317  return 0 ;
2318  }
2319 
2320  if (strcmp(tag_in,RAW_FIBRE_EW) == 0 ) {
2321  strcpy(tag_out,PRO_FIBRE_EW_STACKED);
2322  return 0 ;
2323  }
2324 
2325  if (strcmp(tag_in,RAW_FIBRE_NS) == 0 ) {
2326  strcpy(tag_out,PRO_FIBRE_NS_STACKED);
2327  return 0 ;
2328  }
2329 
2330 
2331  if (strcmp(tag_in,PRO_FIBRE_NS_STACKED_ON) == 0 ) {
2332  strcpy(tag_out,PRO_FIBRE_NS_STACKED);
2333  return 0 ;
2334  }
2335 
2336  if (strcmp(tag_in,PRO_FIBRE_NS_STACKED) == 0 ) {
2337  strcpy(tag_out,PRO_FIBRE_NS_STACKED_DIST);
2338  return 0 ;
2339  }
2340 
2341 
2342  if (strcmp(tag_in,RAW_SLIT_LAMP) == 0 ) {
2343  strcpy(tag_out,PRO_SLIT_LAMP_STACKED);
2344  return 0 ;
2345  }
2346 
2347 
2348  if (strstr(tag_in, "FLUX") != NULL ) {
2349  strcpy(tag_out,PRO_FLUX_LAMP_STACKED);
2350  return 0 ;
2351  }
2352 
2353  if (strstr(tag_in, "PSF") != NULL ) {
2354  strcpy(tag_out,PRO_PSF_CALIBRATOR_STACKED);
2355  return 0 ;
2356  }
2357 
2358 
2359  if (strstr(tag_in, "FOCUS") != NULL ) {
2360  strcpy(tag_out,PRO_FOCUS_STACKED);
2361  return 0 ;
2362  }
2363 
2364  if (strstr(tag_in, "OBJECT_NODDING") != NULL ) {
2365  strcpy(tag_out,PRO_OBJECT_NODDING_STACKED);
2366  return 0 ;
2367  }
2368 
2369  if (strstr(tag_in, "SKY_NODDING") != NULL ) {
2370  strcpy(tag_out,PRO_SKY_NODDING_STACKED);
2371  return 0 ;
2372  }
2373 
2374  if (strstr(tag_in, "STD_NODDING") != NULL ) {
2375  strcpy(tag_out,PRO_STD_NODDING_STACKED);
2376  return 0 ;
2377  }
2378 
2379  if (strstr(tag_in, "OBJECT_SKYSPIDER") != NULL ) {
2380  strcpy(tag_out,PRO_OBJECT_SKYSPIDER_STACKED);
2381  return 0 ;
2382  }
2383 
2384 
2385  if (strstr(tag_in, RAW_STD) != NULL ) {
2386  strcpy(tag_out,PRO_STD_STACKED);
2387  return 0 ;
2388  }
2389 
2390 
2391  if (strstr(tag_in, RAW_SKY_STD) != NULL ) {
2392  strcpy(tag_out,PRO_SKY_STD_STACKED);
2393  return 0 ;
2394  }
2395 
2396  if (strstr(tag_in, RAW_SKY_OH) != NULL ) {
2397  strcpy(tag_out,PRO_SKY_OH_STACKED);
2398  return 0 ;
2399  }
2400 
2401  if (strstr(tag_in, RAW_SKY_PSF_CALIBRATOR) != NULL ) {
2402  strcpy(tag_out,PRO_SKY_PSF_CALIBRATOR_STACKED);
2403  return 0 ;
2404  }
2405 
2406  if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
2407  strcpy(tag_out,PRO_STD_STAR_STACKED);
2408  return 0 ;
2409  }
2410 
2411  if (strstr(tag_in, RAW_STD_STAR) != NULL ) {
2412  strcpy(tag_out,PRO_STD_STAR_DITHER_STACKED);
2413  return 0 ;
2414  }
2415 
2416  if (strstr(tag_in, RAW_SKY) != NULL ) {
2417  strcpy(tag_out,PRO_SKY_STACKED);
2418  return 0 ;
2419  }
2420 
2421  return 1 ;
2422 }
2423 
2424 
2425 int sinfo_is_dark(char * tag)
2426 {
2427  /* Test entries */
2428  if (tag == NULL) return -1 ;
2429 
2430  if (!strcmp(tag, RAW_DARK)) return 1 ;
2431  if (!strcmp(tag, PRO_MASTER_DARK)) return 1 ;
2432  return 0 ;
2433 }
2434 
2435 int sinfo_is_flat_bp(char * tag)
2436 {
2437  /* Test entries */
2438  if (tag == NULL) return -1 ;
2439 
2440  if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
2441  return 0 ;
2442 }
2443 
2444 int sinfo_is_flat_lindet(char * tag)
2445 {
2446  /* Test entries */
2447  if (tag == NULL) return -1 ;
2448 
2449  if (!strcmp(tag, RAW_LINEARITY_LAMP)) return 1 ;
2450  return 0 ;
2451 }
2452 
2453 
2454 int sinfo_blank2dot(const char * in, char* ou)
2455 {
2456  int len=0;
2457  int i=0;
2458 
2459  strcpy(ou,in);
2460  len = strlen(in);
2461  for (i=0;i<len;i++)
2462  {
2463  if (in[i] == ' ') {
2464  ou[i] = '.';
2465  }
2466  }
2467  return 0;
2468 }
2469 
2470 
2471 int sinfo_is_sky_flat(char * tag)
2472 {
2473  /* Test entries */
2474  if (tag == NULL) return -1 ;
2475  if (!strcmp(tag, RAW_FLAT_SKY)) return 1 ;
2476  return 0 ;
2477 }
2478 
2479 
2480 
2481 int sinfo_is_master_flat(char * tag)
2482 {
2483  /* Test entries */
2484  if (tag == NULL) return -1 ;
2485 
2486  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
2487  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
2488  return 0 ;
2489 }
2490 
2491 int sinfo_is_master_flat_dither(char * tag)
2492 {
2493  /* Test entries */
2494  if (tag == NULL) return -1 ;
2495 
2496  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
2497  return 0 ;
2498 }
2499 
2500 /*---------------------------------------------------------------------------*/
2506 /*---------------------------------------------------------------------------*/
2507 int sinfo_is_stack(char * tag)
2508 {
2509  /* Test entries */
2510  if (tag == NULL) return -1 ;
2511 
2512  if (strstr(tag, PRO_STACKED) != NULL) return 1 ;
2513  return 0 ;
2514 }
2515 
2516 int sinfo_is_mflat(char * tag)
2517 {
2518  /* Test entries */
2519  if (tag == NULL) return -1 ;
2520 
2521  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP)) return 1 ;
2522  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP1)) return 1 ;
2523  if (!strcmp(tag, PRO_MASTER_FLAT_LAMP2)) return 1 ;
2524  return 0 ;
2525 }
2526 
2527 
2528 /*---------------------------------------------------------------------------*/
2534 /*---------------------------------------------------------------------------*/
2535 int sinfo_is_psf_calibrator_stacked(char * tag)
2536 {
2537  /* Test entries */
2538  if (tag == NULL) return -1 ;
2539 
2540  if (!strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)) return 1 ;
2541  return 0 ;
2542 }
2543 /*---------------------------------------------------------------------------*/
2549 /*---------------------------------------------------------------------------*/
2550 int sinfo_is_focus_stacked(char * tag)
2551 {
2552  /* Test entries */
2553  if (tag == NULL) return -1 ;
2554 
2555  if (!strcmp(tag, PRO_FOCUS_STACKED)) return 1 ;
2556  return 0 ;
2557 }
2558 
2559 /*---------------------------------------------------------------------------*/
2565 /*---------------------------------------------------------------------------*/
2566 int sinfo_is_lamp_wave_stacked(char * tag)
2567 {
2568  /* Test entries */
2569  if (tag == NULL) return -1 ;
2570 
2571  if (!strcmp(tag, PRO_WAVE_LAMP_STACKED)) return 1 ;
2572  return 0 ;
2573 }
2574 
2575 /*---------------------------------------------------------------------------*/
2581 /*---------------------------------------------------------------------------*/
2582 int sinfo_is_lamp_flux_stacked(char * tag)
2583 {
2584  /* Test entries */
2585  if (tag == NULL) return -1 ;
2586 
2587  if (!strcmp(tag, PRO_FLUX_LAMP_STACKED)) return 1 ;
2588  return 0 ;
2589 }
2590 
2591 /*---------------------------------------------------------------------------*/
2597 /*---------------------------------------------------------------------------*/
2598 int sinfo_is_object_nodding_stacked(char * tag)
2599 {
2600  /* Test entries */
2601  if (tag == NULL) return -1 ;
2602 
2603  if (!strcmp(tag, PRO_OBJECT_NODDING_STACKED)) return 1 ;
2604  return 0 ;
2605 }
2606 
2607 /*---------------------------------------------------------------------------*/
2613 /*---------------------------------------------------------------------------*/
2614 int sinfo_is_object_skyspider_stacked(char * tag)
2615 {
2616  /* Test entries */
2617  if (tag == NULL) return -1 ;
2618 
2619  if (!strcmp(tag, PRO_OBJECT_SKYSPIDER_STACKED)) return 1 ;
2620  return 0 ;
2621 }
2622 
2623 
2624 /*---------------------------------------------------------------------------*/
2630 /*---------------------------------------------------------------------------*/
2631 int sinfo_is_sky_nodding_stacked(char * tag)
2632 {
2633  /* Test entries */
2634  if (tag == NULL) return -1 ;
2635 
2636  if (!strcmp(tag, PRO_SKY_NODDING_STACKED)) return 1 ;
2637  return 0 ;
2638 }
2639 
2640 /*---------------------------------------------------------------------------*/
2646 /*---------------------------------------------------------------------------*/
2647 int sinfo_is_wavemap(char * tag)
2648 {
2649  /* Test entries */
2650  if (tag == NULL) return -1 ;
2651 
2652  if (!strcmp(tag, PRO_WAVE_MAP)) return 1 ;
2653  return 0 ;
2654 }
2655 
2656 /*---------------------------------------------------------------------------*/
2662 /*---------------------------------------------------------------------------*/
2663 int sinfo_is_halosp(char * tag)
2664 {
2665  /* Test entries */
2666  if (tag == NULL) return -1 ;
2667 
2668  if (!strcmp(tag, PRO_HALO_SPECT)) return 1 ;
2669  return 0 ;
2670 }
2671 
2672 /*---------------------------------------------------------------------------*/
2678 /*---------------------------------------------------------------------------*/
2679 int sinfo_is_distlist(char * tag)
2680 {
2681  /* Test entries */
2682  if (tag == NULL) return -1 ;
2683 
2684  if (!strcmp(tag, PRO_SLITLETS_DISTANCE)) return 1 ;
2685  return 0 ;
2686 }
2687 
2688 /*---------------------------------------------------------------------------*/
2694 /*---------------------------------------------------------------------------*/
2695 int sinfo_is_slitpos(char * tag)
2696 {
2697  /* Test entries */
2698  if (tag == NULL) return -1 ;
2699 
2700  if (!strcmp(tag, PRO_SLIT_POS)) return 1 ;
2701  return 0 ;
2702 }
2703 
2704 /*---------------------------------------------------------------------------*/
2710 /*---------------------------------------------------------------------------*/
2711 int sinfo_is_firstcol(char * tag)
2712 {
2713  /* Test entries */
2714  if (tag == NULL) return -1 ;
2715 
2716  if (!strcmp(tag, PRO_FIRST_COL)) return 1 ;
2717  return 0 ;
2718 }
2719 
2720 /*---------------------------------------------------------------------------*/
2726 /*---------------------------------------------------------------------------*/
2727 int sinfo_is_bpmap(char * tag)
2728 {
2729  /* Test entries */
2730  if (tag == NULL) return -1 ;
2731 
2732  if (!strcmp(tag, PRO_BP_MAP)) return 1 ;
2733  return 0 ;
2734 }
2735 
2736 
2737 /*---------------------------------------------------------------------------*/
2746 /*---------------------------------------------------------------------------*/
2747 
2748 int sinfo_get_band(cpl_frame * ref_frame,char * band)
2749 {
2750 
2751  char* ref_file=NULL;
2752  cpl_propertylist* plist=NULL;
2753 
2754  ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
2755  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
2756  sinfo_msg_error( "getting header from reference frame %s",ref_file);
2757  cpl_propertylist_delete(plist) ;
2758  return -1 ;
2759  }
2760 
2761  if (cpl_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
2762  strcpy(band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
2763  /* sinfo_msg("%s value is %s", KEY_NAME_FILT_NAME, band); */
2764 
2765  } else {
2766  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_FILT_NAME);
2767  return -1;
2768  }
2769 
2770  cpl_free(ref_file);
2771  cpl_propertylist_delete(plist);
2772  return 0;
2773 }
2774 
2775 
2776 
2777 
2778 /*---------------------------------------------------------------------------*/
2786 /*---------------------------------------------------------------------------*/
2787 
2788 int sinfo_get_obsname(cpl_frame * ref_frame, const char* obs_name)
2789 {
2790 
2791  char* ref_file=NULL;
2792  cpl_propertylist* plist=NULL;
2793 
2794  ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
2795  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
2796  sinfo_msg_error( "getting header from reference frame %s",ref_file);
2797  cpl_propertylist_delete(plist) ;
2798  return -1 ;
2799  }
2800 
2801  if (cpl_propertylist_has(plist, KEY_NAME_OBS_NAME)) {
2802  strcpy((char*)obs_name, cpl_propertylist_get_string(plist,
2803  KEY_NAME_OBS_NAME));
2804  /* sinfo_msg("%s value is %s", KEY_NAME_OBS_NAME, obs_name); */
2805 
2806  } else {
2807  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_OBS_NAME);
2808  return -1;
2809  }
2810 
2811  cpl_free(ref_file);
2812  cpl_propertylist_delete(plist);
2813  return 0;
2814 }
2815 
2816 
2817 
2818 
2819 
2820 /*---------------------------------------------------------------------------*/
2828 /*---------------------------------------------------------------------------*/
2829 
2830 int sinfo_get_keyvalue_int(cpl_frame * ref_frame, const char* key_name)
2831 {
2832 
2833  char* ref_file=NULL;
2834  cpl_propertylist* plist=NULL;
2835  int result=0;
2836 
2837  ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
2838 
2839  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
2840  sinfo_msg_error( "getting header from reference frame %s",ref_file);
2841  cpl_propertylist_delete(plist) ;
2842  return -1;
2843  }
2844 
2845 
2846  if (cpl_propertylist_has(plist, key_name)) {
2847  result=cpl_propertylist_get_int(plist,key_name);
2848  } else {
2849  sinfo_msg_warning("keyword %s does not exist",key_name);
2850  return -1;
2851  }
2852 
2853  cpl_free(ref_file);
2854  cpl_propertylist_delete(plist);
2855 
2856  return result;
2857 }
2858 
2859 
2860 
2861 /*---------------------------------------------------------------------------*/
2869 /*---------------------------------------------------------------------------*/
2870 
2871 float sinfo_get_keyvalue_float(cpl_frame * ref_frame, const char* key_name)
2872 {
2873 
2874  char* ref_file=NULL;
2875  cpl_propertylist* plist=NULL;
2876  float result=0;
2877 
2878  ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
2879 
2880  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
2881  sinfo_msg_error( "getting header from reference frame %s",ref_file);
2882  cpl_propertylist_delete(plist) ;
2883  return -1;
2884  }
2885 
2886 
2887  if (cpl_propertylist_has(plist, key_name)) {
2888  result=cpl_propertylist_get_float(plist,key_name);
2889  } else {
2890  sinfo_msg_warning("keyword %s does not exist",key_name);
2891  return -1;
2892  }
2893 
2894  cpl_free(ref_file);
2895  cpl_propertylist_delete(plist);
2896 
2897  return result;
2898 }
2899 
2900 
2901 /*---------------------------------------------------------------------------*/
2909 /*---------------------------------------------------------------------------*/
2910 
2911 char sinfo_get_keyvalue_bool(cpl_frame * ref_frame, const char* key_name)
2912 {
2913 
2914  char* ref_file=NULL;
2915  cpl_propertylist* plist=NULL;
2916  int res_val=0;
2917 
2918  ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
2919 
2920  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
2921  sinfo_msg_error( "getting header from reference frame %s",ref_file);
2922  cpl_propertylist_delete(plist) ;
2923  return '0';
2924  }
2925 
2926 
2927  if (cpl_propertylist_has(plist, key_name)) {
2928  res_val=cpl_propertylist_get_bool(plist,key_name);
2929  } else {
2930  sinfo_msg_warning("keyword %s does not exist",key_name);
2931  return '0';
2932  }
2933 
2934  cpl_free(ref_file);
2935  cpl_propertylist_delete(plist);
2936  if(res_val == 1) {
2937  return 'T';
2938  } else {
2939  return 'F';
2940  }
2941 }
2942 
2943 
2944 
2945 
2946 /*---------------------------------------------------------------------------*/
2954 /*---------------------------------------------------------------------------*/
2955 
2956 const char*
2957 sinfo_get_keyvalue_string(cpl_frame * ref_frame, const char* key_name)
2958 {
2959 
2960  char* ref_file=NULL;
2961  cpl_propertylist* plist=NULL;
2962  const char* result=NULL;
2963 
2964  ref_file = cpl_strdup(cpl_frame_get_filename(ref_frame)) ;
2965 
2966  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
2967  sinfo_msg_error( "getting header from reference frame %s",ref_file);
2968  cpl_propertylist_delete(plist) ;
2969  return FALSE;
2970  }
2971 
2972 
2973  if (cpl_propertylist_has(plist, key_name)) {
2974  result=cpl_propertylist_get_string(plist,key_name);
2975  } else {
2976  sinfo_msg_warning("keyword %s does not exist",key_name);
2977  return NULL;
2978  }
2979 
2980  cpl_free(ref_file);
2981  cpl_propertylist_delete(plist);
2982 
2983  return result;
2984 }
2985 
2986 
2987 
2988 double sinfo_get_mjd_obs(cpl_frame * frame)
2989 {
2990  cpl_propertylist* plist=NULL;
2991  const char* file=NULL;
2992 
2993  double mjd_obs=0.;
2994  file = cpl_frame_get_filename(frame) ;
2995 
2996  if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
2997  sinfo_msg_error( "getting header from reference frame %s",file);
2998  sinfo_free_propertylist(&plist) ;
2999  return -1 ;
3000  }
3001 
3002  if (cpl_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
3003  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
3004  } else {
3005  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
3006  sinfo_free_propertylist(&plist) ;
3007  return -1;
3008  }
3009  sinfo_free_propertylist(&plist) ;
3010 
3011  return mjd_obs;
3012 
3013 }
3014 
3015 
3016 
3017 
3018 double sinfo_get_cumoffsetx(cpl_frame * frame)
3019 {
3020  cpl_propertylist* plist=NULL;
3021  char* file=NULL;
3022 
3023  double result=0.;
3024  file = cpl_strdup( cpl_frame_get_filename(frame)) ;
3025 
3026  if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
3027  sinfo_msg_error( "getting header from reference frame %s",file);
3028  cpl_propertylist_delete(plist) ;
3029  cpl_free(file);
3030  return -1 ;
3031  }
3032 
3033  if (cpl_propertylist_has(plist, KEY_NAME_CUMOFFX)) {
3034  result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFX);
3035  } else {
3036  sinfo_msg_error("keyword %s does not exist",KEY_NAME_CUMOFFX);
3037  cpl_propertylist_delete(plist) ;
3038  return -1;
3039  }
3040  cpl_propertylist_delete(plist) ;
3041  cpl_free(file);
3042 
3043  return result;
3044 
3045 }
3046 
3047 
3048 
3049 
3050 double sinfo_get_cumoffsety(cpl_frame * frame)
3051 {
3052  cpl_propertylist* plist=NULL;
3053  char* file=NULL;
3054 
3055  double result=0.;
3056  file = cpl_strdup( cpl_frame_get_filename(frame)) ;
3057 
3058  if ((cpl_error_code)((plist = cpl_propertylist_load(file, 0)) == NULL)) {
3059  sinfo_msg_error( "getting header from reference frame %s",file);
3060  cpl_propertylist_delete(plist) ;
3061  cpl_free(file);
3062  return -1 ;
3063  }
3064 
3065  if (cpl_propertylist_has(plist, KEY_NAME_CUMOFFY)) {
3066  result=cpl_propertylist_get_double(plist, KEY_NAME_CUMOFFY);
3067  } else {
3068  sinfo_msg_error("keyword %s does not exist",KEY_NAME_CUMOFFY);
3069  cpl_propertylist_delete(plist) ;
3070  return -1;
3071  }
3072  cpl_propertylist_delete(plist) ;
3073  cpl_free(file);
3074 
3075  return result;
3076 
3077 }
3078 
3079 int sinfo_frame_is_dither(cpl_frame * frame)
3080 {
3081 
3082  char file[256];
3083  char band[FILE_NAME_SZ];
3084 
3085 
3086  cpl_propertylist* plist=NULL;
3087  int grat_encoder=0;
3088  int dith_status=1;
3089  int len=0;
3090 
3091 
3092  cknull(frame,"Null input frame. Exit!");
3093 
3094  cknull_nomsg(strcpy(file,cpl_frame_get_filename(frame)));
3095  len= strlen(file);
3096 
3097  if(len<1) goto cleanup;
3098  if(sinfo_file_exists(file)==0) goto cleanup;
3099  //file = cpl_strdup(cpl_frame_get_filename(frame)) ;
3100  cknull(plist = cpl_propertylist_load(file, 0),
3101  "getting header from reference frame %s",file);
3102 
3103  if (cpl_propertylist_has(plist, KEY_NAME_FILT_NAME)) {
3104  strcpy(band,cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME));
3105  } else {
3106  sinfo_msg_error("keyword %s does not exist",KEY_NAME_FILT_NAME);
3107  sinfo_free_propertylist(&plist) ;
3108  return -1;
3109  }
3110 
3111  if (cpl_propertylist_has(plist, KEY_NAME_GRAT_ENC)) {
3112  grat_encoder = cpl_propertylist_get_int(plist, KEY_NAME_GRAT_ENC);
3113  } else {
3114  sinfo_msg_error("keyword %s does not exist",KEY_NAME_GRAT_ENC);
3115  sinfo_free_propertylist(&plist) ;
3116  return -1;
3117  }
3118 
3119  sinfo_free_propertylist(&plist) ;
3120 
3121  if (strcmp(band,"H") == 0) {
3122  if( abs(grat_encoder - GRAT_VAL2_H) <= GRAT_VAL_TOL ) {
3123  dith_status = 0;
3124  } else {
3125  dith_status = 0;
3126  }
3127  }
3128  else if (strcmp(band,"H+K") == 0) {
3129  if( abs(grat_encoder - GRAT_VAL2_HK) <= GRAT_VAL_TOL ) {
3130  dith_status = 0;
3131  } else {
3132  dith_status = 0;
3133  }
3134  }
3135  else if (strcmp(band,"K") == 0) {
3136  if( abs(grat_encoder - GRAT_VAL2_K) <= GRAT_VAL_TOL ) {
3137  dith_status = 0;
3138  } else {
3139  dith_status = 0;
3140  }
3141  }
3142  else if (strcmp(band,"J") == 0) {
3143  if( abs(grat_encoder - GRAT_VAL2_J) <= GRAT_VAL_TOL ) {
3144  dith_status = 0;
3145  } else {
3146  dith_status = 0;
3147  }
3148  }
3149  cleanup:
3150 
3151  sinfo_free_propertylist(&plist) ;
3152  if(cpl_error_get_code() != CPL_ERROR_NONE) {
3153  return -1;
3154  } else {
3155  return dith_status;
3156  }
3157 }
3158 
3159 /*---------------------------------------------------------------------------*/
3168 /*---------------------------------------------------------------------------*/
3169 
3170 int sinfo_get_spatial_res(cpl_frame * ref_frame, char * spat_res)
3171 {
3172 
3173  const char* ref_file;
3174  cpl_propertylist* plist=NULL;
3175 
3176  ref_file=cpl_frame_get_filename(ref_frame) ;
3177  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
3178  sinfo_msg_error( "getting header from reference frame %s",ref_file);
3179  sinfo_free_propertylist(&plist) ;
3180  return -1 ;
3181 
3182  }
3183 
3184  if (cpl_propertylist_has(plist, KEY_NAME_PREOPTICS)) {
3185  strcpy(spat_res,cpl_propertylist_get_string(plist, KEY_NAME_PREOPTICS));
3186  /* sinfo_msg("%s value is %s", KEY_NAME_PREOPTICS, spat_res); */
3187  } else {
3188  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_PREOPTICS);
3189  sinfo_free_propertylist(&plist);
3190  return -1;
3191  }
3192  sinfo_free_propertylist(&plist);
3193  return 0;
3194 
3195 }
3196 
3197 /*---------------------------------------------------------------------------*/
3205 /*---------------------------------------------------------------------------*/
3206 
3207 int sinfo_frame_is_sky(cpl_frame * ref_frame)
3208 {
3209 
3210  char dpr_type[FILE_NAME_SZ];
3211  char* ref_file=NULL;
3212  const char* sval=NULL;
3213 
3214  int result=0;
3215  cpl_propertylist* plist=NULL;
3216 
3217  sval = cpl_frame_get_filename(ref_frame) ;
3218  ref_file = cpl_strdup(sval) ;
3219 
3220  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL)) {
3221  sinfo_msg_error( "getting header from reference frame %s",ref_file);
3222  cpl_propertylist_delete(plist) ;
3223  cpl_free(ref_file);
3224  return -1 ;
3225  }
3226 
3227  if (cpl_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
3228  strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
3229  /* sinfo_msg("%s value is %d", KEY_NAME_DPR_TYPE, dpr_type); */
3230  } else {
3231  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_DPR_TYPE);
3232  cpl_propertylist_delete(plist) ;
3233  cpl_free(ref_file);
3234  return -1;
3235  }
3236  cpl_propertylist_delete(plist);
3237  if(strstr(dpr_type,RAW_SKY) != NULL) {
3238  result=1;
3239  }
3240  cpl_free(ref_file);
3241 
3242  return result;
3243 
3244 }
3245 
3246 
3247 /*---------------------------------------------------------------------------*/
3255 /*---------------------------------------------------------------------------*/
3256 
3257 int sinfo_tag_is_sky(char * tag)
3258 {
3259 
3260  int result=0;
3261 
3262  if(
3263  (strcmp(tag,RAW_SKY) == 0) ||
3264  (strcmp(tag,RAW_IMAGE_PRE_SKY) == 0) ||
3265  (strcmp(tag,RAW_SKY_NODDING) == 0) ||
3266  (strcmp(tag,RAW_SKY_JITTER) == 0) ||
3267  (strcmp(tag,RAW_SKY_STD) == 0) ||
3268  (strcmp(tag,RAW_FIBRE_DARK) == 0) ||
3269  (strcmp(tag,RAW_SKY_OH) == 0) ||
3270  (strcmp(tag,RAW_SKY_PSF_CALIBRATOR) == 0)
3271  ) {
3272  result=1;
3273  }
3274 
3275  return result;
3276 
3277 }
3278 
3279 
3280 /*---------------------------------------------------------------------------*/
3288 /*---------------------------------------------------------------------------*/
3289 
3290 int sinfo_tag_is_obj(char * tag)
3291 {
3292 
3293  int result=0;
3294 
3295  if(
3296  (strcmp(tag,RAW_PUPIL_LAMP) == 0) ||
3297  (strcmp(tag,RAW_OBJECT) == 0) ||
3298  (strcmp(tag,RAW_IMAGE_PRE_OBJECT) == 0) ||
3299  (strcmp(tag,RAW_OBJECT_NODDING) == 0) ||
3300  (strcmp(tag,RAW_OBJECT_JITTER) == 0) ||
3301  (strcmp(tag,RAW_PSF_CALIBRATOR) == 0) ||
3302  (strcmp(tag,RAW_FIBRE_PSF) == 0) ||
3303  (strcmp(tag,RAW_STD) == 0) ||
3304  (strcmp(tag,RAW_STD_STAR) == 0)
3305 
3306  ) {
3307  result=1;
3308  }
3309 
3310  return result;
3311 
3312 }
3313 
3314 /*---------------------------------------------------------------------------*/
3322 /*---------------------------------------------------------------------------*/
3323 
3324 int sinfo_tag_is_objpro(char * tag)
3325 {
3326 
3327  int result=0;
3328 
3329  if(
3330  (strcmp(tag,PRO_COADD_OBJ) == 0) ||
3331  (strcmp(tag,PRO_COADD_PSF) == 0) ||
3332  (strcmp(tag,PRO_COADD_STD) == 0) ||
3333  (strcmp(tag,PRO_OBS_OBJ) == 0) ||
3334  (strcmp(tag,PRO_OBS_PSF) == 0) ||
3335  (strcmp(tag,PRO_OBS_STD) == 0) ||
3336  (strcmp(tag,PRO_PSF_CALIBRATOR_STACKED) == 0) ||
3337  (strcmp(tag,PRO_SKY_PSF_CALIBRATOR_STACKED) == 0) ||
3338  (strcmp(tag,PRO_STD_STACKED) == 0) ||
3339  (strcmp(tag,PRO_SKY_STD_STACKED) == 0) ||
3340  (strcmp(tag,PRO_OBJECT_NODDING_STACKED) == 0) ||
3341  (strcmp(tag,PRO_SKY_NODDING_STACKED) == 0)
3342  ) {
3343  result=1;
3344  }
3345 
3346  return result;
3347 
3348 }
3349 
3350 
3351 /*---------------------------------------------------------------------------*/
3359 /*---------------------------------------------------------------------------*/
3360 
3361 int sinfo_frame_is_on(cpl_frame * ref_frame)
3362 {
3363 
3364  char ref_file[FILE_NAME_SZ];
3365  char dpr_type[FILE_NAME_SZ];
3366  int lamp_Xe=0;
3367  int lamp_Kr=0;
3368  int lamp_Ne=0;
3369  int lamp_Ar=0;
3370  int lamp_Halo=0;
3371  int len=0;
3372  int result=0;
3373  cpl_propertylist* plist=NULL;
3374  const char* filename=NULL;
3375  cknull(ref_frame,"Null input frame. Exit!");
3376 
3377  cknull_nomsg(filename=cpl_frame_get_filename(ref_frame));
3378  len= strlen(filename);
3379  if(len<1) goto cleanup;
3380 
3381  check_nomsg(strcpy(ref_file, filename)) ;
3382  if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL)) {
3383  sinfo_msg_error( "getting header from reference frame %s",ref_file);
3384  sinfo_free_propertylist(&plist) ;
3385  return -1 ;
3386  }
3387 
3388  /*-----------------------------------------------------------------------
3389  in J Argon (4)
3390  in H Xenon and Argon (1+4)
3391  in K Neon (3)
3392  in H+K Xenon (1)
3393  -------------------------------------------------------------------------*/
3394  if (cpl_propertylist_has(plist, KEY_NAME_DPR_TYPE)) {
3395  strcpy(dpr_type,cpl_propertylist_get_string(plist, KEY_NAME_DPR_TYPE));
3396  /* sinfo_msg("%s value is %s", KEY_NAME_DPR_TYPE, dpr_type); */
3397  } else {
3398  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_DPR_TYPE);
3399  sinfo_free_propertylist(&plist);
3400  return -1;
3401  }
3402 
3403  /*
3404  In order to use the frame tag to identify frames we have to add this line
3405  strcpy(dpr_type,cpl_frame_get_tag(ref_frame));
3406 
3407  */
3408 
3409  if(strstr(dpr_type,"STD") != NULL) {
3410  result = 1;
3411  sinfo_free_propertylist(&plist);
3412  return result;
3413  }
3414 
3415  if(strstr(dpr_type,"PSF") != NULL) {
3416  result = 1;
3417  sinfo_free_propertylist(&plist);
3418  return result;
3419  }
3420 
3421  if(strstr(dpr_type,"SKY") != NULL) {
3422  result = 0;
3423  sinfo_free_propertylist(&plist);
3424  return result;
3425  }
3426 
3427 
3428  if(strstr(dpr_type,"OBJECT") != NULL) {
3429  result = 1;
3430  sinfo_free_propertylist(&plist);
3431  return result;
3432  }
3433  /*
3434  if(strstr(dpr_type,"PUPIL") != NULL) {
3435  result = 1;
3436  cpl_propertylist_delete(plist);
3437  return result;
3438  }
3439  */
3440 
3441  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_XE)) {
3442  lamp_Xe=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_XE);
3443  /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_XE, lamp_Xe); */
3444  } else {
3445  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_XE);
3446  sinfo_free_propertylist(&plist);
3447  return -1;
3448  }
3449 
3450  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_KR)) {
3451  lamp_Kr=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_KR);
3452  /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_KR, lamp_Kr); */
3453  } else {
3454  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_KR);
3455  sinfo_free_propertylist(&plist);
3456  return -1;
3457  }
3458 
3459  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_NE)) {
3460  lamp_Ne=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_NE);
3461  /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_NE, lamp_Ne); */
3462  } else {
3463  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_NE);
3464  sinfo_free_propertylist(&plist);
3465  return -1;
3466  }
3467 
3468  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_AR)) {
3469  lamp_Ar=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_AR);
3470  /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_AR, lamp_Ar); */
3471  } else {
3472  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_AR);
3473  sinfo_free_propertylist(&plist);
3474  return -1;
3475  }
3476 
3477  if (cpl_propertylist_has(plist, KEY_NAME_LAMP_HALO)) {
3478  lamp_Halo=cpl_propertylist_get_bool(plist, KEY_NAME_LAMP_HALO);
3479  /* sinfo_msg("%s value is %d", KEY_NAME_LAMP_HALO, lamp_Halo); */
3480  } else {
3481  sinfo_msg_warning("keyword %s does not exist",KEY_NAME_LAMP_HALO);
3482  sinfo_free_propertylist(&plist);
3483  return -1;
3484  }
3485 
3486 
3487 
3488 
3489  if(lamp_Xe) {
3490  result=1;
3491  }
3492 
3493  if(lamp_Kr) {
3494  result=1;
3495  }
3496 
3497  if(lamp_Ne) {
3498  result=1;
3499  }
3500 
3501  if(lamp_Ar) {
3502  result=1;
3503  }
3504 
3505 
3506  if(lamp_Halo) {
3507  result=1;
3508  }
3509 
3510  cleanup:
3511  sinfo_free_propertylist(&plist);
3512  return result;
3513 
3514 
3515 }
3516 
3517 
3518 
3519 int
3520 sinfo_pfits_add_qc(cpl_propertylist * plist,
3521  qc_log * qclog)
3522 {
3523  char key_name[80] ;
3524  char key_value[80] ;
3525 
3526  int i =0;
3527 
3528  /* Test entries */
3529  if (plist == NULL) return -1 ;
3530 
3531  /* Parameter Name: PIPEFILE */
3532  /* we add ESO prefix to FITS keywords" */
3533  for(i=0;i<qclog[0].n;i++) {
3534  strcpy(key_name,"ESO ");
3535  strcat(key_name,qclog[i].name);
3536  if(strcmp(qclog[i].type,"string") == 0) {
3537  snprintf(key_value,sizeof(key_value)-1,"%s",qclog[i].s_val);
3538  cpl_propertylist_append_string(plist, key_name,key_value) ;
3539  cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
3540 
3541  } else if(strcmp(qclog[i].type,"bool") == 0) {
3542  snprintf(key_value,sizeof(key_value),"%i",(int)qclog[i].n_val);
3543  cpl_propertylist_append_bool(plist, key_name,(int)qclog[i].n_val) ;
3544  cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
3545  } else if(strcmp(qclog[i].type,"int") == 0) {
3546  snprintf(key_value,sizeof(key_value),"%i",(int)qclog[i].n_val);
3547  cpl_propertylist_append_int(plist, key_name,(int)qclog[i].n_val) ;
3548  cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
3549  } else if(strcmp(qclog[i].type,"float") == 0) {
3550  snprintf(key_value,sizeof(key_value),"%f",(float)qclog[i].n_val);
3551  cpl_propertylist_append_float(plist, key_name,(float)qclog[i].n_val) ;
3552  cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
3553  } else if(strcmp(qclog[i].type,"double") == 0) {
3554  snprintf(key_value,sizeof(key_value),"%f",qclog[i].n_val);
3555  cpl_propertylist_append_double(plist, key_name,qclog[i].n_val) ;
3556  cpl_propertylist_set_comment(plist, key_name,qclog[i].comm) ;
3557  }
3558 
3559  }
3560 
3561  return 0 ;
3562 }
3563 
3564 
3565 
#define sinfo_msg_debug(...)
Print a debug message.
Definition: sinfo_msg.h:103
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
#define sinfo_msg_warning(...)
Print an warning message.
Definition: sinfo_msg.h:93