58#define PAF_KEY_FORMAT "%-21s "
75 const char * filename,
76 const cpl_propertylist* primary_header) ;
78 const char * kwnamw,
const cpl_propertylist * paflist,
81 const char *comment, FILE *paf ) ;
83 const char *comment, FILE *paf ) ;
85 const char *comment, FILE *paf ) ;
106 const cpl_propertylist * paflist,
107 const char * filename,
108 const char * pro_catg )
156 if ( strchr( pqc->
kw_name,
'i' ) != NULL ) {
164 for( i = 0, pk = pqc->
kw_name, pm = kformat ; *pk !=
'\0' ; i++, pk++ )
171 for( i = 0 ; i<10 ; i++ ) {
173 sprintf( curname, kformat, i ) ;
175 if ( cpl_propertylist_has( paflist, curname ) ) {
183 if ( i == 0 )
xsh_msg(
"QC Parameter \"%s\" NOT in propertylist",
186 else if ( cpl_propertylist_has( paflist, pqc->
kw_name ) ) {
192 else xsh_msg_debug(
"QC Parameter \"%s\" NOT in propertylist",
201 return cpl_error_get_code() ;
228 const char * filename,
229 const cpl_propertylist* primary_header)
232 char * paf_id = NULL;
233 const char paf_desc[] =
"QC file";
235 cpl_error_code error;
236 const char* key_value = NULL;
239 cpl_ensure(
instrument != NULL, CPL_ERROR_NULL_INPUT, NULL);
240 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL);
241 cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL);
244 paf_id = cpl_malloc(
sizeof(
char) *
245 (strlen(
instrument) + strlen(
"/") + strlen(recipe) + 1));
246 assert( paf_id != NULL);
249 strcat(paf_id, recipe);
253 paf = fopen(filename,
"w");
257 cpl_ensure(0, CPL_ERROR_FILE_IO, NULL);
264 error = CPL_ERROR_NONE;
267 nlen = fprintf(paf,
"PAF.HDR.START ;# start of header\n");
268 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
272 nlen = fprintf(paf,
"PAF.TYPE \"pipeline product\" ;\n");
273 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
277 nlen = fprintf(paf,
"PAF.ID \"%s\"\n", paf_id);
278 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
282 nlen = fprintf(paf,
"PAF.NAME \"%s\"\n", filename);
283 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
287 nlen = fprintf(paf,
"PAF.DESC \"%s\"\n", paf_desc);
288 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
292 nlen = fprintf(paf,
"PAF.CHCK.CHECKSUM \"\"\n");
293 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
297 nlen = fprintf(paf,
"PAF.HDR.END ;# end of header\n");
298 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
302 if(cpl_propertylist_has(primary_header,
"ARCFILE")) {
303 key_value=cpl_propertylist_get_string(primary_header,
"ARCFILE");
305 key_value=
"ARCFILE_NOT_FOUND";
308 nlen = fprintf(paf,
"ARCFILE \"%s\";# archive file name\n",key_value);
309 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
312 if(cpl_propertylist_has(primary_header,
"PIPEFILE")) {
313 key_value=cpl_propertylist_get_string(primary_header,
"PIPEFILE");
315 key_value=
"PIPEFILE_NOT_FOUND";
318 nlen = fprintf(paf,
"PIPEFILE \"%s\";# File name of data product\n",key_value);
319 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
323 if(cpl_propertylist_has(primary_header,
"PRO.REC1.PIPE.ID")) {
324 key_value=cpl_propertylist_get_string(primary_header,
"PRO.REC1.PIPE.ID");
326 key_value=
"PRO_REC1_PIPE_ID_NOT_FOUND";
329 nlen = fprintf(paf,
"PRO.REC1.PIPE.ID \"%s\";# Pipeline (unique) identifier\n",key_value);
330 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
337 nlen = fprintf(paf,
"PRO.TYPE \"REDUCED\";# Product type\n");
338 if (nlen <=
PAF_KEY_LEN) error = CPL_ERROR_FILE_IO;
344 nlen = fprintf(paf,
"\n");
345 if (nlen != 1) error = CPL_ERROR_FILE_IO;
358 cpl_msg_error(cpl_func,
"Could not write PAF: %s", filename);
360 cpl_ensure(0, error, NULL);
368 for( ; *str !=
'\0' ; str++ )
369 if ( *str ==
' ' ) *str =
'.' ;
402 const cpl_propertylist * paflist,
405 cpl_error_code err=CPL_ERROR_NONE;
406 char * keydot = NULL, *pk ;
408 keydot = cpl_strdup( kwname ) ;
412 if ( strncmp( keydot,
"ESO.", 4 ) == 0 ) pk += 4 ;
415 switch( cpl_propertylist_get_type( paflist, kwname ) ) {
418 cpl_propertylist_get_char( paflist, kwname),
423 cpl_propertylist_get_int( paflist, kwname),
427 if (
sizeof(
long) ==
sizeof(
int))
429 cpl_propertylist_get_long( paflist,
435 cpl_propertylist_get_float( paflist,
439 case CPL_TYPE_DOUBLE:
441 cpl_propertylist_get_double( paflist,
445 case CPL_TYPE_STRING:
447 cpl_propertylist_get_string( paflist,
452 err = CPL_ERROR_UNSUPPORTED_MODE;
469 const char *comment, FILE *paf )
471 cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT);
472 cpl_ensure_code(key, CPL_ERROR_NULL_INPUT);
483 return CPL_ERROR_NONE;
497 const char *comment, FILE *paf )
499 cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT);
500 cpl_ensure_code(key, CPL_ERROR_NULL_INPUT);
511 return CPL_ERROR_NONE;
527 const char *comment, FILE *paf )
529 cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT);
530 cpl_ensure_code(key, CPL_ERROR_NULL_INPUT);
531 cpl_ensure_code(value, CPL_ERROR_NULL_INPUT);
542 return CPL_ERROR_NONE;
static xsh_instrument * instrument
#define XSH_ASSURE_NOT_NULL(pointer)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
#define xsh_msg_debug(...)
Print a debug message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
static FILE * irplib_paf_init(const xsh_instrument *instrume, const char *recipe, const char *filename, const cpl_propertylist *primary_header)
Open a new PAF file, output a default header.
static cpl_error_code irplib_paf_dump_double(char *kw, double value, const char *comment, FILE *paf)
Print a double-property as PAF.
static cpl_error_code irplib_paf_dump(qc_description *pqc, const char *kwnamw, const cpl_propertylist *paflist, FILE *paf)
Print a propertylist as PAF.
cpl_error_code xsh_paf_save(const xsh_instrument *instrument, const char *recipe, const cpl_propertylist *paflist, const char *filename, const char *pro_catg)
Create a new PAF file.
static cpl_error_code irplib_paf_dump_string(char *kw, const char *value, const char *comment, FILE *paf)
Print a string-property as PAF.
static void no_space(char *str)
static cpl_error_code irplib_paf_dump_int(char *kw, int value, const char *comment, FILE *paf)
Print an int-property as PAF.
int xsh_is_qc_for_arm(const char *arm, qc_description *pqc)
qc_description * xsh_get_qc_desc_by_recipe(const char *recipe, qc_description *prev)
int xsh_is_qc_for_pro_catg(const char *pro_catg, qc_description *pqc)
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.