40 #include <fors_utils.h>
45 #define DICT_LINE_LENGTH (80)
46 #define MAX_PAF_NAME_LENGTH (80)
47 #define PAF_ROOT_NAME "qc"
56 const char *
const fors_qc_dic_version =
"2.0";
59 static int pafIndex = 0;
78 const char *qcdic_version,
79 const char *instrument)
81 char pafName[MAX_PAF_NAME_LENGTH];
84 return cpl_error_set(
"fors_qc_start_group", CPL_ERROR_FILE_ALREADY_OPEN);
86 sprintf(pafName,
"%s%.4d.paf", PAF_ROOT_NAME, pafIndex);
88 if (!(pafFile =
newForsPAF(pafName,
"QC1 parameters", NULL, NULL)))
89 return cpl_error_set(
"fors_qc_start_group", CPL_ERROR_FILE_NOT_CREATED);
92 "QC.DID", qcdic_version,
"QC1 dictionary",
95 return CPL_ERROR_NONE;
102 cpl_propertylist_delete(header); \
116 const char *pro_catg,
117 const char *instrument)
119 cpl_propertylist *header = NULL;
120 assure( raw_frame != NULL,
return, NULL );
121 assure( cpl_frame_get_filename(raw_frame) != NULL,
return, NULL );
123 header = cpl_propertylist_load(cpl_frame_get_filename(raw_frame), 0);
124 assure( !cpl_error_get_code(),
return,
"Could not load %s header",
125 cpl_frame_get_filename(raw_frame));
128 "Product category", instrument);
129 assure( !cpl_error_get_code(),
return,
"Cannot write product category to "
133 "DPR type", instrument);
134 assure( !cpl_error_get_code(),
return,
"Missing keyword DPR TYPE in raw "
138 "Template", instrument);
139 assure( !cpl_error_get_code(),
return,
"Missing keyword TPL ID in raw "
142 if (cpl_propertylist_has(header,
"ESO INS FILT1 NAME")) {
144 "Filter name", instrument);
145 assure( !cpl_error_get_code(),
return,
"Failed to write ESO INS FILT1 NAME");
149 "Collimator name", instrument);
150 assure( !cpl_error_get_code(),
return,
"Missing keyword INS COLL NAME in raw "
154 "Chip identifier", instrument);
155 assure( !cpl_error_get_code(),
return,
"Missing keyword DET CHIP1 ID in raw "
159 "Binning factor along X", instrument);
160 assure( !cpl_error_get_code(),
return,
"Missing keyword ESO DET WIN1 BINX "
161 "in raw frame header");
164 "Binning factor along Y", instrument);
165 assure( !cpl_error_get_code(),
return,
"Missing keyword ESO DET WIN1 BINY "
166 "in raw frame header");
169 "Archive name of input data",
171 assure( !cpl_error_get_code(),
return,
"Missing keyword ARCFILE in raw "
175 char *pipefile = dfs_generate_filename(pro_catg);
177 "Pipeline product name", instrument);
178 cpl_free(pipefile); pipefile = NULL;
179 assure( !cpl_error_get_code(),
return,
"Cannot write PIPEFILE to QC log file");
204 return cpl_error_set(
"fors_qc_end_group", CPL_ERROR_DATA_NOT_FOUND);
214 return CPL_ERROR_NONE;
236 const char *comment,
const char *instrument)
240 int length = strlen(instrument) + 3;
244 if (comment == NULL || name == NULL || instrument == NULL)
245 return cpl_error_set(
"fors_qc_write_string", CPL_ERROR_NULL_INPUT);
247 length += strlen(comment) + 1;
249 allComment = cpl_malloc(length *
sizeof(
char));
251 sprintf(allComment,
"%s [%s]", comment, instrument);
255 cpl_free(allComment);
258 cpl_msg_error(
"fors_qc_write_string",
259 "Cannot write parameter %s to QC1 PAF", name);
261 cpl_msg_debug(cpl_func,
"%s [%s] = '%s'", comment, name, value);
263 return CPL_ERROR_NONE;
267 cpl_error_code fors_qc_write_string_chat(
const char *name,
const char *value,
268 const char *comment,
const char *instrument)
272 int length = strlen(instrument) + 3;
276 if (comment == NULL || name == NULL || instrument == NULL)
277 return cpl_error_set(
"fors_qc_write_string_chat", CPL_ERROR_NULL_INPUT);
279 length += strlen(comment) + 1;
281 allComment = cpl_malloc(length *
sizeof(
char));
283 sprintf(allComment,
"%s [%s]", comment, instrument);
287 cpl_free(allComment);
290 cpl_msg_error(
"fors_qc_write_string_chat",
291 "Cannot write parameter %s to QC1 PAF", name);
293 cpl_msg_info(cpl_func,
"%s [%s] = '%s'", comment, name, value);
295 return CPL_ERROR_NONE;
322 const char *unit,
const char *comment,
323 const char *instrument)
326 cpl_error_code status;
327 int length = strlen(instrument) + 3;
331 if (comment == NULL || name == NULL || instrument == NULL)
332 return cpl_error_set(
"fors_qc_write_double", CPL_ERROR_NULL_INPUT);
334 length += strlen(comment) + 1;
337 length += strlen(unit) + 3;
339 allComment = cpl_malloc(length *
sizeof(
char));
342 sprintf(allComment,
"%s (%s) [%s]", comment, unit, instrument);
344 sprintf(allComment,
"%s [%s]", comment, instrument);
348 cpl_free(allComment);
351 cpl_msg_error(
"fors_qc_write_double",
352 "Cannot write parameter %s to QC1 PAF", name);
354 cpl_msg_info(cpl_func,
"%s [%s] = %f %s",
355 comment, name, value, (unit != NULL) ? unit :
"");
357 return CPL_ERROR_NONE;
362 cpl_error_code fors_qc_write_int(
const char *name,
int value,
const char *unit,
363 const char *comment,
const char *instrument)
366 cpl_error_code status;
367 int length = strlen(instrument) + 3;
371 if (comment == NULL || name == NULL || instrument == NULL)
372 return cpl_error_set(
"fors_qc_write_int", CPL_ERROR_NULL_INPUT);
374 length += strlen(comment) + 1;
377 length += strlen(unit) + 3;
379 allComment = cpl_malloc(length *
sizeof(
char));
382 sprintf(allComment,
"%s (%s) [%s]", comment, unit, instrument);
384 sprintf(allComment,
"%s [%s]", comment, instrument);
388 cpl_free(allComment);
391 cpl_msg_error(
"fors_qc_write_int",
392 "Cannot write parameter %s to QC1 PAF", name);
394 cpl_msg_info(cpl_func,
"%s [%s] = %d %s",
395 comment, name, value, (unit != NULL) ? unit :
"");
397 return CPL_ERROR_NONE;
426 const char *name,
const char *unit,
428 const char *instrument)
431 const char func[] =
"fors_qc_keyword_to_paf";
444 if (header == NULL) {
445 cpl_msg_error(func,
"Empty header");
446 return cpl_error_set(func, CPL_ERROR_NULL_INPUT);
449 if (!cpl_propertylist_has(header, name)) {
450 cpl_msg_error(func,
"Keyword %s not found", name);
451 return cpl_error_set(func, CPL_ERROR_DATA_NOT_FOUND);
454 switch (cpl_propertylist_get_type(header, name)) {
456 ivalue = cpl_propertylist_get_int(header, name);
458 case CPL_TYPE_FLOAT :
459 fvalue = cpl_propertylist_get_float(header, name);
461 case CPL_TYPE_DOUBLE :
462 dvalue = cpl_propertylist_get_double(header, name);
464 case CPL_TYPE_STRING :
465 svalue = (
char *)cpl_propertylist_get_string(header, name);
468 cpl_msg_error(func,
"Unsupported keyword type");
469 return cpl_error_set(func, CPL_ERROR_INVALID_TYPE);
477 keep = keyName = cpl_strdup(name);
479 pos = strstr(keyName,
"ESO ");
484 for (i = 0; keyName[i] !=
'\0'; i++)
485 if (keyName[i] ==
' ')
492 switch (cpl_propertylist_get_type(header, name)) {
494 status = fors_qc_write_int(keyName, ivalue, unit, comment, instrument);
496 case CPL_TYPE_FLOAT :
498 case CPL_TYPE_DOUBLE :
506 cpl_msg_error(func,
"Could not copy keyword value to QC1 PAF!");
536 const char *name,
const char *value,
538 const char *instrument)
540 const char func[] =
"fors_qc_write_qc_string";
545 if (strcmp(
"QC.DID", name)) {
546 if (fors_qc_write_string_chat(name, value, comment, instrument)) {
547 cpl_error_set_where(func);
548 return cpl_error_get_code();
553 cpl_error_set_where(func);
554 return cpl_error_get_code();
558 header_name = cpl_malloc((strlen(name) + 6) *
sizeof(
char *));
560 strcpy(header_name,
"ESO ");
561 strcat(header_name, name);
563 for (i = 0; header_name[i] !=
'\0'; i++)
564 if (header_name[i] ==
'.')
565 header_name[i] =
' ';
567 if (cpl_propertylist_update_string(header, header_name, value)) {
568 cpl_free(header_name);
569 cpl_error_set_where(func);
570 return cpl_error_get_code();
573 cpl_propertylist_set_comment(header, header_name, comment);
575 cpl_free(header_name);
577 return CPL_ERROR_NONE;
605 const char *name,
const char *unit,
607 const char *instrument)
610 const char func[] =
"fors_qc_write_qc_double";
617 cpl_error_set_where(func);
618 return cpl_error_get_code();
621 header_name = cpl_malloc((strlen(name) + 6) *
sizeof(
char *));
623 strcpy(header_name,
"ESO ");
624 strcat(header_name, name);
626 for (i = 0; header_name[i] !=
'\0'; i++)
627 if (header_name[i] ==
'.')
628 header_name[i] =
' ';
630 if (cpl_propertylist_update_double(header, header_name, value)) {
631 cpl_free(header_name);
632 cpl_error_set_where(func);
633 return cpl_error_get_code();
636 cpl_propertylist_set_comment(header, header_name, comment);
638 cpl_free(header_name);
640 return CPL_ERROR_NONE;
645 cpl_error_code fors_qc_write_qc_int(cpl_propertylist *header,
int value,
646 const char *name,
const char *unit,
648 const char *instrument)
651 const char func[] =
"fors_qc_write_qc_int";
657 if (fors_qc_write_int(name, value, unit, comment, instrument)) {
658 cpl_error_set_where(func);
659 return cpl_error_get_code();
662 header_name = cpl_malloc((strlen(name) + 6) *
sizeof(
char *));
664 strcpy(header_name,
"ESO ");
665 strcat(header_name, name);
667 for (i = 0; header_name[i] !=
'\0'; i++)
668 if (header_name[i] ==
'.')
669 header_name[i] =
' ';
671 if (cpl_propertylist_update_int(header, header_name, value)) {
672 cpl_free(header_name);
673 cpl_error_set_where(func);
674 return cpl_error_get_code();
677 cpl_propertylist_set_comment(header, header_name, comment);
679 cpl_free(header_name);
681 return CPL_ERROR_NONE;
int forsPAFAppendInt(ForsPAF *paf, const char *name, int value, const char *comment)
Append a integer value to a PAF object.
cpl_error_code fors_qc_write_qc_string(cpl_propertylist *header, const char *name, const char *value, const char *comment, const char *instrument)
Write a string value to the active QC1 PAF object and to a header.
cpl_error_code fors_qc_write_double(const char *name, double value, const char *unit, const char *comment, const char *instrument)
Add double parameter to current QC1 group.
int forsPAFIsEmpty(const ForsPAF *paf)
Check whether a PAF object is empty.
void deleteForsPAF(ForsPAF *paf)
Destroy a PAF object.
cpl_error_code fors_qc_write_qc_double(cpl_propertylist *header, double value, const char *name, const char *unit, const char *comment, const char *instrument)
Write an integer value to the active QC1 PAF object and to a header.
cpl_error_code fors_qc_keyword_to_paf(cpl_propertylist *header, const char *name, const char *unit, const char *comment, const char *instrument)
Copy a keyword value to the currently active QC1 PAF object.
cpl_error_code fors_qc_start_group(cpl_propertylist *header, const char *qcdic_version, const char *instrument)
Initiate a new QC1 group.
cpl_error_code fors_qc_write_string(const char *name, const char *value, const char *comment, const char *instrument)
Add string parameter to current QC1 group.
int forsPAFAppendDouble(ForsPAF *paf, const char *name, double value, const char *comment)
Append a double value to a PAF object.
cpl_error_code fors_qc_end_group(void)
Close current QC1 PAF file.
int forsPAFWrite(ForsPAF *paf)
Write a PAF object to a disk file.
void fors_qc_write_group_heading(const cpl_frame *raw_frame, const char *pro_catg, const char *instrument)
Initiate a new QC1 group and log basic QC.
int forsPAFAppendString(ForsPAF *paf, const char *name, const char *value, const char *comment)
Append a string value to a PAF object.
ForsPAF * newForsPAF(const char *name, const char *type, const char *id, const char *desc)
Create a new PAF object.