KMOS Pipeline Reference Manual 4.5.10
kmos_gen_telluric.c
1/*
2 * This file is part of the KMOS Pipeline
3 * Copyright (C) 2002,2003 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, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 * Includes
26 *----------------------------------------------------------------------------*/
27
28#include <string.h>
29#include <math.h>
30
31#include <cpl.h>
32
33#include "kmclipm_priv_splines.h"
34#include "kmclipm_functions.h"
35#include "kmclipm_constants.h"
36
37#include "kmo_utils.h"
38#include "kmos_pfits.h"
39#include "kmo_dfs.h"
40
41/*-----------------------------------------------------------------------------
42 * Functions prototypes
43 *----------------------------------------------------------------------------*/
44
45static cpl_vector * kmos_gen_telluric_resample(
46 cpl_vector * vec,
47 int b_samples,
48 double crval1,
49 double cdelt1,
50 double * new_crval1,
51 double * new_cdelt1) ;
52static int kmos_gen_telluric_get_avg_zpoint(
53 const cpl_frame * zp_frame,
54 double * zp1_avg,
55 double * zp2_avg,
56 double * zp3_avg) ;
57static int kmos_gen_telluric_create_file_multiply(
58 const cpl_frame * data1_frame,
59 const cpl_frame * data2_frame,
60 const cpl_frame * zp_frame,
61 const char * filename,
62 cpl_frameset * allframes,
63 int b_samples,
64 const cpl_parameterlist * parlist) ;
65static int kmos_gen_telluric_create_file_simple(
66 const cpl_frame * data_frame,
67 const cpl_frame * zp_frame,
68 const cpl_frame * resp_frame,
69 const cpl_frame * mh_frame,
70 const char * filename,
71 cpl_frameset * allframes,
72 int b_samples,
73 int fill_empty_ifus,
74 const cpl_parameterlist * parlist) ;
75
76static int kmos_gen_telluric_check_inputs(cpl_frameset *, int);
77
78static int kmos_gen_telluric_create(cpl_plugin *);
79static int kmos_gen_telluric_exec(cpl_plugin *);
80static int kmos_gen_telluric_destroy(cpl_plugin *);
81static int kmos_gen_telluric(cpl_parameterlist *, cpl_frameset *);
82
83/*-----------------------------------------------------------------------------
84 * Static variables
85 *----------------------------------------------------------------------------*/
86
87static char kmos_gen_telluric_description[] =
88"This recipe creates the TELLURIC frame needed by kmos_sci_red by merging\n"
89"the TELLURIC (produced by kmos_std_star), the static RESPONŠ…E frame and \n"
90"the TELLURIC_CORR (produced with molecfit).\n"
91"The way the frames are combined is controlled by the --method parameter:\n"
92" - 0 (default) : use TELLURIC and get zpoint from TELLURIC\n"
93" If TELLURIC missing, use RESPONSE and get zpoint from RESPONSE\n"
94" - 1 : use TELLURIC_CORR and get zpoint from TELLURIC_CORR\n"
95" - 2 : use RESPONSE and get zpoint from TELLURIC\n"
96" If TELLURIC missing, get zpoint from RESPONSE\n"
97" For missing ZPOINTs, use the average of other IFUs for the \n"
98" same detector. \n"
99" - 3 : use RESPONSE x TELLURIC_CORR and get zpoint from TELLURIC_CORR\n"
100"\n"
101"----------------------------------------------------------------------------\n"
102"Input files:\n"
103"\n"
104" DO category Explanation Required \n"
105" ----------- ----------- -------- \n"
106" TELLURIC Produced by kmos_std_star N\n"
107" TELLURIC_CORR Produced by molecfit N\n"
108" RESPONSE static calibration N\n"
109"\n"
110"Output files:\n"
111"\n"
112" DO category Explanation\n"
113" ----------- -----------\n"
114" TELLURIC_GEN Used by kmos_sci_red\n"
115"----------------------------------------------------------------------------\n"
116"\n";
117
118/*-----------------------------------------------------------------------------
119 * Functions code
120 *----------------------------------------------------------------------------*/
121
128/*----------------------------------------------------------------------------*/
137/*----------------------------------------------------------------------------*/
138int cpl_plugin_get_info(cpl_pluginlist *list)
139{
140 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
141 cpl_plugin *plugin = &recipe->interface;
142
143 cpl_plugin_init(plugin,
144 CPL_PLUGIN_API,
145 KMOS_BINARY_VERSION,
146 CPL_PLUGIN_TYPE_RECIPE,
147 "kmos_gen_telluric",
148 "Generate a TELLURIC frame",
149 kmos_gen_telluric_description,
150 "Yves Jung",
151 "https://support.eso.org/",
152 kmos_get_license(),
153 kmos_gen_telluric_create,
154 kmos_gen_telluric_exec,
155 kmos_gen_telluric_destroy);
156 cpl_pluginlist_append(list, plugin);
157
158 return 0;
159}
160
161/*----------------------------------------------------------------------------*/
169/*----------------------------------------------------------------------------*/
170static int kmos_gen_telluric_create(cpl_plugin *plugin)
171{
172 cpl_recipe *recipe;
173 cpl_parameter *p;
174
175 // Check that the plugin is part of a valid recipe
176 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
177 recipe = (cpl_recipe *)plugin;
178 else
179 return -1;
180
181 // Create the parameters list in the cpl_recipe object
182 recipe->parameters = cpl_parameterlist_new();
183
184 // Fill the parameters list
185 /* --method */
186 p = cpl_parameter_new_value("kmos.kmos_gen_telluric.method",
187 CPL_TYPE_INT, "How the TELLURIC is generated",
188 "kmos.kmos_gen_telluric", 0);
189 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "method");
190 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
191 cpl_parameterlist_append(recipe->parameters, p);
192
193 /* --b_samples */
194 p = cpl_parameter_new_value("kmos.kmos_gen_telluric.b_samples",
195 CPL_TYPE_INT, "The number of samples in wavelength",
196 "kmos.kmos_gen_telluric", -1);
197 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "b_samples");
198 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
199 cpl_parameterlist_append(recipe->parameters, p);
200
201 /* --fill_empty_ifus */
202 p = cpl_parameter_new_value("kmos.kmos_gen_telluric.fill_empty_ifus",
203 CPL_TYPE_BOOL, "Flag to fill empty TELLURIC IFUs (only method 0)",
204 "kmos.kmos_gen_telluric", FALSE);
205 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "fill_empty_ifus");
206 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
207 cpl_parameterlist_append(recipe->parameters, p);
208
209 return 0;
210}
211
212/*----------------------------------------------------------------------------*/
218/*----------------------------------------------------------------------------*/
219static int kmos_gen_telluric_exec(cpl_plugin *plugin)
220{
221 cpl_recipe *recipe;
222
223 // Get the recipe out of the plugin
224 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
225 recipe = (cpl_recipe *)plugin;
226 else return -1;
227
228 return kmos_gen_telluric(recipe->parameters, recipe->frames);
229}
230
231/*----------------------------------------------------------------------------*/
237/*----------------------------------------------------------------------------*/
238static int kmos_gen_telluric_destroy(cpl_plugin *plugin)
239{
240 cpl_recipe *recipe;
241
242 // Get the recipe out of the plugin
243 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
244 recipe = (cpl_recipe *)plugin;
245 else return -1 ;
246
247 cpl_parameterlist_delete(recipe->parameters);
248 return 0 ;
249}
250
251/*----------------------------------------------------------------------------*/
258/*----------------------------------------------------------------------------*/
259static int kmos_gen_telluric(cpl_parameterlist *parlist, cpl_frameset *frameset)
260{
261 const cpl_parameter * par ;
262 int method, fill_empty_ifus, b_samples ;
263 cpl_frame * tell_frame ;
264 cpl_frame * tell_corr_frame ;
265 cpl_frame * resp_frame ;
266 const char * fn ;
267
268 /* Check initial Entries */
269 if (kmos_check_and_set_groups(frameset) != CPL_ERROR_NONE) {
270 return cpl_error_get_code();
271 }
272
273 /* Initialise */
274 fn = "kmos_gen_telluric.fits" ;
275
276 /* Get Parameters */
277 par = cpl_parameterlist_find_const(parlist,"kmos.kmos_gen_telluric.method");
278 method = cpl_parameter_get_int(par);
279 par = cpl_parameterlist_find_const(parlist,
280 "kmos.kmos_gen_telluric.b_samples");
281 b_samples = cpl_parameter_get_int(par);
282 par = cpl_parameterlist_find_const(parlist,
283 "kmos.kmos_gen_telluric.fill_empty_ifus");
284 fill_empty_ifus = cpl_parameter_get_bool(par);
285
286 /* Check Parameters */
287 if (method != 0 && fill_empty_ifus != 0) {
288 fill_empty_ifus = 0 ;
289 cpl_msg_warning(__func__,
290 "Filling empty IFUs is only possible in method 0 - disable it");
291 }
292
293 /* Check the inputs consistency */
294 if (kmos_gen_telluric_check_inputs(frameset, method) != 1) {
295 cpl_msg_error(__func__, "Input frameset / parameter is unconsistent") ;
296 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
297 return -1 ;
298 }
299
300 /* Get frames */
301 tell_frame = cpl_frameset_find(frameset, TELLURIC) ;
302 resp_frame = cpl_frameset_find(frameset, RESPONSE) ;
303 tell_corr_frame = cpl_frameset_find(frameset, TELLURIC_CORR) ;
304
305 /* Switch on the methods */
306 if (method == 0) {
307 if (tell_frame != NULL) {
308 cpl_msg_info(__func__, "Use %s for Data and Zpoint",
309 cpl_frame_get_filename(tell_frame)) ;
310 kmos_gen_telluric_create_file_simple(tell_frame, tell_frame, resp_frame,
311 tell_frame, fn, frameset, b_samples,
312 fill_empty_ifus, parlist) ;
313 } else {
314 cpl_msg_info(__func__, "Use %s for Data and Zpoint",
315 cpl_frame_get_filename(resp_frame)) ;
316 kmos_gen_telluric_create_file_simple(resp_frame, resp_frame, NULL,
317 resp_frame, fn, frameset, b_samples, 0, parlist) ;
318 }
319 } else if (method == 1) {
320 cpl_msg_info(__func__, "Use %s for Data and Zpoint",
321 cpl_frame_get_filename(tell_corr_frame)) ;
322 kmos_gen_telluric_create_file_simple(tell_corr_frame, NULL, NULL,
323 tell_corr_frame, fn, frameset, b_samples, 0, parlist) ;
324 } else if (method == 2) {
325 if (tell_frame != NULL) {
326 cpl_msg_info(__func__, "Use %s for Data and %s for Zpoint",
327 cpl_frame_get_filename(resp_frame),
328 cpl_frame_get_filename(tell_frame)) ;
329 /* kmos_gen_telluric_create_file_simple(resp_frame, tell_frame, NULL,
330 resp_frame, fn, frameset, b_samples, 0, parlist) ; */
331 kmos_gen_telluric_create_file_simple(resp_frame, tell_frame, NULL,
332 tell_frame, fn, frameset, b_samples, 0, parlist) ;
333 } else {
334 cpl_msg_info(__func__, "Use %s for Data and Zpoint",
335 cpl_frame_get_filename(resp_frame)) ;
336 kmos_gen_telluric_create_file_simple(resp_frame, NULL, NULL,
337 resp_frame, fn, frameset, b_samples, 0, parlist) ;
338 }
339 } else if (method == 3) {
340 cpl_msg_info(__func__, "Use %s X %s for Data and %s for Zpoint",
341 cpl_frame_get_filename(resp_frame),
342 cpl_frame_get_filename(tell_corr_frame),
343 cpl_frame_get_filename(tell_corr_frame)) ;
344 kmos_gen_telluric_create_file_multiply(resp_frame, tell_corr_frame,
345 tell_corr_frame, fn, frameset, b_samples, parlist) ;
346 } else {
347 cpl_msg_error(__func__, "Unsupported - Should never come here") ;
348 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_INPUT) ;
349 return -1 ;
350 }
351 return 0;
352}
353
356static int kmos_gen_telluric_create_file_multiply(
357 const cpl_frame * data1_frame,
358 const cpl_frame * data2_frame,
359 const cpl_frame * zp_frame,
360 const char * filename,
361 cpl_frameset * allframes,
362 int b_samples,
363 const cpl_parameterlist * parlist)
364{
365 cpl_propertylist * mh ;
366 cpl_propertylist * applist ;
367 cpl_propertylist * eh ;
368 cpl_propertylist * zph ;
369 cpl_vector * vec1 ;
370 cpl_vector * vec2 ;
371 cpl_vector * vec_resampled ;
372 double zpoint, crval1, cdelt1, new_crval1, new_cdelt1 ;
373 enum kmo_frame_type ft ;
374 char content[256] ;
375 const char * extname ;
376 char * keyword ;
377 int i, ext_nb, id, ifu_nr ;
378 cpl_vector * zpt_list;
379 cpl_vector ** vec3;
380 cpl_propertylist ** eh_list ;
381
382 /* Initialise */
383 id = -1 ;
384 ft = illegal_frame ;
385
386 /* Get Extensions number */
387 ext_nb = cpl_fits_count_extensions(cpl_frame_get_filename(data1_frame)) ;
388
389 if (cpl_fits_count_extensions(cpl_frame_get_filename(data2_frame))!=ext_nb){
390 cpl_msg_error(__func__, "Extensions numbers do not match - abort") ;
391 return -1 ;
392 }
393
394 zpt_list = cpl_vector_new(ext_nb);
395 vec3 = (cpl_vector**)cpl_calloc(ext_nb, sizeof(cpl_vector*));
396 eh_list = (cpl_propertylist**)cpl_calloc(ext_nb, sizeof(cpl_propertylist*));
397
398 /* Create applist with PRO CATG */
399 applist = cpl_propertylist_new() ;
400 cpl_propertylist_update_string(applist, CPL_DFS_PRO_CATG, TELLURIC_GEN) ;
401
402 /* Create PRO_STD keywords */
403 for (i = 0; i < ext_nb ; i++) {
404 /* Load extension header */
405 eh = cpl_propertylist_load(cpl_frame_get_filename(data2_frame),i+1);
406 /* Read EXTNAME */
407 extname = cpl_propertylist_get_string(eh, "EXTNAME") ;
408 kmo_extname_extractor(extname, &ft, &ifu_nr, content) ;
409 cpl_propertylist_delete(eh);
410 /* Load the data */
411 vec1 = cpl_vector_load(cpl_frame_get_filename(data2_frame), i+1) ;
412 vec2 = cpl_vector_load(cpl_frame_get_filename(data1_frame), i+1) ;
413 if (vec1 != NULL) {
414 cpl_vector_delete(vec1) ;
415
416 /* The Telluric is present in this IFU - write the keyword */
417 keyword = cpl_sprintf("%s%d", PRO_STD, ifu_nr);
418 cpl_propertylist_update_int(applist, keyword, 1);
419 cpl_free(keyword);
420 } else {
421 cpl_error_reset() ;
422 }
423
424 }
425
426 /* Load main header */
427 mh = cpl_propertylist_load(cpl_frame_get_filename(data2_frame), 0);
428
429 /* Loop on the extensions */
430 for (i = 0; i < ext_nb ; i++) {
431
432 /* Load extension header */
433 eh = cpl_propertylist_load(cpl_frame_get_filename(data1_frame),i+1);
434
435 /* Read EXTNAME */
436 extname = cpl_propertylist_get_string(eh, "EXTNAME") ;
437 kmo_extname_extractor(extname, &ft, &id, content) ;
438
439 /* Load the data */
440 vec1 = cpl_vector_load(cpl_frame_get_filename(data1_frame), i+1) ;
441 vec2 = cpl_vector_load(cpl_frame_get_filename(data2_frame), i+1) ;
442 if (vec1 == NULL || vec2 == NULL) cpl_error_reset() ;
443
444 /* Resample vec1 if needed */
445 if (vec1 != NULL &&
446 cpl_vector_get_size(vec1) != b_samples && b_samples > 0) {
447
448 /* Get crval1, cdelt1 */
449 cdelt1 = kmos_pfits_get_cdelt1(eh) ;
450 crval1 = kmos_pfits_get_crval1(eh) ;
451
452 /* Recreate vec */
453 vec_resampled = kmos_gen_telluric_resample(vec1, b_samples, crval1,
454 cdelt1, &new_crval1, &new_cdelt1) ;
455 if (vec_resampled != NULL) {
456 cpl_vector_delete(vec1) ;
457 vec1 = vec_resampled ;
458
459 /* Update CRVAL1 / CDELT1 in eh */
460 cpl_propertylist_update_double(eh, "CRVAL1", new_crval1) ;
461 cpl_propertylist_update_double(eh, "CDELT1", new_cdelt1) ;
462 }
463 }
464
465 /* Resample vec2 if needed */
466 if (vec1 != NULL && vec2 != NULL &&
467 cpl_vector_get_size(vec1) != cpl_vector_get_size(vec2)) {
468
469 /* Get crval1, cdelt1 */
470 cdelt1 = kmos_pfits_get_cdelt1(eh) ;
471 crval1 = kmos_pfits_get_crval1(eh) ;
472
473 /* Recreate vec */
474 vec_resampled = kmos_gen_telluric_resample(vec2, b_samples, crval1,
475 cdelt1, &new_crval1, &new_cdelt1) ;
476 if (vec_resampled != NULL) {
477 cpl_vector_delete(vec2) ;
478 vec2 = vec_resampled ;
479 }
480 }
481
482 /* Need to update ZPOINT ? */
483 if (vec1 != NULL && vec2 != NULL && zp_frame != NULL) {
484 zph=cpl_propertylist_load(cpl_frame_get_filename(zp_frame),i+1);
485 zpoint = cpl_propertylist_get_double(zph, "ESO QC ZPOINT");
486 cpl_propertylist_delete(zph);
487 if (cpl_error_get_code() != CPL_ERROR_NONE) {
488 cpl_msg_warning(__func__, "No QC ZPOINT found in %s",
489 cpl_frame_get_filename(zp_frame)) ;
490 cpl_error_reset() ;
491 cpl_vector_set(zpt_list, i, 0.0); // CHECK IF THIS IS CORRECT ~!!!!!!!!!!!!!!!!!!!!!!!!!!!
492 } else {
493 cpl_propertylist_update_double(eh, "ESO QC ZPOINT", zpoint) ;
494 cpl_vector_set(zpt_list, i, zpoint);
495 }
496 }
497
498 /* Multiply the 2 vectors if Data */
499 if (!strcmp(content, "DATA")) cpl_vector_multiply(vec1, vec2) ;
500 cpl_vector_delete(vec2) ;
501
502 vec3[i]=vec1;
503 eh_list[i] = eh;
504
505// /* Save the Extension */
506// if (cpl_error_get_code() == CPL_ERROR_NONE) {
507// /* Save the data */
508// cpl_vector_save(vec3[ext_nb], filename, CPL_TYPE_DOUBLE, eh_list[ext_nb],CPL_IO_EXTEND) ;
509// } else {
510// /* Only the header */
511// cpl_error_reset() ;
512// cpl_propertylist_save(eh_list[ext_nb], filename, CPL_IO_EXTEND) ;
513// }
514 cpl_vector_delete(vec1) ;
515 cpl_propertylist_delete(eh);
516 }
517
518 kmclipm_update_property_double(applist, QC_ZPOINT_AVG, cpl_vector_get_mean(zpt_list), "Avg of Zeropoint values ") ;
519 kmclipm_update_property_double(applist, QC_ZPOINT_RMS, cpl_vector_get_stdev(zpt_list), "RMS of Zeropoint values") ;
520
521
522 if(cpl_propertylist_has(mh,"ESO OBS PROG ID")){
523 const char *prog_id= cpl_propertylist_get_string(mh, "ESO OBS PROG ID");
524
525 if (strcmp(prog_id, "60.A-9452(A)") && strcmp(prog_id, "60.A-9254(A)")) {
526 kmclipm_update_property_int(applist, QC_FLAG_OB, 1, "Obs Flag") ;
527 }
528 else {
529 kmclipm_update_property_int(applist, QC_FLAG_OB, 0, "Obs Flag" ) ;
530 }
531 } else {
532 kmclipm_update_property_int(applist, QC_FLAG_OB, 1, "Obs Flag" ) ;
533 }
534 if(cpl_propertylist_has(mh,QC_NR_STD_STARS)){
535 kmclipm_update_property_int(applist, QC_NR_STD_STARS,
536 cpl_propertylist_get_int(mh, QC_NR_STD_STARS), "Nr. of std stars") ;
537 } else {
538 kmclipm_update_property_int(applist, QC_NR_STD_STARS,0, "Nr. of std stars") ;
539 }
540
541 /* Save product */
542 cpl_dfs_save_propertylist(allframes, mh, parlist, allframes, NULL,
543 "kmos_gen_telluric", applist, NULL, PACKAGE "/" PACKAGE_VERSION,
544 filename) ;
545
546 cpl_propertylist_delete(mh);
547 cpl_propertylist_delete(applist);
548
549 /* Loop on the extensions */
550 for (i = 0; i < ext_nb ; i++) {
551
552 /* Save the Extension */
553 if (cpl_error_get_code() == CPL_ERROR_NONE) {
554 /* Save the data */
555 cpl_vector_save(vec3[i], filename, CPL_TYPE_DOUBLE, eh_list[ext_nb],CPL_IO_EXTEND) ;
556 } else {
557 /* Only the header */
558 cpl_error_reset() ;
559 cpl_propertylist_save(eh_list[i], filename, CPL_IO_EXTEND) ;
560 }
561 }
562
563 for (i = 0; i < ext_nb ; i++) {
564 cpl_vector_delete(vec3[i]);
565 cpl_propertylist_delete(eh_list[i]);
566 }
567
568 return 0 ;
569}
570
571static int kmos_gen_telluric_create_file_simple(
572 const cpl_frame * data_frame,
573 const cpl_frame * zp_frame,
574 const cpl_frame * resp_frame,
575 const cpl_frame * mh_frame,
576 const char * filename,
577 cpl_frameset * allframes,
578 int b_samples,
579 int fill_empty_ifus,
580 const cpl_parameterlist * parlist)
581{
582 cpl_propertylist * mh ;
583 cpl_propertylist * applist ;
584 cpl_propertylist * eh ;
585 cpl_propertylist * tmp_eh ;
586 cpl_propertylist * zph ;
587 cpl_vector * vec ;
588 cpl_vector * vec_ref ;
589 cpl_vector * resp_ref ;
590 cpl_vector * resp_cur ;
591 cpl_vector * vec_resampled ;
592 double zpoint, zpoint_vec_ref, zpoint_resp_ref,
593 zpoint_resp_cur, zp1_avg, zp2_avg, zp3_avg,
594 cdelt1, crval1, new_crval1, new_cdelt1;
595 int i, ext_nb, id, det_nr, ifu_nr, first_data_det1,
596 first_data_det2, first_data_det3,
597 first_noise_det1, first_noise_det2,
598 first_noise_det3, ref_ifu, nvals ;
599 enum kmo_frame_type ft ;
600 char content[256] ;
601 char * keyword ;
602 const char * extname ;
603 cpl_vector * zpt_list;
604 cpl_vector ** vec1;
605 cpl_propertylist ** eh_list;
606
607 /* Initialise */
608 zp1_avg = zp2_avg = zp3_avg = -1.0 ;
609 id = -1 ;
610 ft = illegal_frame ;
611 first_data_det1 = first_data_det2 = first_data_det3 = -1 ;
612 first_noise_det1 = first_noise_det2 = first_noise_det3 = -1 ;
613
614 /* Get Extensions number */
615 ext_nb = cpl_fits_count_extensions(cpl_frame_get_filename(data_frame)) ;
616
617 zpt_list = cpl_vector_new(ext_nb);
618 vec1 = (cpl_vector**)cpl_calloc(ext_nb, sizeof(cpl_vector*));
619 eh_list = (cpl_propertylist**)cpl_calloc(ext_nb, sizeof(cpl_propertylist*));
620
621 /* Create applist with PRO CATG */
622 applist = cpl_propertylist_new() ;
623 cpl_propertylist_update_string(applist, CPL_DFS_PRO_CATG, TELLURIC_GEN) ;
624
625 /* Create PRO_STD keywords */
626 for (i = 0; i < ext_nb ; i++) {
627 /* Load extension header */
628 eh = cpl_propertylist_load(cpl_frame_get_filename(data_frame), i+1);
629 /* Read EXTNAME */
630 extname = cpl_propertylist_get_string(eh, "EXTNAME") ;
631
632 kmo_extname_extractor(extname, &ft, &ifu_nr, content) ;
633 cpl_propertylist_delete(eh);
634
635 /* Get Detector */
636 if (ifu_nr >= 1 && ifu_nr <= 8) det_nr = 1 ;
637 else if (ifu_nr >= 9 && ifu_nr <= 16) det_nr = 2 ;
638 else if (ifu_nr >= 17 && ifu_nr <= 24) det_nr = 3 ;
639 else {
640 cpl_msg_error(__func__, "Cannot Identify the detector") ;
641 cpl_propertylist_delete(applist);
642 return -1 ;
643 }
644
645 /* Try to load the data */
646 vec = cpl_vector_load(cpl_frame_get_filename(data_frame), i+1) ;
647 if (vec == NULL) cpl_error_reset() ;
648
649 /* Store the first non-null extensions per detector */
650 if (vec != NULL) {
651 if (!strcmp(content, "DATA")) {
652 if (det_nr == 1 && first_data_det1 < 0) first_data_det1 = i+1 ;
653 if (det_nr == 2 && first_data_det2 < 0) first_data_det2 = i+1 ;
654 if (det_nr == 3 && first_data_det3 < 0) first_data_det3 = i+1 ;
655 } else if (!strcmp(content, "NOISE")) {
656 if (det_nr == 1 && first_noise_det1 < 0) first_noise_det1 = i+1;
657 if (det_nr == 2 && first_noise_det2 < 0) first_noise_det2 = i+1;
658 if (det_nr == 3 && first_noise_det3 < 0) first_noise_det3 = i+1;
659 }
660 }
661
662 if (vec != NULL || fill_empty_ifus == 1) {
663 if (vec != NULL) cpl_vector_delete(vec) ;
664
665 /* The Telluric is present in this IFU - write the keyword */
666 keyword = cpl_sprintf("%s%d", PRO_STD, ifu_nr);
667 cpl_propertylist_update_int(applist, keyword, 1);
668 cpl_free(keyword);
669 } else {
670 cpl_error_reset() ;
671 }
672 }
673
674 /* Load main header */
675 mh = cpl_propertylist_load(cpl_frame_get_filename(mh_frame), 0);
676
677 cpl_msg_info(__func__, "BEFORE SAVE BEFORE SAVING %s ", cpl_frame_get_filename(mh_frame)) ;
678
679 /* Get ZPOINT averages per detector from the Zp_frame */
680 if (zp_frame != NULL) {
681 kmos_gen_telluric_get_avg_zpoint(zp_frame,&zp1_avg,&zp2_avg,&zp3_avg) ;
682 }
683
684 /* Loop on the extensions */
685 for (i = 0; i < ext_nb ; i++) {
686
687 /* Load extension header */
688 eh = cpl_propertylist_load(cpl_frame_get_filename(data_frame), i+1);
689
690 /* Read EXTNAME */
691 extname = cpl_propertylist_get_string(eh, "EXTNAME") ;
692 kmo_extname_extractor(extname, &ft, &id, content) ;
693
694 if (id >= 1 && id <= 8) det_nr = 1 ;
695 else if (id >= 9 && id <= 16) det_nr = 2 ;
696 else if (id >= 17 && id <= 24) det_nr = 3 ;
697 else {
698 cpl_msg_error(__func__, "Cannot Identify the detector") ;
699 cpl_propertylist_delete(eh);
700 return -1 ;
701 }
702
703 /* Load the data */
704 vec = cpl_vector_load(cpl_frame_get_filename(data_frame), i+1) ;
705 if (vec == NULL) cpl_error_reset() ;
706
707 /* Recover vec if requested */
708 if (vec == NULL && fill_empty_ifus == 1) {
709
710 /* Initialise */
711 vec_ref = NULL ;
712 ref_ifu = -1 ;
713 if (!strcmp(content, "NOISE")) {
714 /* Get ref_ifu */
715 if (det_nr==1) ref_ifu = first_noise_det1 ;
716 if (det_nr==2) ref_ifu = first_noise_det2 ;
717 if (det_nr==3) ref_ifu = first_noise_det3 ;
718
719 /* Load noise reference */
720 vec_ref=cpl_vector_load(cpl_frame_get_filename(data_frame),
721 ref_ifu);
722
723 } else if (!strcmp(content, "DATA")) {
724
725 /* Get ref_ifu */
726 if (det_nr==1) ref_ifu = first_data_det1 ;
727 if (det_nr==2) ref_ifu = first_data_det2 ;
728 if (det_nr==3) ref_ifu = first_data_det3 ;
729
730 /* Load data reference */
731 vec_ref=cpl_vector_load(cpl_frame_get_filename(data_frame),
732 ref_ifu);
733
734 resp_ref = cpl_vector_load(cpl_frame_get_filename(resp_frame),
735 ref_ifu) ;
736 resp_cur = cpl_vector_load(cpl_frame_get_filename(resp_frame),
737 i+1) ;
738
739 if (resp_ref != NULL && resp_cur != NULL) {
740 /* Resample resp_ref if needed */
741 if (cpl_vector_get_size(vec_ref) !=
742 cpl_vector_get_size(resp_ref)) {
743
744 /* Get crval1, cdelt1 from the resp_ref_ifu */
745 tmp_eh = cpl_propertylist_load(
746 cpl_frame_get_filename(resp_frame), ref_ifu);
747 cdelt1 = kmos_pfits_get_cdelt1(tmp_eh) ;
748 crval1 = kmos_pfits_get_crval1(tmp_eh) ;
749 cpl_propertylist_delete(tmp_eh) ;
750
751 /* Resample */
752 vec_resampled = kmos_gen_telluric_resample(resp_ref,
753 cpl_vector_get_size(vec_ref), crval1, cdelt1,
754 &new_crval1, &new_cdelt1) ;
755 if (vec_resampled != NULL) {
756 cpl_vector_delete(resp_ref) ;
757 resp_ref = vec_resampled ;
758 }
759 }
760
761 /* Resample resp_cur if needed */
762 if (cpl_vector_get_size(vec_ref) !=
763 cpl_vector_get_size(resp_cur)) {
764
765 /* Get crval1, cdelt1 from the resp_cur_ifu */
766 tmp_eh = cpl_propertylist_load(
767 cpl_frame_get_filename(resp_frame), i+1);
768 cdelt1 = kmos_pfits_get_cdelt1(tmp_eh) ;
769 crval1 = kmos_pfits_get_crval1(tmp_eh) ;
770 cpl_propertylist_delete(tmp_eh) ;
771
772 /* Resample */
773 vec_resampled = kmos_gen_telluric_resample(resp_cur,
774 cpl_vector_get_size(vec_ref), crval1, cdelt1,
775 &new_crval1, &new_cdelt1) ;
776 if (vec_resampled != NULL) {
777 cpl_vector_delete(resp_ref) ;
778 resp_ref = vec_resampled ;
779 }
780 }
781 cpl_vector_divide(vec_ref, resp_ref);
782 cpl_vector_multiply(vec_ref, resp_cur);
783 }
784 if (resp_ref != NULL) cpl_vector_delete(resp_ref) ;
785 if (resp_cur != NULL) cpl_vector_delete(resp_cur) ;
786 }
787 vec = vec_ref ;
788
789 /* Get crval1, cdelt1 from the ref_ifu */
790 tmp_eh = cpl_propertylist_load(
791 cpl_frame_get_filename(data_frame), ref_ifu);
792
793 cpl_propertylist_copy_property(eh, tmp_eh, "CTYPE1") ;
794 cpl_propertylist_copy_property(eh, tmp_eh, "CRPIX1") ;
795 cpl_propertylist_copy_property(eh, tmp_eh, "CRVAL1") ;
796 cpl_propertylist_copy_property(eh, tmp_eh, "CDELT1") ;
797 cpl_propertylist_delete(tmp_eh) ;
798 cpl_propertylist_erase(eh, "CRPIX2") ;
799 cpl_propertylist_erase(eh, "CTYPE2") ;
800 cpl_propertylist_erase(eh, "CD1_1") ;
801 cpl_propertylist_erase(eh, "CD1_2") ;
802 cpl_propertylist_erase(eh, "CD2_1") ;
803 cpl_propertylist_erase(eh, "CD2_2") ;
804
805 /* Compute ZPOINT */
806 tmp_eh = cpl_propertylist_load(
807 cpl_frame_get_filename(data_frame), ref_ifu);
808 zpoint_vec_ref = cpl_propertylist_get_double(tmp_eh,
809 "ESO QC ZPOINT");
810 cpl_propertylist_delete(tmp_eh) ;
811 tmp_eh = cpl_propertylist_load(
812 cpl_frame_get_filename(resp_frame), ref_ifu);
813 zpoint_resp_ref = cpl_propertylist_get_double(tmp_eh,
814 "ESO QC ZPOINT");
815 cpl_propertylist_delete(tmp_eh) ;
816 tmp_eh = cpl_propertylist_load(
817 cpl_frame_get_filename(resp_frame), i+1);
818 zpoint_resp_cur = cpl_propertylist_get_double(tmp_eh,
819 "ESO QC ZPOINT");
820 cpl_propertylist_delete(tmp_eh) ;
821 /* Compute new ZPOINT */
822 zpoint = zpoint_vec_ref - zpoint_resp_ref + zpoint_resp_cur ;
823 cpl_propertylist_update_double(eh, "ESO QC ZPOINT", zpoint) ;
824 }
825
826 /* Need to update ZPOINT ? */
827 if (vec != NULL && zp_frame != NULL) {
828 zph = cpl_propertylist_load(cpl_frame_get_filename(zp_frame),i+1);
829 zpoint = cpl_propertylist_get_double(zph, "ESO QC ZPOINT");
830 cpl_propertylist_delete(zph);
831 if (cpl_error_get_code() != CPL_ERROR_NONE) {
832 cpl_error_reset() ;
833 if (det_nr == 1) zpoint = zp1_avg ;
834 else if (det_nr == 2) zpoint = zp2_avg ;
835 else zpoint = zp3_avg ;
836
837 /* If No Zpoint is availlable, use the other detectors */
838 if (zpoint < 0) {
839 zpoint = 0.0 ;
840 if (zp1_avg > 0.0) {
841 zpoint += zp1_avg ;
842 nvals++ ;
843 }
844 if (zp2_avg > 0.0) {
845 zpoint += zp2_avg ;
846 nvals++ ;
847 }
848 if (zp3_avg > 0.0) {
849 zpoint += zp3_avg ;
850 nvals++ ;
851 }
852 if (nvals == 0) zpoint = -1.0 ;
853 else zpoint /= nvals ;
854 cpl_msg_warning(__func__,
855 "No QC ZPOINT in %s[%d] - Use average of other Dets: %g",
856 cpl_frame_get_filename(zp_frame), i+1, zpoint) ;
857 } else {
858 cpl_msg_warning(__func__,
859 "No QC ZPOINT in %s[%d] - Use average for Det %d: %g",
860 cpl_frame_get_filename(zp_frame), i+1, det_nr, zpoint) ;
861 }
862 }
863 cpl_propertylist_update_double(eh, "ESO QC ZPOINT", zpoint) ;
864 cpl_vector_set(zpt_list, i, zpoint);
865 }
866
867 /* Resample vec if needed */
868 if (vec != NULL &&
869 cpl_vector_get_size(vec) != b_samples && b_samples > 0) {
870
871 /* Get crval1, cdelt1 */
872 cdelt1 = kmos_pfits_get_cdelt1(eh) ;
873 crval1 = kmos_pfits_get_crval1(eh) ;
874
875 /* Recreate vec */
876 vec_resampled = kmos_gen_telluric_resample(vec, b_samples, crval1,
877 cdelt1, &new_crval1, &new_cdelt1) ;
878 if (vec_resampled != NULL) {
879 cpl_vector_delete(vec) ;
880 vec = vec_resampled ;
881
882 /* Update CRVAL1 / CDELT1 in eh */
883 cpl_propertylist_update_double(eh, "CRVAL1", new_crval1) ;
884 cpl_propertylist_update_double(eh, "CDELT1", new_cdelt1) ;
885 }
886 }
887
888 /* Fix eh */
889 cpl_propertylist_erase(eh, CDELT1);
890 cpl_propertylist_erase(eh, CDELT2);
891 cpl_propertylist_erase(eh, CDELT3);
892 cpl_propertylist_erase(eh, CRVAL3);
893 cpl_propertylist_erase(eh, CRPIX3);
894 cpl_propertylist_erase(eh, CTYPE3);
895
896
897 //cpl_msg_info(__func__, "saving vector list") ;
898 vec1[i] = vec;
899 //cpl_msg_info(__func__, "vector lists saved ") ;
900 eh_list[i] = eh;
901 //cpl_msg_info(__func__, "property lists saved ") ;
902
903 //cpl_vector_delete(vec) ;
904 //cpl_propertylist_delete(eh);
905 }
906
907
908 kmclipm_update_property_double(applist, QC_ZPOINT_AVG, cpl_vector_get_mean(zpt_list), "Avg of Zeropoint values ") ;
909 kmclipm_update_property_double(applist, QC_ZPOINT_RMS, cpl_vector_get_stdev(zpt_list), "RMS of Zeropoint values") ;
910
911
912 if(cpl_propertylist_has(mh,"ESO OBS PROG ID")){
913 const char *prog_id= cpl_propertylist_get_string(mh, "ESO OBS PROG ID");
914
915 if (strcmp(prog_id, "60.A-9452(A)") && strcmp(prog_id, "60.A-9254(A)")) {
916 kmclipm_update_property_int(applist, QC_FLAG_OB, 1, "Obs Flag") ;
917 }
918 else {
919 kmclipm_update_property_int(applist, QC_FLAG_OB, 0, "Obs Flag" ) ;
920 }
921 } else {
922 kmclipm_update_property_int(applist, QC_FLAG_OB, 1, "Obs Flag" ) ;
923 }
924
925
926 if(cpl_propertylist_has(mh,QC_NR_STD_STARS)){
927 kmclipm_update_property_int(applist, QC_NR_STD_STARS,
928 cpl_propertylist_get_int(mh, QC_NR_STD_STARS), "Nr. of std stars") ;
929 } else {
930 kmclipm_update_property_int(applist, QC_NR_STD_STARS,0, "Nr. of std stars") ;
931 }
932
933
934 cpl_msg_info(__func__, "zpoint values saved in main header") ;
935
936
937 /* Save product */
938 cpl_dfs_save_propertylist(allframes, mh, parlist, allframes, zp_frame,
939 "kmos_gen_telluric", applist, NULL, PACKAGE "/" PACKAGE_VERSION,
940 filename) ;
941 cpl_msg_info(__func__, "main header saved ") ;
942
943 cpl_propertylist_delete(mh);
944 cpl_propertylist_delete(applist);
945
946 cpl_msg_info(__func__, "starting to save sub headers ") ;
947
948 for (i = 0; i < ext_nb ; i++) {
949 /* Save the Extension */
950 if (vec1[i] != NULL) {
951 /* Save the data */
952 cpl_vector_save(vec1[i], filename, CPL_TYPE_DOUBLE, eh_list[i], CPL_IO_EXTEND) ;
953 //cpl_msg_info(__func__, "subheader %d saved ",i) ;
954
955 } else {
956 /* Only the header */
957 cpl_propertylist_erase(eh_list[i], CTYPE1);
958 cpl_propertylist_erase(eh_list[i], CTYPE2);
959 cpl_propertylist_erase(eh_list[i], CRPIX1);
960 cpl_propertylist_erase(eh_list[i], CRPIX2);
961 cpl_propertylist_erase(eh_list[i], CRVAL1);
962 cpl_propertylist_erase(eh_list[i], CRVAL2);
963 cpl_propertylist_erase(eh_list[i], CD1_1);
964 cpl_propertylist_erase(eh_list[i], CD1_2);
965 cpl_propertylist_erase(eh_list[i], CD2_1);
966 cpl_propertylist_erase(eh_list[i], CD2_2);
967 cpl_propertylist_save(eh_list[i], filename, CPL_IO_EXTEND) ;
968 }
969 }
970
971 cpl_msg_info(__func__, "subheaders saved ") ;
972
973 //cpl_vector_delete(vec) ;
974 //cpl_propertylist_delete(eh);
975
976 for (i = 0; i < ext_nb ; i++) {
977 cpl_vector_delete(vec1[i]);
978 cpl_propertylist_delete(eh_list[i]);
979 }
980
981 return 0 ;
982}
983/*----------------------------------------------------------------------------*/
994/*----------------------------------------------------------------------------*/
995static cpl_vector * kmos_gen_telluric_resample(
996 cpl_vector * vec,
997 int b_samples,
998 double crval1,
999 double cdelt1,
1000 double * new_crval1,
1001 double * new_cdelt1)
1002{
1003 cpl_bivector * fold ;
1004 cpl_bivector * fnew ;
1005 cpl_vector * old_x ;
1006 cpl_vector * new_x ;
1007 cpl_vector * new_y ;
1008 int vec_size ;
1009 cpl_error_code err;
1010 double current_lambda ;
1011 int i, j ;
1012
1013 /* Check entries */
1014 if (vec == NULL || new_crval1 == NULL || new_cdelt1 == NULL) return NULL;
1015
1016 /* Initialise */
1017 vec_size = cpl_vector_get_size(vec) ;
1018
1019 /* No resample needed */
1020 if (b_samples == vec_size) {
1021 *new_crval1 = crval1 ;
1022 *new_cdelt1 = cdelt1 ;
1023 return cpl_vector_duplicate(vec) ;
1024 }
1025
1026 /* Prepare data */
1027 *new_crval1 = crval1 ;
1028 *new_cdelt1 = cdelt1 * vec_size / b_samples ;
1029
1030 /* Fill the old lambda */
1031 old_x = cpl_vector_new(vec_size) ;
1032 for (i=0 ; i<vec_size ; i++) {
1033 cpl_vector_set(old_x, i, crval1 + i*cdelt1) ;
1034 }
1035
1036 /* Fill the new lambda */
1037 new_x = cpl_vector_new(b_samples) ;
1038 new_y = cpl_vector_new(b_samples) ;
1039 for (i=0 ; i<b_samples ; i++) {
1040 cpl_vector_set(new_x, i, *new_crval1 + i*(*new_cdelt1)) ;
1041 }
1042
1043 if (b_samples < vec_size) {
1044 /* Undersampling */
1045 fold = cpl_bivector_wrap_vectors(old_x, (cpl_vector *)vec) ;
1046 fnew = cpl_bivector_wrap_vectors(new_x, new_y) ;
1047
1048 /* Resample */
1049 err = cpl_bivector_interpolate_linear(fnew, fold) ;
1050
1051 /* Unwrap */
1052 cpl_bivector_unwrap_vectors(fold) ;
1053 cpl_bivector_unwrap_vectors(fnew) ;
1054
1055 if (err != CPL_ERROR_NONE) {
1056 cpl_msg_error(__func__, "Cannot Resample") ;
1057 cpl_vector_delete(old_x) ;
1058 cpl_vector_delete(new_x) ;
1059 cpl_vector_delete(new_y) ;
1060 return NULL ;
1061 }
1062 } else {
1063 /* Oversampling */
1064 for (i=0 ; i<b_samples ; i++) {
1065 /* Current wavelength */
1066 current_lambda = cpl_vector_get(new_x, i) ;
1067 /* Find j : index of this wl in the old vector */
1068 for (j=0 ; j<vec_size-1 ; j++) {
1069 if (cpl_vector_get(old_x, j) > current_lambda) break ;
1070 }
1071 cpl_vector_set(new_y, i, cpl_vector_get(vec, j)) ;
1072 }
1073 }
1074 cpl_vector_delete(old_x) ;
1075 cpl_vector_delete(new_x) ;
1076 return new_y ;
1077}
1078
1079/*----------------------------------------------------------------------------*/
1088/*----------------------------------------------------------------------------*/
1089static int kmos_gen_telluric_get_avg_zpoint(
1090 const cpl_frame * zp_frame,
1091 double * zp1_avg,
1092 double * zp2_avg,
1093 double * zp3_avg)
1094{
1095 double zp1_avg_loc, zp2_avg_loc, zp3_avg_loc, zpoint ; ;
1096 int zp1_nb, zp2_nb, zp3_nb, ext_nb, id, det_nr, i;
1097 cpl_propertylist * eh ;
1098 const char * extname ;
1099 enum kmo_frame_type ft ;
1100 char content[256] ;
1101
1102 /* Check entries */
1103 if (zp_frame==NULL || zp1_avg==NULL || zp2_avg==NULL || zp3_avg==NULL)
1104 return -1 ;
1105
1106 /* Initialise */
1107 *zp1_avg = *zp2_avg = *zp3_avg = -1.0 ;
1108 zp1_nb = zp2_nb = zp3_nb = 0 ;
1109 zp1_avg_loc = zp2_avg_loc = zp3_avg_loc = 0.0 ;
1110 id = -1 ;
1111 ft = illegal_frame ;
1112
1113 /* Get Extensions number */
1114 ext_nb = cpl_fits_count_extensions(cpl_frame_get_filename(zp_frame)) ;
1115
1116 /* Loop on the extensions */
1117 for (i = 0; i < ext_nb ; i++) {
1118 /* Load extension header */
1119 eh = cpl_propertylist_load(cpl_frame_get_filename(zp_frame), i+1);
1120
1121 /* Read EXTNAME */
1122 extname = cpl_propertylist_get_string(eh, "EXTNAME") ;
1123 kmo_extname_extractor(extname, &ft, &id, content) ;
1124
1125 /* Is Data ? */
1126 if (!strcmp(content, "DATA")) {
1127 /* Read ZPOINT */
1128 zpoint = cpl_propertylist_get_double(eh, "ESO QC ZPOINT");
1129
1130 /* ZPOINT is there ? */
1131 if (cpl_error_get_code() == CPL_ERROR_NONE) {
1132 /* Get the detector Nr */
1133 if (id >= 1 && id <= 8) det_nr = 1 ;
1134 else if (id >= 9 && id <= 16) det_nr = 2 ;
1135 else if (id >= 17 && id <= 24) det_nr = 3 ;
1136 else {
1137 cpl_msg_error(__func__, "Cannot Identify the detector") ;
1138 cpl_propertylist_delete(eh);
1139 return -1 ;
1140 }
1141
1142 if (det_nr == 1) {
1143 zp1_avg_loc += zpoint ;
1144 zp1_nb ++ ;
1145 } else if (det_nr == 2) {
1146 zp2_avg_loc += zpoint ;
1147 zp2_nb ++ ;
1148 } else if (det_nr == 3) {
1149 zp3_avg_loc += zpoint ;
1150 zp3_nb ++ ;
1151 } else {
1152 cpl_msg_error(__func__, "Cannot Identify the detector") ;
1153 cpl_propertylist_delete(eh);
1154 return -1 ;
1155 }
1156 } else {
1157 cpl_error_reset() ;
1158 }
1159 }
1160 cpl_propertylist_delete(eh);
1161 }
1162
1163 /* Divide by the number */
1164 if (zp1_nb > 0) *zp1_avg = zp1_avg_loc / zp1_nb ;
1165 if (zp2_nb > 0) *zp2_avg = zp2_avg_loc / zp2_nb ;
1166 if (zp3_nb > 0) *zp3_avg = zp3_avg_loc / zp3_nb ;
1167 return 0 ;
1168}
1169
1170/*----------------------------------------------------------------------------*/
1177/*----------------------------------------------------------------------------*/
1178static int kmos_gen_telluric_check_inputs(
1179 cpl_frameset * frameset,
1180 int method)
1181{
1182 cpl_frame * tell_frame ;
1183 cpl_frame * tell_corr_frame ;
1184 cpl_frame * resp_frame ;
1185
1186 /* Check Entries */
1187 if (frameset == NULL) return -1;
1188 if (method < 0 || method > 3) return -1 ;
1189
1190 tell_frame = cpl_frameset_find(frameset, TELLURIC) ;
1191 resp_frame = cpl_frameset_find(frameset, RESPONSE) ;
1192 tell_corr_frame = cpl_frameset_find(frameset, TELLURIC_CORR) ;
1193
1194 if (method == 0 && tell_frame == NULL && resp_frame == NULL)
1195 return 0 ;
1196 if (method == 1 && tell_corr_frame == NULL)
1197 return 0 ;
1198 if (method == 2 && resp_frame == NULL)
1199 return 0 ;
1200 if (method == 3 && (resp_frame == NULL || tell_corr_frame == NULL))
1201 return 0 ;
1202 return 1 ;
1203}
1204
1205
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.