24 #include "sinfo_pro_save.h"
25 #include "sinfo_key_names.h"
26 #include "sinfo_functions.h"
27 #include "sinfo_utilities.h"
28 #include "sinfo_globals.h"
32 cpl_propertylist * plist,
36 sinfo_log_pro(
char* name_o,
39 cpl_frameset* ref_set,
40 cpl_frameset** out_set,
41 cpl_propertylist** plist,
42 cpl_parameterlist* parlist,
47 sinfo_check_name(
const char* in,
char** ou,
int type,
char** paf);
50 sinfo_clean_header(cpl_propertylist** header);
52 sinfo_clean_cube_header(cpl_propertylist** header);
56 sinfo_paf_print_header(
57 const char * filename,
59 const char * paf_desc,
60 const char * login_name,
98 sinfo_paf_print_header(
99 const char * filename,
101 const char * paf_desc,
102 const char * login_name,
107 if ((paf=fopen(filename,
"w"))==NULL) {
111 fprintf(paf,
"PAF.HDR.START ;# start of header\n");
112 fprintf(paf,
"PAF.TYPE \"pipeline product\" ;\n");
113 fprintf(paf,
"PAF.ID \"%s\"\n", paf_id);
114 fprintf(paf,
"PAF.NAME \"%s\"\n", filename);
115 fprintf(paf,
"PAF.DESC \"%s\"\n", paf_desc);
116 fprintf(paf,
"PAF.CRTE.NAME \"%s\"\n", login_name) ;
117 fprintf(paf,
"PAF.CRTE.DAYTIM \"%s\"\n", datetime) ;
118 fprintf(paf,
"PAF.LCHG.NAME \"%s\"\n", login_name) ;
119 fprintf(paf,
"PAF.LCHG.DAYTIM \"%s\"\n", datetime) ;
120 fprintf(paf,
"PAF.CHCK.CHECKSUM \"\"\n");
121 fprintf(paf,
"PAF.HDR.END ;# end of header\n");
135 sinfo_update_fits_card_int(
const char* file,
const char* card,
int value)
137 cpl_propertylist * plist =NULL;
138 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
140 cpl_propertylist_delete(plist) ;
144 if (CPL_ERROR_NONE!=cpl_propertylist_set_int(plist,card,value)){
146 cpl_propertylist_delete(plist) ;
149 cpl_propertylist_delete(plist) ;
163 sinfo_update_fits_card_float(
const char* file,
const char* card,
float value)
165 cpl_propertylist * plist =NULL;
166 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
170 cpl_propertylist_delete(plist) ;
174 if (CPL_ERROR_NONE!=cpl_propertylist_set_float(plist,card,value)){
178 cpl_propertylist_delete(plist) ;
181 cpl_propertylist_delete(plist) ;
196 sinfo_update_fits_card_double(
const char* file,
const char* card,
double value)
198 cpl_propertylist * plist =NULL;
199 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
201 cpl_propertylist_delete(plist) ;
205 if (CPL_ERROR_NONE!=cpl_propertylist_set_double(plist,card,value)){
207 cpl_propertylist_delete(plist) ;
210 cpl_propertylist_delete(plist) ;
224 sinfo_update_fits_card_long(
const char* file,
const char* card,
long value)
226 cpl_propertylist * plist =NULL;
227 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
229 cpl_propertylist_delete(plist) ;
232 if (CPL_ERROR_NONE!=cpl_propertylist_set_long(plist,card,value)){
234 cpl_propertylist_delete(plist) ;
237 cpl_propertylist_delete(plist) ;
251 sinfo_update_ims_fits_card_string(cpl_imagelist* iml,
257 cpl_propertylist * plist =NULL;
258 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
260 cpl_propertylist_delete(plist) ;
265 if (CPL_ERROR_NONE!=cpl_propertylist_set_string(plist,card,value)){
267 cpl_propertylist_delete(plist) ;
271 if (cpl_imagelist_save(iml,file,CPL_BPP_IEEE_FLOAT,
272 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
274 cpl_propertylist_delete(plist) ;
276 cpl_propertylist_delete(plist) ;
576 int sinfo_pro_save_ima(
580 const char * out_file,
581 const char * pro_catg,
584 cpl_parameterlist* parlist)
590 cpl_propertylist * plist =NULL;
591 cpl_frame * first_frame=NULL;
592 char * ref_file=NULL;
595 first_frame = cpl_frameset_get_first(ref) ;
596 ref_file = (
char*) cpl_strdup(cpl_frame_get_filename(first_frame)) ;
598 name_o = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
599 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
600 sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
601 sinfo_msg(
"Writing ima %s pro catg %s" , name_o, pro_catg) ;
604 if ((cpl_error_code)((plist=cpl_propertylist_load(ref_file, 0)) == NULL)) {
605 sinfo_msg_error(
"getting header from reference ima frame %s",ref_file);
606 cpl_propertylist_delete(plist) ;
611 sinfo_clean_header(&plist);
612 if ( ( strstr(pro_catg,
"MASTER_PSF") != NULL ) ||
613 ( strstr(pro_catg,
"STD_STAR_SPECTRUM") != NULL ) ||
614 ( strstr(pro_catg,
"STD_STAR_SPECTRA") != NULL ) ) {
615 sinfo_clean_cube_header(&plist);
619 sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE,
620 ref,&
set,&plist,parlist,recid);
622 sinfo_pfits_put_qc(plist, qclog) ;
626 if (cpl_image_save(ima, name_o, CPL_BPP_IEEE_FLOAT,
627 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
629 cpl_propertylist_delete(plist) ;
642 cpl_propertylist_delete(plist) ;
643 cpl_msg_indent_less() ;
669 int sinfo_pro_save_tbl(
673 const char * out_file,
674 const char * pro_catg,
677 cpl_parameterlist* parlist)
682 cpl_propertylist * plist=NULL ;
683 cpl_frame* first_frame=NULL;
686 first_frame = cpl_frameset_get_first(ref) ;
687 ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
689 name_o = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
690 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
691 sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_TABLE, &name_p);
692 sinfo_msg(
"Writing tbl %s pro catg %s" , name_o, pro_catg) ;
695 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL))
698 cpl_propertylist_delete(plist) ;
704 sinfo_clean_header(&plist);
707 sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_TABLE,
708 ref,&
set,&plist,parlist,recid);
710 sinfo_pfits_put_qc(plist, qclog) ;
713 if (cpl_table_save(table, plist, NULL, name_o, CPL_IO_DEFAULT)
716 cpl_propertylist_delete(plist) ;
729 cpl_propertylist_delete(plist) ;
730 cpl_msg_indent_less() ;
756 int sinfo_pro_save_ims(
760 const char * out_file,
761 const char * pro_catg,
764 cpl_parameterlist* parlist)
770 cpl_propertylist * plist=NULL ;
771 cpl_frame* first_frame=NULL;
775 first_frame = cpl_frameset_get_first(ref) ;
776 ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
778 name_o = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
779 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
780 sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
781 sinfo_msg(
"Writing ims %s pro catg %s" , name_o, pro_catg) ;
783 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL))
786 cpl_propertylist_delete(plist) ;
792 sinfo_clean_header(&plist);
793 if ( ( strstr(pro_catg,
"STD") != NULL ) ||
794 ( strstr(pro_catg,
"PSF") != NULL ) ||
795 ( strstr(pro_catg,
"OBJ") != NULL ) ) {
796 sinfo_clean_cube_header(&plist);
800 sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE,
801 ref,&
set,&plist,parlist,recid);
804 sinfo_pfits_put_qc(plist, qclog) ;
809 if (cpl_imagelist_save(ims, name_o, CPL_BPP_IEEE_FLOAT,
810 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
812 cpl_propertylist_delete(plist) ;
824 cpl_propertylist_delete(plist) ;
825 cpl_msg_indent_less() ;
835 sinfo_log_pro(
char* name_o,
836 const char* pro_catg,
838 cpl_frameset* ref_set,
839 cpl_frameset** out_set,
840 cpl_propertylist** plist,
841 cpl_parameterlist* parlist,
844 cpl_frame* product_frame = NULL ;
846 cpl_errorstate initial_errorstate = cpl_errorstate_get();
848 pipe_id = cpl_calloc(FILE_NAME_SZ,
sizeof(
char));
849 snprintf(pipe_id,MAX_NAME_SIZE-1,
"%s%s",
"sinfo/",PACKAGE_VERSION);
850 product_frame = cpl_frame_new() ;
851 cpl_frame_set_filename(product_frame, name_o) ;
852 cpl_frame_set_tag(product_frame, pro_catg) ;
853 cpl_frame_set_type(product_frame, frm_type);
854 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
855 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
857 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
858 if(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
859 pipe_id,KEY_VALUE_HPRO_DID,NULL) != CPL_ERROR_NONE) {
862 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
866 if(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
867 pipe_id,KEY_VALUE_HPRO_DID) != CPL_ERROR_NONE) {
870 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
874 cpl_frameset_insert(*out_set, product_frame);
880 sinfo_check_name(
const char* in,
char** ou,
int type,
char** paf) {
884 if (strstr(in,
"." ) != NULL ) {
885 tmp = sinfo_new_get_rootname(in);
888 snprintf(name_b, MAX_NAME_SIZE-1,
"%s", in) ;
891 if (type == CPL_FRAME_TYPE_TABLE) {
903 sinfo_clean_header(cpl_propertylist** header)
905 cpl_propertylist_erase_regexp(*header,
"CHECKSUM",0);
906 cpl_propertylist_erase_regexp(*header,
"^ESO PRO .*",0);
912 sinfo_clean_cube_header(cpl_propertylist** header)
915 cpl_propertylist_erase_regexp(*header,
"^CRVAL*",0);
916 cpl_propertylist_erase_regexp(*header,
"^CRPIX*",0);
917 cpl_propertylist_erase_regexp(*header,
"^CTYPE*",0);
918 cpl_propertylist_erase_regexp(*header,
"^CUNIT*",0);
919 cpl_propertylist_erase_regexp(*header,
"^CD1_1",0);
920 cpl_propertylist_erase_regexp(*header,
"^CD1_2",0);
921 cpl_propertylist_erase_regexp(*header,
"^CD2_1",0);
922 cpl_propertylist_erase_regexp(*header,
"^CD2_2",0);
933 cpl_propertylist * plist,
936 char key_name[FILE_NAME_SZ];
937 char key_value[FILE_NAME_SZ];
938 char key_type[FILE_NAME_SZ];
939 char key_help[FILE_NAME_SZ] ;
950 n=cpl_table_get_nrow(qclog);
952 strcpy(key_name,
"ESO ");
953 strcat(key_name,cpl_table_get_string(qclog,
"key_name",i));
954 strcpy(key_type,cpl_table_get_string(qclog,
"key_type",i));
955 strcpy(key_value,cpl_table_get_string(qclog,
"key_value",i));
956 strcpy(key_help,cpl_table_get_string(qclog,
"key_help",i));
959 if(!sinfo_propertylist_has(plist,key_name)) {
960 if(strcmp(key_type,
"CPL_TYPE_STRING") == 0) {
961 cpl_propertylist_append_string(plist, key_name,key_value) ;
962 cpl_propertylist_set_comment(plist, key_name,key_help) ;
963 }
else if(strcmp(key_type,
"CPL_TYPE_BOOL") == 0) {
964 cpl_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
965 cpl_propertylist_set_comment(plist, key_name,key_help) ;
966 }
else if(strcmp(key_type,
"CPL_TYPE_INT") == 0) {
967 cpl_propertylist_append_int(plist,key_name,atoi(key_value)) ;
968 cpl_propertylist_set_comment(plist, key_name,key_help) ;
969 }
else if(strcmp(key_type,
"CPL_TYPE_FLOAT") == 0) {
970 cpl_propertylist_append_float(plist, key_name,(
float)atof(key_value)) ;
971 cpl_propertylist_set_comment(plist, key_name,key_help) ;
972 }
else if(strcmp(key_type,
"CPL_TYPE_DOUBLE") == 0) {
973 cpl_propertylist_append_double(plist, key_name,atof(key_value)) ;
974 cpl_propertylist_set_comment(plist, key_name,key_help) ;
990 sinfo_qclog_init(
void)
995 table = cpl_table_new(0);
996 cpl_table_new_column(table,
"key_name", CPL_TYPE_STRING);
997 cpl_table_new_column(table,
"key_type", CPL_TYPE_STRING);
998 cpl_table_new_column(table,
"key_value", CPL_TYPE_STRING);
999 cpl_table_new_column(table,
"key_help", CPL_TYPE_STRING);
1009 sinfo_qclog_add_int(cpl_table* table,
1010 const char* key_name,
1012 const char* key_help,
1015 int sz = cpl_table_get_nrow(table);
1017 char key_value[FILE_NAME_SZ];
1018 char key_type[FILE_NAME_SZ];
1020 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1021 strcpy(key_type,
"CPL_TYPE_INT");
1023 cpl_table_set_size(table,sz+1);
1025 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1026 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1027 cpl_table_set_string(table,
"key_value",raw,key_value);
1028 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1037 sinfo_qclog_add_bool(cpl_table* table,
1038 const char* key_name,
1040 const char* key_help,
1043 int sz = cpl_table_get_nrow(table);
1045 char key_value[FILE_NAME_SZ];
1046 char key_type[FILE_NAME_SZ];
1048 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1049 strcpy(key_type,
"CPL_TYPE_BOOL");
1051 cpl_table_set_size(table,sz+1);
1053 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1054 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1055 cpl_table_set_string(table,
"key_value",raw,key_value);
1056 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1065 sinfo_qclog_add_float(cpl_table* table,
1066 const char* key_name,
1068 const char* key_help,
1071 int sz = cpl_table_get_nrow(table);
1073 char key_value[FILE_NAME_SZ];
1074 char key_type[FILE_NAME_SZ];
1076 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1077 strcpy(key_type,
"CPL_TYPE_FLOAT");
1079 cpl_table_set_size(table,sz+1);
1081 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1082 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1083 cpl_table_set_string(table,
"key_value",raw,key_value);
1084 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1093 sinfo_qclog_add_double(cpl_table* table,
1094 const char* key_name,
1096 const char* key_help,
1099 int sz = cpl_table_get_nrow(table);
1101 char key_value[FILE_NAME_SZ];
1102 char key_type[FILE_NAME_SZ];
1104 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1105 strcpy(key_type,
"CPL_TYPE_DOUBLE");
1107 cpl_table_set_size(table,sz+1);
1109 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1110 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1111 cpl_table_set_string(table,
"key_value",raw,key_value);
1112 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1119 sinfo_qclog_add_string(cpl_table* table,
1120 const char* key_name,
1122 const char* key_help,
1125 int sz = cpl_table_get_nrow(table);
1127 char key_value[FILE_NAME_SZ];
1128 char key_type[FILE_NAME_SZ];
1130 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1131 strcpy(key_type,
"CPL_TYPE_STRING");
1133 cpl_table_set_size(table,sz+1);
1135 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1136 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1137 cpl_table_set_string(table,
"key_value",raw,key_value);
1138 cpl_table_set_string(table,
"key_help" ,raw,key_help);