31 #include <uves_time.h>
32 #include <uves_globals.h>
42 #define FILE_NAME_SZ 1024
50 #include "uves_qclog.h"
52 #include <uves_baryvel.h>
53 #include <uves_utils_wrappers.h>
54 #include <uves_pfits.h>
55 #include <uves_error.h>
58 #include <irplib_utils.h>
69 const char * filename,
71 const char * paf_desc,
72 const char * login_name,
73 const char * datetime) ;
102 const char * filename,
104 const char * paf_desc,
105 const char * login_name,
106 const char * datetime)
110 if ((paf=fopen(filename,
"w"))==NULL) {
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");
139 static char path[MAX_NAME_SIZE+1];
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")))
153 lastdot[0] = (char)0;
170 if (strstr(in,
"." ) != NULL )
177 sprintf(name_b,
"%s", in) ;
180 sprintf(*paf,
"%s-%d.paf", name_b, paf_no);
228 const cpl_table* qclog,
231 const char* pro_catg)
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] ;
248 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
266 strcpy(key_name,KEY_NAME_QC_DID);
267 strcpy(key_paf,PAF_NAME_QC_DID);
269 fprintf(paf,
"%-21s \"%s\" ; # %s \n",key_dpaf,
274 fprintf(paf,
"%-21s \"%s/%s\" ; # %s \n", key_dpaf,
275 PACKAGE, PACKAGE_VERSION,KEY_HELP_PIPE_ID);
277 strcpy(key_name, KEY_NAME_PIPEFILE);
278 strcpy(key_paf, KEY_NAME_PIPEFILE);
281 fprintf(paf,
"%-21s \"%s\" ; # %s \n", key_dpaf,
286 strcpy(key_name,KEY_NAME_PRO_TYPE);
287 strcpy(key_paf,PAF_NAME_PRO_TYPE);
290 fprintf(paf,
"%-21s \"%s\" ; # %s \n", key_dpaf,
294 strcpy(key_name,KEY_NAME_PRO_RECID);
295 strcpy(key_paf,PAF_NAME_PRO_RECID);
298 fprintf(paf,
"%-21s \"%s\" ; # %s \n", key_dpaf,
303 strcpy(key_name,KEY_NAME_PRO_DRSID);
304 strcpy(key_paf,PAF_NAME_PRO_DRSID);
307 fprintf(paf,
"%-21s \"%s\" ; # %s \n",key_dpaf,
322 strcpy(key_paf,KEY_NAME_ARCFILE);
324 fprintf(paf,
"%-21s \"%s\" ; # %s \n", key_dpaf,sval,KEY_HELP_ARCFILE) ;
327 strcpy(key_paf,KEY_NAME_ARCFILE);
330 uves_msg_error(
"%s is missing QC LOG will fail!",KEY_NAME_ARCFILE);
336 strcpy(key_paf,PAF_NAME_TPL_ID);
338 fprintf(paf,
"%-21s \"%s\" ; # %s\n", key_dpaf,
339 sval,KEY_HELP_TPL_ID) ;
345 strcpy(key_paf,PAF_NAME_DPR_TYPE);
347 fprintf(paf,
"%-21s \"%s\" ; # %s\n", key_dpaf,
348 sval, KEY_HELP_DPR_TYPE) ;
353 strcpy(key_paf,PAF_NAME_DPR_TECH);
355 fprintf(paf,
"%-21s \"%s\" ; # %s\n", key_dpaf,
356 sval, KEY_HELP_DPR_TECH) ;
361 strcpy(key_paf,PAF_NAME_DPR_CATG);
363 fprintf(paf,
"%-21s \"%s\" ; # %s\n", key_dpaf,
364 sval, KEY_HELP_DPR_CATG) ;
367 strcpy(key_paf,PAF_NAME_PRO_CATG);
369 fprintf(paf,
"%-21s \"%s\" ; # %s\n", key_dpaf,
370 pro_catg, KEY_HELP_PRO_CATG) ;
372 n=cpl_table_get_nrow(qclog);
375 strcpy(key_paf,cpl_table_get_string(qclog,
"key_name",i));
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));
381 if (strcmp(key_type,
"CPL_TYPE_STRING") == 0)
383 fprintf(paf,
"%s \"%s\"\n",
384 key_name, key_value);
388 fprintf(paf,
"%s %s\n",
389 key_name, key_value);
413 cpl_table *qclog = NULL;
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);
433 "Optical path used.",
446 "Instrument mode used.",
460 "Grating common name",
478 "Binning factor along X",
484 "Binning factor along Y",
493 "Detector chip name",
522 const char* key_name,
524 const char* key_help,
527 int sz = cpl_table_get_nrow(table);
529 char key_value[FILE_NAME_SZ];
530 char key_type[FILE_NAME_SZ];
532 sprintf(key_value,format,value);
533 strcpy(key_type,
"CPL_TYPE_INT");
535 cpl_table_set_size(table,sz+1);
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);
562 const char* key_name,
564 const char* key_help,
567 int sz = cpl_table_get_nrow(table);
569 char key_value[FILE_NAME_SZ];
570 char key_type[FILE_NAME_SZ];
572 sprintf(key_value,format,value);
573 strcpy(key_type,
"CPL_TYPE_BOOL");
575 cpl_table_set_size(table,sz+1);
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);
601 const char* key_name,
603 const char* key_help,
606 int sz = cpl_table_get_nrow(table);
608 char key_value[FILE_NAME_SZ];
609 char key_type[FILE_NAME_SZ];
611 sprintf(key_value,format,value);
612 strcpy(key_type,
"CPL_TYPE_FLOAT");
614 cpl_table_set_size(table,sz+1);
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);
642 const char* key_name,
644 const char* key_help,
647 int sz = cpl_table_get_nrow(table);
649 char key_value[FILE_NAME_SZ];
650 char key_type[FILE_NAME_SZ];
652 sprintf(key_value,format,value);
653 strcpy(key_type,
"CPL_TYPE_DOUBLE");
655 cpl_table_set_size(table,sz+1);
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);
684 const char* key_name,
686 const char* key_help,
689 int sz = cpl_table_get_nrow(table);
691 char key_value[FILE_NAME_SZ];
692 char key_type[FILE_NAME_SZ];
694 sprintf(key_value,format,value);
695 strcpy(key_type,
"CPL_TYPE_STRING");
697 cpl_table_set_size(table,sz+1);
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);
719 cpl_table_delete(*table);
737 const cpl_table * qclog)
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] ;
753 n=cpl_table_get_nrow(qclog);
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));
763 if(strcmp(key_type,
"CPL_TYPE_STRING") == 0) {
764 uves_propertylist_append_string(plist, key_name,key_value) ;
766 }
else if(strcmp(key_type,
"CPL_TYPE_BOOL") == 0) {
768 uves_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
770 }
else if(strcmp(key_type,
"CPL_TYPE_INT") == 0) {
771 uves_propertylist_append_int(plist,key_name,atoi(key_value)) ;
773 }
else if(strcmp(key_type,
"CPL_TYPE_FLOAT") == 0) {
774 uves_propertylist_append_float(plist, key_name,(
float)atof(key_value)) ;
776 }
else if(strcmp(key_type,
"CPL_TYPE_DOUBLE") == 0) {
777 uves_propertylist_append_double(plist, key_name,atof(key_value)) ;
805 const cpl_image *raw_image,
807 const cpl_table *info_tbl)
816 if (info_tbl != NULL) {
817 int minorder = cpl_table_get_int(info_tbl,
"Order", 0, NULL);
818 int maxorder = minorder;
822 for(i = 0; i < cpl_table_get_nrow(info_tbl); i++) {
823 int order = cpl_table_get_int(info_tbl,
"Order", i, NULL);
825 minorder = uves_min_int(minorder, order);
826 maxorder = uves_max_int(maxorder, order);
837 uves_msg_debug(
"QC-LOG: Order = %d, S/N = %g, Pos = %g, FHWM = %g, RI = %g",
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));
845 sprintf(key_name,
"QC ORD%d OBJ SN", order);
848 cpl_table_get_double(info_tbl,
"ObjSnBlzCentre",i, NULL),
849 "Av. S/N at order center",
852 sprintf(key_name,
"QC ORD%d OBJ POS", order);
855 cpl_table_get_double(info_tbl,
"ObjPosOnSlit",i, NULL),
856 "Av. OBJ POS at order center",
859 sprintf(key_name,
"QC ORD%d OBJ FWHM", order);
862 cpl_table_get_double(info_tbl,
"ObjFwhmAvg",i, NULL),
866 sprintf(key_name,
"QC ORD%d OBJ RPLPAR", order);
869 cpl_table_get_double(info_tbl,
"Ripple",i, NULL),
870 "Av. relative ripple amplitude",
884 norder = maxorder - minorder + 1;
888 "No. of orders extracted",
893 cpl_image_get_size_x(raw_image),
894 "Input image width (pixels)",
899 uves_round_double(slit),
900 "Extraction slit (pixels)",
905 double barycor, helicor;
910 "Could not compute velocity corrections");
915 "Barycentric radial velocity correction ",
921 "Heliocentric radial velocity correction ",
950 "Slit width (arcsec) [arcsec] (hs).",
956 "Grating central wavelength [nm] (hs).",
965 "Average temperature [C] (ho).",
986 bool flames,
int trace_number)
990 return uves_sprintf(
"QC FIB%d %s", trace_number + 1, name);
994 return uves_sprintf(
"QC %s", name);
1010 enum uves_chip chip,
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;
1046 "Pipeline (unique) identifier",
1052 "Data Processing Type",
1064 "Archive file name",
1077 "Pipeline file name",
1097 "Grating common name",
1103 "Detector chip name",
1136 "Binning factor along X",
1143 "Binning factor along Y",
1167 enum uves_chip chip,
1170 double slit_width=0;
1181 "Slit width (arcsec) [arcsec] (hs).",
1188 "Grating central wavelength [nm] (hs).",
1195 "Average temperature [c] (ho).",
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.
#define uves_msg_error(...)
Print an error message.
const char * uves_pfits_get_dpr_tech(const uves_propertylist *plist)
find out the data tech as defined by the DataFlow
char * uves_get_rootname(const char *filename)
computes rootname
double uves_pfits_get_tempcam(const uves_propertylist *plist, enum uves_chip chip)
find out the pressure value
char * uves_get_datetime_iso8601(void)
Returns the current date and time as a static string.
#define uves_msg_warning(...)
Print an warning message.
const char * uves_pfits_get_arcfile(const uves_propertylist *plist)
find out the arcfile
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.
const char * uves_pfits_get_dpr_catg(const uves_propertylist *plist)
find out the data category as defined by the DataFlow
int uves_qclog_delete(cpl_table **table)
delete QC-LOG table
double uves_pfits_get_gratwlen(const uves_propertylist *plist, enum uves_chip chip)
find out the central wavelength
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.
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.
double uves_pfits_get_slitwidth(const uves_propertylist *plist, enum uves_chip chip)
find out the slit width
const char * uves_pfits_get_pro_catg(const uves_propertylist *plist)
find out the product category as defined by the DataFlow
int uves_qclog_dump_common_wave(const uves_propertylist *plist, enum uves_chip chip, cpl_table *qclog)
Create common QC log.
const char * uves_pfits_get_chip_name(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip name.
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.
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.
void uves_get_paf_name(const char *in, int paf_no, char **paf)
get paf file name
int uves_pfits_get_binx(const uves_propertylist *plist)
Find out the x binning factor.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
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.
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.
const char * uves_remove_string_prefix(const char *s, const char *prefix)
Remove named prefix from string.
const char * uves_pfits_get_gratname(const uves_propertylist *plist, enum uves_chip chip)
find out the grating name value
const char * uves_pfits_get_insmode(const uves_propertylist *plist)
find out the chip name value
const char * uves_pfits_get_inspath(const uves_propertylist *plist)
find out the chip name value
const char * uves_pfits_get_readspeed(const uves_propertylist *plist)
find out the readout speed
int uves_qclog_dump_common(const uves_propertylist *plist, enum uves_chip chip, cpl_table *qclog)
Create common QC log.
#define uves_msg_debug(...)
Print a debug message.
const char * uves_pfits_get_dpr_type(const uves_propertylist *plist)
find out the data type as defined by the DataFlow
void uves_qclog_add_common_wave(const uves_propertylist *raw_header, enum uves_chip chip, cpl_table *qclog)
Write common QC parameters.
const char * uves_pfits_get_templateid(const uves_propertylist *plist)
find out the template id
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
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.
cpl_table * uves_qclog_init(const uves_propertylist *raw_header, enum uves_chip chip)
Init QC-LOG table.
void uves_baryvel(const uves_propertylist *raw_header, double *bary_corr, double *helio_corr)
Compute velocity correction.
const char * uves_pfits_get_chipid(const uves_propertylist *plist, enum uves_chip chip)
Find out the chip ID.
const char * uves_qclog_get_qc_name(const char *name, bool flames, int trace_number)
Create QC parameter name.
int uves_blank2dot(const char *in, char *ou)
replace a blank to a dot
const char * uves_pfits_get_pipefile(const uves_propertylist *plist)
find out the pipefile
int uves_pfits_put_qc(uves_propertylist *plist, const cpl_table *qclog)
Add QC-LOG to FITS header.