38#include <casu_utils.h>
40#include <casu_stats.h>
41#include <casu_wcsutils.h>
44#include "vircam_utils.h"
45#include "vircam_pfits.h"
46#include "vircam_dfs.h"
47#include "vircam_mods.h"
48#include "vircam_paf.h"
50#include "vircam_jmp_utils.h"
52struct vircam_jmp_configStruct vircam_jmp_config;
55static char *vircam_jmp_outfile(
const char *bname,
int ind,
int isfits);
71void vircam_jmp_set_config_ipix (
int ipix) {vircam_jmp_config.ipix = ipix ;}
72void vircam_jmp_set_config_icrowd (
int icrowd) {vircam_jmp_config.icrowd = icrowd ;}
73void vircam_jmp_set_config_rcore (
float rcore) {vircam_jmp_config.rcore = rcore ;}
74void vircam_jmp_set_config_threshold (
float threshold) {vircam_jmp_config.threshold = threshold ;}
75void vircam_jmp_set_config_nbsize (
int nbsize) {vircam_jmp_config.nbsize = nbsize ;}
76void vircam_jmp_set_config_savecat (
int savecat) {vircam_jmp_config.savecat = savecat ;}
77void vircam_jmp_set_config_destripe (
int destripe) {vircam_jmp_config.destripe = destripe ;}
78void vircam_jmp_set_config_skycor (
int skycore) {vircam_jmp_config.skycor = skycore ;}
79void vircam_jmp_set_config_savesimple (
int savesimple) {vircam_jmp_config.savesimple= savesimple;}
80void vircam_jmp_set_config_extenum (
int extenum) {vircam_jmp_config.extenum = extenum ;}
81void vircam_jmp_set_offsky(
int inp_offsky) {offsky=inp_offsky;}
82void vircam_jmp_set_isfirst(
int inp_isfirst) {isfirst=inp_isfirst;}
84int vircam_jmp_get_config_savecat () {
return vircam_jmp_config.savecat ;}
85int vircam_jmp_get_config_destripe () {
return vircam_jmp_config.destripe ;}
86int vircam_jmp_get_config_skycor () {
return vircam_jmp_config.skycor ;}
87int vircam_jmp_get_config_savesimple () {
return vircam_jmp_config.savesimple;}
88int vircam_jmp_get_config_extenum () {
return vircam_jmp_config.extenum ;}
91void vircam_set_recipename(
const char* recipename,
int recipe_flag) {
92 (void)strncpy(vircam_recipename,recipename,VIRCAM_PATHSZ);
93 (void)snprintf(vircam_recipepaf,VIRCAM_PATHSZ,
"VIRCAM/%s",recipename);
94 recflag = recipe_flag;
120 cpl_parameterlist *parlist) {
121 cpl_propertylist *plist;
123 cpl_frame *product_frame,*
template;
125 const char *base[] = {
"",
"simple_jmp",
"simple_std",
"simple_mes"};
126 const char *fctid =
"vircam_jmp_save_simple";
130 if ((*ps).product_frames_simple == NULL)
131 (*ps).product_frames_simple = cpl_malloc((*ps).nscience*
sizeof(cpl_frame *));
135 for (i = 0; i < (*ps).nscience; i++) {
136 fname = vircam_jmp_outfile(base[recflag],i,1);
138 template = cpl_frameset_get_position((*ps).science_frames,i);
147 product_frame = cpl_frame_new();
148 cpl_frame_set_filename(product_frame,fname);
151 cpl_frame_set_tag(product_frame,VIRCAM_PRO_SIMPLE_SCI);
154 cpl_frame_set_tag(product_frame,VIRCAM_PRO_SIMPLE_STD);
157 cpl_frame_set_tag(product_frame,VIRCAM_PRO_SIMPLE_SCI);
160 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
161 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
162 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
170 "PRO-1.15",
template,1);
174 if (cpl_image_save(NULL,fname,CPL_TYPE_UCHAR,plist,
175 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
176 cpl_msg_error(fctid,
"Cannot save product PHU");
177 cpl_frame_delete(product_frame);
181 cpl_frameset_insert(framelist,product_frame);
182 (*ps).product_frames_simple[i] = product_frame;
193 product_frame = (*ps).product_frames_simple[i];
195 parlist,vircam_recipename,
196 "PRO-1.15",
template);
198 CPL_TYPE_FLOAT,plist,
199 CPL_IO_EXTEND) != CPL_ERROR_NONE) {
200 cpl_msg_error(fctid,
"Cannot save product image extension");
237 cpl_parameterlist *parlist) {
238 cpl_propertylist *plist;
240 cpl_frame *product_frame,*
template;
242 const char *base =
"simple_off";
243 const char *fctid =
"vircam_jmp_save_simple_offsets";
247 if ((*ps).product_frames_simple_off == NULL)
248 (*ps).product_frames_simple_off =
249 cpl_malloc((*ps).noffsets*
sizeof(cpl_frame *));
253 for (i = 0; i < (*ps).noffsets; i++) {
254 fname = vircam_jmp_outfile(base,i,1);
256 template = cpl_frameset_get_position((*ps).offset_skies,i);
265 product_frame = cpl_frame_new();
266 cpl_frame_set_filename(product_frame,fname);
267 cpl_frame_set_tag(product_frame,VIRCAM_PRO_SIMPLE_SKY);
268 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
269 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
270 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
278 "PRO-1.15",
template,1);
282 if (cpl_image_save(NULL,fname,CPL_TYPE_UCHAR,plist,
283 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
284 cpl_msg_error(fctid,
"Cannot save product PHU");
285 cpl_frame_delete(product_frame);
289 cpl_frameset_insert(framelist,product_frame);
290 (*ps).product_frames_simple_off[i] = product_frame;
301 product_frame = (*ps).product_frames_simple_off[i];
303 parlist,vircam_recipename,
304 "PRO-1.15",
template);
306 CPL_TYPE_FLOAT,plist,
307 CPL_IO_EXTEND) != CPL_ERROR_NONE) {
308 cpl_msg_error(fctid,
"Cannot save product image extension");
345 cpl_parameterlist *parlist) {
350 cpl_frame *product_frame,*
template;
352 const char *base =
"offsky";
353 const char *fctid =
"vircam_jmp_save_offsky";
361 template = cpl_frameset_get_position((*ps).offset_skies,0);
365 fname = vircam_jmp_outfile(base,0,1);
374 product_frame = cpl_frame_new();
375 cpl_frame_set_filename(product_frame,fname);
376 cpl_frame_set_tag(product_frame,VIRCAM_PRO_OFFSET_SKY);
377 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
378 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
379 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
380 (*ps).product_frame_sky = product_frame;
386 parlist,vircam_recipename,
387 "PRO-1.15",
template,0);
391 if (cpl_image_save(NULL,fname,CPL_TYPE_UCHAR,p,
392 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
393 cpl_msg_error(fctid,
"Cannot save product PHU");
394 cpl_frame_delete(product_frame);
398 cpl_frameset_insert(framelist,product_frame);
409 product_frame = (*ps).product_frame_sky;
411 vircam_recipename,
"PRO-1.15",
template);
412 if (cpl_image_save(fim,fname,CPL_TYPE_FLOAT,p,CPL_IO_EXTEND) !=
414 cpl_msg_error(fctid,
"Cannot save product image extension");
421 cpl_propertylist_delete(p);
453 cpl_parameterlist *parlist) {
454 cpl_propertylist *plist,*p;
455 int i,isdummy,isdummyc,j,jref;
456 cpl_frame *product_frame,*
template;
458 const char *base[] = {
"",
"super_jmp",
"super_std",
"super_mes"};
459 const char *basec[] = {
"",
"superc_jmp",
"superc_std",
"superc_mes"};
461 cpl_image *fim,*fimc;
462 const char *fctid =
"vircam_jmp_save_super";
466 if ((*ps).product_frames_super == NULL)
467 (*ps).product_frames_super = cpl_malloc((*ps).nustep_sets*
sizeof(cpl_frame *));
468 if ((*ps).product_frames_superc == NULL)
469 (*ps).product_frames_superc = cpl_malloc((*ps).nustep_sets*
sizeof(cpl_frame *));
473 for (i = 0; i < (*ps).nustep_sets; i++) {
479 ff = (*ps).ustep_sets[i].super;
481 ffc = (*ps).ustep_sets[i].superc;
488 fname = vircam_jmp_outfile(base[recflag],i,1);
489 fnamec = vircam_jmp_outfile(basec[recflag],i,1);
494 for (j = 0; j < (*ps).ustep_sets[i].nframes; j++) {
495 if ((*ps).sci_fits[j] == (*ps).ustep_sets[i].f[j]) {
501 template = cpl_frameset_get_position((*ps).science_frames,jref);
512 product_frame = cpl_frame_new();
513 cpl_frame_set_filename(product_frame,fname);
516 cpl_frame_set_tag(product_frame,VIRCAM_PRO_INTER_SCI);
519 cpl_frame_set_tag(product_frame,VIRCAM_PRO_INTER_STD);
522 cpl_frame_set_tag(product_frame,VIRCAM_PRO_INTER_SCI);
525 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
526 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
527 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
535 "PRO-1.15",
template,1);
539 if (cpl_image_save(NULL,fname,CPL_TYPE_UCHAR,plist,
540 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
541 cpl_msg_error(fctid,
"Cannot save product PHU");
542 cpl_frame_delete(product_frame);
547 cpl_frameset_insert(framelist,product_frame);
548 (*ps).product_frames_super[i] = product_frame;
552 product_frame = cpl_frame_new();
553 cpl_frame_set_filename(product_frame,fnamec);
556 cpl_frame_set_tag(product_frame,VIRCAM_PRO_CONF_INTER_SCI);
559 cpl_frame_set_tag(product_frame,VIRCAM_PRO_CONF_INTER_STD);
562 cpl_frame_set_tag(product_frame,VIRCAM_PRO_CONF_INTER_SCI);
565 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
566 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
567 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
575 "PRO-1.15",
template,1);
579 if (cpl_image_save(NULL,fnamec,CPL_TYPE_UCHAR,plist,
580 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
581 cpl_msg_error(fctid,
"Cannot save product PHU");
582 cpl_frame_delete(product_frame);
587 cpl_frameset_insert(framelist,product_frame);
588 (*ps).product_frames_superc[i] = product_frame;
600 product_frame = (*ps).product_frames_super[i];
602 vircam_recipename,
"PRO-1.15",
604 if (cpl_image_save(fim,fname,CPL_TYPE_FLOAT,p,CPL_IO_EXTEND) !=
606 cpl_msg_error(fctid,
"Cannot save product image extension");
611 cpl_propertylist_delete(p);
621 product_frame = (*ps).product_frames_superc[i];
623 vircam_recipename,
"PRO-1.15",
625 if (cpl_image_save(fimc,fnamec,CPL_TYPE_SHORT,p,CPL_IO_EXTEND) !=
627 cpl_msg_error(fctid,
"Cannot save confidence map image extension");
632 cpl_propertylist_delete(p);
667 cpl_parameterlist *parlist,
668 cpl_propertylist *dummyqcprops) {
669 cpl_propertylist *plist,*p,*pafprop;
670 int isdummy,isdummyc;
672 cpl_image *fim,*fimc;
673 cpl_frame *product_frame;
674 char *fname,*fnamec,*fnamepaf;
675 const char *base[] = {
"",
"stack_jmp",
"stack_std",
"stack_mes"};
676 const char *basec[] = {
"",
"stackc_jmp",
"stackc_std",
"stackc_mes"};
677 const char *fctid =
"vircam_jmp_save_stack";
683 ff = (*ps).stack_frame;
685 ffc = (*ps).stackc_frame;
692 fname = vircam_jmp_outfile(base[recflag],0,1);
693 fnamec = vircam_jmp_outfile(basec[recflag],0,1);
694 fnamepaf = vircam_jmp_outfile(base[recflag],0,0);
703 product_frame = cpl_frame_new();
704 cpl_frame_set_filename(product_frame,fname);
707 cpl_frame_set_tag(product_frame,VIRCAM_PRO_JITTERED_SCI);
710 cpl_frame_set_tag(product_frame,VIRCAM_PRO_JITTERED_STD);
713 cpl_frame_set_tag(product_frame,VIRCAM_PRO_JITTERED_SCI);
716 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
717 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
718 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
719 (*ps).product_frame_stack = product_frame;
725 parlist,vircam_recipename,
730 if (cpl_image_save(NULL,fname,CPL_TYPE_UCHAR,plist,
731 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
732 cpl_msg_error(fctid,
"Cannot save product PHU");
733 cpl_frame_delete(product_frame);
739 cpl_frameset_insert(framelist,product_frame);
743 product_frame = cpl_frame_new();
744 cpl_frame_set_filename(product_frame,fnamec);
747 cpl_frame_set_tag(product_frame,VIRCAM_PRO_CONF_SCI);
750 cpl_frame_set_tag(product_frame,VIRCAM_PRO_CONF_STD);
753 cpl_frame_set_tag(product_frame,VIRCAM_PRO_CONF_SCI);
756 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
757 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
758 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
759 (*ps).product_frame_stackc = product_frame;
765 parlist,vircam_recipename,
770 if (cpl_image_save(NULL,fnamec,CPL_TYPE_UCHAR,plist,
771 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
772 cpl_msg_error(fctid,
"Cannot save product PHU");
773 cpl_frame_delete(product_frame);
779 cpl_frameset_insert(framelist,product_frame);
792 product_frame = (*ps).product_frame_stack;
794 vircam_recipename,
"PRO-1.15",NULL);
795 if (cpl_image_save(fim,fname,CPL_TYPE_FLOAT,p,CPL_IO_EXTEND) !=
797 cpl_msg_error(fctid,
"Cannot save product image extension");
807 pafprop = vircam_paf_req_items(p);
810 vircam_paf_append(pafprop,p,
"ESO DET NDIT");
811 vircam_paf_append(pafprop,p,
"ESO PRO CATG");
818 if (vircam_paf_print(fnamepaf,vircam_recipepaf,
"QC file",
820 cpl_msg_warning(fctid,
"Unable to save PAF for stack");
821 cpl_propertylist_delete(pafprop);
825 cpl_propertylist_delete(p);
834 cpl_propertylist_erase_regexp(p,
"ESO QC",0);
839 product_frame = (*ps).product_frame_stackc;
841 vircam_recipename,
"PRO-1.15",NULL);
842 if (cpl_image_save(fimc,fnamec,CPL_TYPE_SHORT,p,CPL_IO_EXTEND) !=
844 cpl_msg_error(fctid,
"Cannot save product image extension");
851 cpl_propertylist_delete(p);
886 cpl_parameterlist *parlist,
887 cpl_propertylist *dummyqcprops) {
888 cpl_frame *product_frame;
891 cpl_propertylist *ehu,*phu,*ehu2,*pafprop;
892 char *fname,*fnamepaf;
893 const char *base[] = {
"",
"catalogue_jmp",
"catalogue_std",
"catalogue_mes"};
894 const char *fctid =
"vircam_jmp_save_catalogue";
900 if ((*ps).outcat != NULL) {
911 if ((*ps).outcat != NULL) {
913 }
else if ((*ps).stack_frame != NULL) {
916 for (i = 0; i < (*ps).nscience; i++) {
921 if ((*ps).outcat != NULL) {
923 }
else if ((*ps).stack_frame != NULL) {
926 for (i = 0; i < (*ps).nscience; i++) {
934 fname = vircam_jmp_outfile(base[recflag],0,1);
935 fnamepaf = vircam_jmp_outfile(base[recflag],0,0);
944 product_frame = cpl_frame_new();
945 cpl_frame_set_filename(product_frame,fname);
948 cpl_frame_set_tag(product_frame,VIRCAM_PRO_OBJCAT_SCI);
951 cpl_frame_set_tag(product_frame,VIRCAM_PRO_OBJCAT_STD);
954 cpl_frame_set_tag(product_frame,VIRCAM_PRO_OBJCAT_SCI);
957 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_TABLE);
958 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
959 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
960 (*ps).product_frame_cat = product_frame;
965 parlist,vircam_recipename,
970 ehu2 = cpl_propertylist_duplicate(ehu);
980 parlist,vircam_recipename,
985 if (cpl_table_save(ftab,phu,ehu2,fname,CPL_IO_DEFAULT) !=
987 cpl_msg_error(fctid,
"Cannot save product PHU");
988 cpl_frame_delete(product_frame);
989 freepropertylist(ehu2);
996 pafprop = vircam_paf_req_items(ehu2);
998 vircam_paf_append(pafprop,ehu2,
"ESO PRO CATG");
999 vircam_paf_append(pafprop,phu,
"ESO INS FILT1 NAME");
1000 vircam_paf_append(pafprop,ehu,
"ESO DET NDIT");
1001 vircam_paf_append(pafprop,phu,
"RA");
1002 vircam_paf_append(pafprop,phu,
"DEC");
1003 vircam_paf_append(pafprop,phu,
"ESO TEL AIRM START");
1004 vircam_paf_append(pafprop,phu,
"ESO TEL GUID FWHM");
1005 vircam_paf_append(pafprop,phu,
"ESO TEL AMBI RHUM");
1006 vircam_paf_append(pafprop,phu,
"ESO OBS TARG NAME");
1007 if (vircam_paf_print(fnamepaf,vircam_recipepaf,
"QC file",
1008 pafprop) != CASU_OK)
1009 cpl_msg_warning(fctid,
"Unable to save PAF for catalogue");
1010 cpl_propertylist_delete(pafprop);
1014 freepropertylist(ehu2);
1016 cpl_table_delete(ftab);
1017 cpl_frameset_insert(framelist,product_frame);
1023 product_frame = (*ps).product_frame_cat;
1026 parlist,vircam_recipename,
1031 ehu2 = cpl_propertylist_duplicate(ehu);
1039 if (cpl_table_save(ftab,NULL,ehu2,fname,CPL_IO_EXTEND) !=
1041 cpl_msg_error(fctid,
"Cannot save product table extension");
1042 freepropertylist(ehu2);
1049 pafprop = vircam_paf_req_items(ehu2);
1051 vircam_paf_append(pafprop,ehu2,
"ESO PRO CATG");
1052 vircam_paf_append(pafprop,phu,
"ESO INS FILT1 NAME");
1053 vircam_paf_append(pafprop,ehu,
"ESO DET NDIT");
1054 vircam_paf_append(pafprop,phu,
"RA");
1055 vircam_paf_append(pafprop,phu,
"DEC");
1056 vircam_paf_append(pafprop,phu,
"ESO TEL AIRM START");
1057 vircam_paf_append(pafprop,phu,
"ESO TEL GUID FWHM");
1058 vircam_paf_append(pafprop,phu,
"ESO TEL AMBI RHUM");
1059 vircam_paf_append(pafprop,phu,
"ESO OBS TARG NAME");
1060 if (vircam_paf_print(fnamepaf,vircam_recipepaf,
"QC file",
1061 pafprop) != CASU_OK)
1062 cpl_msg_warning(fctid,
"Unable to save PAF for catalogue");
1063 cpl_propertylist_delete(pafprop);
1067 freepropertylist(ehu2);
1069 cpl_table_delete(ftab);
1072 freespace(fnamepaf);
1101 cpl_parameterlist *parlist,
1102 cpl_propertylist *dummyqcprops) {
1103 cpl_frame *product_frame;
1106 cpl_propertylist *ehu,*phu,*ehu2,*pafprop;
1107 const char *fname =
"illum.fits";
1108 const char *fnamepaf =
"illum";
1109 const char *fctid =
"vircam_jmp_save_illum";
1115 if ((*ps).illcor != NULL) {
1126 if ((*ps).illcor != NULL) {
1129 for (i = 0; i < (*ps).nscience; i++) {
1134 if ((*ps).illcor != NULL) {
1137 for (i = 0; i < (*ps).nscience; i++) {
1150 product_frame = cpl_frame_new();
1151 cpl_frame_set_filename(product_frame,fname);
1154 cpl_frame_set_tag(product_frame,VIRCAM_PRO_ILLCOR_STD);
1157 cpl_frame_set_tag(product_frame,VIRCAM_PRO_ILLCOR_MES);
1160 cpl_frame_set_tag(product_frame,VIRCAM_PRO_ILLCOR_STD);
1163 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_TABLE);
1164 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
1165 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
1166 (*ps).product_frame_illcor = product_frame;
1170 if ((*ps).phupaf == NULL)
1171 (*ps).phupaf = vircam_paf_phu_items(phu);
1173 parlist,vircam_recipename,
1178 ehu2 = cpl_propertylist_duplicate(ehu);
1189 parlist,vircam_recipename,
1194 if (cpl_table_save(ftab,phu,ehu2,fname,CPL_IO_DEFAULT) !=
1196 cpl_msg_error(fctid,
"Cannot save product PHU");
1197 cpl_frame_delete(product_frame);
1198 freepropertylist(ehu2);
1204 pafprop = vircam_paf_req_items(ehu2);
1206 vircam_paf_append(pafprop,ehu2,
"ESO PRO CATG");
1207 vircam_paf_append(pafprop,phu,
"ESO INS FILT1 NAME");
1208 vircam_paf_append(pafprop,ehu,
"ESO DET NDIT");
1209 vircam_paf_append(pafprop,phu,
"RA");
1210 vircam_paf_append(pafprop,phu,
"DEC");
1211 vircam_paf_append(pafprop,phu,
"ESO TEL AIRM START");
1212 vircam_paf_append(pafprop,phu,
"ESO TEL GUID FWHM");
1213 vircam_paf_append(pafprop,phu,
"ESO TEL AMBI RHUM");
1214 vircam_paf_append(pafprop,phu,
"ESO OBS TARG NAME");
1215 if (vircam_paf_print((
char *)fnamepaf,vircam_recipepaf,
"QC file",
1216 pafprop) != CASU_OK)
1217 cpl_msg_warning(fctid,
"Unable to save PAF for illcor table");
1218 cpl_propertylist_delete(pafprop);
1223 cpl_table_delete(ftab);
1224 freepropertylist(ehu2);
1225 cpl_frameset_insert(framelist,product_frame);
1232 product_frame = (*ps).product_frame_illcor;
1235 parlist,vircam_recipename,
1240 ehu2 = cpl_propertylist_duplicate(ehu);
1248 if (cpl_table_save(ftab,NULL,ehu2,fname,CPL_IO_EXTEND) !=
1250 cpl_msg_error(fctid,
"Cannot save product image extension");
1251 freepropertylist(ehu2);
1257 pafprop = vircam_paf_req_items(ehu2);
1259 vircam_paf_append(pafprop,ehu2,
"ESO PRO CATG");
1260 vircam_paf_append(pafprop,phu,
"ESO INS FILT1 NAME");
1261 vircam_paf_append(pafprop,ehu,
"ESO DET NDIT");
1262 vircam_paf_append(pafprop,phu,
"RA");
1263 vircam_paf_append(pafprop,phu,
"DEC");
1264 vircam_paf_append(pafprop,phu,
"ESO TEL AIRM START");
1265 vircam_paf_append(pafprop,phu,
"ESO TEL GUID FWHM");
1266 vircam_paf_append(pafprop,phu,
"ESO TEL AMBI RHUM");
1267 vircam_paf_append(pafprop,phu,
"ESO OBS TARG NAME");
1268 if (vircam_paf_print((
char *)fnamepaf,vircam_recipepaf,
"QC file",
1269 pafprop) != CASU_OK)
1270 cpl_msg_warning(fctid,
"Unable to save PAF for illcor table");
1271 cpl_propertylist_delete(pafprop);
1275 freepropertylist(ehu2);
1277 cpl_table_delete(ftab);
1304 int nalloc,i,match,j,ustepnum,nustep;
1306 cpl_propertylist *plist;
1307 const char *fctid =
"vircam_jmp_ustep_seq";
1313 (*ps).ustep_sets = cpl_malloc(nalloc*
sizeof(ustep_set));
1314 (*ps).nustep_sets = 0;
1319 for (i = 0; i < (*ps).nscience; i++) {
1320 ff = (*ps).sci_fits[i];
1323 cpl_msg_error(fctid,
"No microstep number in %s",
1334 for (j = 0; j < (*ps).nustep_sets; j++) {
1335 if (ustepnum == (*ps).ustep_sets[j].ustep_number) {
1337 (*ps).ustep_sets[j].f[(*ps).ustep_sets[j].nframes] = ff;
1338 (*ps).ustep_sets[j].nframes += 1;
1340 (*ps).ustep_sets[j].ngood += 1;
1349 if ((*ps).nustep_sets+1 == nalloc) {
1350 nalloc += INITALLOC;
1351 (*ps).ustep_sets = cpl_realloc((*ps).ustep_sets,nalloc*
sizeof(ustep_set));
1357 (*ps).ustep_sets[(*ps).nustep_sets].f = cpl_malloc(nustep*
sizeof(casu_fits *));
1358 (*ps).ustep_sets[(*ps).nustep_sets].ustep_number = ustepnum;
1359 (*ps).ustep_sets[(*ps).nustep_sets].nustep = nustep;
1360 (*ps).ustep_sets[(*ps).nustep_sets].status = CASU_OK;
1361 (*ps).ustep_sets[(*ps).nustep_sets].super = NULL;
1362 (*ps).ustep_sets[(*ps).nustep_sets].superc = NULL;
1363 (*ps).ustep_sets[(*ps).nustep_sets].nframes = 0;
1364 (*ps).ustep_sets[(*ps).nustep_sets].f[0] = ff;
1365 (*ps).ustep_sets[(*ps).nustep_sets].nframes = 1;
1366 (*ps).ustep_sets[(*ps).nustep_sets].ngood = 0;
1368 (*ps).ustep_sets[(*ps).nustep_sets].ngood += 1;
1369 (*ps).nustep_sets++;
1375 (*ps).ustep_sets = cpl_realloc((*ps).ustep_sets,
1376 (*ps).nustep_sets*
sizeof(ustep_set));
1380 for (i = 0; i < (*ps).nustep_sets; i++) {
1381 if ((*ps).ustep_sets[i].ngood == 0) {
1382 cpl_msg_warning(fctid,
1383 "Microstep sequence %" CPL_SIZE_FORMAT
" has no input",
1384 (cpl_size)((*ps).ustep_sets[i].ustep_number));
1385 (*ps).ustep_sets[i].status = CASU_FATAL;
1386 }
else if ((*ps).ustep_sets[i].ngood != (*ps).ustep_sets[i].nustep) {
1387 cpl_msg_warning(fctid,
"Microstep sequence %" CPL_SIZE_FORMAT
" incomplete",
1388 (cpl_size)((*ps).ustep_sets[i].ustep_number));
1389 (*ps).ustep_sets[i].status = CASU_WARN;
1414 int i,refset,k,nstep,status,nk;
1418 double refx,refy,refra,refdec,x,y;
1419 cpl_image *fi,*outimage,*outconf;
1420 cpl_propertylist *plist;
1421 casu_fits *ff,**tmp;
1423 const char *fctid =
"vircam_jmp_interleave";
1431 (*ps).dith_input = cpl_malloc((*ps).nustep_sets*
sizeof(casu_fits*));
1432 (*ps).dithc_input = cpl_malloc((*ps).nustep_sets*
sizeof(casu_fits*));
1437 for (i = 0; i < (*ps).nustep_sets; i++) {
1438 if ((*ps).ustep_sets[i].status == CASU_FATAL) {
1441 ff =
casu_fits_wrap(outimage,(*ps).ustep_sets[i].f[0],NULL,NULL);
1442 (*ps).dith_input[(*ps).ndith] = ff;
1444 (*ps).ustep_sets[i].super = ff;
1446 (*ps).dithc_input[(*ps).ndith++] = ff;
1448 (*ps).ustep_sets[i].superc = ff;
1459 for (k = 0; k < (*ps).ustep_sets[i].nframes; k++) {
1460 ff = (*ps).ustep_sets[i].f[k];
1465 cpl_msg_error(fctid,
"Unable to open WCS structure %s",
1475 val =
casu_med(cpl_image_get_data_float(fi),NULL,npts);
1477 "ESO DRS BACKMED",val);
1483 d = cpl_array_get_data_int_const(cpl_wcs_get_image_dims(wcs));
1484 refx = 0.5*(double)d[0];
1485 refy = 0.5*(double)d[1];
1488 "ESO DRS XOFFMICRO",0.0);
1490 "ESO DRS YOFFMICRO",0.0);
1491 cpl_wcs_delete(wcs);
1502 "ESO DRS XOFFMICRO",x);
1504 "ESO DRS YOFFMICRO",y);
1505 cpl_wcs_delete(wcs);
1510 tmp = cpl_malloc((*ps).ustep_sets[i].nframes*
sizeof(casu_fits *));
1512 for (k = 0; k < (*ps).ustep_sets[i].nframes; k++) {
1513 ff = (*ps).ustep_sets[i].f[k];
1517 if (nk < (*ps).ustep_sets[i].nframes) {
1518 cpl_msg_error(fctid,
"A frame in this ustep sequence failed");
1519 (*ps).ustep_sets[i].status = CASU_WARN;
1525 nstep = (int)sqrt((
double)((*ps).ustep_sets[i].nustep));
1529 if (status != CASU_OK) {
1530 cpl_msg_error(fctid,
1531 "Interleaving failed for ugroup %" CPL_SIZE_FORMAT
" extn %" CPL_SIZE_FORMAT,
1532 (cpl_size)((*ps).ustep_sets[i].ustep_number),
1534 freepropertylist(plist);
1535 freeimage(outimage);
1539 ff =
casu_fits_wrap(outimage,(*ps).ustep_sets[i].f[0],NULL,NULL);
1541 (*ps).ustep_sets[i].super = ff;
1544 (*ps).ustep_sets[i].superc = ff;
1551 (*ps).ustep_sets[i].f[0],NULL,
1554 (*ps).ustep_sets[i].f[0],
1556 (*ps).ndithc = (*ps).ndith;
1557 (*ps).ustep_sets[i].super = (*ps).dith_input[(*ps).ndith - 1];
1558 (*ps).ustep_sets[i].superc = (*ps).dithc_input[(*ps).ndithc - 1];
1559 freepropertylist(plist);
1586 int status,i,ustepnum,nmatch,refset;
1587 float *xoffs,*yoffs,xoff,yoff,filtfwhm;
1588 cpl_wcs *wcsref,*wcs;
1590 casu_tfits *catref,*outcat;
1591 cpl_table *cr,*oc,*outxy;
1592 const char *fctid =
"vircam_jmp_dither_offsets";
1593 const double maxoffset = 2048;
1600 if ((*ps).ndith == 0)
1605 if ((*ps).ndith == 1) {
1607 "ESO DRS XOFFDITHER",(
double)0.0);
1609 "ESO DRS YOFFDITHER",(
double)0.0);
1616 xoffs = cpl_malloc((*ps).ndith*
sizeof(
float));
1617 yoffs = cpl_malloc((*ps).ndith*
sizeof(
float));
1623 for (i = 0; i < (*ps).ndith; i++) {
1624 ff = (*ps).dith_input[i];
1634 cpl_msg_warning(fctid,
1635 "Unable to get WCS for ustep %" CPL_SIZE_FORMAT,
1636 (cpl_size)ustepnum);
1661 if (status != CASU_OK) {
1664 cpl_msg_warning(fctid,
1665 "Unable to WCS difference for %" CPL_SIZE_FORMAT,
1666 (cpl_size)ustepnum);
1667 }
else if (fabs((
double)xoff) > maxoffset ||
1668 fabs((
double)yoff) > maxoffset) {
1669 cpl_msg_warning(fctid,
1670 "WCS offsets for %" CPL_SIZE_FORMAT
" are > %g: %g %g -- ignoring",
1671 (cpl_size)ustepnum,maxoffset,xoff,yoff);
1678 cpl_wcs_delete(wcs);
1681 cpl_wcs_delete(wcsref);
1687 filtfwhm = (inter_lv ? 3.5 : 2.0);
1688 for (i = 0; i < (*ps).ndith; i++) {
1689 ff = (*ps).dith_input[i];
1693 if ((*ps).ndithc != 1)
1694 ffc = (*ps).dithc_input[i];
1696 ffc = (*ps).dithc_input[0];
1699 (void)
casu_imcore(ff,ffc,25,5.0,0,3.5,64,1,filtfwhm,&outcat,4.0,
1709 cpl_msg_error(fctid,
1710 "Unable to get offsets for %" CPL_SIZE_FORMAT,
1711 (cpl_size)ustepnum);
1720 cpl_msg_error(fctid,
1721 "Unable to get object offset for %" CPL_SIZE_FORMAT
". Going with WCS offset",
1722 (cpl_size)ustepnum);
1731 cpl_table_add_scalar(oc,
"X_coordinate",(
double)xoffs[i]);
1732 cpl_table_add_scalar(oc,
"Y_coordinate",(
double)yoffs[i]);
1733 if (catref == NULL) {
1741 (void)
casu_matchxy(oc,cr,100.0,&xoff,&yoff,&nmatch,&outxy,&status);
1749 if ((nmatch == 0 || status == CASU_FATAL) &&
1754 cpl_msg_error(fctid,
1755 "Unable to match stars for %" CPL_SIZE_FORMAT,
1756 (cpl_size)ustepnum);
1762 }
else if ((nmatch == 0 || status == CASU_FATAL) &&
1767 cpl_msg_warning(fctid,
1768 "Unable to match stars for %" CPL_SIZE_FORMAT
". Going with WCS offsets",
1769 (cpl_size)ustepnum);
1781 for (i = 0; i < (*ps).ndith; i++) {
1784 ff = (*ps).dith_input[i];
1786 "ESO DRS XOFFDITHER",(
double)xoffs[i]);
1788 "ESO DRS YOFFDITHER",(
double)yoffs[i]);
1817 int status,ngood,i,n;
1818 casu_fits **d,**dc,*ff;
1819 cpl_propertylist *dither_ehu,*dither_phu;
1820 cpl_image *outdither,*outditherc;
1821 const char *fctid =
"vircam_jmp_dither_images";
1826 for (i = 0; i < (*ps).ndith; i++)
1834 cpl_msg_error(fctid,
"No good input images for jittering");
1840 (*ps).stack_frame = ff;
1844 (*ps).stackc_frame = ff;
1850 d = cpl_malloc(ngood*
sizeof(casu_fits *));
1851 dc = cpl_malloc(ngood*
sizeof(casu_fits *));
1853 for (i = 0; i < (*ps).ndith; i++) {
1855 d[n] = (*ps).dith_input[i];
1856 if ((*ps).ndithc != 1)
1857 dc[n++] = (*ps).dithc_input[i];
1859 dc[n++] = (*ps).dithc_input[0];
1866 (void)
casu_imdither(d,dc,ngood,ngood,5.0,5.0,&dither_ehu,
"EXPTIME",
1867 &outdither,&outditherc,&status);
1869 if (status != CASU_OK) {
1870 freeimage(outdither);
1871 freeimage(outditherc);
1872 cpl_msg_error(fctid,
"Error jittering to output");
1882 freepropertylist(dither_phu);
1883 freepropertylist(dither_ehu);
1906 const char *fctid =
"vircam_jmp_catalogue";
1909 float filtfwhm,gain;
1914 cpl_msg_error(fctid,
"No stack image available. No catalogue generated");
1921 filtfwhm = (inter_lv ? 3.5 : 2);
1923 (void)
casu_imcore((*ps).stack_frame,(*ps).stackc_frame,
1924 vircam_jmp_config.ipix,
1925 vircam_jmp_config.threshold,
1926 vircam_jmp_config.icrowd,
1927 vircam_jmp_config.rcore,
1928 vircam_jmp_config.nbsize,2,filtfwhm,
1929 &outtab,gain,&status);
1935 if (status != CASU_OK) {
1936 cpl_msg_error(fctid,
"Error generating catalogue");
1940 (*ps).outcat = outtab;
1965 int status,ncat,nstd,level;
1966 const char *fctid =
"vircam_jmp_matched_stds";
1967 cpl_table *stdscat,*newstds,*tmp,*tmp2,*cat;
1968 cpl_propertylist *p;
1976 if ((*ps).outcat == NULL) {
1977 cpl_msg_error(fctid,
"No input catalogue found");
1984 catapath,cata,0,
".",&stdscat,&status);
1985 if (status != CASU_OK) {
1987 cpl_msg_error(fctid,
"Failed to find any standards");
1993 (void)cpl_table_or_selected_float(stdscat,
"e_Jmag",CPL_LESS_THAN,0.2);
1994 (void)cpl_table_and_selected_float(stdscat,
"e_Kmag",CPL_LESS_THAN,0.2);
1995 newstds = cpl_table_extract_selected(stdscat);
1996 nstd = (int)cpl_table_get_nrow(newstds);
2004 ncat = (int)cpl_table_get_nrow(cat);
2005 if (ncat > 500 && ncat > 2.0*nstd) {
2006 tmp = cpl_table_duplicate(cat);
2007 (void)cpl_table_or_selected_float(tmp,
"Ellipticity",CPL_LESS_THAN,0.5);
2008 tmp2 = cpl_table_extract_selected(tmp);
2009 ncat = (int)cpl_table_get_nrow(tmp2);
2011 p = cpl_propertylist_new();
2012 cpl_propertylist_append_bool(p,
"Aper_flux_3",TRUE);
2013 cpl_table_sort(tmp2,(
const cpl_propertylist *)p);
2014 cpl_propertylist_delete(p);
2015 level = min(ncat,max(1,min(5000,max(500,2*nstd))));
2016 tmp = cpl_table_extract(tmp2,1,(cpl_size)level);
2018 ncat = (int)cpl_table_get_nrow(tmp);
2026 (void)
casu_matchstds(cat,newstds,300.0,&((*ps).matchstds),&status);
2030 if (status != CASU_OK) {
2031 freetable((*ps).matchstds);
2032 cpl_msg_error(fctid,
"Failed to match standards to catalogue");
2058 const char *fctid =
"vircam_jmp_wcsfit";
2059 float *ra,*dec,*x,*y;
2070 if ((*ps).matchstds == NULL) {
2071 cpl_msg_error(fctid,
"No input matched standards catalogue found");
2080 if (status != CASU_OK) {
2081 cpl_msg_error(fctid,
"Failed to fit WCS");
2088 n = (int)cpl_table_get_nrow(cat);
2091 cpl_msg_error(fctid,
"Failed to fill RA and Dec in catalogue");
2094 x = cpl_table_get_data_float(cat,
"X_coordinate");
2095 y = cpl_table_get_data_float(cat,
"Y_coordinate");
2096 ra = cpl_table_get_data_float(cat,
"RA");
2097 dec = cpl_table_get_data_float(cat,
"DEC");
2098 for (i = 0; i < n; i++) {
2103 cpl_wcs_delete(wcs);
2126 const char *fctid =
"vircam_jmp_photcal";
2136 if ((*ps).matchstds == NULL || (
int)cpl_table_get_nrow((*ps).matchstds) == 0) {
2137 cpl_msg_error(fctid,
"No input matched standards catalogue found");
2144 cpl_msg_error(fctid,
"No filter name in stack header");
2150 pp =
casu_tfits_wrap(cpl_table_duplicate((*ps).matchstds),(*ps).outcat,NULL,
2153 1,filt,(*ps).tphottab,1,NULL,NULL,
"EXPTIME",
2154 "ESO TEL AIRM START",100000.0,&status);
2156 if (status != CASU_OK) {
2157 cpl_msg_error(fctid,
"Failed to fit photometric zeropoint");
2188 n = (int)cpl_image_get_size_x(im)*(int)cpl_image_get_size_y(im);
2189 data = cpl_image_get_data_int(im);
2193 for (i = 0; i < n; i++)
2194 data[i] = (data[i] == 1 ? 0 : 100);
2218 int i,ngood,status,nfrms;
2220 casu_fits **ftmp,*ff,**frms = NULL;
2221 const char *fctid =
"vircam_jmp_skycor";
2222 unsigned char *rejmask,*rejplus;
2223 cpl_propertylist *drs;
2224 cpl_image *skyimg,*fim;
2225 float *data,med,sig;
2229 if (offsky == 0 || offsky == 1) {
2234 nfrms = (*ps).noffsets;
2235 frms = (*ps).offsky_fits;
2237 nfrms = (*ps).nscience;
2238 frms = (*ps).sci_fits;
2243 ftmp = cpl_malloc(nfrms*
sizeof(casu_fits *));
2245 for (i = 0; i < nfrms; i++) {
2255 cpl_msg_error(fctid,
"Sky correction impossible. No good sky frames available");
2262 (void)
casu_imcombine(ftmp,NULL,ngood,1,1,1,2.0,
"EXPTIME",&skyimg,NULL,
2263 &rejmask,&rejplus,&drs,&status);
2267 freepropertylist(drs);
2275 data = cpl_image_get_data_float(skyimg);
2276 npts = (long)cpl_image_get_size_x(skyimg)*(long)cpl_image_get_size_y(skyimg);
2277 casu_qmedsig(data,NULL,npts,5.0,3,-1000.0,65535.0,&med,&sig);
2278 for (i = 0; i < npts; i++)
2286 freepropertylist(drs);
2288 cpl_propertylist_update_float(drs,
"ESO QC SKYMED",med);
2289 cpl_propertylist_set_comment(drs,
"ESO QC SKYMED",
2290 "Median sky background");
2291 cpl_propertylist_update_float(drs,
"ESO QC SKYSIG",sig);
2292 cpl_propertylist_set_comment(drs,
"ESO QC SKYSIG",
2293 "Sky background sigma");
2299 for (i = 0; i < (*ps).nscience; i++) {
2300 ff = (*ps).sci_fits[i];
2304 cpl_image_subtract(fim,skyimg);
2306 cpl_propertylist_update_string(drs,
"ESO DRS SKYCOR",
"internal");
2307 }
else if (offsky == 1) {
2308 cpl_propertylist_update_string(drs,
"ESO DRS SKYCOR",
"offsky");
2309 }
else if (offsky == -1) {
2310 cpl_propertylist_update_string(drs,
"ESO DRS SKYCOR",
2313 cpl_propertylist_set_comment(drs,
"ESO DRS SKYCOR",
2314 "Sky correction method");
2317 for (i = 0; i < (*ps).noffsets; i++) {
2318 ff = (*ps).offsky_fits[i];
2322 cpl_image_subtract(fim,skyimg);
2324 cpl_propertylist_update_string(drs,
"ESO DRS SKYCOR",
"internal");
2325 }
else if (offsky == 1) {
2326 cpl_propertylist_update_string(drs,
"ESO DRS SKYCOR",
"offsky");
2327 }
else if (offsky == -1) {
2328 cpl_propertylist_update_string(drs,
"ESO DRS SKYCOR",
2331 cpl_propertylist_set_comment(drs,
"ESO DRS SKYCOR",
2332 "Image has been sky corrected");
2339 cpl_image_delete(skyimg);
2340 else if (offsky == 1)
2341 cpl_image_add_scalar(skyimg,med);
2365 cpl_propertylist *p_rg;
2366 const char *fctid =
"vircam_jmp_get_readnoise_gain";
2370 p_rg = cpl_propertylist_load(cpl_frame_get_filename((*ps).readgain_file),
2375 switch (cpl_propertylist_get_type(p_rg,
"ESO QC READNOISE")) {
2376 case CPL_TYPE_FLOAT:
2377 *readnoise = cpl_propertylist_get_float(p_rg,
"ESO QC READNOISE");
2379 case CPL_TYPE_DOUBLE:
2380 *readnoise = (float)cpl_propertylist_get_double(p_rg,
2381 "ESO QC READNOISE");
2386 cpl_msg_error(fctid,
"Unable to get READNOISE estimate, guessing %g\n",
2392 switch (cpl_propertylist_get_type(p_rg,
"ESO QC CONAD")) {
2393 case CPL_TYPE_FLOAT:
2394 *gain = cpl_propertylist_get_float(p_rg,
"ESO QC CONAD");
2396 case CPL_TYPE_DOUBLE:
2397 *gain = (float)cpl_propertylist_get_double(p_rg,
"ESO QC CONAD");
2402 cpl_msg_error(fctid,
"Unable to get GAIN estimate, guessing %g\n",
2405 cpl_propertylist_delete(p_rg);
2426 int ngood,i,status,ii;
2427 float illcor_rms,gain;
2428 casu_fits **ftmp,*ff,*ffc;
2430 cpl_table **mstds,*stdscat,*ms,*illcor,*ot;
2432 cpl_propertylist **pl,*phu,*ehu;
2433 const char *fctid =
"vircam_jmp_illum";
2437 (*ps).illcor = NULL;
2441 ftmp = cpl_malloc((*ps).nscience*
sizeof(casu_fits *));
2443 for (i = 0; i < (*ps).nscience; i++) {
2444 ff = (*ps).sci_fits[i];
2453 cpl_msg_error(fctid,
"Illumination correction impossible. No good science frames available");
2460 cpl_msg_error(fctid,
"No filter name in stack header");
2468 mstds = cpl_malloc(ngood*
sizeof(cpl_table *));
2469 for (i = 0; i < ngood; i++)
2471 pl = cpl_malloc(ngood*
sizeof(cpl_propertylist *));
2472 for (i = 0; i < ngood; i++)
2479 for (i = 0; i < ngood; i++) {
2484 1.5*vircam_jmp_config.threshold,0,
2485 vircam_jmp_config.rcore,vircam_jmp_config.nbsize,2,
2486 3.5,&outtab,gain,&status);
2487 if (status != CASU_OK)
2494 cat,0,
".",&stdscat,&status);
2495 if (status == CASU_FATAL) {
2498 for (ii = 0; ii < ngood; ii++) {
2499 freetable(mstds[ii]);
2500 freepropertylist(pl[ii]);
2504 cpl_msg_error(fctid,
"Illumination correction fails");
2506 }
else if (status == CASU_WARN) {
2516 if (status == CASU_FATAL) {
2520 for (ii = 0; ii < ngood; ii++) {
2521 freetable(mstds[ii]);
2522 freepropertylist(pl[ii]);
2526 cpl_msg_error(fctid,
"%s",cpl_error_get_message());
2537 (void)
vircam_illum(ftmp,mstds,pl,ngood,filt,(*ps).tphottab,128,&illcor,
2538 &illcor_rms,&status);
2545 cpl_propertylist_update_float(ehu,
"ESO QC ILLUMCOR_RMS",illcor_rms);
2546 cpl_propertylist_set_comment(ehu,
"ESO QC ILLUMCOR_RMS",
2547 "RMS of illumination correction map");
2551 for (i = 0; i < ngood; i++) {
2552 freetable(mstds[i]);
2553 freepropertylist(pl[i]);
2584static char *vircam_jmp_outfile(
const char *bname,
int ind,
int isfits) {
2595 nf += ((int)log10((
double)ind)+1);
2603 fname = cpl_malloc(nf);
2608 (void)snprintf(fname,nf,
"%s_%d.fits",bname,ind);
2610 (
void)snprintf(fname,nf,
"%s_%d",bname,ind);
2635 (*ps).labels = NULL;
2636 (*ps).master_dark = NULL;
2637 (*ps).master_twilight_flat = NULL;
2638 (*ps).master_conf = NULL;
2639 (*ps).master_sky = NULL;
2641 (*ps).chantab = NULL;
2642 (*ps).phottab = NULL;
2643 (*ps).tphottab = NULL;
2644 (*ps).readgain_file = NULL;
2645 (*ps).science_frames = NULL;
2646 (*ps).offset_skies = NULL;
2647 (*ps).product_frames_simple = NULL;
2648 (*ps).product_frames_simple_off = NULL;
2649 (*ps).product_frames_super = NULL;
2650 (*ps).product_frames_superc = NULL;
2651 (*ps).product_frame_stack = NULL;
2652 (*ps).product_frame_stackc = NULL;
2653 (*ps).product_frame_cat = NULL;
2654 (*ps).product_frame_illcor = NULL;
2655 (*ps).product_frame_sky = NULL;
2656 (*ps).phupaf = NULL;
2657 (*ps).gaincors = NULL;
2658 (*ps).catpath = NULL;
2659 (*ps).catname = NULL;
2660 (*ps).catpath2 = NULL;
2661 (*ps).catname2 = NULL;
2669 (*ps).fchantab = NULL;
2671 (*ps).sci_fits = NULL;
2673 (*ps).offsky_fits = NULL;
2674 (*ps).nustep_sets = 0;
2675 (*ps).ustep_sets = NULL;
2678 (*ps).dith_input = NULL;
2679 (*ps).dithc_input = NULL;
2680 (*ps).stack_frame = NULL;
2681 (*ps).stackc_frame = NULL;
2682 (*ps).outcat = NULL;
2683 (*ps).outsky = NULL;
2684 (*ps).matchstds = NULL;
2685 (*ps).illcor = NULL;
2716 freefits((*ps).fdark);
2717 freefits((*ps).fflat);
2718 freefits((*ps).fconf);
2719 freefits((*ps).fsky);
2720 freetfits((*ps).fchantab);
2721 freefitslist((*ps).sci_fits,(*ps).nscience);
2722 freefitslist((*ps).offsky_fits,(*ps).noffsets);
2724 for (i = 0; i < (*ps).nustep_sets; i++) {
2725 freespace((*ps).ustep_sets[i].f);
2726 freefits((*ps).ustep_sets[i].super);
2727 freefits((*ps).ustep_sets[i].superc);
2729 freespace((*ps).ustep_sets);
2730 (*ps).nustep_sets = 0;
2731 freespace((*ps).dith_input);
2733 freespace((*ps).dithc_input);
2736 freefits((*ps).stack_frame);
2737 freefits((*ps).stackc_frame);
2738 if(ps->outcat !=NULL) freetfits((*ps).outcat);
2739 if(ps->matchstds!=NULL) freetable((*ps).matchstds);
2740 freetfits((*ps).illcor);
2741 freefits((*ps).outsky);
2748 freespace((*ps).labels);
2749 freeframe((*ps).master_dark);
2750 freeframe((*ps).master_twilight_flat);
2751 freeframe((*ps).master_conf);
2752 freeframe((*ps).master_sky);
2753 freemask((*ps).mask);
2754 freeframe((*ps).chantab);
2755 freeframe((*ps).phottab);
2756 freeframe((*ps).readgain_file);
2757 freetable((*ps).tphottab);
2758 freeframeset((*ps).science_frames);
2759 freeframeset((*ps).offset_skies);
2760 freepropertylist((*ps).phupaf);
2761 freespace((*ps).product_frames_simple);
2762 freespace((*ps).product_frames_super);
2763 freespace((*ps).product_frames_superc);
2764 freespace((*ps).product_frames_simple_off);
2765 freespace((*ps).gaincors);
2766 freespace((*ps).catpath);
2767 freespace((*ps).catname);
2768 freespace((*ps).catpath2);
2769 freespace((*ps).catname2);
casu_fits * casu_fits_wrap(cpl_image *im, casu_fits *model, cpl_propertylist *phu, cpl_propertylist *ehu)
int casu_fits_get_status(casu_fits *p)
cpl_image * casu_fits_get_image(casu_fits *p)
int casu_fits_set_error(casu_fits *p, int status)
char * casu_fits_get_fullname(casu_fits *p)
cpl_propertylist * casu_fits_get_phu(casu_fits *p)
char * casu_fits_get_filename(casu_fits *p)
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
int casu_fits_get_nexten(casu_fits *p)
int casu_imdither(casu_fits **inf, casu_fits **inconf, int nimages, int nconfs, float lthr, float hthr, cpl_propertylist **p, const char *expkey, cpl_image **out, cpl_image **outc, int *status)
Dither a set of jittered observations.
int casu_imcore(casu_fits *infile, casu_fits *conf, int ipix, float threshold, int icrowd, float rcore, int nbsize, int cattype, float filtfwhm, casu_tfits **outtab, float gainloc, int *status)
Generate object catalogues from input images.
int casu_imcombine(casu_fits **fset, casu_fits **fsetv, int nfits, int combtype, int scaletype, int xrej, float thresh, const char *expkey, cpl_image **outimage, cpl_image **outvimage, unsigned char **rejmask, unsigned char **rejplus, cpl_propertylist **drs, int *status)
Stack images into a mean or median image with rejection.
int casu_matchstds(cpl_table *objtab, cpl_table *stdstab, float srad, cpl_table **outtab, int *status)
Match object and standard star tables by their xy coordinates.
int casu_matchxy(cpl_table *progtab, cpl_table *template, float srad, float *xoffset, float *yoffset, int *nm, cpl_table **outtab, int *status)
Match two lists of x,y coordinates from two tables to find the cartesian offset between them.
int casu_photcal_extinct(casu_fits **images, casu_tfits **mstds, casu_tfits **cats, int nimages, char *filt, cpl_table *phottab, int minstars, cpl_frame *schlf_n, cpl_frame *schlf_s, const char *expkey, const char *amkey, float magerrcut, int *status)
Do photometric calibration.
int casu_platesol(cpl_propertylist *plist, cpl_propertylist *tlist, cpl_table *matchedstds, int nconst, int shiftan, int *status)
Work out a WCS for an image.
int casu_getstds(cpl_propertylist *plist, int cache, char *path, char *catname, int cdssearch, char *cacheloc, cpl_table **stds, int *status)
Get a table of standard stars that appear on an image from a catalogue.
float casu_med(float *data, unsigned char *bpm, long npts)
void casu_qmedsig(float *data, unsigned char *bpm, long npts, float thresh, int niter, float lowv, float highv, float *median, float *sigma)
cpl_propertylist * casu_tfits_get_ehu(casu_tfits *p)
casu_tfits * casu_tfits_wrap(cpl_table *tab, casu_tfits *model, cpl_propertylist *phu, cpl_propertylist *ehu)
void casu_tfits_delete(casu_tfits *p)
cpl_propertylist * casu_tfits_get_phu(casu_tfits *p)
cpl_table * casu_tfits_get_table(casu_tfits *p)
void casu_merge_propertylists(cpl_propertylist *p1, cpl_propertylist *p2)
Merge two propertylists.
long casu_getnpts(cpl_image *in)
Get the number of pixels in a 2d image.
void casu_dummy_property(cpl_propertylist *p)
Set dummy property keyword.
cpl_image * casu_dummy_image(casu_fits *model)
Create a dummy image of zeros based on a model.
cpl_table * casu_dummy_catalogue(int type)
Create a dummy catalogue of a given type with no rows.
int casu_removewcs(cpl_propertylist *p, int *status)
int casu_diffxywcs(cpl_wcs *wcs, cpl_wcs *wcsref, float *xoff, float *yoff, int *status)
void casu_radectoxy(cpl_wcs *wcs, double ra, double dec, double *x, double *y)
void casu_xytoradec(cpl_wcs *wcs, double x, double y, double *ra, double *dec)
int vircam_illum(casu_fits **images, cpl_table **mstds, cpl_propertylist **pl, int nimages, char *filt, cpl_table *phottab, int nbsize, cpl_table **illcor, float *illcor_rms, int *status)
Work out the illumination correction.
int vircam_interleave(casu_fits **infiles, int ninputs, casu_fits **inconfs, int nconfs, int nsteps, cpl_propertylist **p, cpl_image **outimage, cpl_image **outconf, int *status)
Interleave a set of microstepped observations.
void vircam_dfs_set_product_primary_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit, int synch)
void vircam_dfs_set_product_exten_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit)
int vircam_jmp_save_offsky(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist)
void vircam_jmp_dither_images(struct psStruct *ps)
void vircam_jmp_init(struct psStruct *ps)
void vircam_jmp_get_readnoise_gain(struct psStruct *ps, int jext, float *readnoise, float *gain)
void vircam_jmp_matched_stds(struct psStruct *ps, char *cata, char *catapath)
void vircam_jmp_ustep_seq(struct psStruct *ps)
int vircam_jmp_save_super(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist)
void vircam_jmp_bpm2conf(struct psStruct *ps)
int vircam_jmp_save_catalogue(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist, cpl_propertylist *dummyqcprops)
void vircam_jmp_wcsfit(struct psStruct *ps)
void vircam_jmp_photcal(struct psStruct *ps)
int vircam_jmp_save_stack(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist, cpl_propertylist *dummyqcprops)
int vircam_jmp_save_simple_offsets(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist)
void vircam_jmp_illum(struct psStruct *ps, char *cat, char *catpath)
void vircam_jmp_dither_offsets(struct psStruct *ps, int inter_lv)
void vircam_jmp_tidy(struct psStruct *ps, int level)
int vircam_jmp_save_illum(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist, cpl_propertylist *dummyqcprops)
int vircam_jmp_save_simple(struct psStruct *ps, cpl_frameset *framelist, cpl_parameterlist *parlist)
void vircam_jmp_skycor(struct psStruct *ps)
void vircam_jmp_interleave(struct psStruct *ps)
void vircam_jmp_catalogue(struct psStruct *ps, int inter_lv)
int vircam_pfits_get_nusteps(const cpl_propertylist *plist, int *nusteps)
Get the value of the number of microsteps in a sequence.
int vircam_pfits_get_ustepnum(const cpl_propertylist *plist, int *ustepnum)
Get the value of the first run number in the current microstep sequence.
int vircam_pfits_get_filter(const cpl_propertylist *plist, char *filt)
Get the name of the current filter.
cpl_table * vircam_illcor_newtab(int nrows)