KMOS Pipeline Reference Manual  1.2.0
kmo_fits_strip.c
00001 /* $Id: kmo_fits_strip.c,v 1.11 2013/06/17 07:52:26 aagudo Exp $
00002  *
00003  * This file is part of the KMOS Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: aagudo $
00023  * $Date: 2013/06/17 07:52:26 $
00024  * $Revision: 1.11 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 #include <math.h>
00033 #include <string.h>
00034 
00035 #include <cpl.h>
00036 
00037 #include "kmclipm_constants.h"
00038 #include "kmclipm_functions.h"
00039 
00040 #include "kmo_dfs.h"
00041 #include "kmo_error.h"
00042 #include "kmo_debug.h"
00043 
00044 static int kmo_fits_strip_create(cpl_plugin *);
00045 static int kmo_fits_strip_exec(cpl_plugin *);
00046 static int kmo_fits_strip_destroy(cpl_plugin *);
00047 static int kmo_fits_strip(cpl_parameterlist *, cpl_frameset *);
00048 
00049 static char kmo_fits_strip_description[] =
00050 "With this recipe KMOS fits frames can be stripped in following way:\n"
00051 "\n"
00052 "--noise\n"
00053 "All noise extensions will be removed. Only the data extensions remain.\n"
00054 "\n"
00055 "--angle\n"
00056 "Applies only to calibration products from kmo_flat and kmo_wave_cal.\n"
00057 "All extensions matching provided angle are kept, the others are removed.\n"
00058 "\n"
00059 "--empty\n"
00060 "All empty extensions will be removed.\n"
00061 "\n"
00062 "All parameters can be combined. When no parameter is provided, no output\n"
00063 "will be generated.\n"
00064 "\n"
00065 "-------------------------------------------------------------------------------\n"
00066 "  Input files:\n"
00067 "\n"
00068 "   DO                    KMOS                                                  \n"
00069 "   category              Type   Explanation                    Required #Frames\n"
00070 "   --------              -----  -----------                    -------- -------\n"
00071 "   <none or any>         F2D or frame to strip                     Y       1   \n"
00072 "                         F3I or\n"
00073 "                         F2I or\n"
00074 "                         F1I or\n"
00075 "\n"
00076 "  Output files:\n"
00077 "\n"
00078 "   DO                    KMOS\n"
00079 "   category              Type   Explanation\n"
00080 "   --------              -----  -----------\n"
00081 "   STRIP                 F2D or Stripped frame\n"
00082 "                         F3I or \n"
00083 "                         F2I or \n"
00084 "                         F1I    \n"
00085 "-------------------------------------------------------------------------------\n"
00086 "\n";
00087 
00104 int cpl_plugin_get_info(cpl_pluginlist *list)
00105 {
00106     cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00107     cpl_plugin *plugin = &recipe->interface;
00108 
00109     cpl_plugin_init(plugin,
00110                         CPL_PLUGIN_API,
00111                         KMOS_BINARY_VERSION,
00112                         CPL_PLUGIN_TYPE_RECIPE,
00113                         "kmo_fits_strip",
00114                         "Strip noise, rotator and/or empty extensions from a "
00115                         "processed KMOS fits frame",
00116                         kmo_fits_strip_description,
00117                         "Alex Agudo Berbel",
00118                         "kmos-spark@mpe.mpg.de",
00119                         kmos_get_license(),
00120                         kmo_fits_strip_create,
00121                         kmo_fits_strip_exec,
00122                         kmo_fits_strip_destroy);
00123 
00124     cpl_pluginlist_append(list, plugin);
00125 
00126     return 0;
00127 }
00128 
00136 static int kmo_fits_strip_create(cpl_plugin *plugin)
00137 {
00138     cpl_recipe *recipe = NULL;
00139     cpl_parameter *p = NULL;
00140 
00141     /* Check that the plugin is part of a valid recipe */
00142     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00143         recipe = (cpl_recipe *)plugin;
00144     else
00145         return -1;
00146 
00147     /* Create the parameters list in the cpl_recipe object */
00148     recipe->parameters = cpl_parameterlist_new();
00149 
00150     /* Fill the parameters list */
00151     /* --empty */
00152     p = cpl_parameter_new_value("kmos.kmo_fits_strip.empty",
00153                                 CPL_TYPE_BOOL,
00154                                 "TRUE: if empty extensions shall be removed,"
00155                                 " FALSE: otherwise",
00156                                 "kmos.kmo_fits_strip",
00157                                 FALSE);
00158     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "empty");
00159     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00160     cpl_parameterlist_append(recipe->parameters, p);
00161 
00162     /* --noise */
00163     p = cpl_parameter_new_value("kmos.kmo_fits_strip.noise",
00164                                 CPL_TYPE_BOOL,
00165                                 "TRUE: if noise extensions shall be removed,"
00166                                 " FALSE: otherwise",
00167                                 "kmos.kmo_fits_strip",
00168                                 FALSE);
00169     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "noise");
00170     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00171     cpl_parameterlist_append(recipe->parameters, p);
00172 
00173     /* --angle */
00174     p = cpl_parameter_new_value("kmos.kmo_fits_strip.angle",
00175                                 CPL_TYPE_INT,
00176                                 "All extensions not matching provided angle "
00177                                 "are stripped.",
00178                                 "kmos.kmo_fits_strip",
00179                                 -1);
00180     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "angle");
00181     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
00182     cpl_parameterlist_append(recipe->parameters, p);
00183 
00184     return 0;
00185 }
00186 
00192 static int kmo_fits_strip_exec(cpl_plugin *plugin)
00193 {
00194     cpl_recipe  *recipe;
00195 
00196     /* Get the recipe out of the plugin */
00197     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00198         recipe = (cpl_recipe *)plugin;
00199     else return -1 ;
00200 
00201     return kmo_fits_strip(recipe->parameters, recipe->frames);
00202 }
00203 
00209 static int kmo_fits_strip_destroy(cpl_plugin *plugin)
00210 {
00211     cpl_recipe *recipe;
00212 
00213     /* Get the recipe out of the plugin */
00214     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00215         recipe = (cpl_recipe *)plugin;
00216     else return -1 ;
00217 
00218     cpl_parameterlist_delete(recipe->parameters);
00219     return 0 ;
00220 }
00221 
00222 static const char * kmos_get_base_name(const char * self)
00223 {
00224     const char * p = self ? strrchr(self, '/') : NULL;
00225 
00226     return p ? p + 1 : self;
00227 }
00228 
00247 static int kmo_fits_strip(cpl_parameterlist *parlist, cpl_frameset *frameset)
00248 {
00249 #define PRO_REC_PARAMi_NAME         "ESO PRO REC1 PARAM%d NAME"
00250 #define PRO_REC_PARAMi_VALUE        "ESO PRO REC1 PARAM%d VALUE"
00251 
00252     int                 ret_val             = 0,
00253                         nr_devices          = 0,
00254                         remove_noise        = FALSE,
00255                         remove_empty        = FALSE,
00256                         remove_angle        = FALSE,
00257                         found_angle         = FALSE,
00258                         isCalFrame          = 0,
00259                         isMasterFlat        = 0,
00260                         actDetNr            = 0,
00261                         cal_device_nr       = 0,
00262                         dummy               = 0,
00263                         npar                = 0,
00264                         index               = 0;
00265     double              angle               = 0.,
00266                         tmp_angle           = 0.,
00267                         ret_angle           = 0.,
00268                         secClosestAng       = 0.,
00269                         ocsRotAngle         = 0.,
00270                         proRotAngle         = 0.;
00271     cpl_propertylist    *header             = NULL,
00272                         *sub_header         = NULL;
00273     cpl_imagelist       *cube               = NULL;
00274     cpl_image           *img                = NULL;
00275     cpl_vector          *vec                = NULL;
00276     main_fits_desc      desc;
00277     cpl_frame           *frame              = NULL;
00278     const char          *kname              = NULL,
00279                         *filename           = NULL;
00280     char                *ggg                = NULL,
00281                         cval[1024];
00282     const cpl_parameter *param              = NULL;
00283     cpl_frame           *product_frame      = NULL;
00284     kmclipm_vector      *kv                 = NULL;
00285 
00286     KMO_TRY
00287     {
00288         kmo_init_fits_desc(&desc);
00289 
00290         /* --- check input --- */
00291         KMO_TRY_ASSURE((parlist != NULL) &&
00292                        (frameset != NULL),
00293                        CPL_ERROR_NULL_INPUT,
00294                        "Not all input data is provided!");
00295 
00296         KMO_TRY_ASSURE(cpl_frameset_get_size(frameset) == 1,
00297                        CPL_ERROR_NULL_INPUT,
00298                        "A fits-file must be provided!");
00299 
00300         KMO_TRY_EXIT_IF_NULL(
00301             frame = kmo_dfs_get_frame(frameset, "0"));
00302 
00303         KMO_TRY_EXIT_IF_NULL(
00304             filename = cpl_frame_get_filename(frame));
00305 
00306         desc = kmo_identify_fits_header(filename);
00307         KMO_TRY_CHECK_ERROR_STATE_MSG("Provided fits file doesn't seem to be "
00308                                       "in KMOS-format!");
00309 
00310         KMO_TRY_ASSURE((desc.fits_type == f2d_fits) ||
00311                        (desc.fits_type == f3i_fits) ||
00312                        (desc.fits_type == f2i_fits) ||
00313                        (desc.fits_type == f1i_fits),
00314                        CPL_ERROR_ILLEGAL_INPUT,
00315                        "Input data hasn't correct data type "
00316                        "(KMOSTYPE must be F2D, F3I, F2I or F1I)!");
00317 
00318         KMO_TRY_ASSURE(kmo_dfs_set_groups(frameset, "kmo_fits_strip") == 1,
00319                        CPL_ERROR_ILLEGAL_INPUT,
00320                        "Cannot identify RAW and CALIB frames!");
00321 
00322         cpl_msg_info("", "--- Parameter setup for kmo_fits_strip ----");
00323         remove_empty = kmo_dfs_get_parameter_bool(parlist,
00324                                                   "kmos.kmo_fits_strip.empty");
00325         KMO_TRY_CHECK_ERROR_STATE();
00326         KMO_TRY_ASSURE((remove_empty == TRUE) ||
00327                        (remove_empty == FALSE),
00328                        CPL_ERROR_ILLEGAL_INPUT,
00329                        "empty must be TRUE or FALSE!");
00330         KMO_TRY_EXIT_IF_ERROR(
00331             kmo_dfs_print_parameter_help(parlist, "kmos.kmo_fits_strip.empty"));
00332 
00333         remove_noise = kmo_dfs_get_parameter_bool(parlist,
00334                                                   "kmos.kmo_fits_strip.noise");
00335         KMO_TRY_CHECK_ERROR_STATE();
00336         KMO_TRY_ASSURE((remove_noise == TRUE) ||
00337                        (remove_noise == FALSE),
00338                        CPL_ERROR_ILLEGAL_INPUT,
00339                        "noise must be TRUE or FALSE!");
00340         KMO_TRY_EXIT_IF_ERROR(
00341             kmo_dfs_print_parameter_help(parlist, "kmos.kmo_fits_strip.noise"));
00342 
00343         angle = kmo_dfs_get_parameter_int(parlist,
00344                                           "kmos.kmo_fits_strip.angle");
00345         KMO_TRY_CHECK_ERROR_STATE();
00346         KMO_TRY_EXIT_IF_ERROR(
00347             kmo_dfs_print_parameter_help(parlist, "kmos.kmo_fits_strip.angle"));
00348 
00349         if (angle >= 0) {
00350             remove_angle = TRUE;
00351         }
00352 
00353         KMO_TRY_ASSURE(!remove_angle || ((angle >=0) && (angle < 360)),
00354                        CPL_ERROR_ILLEGAL_INPUT,
00355                        "angle must be between 0 and 360 degrees!");
00356 
00357         cpl_msg_info("", "-------------------------------------------");
00358 
00359         if ((!remove_empty) && (!remove_noise) && (!remove_angle)) {
00360             // do nothing
00361             cpl_msg_info("","No action has been specified (angle-, noise- or empty-parameter),"
00362                             " therefore no output is generated");
00363         } else {
00364             // check if it is a multi-angle-calibration file
00365             isCalFrame = FALSE;
00366             KMO_TRY_EXIT_IF_NULL(
00367                 sub_header = kmo_dfs_load_sub_header(frameset, "0", 1, FALSE));
00368             if (cpl_propertylist_has(sub_header, CAL_ROTANGLE)) {
00369                 isCalFrame = TRUE;
00370             }
00371             cpl_propertylist_delete(sub_header); sub_header = NULL;
00372 
00373             //
00374             // --- save primary extension ---
00375             //
00376             // load data and save it away again
00377             KMO_TRY_EXIT_IF_NULL(
00378                 header = kmo_dfs_load_primary_header(frameset, "0"));
00379 
00380             if (strcmp(MASTER_FLAT, cpl_propertylist_get_string(header, CPL_DFS_PRO_CATG))==0) {
00381                 isMasterFlat = TRUE;
00382             }
00383 
00384             if (remove_angle && isCalFrame) {
00385                 // update OCS.ROT.NAANGLE if it differs
00386                 ocsRotAngle = cpl_propertylist_get_double(header, ROTANGLE);
00387                 ocsRotAngle = kmclipm_strip_angle(&ocsRotAngle);
00388                 proRotAngle = kmclipm_cal_propertylist_find_angle(filename, 1, FALSE, angle,
00389                         &dummy, &secClosestAng);
00390                 KMO_TRY_CHECK_ERROR_STATE();
00391                 if (fabs(ocsRotAngle-proRotAngle) > 0.1) {
00392                     cpl_msg_warning("", "In the product the original ESO OCS ROT NAANGLE keyword "
00393                                         "has been updated with the chosen "
00394                                         "ESO PRO ROT NAANGLE (was: %g, is: %g)!", ocsRotAngle, proRotAngle);
00395                     KMO_TRY_EXIT_IF_ERROR(
00396                         cpl_propertylist_update_double(header, ROTANGLE, proRotAngle));
00397                 }
00398             }
00399 //            // kmo_dfs_save_main_header() doesn't allow to change ESO OCS ROT NAANGLE
00400 //            KMO_TRY_EXIT_IF_ERROR(
00401 //                kmo_dfs_save_main_header(frameset, STRIP, "", frame,
00402 //                                         header, parlist, cpl_func));
00403             {
00404                 // setup DFS manually (no MD5 calculated...)
00405                 KMO_TRY_EXIT_IF_ERROR(
00406                     cpl_propertylist_update_string(header, "PIPEFILE", "strip.fits"));
00407                 KMO_TRY_EXIT_IF_ERROR(
00408                     cpl_propertylist_update_string(header, CPL_DFS_PRO_CATG, STRIP));
00409                 KMO_TRY_EXIT_IF_ERROR(
00410                     cpl_propertylist_update_string(header, "ESO PRO REC1 ID", cpl_func));
00411                 ggg = cpl_sprintf("cpl-%d.%d.%d", cpl_version_get_major(), cpl_version_get_minor(), cpl_version_get_micro());
00412                 KMO_TRY_EXIT_IF_ERROR(
00413                     cpl_propertylist_update_string(header, "ESO PRO REC1 DRS ID", ggg));
00414                 cpl_free(ggg); ggg = NULL;
00415                 KMO_TRY_EXIT_IF_ERROR(
00416                     cpl_propertylist_update_string(header, "ESO PRO REC1 PIPE ID", VERSION));
00417                 KMO_TRY_EXIT_IF_ERROR(
00418                     cpl_propertylist_update_string(header, "ESO PRO REC1 CAL1 NAME", kmos_get_base_name(filename)));
00419                 KMO_TRY_EXIT_IF_ERROR(
00420                     cpl_propertylist_update_string(header, "ESO PRO REC1 CAL1 CATG", COMMANDLINE));
00421                 KMO_TRY_EXIT_IF_ERROR(
00422                     cpl_propertylist_update_string(header, "ESO PRO REC1 CAL1 DATAMD5", cpl_propertylist_get_string(header, "DATAMD5")));
00423                 KMO_TRY_CHECK_ERROR_STATE();
00424 
00425                 while (param != NULL) {
00426                     char *pval, *dval;
00427                     ++npar;
00428 
00429                     kname = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI);
00430                     const char * comment = cpl_parameter_get_help(param);
00431                     switch (cpl_parameter_get_type(param)) {
00432                     case CPL_TYPE_BOOL:
00433                         pval = cpl_strdup(cpl_parameter_get_bool(param) == 1 ? "true" : "false");
00434                         dval = cpl_sprintf("Default: %s", cpl_parameter_get_default_bool(param) == 1 ? "true" : "false");
00435                         break;
00436                     case CPL_TYPE_INT:
00437                         pval = cpl_sprintf("%d", cpl_parameter_get_int(param));
00438                         dval = cpl_sprintf("Default: %d", cpl_parameter_get_default_int(param));
00439                         break;
00440                     case CPL_TYPE_DOUBLE:
00441                         pval = cpl_sprintf("%g", cpl_parameter_get_double(param));
00442                         dval = cpl_sprintf("Default: %g", cpl_parameter_get_default_double(param));
00443                         break;
00444                     case CPL_TYPE_STRING:
00445                         pval = cpl_strdup(cpl_parameter_get_string(param));
00446                         dval = cpl_sprintf("Default: '%s'", cpl_parameter_get_default_string(param));
00447                         break;
00448                     default:
00449                         /* Theoretically impossible to get here */
00450                         KMO_TRY_ASSURE(1==0,
00451                                        CPL_ERROR_UNSPECIFIED,
00452                                        "what?");
00453                     }
00454                     snprintf(cval, 1024, PRO_REC_PARAMi_NAME, npar);
00455                     cpl_propertylist_update_string(header, cval, kname);
00456                     cpl_propertylist_set_comment(header, cval, comment);
00457 
00458                     snprintf(cval, 1024, PRO_REC_PARAMi_VALUE, npar);
00459                     cpl_propertylist_update_string(header, cval, pval);
00460                     cpl_propertylist_set_comment(header, cval, dval);
00461 
00462                     cpl_free((void*)pval);
00463                     cpl_free((void*)dval);
00464 
00465                     param = cpl_parameterlist_get_next_const(parlist);
00466                 }
00467             }
00468             KMO_TRY_CHECK_ERROR_STATE();
00469 
00470             cpl_msg_info(cpl_func, "Writing FITS %s product(%s): %s", "propertylist", "STRIP", "strip.fits");
00471             KMO_TRY_EXIT_IF_NULL(
00472                 product_frame = cpl_frame_new());
00473             KMO_TRY_EXIT_IF_ERROR(
00474                 cpl_frame_set_filename(product_frame, "strip.fits"));
00475             KMO_TRY_EXIT_IF_ERROR(
00476                 cpl_frame_set_tag(product_frame, "STRIP"));
00477             KMO_TRY_EXIT_IF_ERROR(
00478                 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_ANY));
00479             KMO_TRY_EXIT_IF_ERROR(
00480                 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
00481             KMO_TRY_EXIT_IF_ERROR(
00482                 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL));
00483             KMO_TRY_EXIT_IF_ERROR(
00484                 cpl_frameset_insert(frameset, product_frame));
00485 
00486             KMO_TRY_EXIT_IF_ERROR(
00487                 cpl_propertylist_save(header, "strip.fits", CPL_IO_CREATE));
00488             cpl_propertylist_delete(header); header = NULL;
00489 
00490             if (!isCalFrame) {
00491                 if (!desc.ex_noise) {
00492                     nr_devices = desc.nr_ext;
00493                 } else {
00494                     nr_devices = desc.nr_ext / 2;
00495                 }
00496             } else {
00497                 nr_devices = 3;
00498             }
00499 
00500             if (isCalFrame) {
00501                 if (isMasterFlat) {
00502                     remove_noise = !remove_noise;
00503                 }
00504             } else {
00505                 if (desc.ex_noise) {
00506                     remove_noise = !remove_noise;
00507                 }
00508             }
00509 
00510             actDetNr = 1;
00511             int i = 0, n = 0;
00512             for (i = 0; i < nr_devices; i++)
00513             {
00514                 // either loop noise or not
00515                 for (n = FALSE; n <= remove_noise; n++) {
00516                     if (isCalFrame) {
00517                         KMO_TRY_EXIT_IF_NULL(
00518                             header = kmclipm_cal_propertylist_load(filename, i+1, n, angle, &ret_angle));
00519                     } else {
00520                         KMO_TRY_EXIT_IF_NULL(
00521                             header = kmo_dfs_load_sub_header(frameset, "0", i + 1, n));
00522                     }
00523 
00524                     if (remove_angle) {
00525                         // examine angle
00526                         if (cpl_propertylist_has(header, CAL_ROTANGLE)) {
00527                             tmp_angle = cpl_propertylist_get_double(header, CAL_ROTANGLE);
00528                             KMO_TRY_CHECK_ERROR_STATE();
00529 
00530                             if (fabs(angle - tmp_angle) < 0.01) {
00531                                 found_angle = TRUE;
00532                                 isCalFrame = TRUE;
00533                             } else {
00534                                 found_angle = FALSE;
00535                             }
00536                         } else {
00537                             // frame doesn't seem to have the CAL_ROTANGLE keyword
00538                             // process all extensions
00539                             found_angle = TRUE;
00540                         }
00541                     } else {
00542                         found_angle = TRUE;
00543                     }
00544 
00545                     index = kmo_identify_index(filename, i+1, n);
00546                     if (found_angle) {
00547                         if ((desc.fits_type == f2d_fits) ||
00548                             (desc.fits_type == f2i_fits))
00549                         {
00550                             if (isCalFrame) {
00551                                 cal_device_nr = cpl_propertylist_get_int(header, CHIPINDEX);
00552                                 KMO_TRY_CHECK_ERROR_STATE();
00553                                 if (cal_device_nr == actDetNr) {
00554                                     KMO_TRY_EXIT_IF_ERROR(
00555                                         kmo_update_sub_keywords(header,
00556                                                                 n,
00557                                                                 FALSE,
00558                                                                 desc.frame_type,
00559                                                                 actDetNr));
00560                                     KMO_TRY_EXIT_IF_NULL(
00561                                         img = kmo_dfs_load_cal_image(frameset, "0",
00562                                                                      i+1, n, angle,
00563                                                                      FALSE, NULL,
00564                                                                      &ret_angle, -1, 0, 0));
00565 
00566                                     if (fabs(angle-ret_angle) > 0.01) {
00567                                         cpl_msg_warning("","Angle provided: %g, angle found: %g", angle, ret_angle);
00568                                     }
00569                                     if (n == remove_noise) {
00570                                         actDetNr++;
00571                                     }
00572                                 }
00573                                 if (img != NULL) {
00574                                     KMO_TRY_EXIT_IF_ERROR(
00575                                         kmo_dfs_save_image(img, STRIP, "", header, 0./0.));
00576                                 }
00577                             } else {
00578                                 img = cpl_image_load(filename,CPL_TYPE_FLOAT, 0, index);
00579                                 if (CPL_ERROR_NONE != cpl_error_get_code()) {
00580                                     cpl_error_reset();
00581                                     if (!remove_empty) {
00582                                         KMO_TRY_EXIT_IF_ERROR(
00583                                             kmo_dfs_save_image(img, STRIP, "", header, 0./0.));
00584                                     }
00585                                 } else {
00586                                     KMO_TRY_EXIT_IF_ERROR(
00587                                         kmo_dfs_save_image(img, STRIP, "", header, 0./0.));
00588                                 }
00589                             }
00590                             cpl_image_delete(img); img = NULL;
00591                         } else if (desc.fits_type == f3i_fits) {
00592                             cube = cpl_imagelist_load(filename,CPL_TYPE_FLOAT, index);
00593                             if (CPL_ERROR_NONE != cpl_error_get_code()) {
00594                                 cpl_error_reset();
00595                                 if (!remove_empty) {
00596                                     KMO_TRY_EXIT_IF_ERROR(
00597                                         kmo_dfs_save_cube(cube, STRIP, "", header, 0./0.));
00598                                 }
00599                             } else {
00600                                 KMO_TRY_EXIT_IF_ERROR(
00601                                     kmo_dfs_save_cube(cube, STRIP, "", header, 0./0.));
00602                             }
00603                             cpl_imagelist_delete(cube); cube = NULL;
00604                         } else if (desc.fits_type == f1i_fits) {
00605                             vec = cpl_vector_load(filename, index);
00606                             if (CPL_ERROR_NONE != cpl_error_get_code()) {
00607                                 cpl_error_reset();
00608                                 if (!remove_empty) {
00609                                     KMO_TRY_EXIT_IF_ERROR(
00610                                         kmo_dfs_save_vector(NULL, STRIP, "", header, 0./0.));
00611                                 }
00612                             } else {
00613                                 KMO_TRY_EXIT_IF_NULL(
00614                                     kv = kmclipm_vector_create(vec));
00615                                 KMO_TRY_EXIT_IF_ERROR(
00616                                     kmo_dfs_save_vector(kv, STRIP, "", header, 0./0.));
00617                             }
00618                             kmclipm_vector_delete(kv); kv = NULL;
00619                         }
00620                     } // if (found_angle)
00621                     cpl_propertylist_delete(header); header = NULL;
00622                 } // for (n)
00623             } // for (i = nr_devices)
00624         } // if ((!remove_empty) && (!remove_noise) && (!remove_angle))
00625     }
00626     KMO_CATCH
00627     {
00628         KMO_CATCH_MSG();
00629 
00630         ret_val = -1;
00631     }
00632 
00633     cpl_propertylist_delete(header); header = NULL;
00634     cpl_imagelist_delete(cube); cube = NULL;
00635     cpl_image_delete(img); img = NULL;
00636     kmclipm_vector_delete(kv); kv = NULL;
00637     kmo_free_fits_desc(&desc);
00638 
00639     return ret_val;
00640 }
00641