SINFONI Pipeline Reference Manual  2.6.0
sinfo_utl_efficiency.c
1 /*
2  * This file is part of the ESO SINFONI Pipeline
3  * Copyright (C) 2004-2009 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 /*
20  * $Author: amodigli $
21  * $Date: 2012-03-03 10:17:31 $
22  * $Revision: 1.17 $
23  *
24  */
25 
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29 #include <string.h>
30 #include <math.h>
31 #include <cpl.h>
32 /* irplib */
33 #include <irplib_utils.h>
34 
35 #include <sinfo_pfits.h>
36 #include <sinfo_msg.h>
37 #include <sinfo_dfs.h>
38 #include <sinfo_error.h>
39 #include <sinfo_utils_wrappers.h>
40 #include "sinfo_utl_efficiency.h"
41 #include <sinfo_star_index.h>
42 
43 #define PRO_STD_STAR_SPECTRA "STD_STAR_SPECTRA"
44 static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH";
45 static const char COL_NAME_WAVELENGTH_C[] = "WAVELENGTH";
46 static const char COL_NAME_LAMBDA[] = "LAMBDA";
47 static const char COL_NAME_LA_SILLA[] = "LA_SILLA";
48 static const char COL_NAME_REF[] = "REF";
49 static const char COL_NAME_COR[] = "COR";
50 static const char COL_NAME_SRC_COR[] = "SRC_COR";
51 static const char COL_NAME_COUNTS_BKG[] = "INT_OBJ";//"counts_tot";
52 static const char COL_NAME_FLUX[] = "FLUX";
53 static const char COL_NAME_EPHOT[] = "EPHOT";
54 static const char COL_NAME_EXT[] = "EXT";
55 static const char COL_NAME_SRC_EFF[] = "EFF";
56 static const char PAR_NAME_DIT[] = "ESO DET DIT";
57 
58 static char FRM_RAW_IMA_SLIT[] = PRO_STD_STAR_SPECTRA;
59 static char FRM_FLUX_STD_TAB[] = FLUX_STD_TABLE;
60 static char FRM_FLUX_STD_CAT[] = FLUX_STD_CATALOG;
61 static char FRM_EXTCOEFF_TAB[] = EXTCOEFF_TABLE;
62 
63 static int
64 sinfo_column_to_double(cpl_table* ptable, const char* column);
65 
66 static double
67 sinfo_table_interpolate(cpl_table* tbl,
68  double wav,
69  const char* colx,
70  const char* coly);
71 static double*
72 sinfo_create_column_double(cpl_table* tbl, const char* col_name, int nrow);
73 
74 
75 
76 cpl_error_code
77 sinfo_get_std_obs_values(cpl_propertylist* plist,
78  double* exptime,
79  double* airmass,
80  double* dRA,
81  double* dDEC);
82 
83 /*--------------------------------------------------------------------------*/
84 
86 /*---------------------------------------------------------------------------*/
97 /*---------------------------------------------------------------------------*/
98 
99 void
100 sinfo_load_ref_table(cpl_frameset* frames,
101  double dRA,
102  double dDEC,
103  double EPSILON,
104  cpl_table** pptable)
105 {
106  const char* name = NULL;
107  cpl_frame* frm_ref = NULL;
108 
109  /* REF STD frame */
110  frm_ref=cpl_frameset_find(frames,FRM_FLUX_STD_TAB);
111  if (!frm_ref)
112  {
113  sinfo_msg("REF frame is not found, trying to get REF from the catalog");
114  /* REF STD catalog frame */
115  // get from catalog
116  check_nomsg(frm_ref=cpl_frameset_find(frames,FRM_FLUX_STD_CAT));
117  if (frm_ref)
118  {
119  check_nomsg(name=cpl_frame_get_filename(frm_ref));
120  if (name)
121  {
122  star_index* pstarindex = star_index_load(name);
123  if (pstarindex)
124  {
125  const char* star_name = 0;
126  sinfo_msg("The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]", dRA, dDEC, EPSILON);
127  *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name);
128  if (*pptable && star_name)
129  {
130  sinfo_msg("REF table is found in the catalog, star name is [%s]", star_name);
131  }
132  else
133  {
134  sinfo_msg("ERROR - REF table could not be found in the catalog");
135  }
136  }
137  else
138  {
139  sinfo_msg("ERROR - could not load the catalog");
140  }
141  }
142  }
143  }
144  else
145  {
146  sinfo_msg("REF frame is found");
147  check_nomsg(name=cpl_frame_get_filename(frm_ref));
148  check_nomsg(*pptable=cpl_table_load(name,1,0));
149  }
150  return;
151  cleanup:
152  return;
153 }
154 
155 
156 
157 
158 /*---------------------------------------------------------------------------*/
169 /*---------------------------------------------------------------------------*/
170 
171 static void
172 sinfo_parse_catalog_std_stars(cpl_frame* cat,
173  double dRA,
174  double dDEC,
175  double EPSILON,
176  cpl_table** pptable)
177 {
178  const char* name = NULL;
179 
180  if (cat) {
181  check_nomsg(name=cpl_frame_get_filename(cat));
182  if (name) {
183  star_index* pstarindex = star_index_load(name);
184  if (pstarindex) {
185  const char* star_name = 0;
186  sinfo_msg("The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]", dRA, dDEC, EPSILON);
187  *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name);
188  if (*pptable && star_name) {
189  sinfo_msg("REF table is found in the catalog, star name is [%s]", star_name);
190  }
191  else {
192  sinfo_msg("ERROR - REF table could not be found in the catalog");
193  }
194  }
195  else {
196  sinfo_msg("ERROR - could not load the catalog");
197  }
198 
199  }
200  }
201 
202  cleanup:
203  return;
204 }
205 
206 
207 
208 
209 /*---------------------------------------------------------------------------*/
218 /*---------------------------------------------------------------------------*/
219 
220 
221 double
222 sinfo_data_interpolate(
223  double wav,
224  int nrow,
225  double* pw,
226  double* pe
227  )
228 {
229  double y = 0;
230  double w1=pw[0];
231  double w2=pw[nrow-1];
232  double y1_=pe[0]; /*was changed from y1 to y1_ due a warning from compiler - shadowed variable*/
233  double y2=pe[nrow-1];
234  if(wav < pw[0])
235  {
236  w1=pw[0];
237  w2=pw[1];
238  y1_=pe[0];
239  y2=pe[1];
240  }
241  else if (wav > pw[nrow - 1])
242  {
243  w1=pw[nrow - 2];
244  w2=pw[nrow - 1];
245  y1_=pe[nrow - 2];
246  y2=pe[nrow - 1];
247  }
248  else
249  {
250  int l = 0;
251  int h = nrow - 1;
252  int curr_row = 0;
253  curr_row = (h-l) / 2;
254  while( h-l >1 )
255  {
256  if(wav < pw[curr_row])
257  {
258  h = curr_row;
259  }
260  else
261  {
262  l = curr_row;
263  }
264  curr_row = (h-l) / 2 + l;
265  }
266  w1=pw[curr_row];
267  w2=pw[curr_row + 1];
268  y1_=pe[curr_row];
269  y2=pe[curr_row + 1];
270  }
271  y=y1_+(y2-y1_)/(w2-w1)*(wav-w1);
272  return y;
273 }
274 static double
275 sinfo_table_interpolate(cpl_table* tbl,
276  double wav,
277  const char* colx,
278  const char* coly)
279 {
280 
281  double y=0;
282  double* pe=NULL;
283  double* pw=NULL;
284  int nrow=0;
285 
286  check_nomsg(pw=cpl_table_get_data_double(tbl,colx));
287  check_nomsg(pe=cpl_table_get_data_double(tbl,coly));
288  check_nomsg(nrow=cpl_table_get_nrow(tbl));
289 
290  y = sinfo_data_interpolate(wav, nrow, pw, pe);
291  cleanup:
292  return y;
293 
294 }
295 
296 static double*
297 sinfo_create_column_double(cpl_table* tbl, const char* col_name, int nrow)
298 {
299  double* retval = 0;
300  check_nomsg(cpl_table_new_column(tbl, col_name, CPL_TYPE_DOUBLE));
301  check_nomsg(cpl_table_fill_column_window_double(tbl, col_name, 0, nrow, -1));
302  check_nomsg(retval = cpl_table_get_data_double(tbl,col_name));
303  return retval;
304  cleanup:
305  return retval;
306 }
307 
308 
309 /*---------------------------------------------------------------------------*/
319 /*---------------------------------------------------------------------------*/
320 
321 cpl_error_code
322 sinfo_get_std_obs_values(cpl_propertylist* plist,
323  double* exptime,
324  double* airmass,
325  double* dRA,
326  double* dDEC)
327 {
328  double airmass_start=0;
329  double airmass_end=0;
330 
331  check_nomsg(*exptime=sinfo_pfits_get_exp_time(plist));
332  airmass_start=sinfo_pfits_get_airmass_start(plist);
333  airmass_end=sinfo_pfits_get_airmass_end(plist);
334  *dRA=sinfo_pfits_get_ra(plist);
335  *dDEC=sinfo_pfits_get_dec(plist);
336  *airmass=0.5*(airmass_start+airmass_end);
337 
338  cleanup:
339  return cpl_error_get_code();
340 
341 }
342 
343 /*---------------------------------------------------------------------------*/
360 /*---------------------------------------------------------------------------*/
361 /* TODO: not used */
362 cpl_table*
363 sinfo_utl_efficiency(
364  cpl_frameset * frames,
365  double dGain,
366  double dEpsilon,
367  double aimprim,
368  const char* col_name_atm_wave,
369  const char* col_name_atm_abs,
370  const char* col_name_ref_wave,
371  const char* col_name_ref_flux,
372  const char* col_name_ref_bin,
373  const char* col_name_obj_wave,
374  const char* col_name_obj_flux
375  )
376 {
377  cpl_frame* frm_sci = NULL;
378  cpl_frame* frm_atmext = NULL;
379  cpl_table* tbl_obj_spectrum = NULL; // input table with spectrum
380  cpl_table* tbl_atmext = NULL;
381  double exptime = 600;
382 
383  cpl_propertylist* plist = NULL;
384  cpl_table* tbl_ref = NULL;
385  cpl_table* tbl_result=NULL;
386 
387  const char* name=NULL;
388  double dRA = 0;
389  double dDEC = 0;
390 
391  double airmass=0;
392  const double mk2AA=1E4; /* mkm/AA */
393 
394 
395  // read all input data and call the internal function
396  // read the input tables
397  // 1. observation
398  check_nomsg(frm_sci=cpl_frameset_find(frames, FRM_RAW_IMA_SLIT));
399  check_nomsg(name=cpl_frame_get_filename(frm_sci));
400  sinfo_msg("name=%s",name);
401  check_nomsg(tbl_obj_spectrum=cpl_table_load(name,1,0));
402  check_nomsg(plist=cpl_propertylist_load(name,0));
403 
404  sinfo_get_std_obs_values(plist,&exptime,&airmass,&dRA,&dDEC);
405 
406  // 2. reference table
407  sinfo_load_ref_table(frames, dRA, dDEC, dEpsilon, &tbl_ref);
408  if (tbl_ref)
409  {
410  // 3. atmext
411  check_nomsg(frm_atmext=cpl_frameset_find(frames,FRM_EXTCOEFF_TAB));
412  check_nomsg(name=cpl_frame_get_filename(frm_atmext));
413  check_nomsg(tbl_atmext=cpl_table_load(name,1,0));
414 
415  tbl_result = sinfo_utl_efficiency_internal(
416  tbl_obj_spectrum,
417  tbl_atmext,
418  tbl_ref,
419  exptime,
420  airmass,
421  aimprim,
422  dGain,
423  1,
424  mk2AA,//valid only for SINFONI
425  col_name_atm_wave,
426  col_name_atm_abs,
427  col_name_ref_wave,
428  col_name_ref_flux,
429  col_name_ref_bin,
430  col_name_obj_wave,
431  col_name_obj_flux
432  );
433  }
434 
435  cleanup:
436  sinfo_free_propertylist(&plist);
437  sinfo_free_table(&tbl_atmext);
438  sinfo_free_table(&tbl_obj_spectrum);
439  sinfo_free_table(&tbl_ref);
440  return tbl_result;
441 }
442 static int
443 sinfo_column_to_double(cpl_table* ptable, const char* column)
444 {
445  const char* TEMP = "_temp_";
446  check_nomsg(cpl_table_duplicate_column(ptable, TEMP, ptable, column));
447  check_nomsg(cpl_table_erase_column(ptable, column));
448  check_nomsg(cpl_table_cast_column(ptable, TEMP, column, CPL_TYPE_DOUBLE));
449  check_nomsg(cpl_table_erase_column(ptable, TEMP ));
450  return 0;
451  cleanup:
452  sinfo_msg(" error column to double [%s]", column);
453  return -1;
454 }
455 
456 
457 /*---------------------------------------------------------------------------*/
478 /*---------------------------------------------------------------------------*/
479 /* TODO: not used */
480 cpl_table*
481 sinfo_utl_efficiency_internal(
482  cpl_table* tbl_obj_spectrum,
483  cpl_table* tbl_atmext,
484  cpl_table* tbl_ref,
485  double exptime,
486  double airmass,
487  double aimprim,
488  double gain,
489  int biny,
490  double src2ref_wave_sampling,
491  const char* col_name_atm_wave,
492  const char* col_name_atm_abs,
493  const char* col_name_ref_wave,
494  const char* col_name_ref_flux,
495  const char* col_name_ref_bin,
496  const char* col_name_obj_wave,
497  const char* col_name_obj_flux
498  )
499 {
500 
501  const double TEL_AREA = 51.2e4; /* collecting area in cm2 */
502  double cdelta1 = 0;
503  int i = 0;
504  cpl_table* tbl_sel = NULL;
505 
506  /* structure of the input table
507  * col type description
508  * wavelength double
509  * flux double
510  * */
511  cpl_table* tbl_result = NULL; // output table
512 
513  /*
514  * structure of the output table
515  * col type description
516  * wavelength double
517  * EFF double efficiency in range 0-1
518  * */
519 
520  double* pref = NULL;
521  double* pext = NULL;
522  double* pcor = NULL;
523  double* peph = NULL;
524 
525  double* pw = NULL; // wavelength of the input table
526  /* double* pf = NULL; // flux of the input table */
527  int nrow = 0;
528  double ref_bin_size=0;
529 
530  nrow = cpl_table_get_nrow(tbl_obj_spectrum);
531  sinfo_msg("Starting efficiency calculation: exptime[%f] airmass[%f] nrow[%d]",
532  exptime, airmass, nrow);
533 
534  //cpl_table_dump(tbl_obj_spectrum,0,3,stdout);
535  //sinfo_msg("col wave=%s col_flux=%s",col_name_obj_wave,col_name_obj_flux);
536 
537  /* convert to double */
538  sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_wave);
539  sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_flux);
540 
541  check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_wave ));
542  check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_abs ));
543  check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_wave ));
544  check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_flux ));
545  check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_bin ));
546 
547  /* get bin size of ref STD star spectrum */
548  ref_bin_size=cpl_table_get_double(tbl_ref,col_name_ref_bin,0,NULL);
549  sinfo_msg("ref_bin_size[AA]=%g",ref_bin_size);
550  /*
551  sinfo_msg("Unit conversion factor src/ref STD spectrum=%g",
552  src2ref_wave_sampling);
553  */
554 
555  /* convert obj spectrum wave unit to the same of the reference one */
556  check_nomsg(cpl_table_multiply_scalar(tbl_obj_spectrum,col_name_obj_wave,
557  src2ref_wave_sampling));
558 
559  check_nomsg(cpl_table_save(tbl_ref,NULL,NULL,"ref2.fits",CPL_IO_DEFAULT));
560  check_nomsg(cpl_table_save(tbl_atmext,NULL,NULL,"atm2.fits",CPL_IO_DEFAULT));
561  check_nomsg(cpl_table_save(tbl_obj_spectrum,NULL,NULL,"sci2.fits",CPL_IO_DEFAULT));
562  sinfo_msg("object 2 src std %g",src2ref_wave_sampling);
563  check_nomsg(pw=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_wave));
564  /* check_nomsg(pf=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_flux)); */
565 
566  // prepare columns for the output data
567  check_nomsg(tbl_result=cpl_table_new(nrow));
568  check_nomsg(pref=sinfo_create_column_double(tbl_result, COL_NAME_REF, nrow));
569  check_nomsg(pext=sinfo_create_column_double(tbl_result, COL_NAME_EXT, nrow));
570  check_nomsg(pcor=sinfo_create_column_double(tbl_result, COL_NAME_COR, nrow));
571  check_nomsg(peph=sinfo_create_column_double(tbl_result, COL_NAME_EPHOT, nrow));
572  sinfo_msg("wave range: [%g,%g]",pw[0],pw[nrow-1]);
573  sinfo_msg("src_bin_size[AA]=%g",pw[1] - pw[0]);
574 
575  cdelta1 = (pw[1] - pw[0]) / src2ref_wave_sampling ; /* we want the delta in original units. As we rescaled to AA we need to correct for this */
576  //sinfo_msg("nrow=%d cdelta1=%g",nrow,cdelta1);
577  for (i = 0; i < nrow; i++)
578  {
579  check_nomsg(pext[i] = sinfo_table_interpolate(tbl_atmext, pw[i],col_name_atm_wave, col_name_atm_abs));
580  check_nomsg(pref[i] = sinfo_table_interpolate(tbl_ref, pw[i], col_name_ref_wave,col_name_ref_flux));
581  pcor[i] = pow(10,(0.4*pext[i] * (aimprim - airmass)));
582  peph[i] = 1.e7*1.986e-19/(pw[i]*1e-4);
583  /* ph energy: 1.986*10^-19(J.ph^-1)/lam(um) ==>
584  in as pw is expressed in Angstrom units we need to multiply by 10-4
585  */
586  /*
587  if(i< 2) {
588  sinfo_msg("pw[i]=%g,pcor=%g peph=%g",pw[i],pcor[i],peph[i]);
589  }
590  */
591  }
592 
593 
594  /*
595  sinfo_msg("atm: %s, %s ref: %s, %s obj: %s, %s",
596  col_name_atm_wave,col_name_atm_abs,
597  col_name_ref_wave,col_name_ref_flux,
598  col_name_obj_wave,col_name_obj_flux);
599  */
600  check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_COR,
601  tbl_obj_spectrum, col_name_obj_flux));
602  check_nomsg(cpl_table_duplicate_column(tbl_result,col_name_obj_wave,
603  tbl_obj_spectrum,col_name_obj_wave));
604  /* correct for atmospheric extintion */
605  check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_COR,COL_NAME_COR));
606 
607  /* correct object flux by binning:
608  divides by binsize in ref_wave_sampling (usually AA):
609  cdelt1[src_sampling]*src2ref_wave_sampling */
610  cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, src2ref_wave_sampling);
611 
612  cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, cdelta1);
613  /* correct for spatial bin size */
614 
615  cpl_table_divide_scalar(tbl_result,COL_NAME_SRC_COR,biny);
616 
617 
618  /*correct ref std star flux by binning:
619  divides by the bin size in ref_wave_sampling (usually AA) */
620  check_nomsg(cpl_table_divide_scalar(tbl_result,COL_NAME_REF,ref_bin_size));
621 
622  check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_EFF,
623  tbl_result,COL_NAME_SRC_COR));
624 
625 
626  /* correct for detector gain, exposure time, telescope area */
627  check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF,
628  gain / (exptime * TEL_AREA)));
629 
630  /* correct for photon energy */
631  check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_EFF,
632  COL_NAME_EPHOT));
633 
634 
635  check_nomsg(cpl_table_divide_columns(tbl_result,COL_NAME_SRC_EFF,COL_NAME_REF));
636  /* apply factor 1.e16 as reference catalog has fluxes in units of 1e-16 */
637  check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF,1.e16));
638  //check_nomsg(cpl_table_save(tbl_result,NULL,NULL,"pippo.fits", CPL_IO_DEFAULT));
639  /* clean from outliers */
640  cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF,
641  CPL_GREATER_THAN,1.e-5);
642  cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF,
643  CPL_LESS_THAN,100.);
644  tbl_sel=cpl_table_extract_selected(tbl_result);
645  check_nomsg(cpl_table_save(tbl_result,NULL,NULL,"result9.fits",CPL_IO_DEFAULT));
646 
647  cleanup:
648  sinfo_free_table(&tbl_result);
649  return tbl_sel;
650 }
651 
652 /* TODO: not used */
653 cpl_table*
654 sinfo_efficiency_compute(cpl_frame* frm_sci,
655  cpl_frame* frm_cat,
656  cpl_frame* frm_atmext)
657 
658 {
659 
660  cpl_propertylist* plist=NULL;
661 
662  cpl_table* tbl_eff=NULL;
663  cpl_table* tbl_ref=NULL;
664  cpl_table* tbl_atmext=NULL;
665  cpl_table* tbl_sci=NULL;
666 
667  double exptime=600;
668  double airmass=0;
669  double airmass_start=0;
670  double airmass_end=0;
671  double dRA=0;
672  double dDEC=0;
673  double gain=0;
674  double aimprim=0;
675  double dEpsilon=0.1;
676  double um2AA=1.e4;
677 
678  /* int nrow=0; */
679  int biny=1;
680 
681  const char* name_sci=NULL;
682  const char* name_atm=NULL;
683 
684  name_sci=cpl_frame_get_filename(frm_sci);
685  sinfo_msg("name_sci=%s",name_sci);
686  check_nomsg(plist=cpl_propertylist_load(name_sci,0));
687  check_nomsg(tbl_sci=cpl_table_load(name_sci,1,0));
688  check_nomsg(dRA=sinfo_pfits_get_ra(plist));
689  dDEC=sinfo_pfits_get_dec(plist);
690  airmass_start=sinfo_pfits_get_airmass_end(plist);
691  airmass_end=sinfo_pfits_get_airmass_end(plist);
692  airmass=0.5*(airmass_start+airmass_end);
693  gain=2.42;
694  biny=1;
695  check_nomsg(exptime=sinfo_pfits_get_dit(plist));
696  sinfo_free_propertylist(&plist);
697  sinfo_msg("gain=%g airm=%g exptime=%g airmass=%g ra=%g dec=%g",
698  gain,airmass,exptime,airmass,dRA,dDEC);
699 
700  sinfo_msg("table sci spectra=%s",name_sci);
701  /* nrow=cpl_table_get_nrow(tbl_sci); */
702 
703  check_nomsg(name_atm=cpl_frame_get_filename(frm_atmext));
704  check_nomsg(tbl_atmext=cpl_table_load(name_atm,1,0));
705 
706  check_nomsg(sinfo_parse_catalog_std_stars(frm_cat,dRA,dDEC,dEpsilon,&tbl_ref));
707 
708  if(tbl_ref == NULL) {
709  sinfo_msg_error("Provide std sar catalog frame");
710  return NULL;
711  //cpl_table_dump(tbl_ref,0,3,stdout);
712  }
713 
714  check_nomsg(cpl_table_save(tbl_sci,NULL,NULL,"sci.fits",CPL_IO_DEFAULT));
715  check_nomsg(tbl_eff=sinfo_utl_efficiency_internal(tbl_sci,tbl_atmext,tbl_ref,
716  exptime,airmass,aimprim,gain,
717  biny,um2AA,
718  "LAMBDA",
719  "LA_SILLA",
720  "LAMBDA",
721  "F_LAMBDA",
722  "BIN_WIDTH",
723  "wavelength",
724  "counts_bkg"));
725 
726  cleanup:
727  sinfo_free_table(&tbl_ref);
728  sinfo_free_table(&tbl_atmext);
729  sinfo_free_propertylist(&plist);
730 
731  return tbl_eff;
732 
733 }
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69