/* $Id: kmo_fits_strip-test.c,v 1.6 2013-10-09 10:44:55 aagudo Exp $
 *
 * This file is part of the KMOS Library
 * Copyright (C) 2002-2006 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

/*
 * $Author: aagudo $
 * $Date: 2013-10-09 10:44:55 $
 * $Revision: 1.6 $
 * $Name: not supported by cvs2svn $
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>

#include <cpl.h>

#include "kmo_test_create_data.h"

/**
    @defgroup kmo_fits_strip_test   kmo_fits_strip unit tests

    @{
*/

/**
 * @brief   test
 */
static void test_fits_strip(const char *option, const char *file, int ret_val)
{
    // create esorex-command
    char esorex_command[256];
    sprintf(esorex_command,
            "esorex --suppress-prefix=TRUE kmo_fits_strip %s %s", option, file);

    kmo_get_pipe_command(esorex_command,
                         "log_kmo_fits_strip.txt", NULL, TRUE);

    // execute esorex-command
    if (ret_val == 0) {
        cpl_test_eq(0, system(esorex_command));
    } else {
        cpl_test_noneq(0, system(esorex_command));
    }
}

/**
  @brief	Test of kmo_fits_strip recipe.
 */
int main()
{
    double tol = 0.01;

    cpl_test_init("<kmos-spark@mpe.mpg.de>", CPL_MSG_WARNING);

    /* ----- run the tests ----- */
    FILE *fd = fopen("log_kmo_fits_strip.txt", "w");
    fprintf(fd, "%s\n", " ");
    fclose(fd);

    test_fits_strip("", "master_dark.fits", 0);
    test_fits_strip("--noise", "master_dark.fits", 0);
    cpl_test_abs(kmo_test_esorex_data("strip", 1), 26.9946, tol);

    test_fits_strip("--empty", "telluric_KKK.fits", 0);
    cpl_test_abs(kmo_test_esorex_data("strip", 1), 11.6164, tol);

    test_fits_strip("--angle=0", "master_flat_KKK.fits", 0);
    cpl_test_abs(kmo_test_esorex_data("strip", 1), 3.00054, tol);

    return cpl_test_end(0);
}

/** @} */
