UVES Pipeline Reference Manual  5.4.6
uves_qclog.c
1 /* $Id: uves_qclog.c,v 1.53 2012-11-19 09:12:54 jtaylor Exp $
2  *
3  * This file is part of the UVES 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: jtaylor $
23  * $Date: 2012-11-19 09:12:54 $
24  * $Revision: 1.53 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <uves_time.h>
32 #include <uves_globals.h>
33 /*----------------------------------------------------------------------------*/
37 /*----------------------------------------------------------------------------*/
38 
39 /*-----------------------------------------------------------------------------
40  Defines
41  -----------------------------------------------------------------------------*/
42 #define FILE_NAME_SZ 1024 /* fixme: should not use fixed size buffers */
43 
46 /*-----------------------------------------------------------------------------
47  Includes
48  -----------------------------------------------------------------------------*/
49 
50 #include "uves_qclog.h"
51 
52 #include <uves_baryvel.h>
53 #include <uves_utils_wrappers.h>
54 #include <uves_pfits.h>
55 #include <uves_error.h>
56 #include <uves_msg.h>
57 
58 #include <irplib_utils.h>
59 #include <string.h>
60 /*-----------------------------------------------------------------------------
61  Forward declarations
62  -----------------------------------------------------------------------------*/
63 
64 /*-----------------------------------------------------------------------------
65  Function codes
66  -----------------------------------------------------------------------------*/
67 
68 static FILE * uves_paf_print_header(
69  const char * filename,
70  const char * paf_id,
71  const char * paf_desc,
72  const char * login_name,
73  const char * datetime) ;
74 
75 /*----------------------------------------------------------------------------*/
100 /*----------------------------------------------------------------------------*/
101 static FILE * uves_paf_print_header(
102  const char * filename,
103  const char * paf_id,
104  const char * paf_desc,
105  const char * login_name,
106  const char * datetime)
107 {
108  FILE * paf ;
109 
110  if ((paf=fopen(filename, "w"))==NULL) {
111  uves_msg_error("cannot create PAF file [%s]", filename);
112  return NULL ;
113  }
114  fprintf(paf, "PAF.HDR.START ; # start of header\n");
115  fprintf(paf, "PAF.TYPE \"pipeline product\" ;\n");
116  fprintf(paf, "PAF.ID \"%s\"\n", paf_id);
117  fprintf(paf, "PAF.NAME \"%s\"\n", filename);
118  fprintf(paf, "PAF.DESC \"%s\"\n", paf_desc);
119  fprintf(paf, "PAF.CRTE.NAME \"%s\"\n", login_name) ;
120  fprintf(paf, "PAF.CRTE.DAYTIM \"%s\"\n", datetime) ;
121  fprintf(paf, "PAF.LCHG.NAME \"%s\"\n", login_name) ;
122  fprintf(paf, "PAF.LCHG.DAYTIM \"%s\"\n", datetime) ;
123  fprintf(paf, "PAF.CHCK.CHECKSUM \"\"\n");
124  fprintf(paf, "PAF.HDR.END ; # end of header\n");
125  fprintf(paf, "\n");
126  return paf ;
127 }
128 
129 
136 char *
137 uves_get_rootname(const char * filename)
138 {
139  static char path[MAX_NAME_SIZE+1];
140  char * lastdot ;
141 
142  if (strlen(filename)>MAX_NAME_SIZE) return NULL ;
143  memset(path, 0, MAX_NAME_SIZE);
144  strcpy(path, filename);
145  lastdot = strrchr(path, '.');
146  if (lastdot == NULL) return path ;
147  if ((!strcmp(lastdot, ".fits")) || (!strcmp(lastdot, ".FITS")) ||
148  (!strcmp(lastdot, ".paf")) || (!strcmp(lastdot, ".PAF")) ||
149  (!strcmp(lastdot, ".dat")) || (!strcmp(lastdot, ".DAT")) ||
150  (!strcmp(lastdot, ".tfits")) || (!strcmp(lastdot, ".TFITS")) ||
151  (!strcmp(lastdot, ".ascii")) || (!strcmp(lastdot, ".ASCII")))
152  {
153  lastdot[0] = (char)0;
154  }
155  return path ;
156 }
164 void
165 uves_get_paf_name(const char* in, int paf_no, char** paf)
166 {
167  char* tmp=NULL;
168  char name_b[512] ;
169 
170  if (strstr(in, "." ) != NULL )
171  {
172  tmp = uves_get_rootname(in);
173  strcpy(name_b, tmp);
174  }
175  else
176  {
177  sprintf(name_b, "%s", in) ;
178  }
179 
180  sprintf(*paf, "%s-%d.paf", name_b, paf_no);
181 
182  return;
183 }
189 int uves_blank2dot(const char * in, char* ou)
190 {
191  int len=0;
192  int i=0;
193 
194  strcpy(ou,in);
195  len = strlen(in);
196  for (i=0;i<len;i++)
197  {
198  if (in[i] == ' ') {
199  ou[i] = '.';
200  }
201  }
202  return 0;
203 }
204 
205 
206 /*----------------------------------------------------------------------------*/
207 
208 
224 /*----------------------------------------------------------------------------*/
225 int uves_save_paf(const char* filename,
226  int paf_no,
227  const char* rec_id,
228  const cpl_table* qclog,
229  uves_propertylist* plist,
230  const uves_propertylist* rhead,
231  const char* pro_catg)
232 {
233 
234 
235  FILE * paf ;
236  const char * sval ;
237  char key_name[FILE_NAME_SZ] ;
238  char key_paf[FILE_NAME_SZ] ;
239  char key_dpaf[FILE_NAME_SZ] ;
240  char key_type[FILE_NAME_SZ] ;
241  char key_value[FILE_NAME_SZ] ;
242  char key_help[FILE_NAME_SZ] ;
243  char* name_p=NULL;
244 
245  int i =0;
246  int n=0;
247 
248  name_p = cpl_malloc(FILE_NAME_SZ * sizeof(char));
249  uves_get_paf_name(filename, paf_no, &name_p);
250 
251 
252  uves_msg( "Writing %s" , name_p) ;
253  /* Create the default PAF header */
254  if ((paf = uves_paf_print_header(
255  name_p,
256  rec_id,
257  "QC file",
258  "login-name",
259  uves_get_datetime_iso8601())) == NULL) {
260  uves_msg_error( "cannot open file [%s] for output", name_p) ;
261  return -1 ;
262  }
263  cpl_free(name_p);
264 
265 
266  strcpy(key_name,KEY_NAME_QC_DID);
267  strcpy(key_paf,PAF_NAME_QC_DID);
268  uves_blank2dot(key_paf,key_dpaf);
269  fprintf(paf,"%-21s \"%s\" ; # %s \n",key_dpaf,
270  uves_propertylist_get_string(plist,key_name),KEY_HELP_QC_DID);
271 
272 
273  uves_blank2dot(PAF_NAME_PIPE_ID,key_dpaf);
274  fprintf(paf,"%-21s \"%s/%s\" ; # %s \n", key_dpaf,
275  PACKAGE, PACKAGE_VERSION,KEY_HELP_PIPE_ID);
276 
277  strcpy(key_name, KEY_NAME_PIPEFILE);
278  strcpy(key_paf, KEY_NAME_PIPEFILE);
279  uves_blank2dot(key_paf, key_dpaf);
280  if (uves_propertylist_contains(plist, key_name)) {
281  fprintf(paf,"%-21s \"%s\" ; # %s \n", key_dpaf,
282  uves_propertylist_get_string(plist,key_name),KEY_HELP_PIPEFILE);
283  }
284 
285  /* Value: "TEMPORARY", "PREPROCESSED", "REDUCED" or "QCPARAM". */
286  strcpy(key_name,KEY_NAME_PRO_TYPE);
287  strcpy(key_paf,PAF_NAME_PRO_TYPE);
288  uves_blank2dot(key_paf,key_dpaf);
289  if (uves_propertylist_contains(plist, key_name)) {
290  fprintf(paf,"%-21s \"%s\" ; # %s \n", key_dpaf,
291  uves_propertylist_get_string(plist,key_name),KEY_HELP_PRO_TYPE);
292  }
293 
294  strcpy(key_name,KEY_NAME_PRO_RECID);
295  strcpy(key_paf,PAF_NAME_PRO_RECID);
296  uves_blank2dot(key_paf,key_dpaf);
297  if (uves_propertylist_contains(plist, key_name)) {
298  fprintf(paf,"%-21s \"%s\" ; # %s \n", key_dpaf,
299  uves_propertylist_get_string(plist,key_name),KEY_HELP_PRO_RECID);
300  }
301 
302  /* sprintf(cval, "CPL-%s", get_cpl_version()); */
303  strcpy(key_name,KEY_NAME_PRO_DRSID);
304  strcpy(key_paf,PAF_NAME_PRO_DRSID);
305  uves_blank2dot(key_paf,key_dpaf);
306  if (uves_propertylist_contains(plist, key_name)) {
307  fprintf(paf,"%-21s \"%s\" ; # %s \n",key_dpaf,
308  uves_propertylist_get_string(plist,key_name),KEY_HELP_PRO_DRSID);
309  }
310  /*
311  if (uves_propertylist_contains(plist,KEY_NAME_DATE_OBS)) {
312  sval = uves_pfits_get_date_obs(plist);
313  strcpy(key_paf,KEY_NAME_DATE_OBS);
314  uves_blank2dot(key_paf,key_dpaf);
315  fprintf(paf, "%-21s \"%s\" ; # %s\n",key_dpaf,
316  sval,KEY_HELP_DATE_OBS) ;
317  }
318  */
319 
320  if (uves_propertylist_contains(rhead,KEY_NAME_ARCFILE)) {
321  sval = uves_pfits_get_arcfile(rhead);
322  strcpy(key_paf,KEY_NAME_ARCFILE);
323  uves_blank2dot(key_paf,key_dpaf);
324  fprintf(paf, "%-21s \"%s\" ; # %s \n", key_dpaf,sval,KEY_HELP_ARCFILE) ;
325  } else if (uves_propertylist_contains(rhead,KEY_NAME_PRO_REC1_RAW1_NAME)) {
326  sval = uves_pfits_get_rec1raw1name(rhead);
327  strcpy(key_paf,KEY_NAME_ARCFILE);
328  uves_blank2dot(key_paf,key_dpaf);
329  } else {
330  uves_msg_error("%s is missing QC LOG will fail!",KEY_NAME_ARCFILE);
331  }
332 
333 
334  if (uves_propertylist_contains(plist,KEY_NAME_TPL_ID)) {
335  sval = uves_pfits_get_templateid(plist);
336  strcpy(key_paf,PAF_NAME_TPL_ID);
337  uves_blank2dot(key_paf,key_dpaf);
338  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
339  sval,KEY_HELP_TPL_ID) ;
340 
341  }
342 
343  if (uves_propertylist_contains(plist,KEY_NAME_DPR_TYPE)) {
344  sval = uves_pfits_get_dpr_type(plist);
345  strcpy(key_paf,PAF_NAME_DPR_TYPE);
346  uves_blank2dot(key_paf,key_dpaf);
347  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
348  sval, KEY_HELP_DPR_TYPE) ;
349  }
350 
351  if (uves_propertylist_contains(plist,KEY_NAME_DPR_TECH)) {
352  sval = uves_pfits_get_dpr_tech(plist);
353  strcpy(key_paf,PAF_NAME_DPR_TECH);
354  uves_blank2dot(key_paf,key_dpaf);
355  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
356  sval, KEY_HELP_DPR_TECH) ;
357  }
358 
359  if (uves_propertylist_contains(plist,KEY_NAME_DPR_CATG)) {
360  sval = uves_pfits_get_dpr_catg(plist);
361  strcpy(key_paf,PAF_NAME_DPR_CATG);
362  uves_blank2dot(key_paf,key_dpaf);
363  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
364  sval, KEY_HELP_DPR_CATG) ;
365  }
366 
367  strcpy(key_paf,PAF_NAME_PRO_CATG);
368  uves_blank2dot(key_paf,key_dpaf);
369  fprintf(paf, "%-21s \"%s\" ; # %s\n", key_dpaf,
370  pro_catg, KEY_HELP_PRO_CATG) ;
371 
372  n=cpl_table_get_nrow(qclog);
373  for(i=0;i<n;i++)
374  {
375  strcpy(key_paf,cpl_table_get_string(qclog,"key_name",i));
376  uves_blank2dot(key_paf,key_name);
377  strcpy(key_type, cpl_table_get_string(qclog, "key_type",i));
378  strcpy(key_value, cpl_table_get_string(qclog, "key_value",i));
379  strcpy(key_help, cpl_table_get_string(qclog, "key_help" , i));
380 
381  if (strcmp(key_type, "CPL_TYPE_STRING") == 0)
382  {
383  fprintf(paf,"%s \"%s\"\n",
384  key_name, key_value);
385  }
386  else
387  {
388  fprintf(paf,"%s %s\n",
389  key_name, key_value);
390  }
391  }
392  fprintf(paf, "\n");
393  fclose(paf) ;
394 
395  return 0;
396 
397 }
398 
399 
400 /*----------------------------------------------------------------------------*/
408 /*----------------------------------------------------------------------------*/
409 cpl_table *
411  enum uves_chip chip)
412 {
413  cpl_table *qclog = NULL;
414 
415  qclog = cpl_table_new(0);
416  cpl_table_new_column(qclog,"key_name", CPL_TYPE_STRING);
417  cpl_table_new_column(qclog,"key_type", CPL_TYPE_STRING);
418  cpl_table_new_column(qclog,"key_value", CPL_TYPE_STRING);
419  cpl_table_new_column(qclog,"key_help", CPL_TYPE_STRING);
420 
422  uves_remove_string_prefix(KEY_NAME_QC_DID,"ESO "),
423  "UVES-1.14",
424  KEY_NAME_QC_DID,
425  "%s"));
426 
427  /* Not present in bias/dark frames: */
428  if (uves_propertylist_contains(raw_header, UVES_INSPATH))
429  {
431  uves_remove_string_prefix(UVES_INSPATH,"ESO "),
432  uves_pfits_get_inspath(raw_header),
433  "Optical path used.",
434  "%s"));
435  }
436  else
437  {
438  uves_msg_debug("Missing descriptor %s", UVES_INSPATH);
439  }
440 
441  if (uves_propertylist_contains(raw_header, UVES_INSMODE))
442  {
444  uves_remove_string_prefix(UVES_INSMODE,"ESO "),
445  uves_pfits_get_insmode(raw_header),
446  "Instrument mode used.",
447  "%s"));
448  }
449  else
450  {
451  uves_msg_debug("Missing descriptor %s", UVES_INSMODE);
452  }
453 
454 
455  if (uves_propertylist_contains(raw_header, UVES_GRATNAME(chip)))
456  {
458  uves_remove_string_prefix(UVES_GRATNAME(chip),"ESO "),
459  uves_pfits_get_gratname(raw_header,chip),
460  "Grating common name",
461  "%s"));
462  }
463  else
464  {
465  uves_msg_debug("Missing descriptor %s", UVES_GRATNAME(chip));
466  }
467 
468  /* Always present: */
470  uves_remove_string_prefix(UVES_READ_SPEED,"ESO "),
471  uves_pfits_get_readspeed(raw_header),
472  "Readout speed",
473  "%s"));
474 
476  uves_remove_string_prefix(UVES_BINX, "ESO "),
477  uves_pfits_get_binx(raw_header),
478  "Binning factor along X",
479  "%d"));
480 
482  uves_remove_string_prefix(UVES_BINY, "ESO "),
483  uves_pfits_get_biny(raw_header),
484  "Binning factor along Y",
485  "%d"));
486 
487  if (uves_propertylist_contains(raw_header, UVES_CHIP_NAME(chip)))
488  {
490  uves_remove_string_prefix(UVES_CHIP_NAME(chip),"ESO "),
491  /* UVES_QC_CHIP_VAL(chip), */
492  uves_pfits_get_chip_name(raw_header, chip),
493  "Detector chip name",
494  "%s"));
495  }
496  else
497  {
498  uves_msg_warning("Missing descriptor %s", UVES_CHIP_NAME(chip));
499  }
500 
501  cleanup:
502  return qclog;
503 }
504 
505 
506 
507 /*----------------------------------------------------------------------------*/
518 /*----------------------------------------------------------------------------*/
519 
520 int
521 uves_qclog_add_int(cpl_table* table,
522  const char* key_name,
523  const int value,
524  const char* key_help,
525  const char* format)
526 {
527  int sz = cpl_table_get_nrow(table);
528  int raw = sz;
529  char key_value[FILE_NAME_SZ];
530  char key_type[FILE_NAME_SZ];
531 
532  sprintf(key_value,format,value);
533  strcpy(key_type,"CPL_TYPE_INT");
534 
535  cpl_table_set_size(table,sz+1);
536 
537  cpl_table_set_string(table,"key_name" ,raw,key_name);
538  cpl_table_set_string(table,"key_type" ,raw,key_type);
539  cpl_table_set_string(table,"key_value",raw,key_value);
540  cpl_table_set_string(table,"key_help" ,raw,key_help);
541 
542  return 0;
543 
544 }
545 
546 
547 
558 /*----------------------------------------------------------------------------*/
559 
560 int
561 uves_qclog_add_bool(cpl_table* table,
562  const char* key_name,
563  const char value,
564  const char* key_help,
565  const char* format)
566 {
567  int sz = cpl_table_get_nrow(table);
568  int raw = sz;
569  char key_value[FILE_NAME_SZ];
570  char key_type[FILE_NAME_SZ];
571 
572  sprintf(key_value,format,value);
573  strcpy(key_type,"CPL_TYPE_BOOL");
574 
575  cpl_table_set_size(table,sz+1);
576 
577  cpl_table_set_string(table,"key_name" ,raw,key_name);
578  cpl_table_set_string(table,"key_type" ,raw,key_type);
579  cpl_table_set_string(table,"key_value",raw,key_value);
580  cpl_table_set_string(table,"key_help" ,raw,key_help);
581 
582  return 0;
583 
584 }
585 
596 /*----------------------------------------------------------------------------*/
597 
598 
599 int
600 uves_qclog_add_float(cpl_table* table,
601  const char* key_name,
602  const float value,
603  const char* key_help,
604  const char* format)
605 {
606  int sz = cpl_table_get_nrow(table);
607  int raw = sz;
608  char key_value[FILE_NAME_SZ];
609  char key_type[FILE_NAME_SZ];
610 
611  sprintf(key_value,format,value);
612  strcpy(key_type,"CPL_TYPE_FLOAT");
613 
614  cpl_table_set_size(table,sz+1);
615 
616  cpl_table_set_string(table,"key_name" ,raw,key_name);
617  cpl_table_set_string(table,"key_type" ,raw,key_type);
618  cpl_table_set_string(table,"key_value",raw,key_value);
619  cpl_table_set_string(table,"key_help" ,raw,key_help);
620 
621  return 0;
622 
623 }
624 
625 
626 
637 /*----------------------------------------------------------------------------*/
638 
639 
640 int
641 uves_qclog_add_double(cpl_table* table,
642  const char* key_name,
643  const double value,
644  const char* key_help,
645  const char* format)
646 {
647  int sz = cpl_table_get_nrow(table);
648  int raw = sz;
649  char key_value[FILE_NAME_SZ];
650  char key_type[FILE_NAME_SZ];
651 
652  sprintf(key_value,format,value);
653  strcpy(key_type,"CPL_TYPE_DOUBLE");
654 
655  cpl_table_set_size(table,sz+1);
656 
657  cpl_table_set_string(table,"key_name" ,raw,key_name);
658  cpl_table_set_string(table,"key_type" ,raw,key_type);
659  cpl_table_set_string(table,"key_value",raw,key_value);
660  cpl_table_set_string(table,"key_help" ,raw,key_help);
661 
662  return 0;
663 
664 }
665 
666 
677 /*----------------------------------------------------------------------------*/
678 
679 
680 
681 
682 int
683 uves_qclog_add_string(cpl_table* table,
684  const char* key_name,
685  const char* value,
686  const char* key_help,
687  const char* format)
688 {
689  int sz = cpl_table_get_nrow(table);
690  int raw = sz;
691  char key_value[FILE_NAME_SZ];
692  char key_type[FILE_NAME_SZ];
693 
694  sprintf(key_value,format,value);
695  strcpy(key_type,"CPL_TYPE_STRING");
696 
697  cpl_table_set_size(table,sz+1);
698 
699  cpl_table_set_string(table,"key_name" ,raw,key_name);
700  cpl_table_set_string(table,"key_type" ,raw,key_type);
701  cpl_table_set_string(table,"key_value",raw,key_value);
702  cpl_table_set_string(table,"key_help" ,raw,key_help);
703 
704  return 0;
705 
706 }
707 
713 /*----------------------------------------------------------------------------*/
714 
715 int
716 uves_qclog_delete(cpl_table** table)
717 {
718  if (table != NULL) {
719  cpl_table_delete(*table);
720  *table = NULL;
721  }
722  return 0;
723 }
724 
725 
732 /*----------------------------------------------------------------------------*/
733 
734 
736  uves_propertylist * plist,
737  const cpl_table * qclog)
738 {
739  char key_name[FILE_NAME_SZ];
740  char key_value[FILE_NAME_SZ];
741  char key_type[FILE_NAME_SZ];
742  char key_help[FILE_NAME_SZ] ;
743 
744  int i =0;
745  int n =0;
746  /* Test entries */
747  if (plist == NULL) {
748  uves_msg_error("plist=NULL, something strange");
749  return -1 ;
750  }
751  /* Parameter Name: PIPEFILE */
752 
753  n=cpl_table_get_nrow(qclog);
754  for(i=0;i<n;i++) {
755  strcpy(key_name,"ESO ");
756  strcat(key_name,cpl_table_get_string(qclog,"key_name",i));
757  strcpy(key_type,cpl_table_get_string(qclog,"key_type",i));
758  strcpy(key_value,cpl_table_get_string(qclog,"key_value",i));
759  strcpy(key_help,cpl_table_get_string(qclog,"key_help",i));
760 
761  /* uves_msg("name=%s type=%s value=%s\n",key_name,key_type,key_value); */
762  if(!uves_propertylist_contains(plist,key_name)) {
763  if(strcmp(key_type,"CPL_TYPE_STRING") == 0) {
764  uves_propertylist_append_string(plist, key_name,key_value) ;
765  uves_propertylist_set_comment(plist, key_name,key_help) ;
766  } else if(strcmp(key_type,"CPL_TYPE_BOOL") == 0) {
767  /* printf("key_value=%s\n",key_value); */
768  uves_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
769  uves_propertylist_set_comment(plist, key_name,key_help) ;
770  } else if(strcmp(key_type,"CPL_TYPE_INT") == 0) {
771  uves_propertylist_append_int(plist,key_name,atoi(key_value)) ;
772  uves_propertylist_set_comment(plist, key_name,key_help) ;
773  } else if(strcmp(key_type,"CPL_TYPE_FLOAT") == 0) {
774  uves_propertylist_append_float(plist, key_name,(float)atof(key_value)) ;
775  uves_propertylist_set_comment(plist, key_name,key_help) ;
776  } else if(strcmp(key_type,"CPL_TYPE_DOUBLE") == 0) {
777  uves_propertylist_append_double(plist, key_name,atof(key_value)) ;
778  uves_propertylist_set_comment(plist, key_name,key_help) ;
779  }
780  else
781  {
782  uves_msg_error("Unrecognized type: %s", key_type);
783  return -1;
784  }
785  }
786 
787  }
788 
789  return 0 ;
790 }
791 
792 /*----------------------------------------------------------------------------*/
801 /*----------------------------------------------------------------------------*/
802 void
803 uves_qclog_add_sci(cpl_table *qclog,
804  const uves_propertylist *raw_header,
805  const cpl_image *raw_image,
806  double slit,
807  const cpl_table *info_tbl)
808 {
809  char key_name[80];
810 
811  /* These QC parameters are computed only in optimal extraction.
812  Update: After request from DFO, these are also calculated for
813  average+linear extraction.
814  */
815 
816  if (info_tbl != NULL) {
817  int minorder = cpl_table_get_int(info_tbl, "Order", 0, NULL);
818  int maxorder = minorder;
819  int norder; /* Number of orders extracted */
820  int i;
821 
822  for(i = 0; i < cpl_table_get_nrow(info_tbl); i++) {
823  int order = cpl_table_get_int(info_tbl,"Order", i, NULL);
824 
825  minorder = uves_min_int(minorder, order);
826  maxorder = uves_max_int(maxorder, order);
827 
828  /*
829  sprintf(key_name, "QC ORDER NUM%d", i);
830  check_nomsg(uves_qclog_add_int(qclog,
831  key_name,
832  cpl_table_get_int(info_tbl,"Order",i, NULL),
833  "Order Number",
834  "%d"));
835  */
836 
837  uves_msg_debug("QC-LOG: Order = %d, S/N = %g, Pos = %g, FHWM = %g, RI = %g",
838  order,
839  cpl_table_get_double(info_tbl, "ObjSnBlzCentre" ,i ,NULL),
840  cpl_table_get_double(info_tbl, "ObjPosOnSlit" ,i ,NULL),
841  cpl_table_get_double(info_tbl, "ObjFwhmAvg" ,i ,NULL),
842  cpl_table_get_double(info_tbl, "Ripple" ,i ,NULL));
843 
844 
845  sprintf(key_name, "QC ORD%d OBJ SN", order);
847  key_name,
848  cpl_table_get_double(info_tbl,"ObjSnBlzCentre",i, NULL),
849  "Av. S/N at order center",
850  "%8.4f"));
851 
852  sprintf(key_name, "QC ORD%d OBJ POS", order);
854  key_name,
855  cpl_table_get_double(info_tbl,"ObjPosOnSlit",i, NULL),
856  "Av. OBJ POS at order center",
857  "%8.4f"));
858 
859  sprintf(key_name, "QC ORD%d OBJ FWHM", order);
861  key_name,
862  cpl_table_get_double(info_tbl,"ObjFwhmAvg",i, NULL),
863  "Av. FWHM on order",
864  "%8.4f"));
865 
866  sprintf(key_name, "QC ORD%d OBJ RPLPAR", order);
868  key_name,
869  cpl_table_get_double(info_tbl,"Ripple",i, NULL),
870  "Av. relative ripple amplitude",
871  "%8.4f"));
872  } /* for i */
873 
874  /* !WARNING!: Duplicate code follows. If changed, please
875  * synchronize with the place where ORDER_TRACE_xxxx
876  * is saved.
877  *
878  * These parameters used to (MIDAS),
879  * be added only to ORDER_TRACE_xxxx.
880  * Now add them to the same products as other
881  * QC parameters
882  */
883 
884  norder = maxorder - minorder + 1;
886  "QC EX NORD",
887  norder,
888  "No. of orders extracted",
889  "%d"));
890 
892  "QC EX XSIZE",
893  cpl_image_get_size_x(raw_image),
894  "Input image width (pixels)",
895  "%d"));
896 
898  "QC EX YSIZE",
899  uves_round_double(slit),
900  "Extraction slit (pixels)",
901  "%d"));
902  } /* if info_tbl != NULL */
903 
904  {
905  double barycor, helicor;
906 
907  check( uves_baryvel(raw_header,
908  &barycor,
909  &helicor),
910  "Could not compute velocity corrections");
911 
913  "QC VRAD BARYCOR",
914  barycor,
915  "Barycentric radial velocity correction ",
916  "%13.6f"));
917 
919  "QC VRAD HELICOR",
920  helicor,
921  "Heliocentric radial velocity correction ",
922  "%13.6f"));
923  }
924 
925  cleanup:
926  return;
927 }
928 
929 /*----------------------------------------------------------------------------*/
939 /*----------------------------------------------------------------------------*/
940 
941 void
943  enum uves_chip chip,
944  cpl_table *qclog)
945 {
946 
948  uves_remove_string_prefix(UVES_SLITWIDTH(chip),"ESO "),
949  uves_pfits_get_slitwidth(raw_header,chip),
950  "Slit width (arcsec) [arcsec] (hs).",
951  "%.1f"));
952 
954  uves_remove_string_prefix(UVES_GRATWLEN(chip),"ESO "),
955  uves_pfits_get_gratwlen(raw_header,chip),
956  "Grating central wavelength [nm] (hs).",
957  "%.1f"));
958 
959 
960 
961 
963  uves_remove_string_prefix(UVES_TEMPCAM(chip),"ESO "),
964  uves_pfits_get_tempcam(raw_header,chip),
965  "Average temperature [C] (ho).",
966  "%.1f"));
967 
968 
969 
970  cleanup:
971  return;
972 }
973 
974 /*----------------------------------------------------------------------------*/
982 /*----------------------------------------------------------------------------*/
983 
984 const char *
985 uves_qclog_get_qc_name(const char *name,
986  bool flames, int trace_number)
987 {
988  if (flames)
989  {
990  return uves_sprintf("QC FIB%d %s", trace_number + 1, name);
991  }
992  else
993  {
994  return uves_sprintf("QC %s", name);
995  }
996 }
997 
998 /*----------------------------------------------------------------------------*/
1006 /*----------------------------------------------------------------------------*/
1007 
1008 int
1010  enum uves_chip chip,
1011  cpl_table* qclog)
1012 
1013 {
1014 
1015 
1016  int binx=0;
1017  int biny=0;
1018  const char* read_speed=NULL;
1019  const char* dpr_type=NULL;
1020  const char* tpl_id=NULL;
1021  const char* arcfile=NULL;
1022  const char* pro_catg=NULL;
1023  const char* pipefile=NULL;
1024  const char* ins_path=NULL;
1025  const char* ins_mode=NULL;
1026  const char* name_cross=NULL;
1027  const char* name_ccd=NULL;
1028 
1029 
1030  check_nomsg(binx=uves_pfits_get_binx(plist));
1031  check_nomsg(biny=uves_pfits_get_biny(plist));
1032  check_nomsg(read_speed=uves_pfits_get_readspeed(plist));
1033  check_nomsg(dpr_type=uves_pfits_get_dpr_catg(plist));
1034  check_nomsg(tpl_id=uves_pfits_get_templateid(plist));
1035  check_nomsg(arcfile=uves_pfits_get_arcfile(plist));
1036  check_nomsg(pro_catg=uves_pfits_get_pro_catg(plist));
1037  check_nomsg(pipefile=uves_pfits_get_pipefile(plist));
1038  check_nomsg(ins_path=uves_pfits_get_inspath(plist));
1039  check_nomsg(ins_mode=uves_pfits_get_insmode(plist));
1040  check_nomsg(name_cross=uves_pfits_get_gratname(plist,chip));
1041  check_nomsg(name_ccd=uves_pfits_get_chipid(plist,chip));
1042 
1043  ck0_nomsg(uves_qclog_add_string(qclog,
1044  "PRO REC1 PIPE ID",
1045  PACKAGE_VERSION,
1046  "Pipeline (unique) identifier",
1047  "%s"));
1048 
1049  ck0_nomsg(uves_qclog_add_string(qclog,
1050  "DPR TYPE",
1051  dpr_type,
1052  "Data Processing Type",
1053  "%s"));
1054 
1055  ck0_nomsg(uves_qclog_add_string(qclog,
1056  "TPL ID",
1057  tpl_id,
1058  "Template Id",
1059  "%s"));
1060 
1061  ck0_nomsg(uves_qclog_add_string(qclog,
1062  "ARCFILE",
1063  arcfile,
1064  "Archive file name",
1065  "%s"));
1066 
1067  ck0_nomsg(uves_qclog_add_string(qclog,
1068  "PRO CATG",
1069  pro_catg,
1070  "Product Category",
1071  "%s"));
1072 
1073 
1074  ck0_nomsg(uves_qclog_add_string(qclog,
1075  "PIPEFILE",
1076  pipefile,
1077  "Pipeline file name",
1078  "%s"));
1079 
1080 
1081  ck0_nomsg(uves_qclog_add_string(qclog,
1082  "INS PATH",
1083  ins_path,
1084  "Instrument Path",
1085  "%s"));
1086 
1087 
1088  ck0_nomsg(uves_qclog_add_string(qclog,
1089  "INS MODE",
1090  ins_mode,
1091  "Instrument mode",
1092  "%s"));
1093 
1094  ck0_nomsg(uves_qclog_add_string(qclog,
1095  "NAME CROSS",
1096  name_cross,
1097  "Grating common name",
1098  "%s"));
1099 
1100  ck0_nomsg(uves_qclog_add_string(qclog,
1101  "NAME CCD",
1102  name_ccd,
1103  "Detector chip name",
1104  "%s"));
1105 
1106 
1107  /*
1108  qc1log/out 1 {p2} "PRO.REC1.PIPE.ID" "{p_version}" "Pipeline (unique) identifier" PRO
1109  qc1log/out 1 {p1} {h_dprtype} "{dpr_type}" + DPR
1110  qc1log/out 1 {p2} {h_tpid} "{tpl_id}" + TPL
1111  qc1log/out 1 {p2} {h_arcfile} {arcfile} + PRIMARY-FITS
1112  qc1log/out 1 {p2} {h_procatg} {pro_catg} + PRO
1113  qc1log/out 1 {p2} {h_pipefile} {p2} + PRO
1114  set/format i1 f8.4,f8.4
1115  qc1log/out 1 {p2} {h_inspath} {{p1},{h_inspath}} "Optical path used." UVES_ICS
1116  qc1log/out 1 {p2} {h_insmode} {{p1},{h_insmode}} "Instrument mode used." UVES_ICS
1117 qc1log/out 1 {p2} "{h_namecros({PATHID})(5:18)}" {{p1},{h_namecros({PATHID})}} "Grating common name" UVES_ICS
1118 nameccd = "{{p1},{h_fits_nameccd({PATHID})}}"
1119 qc1log/out 1 {p2} "{h_fits_nameccd({PATHID})(5:)}" "{nameccd}" "Detector chip name" CCDDCS
1120 qc1log/out 1 {p2} "{h_speed}" {speed} "Readout speed" CCDDCS
1121 qc1log/out 1 {p2} "{h_xwinbin}" {binx} "Binning factor along X" CCDDCS
1122 qc1log/out 1 {p2} "{h_ywinbin}" {biny} "Binning factor along Y" CCDDCS
1123 set/format
1124  */
1125 
1126  ck0_nomsg(uves_qclog_add_string(qclog,
1127  "DET READ SPEED",
1128  read_speed,
1129  "Readout speed",
1130  "%8.4f"));
1131 
1132 
1133  ck0_nomsg(uves_qclog_add_double(qclog,
1134  "DET BINX",
1135  binx,
1136  "Binning factor along X",
1137  "%8.4f"));
1138 
1139 
1140  ck0_nomsg(uves_qclog_add_double(qclog,
1141  "DET BINY",
1142  biny,
1143  "Binning factor along Y",
1144  "%8.4f"));
1145 
1146 
1147 
1148  return 0;
1149  cleanup:
1150  return -1;
1151 
1152 }
1153 
1154 
1155 /*----------------------------------------------------------------------------*/
1163 /*----------------------------------------------------------------------------*/
1164 
1165 int
1167  enum uves_chip chip,
1168  cpl_table* qclog)
1169  {
1170  double slit_width=0;
1171  double temp_cam=0;
1172  double wave_len=0;
1173  check_nomsg(wave_len=uves_pfits_get_gratwlen(plist,chip));
1174  check_nomsg(temp_cam=uves_pfits_get_tempcam(plist,chip));
1175  check_nomsg(slit_width=uves_pfits_get_slitwidth(plist,chip));
1176 
1177 
1178  ck0_nomsg(uves_qclog_add_double(qclog,
1179  "DET SLIT WIDTH",
1180  slit_width,
1181  "Slit width (arcsec) [arcsec] (hs).",
1182  "%8.4f"));
1183 
1184 
1185  ck0_nomsg(uves_qclog_add_double(qclog,
1186  "DET WCENT",
1187  wave_len,
1188  "Grating central wavelength [nm] (hs).",
1189  "%8.4f"));
1190 
1191 
1192  ck0_nomsg(uves_qclog_add_double(qclog,
1193  "TEMP CAM",
1194  temp_cam,
1195  "Average temperature [c] (ho).",
1196  "%8.4f"));
1197 
1198 
1199  /*
1200  set/format i1 f8.4,f8.4
1201  qc1log/out 1 {p2} "{h_slwidth({PATHID})}" {swid} "Slit width (arcsec) [arcsec] (hs)." UVES_ICS
1202 qc1log/out 1 {p2} "{h_cwlen({PATHID})(5:)}" {wlen} "Grating central wavelength [nm] (hs)." UVES_ICS
1203 qc1log/out 1 {p2} "{h_tempcam({PATHID})(5:)}" {temp} "Average temperature [c] (ho)." UVES_ICS
1204 set/format
1205 
1206  */
1207  return 0;
1208 
1209  cleanup:
1210  return -1;
1211 
1212 }
1213 
int uves_save_paf(const char *filename, int paf_no, const char *rec_id, const cpl_table *qclog, uves_propertylist *plist, const uves_propertylist *rhead, const char *pro_catg)
Init QC-LOG table.
Definition: uves_qclog.c:225
#define uves_msg_error(...)
Print an error message.
Definition: uves_msg.h:64
const char * uves_pfits_get_dpr_tech(const uves_propertylist *plist)
find out the data tech as defined by the DataFlow
Definition: uves_pfits.c:513
char * uves_get_rootname(const char *filename)
computes rootname
Definition: uves_qclog.c:137
double uves_pfits_get_tempcam(const uves_propertylist *plist, enum uves_chip chip)
find out the pressure value
Definition: uves_pfits.c:1313
char * uves_get_datetime_iso8601(void)
Returns the current date and time as a static string.
Definition: uves_time.c:118
#define uves_msg_warning(...)
Print an warning message.
Definition: uves_msg.h:87
const char * uves_pfits_get_arcfile(const uves_propertylist *plist)
find out the arcfile
Definition: uves_pfits.c:272
int uves_qclog_add_string(cpl_table *table, const char *key_name, const char *value, const char *key_help, const char *format)
Add string key to QC-LOG table.
Definition: uves_qclog.c:683
#define check_nomsg(CMD)
Definition: uves_error.h:204
const char * uves_pfits_get_dpr_catg(const uves_propertylist *plist)
find out the data category as defined by the DataFlow
Definition: uves_pfits.c:440
int uves_qclog_delete(cpl_table **table)
delete QC-LOG table
Definition: uves_qclog.c:716
double uves_pfits_get_gratwlen(const uves_propertylist *plist, enum uves_chip chip)
find out the central wavelength
Definition: uves_pfits.c:1371
int uves_qclog_add_double(cpl_table *table, const char *key_name, const double value, const char *key_help, const char *format)
Add double key to QC-LOG table.
Definition: uves_qclog.c:641
int uves_qclog_add_float(cpl_table *table, const char *key_name, const float value, const char *key_help, const char *format)
Add float key to QC-LOG table.
Definition: uves_qclog.c:600
double uves_pfits_get_slitwidth(const uves_propertylist *plist, enum uves_chip chip)
find out the slit width
Definition: uves_pfits.c:1504
const char * uves_pfits_get_pro_catg(const uves_propertylist *plist)
find out the product category as defined by the DataFlow
Definition: uves_pfits.c:494
int uves_qclog_dump_common_wave(const uves_propertylist *plist, enum uves_chip chip, cpl_table *qclog)
Create common QC log.
Definition: uves_qclog.c:1166
const char * uves_pfits_get_chip_name(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip name.
Definition: uves_pfits.c:639
int uves_qclog_add_int(cpl_table *table, const char *key_name, const int value, const char *key_help, const char *format)
Add integer key to QC-LOG table.
Definition: uves_qclog.c:521
int uves_qclog_add_bool(cpl_table *table, const char *key_name, const char value, const char *key_help, const char *format)
Add boolean key to QC-LOG table.
Definition: uves_qclog.c:561
void uves_get_paf_name(const char *in, int paf_no, char **paf)
get paf file name
Definition: uves_qclog.c:165
int uves_pfits_get_binx(const uves_propertylist *plist)
Find out the x binning factor.
Definition: uves_pfits.c:1176
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
Definition: uves_msg.h:119
cpl_error_code uves_propertylist_set_comment(uves_propertylist *self, const char *name, const char *comment)
Modify the comment field of the given property list entry.
const char * uves_propertylist_get_string(const uves_propertylist *self, const char *name)
Get the string value of the given property list entry.
int uves_pfits_get_biny(const uves_propertylist *plist)
Find out the y binning factor.
Definition: uves_pfits.c:1194
void uves_qclog_add_sci(cpl_table *qclog, const uves_propertylist *raw_header, const cpl_image *raw_image, double slit, const cpl_table *info_tbl)
Write QC parameters related to science reduction.
Definition: uves_qclog.c:803
const char * uves_remove_string_prefix(const char *s, const char *prefix)
Remove named prefix from string.
Definition: uves_utils.c:3612
const char * uves_pfits_get_gratname(const uves_propertylist *plist, enum uves_chip chip)
find out the grating name value
Definition: uves_pfits.c:1427
const char * uves_pfits_get_insmode(const uves_propertylist *plist)
find out the chip name value
Definition: uves_pfits.c:1391
const char * uves_pfits_get_inspath(const uves_propertylist *plist)
find out the chip name value
Definition: uves_pfits.c:1409
const char * uves_pfits_get_readspeed(const uves_propertylist *plist)
find out the readout speed
Definition: uves_pfits.c:1446
int uves_qclog_dump_common(const uves_propertylist *plist, enum uves_chip chip, cpl_table *qclog)
Create common QC log.
Definition: uves_qclog.c:1009
#define uves_msg_debug(...)
Print a debug message.
Definition: uves_msg.h:97
const char * uves_pfits_get_dpr_type(const uves_propertylist *plist)
find out the data type as defined by the DataFlow
Definition: uves_pfits.c:532
void uves_qclog_add_common_wave(const uves_propertylist *raw_header, enum uves_chip chip, cpl_table *qclog)
Write common QC parameters.
Definition: uves_qclog.c:942
const char * uves_pfits_get_templateid(const uves_propertylist *plist)
find out the template id
Definition: uves_pfits.c:399
int uves_propertylist_contains(const uves_propertylist *self, const char *name)
Check whether a property is present in a property list.
const char * uves_pfits_get_rec1raw1name(const uves_propertylist *plist)
find out the arcfile
Definition: uves_pfits.c:380
static FILE * uves_paf_print_header(const char *filename, const char *paf_id, const char *paf_desc, const char *login_name, const char *datetime)
Open a new PAF file, output a default header.
Definition: uves_qclog.c:101
#define check(CMD,...)
Definition: uves_error.h:198
cpl_table * uves_qclog_init(const uves_propertylist *raw_header, enum uves_chip chip)
Init QC-LOG table.
Definition: uves_qclog.c:410
void uves_baryvel(const uves_propertylist *raw_header, double *bary_corr, double *helio_corr)
Compute velocity correction.
Definition: uves_baryvel.c:120
const char * uves_pfits_get_chipid(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip ID.
Definition: uves_pfits.c:619
const char * uves_qclog_get_qc_name(const char *name, bool flames, int trace_number)
Create QC parameter name.
Definition: uves_qclog.c:985
int uves_blank2dot(const char *in, char *ou)
replace a blank to a dot
Definition: uves_qclog.c:189
const char * uves_pfits_get_pipefile(const uves_propertylist *plist)
find out the pipefile
Definition: uves_pfits.c:355
int uves_pfits_put_qc(uves_propertylist *plist, const cpl_table *qclog)
Add QC-LOG to FITS header.
Definition: uves_qclog.c:735