30 #include <irplib_utils.h>
32 #include <uves_error.h>
33 #include <uves_qclog.h>
35 #include <uves_utils_wrappers.h>
36 #include <flames_midas_def.h>
37 #include <flames_corvel.h>
38 #include <flames_reduce_vcorrel.h>
42 double DRS_CVEL_MIN = -6.;
43 double DRS_CVEL_MAX = +6.;
44 double DRS_CVEL_STEP = 0.5;
48 flames_reduce_vcorrel(
const char* sci_pfx,
52 const cpl_frame* cvel_tab,
53 const char* xxima_pfx,
54 const char* xwcal_pfx,
55 const double drs_cvel_min,
56 const double drs_cvel_max,
65 char cvel_tab_name[80];
74 const int npix=(drs_cvel_max-drs_cvel_min)/DRS_CVEL_STEP+1;
76 cpl_image* tim_ccf_ima=NULL;
77 cpl_image* nim_ccf_ima=NULL;
79 cpl_table* cvel_tbl=NULL;
80 double ccfcnt[ord_max];
90 char out_cvel_tab[80];
93 cpl_table* cvel_ord_tbl=NULL;
96 cpl_image* tot_ima=NULL;
97 cpl_image* nrm_ima=NULL;
104 cpl_propertylist* plist_ima_new=NULL;
105 cpl_propertylist* plist_tbl_new=NULL;
112 const char* command=NULL;
120 sprintf(otab,
"%s%s%s",cvel_pfx,ccd_id,
".fits");
121 sprintf(tim_ccf,
"%s%s%s%s",
"tot_",cvel_pfx,ccd_id,
".fits");
122 sprintf(nim_ccf,
"%s%s%s%s",
"nrm_",cvel_pfx,ccd_id,
".fits");
123 sprintf(iim_pfx,
"%s%s%s%s",
"mw",sci_pfx,xxima_pfx,
".fits");
124 sprintf(tab_pfx,
"%s%s%s",
"tab_",ccd_id,
"_");
125 sprintf(nim_pfx,
"%s%s%s",
"nrm_",ccd_id,
"_");
126 sprintf(tim_pfx,
"%s%s%s",
"tot_",ccd_id,
"_");
127 sprintf(ref_frm,
"%s%s%s",
"w",sci_pfx,xwcal_pfx);
132 uves_msg(
"name=%s",cpl_frame_get_filename(cvel_tab));
133 sprintf(cvel_tab_name,
"%s",cpl_frame_get_filename(cvel_tab));
136 tim_ccf_ima=cpl_image_new(npix,ord_max,CPL_TYPE_FLOAT);
137 nim_ccf_ima=cpl_image_new(npix,ord_max,CPL_TYPE_FLOAT);
144 cvel_tbl=cpl_table_new(0);
145 check_nomsg(cpl_table_new_column(cvel_tbl,
"Select",CPL_TYPE_INT));
146 check_nomsg(cpl_table_new_column(cvel_tbl,
"ccf_pos",CPL_TYPE_DOUBLE));
147 check_nomsg(cpl_table_new_column(cvel_tbl,
"ccf_nrm",CPL_TYPE_DOUBLE));
148 check_nomsg(cpl_table_new_column(cvel_tbl,
"ccf_out",CPL_TYPE_DOUBLE));
149 check_nomsg(cpl_table_new_column(cvel_tbl,
"ORDER",CPL_TYPE_INT));
159 uves_check_rec_status(0);
161 for (ord=ord_min;ord<=ord_max;ord++) {
165 sprintf(out_cvel_tab,
"%s%s%d%s",
"tab_",ccd_id,ord,
".fits");
166 sprintf(out_tot_ima,
"%s%s%d%s",
"tot_",ccd_id,ord,
".fits");
167 sprintf(out_nrm_ima,
"%s%s%d%s",
"nrm_",ccd_id,ord,
".fits");
170 uves_msg_debug(
"vc2 %s %s %s",out_cvel_tab,out_tot_ima,out_nrm_ima);
172 iim_pfx,cvel_tab_name,ord);
194 drs_cvel_min,drs_cvel_max,DRS_CVEL_STEP);
196 check_nomsg(tot_ima=cpl_image_load(out_tot_ima,CPL_TYPE_FLOAT,0,0));
197 check_nomsg(nrm_ima=cpl_image_load(out_nrm_ima,CPL_TYPE_FLOAT,0,0));
198 check_nomsg(cpl_image_copy(tim_ccf_ima,tot_ima,1,ord-ord_min+1));
199 check_nomsg(cpl_image_copy(nim_ccf_ima,nrm_ima,1,ord-ord_min+1));
200 check_nomsg(cvel_ord_tbl=cpl_table_load(out_cvel_tab,1,1));
203 check_nomsg(cpl_table_new_column(cvel_ord_tbl,
"ORDER",CPL_TYPE_INT));
204 check_nomsg(nrow=cpl_table_get_nrow(cvel_ord_tbl));
206 check_nomsg(cpl_table_fill_column_window_int(cvel_ord_tbl,
"ORDER",0,nrow,ord));
208 const char* unit=cpl_table_get_column_unit(cvel_ord_tbl,
"ccf_pos");
209 cpl_table_set_column_unit(cvel_tbl,
"ccf_pos",unit);
210 unit=cpl_table_get_column_unit(cvel_ord_tbl,
"ccf_nrm");
211 cpl_table_set_column_unit(cvel_tbl,
"ccf_nrm",unit);
212 unit=cpl_table_get_column_unit(cvel_ord_tbl,
"ccf_out");
213 cpl_table_set_column_unit(cvel_tbl,
"ccf_out",unit);
215 check_nomsg(cpl_table_insert(cvel_tbl,cvel_ord_tbl,row_pos));
218 if((status=SCFOPN(out_tot_ima,D_R4_FORMAT,0,F_IMA_TYPE,&in_ima_id))!=0) {
220 return flames_midas_error(MAREMMA);
223 if((status=SCFOPN(iim_pfx,D_R4_FORMAT,0,F_IMA_TYPE,&iim_pfx_id))!=0) {
225 return flames_midas_error(MAREMMA);
230 sprintf(key_name,
"%s",
"CORVEL_MAX");
231 if((status=SCDRDD(iim_pfx_id,key_name,1,1,&actvals,&corvel_max,&unit,&null))
234 key_name,out_tot_ima);
235 return flames_midas_error(MAREMMA);
240 sprintf(key_name,
"%s%d",
"CCF_PMX",ord);
242 if(!irplib_isnan(corvel_max)) {
243 ccfcnt[ord]=corvel_max;
244 check_nomsg(cpl_propertylist_append_double(plist_ima_new,key_name,
250 cpl_sprintf(
"%s%d%s",
251 "QC CCF",ord,
" POSMAX"),
259 check_nomsg(cpl_propertylist_append_double(plist_ima_new,key_name,
266 cpl_sprintf(
"%s%d%s",
267 "QC CCF",ord,
" POSMAX"),
276 sprintf(key_name,
"%s",
"CCF_MAX");
277 if((status=SCDRDD(in_ima_id,key_name,1,1,&actvals,&ccf_max,&unit,&null))
280 key_name,out_tot_ima);
281 return flames_midas_error(MAREMMA);
285 sprintf(key_name,
"%s%d",
"CCF_MAX",ord);
287 check_nomsg(cpl_propertylist_append_double(plist_ima_new,key_name,ccf_max));
291 cpl_sprintf(
"%s%d%s",
292 "QC CCF",ord,
" INTMAX"),
299 sprintf(key_name,
"%s",
"WAV_RNG");
300 if((status=SCDRDD(in_ima_id,key_name,1,1,&actvals,&wav_rng,&unit,&null))
303 key_name,out_tot_ima);
304 return flames_midas_error(MAREMMA);
307 sprintf(key_name,
"%s%d",
"WAV_RNG",ord);
310 check_nomsg(cpl_propertylist_append_double(plist_ima_new,key_name,wav_rng));
314 cpl_sprintf(
"%s%d%s",
315 "QC CCF",ord,
" WAVRNG"),
322 sprintf(key_name,
"%s",
"PIX_TOT");
323 if((status=SCDRDD(in_ima_id,key_name,1,1,&actvals,&pix_tot,&unit,&null))
326 key_name,out_tot_ima);
327 return flames_midas_error(MAREMMA);
332 if(!irplib_isinf(pix_tot)) {
334 sprintf(key_name,
"%s%d",
"PIX_TOT",ord);
335 check_nomsg(cpl_propertylist_append_double(plist_ima_new,key_name,pix_tot));
338 cpl_sprintf(
"%s%d%s",
339 "QC CCF",ord,
" PIXTOT"),
346 sprintf(key_name,
"%s%d",
"PIX_TOT",ord);
347 check_nomsg(cpl_propertylist_append_double(plist_ima_new,key_name,999.));
350 cpl_sprintf(
"%s%d%s",
351 "QC CCF",ord,
" PIXTOT"),
359 sprintf(key_name,
"%s",
"LIN_TOT");
360 if((status=SCDRDI(in_ima_id,key_name,1,1,&actvals,&lin_tot,&unit,&null))
363 key_name,out_tot_ima);
364 return flames_midas_error(MAREMMA);
368 sprintf(key_name,
"%s%d",
"LIN_TOT",ord);
370 check_nomsg(cpl_propertylist_append_int(plist_ima_new,key_name,lin_tot));
375 cpl_sprintf(
"%s%d%s",
376 "QC CCF",ord,
" LINTOT"),
382 if((status = SCFCLO(in_ima_id))!=0) {
384 return flames_midas_error(MAREMMA);
386 if((status = SCFCLO(iim_pfx_id))!=0) {
388 return flames_midas_error(MAREMMA);
392 uves_free_table(&cvel_ord_tbl);
393 uves_free_image(&tot_ima);
394 uves_free_image(&nrm_ima);
396 command=uves_sprintf(
"%s%s",
"rm -rf ",out_cvel_tab);
398 command=uves_sprintf(
"%s%s",
"rm -rf ",out_tot_ima);
400 command=uves_sprintf(
"%s%s",
"rm -rf ",out_nrm_ima);
407 check_nomsg(cpl_image_save(tim_ccf_ima,
"tot_ima.fits",CPL_BPP_IEEE_FLOAT,
408 plist_ima_new,CPL_IO_DEFAULT));
409 check_nomsg(cpl_image_save(nim_ccf_ima,
"nrm_ima.fits",CPL_BPP_IEEE_FLOAT,
410 plist_ima_new,CPL_IO_DEFAULT));
412 check_nomsg(cpl_table_save(cvel_tbl, plist_tbl_new, NULL, otab,
415 uves_free_image(&tim_ccf_ima);
416 uves_free_image(&nim_ccf_ima);
417 uves_free_table(&cvel_tbl);
419 ord = ord_max-ord_min+1;
426 for (ord=ord_min; ord<= ord_max; ord++) {
427 if (ccfcnt[ord] != 999) {
428 *avg_cnt +=ccfcnt[ord];
429 uves_msg_debug(
"POSMAX avg=%g cnt=%g ord=%d",*avg_cnt,ccfcnt[ord],ord);
436 for (ord = ord_min; ord <= ord_max; ord++) {
437 if (ccfcnt[ord] != 999) {
438 *sig_cnt += (ccfcnt[ord]-*avg_cnt)*(ccfcnt[ord]-*avg_cnt);
442 *sig_cnt = sqrt(*sig_cnt/(num_ord-1));
444 *zero_point+=(*avg_cnt);
565 if(plist_ima_new!=NULL) {
567 cpl_propertylist_delete(plist_ima_new);
570 uves_free_table(&cvel_tbl);
571 uves_free_image(&tim_ccf_ima);
572 uves_free_image(&nim_ccf_ima);
573 uves_free_image(&tot_ima);
574 uves_free_image(&nrm_ima);
575 uves_free_table(&cvel_ord_tbl);
579 if (cpl_error_get_code() != CPL_ERROR_NONE) {
580 uves_check_rec_status(9);
#define uves_msg_error(...)
Print an error message.
#define uves_msg_warning(...)
Print an warning message.
int uves_qclog_add_string(cpl_table *table, const char *key_name, const char *value, const char *key_help, const char *format)
Add string key to QC-LOG table.
int uves_qclog_add_double(cpl_table *table, const char *key_name, const double value, const char *key_help, const char *format)
Add double key to QC-LOG table.
int uves_qclog_add_int(cpl_table *table, const char *key_name, const int value, const char *key_help, const char *format)
Add integer key to QC-LOG table.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
#define uves_msg_debug(...)
Print a debug message.