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);
71 sinfo_update_fits_card_int(
const char* file,
const char* card,
int value)
73 cpl_propertylist * plist =NULL;
74 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
76 cpl_propertylist_delete(plist) ;
80 if (CPL_ERROR_NONE!=cpl_propertylist_set_int(plist,card,value)){
82 cpl_propertylist_delete(plist) ;
85 cpl_propertylist_delete(plist) ;
99 sinfo_update_fits_card_float(
const char* file,
const char* card,
float value)
101 cpl_propertylist * plist =NULL;
102 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
106 cpl_propertylist_delete(plist) ;
110 if (CPL_ERROR_NONE!=cpl_propertylist_set_float(plist,card,value)){
114 cpl_propertylist_delete(plist) ;
117 cpl_propertylist_delete(plist) ;
132 sinfo_update_fits_card_double(
const char* file,
const char* card,
double value)
134 cpl_propertylist * plist =NULL;
135 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
137 cpl_propertylist_delete(plist) ;
141 if (CPL_ERROR_NONE!=cpl_propertylist_set_double(plist,card,value)){
143 cpl_propertylist_delete(plist) ;
146 cpl_propertylist_delete(plist) ;
160 sinfo_update_fits_card_long(
const char* file,
const char* card,
long value)
162 cpl_propertylist * plist =NULL;
163 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
165 cpl_propertylist_delete(plist) ;
168 if (CPL_ERROR_NONE!=cpl_propertylist_set_long(plist,card,value)){
170 cpl_propertylist_delete(plist) ;
173 cpl_propertylist_delete(plist) ;
187 sinfo_update_ims_fits_card_string(cpl_imagelist* iml,
193 cpl_propertylist * plist =NULL;
194 if ((plist = cpl_propertylist_load(file, 0)) == NULL) {
196 cpl_propertylist_delete(plist) ;
201 if (CPL_ERROR_NONE!=cpl_propertylist_set_string(plist,card,value)){
203 cpl_propertylist_delete(plist) ;
207 if (cpl_imagelist_save(iml,file,CPL_BPP_IEEE_FLOAT,
208 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
210 cpl_propertylist_delete(plist) ;
213 cpl_propertylist_delete(plist) ;
513 int sinfo_pro_save_ima(
517 const char * out_file,
518 const char * pro_catg,
521 cpl_parameterlist* parlist)
527 cpl_propertylist * plist =NULL;
529 char * ref_file=NULL;
532 cpl_frameset_iterator* it = cpl_frameset_iterator_new(ref);
533 cpl_frame *first_frame = cpl_frameset_iterator_get(it);
535 ref_file = (
char*) cpl_strdup(cpl_frame_get_filename(first_frame)) ;
537 name_o = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
538 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
539 sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
540 sinfo_msg(
"Writing ima %s pro catg %s" , name_o, pro_catg) ;
543 if ((cpl_error_code)((plist=cpl_propertylist_load(ref_file, 0)) == NULL)) {
544 sinfo_msg_error(
"getting header from reference ima frame %s",ref_file);
545 cpl_propertylist_delete(plist) ;
547 cpl_frameset_iterator_delete(it);
551 sinfo_clean_header(&plist);
552 if ( ( strstr(pro_catg,
"MASTER_PSF") != NULL ) ||
553 ( strstr(pro_catg,
"STD_STAR_SPECTRUM") != NULL ) ||
554 ( strstr(pro_catg,
"STD_STAR_SPECTRA") != NULL ) ) {
555 sinfo_clean_cube_header(&plist);
559 sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE,
560 ref,&set,&plist,parlist,recid);
562 sinfo_pfits_put_qc(plist, qclog) ;
566 if (cpl_image_save(ima, name_o, CPL_BPP_IEEE_FLOAT,
567 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
569 cpl_propertylist_delete(plist) ;
573 cpl_frameset_iterator_delete(it);
583 cpl_propertylist_delete(plist) ;
584 cpl_msg_indent_less() ;
588 cpl_frameset_iterator_delete(it);
611 int sinfo_pro_save_tbl(
615 const char * out_file,
616 const char * pro_catg,
619 cpl_parameterlist* parlist)
624 cpl_propertylist * plist=NULL ;
628 cpl_frameset_iterator* it = cpl_frameset_iterator_new(ref);
629 cpl_frame *first_frame = cpl_frameset_iterator_get(it);
630 ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
632 name_o = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
633 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
634 sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_TABLE, &name_p);
635 sinfo_msg(
"Writing tbl %s pro catg %s" , name_o, pro_catg) ;
638 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file,0)) == NULL))
641 cpl_propertylist_delete(plist) ;
645 cpl_frameset_iterator_delete(it);
648 sinfo_clean_header(&plist);
651 sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_TABLE,
652 ref,&set,&plist,parlist,recid);
654 sinfo_pfits_put_qc(plist, qclog) ;
657 if (cpl_table_save(table, plist, NULL, name_o, CPL_IO_DEFAULT)
660 cpl_propertylist_delete(plist) ;
664 cpl_frameset_iterator_delete(it);
674 cpl_propertylist_delete(plist) ;
675 cpl_msg_indent_less() ;
679 cpl_frameset_iterator_delete(it);
702 int sinfo_pro_save_ims(
706 const char * out_file,
707 const char * pro_catg,
710 cpl_parameterlist* parlist)
716 cpl_propertylist * plist=NULL ;
720 cpl_frameset_iterator* it = cpl_frameset_iterator_new(ref);
721 cpl_frame *first_frame = cpl_frameset_iterator_get(it);
723 ref_file = cpl_strdup(cpl_frame_get_filename(first_frame)) ;
725 name_o = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
726 name_p = cpl_malloc(FILE_NAME_SZ *
sizeof(
char));
727 sinfo_check_name(out_file, &name_o, CPL_FRAME_TYPE_IMAGE, &name_p);
728 sinfo_msg(
"Writing ims %s pro catg %s" , name_o, pro_catg) ;
730 if ((cpl_error_code)((plist = cpl_propertylist_load(ref_file, 0)) == NULL))
733 cpl_propertylist_delete(plist) ;
737 cpl_frameset_iterator_delete(it);
740 sinfo_clean_header(&plist);
741 if ( ( strstr(pro_catg,
"STD") != NULL ) ||
742 ( strstr(pro_catg,
"PSF") != NULL ) ||
743 ( strstr(pro_catg,
"OBJ") != NULL ) ) {
744 sinfo_clean_cube_header(&plist);
748 sinfo_log_pro(name_o, pro_catg, CPL_FRAME_TYPE_IMAGE,
749 ref,&set,&plist,parlist,recid);
752 sinfo_pfits_put_qc(plist, qclog) ;
757 if (cpl_imagelist_save(ims, name_o, CPL_BPP_IEEE_FLOAT,
758 plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
760 cpl_propertylist_delete(plist) ;
764 cpl_frameset_iterator_delete(it);
773 cpl_propertylist_delete(plist) ;
774 cpl_msg_indent_less() ;
778 cpl_frameset_iterator_delete(it);
785 sinfo_log_pro(
char* name_o,
786 const char* pro_catg,
788 cpl_frameset* ref_set,
789 cpl_frameset** out_set,
790 cpl_propertylist** plist,
791 cpl_parameterlist* parlist,
794 cpl_frame* product_frame = NULL ;
796 cpl_errorstate initial_errorstate = cpl_errorstate_get();
798 pipe_id = cpl_calloc(FILE_NAME_SZ,
sizeof(
char));
799 snprintf(pipe_id,MAX_NAME_SIZE-1,
"%s%s",
"sinfo/",PACKAGE_VERSION);
800 product_frame = cpl_frame_new() ;
801 cpl_frame_set_filename(product_frame, name_o) ;
802 cpl_frame_set_tag(product_frame, pro_catg) ;
803 cpl_frame_set_type(product_frame, frm_type);
804 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT);
805 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL);
807 #if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(4, 8, 0)
808 if(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
809 pipe_id,KEY_VALUE_HPRO_DID,NULL) != CPL_ERROR_NONE) {
812 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
816 if(cpl_dfs_setup_product_header(*plist,product_frame,ref_set,parlist,recid,
817 pipe_id,KEY_VALUE_HPRO_DID) != CPL_ERROR_NONE) {
820 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
824 cpl_frameset_insert(*out_set, product_frame);
830 sinfo_check_name(
const char* in,
char** ou,
int type,
char** paf) {
833 if (strstr(in,
"." ) != NULL ) {
834 char* tmp = sinfo_new_get_rootname(in);
837 snprintf(name_b, MAX_NAME_SIZE-1,
"%s", in) ;
840 if (type == CPL_FRAME_TYPE_TABLE) {
852 sinfo_clean_header(cpl_propertylist** header)
854 cpl_propertylist_erase_regexp(*header,
"CHECKSUM",0);
855 cpl_propertylist_erase_regexp(*header,
"^ESO PRO .*",0);
861 sinfo_clean_cube_header(cpl_propertylist** header)
864 cpl_propertylist_erase_regexp(*header,
"^CRVAL*",0);
865 cpl_propertylist_erase_regexp(*header,
"^CRPIX*",0);
866 cpl_propertylist_erase_regexp(*header,
"^CTYPE*",0);
867 cpl_propertylist_erase_regexp(*header,
"^CUNIT*",0);
868 cpl_propertylist_erase_regexp(*header,
"^CD1_1",0);
869 cpl_propertylist_erase_regexp(*header,
"^CD1_2",0);
870 cpl_propertylist_erase_regexp(*header,
"^CD2_1",0);
871 cpl_propertylist_erase_regexp(*header,
"^CD2_2",0);
882 cpl_propertylist * plist,
885 char key_name[FILE_NAME_SZ];
886 char key_value[FILE_NAME_SZ];
887 char key_type[FILE_NAME_SZ];
888 char key_help[FILE_NAME_SZ] ;
899 n=cpl_table_get_nrow(qclog);
901 strcpy(key_name,
"ESO ");
902 strcat(key_name,cpl_table_get_string(qclog,
"key_name",i));
903 strcpy(key_type,cpl_table_get_string(qclog,
"key_type",i));
904 strcpy(key_value,cpl_table_get_string(qclog,
"key_value",i));
905 strcpy(key_help,cpl_table_get_string(qclog,
"key_help",i));
908 if(!cpl_propertylist_has(plist,key_name)) {
909 if(strcmp(key_type,
"CPL_TYPE_STRING") == 0) {
910 cpl_propertylist_append_string(plist, key_name,key_value) ;
911 cpl_propertylist_set_comment(plist, key_name,key_help) ;
912 }
else if(strcmp(key_type,
"CPL_TYPE_BOOL") == 0) {
913 cpl_propertylist_append_bool(plist, key_name,atoi(key_value)) ;
914 cpl_propertylist_set_comment(plist, key_name,key_help) ;
915 }
else if(strcmp(key_type,
"CPL_TYPE_INT") == 0) {
916 cpl_propertylist_append_int(plist,key_name,atoi(key_value)) ;
917 cpl_propertylist_set_comment(plist, key_name,key_help) ;
918 }
else if(strcmp(key_type,
"CPL_TYPE_FLOAT") == 0) {
919 cpl_propertylist_append_float(plist, key_name,(
float)atof(key_value)) ;
920 cpl_propertylist_set_comment(plist, key_name,key_help) ;
921 }
else if(strcmp(key_type,
"CPL_TYPE_DOUBLE") == 0) {
922 cpl_propertylist_append_double(plist, key_name,atof(key_value)) ;
923 cpl_propertylist_set_comment(plist, key_name,key_help) ;
939 sinfo_qclog_init(
void)
944 table = cpl_table_new(0);
945 cpl_table_new_column(table,
"key_name", CPL_TYPE_STRING);
946 cpl_table_new_column(table,
"key_type", CPL_TYPE_STRING);
947 cpl_table_new_column(table,
"key_value", CPL_TYPE_STRING);
948 cpl_table_new_column(table,
"key_help", CPL_TYPE_STRING);
958 sinfo_qclog_add_int(cpl_table* table,
959 const char* key_name,
961 const char* key_help,
964 int sz = cpl_table_get_nrow(table);
966 char key_value[FILE_NAME_SZ];
967 char key_type[FILE_NAME_SZ];
969 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
970 strcpy(key_type,
"CPL_TYPE_INT");
972 cpl_table_set_size(table,sz+1);
974 cpl_table_set_string(table,
"key_name" ,raw,key_name);
975 cpl_table_set_string(table,
"key_type" ,raw,key_type);
976 cpl_table_set_string(table,
"key_value",raw,key_value);
977 cpl_table_set_string(table,
"key_help" ,raw,key_help);
986 sinfo_qclog_add_bool(cpl_table* table,
987 const char* key_name,
989 const char* key_help,
992 int sz = cpl_table_get_nrow(table);
994 char key_value[FILE_NAME_SZ];
995 char key_type[FILE_NAME_SZ];
997 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
998 strcpy(key_type,
"CPL_TYPE_BOOL");
1000 cpl_table_set_size(table,sz+1);
1002 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1003 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1004 cpl_table_set_string(table,
"key_value",raw,key_value);
1005 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1014 sinfo_qclog_add_float(cpl_table* table,
1015 const char* key_name,
1017 const char* key_help,
1020 int sz = cpl_table_get_nrow(table);
1022 char key_value[FILE_NAME_SZ];
1023 char key_type[FILE_NAME_SZ];
1025 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1026 strcpy(key_type,
"CPL_TYPE_FLOAT");
1028 cpl_table_set_size(table,sz+1);
1030 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1031 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1032 cpl_table_set_string(table,
"key_value",raw,key_value);
1033 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1042 sinfo_qclog_add_double(cpl_table* table,
1043 const char* key_name,
1045 const char* key_help,
1048 int sz = cpl_table_get_nrow(table);
1050 char key_value[FILE_NAME_SZ];
1051 char key_type[FILE_NAME_SZ];
1053 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1054 strcpy(key_type,
"CPL_TYPE_DOUBLE");
1056 cpl_table_set_size(table,sz+1);
1058 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1059 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1060 cpl_table_set_string(table,
"key_value",raw,key_value);
1061 cpl_table_set_string(table,
"key_help" ,raw,key_help);
1068 sinfo_qclog_add_string(cpl_table* table,
1069 const char* key_name,
1071 const char* key_help,
1074 int sz = cpl_table_get_nrow(table);
1076 char key_value[FILE_NAME_SZ];
1077 char key_type[FILE_NAME_SZ];
1079 snprintf(key_value,MAX_NAME_SIZE-1,format,value);
1080 strcpy(key_type,
"CPL_TYPE_STRING");
1082 cpl_table_set_size(table,sz+1);
1084 cpl_table_set_string(table,
"key_name" ,raw,key_name);
1085 cpl_table_set_string(table,
"key_type" ,raw,key_type);
1086 cpl_table_set_string(table,
"key_value",raw,key_value);
1087 cpl_table_set_string(table,
"key_help" ,raw,key_help);
#define sinfo_msg_error(...)
Print an error message.
#define sinfo_msg_warning(...)
Print an warning message.