33#include "kmo_priv_arithmetic.h"
34#include "kmo_constants.h"
36#define FORBIDDEN_SCALAR -99999.9
38static int kmo_arithmetic_create(cpl_plugin *);
39static int kmo_arithmetic_exec(cpl_plugin *);
40static int kmo_arithmetic_destroy(cpl_plugin *);
41static int kmo_arithmetic(cpl_parameterlist *, cpl_frameset *);
43static char kmo_arithmetic_description[] =
44"With this recipe simple arithmetic operations, like addition, subtraction,\n"
45"multiplication, divison and raising to a power can be performed.\n"
46"Since FITS files formatted as F1I, F2I and F3I can contain data (and eventually\n"
47"noise) of either just one IFU or of all 24 IFUs, kmo_arithmetic behaves diffe-\n"
48"rently in these cases.\n"
49"When the number of IFUs is the same for both operands, the first IFU of the\n"
50"first operand is processed with the first IFU of the second operand.\n"
51"When the second operand has only one IFU while the first operand has more IFUs,\n"
52"then the all the IFUs of the first operand are processed individually which the\n"
53"IFU of the second operand.\n"
54"If an operand contains noise and the other doesn't, the noise will not be\n"
57"Noise is only propagated if both operand contain noise extensions. If the\n"
58"second operator is a scalar noise is also propagated, of course.\n"
60"If two cubes are given as operands, they will be combined according to the \n"
61"given operator.If a cube is given as first operand and an image as second,\n"
62"then it operates on each slice of the cube; similarly if a spectrum is given\n"
63"as the second operand, it operates on each spectrum of the cube; and a number\n"
64"as the second operand operates on each pixel of the cube.\n"
69"Any of the following operations to perform: '+', '-', '*' or '/' (also '^' \n"
70"when the 2nd operand is a scalar\n"
73"To be provided if a frame should be processed together with a scalar\n"
76"Define a string to append to the product filename ARITHMETIC in order to get\n"
79"-------------------------------------------------------------------------------\n"
83" category Type Explanation Required #Frames\n"
84" -------- ----- ----------- -------- -------\n"
85" <none or any> F3I or Data with or Y 1 \n"
86" F2I or without noise frame \n"
90" <none or any> F3I or Data with or N 0,1 \n"
91" F2I or without noise frame \n"
99" category Type Explanation\n"
100" -------- ----- -----------\n"
101" ARITHMETIC F3I or \n"
105"-------------------------------------------------------------------------------\n"
126 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
127 cpl_plugin *plugin = &recipe->interface;
129 cpl_plugin_init(plugin,
132 CPL_PLUGIN_TYPE_RECIPE,
134 "Perform basic arithmetic on cubes",
135 kmo_arithmetic_description,
137 "https://support.eso.org/",
139 kmo_arithmetic_create,
141 kmo_arithmetic_destroy);
143 cpl_pluginlist_append(list, plugin);
155static int kmo_arithmetic_create(cpl_plugin *plugin)
161 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
162 recipe = (cpl_recipe *)plugin;
167 recipe->parameters = cpl_parameterlist_new();
171 p = cpl_parameter_new_value(
"kmos.kmo_arithmetic.operator",
173 "The operator ('+', '-', '*', '/' or '^')",
174 "kmos.kmo_arithmetic",
176 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"operator");
177 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
178 cpl_parameterlist_append(recipe->parameters, p);
181 p = cpl_parameter_new_value(
"kmos.kmo_arithmetic.scalar",
183 "The scalar operand",
184 "kmos.kmo_arithmetic",
186 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"scalar");
187 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
188 cpl_parameterlist_append(recipe->parameters, p);
191 p = cpl_parameter_new_value(
"kmos.kmo_arithmetic.file_extension",
193 "String to add to product filename.",
194 "kmos.kmo_arithmetic",
196 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"file_extension");
197 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
198 cpl_parameterlist_append(recipe->parameters, p);
208static int kmo_arithmetic_exec(cpl_plugin *plugin)
213 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
214 recipe = (cpl_recipe *)plugin;
217 return kmo_arithmetic(recipe->parameters, recipe->frames);
225static int kmo_arithmetic_destroy(cpl_plugin *plugin)
230 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
231 recipe = (cpl_recipe *)plugin;
234 cpl_parameterlist_delete(recipe->parameters);
252static int kmo_arithmetic(cpl_parameterlist *parlist, cpl_frameset *frameset)
254 const char *op = NULL,
255 *file_extension = NULL;
257 cpl_imagelist *op1_3d = NULL,
259 *op1_noise_3d = NULL,
260 *op2_noise_3d = NULL;
261 cpl_image *op1_2d = NULL,
263 *op1_noise_2d = NULL,
264 *op2_noise_2d = NULL;
265 kmclipm_vector *op1_1d = NULL,
267 *op1_noise_1d = NULL,
268 *op2_noise_1d = NULL;
269 double op2_scalar = FORBIDDEN_SCALAR;
279 cpl_propertylist *main_header = NULL,
280 *sub_header_data = NULL,
281 *sub_header_noise = NULL;
282 main_fits_desc desc1,
284 cpl_frame *op1_frame = NULL,
289 kmo_init_fits_desc(&desc1);
290 kmo_init_fits_desc(&desc2);
293 KMO_TRY_ASSURE((parlist != NULL) &&
295 CPL_ERROR_NULL_INPUT,
296 "Not all input data is provided!");
298 KMO_TRY_ASSURE(kmo_dfs_set_groups(frameset) == 1,
299 CPL_ERROR_ILLEGAL_INPUT,
300 "Cannot identify RAW and CALIB frames!");
302 cpl_msg_info(
"",
"--- Parameter setup for kmo_arithmetic ----");
304 op2_scalar = kmo_dfs_get_parameter_double(parlist,
305 "kmos.kmo_arithmetic.scalar");
306 KMO_TRY_CHECK_ERROR_STATE();
308 KMO_TRY_ASSURE((cpl_frameset_get_size(frameset) == 2) ||
309 ((cpl_frameset_get_size(frameset) == 1) &&
310 (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3)),
311 CPL_ERROR_NULL_INPUT,
312 "Two fits-files or one fits-file and one "
313 "scalar must be provided!");
315 if (cpl_frameset_get_size(frameset) == 1) {
316 KMO_TRY_EXIT_IF_ERROR(
317 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_arithmetic.scalar"));
319 KMO_TRY_EXIT_IF_NULL(
320 op2_frame = kmo_dfs_get_frame(frameset,
"1"));
322 KMO_TRY_EXIT_IF_NULL(
323 op1_frame = kmo_dfs_get_frame(frameset,
"0"));
325 KMO_TRY_EXIT_IF_NULL(
326 op = kmo_dfs_get_parameter_string(parlist,
327 "kmos.kmo_arithmetic.operator"));
328 KMO_TRY_ASSURE((strcmp(op,
"+") == 0) ||
329 (strcmp(op,
"-") == 0) ||
330 (strcmp(op,
"*") == 0) ||
331 (strcmp(op,
"/") == 0) ||
332 (strcmp(op,
"^") == 0),
333 CPL_ERROR_ILLEGAL_INPUT,
334 "Operator not valid! Has it been provided?");
336 KMO_TRY_EXIT_IF_ERROR(
337 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_arithmetic.operator"));
339 file_extension = kmo_dfs_get_parameter_string(parlist,
340 "kmos.kmo_arithmetic.file_extension");
341 KMO_TRY_CHECK_ERROR_STATE();
343 KMO_TRY_EXIT_IF_ERROR(
344 kmo_dfs_print_parameter_help(parlist,
"kmos.kmo_arithmetic.file_extension"));
346 cpl_msg_info(
"",
"-------------------------------------------");
348 if (strcmp(file_extension,
"") == 0) {
349 fn_out = cpl_sprintf(
"%s", ARITHMETIC);
351 fn_out = cpl_sprintf(
"%s_%s", ARITHMETIC, file_extension);
355 desc1 = kmo_identify_fits_header(
356 cpl_frame_get_filename(op1_frame));
357 KMO_TRY_CHECK_ERROR_STATE_MSG(
"Provided fits file doesn't seem to be "
360 KMO_TRY_ASSURE((desc1.fits_type == f3i_fits) ||
361 (desc1.fits_type == f2i_fits) ||
362 (desc1.fits_type == f1i_fits) ||
363 (desc1.fits_type == f2d_fits) ||
364 (desc1.fits_type == raw_fits),
365 CPL_ERROR_ILLEGAL_INPUT,
366 "First input file hasn't correct data type "
367 "(KMOSTYPE must be F3I, F2I, F1I, F2D or RAW)!");
370 if (fabs(op2_scalar-FORBIDDEN_SCALAR) < 1e-3) {
371 desc2 = kmo_identify_fits_header(
372 cpl_frame_get_filename(op2_frame));
373 KMO_TRY_CHECK_ERROR_STATE_MSG(
"Provided fits file doesn't seem to "
374 "be in KMOS-format!");
376 if (desc1.fits_type == f3i_fits) {
377 KMO_TRY_ASSURE((desc2.fits_type == f3i_fits) ||
378 (desc2.fits_type == f2i_fits)||
379 (desc2.fits_type == f1i_fits),
380 CPL_ERROR_ILLEGAL_INPUT,
381 "For a F3I frame, the 2nd frame must be a "
382 "F3I, F2I or a F1I frame!");
384 if (desc2.fits_type == f3i_fits) {
385 KMO_TRY_ASSURE((desc1.naxis1 == desc2.naxis1) &&
386 (desc1.naxis2 == desc2.naxis2) &&
387 (desc1.naxis3 == desc2.naxis3),
388 CPL_ERROR_INCOMPATIBLE_INPUT,
389 "The dimensions of the two operands do "
391 }
else if (desc2.fits_type == f2i_fits) {
392 KMO_TRY_ASSURE((desc1.naxis1 == desc2.naxis1) &&
393 (desc1.naxis2 == desc2.naxis2),
394 CPL_ERROR_INCOMPATIBLE_INPUT,
395 "The dimensions of the two operands do "
397 }
else if (desc2.fits_type == f1i_fits) {
398 KMO_TRY_ASSURE((desc1.naxis3 == desc2.naxis1),
399 CPL_ERROR_INCOMPATIBLE_INPUT,
400 "The dimensions of the two operands do "
403 }
else if (desc1.fits_type == f2i_fits) {
404 KMO_TRY_ASSURE(desc2.fits_type == f2i_fits,
405 CPL_ERROR_ILLEGAL_INPUT,
406 "For a F2I frame, the 2nd frame must be a "
408 KMO_TRY_ASSURE((desc1.naxis1 == desc2.naxis1) &&
409 (desc1.naxis2 == desc2.naxis2),
410 CPL_ERROR_INCOMPATIBLE_INPUT,
411 "The dimensions of the two operands do "
413 }
else if (desc1.fits_type == f1i_fits) {
414 KMO_TRY_ASSURE(desc2.fits_type == f1i_fits,
415 CPL_ERROR_ILLEGAL_INPUT,
416 "For a F1I frame, the 2nd frame must be a "
418 KMO_TRY_ASSURE(desc1.naxis1 == desc2.naxis1,
419 CPL_ERROR_INCOMPATIBLE_INPUT,
420 "The dimensions of the two operands do "
422 }
else if (desc1.fits_type == f2d_fits) {
423 KMO_TRY_ASSURE((desc2.fits_type == f2d_fits) ||
424 ((desc2.fits_type == raw_fits) && (desc1.ex_noise == FALSE)),
425 CPL_ERROR_ILLEGAL_INPUT,
426 "For a F2D frame, the 2nd frame must be a "
428 KMO_TRY_ASSURE((desc1.naxis1 == desc2.naxis1) &&
429 (desc1.naxis2 == desc2.naxis2),
430 CPL_ERROR_INCOMPATIBLE_INPUT,
431 "The dimensions of the two operands do "
433 }
else if (desc1.fits_type == raw_fits) {
434 KMO_TRY_ASSURE((desc2.fits_type == raw_fits) ||
435 ((desc2.fits_type == f2d_fits) && (desc2.ex_noise == FALSE)),
436 CPL_ERROR_ILLEGAL_INPUT,
437 "For a RAW frame, the 2nd frame must be a "
439 KMO_TRY_ASSURE((desc1.naxis1 == desc2.naxis1) &&
440 (desc1.naxis2 == desc2.naxis2),
441 CPL_ERROR_INCOMPATIBLE_INPUT,
442 "The dimensions of the two operands do "
446 if (((desc2.nr_ext == 1) &&
447 (desc2.sub_desc[0].valid_data == TRUE))
449 ((desc2.nr_ext == 2) &&
450 (desc2.ex_noise == TRUE) &&
451 (desc2.sub_desc[0].valid_data == TRUE) &&
452 (desc2.sub_desc[1].valid_data == TRUE))) {
455 if (desc1.ex_noise == desc2.ex_noise) {
456 KMO_TRY_ASSURE(desc1.nr_ext == desc2.nr_ext,
457 CPL_ERROR_INCOMPATIBLE_INPUT,
458 "The number of IFUs of the two operands do "
461 KMO_TRY_ASSURE(desc1.nr_ext == desc2.nr_ext * 2,
462 CPL_ERROR_INCOMPATIBLE_INPUT,
463 "The number of IFUs of the two operands do "
470 KMO_TRY_EXIT_IF_ERROR(
471 kmo_dfs_save_main_header(frameset, fn_out,
"", op1_frame, NULL,
477 if (desc1.ex_noise == TRUE) {
478 nr_devices = desc1.nr_ext / 2;
480 nr_devices = desc1.nr_ext;
483 if ((single_ifu == TRUE) &&
484 (desc2.sub_desc[0].valid_data == TRUE))
486 switch (desc2.fits_type) {
489 KMO_TRY_EXIT_IF_NULL(
490 op2_3d = kmo_dfs_load_cube(frameset,
"1",
491 desc2.sub_desc[0].device_nr,
494 if ((desc1.ex_noise == TRUE) && (desc2.ex_noise == TRUE)) {
495 KMO_TRY_EXIT_IF_NULL(
496 op2_noise_3d = kmo_dfs_load_cube(frameset,
"1",
497 desc2.sub_desc[0].device_nr,
502 KMO_TRY_EXIT_IF_NULL(
503 op2_2d = kmo_dfs_load_image(frameset,
"1",
504 desc2.sub_desc[0].device_nr,
505 FALSE, FALSE, NULL));
507 if ((desc1.ex_noise == TRUE) && (desc2.ex_noise == TRUE)) {
508 KMO_TRY_EXIT_IF_NULL(
509 op2_noise_2d = kmo_dfs_load_image(frameset,
511 desc2.sub_desc[0].device_nr,
516 KMO_TRY_EXIT_IF_NULL(
517 op2_1d = kmo_dfs_load_vector(frameset,
"1",
518 desc2.sub_desc[0].device_nr,
521 if ((desc1.ex_noise == TRUE) && (desc2.ex_noise == TRUE)) {
522 KMO_TRY_EXIT_IF_NULL(
523 op2_noise_1d = kmo_dfs_load_vector(frameset,
525 desc2.sub_desc[0].device_nr,
534 for (i = 1; i <= nr_devices; i++) {
535 if (desc1.ex_noise == FALSE) {
536 devnr1 = desc1.sub_desc[i - 1].device_nr;
538 devnr1 = desc1.sub_desc[2 * i - 1].device_nr;
541 if (fabs(op2_scalar-FORBIDDEN_SCALAR) < 1e-3) {
542 if (desc2.ex_noise == FALSE) {
543 devnr2 = desc2.sub_desc[i - 1].device_nr;
545 devnr2 = desc2.sub_desc[2 * i - 1].device_nr;
549 KMO_TRY_EXIT_IF_NULL(
550 sub_header_data = kmo_dfs_load_sub_header(frameset,
"0",
553 switch (desc1.fits_type) {
556 KMO_TRY_EXIT_IF_NULL(
557 op1_2d = kmo_dfs_load_image(frameset,
"0", i,
563 if ((desc2.fits_type == raw_fits) ||
564 (desc2.fits_type == f2d_fits))
567 KMO_TRY_EXIT_IF_NULL(
568 op2_2d = kmo_dfs_load_image(frameset,
"1", i,
571 KMO_TRY_EXIT_IF_ERROR(
572 kmo_arithmetic_2D_2D(op1_2d, op2_2d, NULL, NULL, op));
578 else if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
579 KMO_TRY_EXIT_IF_ERROR(
580 kmo_arithmetic_2D_scalar(op1_2d, op2_scalar, NULL,
589 KMO_TRY_EXIT_IF_ERROR(
590 kmo_dfs_save_image(op1_2d, fn_out,
"",
591 sub_header_data, 0./0.));
594 KMO_TRY_EXIT_IF_NULL(
595 op1_2d = kmo_dfs_load_image(frameset,
"0", i,
596 FALSE, FALSE, NULL));
601 if ((desc2.fits_type == f2d_fits) ||
602 (desc2.fits_type == raw_fits))
604 KMO_TRY_EXIT_IF_NULL(
605 op2_2d = kmo_dfs_load_image(frameset,
"1", i,
606 FALSE, FALSE, NULL));
608 if ((desc1.ex_noise == TRUE) &&
609 (desc2.ex_noise == TRUE)) {
610 KMO_TRY_EXIT_IF_NULL(
611 op1_noise_2d = kmo_dfs_load_image(frameset,
612 "0", i, TRUE, FALSE, NULL));
614 KMO_TRY_EXIT_IF_NULL(
615 op2_noise_2d = kmo_dfs_load_image(frameset,
616 "1", i, TRUE, FALSE, NULL));
618 KMO_TRY_EXIT_IF_ERROR(
619 kmo_arithmetic_2D_2D(op1_2d, op2_2d,
620 op1_noise_2d, op2_noise_2d,
627 else if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
629 if (desc1.ex_noise == TRUE) {
630 KMO_TRY_EXIT_IF_NULL(
631 op1_noise_2d = kmo_dfs_load_image(frameset,
632 "0", i, TRUE, FALSE, NULL));
634 KMO_TRY_EXIT_IF_ERROR(
635 kmo_arithmetic_2D_scalar(op1_2d,
642 KMO_TRY_EXIT_IF_ERROR(
643 kmo_dfs_save_image(op1_2d, fn_out,
"",
644 sub_header_data, 0./0.));
646 if (op1_noise_2d != NULL) {
647 KMO_TRY_EXIT_IF_NULL(
648 sub_header_noise = kmo_dfs_load_sub_header(frameset,
650 KMO_TRY_EXIT_IF_ERROR(
651 kmo_dfs_save_image(op1_noise_2d, fn_out,
"",
652 sub_header_noise, 0./0.));
654 cpl_propertylist_delete(sub_header_noise);
655 sub_header_noise = NULL;
662 if (desc1.ex_noise == FALSE) {
663 if (desc1.sub_desc[i - 1].valid_data == TRUE) {
664 if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
666 }
else if (((single_ifu == TRUE) &&
667 (desc2.sub_desc[0].valid_data == TRUE))
669 (desc2.sub_desc[i - 1].valid_data == TRUE))
675 if (desc1.ex_noise == TRUE) {
676 if (desc1.sub_desc[2 * i - 1].valid_data == TRUE) {
680 if ((desc1.ex_noise == TRUE) && (desc2.ex_noise == TRUE)) {
681 if (desc1.sub_desc[2 * i - 1].valid_data == TRUE) {
682 if (((single_ifu == TRUE) &&
683 (desc2.sub_desc[1].valid_data == TRUE))
685 (desc2.sub_desc[2 * i - 1].valid_data == TRUE))
691 if ((single_ifu == TRUE) && (desc1.ex_noise == FALSE)) {
692 if ((desc1.sub_desc[i - 1].valid_data == TRUE) &&
693 (desc2.sub_desc[0].valid_data == TRUE)) {
698 if (calc_f3i == TRUE)
700 KMO_TRY_EXIT_IF_NULL(
701 op1_3d = kmo_dfs_load_cube(frameset,
"0",
706 if (desc2.fits_type == f3i_fits) {
707 if (single_ifu == FALSE) {
708 KMO_TRY_EXIT_IF_NULL(
709 op2_3d = kmo_dfs_load_cube(frameset,
714 if ((desc1.ex_noise == TRUE) &&
715 (desc2.ex_noise == TRUE))
717 KMO_TRY_EXIT_IF_NULL(
718 op1_noise_3d = kmo_dfs_load_cube(frameset,
722 if (single_ifu == FALSE) {
723 KMO_TRY_EXIT_IF_NULL(
724 op2_noise_3d = kmo_dfs_load_cube(
731 KMO_TRY_EXIT_IF_ERROR(
732 kmo_arithmetic_3D_3D(op1_3d, op2_3d,
733 op1_noise_3d, op2_noise_3d,
740 else if (desc2.fits_type == f2i_fits) {
741 if (single_ifu == FALSE) {
742 KMO_TRY_EXIT_IF_NULL(
743 op2_2d = kmo_dfs_load_image(frameset,
745 FALSE, FALSE, NULL));
748 if ((desc1.ex_noise == TRUE) &&
749 (desc2.ex_noise == TRUE))
751 KMO_TRY_EXIT_IF_NULL(
752 op1_noise_3d = kmo_dfs_load_cube(frameset,
756 if (single_ifu == FALSE) {
757 KMO_TRY_EXIT_IF_NULL(
758 op2_noise_2d = kmo_dfs_load_image(
765 KMO_TRY_EXIT_IF_ERROR(
766 kmo_arithmetic_3D_2D(op1_3d, op2_2d,
767 op1_noise_3d, op2_noise_2d,
773 else if (desc2.fits_type == f1i_fits) {
774 if (single_ifu == FALSE) {
775 KMO_TRY_EXIT_IF_NULL(
776 op2_1d = kmo_dfs_load_vector(frameset,
781 if ((desc1.ex_noise == TRUE) &&
782 (desc2.ex_noise == TRUE))
784 KMO_TRY_EXIT_IF_NULL(
785 op1_noise_3d = kmo_dfs_load_cube(frameset,
789 if (single_ifu == FALSE) {
790 KMO_TRY_EXIT_IF_NULL(
791 op2_noise_1d = kmo_dfs_load_vector(
798 KMO_TRY_EXIT_IF_ERROR(
799 kmo_arithmetic_3D_1D(op1_3d, op2_1d,
800 op1_noise_3d, op2_noise_1d,
806 else if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
807 if (desc1.ex_noise == TRUE) {
808 KMO_TRY_EXIT_IF_NULL(
809 op1_noise_3d = kmo_dfs_load_cube(frameset,
814 KMO_TRY_EXIT_IF_ERROR(
815 kmo_arithmetic_3D_scalar(op1_3d,
822 KMO_TRY_EXIT_IF_ERROR(
823 kmo_dfs_save_cube(op1_3d, fn_out,
"",
824 sub_header_data, 0./0.));
826 if (op1_noise_3d != NULL) {
827 KMO_TRY_EXIT_IF_NULL(
828 sub_header_noise = kmo_dfs_load_sub_header(
833 KMO_TRY_EXIT_IF_ERROR(
834 kmo_dfs_save_cube(op1_noise_3d, fn_out,
"",
835 sub_header_noise, 0./0.));
837 cpl_propertylist_delete(sub_header_noise);
838 sub_header_noise = NULL;
844 KMO_TRY_EXIT_IF_ERROR(
845 kmo_dfs_save_sub_header(fn_out,
"",
849 if ((desc1.ex_noise == TRUE) &&
850 ((((desc2.fits_type == f3i_fits) ||
851 (desc2.fits_type == f2i_fits) ||
852 (desc2.fits_type == f1i_fits)
854 (desc2.ex_noise == TRUE)
856 (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3)
861 KMO_TRY_EXIT_IF_NULL(
862 sub_header_noise = kmo_dfs_load_sub_header(
866 KMO_TRY_EXIT_IF_ERROR(
867 kmo_dfs_save_sub_header(fn_out,
"",
870 cpl_propertylist_delete(sub_header_noise);
871 sub_header_noise = NULL;
879 if (desc1.ex_noise == FALSE) {
880 if (desc1.sub_desc[i - 1].valid_data == TRUE) {
881 if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
883 }
else if (((single_ifu == TRUE) &&
884 (desc2.sub_desc[0].valid_data == TRUE))
886 (desc2.sub_desc[i - 1].valid_data == TRUE))
892 if (desc1.ex_noise == TRUE) {
893 if (desc1.sub_desc[2 * i - 1].valid_data == TRUE) {
897 if ((desc1.ex_noise == TRUE) && (desc2.ex_noise == TRUE)) {
898 if (desc1.sub_desc[2 * i - 1].valid_data == TRUE) {
899 if (((single_ifu == TRUE) &&
900 (desc2.sub_desc[1].valid_data == TRUE))
902 (desc2.sub_desc[2 * i - 1].valid_data == TRUE))
908 if ((single_ifu == TRUE) && (desc1.ex_noise == FALSE)) {
909 if ((desc1.sub_desc[i - 1].valid_data == TRUE) &&
910 (desc2.sub_desc[0].valid_data == TRUE)) {
915 if (calc_f2i == TRUE)
917 KMO_TRY_EXIT_IF_NULL(
918 op1_2d = kmo_dfs_load_image(frameset,
"0",
919 devnr1, FALSE, FALSE, NULL));
923 if (desc2.fits_type == f2i_fits) {
924 if (single_ifu == FALSE) {
925 KMO_TRY_EXIT_IF_NULL(
926 op2_2d = kmo_dfs_load_image(frameset,
"1",
927 devnr2, FALSE, FALSE, NULL));
930 if ((desc1.ex_noise == TRUE) &&
931 (desc2.ex_noise == TRUE))
933 KMO_TRY_EXIT_IF_NULL(
934 op1_noise_2d = kmo_dfs_load_image(
936 devnr1, TRUE, FALSE, NULL));
938 if (single_ifu == FALSE) {
939 KMO_TRY_EXIT_IF_NULL(
940 op2_noise_2d = kmo_dfs_load_image(
942 devnr2, TRUE, FALSE, NULL));
946 KMO_TRY_EXIT_IF_ERROR(
947 kmo_arithmetic_2D_2D(op1_2d, op2_2d,
948 op1_noise_2d, op2_noise_2d,
954 else if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
955 if (desc1.ex_noise == TRUE) {
956 KMO_TRY_EXIT_IF_NULL(
957 op1_noise_2d = kmo_dfs_load_image(
959 devnr1, TRUE, FALSE, NULL));
962 KMO_TRY_EXIT_IF_ERROR(
963 kmo_arithmetic_2D_scalar(op1_2d,
970 KMO_TRY_EXIT_IF_ERROR(
971 kmo_dfs_save_image(op1_2d, fn_out,
"",
972 sub_header_data, 0./0.));
974 if (op1_noise_2d != NULL) {
975 KMO_TRY_EXIT_IF_NULL(
976 sub_header_noise = kmo_dfs_load_sub_header(
980 KMO_TRY_EXIT_IF_ERROR(
981 kmo_dfs_save_image(op1_noise_2d, fn_out,
"",
982 sub_header_noise, 0./0.));
984 cpl_propertylist_delete(sub_header_noise);
985 sub_header_noise = NULL;
991 KMO_TRY_EXIT_IF_ERROR(
992 kmo_dfs_save_sub_header(fn_out,
"", sub_header_data));
995 if ((desc1.ex_noise == TRUE)
997 (((desc2.fits_type == f2i_fits) && (desc2.ex_noise == TRUE)) ||
998 (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3)))
1001 KMO_TRY_EXIT_IF_NULL(
1002 sub_header_noise = kmo_dfs_load_sub_header(
1006 KMO_TRY_EXIT_IF_ERROR(
1007 kmo_dfs_save_sub_header(fn_out,
"", sub_header_noise));
1009 cpl_propertylist_delete(sub_header_noise);
1010 sub_header_noise = NULL;
1018 if (desc1.ex_noise == FALSE) {
1019 if (desc1.sub_desc[i - 1].valid_data == TRUE) {
1020 if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
1022 }
else if (((single_ifu == TRUE) &&
1023 (desc2.sub_desc[0].valid_data == TRUE))
1025 (desc2.sub_desc[i - 1].valid_data == TRUE))
1031 if (desc1.ex_noise == TRUE) {
1032 if (desc1.sub_desc[2 * i - 1].valid_data == TRUE) {
1036 if ((desc1.ex_noise == TRUE) && (desc2.ex_noise == TRUE)) {
1037 if (desc1.sub_desc[2 * i - 1].valid_data == TRUE) {
1038 if (((single_ifu == TRUE) &&
1039 (desc2.sub_desc[1].valid_data == TRUE))
1041 (desc2.sub_desc[2 * i - 1].valid_data == TRUE))
1047 if ((single_ifu == TRUE) && (desc1.ex_noise == FALSE)) {
1048 if ((desc1.sub_desc[i - 1].valid_data == TRUE) &&
1049 (desc2.sub_desc[0].valid_data == TRUE)) {
1054 if (calc_f1i == TRUE)
1056 KMO_TRY_EXIT_IF_NULL(
1057 op1_1d = kmo_dfs_load_vector(frameset,
"0",
1062 if (desc2.fits_type == f1i_fits) {
1063 if (single_ifu == FALSE) {
1064 KMO_TRY_EXIT_IF_NULL(
1065 op2_1d = kmo_dfs_load_vector(frameset,
"1",
1069 if ((desc1.ex_noise == TRUE) &&
1070 (desc2.ex_noise == TRUE))
1072 KMO_TRY_EXIT_IF_NULL(
1073 op1_noise_1d = kmo_dfs_load_vector(
1077 if (single_ifu == FALSE) {
1078 KMO_TRY_EXIT_IF_NULL(
1079 op2_noise_1d = kmo_dfs_load_vector(
1085 KMO_TRY_EXIT_IF_ERROR(
1086 kmo_arithmetic_1D_1D(op1_1d, op2_1d,
1087 op1_noise_1d, op2_noise_1d,
1093 else if (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3) {
1094 if (desc1.ex_noise == TRUE) {
1095 KMO_TRY_EXIT_IF_NULL(
1096 op1_noise_1d = kmo_dfs_load_vector(
1101 KMO_TRY_EXIT_IF_ERROR(
1102 kmo_arithmetic_1D_scalar(op1_1d,
1109 KMO_TRY_EXIT_IF_ERROR(
1110 kmo_dfs_save_vector(op1_1d, fn_out,
"",
1111 sub_header_data, 0./0.));
1113 if (op1_noise_1d != NULL) {
1114 KMO_TRY_EXIT_IF_NULL(
1115 sub_header_noise = kmo_dfs_load_sub_header(
1119 KMO_TRY_EXIT_IF_ERROR(
1120 kmo_dfs_save_vector(op1_noise_1d, fn_out,
"",
1121 sub_header_noise, 0./0.));
1123 cpl_propertylist_delete(sub_header_noise);
1124 sub_header_noise = NULL;
1130 KMO_TRY_EXIT_IF_ERROR(
1131 kmo_dfs_save_sub_header(fn_out,
"", sub_header_data));
1134 if ((desc1.ex_noise == TRUE)
1136 (((desc2.fits_type == f2i_fits) && (desc2.ex_noise == TRUE)) ||
1137 (fabs(op2_scalar-FORBIDDEN_SCALAR) > 1e-3)))
1140 KMO_TRY_EXIT_IF_NULL(
1141 sub_header_noise = kmo_dfs_load_sub_header(
1145 KMO_TRY_EXIT_IF_ERROR(
1146 kmo_dfs_save_sub_header(fn_out,
"",
1149 cpl_propertylist_delete(sub_header_noise);
1150 sub_header_noise = NULL;
1158 cpl_propertylist_delete(sub_header_data); sub_header_data = NULL;
1160 cpl_image_delete(op1_2d); op1_2d = NULL;
1161 cpl_imagelist_delete(op1_3d); op1_3d = NULL;
1163 cpl_image_delete(op1_noise_2d); op1_noise_2d = NULL;
1164 cpl_imagelist_delete(op1_noise_3d); op1_noise_3d = NULL;
1166 if (single_ifu == FALSE) {
1167 kmclipm_vector_delete(op2_1d); op2_1d = NULL,
1168 cpl_image_delete(op2_2d); op2_2d = NULL;
1169 cpl_imagelist_delete(op2_3d); op2_3d = NULL;
1171 kmclipm_vector_delete(op2_noise_1d); op2_noise_1d = NULL,
1172 cpl_image_delete(op2_noise_2d); op2_noise_2d = NULL;
1173 cpl_imagelist_delete(op2_noise_3d); op2_noise_3d = NULL;
1183 kmo_free_fits_desc(&desc1);
1184 kmo_free_fits_desc(&desc2);
1185 cpl_free(fn_out); fn_out = NULL;
1186 cpl_propertylist_delete(main_header); main_header = NULL;
1187 cpl_propertylist_delete(sub_header_data); sub_header_data = NULL;
1188 cpl_propertylist_delete(sub_header_noise); sub_header_noise = NULL;
1189 cpl_image_delete(op1_2d); op1_2d = NULL;
1190 cpl_imagelist_delete(op1_3d); op1_3d = NULL;
1191 kmclipm_vector_delete(op2_1d); op2_1d = NULL;
1192 cpl_image_delete(op2_2d); op2_2d = NULL;
1193 cpl_imagelist_delete(op2_3d); op2_3d = NULL;
1194 cpl_image_delete(op1_noise_2d); op1_noise_2d = NULL;
1195 cpl_imagelist_delete(op1_noise_3d); op1_noise_3d = NULL;
1196 kmclipm_vector_delete(op2_noise_1d); op2_noise_1d = NULL;
1197 cpl_image_delete(op2_noise_2d); op2_noise_2d = NULL;
1198 cpl_imagelist_delete(op2_noise_3d); op2_noise_3d = NULL;
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.