diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/acinclude.m4 cpl-plugin-sinfo-3.1.0+dfsg/acinclude.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/acinclude.m4 2013-06-20 12:30:56.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/acinclude.m4 2018-02-09 12:20:21.000000000 +0000 @@ -13,7 +13,7 @@ detmon_fftw_libraries="" AC_ARG_WITH(fftw, - AC_HELP_STRING([--with-fftw], + AS_HELP_STRING([--with-fftw], [location where fftw is installed]), [ detmon_with_fftw_includes=$withval/include @@ -21,17 +21,17 @@ ]) AC_ARG_WITH(fftw-includes, - AC_HELP_STRING([--with-fftw-includes], + AS_HELP_STRING([--with-fftw-includes], [location of the fftw header files]), detmon_with_fftw_includes=$withval) AC_ARG_WITH(fftw-libs, - AC_HELP_STRING([--with-fftw-libs], + AS_HELP_STRING([--with-fftw-libs], [location of the fftw library]), detmon_with_fftw_libs=$withval) AC_ARG_ENABLE(fftw-test, - AC_HELP_STRING([--disable-fftw-test], + AS_HELP_STRING([--disable-fftw-test], [disables checks for the fftw library and headers]), detmon_enable_fftw_test=$enableval, detmon_enable_fftw_test=yes) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/aclocal.m4 cpl-plugin-sinfo-3.1.0+dfsg/aclocal.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/aclocal.m4 2017-04-20 15:53:03.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/aclocal.m4 2018-04-13 15:46:34.000000000 +0000 @@ -1211,6 +1211,8 @@ m4_include([m4macros/cpl.m4]) m4_include([m4macros/eso.m4]) +m4_include([m4macros/gsl.m4]) +m4_include([m4macros/hdrl.m4]) m4_include([m4macros/libtool.m4]) m4_include([m4macros/ltoptions.m4]) m4_include([m4macros/ltsugar.m4]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/calib/cal_size cpl-plugin-sinfo-3.1.0+dfsg/calib/cal_size --- cpl-plugin-sinfo-3.0.0+dfsg/calib/cal_size 2017-06-28 20:54:41.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/calib/cal_size 2018-04-27 08:32:26.000000000 +0000 @@ -1 +1 @@ -17112 +505240 diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/calib/gasgano/config/sinfo.oca cpl-plugin-sinfo-3.1.0+dfsg/calib/gasgano/config/sinfo.oca --- cpl-plugin-sinfo-3.0.0+dfsg/calib/gasgano/config/sinfo.oca 2017-04-20 15:52:59.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/calib/gasgano/config/sinfo.oca 2018-04-13 15:45:54.000000000 +0000 @@ -221,6 +221,21 @@ DO.CATG = "FLUX_STD_CATALOG"; } +if PRO.CATG like "%EFFICIENCY_WINDOWS%" then +{ + DO.CATG = "EFFICIENCY_WINDOWS"; +} + +if PRO.CATG like "%FLUX_STD_CATALOG%" then +{ + DO.CATG = "FLUX_STD_CATALOG"; +} + +if PRO.CATG like "%EFFICIENCY%" then +{ + DO.CATG = "EFFICIENCY"; +} + if PRO.CATG like "%BP_MAP%" then { @@ -290,10 +305,16 @@ { DO.CATG = "FIRST_COL"; } -if PRO.CATG like "%DRS_SETUP_WAVE%" then +if PRO.CATG == "DRS_SETUP_WAVE" then { DO.CATG = "DRS_SETUP_WAVE"; } + +if PRO.CATG == "DRS_SETUP_WAVE_OH" then +{ + DO.CATG = "DRS_SETUP_WAVE_OH"; +} + if PRO.CATG like "%MASTER_FLAT_LAMP%" then { DO.CATG = "MASTER_FLAT_LAMP"; @@ -571,6 +592,49 @@ DO.CATG = "SKY_STACKED_DUMMY"; } + + +if PRO.CATG == "EFFICIENCY_WINDOWS" then +{ + DO.CATG = "EFFICIENCY_WINDOWS"; +} +if PRO.CATG == "RESPONSE_WINDOWS" then +{ + DO.CATG = "RESPONSE_WINDOWS"; +} +if PRO.CATG == "EXTCOEFF_TABLE" then +{ + DO.CATG = "EXTCOEFF_TABLE"; +} +if PRO.CATG == "FLUX_STD_CATALOG" then +{ + DO.CATG = "FLUX_STD_CATALOG"; +} +if PRO.CATG == "FIT_AREAS" then +{ + DO.CATG = "FIT_AREAS"; +} +if PRO.CATG == "QUALITY_AREAS" then +{ + DO.CATG = "QUALITY_AREAS"; +} +if PRO.CATG == "HIGH_ABS_REGIONS" then +{ + DO.CATG = "HIGH_ABS_REGIONS"; +} +if PRO.CATG == "RESPONSE" then +{ + DO.CATG = "RESPONSE"; +} +if PRO.CATG == "RESP_FIT_POINTS_CATALOG" then +{ + DO.CATG = "RESP_FIT_POINTS_CATALOG"; +} +if PRO.CATG == "TELL_MOD_CATALOG" then +{ + DO.CATG = "TELL_MOD_CATALOG"; +} + select execute(sinfo_rec_jitter_stdstar) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "STD"; select execute(sinfo_rec_mflat) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "FLAT_LAMP"; select execute(sinfo_rec_distortion) from inputFiles where SIG.TEMPLATE == 1 and LF.DO.CATG == "FLAT_NS"; @@ -678,6 +742,17 @@ minRet = 1; maxRet = 1; select file as DISTORTION from calibFiles where DO.CATG == "DISTORTION" and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + +minRet = 0; maxRet = 1; +select file as EXTCOEFF_TABLE from calibFiles where DO.CATG == "EXTCOEFF_TABLE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + +minRet = 0; maxRet = 1; +select file as RESPONSE from calibFiles where DO.CATG == "RESPONSE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + recipe sinfo_rec_jitter; } @@ -691,6 +766,13 @@ minRet = 0; maxRet = 1; select file as FLUX_STD_CATALOG from calibFiles where DO.CATG == "FLUX_STD_CATALOG" and inputFile.INSTRUME==INSTRUME; +minRet = 0; maxRet = 1; +select file as EFFICIENCY_WINDOWS from calibFiles where DO.CATG == "EFFICIENCY_WINDOWS" and inputFile.INS.FILT1.NAME==INS.FILT1.NAME + and inputFile.INSTRUME==INSTRUME; + + + + minRet = 1; maxRet = 1; select file as MASTER_BP_MAP from calibFiles where DO.CATG == "MASTER_BP_MAP" and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME; @@ -715,6 +797,50 @@ minRet = 1; maxRet = 1; select file as DISTORTION from calibFiles where DO.CATG == "DISTORTION" and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + +minRet = 0; maxRet = 1; +select file as EFFICIENCY_WINDOWS from calibFiles where DO.CATG == "EFFICIENCY_WINDOWS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as RESPONSE_WINDOWS from calibFiles where DO.CATG == "RESPONSE_WINDOWS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as EXTCOEFF_TABLE from calibFiles where DO.CATG == "EXTCOEFF_TABLE" + and inputFile.INSTRUME==INSTRUME; + +minRet = 0; maxRet = 1; +select file as FLUX_STD_CATALOG from calibFiles where DO.CATG == "FLUX_STD_CATALOG" + and inputFile.INSTRUME==INSTRUME; + +minRet = 0; maxRet = 1; +select file as TELL_MOD_CATALOG from calibFiles where DO.CATG == "TELL_MOD_CATALOG" + and inputFile.INSTRUME==INSTRUME; + + + +minRet = 0; maxRet = 1; +select file as FIT_AREAS from calibFiles where DO.CATG == "FIT_AREAS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as QUALITY_AREAS from calibFiles where DO.CATG == "QUALITY_AREAS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as HIGH_ABS_REGIONS from calibFiles where DO.CATG == "HIGH_ABS_REGIONS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as RESP_FIT_POINTS_CATALOG from calibFiles where DO.CATG == "RESP_FIT_POINTS_CATALOG" + and inputFile.INSTRUME==INSTRUME; + +//minRet = 0; maxRet = 1; +//select file as RESPONSE from calibFiles where DO.CATG == "RESPONSE" +// and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + recipe sinfo_rec_jitter; } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/calib/gasgano/config/SINFO.prefs cpl-plugin-sinfo-3.1.0+dfsg/calib/gasgano/config/SINFO.prefs --- cpl-plugin-sinfo-3.0.0+dfsg/calib/gasgano/config/SINFO.prefs 2017-04-20 15:52:59.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/calib/gasgano/config/SINFO.prefs 2018-04-13 15:45:54.000000000 +0000 @@ -5,7 +5,7 @@ COMPONENT_FONT=Dialog:14 CUBE_TO_VIEWER= CUBE_VIEWER_TYPE=SHELLCOMMAND -DATA_FILES=/usr/share/esopipes/datastatic/sinfo-3.0.0 +DATA_FILES=/usr/share/esopipes/datastatic/sinfo-3.1.0 DBOBS_DISPLAY_COLUMNS=CLASSIFICATION:RA:DEC:TPL.EXPNO:TPL.NEXP DBOBS_DISPLAY_COLUMNS_SIZE=0:0:0:0:0 DBOBS_INSTRUMENT=All @@ -41,7 +41,7 @@ PRINT_FONT=Monospaced:16 PRINT_ORIENTATION=P RADEC_CONVERSION=true -RECIPE_SET=sinfo_rec_detlin=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_detlin.so;sinfo_rec_distortion=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_distortion.so;sinfo_rec_jitter=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_jitter.so;sinfo_rec_mdark=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_mdark.so;sinfo_rec_mflat=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_mflat.so;sinfo_rec_pupil=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_pupil.so;sinfo_rec_wavecal=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_rec_wavecal.so;sinfo_utl_bp_mask_add=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_bp_mask_add.so;sinfo_utl_cube2ima=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_cube2ima.so;sinfo_utl_cube_combine=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_cube_combine.so;sinfo_utl_cube2spectrum=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_cube2spectrum.so;sinfo_utl_cube_arith=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_cube_arith.so;sinfo_utl_ima_arith=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_ima_arith.so;sinfo_utl_skycor=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_skycor.so;sinfo_utl_skymap=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_skymap.so;sinfo_utl_spectrum_divide_by_blackbody=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_spectrum_divide_by_blackbody.so;sinfo_utl_spectrum_wavelength_shift=/usr/lib64/esopipes-plugins/sinfo-3.0.0/sinfo_utl_spectrum_wavelength_shift.so +RECIPE_SET=sinfo_rec_detlin=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_detlin.so;sinfo_rec_distortion=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_distortion.so;sinfo_rec_jitter=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_jitter.so;sinfo_rec_mdark=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_mdark.so;sinfo_rec_mflat=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_mflat.so;sinfo_rec_pupil=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_pupil.so;sinfo_rec_wavecal=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_rec_wavecal.so;sinfo_utl_bp_mask_add=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_bp_mask_add.so;sinfo_utl_cube2ima=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_cube2ima.so;sinfo_utl_cube_combine=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_cube_combine.so;sinfo_utl_cube2spectrum=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_cube2spectrum.so;sinfo_utl_cube_arith=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_cube_arith.so;sinfo_utl_ima_arith=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_ima_arith.so;sinfo_utl_skycor=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_skycor.so;sinfo_utl_skymap=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_skymap.so;sinfo_utl_spectrum_divide_by_blackbody=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_spectrum_divide_by_blackbody.so;sinfo_utl_spectrum_wavelength_shift=/usr/lib64/esopipes-plugins/sinfo-3.1.0/sinfo_utl_spectrum_wavelength_shift.so SCRIPTS_DIR=/home/astro4/gasgano/scripts/gas-scripts SHORTEN_FILES_PATH=false SHORT_FILENAME=true diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/ChangeLog cpl-plugin-sinfo-3.1.0+dfsg/ChangeLog --- cpl-plugin-sinfo-3.0.0+dfsg/ChangeLog 2017-04-20 11:35:01.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/ChangeLog 2018-03-13 15:32:40.000000000 +0000 @@ -1,3 +1,23 @@ +3.1.0 13/03/2017 Paranal 2018 release. +3.1.0b10 19/02/2017 Candidate Paranal 2018 release. Proper handling of DRS_SETUP_WAVE and DRS_SETUP_WAVE_OH +3.1.0b9 19/02/2017 Candidate Paranal 2018 release. Merged HDRL-response branch. +3.1.0b8 19/02/2017 Candidate Paranal 2018 release. Set different PRO.CATG on DRS_SETUP_WAVE for OH lines +3.1.0b7 15/02/2018 Andling case where HIGH_ABS_REGIONS is missing +3.1.0b6 09/02/2017 Candidate Paranal 2018 release. Fix typo help parameter bp_dist.max_cut +3.1.0b5 09/02/2017 Candidate Paranal 2018 release. Better fix of PIPE-7651 +3.1.0b4 06/02/2018 Updated for new data after commissioning +3.1.0b3 06/02/2017 Candidate Paranal 2018 release. Fixed problem reducing SINFONI J band distortion data after com 01/02/2017. PIPE-7651 +3.1.0b1 15/12/2017 Candidate Paranal 2018 release +3.0.9 15/12/2017 Fixed PIPE-7570 +3.0.8 07/12/2017 Fixed bug in fluxcal of cube +3.0.7 29/11/2017 Updated to reflect new HDRL +3.0.6 13/11/2017 Updated to test new esoreflex +3.0.5 04/09/2017 Fixed PIPE-7327, added response computation +3.0.4 04/06/2017 added creation QC param for efficiency +3.0.3 09/05/2017 fixed problems including GSL in HDRL +3.0.2 09/05/2017 fixed PIPE-7200 +3.0.2 08/05/2017 3.0.2 fixed PIPE-7147 +3.0.1 05/05/2017 3.0.1 including first implementation (not yet certified by SDP) of efficiency 3.0.0 19/04/2017 Renamed 2.9.9 as 3.0.0 for public release 2.9.9 03/04/2017 Fixed PIPE-7147 2.9.8 23/02/2017 Candidate April 2017 release (fixed RBS cfg) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/config.h.in cpl-plugin-sinfo-3.1.0+dfsg/config.h.in --- cpl-plugin-sinfo-3.0.0+dfsg/config.h.in 2017-04-20 15:53:04.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/config.h.in 2018-04-13 15:46:35.000000000 +0000 @@ -24,9 +24,15 @@ /* Define to 1 if you have the `floor' function. */ #undef HAVE_FLOOR +/* Define to 1 iff you have GSL */ +#undef HAVE_GSL + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H +/* Define to 1 iff you have GSL */ +#undef HAVE_LIBGSL + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/configure cpl-plugin-sinfo-3.1.0+dfsg/configure --- cpl-plugin-sinfo-3.0.0+dfsg/configure 2017-04-20 15:53:04.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/configure 2018-04-13 15:46:35.000000000 +0000 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for SINFONI Instrument Pipeline 3.0.0. +# Generated by GNU Autoconf 2.69 for SINFONI Instrument Pipeline 3.1.0. # # Report bugs to . # @@ -590,12 +590,13 @@ # Identity of this package. PACKAGE_NAME='SINFONI Instrument Pipeline' PACKAGE_TARNAME='sinfo' -PACKAGE_VERSION='3.0.0' -PACKAGE_STRING='SINFONI Instrument Pipeline 3.0.0' +PACKAGE_VERSION='3.1.0' +PACKAGE_STRING='SINFONI Instrument Pipeline 3.1.0' PACKAGE_BUGREPORT='usd-help@eso.org' PACKAGE_URL='' ac_unique_file="Makefile.am" +enable_option_checking=no ac_default_prefix=${PIPE_HOME:-/usr/local} # Factoring default headers for most tests. ac_includes_default="\ @@ -651,6 +652,11 @@ pipedocsdir privatelibdir plugindir +HDRL_INCLUDES +HDRL_INTERNAL_CFLAGS +HDRL_LDFLAGS +LIBHDRL +HDRL_LIBS CPL_LDFLAGS CPL_CFLAGS CPL_INCLUDES @@ -658,6 +664,9 @@ LIBCPLUI LIBCPLDRS LIBCPLCORE +GSL_LIBS +GSL_LDFLAGS +GSL_INCLUDES LIBTOOL_DEPS LT_SYS_LIBRARY_PATH OTOOL64 @@ -715,6 +724,7 @@ MAINT MAINTAINER_MODE_FALSE MAINTAINER_MODE_TRUE +subdirs AM_BACKSLASH AM_DEFAULT_VERBOSITY AM_DEFAULT_V @@ -808,6 +818,10 @@ with_gnu_ld with_sysroot enable_libtool_lock +with_gsl +with_gsl_includes +with_gsl_libs +enable_gsl_test with_cpl with_cpl_includes with_cpl_libs @@ -829,7 +843,7 @@ DOXYGEN LATEX LT_SYS_LIBRARY_PATH' - +ac_subdirs_all='hdrl' # Initialize some variables set by options. ac_init_help= @@ -1369,7 +1383,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures SINFONI Instrument Pipeline 3.0.0 to adapt to many kinds of systems. +\`configure' configures SINFONI Instrument Pipeline 3.1.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1440,7 +1454,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of SINFONI Instrument Pipeline 3.0.0:";; + short | recursive ) echo "Configuration of SINFONI Instrument Pipeline 3.1.0:";; esac cat <<\_ACEOF @@ -1465,6 +1479,7 @@ --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) + --disable-gsl-test disables checks for the GSL library and headers --disable-cpl-test disables checks for the CPL library and headers --enable-profile compiles with compiler options necessary for profiling (may not work!) [default=no] @@ -1480,6 +1495,9 @@ --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-sysroot[=DIR] Search for dependent libraries within DIR (or the compiler's sysroot if not specified). + --with-gsl location where GSL is installed + --with-gsl-includes location of the GSL header files + --with-gsl-libs location of the GSL library --with-cpl location where CPL is installed --with-cpl-includes location of the CPL header files --with-cpl-libs location of the CPL library @@ -1568,7 +1586,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -SINFONI Instrument Pipeline configure 3.0.0 +SINFONI Instrument Pipeline configure 3.1.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1983,7 +2001,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by SINFONI Instrument Pipeline $as_me 3.0.0, which was +It was created by SINFONI Instrument Pipeline $as_me 3.1.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2962,7 +2980,7 @@ # Define the identity of the package. PACKAGE='sinfo' - VERSION='3.0.0' + VERSION='3.1.0' cat >>confdefs.h <<_ACEOF @@ -3055,6 +3073,10 @@ fi fi + + +subdirs="$subdirs hdrl" + ac_config_headers="$ac_config_headers config.h" @@ -4966,20 +4988,1130 @@ eso_enable_strict_std_set=no - if test -n "$CFLAGS"; then - echo $CFLAGS | $EGREP '(\-std=|-ansi)' >/dev/null 2>&1 - if test x"$?" = x0; then - eso_enable_strict_std_set=yes - fi - fi + if test -n "$CFLAGS"; then + echo $CFLAGS | $EGREP '(\-std=|-ansi)' >/dev/null 2>&1 + if test x"$?" = x0; then + eso_enable_strict_std_set=yes + fi + fi + + if test x"$eso_enable_strict_std_set" = xno; then + + + + flag=`echo std=c99 | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +$as_echo_n "checking whether $CC supports -std=c99... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -std=c99 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -std=c99" + else + : + + fi + + fi + + + + + flag=`echo pedantic | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pedantic" >&5 +$as_echo_n "checking whether $CC supports -pedantic... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -pedantic -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -pedantic -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -pedantic" + else + : + + fi + + + fi + + + + + flag=`echo fno-builtin | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-builtin" >&5 +$as_echo_n "checking whether $CC supports -fno-builtin... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -fno-builtin -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -fno-builtin -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -fno-builtin" + else + : + + fi + + + + + flag=`echo std=c99 | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +$as_echo_n "checking whether $CC supports -std=c99... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -std=c99 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -std=c99" + else + : + + fi + + + + + flag=`echo Werror=implicit-function-declaration | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=implicit-function-declaration" >&5 +$as_echo_n "checking whether $CC supports -Werror=implicit-function-declaration... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=implicit-function-declaration -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=implicit-function-declaration -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="-Werror=implicit-function-declaration $CFLAGS" + else + : + + fi + + + +#From Lars + + + + + flag=`echo Werror=incompatible-pointer-types | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=incompatible-pointer-types" >&5 +$as_echo_n "checking whether $CC supports -Werror=incompatible-pointer-types... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=incompatible-pointer-types -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=incompatible-pointer-types -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=incompatible-pointer-types" + else + : + + fi + +# Werror=format=2 replaced by below for CPL_DIAG_PRAGMA_PUSH_IGN(-Wformat-nonliteral) + + + + flag=`echo Werror=format | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=format" >&5 +$as_echo_n "checking whether $CC supports -Werror=format... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=format -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=format -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=format" + else + : + + fi + + + + + flag=`echo Werror=format-nonliteral | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=format-nonliteral" >&5 +$as_echo_n "checking whether $CC supports -Werror=format-nonliteral... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=format-nonliteral -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=format-nonliteral -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=format-nonliteral" + else + : + + fi + + + + + flag=`echo Werror=format-security | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=format-security" >&5 +$as_echo_n "checking whether $CC supports -Werror=format-security... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=format-security -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=format-security -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS=" $CFLAGS -Werror=format-security" + else + : + + fi + + + + + flag=`echo Werror=format-y2k | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=format-y2k" >&5 +$as_echo_n "checking whether $CC supports -Werror=format-y2k... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=format-y2k -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=format-y2k -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=format-y2k" + else + : + + fi + + + + + flag=`echo Werror=init-self | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=init-self" >&5 +$as_echo_n "checking whether $CC supports -Werror=init-self... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=init-self -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=init-self -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=init-self" + else + : + + fi + + + + + flag=`echo Werror=missing-declarations | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=missing-declarations" >&5 +$as_echo_n "checking whether $CC supports -Werror=missing-declarations... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=missing-declarations -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=missing-declarations -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=missing-declarations" + else + : + + fi + + + + + flag=`echo Werror=missing-format-attribute | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=missing-format-attribute" >&5 +$as_echo_n "checking whether $CC supports -Werror=missing-format-attribute... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=missing-format-attribute -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=missing-format-attribute -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=missing-format-attribute" + else + : + + fi + + + + + flag=`echo Werror=missing-noreturn | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=missing-noreturn" >&5 +$as_echo_n "checking whether $CC supports -Werror=missing-noreturn... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=missing-noreturn -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=missing-noreturn -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=missing-noreturn" + else + : + + fi + + + + + flag=`echo Werror=nested-externs | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=nested-externs" >&5 +$as_echo_n "checking whether $CC supports -Werror=nested-externs... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=nested-externs -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=nested-externs -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=nested-externs" + else + : + + fi + + + + + flag=`echo Werror=pointer-arith | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=pointer-arith" >&5 +$as_echo_n "checking whether $CC supports -Werror=pointer-arith... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=pointer-arith -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=pointer-arith -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=pointer-arith" + else + : + + fi + + + + + flag=`echo Werror=redundant-decls | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=redundant-decls" >&5 +$as_echo_n "checking whether $CC supports -Werror=redundant-decls... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=redundant-decls -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=redundant-decls -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=redundant-decls" + else + : + + fi + + + + + flag=`echo Werror=sign-compare | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=sign-compare" >&5 +$as_echo_n "checking whether $CC supports -Werror=sign-compare... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=sign-compare -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=sign-compare -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=sign-compare" + else + : + + fi + + + + + flag=`echo Werror=undef | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=undef" >&5 +$as_echo_n "checking whether $CC supports -Werror=undef... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=undef -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=undef -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=undef" + else + : + + fi + + + + + flag=`echo Werror=variadic-macros | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=variadic-macros" >&5 +$as_echo_n "checking whether $CC supports -Werror=variadic-macros... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=variadic-macros -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=variadic-macros -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=variadic-macros" + else + : + + fi + + + + + flag=`echo Werror=volatile-register-var | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=volatile-register-var" >&5 +$as_echo_n "checking whether $CC supports -Werror=volatile-register-var... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=volatile-register-var -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=volatile-register-var -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=volatile-register-var" + else + : + + fi + + + + + flag=`echo Werror=write-strings | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=write-strings" >&5 +$as_echo_n "checking whether $CC supports -Werror=write-strings... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=write-strings -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=write-strings -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=write-strings" + else + : + + fi - if test x"$eso_enable_strict_std_set" = xno; then - flag=`echo std=c99 | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 -$as_echo_n "checking whether $CC supports -std=c99... " >&6; } + flag=`echo Werror=old-style-definition | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=old-style-definition" >&5 +$as_echo_n "checking whether $CC supports -Werror=old-style-definition... " >&6; } if eval \${eso_cv_prog_cc_$flag+:} false; then : $as_echo_n "(cached) " >&6 else @@ -4994,9 +6126,9 @@ echo 'int main() { return 0; }' >conftest.$ac_ext - try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`" + try_compile="`$CC -Werror=old-style-definition -c conftest.$ac_ext 2>&1`" if test -z "$try_compile"; then - try_link="`$CC -std=c99 -o conftest$ac_exeext \ + try_link="`$CC -Werror=old-style-definition -o conftest$ac_exeext \ conftest.$ac_ext 2>&1`" if test -z "$try_link"; then eval "eso_cv_prog_cc_$flag=yes" @@ -5018,20 +6150,18 @@ if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : - CFLAGS="$CFLAGS -std=c99" + CFLAGS="$CFLAGS -Werror=old-style-definition" else : fi - fi - - flag=`echo pedantic | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pedantic" >&5 -$as_echo_n "checking whether $CC supports -pedantic... " >&6; } + flag=`echo Werror=missing-prototypes | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=missing-prototypes" >&5 +$as_echo_n "checking whether $CC supports -Werror=missing-prototypes... " >&6; } if eval \${eso_cv_prog_cc_$flag+:} false; then : $as_echo_n "(cached) " >&6 else @@ -5046,9 +6176,9 @@ echo 'int main() { return 0; }' >conftest.$ac_ext - try_compile="`$CC -pedantic -c conftest.$ac_ext 2>&1`" + try_compile="`$CC -Werror=missing-prototypes -c conftest.$ac_ext 2>&1`" if test -z "$try_compile"; then - try_link="`$CC -pedantic -o conftest$ac_exeext \ + try_link="`$CC -Werror=missing-prototypes -o conftest$ac_exeext \ conftest.$ac_ext 2>&1`" if test -z "$try_link"; then eval "eso_cv_prog_cc_$flag=yes" @@ -5070,21 +6200,18 @@ if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : - CFLAGS="$CFLAGS -pedantic" + CFLAGS="$CFLAGS -Wmissing-prototypes" else : fi - fi - - - flag=`echo fno-builtin | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-builtin" >&5 -$as_echo_n "checking whether $CC supports -fno-builtin... " >&6; } + flag=`echo Werror=maybe-uninitialized | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=maybe-uninitialized" >&5 +$as_echo_n "checking whether $CC supports -Werror=maybe-uninitialized... " >&6; } if eval \${eso_cv_prog_cc_$flag+:} false; then : $as_echo_n "(cached) " >&6 else @@ -5099,9 +6226,9 @@ echo 'int main() { return 0; }' >conftest.$ac_ext - try_compile="`$CC -fno-builtin -c conftest.$ac_ext 2>&1`" + try_compile="`$CC -Werror=maybe-uninitialized -c conftest.$ac_ext 2>&1`" if test -z "$try_compile"; then - try_link="`$CC -fno-builtin -o conftest$ac_exeext \ + try_link="`$CC -Werror=maybe-uninitialized -o conftest$ac_exeext \ conftest.$ac_ext 2>&1`" if test -z "$try_link"; then eval "eso_cv_prog_cc_$flag=yes" @@ -5123,7 +6250,7 @@ if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : - CFLAGS="$CFLAGS -fno-builtin" + CFLAGS="$CFLAGS -Wmaybe-uninitialized" else : @@ -5132,9 +6259,11 @@ - flag=`echo std=c99 | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 -$as_echo_n "checking whether $CC supports -std=c99... " >&6; } + + + flag=`echo fno-common | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-common" >&5 +$as_echo_n "checking whether $CC supports -fno-common... " >&6; } if eval \${eso_cv_prog_cc_$flag+:} false; then : $as_echo_n "(cached) " >&6 else @@ -5149,9 +6278,9 @@ echo 'int main() { return 0; }' >conftest.$ac_ext - try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`" + try_compile="`$CC -fno-common -c conftest.$ac_ext 2>&1`" if test -z "$try_compile"; then - try_link="`$CC -std=c99 -o conftest$ac_exeext \ + try_link="`$CC -fno-common -o conftest$ac_exeext \ conftest.$ac_ext 2>&1`" if test -z "$try_link"; then eval "eso_cv_prog_cc_$flag=yes" @@ -5173,7 +6302,7 @@ if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : - CFLAGS="$CFLAGS -std=c99" + CFLAGS="$CFLAGS -fno-common" else : @@ -5182,9 +6311,9 @@ - flag=`echo Werror=implicit-function-declaration | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=implicit-function-declaration" >&5 -$as_echo_n "checking whether $CC supports -Werror=implicit-function-declaration... " >&6; } + flag=`echo fstrict-aliasing | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fstrict-aliasing" >&5 +$as_echo_n "checking whether $CC supports -fstrict-aliasing... " >&6; } if eval \${eso_cv_prog_cc_$flag+:} false; then : $as_echo_n "(cached) " >&6 else @@ -5199,9 +6328,9 @@ echo 'int main() { return 0; }' >conftest.$ac_ext - try_compile="`$CC -Werror=implicit-function-declaration -c conftest.$ac_ext 2>&1`" + try_compile="`$CC -fstrict-aliasing -c conftest.$ac_ext 2>&1`" if test -z "$try_compile"; then - try_link="`$CC -Werror=implicit-function-declaration -o conftest$ac_exeext \ + try_link="`$CC -fstrict-aliasing -o conftest$ac_exeext \ conftest.$ac_ext 2>&1`" if test -z "$try_link"; then eval "eso_cv_prog_cc_$flag=yes" @@ -5223,7 +6352,7 @@ if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : - CFLAGS="-Werror=implicit-function-declaration $CFLAGS" + CFLAGS="$CFLAGS -fstrict-aliasing" else : @@ -5231,6 +6360,9 @@ + + + # Extract the first word of "doxygen", so it can be a program name with args. set dummy doxygen; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 @@ -13175,6 +14307,127 @@ #LIB_CHECK_FFTW + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSL" >&5 +$as_echo_n "checking for GSL... " >&6; } + + gsl_check_gsl_lib="-lgsl -lgslcblas" + + gsl_includes="" + gsl_libraries="" + + +# Check whether --with-gsl was given. +if test "${with_gsl+set}" = set; then : + withval=$with_gsl; + gsl_with_gsl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + gsl_with_gsl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + +fi + + + +# Check whether --with-gsl-includes was given. +if test "${with_gsl_includes+set}" = set; then : + withval=$with_gsl_includes; gsl_with_gsl_includes=$withval +fi + + + +# Check whether --with-gsl-libs was given. +if test "${with_gsl_libs+set}" = set; then : + withval=$with_gsl_libs; gsl_with_gsl_libs=-L$withval +fi + + + # Check whether --enable-gsl-test was given. +if test "${enable_gsl_test+set}" = set; then : + enableval=$enable_gsl_test; gsl_enable_gsl_test=$enableval +else + gsl_enable_gsl_test=yes +fi + + + + if test "x$gsl_enable_gsl_test" = xyes; then + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$gsl_with_gsl_libs"; then + LDFLAGS="$gsl_with_gsl_libs" + elif test -n "$GSLDIR"; then + LDFLAGS="-L$GSLDIR/lib -L$GSLDIR/lib64 -L$GSLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$gsl_with_gsl_includes"; then + CFLAGS="-I$gsl_with_gsl_includes" + elif test -n "$GSLDIR"; then + CFLAGS="-I$GSLDIR/include" + else + CFLAGS="" + fi + LIBS=$gsl_check_gsl_lib + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +gsl_sf_bessel_J0(5.); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_GSL 1" >>confdefs.h + + +$as_echo "#define HAVE_LIBGSL 1" >>confdefs.h + + # Set up the symbols + GSL_INCLUDES="$CFLAGS" + GSL_LDFLAGS="$LDFLAGS" + GSL_LIBS="$gsl_check_gsl_lib" + +else + + if test "x" = xoptional; then + { $as_echo "$as_me:${as_lineno-$LINENO}: Optional GSL not found" >&5 +$as_echo "$as_me: Optional GSL not found" >&6;} + else + as_fn_error $? "GSL not found" "$LINENO" 5 + fi + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 +$as_echo "disabled" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: GSL checks have been disabled! This package may not build!" >&5 +$as_echo "$as_me: WARNING: GSL checks have been disabled! This package may not build!" >&2;} + GSL_INCLUDES="" + GSL_LDFLAGS="" + GSL_LIBS="" + fi + + + + + + # Checks for header files. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } @@ -13872,6 +15125,154 @@ + HDRL_LOCATION="hdrl" + + # check for optional GSL, needed in pipelines to correctly setup + # HDRL_LDFLAGS and HDRL_LIBS and in the case of no GSL being present to not + # declare functions using GSL in the hdrl headers as this requires a + # HAVE_GSL defined in the pipelines config.h + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSL" >&5 +$as_echo_n "checking for GSL... " >&6; } + + gsl_check_gsl_lib="-lgsl -lgslcblas" + + gsl_includes="" + gsl_libraries="" + + +# Check whether --with-gsl was given. +if test "${with_gsl+set}" = set; then : + withval=$with_gsl; + gsl_with_gsl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + gsl_with_gsl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + +fi + + + +# Check whether --with-gsl-includes was given. +if test "${with_gsl_includes+set}" = set; then : + withval=$with_gsl_includes; gsl_with_gsl_includes=$withval +fi + + + +# Check whether --with-gsl-libs was given. +if test "${with_gsl_libs+set}" = set; then : + withval=$with_gsl_libs; gsl_with_gsl_libs=-L$withval +fi + + + # Check whether --enable-gsl-test was given. +if test "${enable_gsl_test+set}" = set; then : + enableval=$enable_gsl_test; gsl_enable_gsl_test=$enableval +else + gsl_enable_gsl_test=yes +fi + + + + if test "x$gsl_enable_gsl_test" = xyes; then + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$gsl_with_gsl_libs"; then + LDFLAGS="$gsl_with_gsl_libs" + elif test -n "$GSLDIR"; then + LDFLAGS="-L$GSLDIR/lib -L$GSLDIR/lib64 -L$GSLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$gsl_with_gsl_includes"; then + CFLAGS="-I$gsl_with_gsl_includes" + elif test -n "$GSLDIR"; then + CFLAGS="-I$GSLDIR/include" + else + CFLAGS="" + fi + LIBS=$gsl_check_gsl_lib + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +gsl_sf_bessel_J0(5.); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_GSL 1" >>confdefs.h + + +$as_echo "#define HAVE_LIBGSL 1" >>confdefs.h + + # Set up the symbols + GSL_INCLUDES="$CFLAGS" + GSL_LDFLAGS="$LDFLAGS" + GSL_LIBS="$gsl_check_gsl_lib" + +else + + if test "xoptional" = xoptional; then + { $as_echo "$as_me:${as_lineno-$LINENO}: Optional GSL not found" >&5 +$as_echo "$as_me: Optional GSL not found" >&6;} + else + as_fn_error $? "GSL not found" "$LINENO" 5 + fi + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 +$as_echo "disabled" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: GSL checks have been disabled! This package may not build!" >&5 +$as_echo "$as_me: WARNING: GSL checks have been disabled! This package may not build!" >&2;} + GSL_INCLUDES="" + GSL_LDFLAGS="" + GSL_LIBS="" + fi + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking HDRL in $HDRL_LOCATION" >&5 +$as_echo_n "checking HDRL in $HDRL_LOCATION... " >&6; } + + # requires cpl and libm as it is a static library + HDRL_LIBS="-lhdrl -lcplcore -lcpldrs -lcplui -lcpldfs -lcext -lm $GSL_LIBS" + # la file to be added to DEPENDENCIES libtool doesn't track static libs + LIBHDRL="\$(top_builddir)/$HDRL_LOCATION/libhdrl.la" + HDRL_LDFLAGS="-L\$(top_builddir)/$HDRL_LOCATION $GSL_LDFLAGS" + HDRL_INCLUDES="-I\$(top_srcdir)/$HDRL_LOCATION" + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } + + # Check for Purify CHECK_PURIFY @@ -14918,7 +16319,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by SINFONI Instrument Pipeline $as_me 3.0.0, which was +This file was extended by SINFONI Instrument Pipeline $as_me 3.1.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -14984,7 +16385,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -SINFONI Instrument Pipeline config.status 3.0.0 +SINFONI Instrument Pipeline config.status 3.1.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -16676,6 +18077,151 @@ # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi + +# +# CONFIG_SUBDIRS section. +# +if test "$no_recursion" != yes; then + + # Remove --cache-file, --srcdir, and --disable-option-checking arguments + # so they do not pile up. + ac_sub_configure_args= + ac_prev= + eval "set x $ac_configure_args" + shift + for ac_arg + do + if test -n "$ac_prev"; then + ac_prev= + continue + fi + case $ac_arg in + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \ + | --c=*) + ;; + --config-cache | -C) + ;; + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + ;; + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + ;; + --disable-option-checking) + ;; + *) + case $ac_arg in + *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append ac_sub_configure_args " '$ac_arg'" ;; + esac + done + + # Always prepend --prefix to ensure using the same prefix + # in subdir configurations. + ac_arg="--prefix=$prefix" + case $ac_arg in + *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + ac_sub_configure_args="'$ac_arg' $ac_sub_configure_args" + + # Pass --silent + if test "$silent" = yes; then + ac_sub_configure_args="--silent $ac_sub_configure_args" + fi + + # Always prepend --disable-option-checking to silence warnings, since + # different subdirs can have different --enable and --with options. + ac_sub_configure_args="--disable-option-checking $ac_sub_configure_args" + + ac_popdir=`pwd` + for ac_dir in : $subdirs; do test "x$ac_dir" = x: && continue + + # Do not complain, so a configure script can configure whichever + # parts of a large source tree are present. + test -d "$srcdir/$ac_dir" || continue + + ac_msg="=== configuring in $ac_dir (`pwd`/$ac_dir)" + $as_echo "$as_me:${as_lineno-$LINENO}: $ac_msg" >&5 + $as_echo "$ac_msg" >&6 + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + cd "$ac_dir" + + # Check for guested configure; otherwise get Cygnus style configure. + if test -f "$ac_srcdir/configure.gnu"; then + ac_sub_configure=$ac_srcdir/configure.gnu + elif test -f "$ac_srcdir/configure"; then + ac_sub_configure=$ac_srcdir/configure + elif test -f "$ac_srcdir/configure.in"; then + # This should be Cygnus configure. + ac_sub_configure=$ac_aux_dir/configure + else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: no configuration information is in $ac_dir" >&5 +$as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2;} + ac_sub_configure= + fi + + # The recursion is here. + if test -n "$ac_sub_configure"; then + # Make the cache file name correct relative to the subdirectory. + case $cache_file in + [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;; + *) # Relative name. + ac_sub_cache_file=$ac_top_build_prefix$cache_file ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5 +$as_echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&6;} + # The eval makes quoting arguments work. + eval "\$SHELL \"\$ac_sub_configure\" $ac_sub_configure_args \ + --cache-file=\"\$ac_sub_cache_file\" --srcdir=\"\$ac_srcdir\"" || + as_fn_error $? "$ac_sub_configure failed for $ac_dir" "$LINENO" 5 + fi + + cd "$ac_popdir" + done +fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/configure.ac cpl-plugin-sinfo-3.1.0+dfsg/configure.ac --- cpl-plugin-sinfo-3.0.0+dfsg/configure.ac 2017-04-20 11:35:01.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/configure.ac 2018-03-13 15:32:40.000000000 +0000 @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([SINFONI Instrument Pipeline], [3.0.0], [usd-help@eso.org], [sinfo]) +AC_INIT([SINFONI Instrument Pipeline], [3.1.0], [usd-help@eso.org], [sinfo]) AC_PREREQ([2.59]) @@ -11,6 +11,7 @@ AC_CANONICAL_TARGET AM_INIT_AUTOMAKE +AC_CONFIG_SUBDIRS([hdrl]) AC_CONFIG_HEADERS([config.h]) AM_MAINTAINER_MODE([enable]) @@ -46,6 +47,57 @@ ESO_PROG_CC_FLAG([std=c99], [CFLAGS="$CFLAGS -std=c99"]) ESO_PROG_CC_FLAG([Werror=implicit-function-declaration], [CFLAGS="-Werror=implicit-function-declaration $CFLAGS"]) + + +#From Lars + +ESO_PROG_CC_FLAG([Werror=incompatible-pointer-types], + [CFLAGS="$CFLAGS -Werror=incompatible-pointer-types"]) +# Werror=format=2 replaced by below for CPL_DIAG_PRAGMA_PUSH_IGN(-Wformat-nonliteral) +ESO_PROG_CC_FLAG([Werror=format], [CFLAGS="$CFLAGS -Werror=format"]) +ESO_PROG_CC_FLAG([Werror=format-nonliteral], + [CFLAGS="$CFLAGS -Werror=format-nonliteral"]) +ESO_PROG_CC_FLAG([Werror=format-security], + [CFLAGS=" $CFLAGS -Werror=format-security"]) +ESO_PROG_CC_FLAG([Werror=format-y2k], + [CFLAGS="$CFLAGS -Werror=format-y2k"]) +ESO_PROG_CC_FLAG([Werror=init-self], + [CFLAGS="$CFLAGS -Werror=init-self"]) +ESO_PROG_CC_FLAG([Werror=missing-declarations], + [CFLAGS="$CFLAGS -Werror=missing-declarations"]) +ESO_PROG_CC_FLAG([Werror=missing-format-attribute], + [CFLAGS="$CFLAGS -Werror=missing-format-attribute"]) +ESO_PROG_CC_FLAG([Werror=missing-noreturn], + [CFLAGS="$CFLAGS -Werror=missing-noreturn"]) +ESO_PROG_CC_FLAG([Werror=nested-externs], + [CFLAGS="$CFLAGS -Werror=nested-externs"]) +ESO_PROG_CC_FLAG([Werror=pointer-arith], + [CFLAGS="$CFLAGS -Werror=pointer-arith"]) +ESO_PROG_CC_FLAG([Werror=redundant-decls], + [CFLAGS="$CFLAGS -Werror=redundant-decls"]) +ESO_PROG_CC_FLAG([Werror=sign-compare], + [CFLAGS="$CFLAGS -Werror=sign-compare"]) +ESO_PROG_CC_FLAG([Werror=undef], + [CFLAGS="$CFLAGS -Werror=undef"]) +ESO_PROG_CC_FLAG([Werror=variadic-macros], + [CFLAGS="$CFLAGS -Werror=variadic-macros"]) +ESO_PROG_CC_FLAG([Werror=volatile-register-var], + [CFLAGS="$CFLAGS -Werror=volatile-register-var"]) +ESO_PROG_CC_FLAG([Werror=write-strings], + [CFLAGS="$CFLAGS -Werror=write-strings"]) +ESO_PROG_CC_FLAG([Werror=old-style-definition], + [CFLAGS="$CFLAGS -Werror=old-style-definition"]) +ESO_PROG_CC_FLAG([Werror=missing-prototypes], + [CFLAGS="$CFLAGS -Wmissing-prototypes"]) +ESO_PROG_CC_FLAG([Werror=maybe-uninitialized], + [CFLAGS="$CFLAGS -Wmaybe-uninitialized"]) + + +ESO_PROG_CC_FLAG([fno-common], [CFLAGS="$CFLAGS -fno-common"]) +ESO_PROG_CC_FLAG([fstrict-aliasing], [CFLAGS="$CFLAGS -fstrict-aliasing"]) + + + ESO_CHECK_DOCTOOLS AC_ENABLE_STATIC(no) @@ -60,6 +112,7 @@ AC_CHECK_LIB(nsl, inet_ntoa, [LIBS="$LIBS -lnsl"]) #LIB_CHECK_FFTW +GSL_CHECK_LIBS # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS([string.h]) @@ -74,6 +127,7 @@ # Check for CPL/Qfits presence and usability CPL_CHECK_LIBS +HDRL_CHECK([hdrl]) # Check for Purify CHECK_PURIFY diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/changelog cpl-plugin-sinfo-3.1.0+dfsg/debian/changelog --- cpl-plugin-sinfo-3.0.0+dfsg/debian/changelog 2017-07-02 08:56:21.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/changelog 2018-04-27 12:21:33.000000000 +0000 @@ -1,3 +1,16 @@ +cpl-plugin-sinfo (3.1.0+dfsg-1) unstable; urgency=low + + * Add d/u/metadata + * Update VCS fields to use salsa.d.o + * Use name-based sorting for the recipes to ensure reproducible build + * New upstream version 3.1.0+dfsg. Rediff patches + * Push Standards-Version to 4.1.4. Change remaining URLs to https + * Push compat to 11 + * Switch to Python 3 + * Adjust documentation path + + -- Ole Streicher Fri, 27 Apr 2018 14:21:33 +0200 + cpl-plugin-sinfo (3.0.0+dfsg-1) unstable; urgency=low * New upstream version 3.0.0+dfsg diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/compat cpl-plugin-sinfo-3.1.0+dfsg/debian/compat --- cpl-plugin-sinfo-3.0.0+dfsg/debian/compat 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/compat 2018-04-27 12:19:09.000000000 +0000 @@ -1 +1 @@ -9 +11 diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/control cpl-plugin-sinfo-3.1.0+dfsg/debian/control --- cpl-plugin-sinfo-3.0.0+dfsg/debian/control 2017-07-02 08:56:11.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/control 2018-04-27 12:21:33.000000000 +0000 @@ -3,22 +3,22 @@ Priority: optional Maintainer: Debian Astronomy Maintainers Uploaders: Ole Streicher -Build-Depends: debhelper (>= 9), - dh-autoreconf, +Build-Depends: debhelper (>= 11), libcpl-dev (>= 5.3.1), - python, - python-astropy, - python-cpl, - python-sphinx -Standards-Version: 4.0.0 -Homepage: http://www.eso.org/sci/software/pipelines/sinfoni/sinfoni-pipe-recipes.html -Vcs-Git: https://anonscm.debian.org/git/debian-astro/packages/cpl-plugin-sinfo.git -Vcs-Browser: https://anonscm.debian.org/cgit/debian-astro/packages/cpl-plugin-sinfo.git + libgsl-dev, + python3, + python3-astropy, + python3-cpl, + python3-sphinx +Standards-Version: 4.1.4 +Homepage: https://www.eso.org/sci/software/pipelines/sinfoni/sinfoni-pipe-recipes.html +Vcs-Git: https://salsa.debian.org/debian-astro-team/cpl-plugin-sinfo.git +Vcs-Browser: https://salsa.debian.org/debian-astro-team/cpl-plugin-sinfo Package: cpl-plugin-sinfo Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends} -Recommends: esorex|python-cpl +Recommends: esorex | python3-cpl Suggests: cpl-plugin-sinfo-calib (= ${binary:Version}), cpl-plugin-sinfo-doc Multi-Arch: same Description: ESO data reduction pipeline for the SINFONI instrument @@ -50,7 +50,7 @@ Architecture: all Multi-Arch: foreign Section: contrib/science -Depends: ${misc:Depends}, cpl-plugin-sinfo, wget +Depends: cpl-plugin-sinfo, wget, ${misc:Depends} Description: ESO data reduction pipeline calibration data downloader for SINFONI This package downloads calibration data of the data reduction pipeline for the SINFONI instrument of the Very Large Telescope (VLT) from the European diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/copyright cpl-plugin-sinfo-3.1.0+dfsg/debian/copyright --- cpl-plugin-sinfo-3.0.0+dfsg/debian/copyright 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/copyright 2018-04-27 12:21:33.000000000 +0000 @@ -1,4 +1,4 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: sinfo Upstream-Contact: ESO User Support Department Source: ftp://ftp.eso.org/pub/dfs/pipelines/sinfoni/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/cpl-plugin-doc.doc-base.in cpl-plugin-sinfo-3.1.0+dfsg/debian/cpl-plugin-doc.doc-base.in --- cpl-plugin-sinfo-3.0.0+dfsg/debian/cpl-plugin-doc.doc-base.in 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/cpl-plugin-doc.doc-base.in 2018-04-27 12:21:33.000000000 +0000 @@ -12,5 +12,5 @@ This document describes the Python interface for the __PIPELINE__ pipeline. Format: HTML -Index: /usr/share/doc/cpl-plugin-__PIPELINE__-doc/html/index.html -Files: /usr/share/doc/cpl-plugin-__PIPELINE__-doc/html/* +Index: /usr/share/doc/cpl-plugin-__PIPELINE__/html/index.html +Files: /usr/share/doc/cpl-plugin-__PIPELINE__/html/* diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/create_manpage.py cpl-plugin-sinfo-3.1.0+dfsg/debian/create_manpage.py --- cpl-plugin-sinfo-3.0.0+dfsg/debian/create_manpage.py 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/create_manpage.py 2018-04-27 12:20:26.000000000 +0000 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import cpl import os @@ -31,13 +31,13 @@ .B ftp://ftp.eso.org/pub/dfs/pipelines/{pipeline}ni/{pipeline}-pipeline-manual-19.0.pdf .PP An overview over the existing ESO pipelines can be found on the web page -\\fBhttp://www.eso.org/sci/software/pipelines/\\fR. +\\fBhttps://www.eso.org/sci/software/pipelines/\\fR. .PP Basic documentation about the EsoRex program can be found at the esorex (1) man page. .PP It is possible to call the pipelines from python using the python-cpl package. -See \\fBhttp://packages.python.org/python-cpl/index.html\\fR for further +See \\fBhttps://packages.python.org/python-cpl/index.html\\fR for further information. .PP The other recipes of the {pipeline} pipeline are diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/create_sphinx.py cpl-plugin-sinfo-3.1.0+dfsg/debian/create_sphinx.py --- cpl-plugin-sinfo-3.0.0+dfsg/debian/create_sphinx.py 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/create_sphinx.py 2018-04-27 12:20:35.000000000 +0000 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import cpl import os @@ -35,7 +35,7 @@ {parameters} -.. seealso:: `cpl.Recipe `_ +.. seealso:: `cpl.Recipe `_ for more information about the recipe object. Bug reports @@ -78,10 +78,10 @@ * The `{PIPELINE} Pipeline User Manual `_ in PDF format, - * an `overview `_ + * an `overview `_ over the existing ESO pipelines, - * the `python-cpl `_ package. + * the `python-cpl `_ package. Bug reports =========== @@ -139,11 +139,10 @@ cpl.Recipe.path = "recipes" recipes = [ cpl.Recipe(name) for name, version in cpl.Recipe.list() ] -oca = file(os.path.join("calib", "gasgano", "config", pipeline + ".oca")).read() +oca = open(os.path.join("calib", "gasgano", "config", pipeline + ".oca")).read() oca = oca[oca.find("action"):] recipes_oca = [recipe for recipe in recipes if recipe.__name__ in oca] -index = [ oca.find(recipe.__name__) for recipe in recipes_oca ] -recipes_oca = [r for (i, r) in sorted(zip(index, recipes_oca))] +recipes_oca.sort(key = lambda x: x.__name__) recipes_x = [recipe for recipe in recipes if not recipe.__name__ in oca] recipes_x.sort(key = lambda x: x.__name__) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/patches/fix_test_fail.patch cpl-plugin-sinfo-3.1.0+dfsg/debian/patches/fix_test_fail.patch --- cpl-plugin-sinfo-3.0.0+dfsg/debian/patches/fix_test_fail.patch 2017-07-02 08:56:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/patches/fix_test_fail.patch 2018-04-27 12:18:33.000000000 +0000 @@ -7,10 +7,10 @@ 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/irplib/tests/irplib_polynomial-test.c b/irplib/tests/irplib_polynomial-test.c -index c27d167..d5cdf86 100644 +index cead713..8b02e90 100644 --- a/irplib/tests/irplib_polynomial-test.c +++ b/irplib/tests/irplib_polynomial-test.c -@@ -579,16 +579,16 @@ irplib_polynomial_test_root_all_macro(const cpl_vector * self, cpl_size nreal, +@@ -589,16 +589,16 @@ irplib_polynomial_test_root_all_macro(const cpl_vector * self, cpl_size nreal, const double root = cpl_vector_get(roots, i); const double residual = cpl_polynomial_eval_1d(p1d, root, NULL); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/patches/force-serial-tests.patch cpl-plugin-sinfo-3.1.0+dfsg/debian/patches/force-serial-tests.patch --- cpl-plugin-sinfo-3.0.0+dfsg/debian/patches/force-serial-tests.patch 2017-07-02 08:56:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/patches/force-serial-tests.patch 2018-04-27 12:18:33.000000000 +0000 @@ -23,7 +23,7 @@ DISTCLEANFILES = *~ diff --git a/recipes/tests/Makefile.am b/recipes/tests/Makefile.am -index 5663e83..f58c0eb 100644 +index ad79a30..82b3b79 100644 --- a/recipes/tests/Makefile.am +++ b/recipes/tests/Makefile.am @@ -17,7 +17,7 @@ @@ -49,7 +49,7 @@ DISTCLEANFILES = *~ diff --git a/sinfoni/tests/Makefile.am b/sinfoni/tests/Makefile.am -index 3837777..2decd0f 100644 +index 0b51929..fd2d2ea 100644 --- a/sinfoni/tests/Makefile.am +++ b/sinfoni/tests/Makefile.am @@ -17,7 +17,7 @@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/patches/set_plugindir.patch cpl-plugin-sinfo-3.1.0+dfsg/debian/patches/set_plugindir.patch --- cpl-plugin-sinfo-3.0.0+dfsg/debian/patches/set_plugindir.patch 2017-07-02 08:56:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/patches/set_plugindir.patch 2018-04-27 12:18:33.000000000 +0000 @@ -7,7 +7,7 @@ 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acinclude.m4 b/acinclude.m4 -index 02b4b11..3e96b50 100644 +index 90b43f6..42eb43c 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -216,7 +216,7 @@ AC_DEFUN([SINFONI_SET_PATHS], diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/rules cpl-plugin-sinfo-3.1.0+dfsg/debian/rules --- cpl-plugin-sinfo-3.0.0+dfsg/debian/rules 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/rules 2018-04-27 12:21:33.000000000 +0000 @@ -2,16 +2,16 @@ # -*- makefile -*- #export DH_VERBOSE=1 -DEBVERS ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p') -VERSION ?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/+.*//') -DEBPKGNAME ?= $(shell dpkg-parsechangelog | grep -E ^Source: | cut -d" " -f2) -PIPELINE ?= $(shell echo '$(DEBPKGNAME)' | sed -e 's/cpl-plugin-//') +include /usr/share/dpkg/pkg-info.mk + +VERSION ?= $(shell echo '$(DEB_VERSION)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/+.*//') +PIPELINE ?= $(shell echo '$(DEB_SOURCE)' | sed -e 's/cpl-plugin-//') get-orig-source: sh ./debian/repackage.sh %: - dh $@ --with autoreconf,sphinxdoc + dh $@ --with sphinxdoc debian_files: if [ -d calib/cal ] ; then \ @@ -23,7 +23,7 @@ for f in $$dfiles ; do \ sed "s/__VERSION__/$(VERSION)/g;s/__PIPELINE__/${PIPELINE}/g" \ < debian/cpl-plugin$$f.in \ - > debian/${DEBPKGNAME}$$f ; \ + > debian/${DEB_SOURCE}$$f ; \ done override_dh_install: debian_files @@ -31,12 +31,12 @@ override_dh_installman-indep: mkdir -p man - python debian/create_manpage.py ${PIPELINE} + python3 debian/create_manpage.py ${PIPELINE} dh_installman override_dh_installdocs-indep: mkdir -p sphinx - python debian/create_sphinx.py ${PIPELINE} + python3 debian/create_sphinx.py ${PIPELINE} sphinx-build sphinx sphinx/html dh_installdocs @@ -47,14 +47,14 @@ override_dh_clean: dh_clean - rm -rf debian/${DEBPKGNAME}.install \ - debian/${DEBPKGNAME}-doc.manpages \ - debian/${DEBPKGNAME}-doc.docs \ - debian/${DEBPKGNAME}-doc.doc-base \ - debian/${DEBPKGNAME}-calib.lintian-overrides \ - debian/${DEBPKGNAME}-calib.install \ - debian/${DEBPKGNAME}-calib.postinst \ - debian/${DEBPKGNAME}-calib.prerm \ + rm -rf debian/${DEB_SOURCE}.install \ + debian/${DEB_SOURCE}-doc.manpages \ + debian/${DEB_SOURCE}-doc.docs \ + debian/${DEB_SOURCE}-doc.doc-base \ + debian/${DEB_SOURCE}-calib.lintian-overrides \ + debian/${DEB_SOURCE}-calib.install \ + debian/${DEB_SOURCE}-calib.postinst \ + debian/${DEB_SOURCE}-calib.prerm \ debian/README.Debian \ man sphinx @@ -74,7 +74,7 @@ override_dh_gencontrol-indep: dh_gencontrol if [ ! -d calib/cal ] ; then \ - sed "s/Installed-Size:.*/Installed-Size: $(shell cat calib/cal_size)/" -i debian/${DEBPKGNAME}-calib/DEBIAN/control ; \ + sed "s/Installed-Size:.*/Installed-Size: $(shell cat calib/cal_size)/" -i debian/${DEB_SOURCE}-calib/DEBIAN/control ; \ fi override_dh_auto_test: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/tests/control cpl-plugin-sinfo-3.1.0+dfsg/debian/tests/control --- cpl-plugin-sinfo-3.0.0+dfsg/debian/tests/control 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/tests/control 2018-04-27 12:20:44.000000000 +0000 @@ -1,2 +1,2 @@ Tests: test-recipe.py -Depends: cpl-plugin-sinfo, python-cpl, python-astropy +Depends: cpl-plugin-sinfo, python3-cpl, python3-astropy diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/tests/test-recipe.py cpl-plugin-sinfo-3.1.0+dfsg/debian/tests/test-recipe.py --- cpl-plugin-sinfo-3.0.0+dfsg/debian/tests/test-recipe.py 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/tests/test-recipe.py 2018-04-27 12:20:51.000000000 +0000 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Simple pipeline test by loading all recipes and printing some diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/upstream/metadata cpl-plugin-sinfo-3.1.0+dfsg/debian/upstream/metadata --- cpl-plugin-sinfo-3.0.0+dfsg/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/upstream/metadata 2018-04-27 12:18:33.000000000 +0000 @@ -0,0 +1,19 @@ +ASCL-Id: 1708.019 +Contact: usd-help@eso.org +Name: sinfo-kit +Reference: + Author: > + Eisenhauer, F. and Abuter, R. and Bickert, K. and Biancat-Marchet, F. and + Bonnet, H. and Brynnel, J. and Conzelmann, R.D. and Delabre, B. and + Donaldson, R. and Farinato, J. and Fedrigo, E. and Genzel, R. and + Hubin, N.N. and Iserlohe, C. and Kasper, M.E. and Kissler-Patig, M. and + Monnet, G.J. and Roehrle, C. and Schreiber, J. and Stroebele, S. and + Tecza, M. and Thatte, N.A. and Weisz, H. + Title: SINFONI - Integral field spectroscopy at 50 milli-arcsecond resolution with the ESO VLT + Journal: Instrument Design and Performance for Optical/Infrared Ground-based Telescopes + Year: 2003 + Volume: 4841 + Pages: 1548-1561 + URL: https://www.spiedigitallibrary.org/conference-proceedings-of-spie/4841/1/SINFONI--integral-field-spectroscopy-at-50-milli-arcsecond-resolution/10.1117/12.459468.short + eprint: https://arxiv.org/pdf/astro-ph/0306191.pdf + Doi: 10.1117/12.459468 diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/debian/watch cpl-plugin-sinfo-3.1.0+dfsg/debian/watch --- cpl-plugin-sinfo-3.0.0+dfsg/debian/watch 2016-11-20 09:32:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/debian/watch 2018-04-27 12:18:33.000000000 +0000 @@ -1,6 +1,6 @@ version=3 opts=dversionmangle=s/\+dfsg// \ -http://www.eso.org/sci/software/pipelines/ \ +https://www.eso.org/sci/software/pipelines/ \ .*/sinfo-kit-([\d\.]+)(?:-.+)?\.(?:tgz|tbz2|txz|tar\.(?:gz|bz2|xz)) \ debian debian/repackage.sh #opts=uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha|b|a)[\-\.]?\d*)$/$1~$2/ \ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/doxygen/Doxyfile.in cpl-plugin-sinfo-3.1.0+dfsg/doxygen/Doxyfile.in --- cpl-plugin-sinfo-3.0.0+dfsg/doxygen/Doxyfile.in 2006-11-04 15:29:10.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/doxygen/Doxyfile.in 2017-10-03 08:50:43.000000000 +0000 @@ -180,8 +180,8 @@ GRAPHICAL_HIERARCHY = NO DOT_PATH = DOTFILE_DIRS = -MAX_DOT_GRAPH_WIDTH = 1024 -MAX_DOT_GRAPH_HEIGHT = 1024 +#MAX_DOT_GRAPH_WIDTH = 1024 +#MAX_DOT_GRAPH_HEIGHT = 1024 GENERATE_LEGEND = YES DOT_CLEANUP = YES @@ -189,9 +189,9 @@ # Configuration::addtions related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO -CGI_NAME = -CGI_URL = -DOC_URL = -DOC_ABSPATH = -BIN_ABSPATH = -EXT_DOC_PATHS = +#CGI_NAME = +#CGI_URL = +#DOC_URL = +#DOC_ABSPATH = +#BIN_ABSPATH = +#EXT_DOC_PATHS = diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/acinclude.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/acinclude.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/acinclude.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/acinclude.m4 2016-06-23 12:04:54.000000000 +0000 @@ -0,0 +1,98 @@ +# on SL6 aclocal 1.11 doesn't check this folder even though its in +# AC_CONFIG_MACRO_DIR. Fixed in later aclocal versions +m4_include([m4macros/cpl-pipeline.m4]) +m4_include([m4macros/eso.m4]) + +# HDRL_SET_VERSION_INFO(VERSION, [CURRENT], [REVISION], [AGE]) +#---------------------------------------------------------------- +# Setup various version information, especially the libtool versioning +AC_DEFUN([HDRL_SET_VERSION_INFO], +[ + hdrldemo_version=`echo "$1" | sed -e 's/[[a-z,A-Z]].*$//'` + + hdrldemo_major_version=`echo "$hdrldemo_version" | \ + sed 's/\([[0-9]]*\).\(.*\)/\1/'` + hdrldemo_minor_version=`echo "$hdrldemo_version" | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\)\(.*\)/\2/'` + hdrldemo_micro_version=`echo "$hdrldemo_version" | \ + sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` + + if test -z "$hdrldemo_major_version"; then hdrldemo_major_version=0 + fi + + if test -z "$hdrldemo_minor_version"; then hdrldemo_minor_version=0 + fi + + if test -z "$hdrldemo_micro_version"; then hdrldemo_micro_version=0 + fi + + HDRL_VERSION="$hdrldemo_version" + HDRL_MAJOR_VERSION=$hdrldemo_major_version + HDRL_MINOR_VERSION=$hdrldemo_minor_version + HDRL_MICRO_VERSION=$hdrldemo_micro_version + + if test -z "$4"; then HDRL_INTERFACE_AGE=0 + else HDRL_INTERFACE_AGE="$4" + fi + + HDRL_BINARY_AGE=`expr 100 '*' $HDRL_MINOR_VERSION + $HDRL_MICRO_VERSION` + HDRL_BINARY_VERSION=`expr 10000 '*' $HDRL_MAJOR_VERSION + \ + $HDRL_BINARY_AGE` + + AC_SUBST(HDRL_VERSION) + AC_SUBST(HDRL_MAJOR_VERSION) + AC_SUBST(HDRL_MINOR_VERSION) + AC_SUBST(HDRL_MICRO_VERSION) + AC_SUBST(HDRL_INTERFACE_AGE) + AC_SUBST(HDRL_BINARY_VERSION) + AC_SUBST(HDRL_BINARY_AGE) + + AC_DEFINE_UNQUOTED(HDRL_MAJOR_VERSION, $HDRL_MAJOR_VERSION, + [HDRL major version number]) + AC_DEFINE_UNQUOTED(HDRL_MINOR_VERSION, $HDRL_MINOR_VERSION, + [HDRL minor version number]) + AC_DEFINE_UNQUOTED(HDRL_MICRO_VERSION, $HDRL_MICRO_VERSION, + [HDRL micro version number]) + AC_DEFINE_UNQUOTED(HDRL_INTERFACE_AGE, $HDRL_INTERFACE_AGE, + [HDRL interface age]) + AC_DEFINE_UNQUOTED(HDRL_BINARY_VERSION, $HDRL_BINARY_VERSION, + [HDRL binary version number]) + AC_DEFINE_UNQUOTED(HDRL_BINARY_AGE, $HDRL_BINARY_AGE, + [HDRL binary age]) + + ESO_SET_LIBRARY_VERSION([$2], [$3], [$4]) +]) + + +# HDRL_CREATE_SYMBOLS +#----------------------- +# Define include and library related makefile symbols +AC_DEFUN([HDRL_CREATE_SYMBOLS], +[ + + # Symbols for package include file and library search paths + + HDRL_INCLUDES='-I$(top_srcdir)' + HDRL_LDFLAGS='-L$(top_builddir)' + + # Library aliases + + LIBHDRL='$(top_builddir)/libhdrl.la' + + # Substitute the defined symbols + + AC_SUBST(HDRL_INCLUDES) + AC_SUBST(HDRL_LDFLAGS) + + AC_SUBST(LIBHDRL) + AC_SUBST(LIBHDRL) + + # Check for CPL and user defined libraries + AC_REQUIRE([ESO_CHECK_CPL]) + + all_includes='$(HDRL_INCLUDES) $(CPL_INCLUDES)' + all_ldflags='$(HDRL_LDFLAGS) $(CPL_LDFLAGS)' + + AC_SUBST(all_includes) + AC_SUBST(all_ldflags) +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/aclocal.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/aclocal.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/aclocal.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/aclocal.m4 2018-04-13 15:46:29.000000000 +0000 @@ -0,0 +1,1218 @@ +# generated automatically by aclocal 1.15 -*- Autoconf -*- + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, +[m4_warning([this file was generated for autoconf 2.69. +You have another version of autoconf. It may work, but is not guaranteed to. +If you have problems, you may need to regenerate the build system entirely. +To do so, use the procedure documented by the package, typically 'autoreconf'.])]) + +# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_AUTOMAKE_VERSION(VERSION) +# ---------------------------- +# Automake X.Y traces this macro to ensure aclocal.m4 has been +# generated from the m4 files accompanying Automake X.Y. +# (This private macro should not be called outside this file.) +AC_DEFUN([AM_AUTOMAKE_VERSION], +[am__api_version='1.15' +dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to +dnl require some minimum version. Point them to the right macro. +m4_if([$1], [1.15], [], + [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl +]) + +# _AM_AUTOCONF_VERSION(VERSION) +# ----------------------------- +# aclocal traces this macro to find the Autoconf version. +# This is a private macro too. Using m4_define simplifies +# the logic in aclocal, which can simply ignore this definition. +m4_define([_AM_AUTOCONF_VERSION], []) + +# AM_SET_CURRENT_AUTOMAKE_VERSION +# ------------------------------- +# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. +# This function is AC_REQUIREd by AM_INIT_AUTOMAKE. +AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], +[AM_AUTOMAKE_VERSION([1.15])dnl +m4_ifndef([AC_AUTOCONF_VERSION], + [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl +_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) + +# AM_AUX_DIR_EXPAND -*- Autoconf -*- + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets +# $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to +# '$srcdir', '$srcdir/..', or '$srcdir/../..'. +# +# Of course, Automake must honor this variable whenever it calls a +# tool from the auxiliary directory. The problem is that $srcdir (and +# therefore $ac_aux_dir as well) can be either absolute or relative, +# depending on how configure is run. This is pretty annoying, since +# it makes $ac_aux_dir quite unusable in subdirectories: in the top +# source directory, any form will work fine, but in subdirectories a +# relative path needs to be adjusted first. +# +# $ac_aux_dir/missing +# fails when called from a subdirectory if $ac_aux_dir is relative +# $top_srcdir/$ac_aux_dir/missing +# fails if $ac_aux_dir is absolute, +# fails when called from a subdirectory in a VPATH build with +# a relative $ac_aux_dir +# +# The reason of the latter failure is that $top_srcdir and $ac_aux_dir +# are both prefixed by $srcdir. In an in-source build this is usually +# harmless because $srcdir is '.', but things will broke when you +# start a VPATH build or use an absolute $srcdir. +# +# So we could use something similar to $top_srcdir/$ac_aux_dir/missing, +# iff we strip the leading $srcdir from $ac_aux_dir. That would be: +# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` +# and then we would define $MISSING as +# MISSING="\${SHELL} $am_aux_dir/missing" +# This will work as long as MISSING is not called from configure, because +# unfortunately $(top_srcdir) has no meaning in configure. +# However there are other variables, like CC, which are often used in +# configure, and could therefore not use this "fixed" $ac_aux_dir. +# +# Another solution, used here, is to always expand $ac_aux_dir to an +# absolute PATH. The drawback is that using absolute paths prevent a +# configured tree to be moved without reconfiguration. + +AC_DEFUN([AM_AUX_DIR_EXPAND], +[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` +]) + +# AM_CONDITIONAL -*- Autoconf -*- + +# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_CONDITIONAL(NAME, SHELL-CONDITION) +# ------------------------------------- +# Define a conditional. +AC_DEFUN([AM_CONDITIONAL], +[AC_PREREQ([2.52])dnl + m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], + [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl +AC_SUBST([$1_TRUE])dnl +AC_SUBST([$1_FALSE])dnl +_AM_SUBST_NOTMAKE([$1_TRUE])dnl +_AM_SUBST_NOTMAKE([$1_FALSE])dnl +m4_define([_AM_COND_VALUE_$1], [$2])dnl +if $2; then + $1_TRUE= + $1_FALSE='#' +else + $1_TRUE='#' + $1_FALSE= +fi +AC_CONFIG_COMMANDS_PRE( +[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then + AC_MSG_ERROR([[conditional "$1" was never defined. +Usually this means the macro was only invoked conditionally.]]) +fi])]) + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + + +# There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be +# written in clear, in which case automake, when reading aclocal.m4, +# will think it sees a *use*, and therefore will trigger all it's +# C support machinery. Also note that it means that autoscan, seeing +# CC etc. in the Makefile, will ask for an AC_PROG_CC use... + + +# _AM_DEPENDENCIES(NAME) +# ---------------------- +# See how the compiler implements dependency checking. +# NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". +# We try a few techniques and use that to set a single cache variable. +# +# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was +# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular +# dependency, and given that the user is not expected to run this macro, +# just rely on AC_PROG_CC. +AC_DEFUN([_AM_DEPENDENCIES], +[AC_REQUIRE([AM_SET_DEPDIR])dnl +AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl +AC_REQUIRE([AM_MAKE_INCLUDE])dnl +AC_REQUIRE([AM_DEP_TRACK])dnl + +m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], + [$1], [CXX], [depcc="$CXX" am_compiler_list=], + [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], + [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], + [$1], [UPC], [depcc="$UPC" am_compiler_list=], + [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], + [depcc="$$1" am_compiler_list=]) + +AC_CACHE_CHECK([dependency style of $depcc], + [am_cv_$1_dependencies_compiler_type], +[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_$1_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` + fi + am__universal=false + m4_case([$1], [CC], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac], + [CXX], + [case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac]) + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_$1_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_$1_dependencies_compiler_type=none +fi +]) +AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) +AM_CONDITIONAL([am__fastdep$1], [ + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) +]) + + +# AM_SET_DEPDIR +# ------------- +# Choose a directory name for dependency files. +# This macro is AC_REQUIREd in _AM_DEPENDENCIES. +AC_DEFUN([AM_SET_DEPDIR], +[AC_REQUIRE([AM_SET_LEADING_DOT])dnl +AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl +]) + + +# AM_DEP_TRACK +# ------------ +AC_DEFUN([AM_DEP_TRACK], +[AC_ARG_ENABLE([dependency-tracking], [dnl +AS_HELP_STRING( + [--enable-dependency-tracking], + [do not reject slow dependency extractors]) +AS_HELP_STRING( + [--disable-dependency-tracking], + [speeds up one-time build])]) +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi +AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) +AC_SUBST([AMDEPBACKSLASH])dnl +_AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl +AC_SUBST([am__nodep])dnl +_AM_SUBST_NOTMAKE([am__nodep])dnl +]) + +# Generate code to set up dependency tracking. -*- Autoconf -*- + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + + +# _AM_OUTPUT_DEPENDENCY_COMMANDS +# ------------------------------ +AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], +[{ + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`AS_DIRNAME("$mf")` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`AS_DIRNAME(["$file"])` + AS_MKDIR_P([$dirpart/$fdir]) + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} +])# _AM_OUTPUT_DEPENDENCY_COMMANDS + + +# AM_OUTPUT_DEPENDENCY_COMMANDS +# ----------------------------- +# This macro should only be invoked once -- use via AC_REQUIRE. +# +# This code is only required when automatic dependency tracking +# is enabled. FIXME. This creates each '.P' file that we will +# need in order to bootstrap the dependency handling code. +AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], +[AC_CONFIG_COMMANDS([depfiles], + [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], + [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"]) +]) + + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +AC_DEFUN([AM_WITH_DMALLOC], +[AC_MSG_CHECKING([if malloc debugging is wanted]) +AC_ARG_WITH([dmalloc], +[AS_HELP_STRING([--with-dmalloc], + [use dmalloc, as in http://www.dmalloc.com])], +[if test "$withval" = yes; then + AC_MSG_RESULT([yes]) + AC_DEFINE([WITH_DMALLOC], [1], + [Define if using the dmalloc debugging malloc package]) + LIBS="$LIBS -ldmalloc" + LDFLAGS="$LDFLAGS -g" +else + AC_MSG_RESULT([no]) +fi], [AC_MSG_RESULT([no])]) +]) + +# Do all the work for Automake. -*- Autoconf -*- + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This macro actually does too much. Some checks are only needed if +# your package does certain things. But this isn't really a big deal. + +dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O. +m4_define([AC_PROG_CC], +m4_defn([AC_PROG_CC]) +[_AM_PROG_CC_C_O +]) + +# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) +# AM_INIT_AUTOMAKE([OPTIONS]) +# ----------------------------------------------- +# The call with PACKAGE and VERSION arguments is the old style +# call (pre autoconf-2.50), which is being phased out. PACKAGE +# and VERSION should now be passed to AC_INIT and removed from +# the call to AM_INIT_AUTOMAKE. +# We support both call styles for the transition. After +# the next Automake release, Autoconf can make the AC_INIT +# arguments mandatory, and then we can depend on a new Autoconf +# release and drop the old call support. +AC_DEFUN([AM_INIT_AUTOMAKE], +[AC_PREREQ([2.65])dnl +dnl Autoconf wants to disallow AM_ names. We explicitly allow +dnl the ones we care about. +m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl +AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl +AC_REQUIRE([AC_PROG_INSTALL])dnl +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi +AC_SUBST([CYGPATH_W]) + +# Define the identity of the package. +dnl Distinguish between old-style and new-style calls. +m4_ifval([$2], +[AC_DIAGNOSE([obsolete], + [$0: two- and three-arguments forms are deprecated.]) +m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl + AC_SUBST([PACKAGE], [$1])dnl + AC_SUBST([VERSION], [$2])], +[_AM_SET_OPTIONS([$1])dnl +dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. +m4_if( + m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), + [ok:ok],, + [m4_fatal([AC_INIT should be called with package and version arguments])])dnl + AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl + AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl + +_AM_IF_OPTION([no-define],, +[AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) + AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl + +# Some tools Automake needs. +AC_REQUIRE([AM_SANITY_CHECK])dnl +AC_REQUIRE([AC_ARG_PROGRAM])dnl +AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) +AM_MISSING_PROG([AUTOCONF], [autoconf]) +AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) +AM_MISSING_PROG([AUTOHEADER], [autoheader]) +AM_MISSING_PROG([MAKEINFO], [makeinfo]) +AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl +AC_REQUIRE([AC_PROG_MKDIR_P])dnl +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +AC_SUBST([mkdir_p], ['$(MKDIR_P)']) +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([AC_PROG_MAKE_SET])dnl +AC_REQUIRE([AM_SET_LEADING_DOT])dnl +_AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], + [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], + [_AM_PROG_TAR([v7])])]) +_AM_IF_OPTION([no-dependencies],, +[AC_PROVIDE_IFELSE([AC_PROG_CC], + [_AM_DEPENDENCIES([CC])], + [m4_define([AC_PROG_CC], + m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_CXX], + [_AM_DEPENDENCIES([CXX])], + [m4_define([AC_PROG_CXX], + m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJC], + [_AM_DEPENDENCIES([OBJC])], + [m4_define([AC_PROG_OBJC], + m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl +AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], + [_AM_DEPENDENCIES([OBJCXX])], + [m4_define([AC_PROG_OBJCXX], + m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl +]) +AC_REQUIRE([AM_SILENT_RULES])dnl +dnl The testsuite driver may need to know about EXEEXT, so add the +dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This +dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below. +AC_CONFIG_COMMANDS_PRE(dnl +[m4_provide_if([_AM_COMPILER_EXEEXT], + [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) + fi +fi +dnl The trailing newline in this macro's definition is deliberate, for +dnl backward compatibility and to allow trailing 'dnl'-style comments +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. +]) + +dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not +dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further +dnl mangled by Autoconf and run in a shell conditional statement. +m4_define([_AC_COMPILER_EXEEXT], +m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) + +# When config.status generates a header, we must update the stamp-h file. +# This file resides in the same directory as the config header +# that is generated. The stamp files are numbered to have different names. + +# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the +# loop where config.status creates the headers, so we can generate +# our stamp files there. +AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], +[# Compute $1's index in $config_headers. +_am_arg=$1 +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_SH +# ------------------ +# Define $install_sh. +AC_DEFUN([AM_PROG_INSTALL_SH], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi +AC_SUBST([install_sh])]) + +# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Check whether the underlying file-system supports filenames +# with a leading dot. For instance MS-DOS doesn't. +AC_DEFUN([AM_SET_LEADING_DOT], +[rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null +AC_SUBST([am__leading_dot])]) + +# Add --enable-maintainer-mode option to configure. -*- Autoconf -*- +# From Jim Meyering + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_MAINTAINER_MODE([DEFAULT-MODE]) +# ---------------------------------- +# Control maintainer-specific portions of Makefiles. +# Default is to disable them, unless 'enable' is passed literally. +# For symmetry, 'disable' may be passed as well. Anyway, the user +# can override the default with the --enable/--disable switch. +AC_DEFUN([AM_MAINTAINER_MODE], +[m4_case(m4_default([$1], [disable]), + [enable], [m4_define([am_maintainer_other], [disable])], + [disable], [m4_define([am_maintainer_other], [enable])], + [m4_define([am_maintainer_other], [enable]) + m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) +AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) + dnl maintainer-mode's default is 'disable' unless 'enable' is passed + AC_ARG_ENABLE([maintainer-mode], + [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode], + am_maintainer_other[ make rules and dependencies not useful + (and sometimes confusing) to the casual installer])], + [USE_MAINTAINER_MODE=$enableval], + [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) + AC_MSG_RESULT([$USE_MAINTAINER_MODE]) + AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) + MAINT=$MAINTAINER_MODE_TRUE + AC_SUBST([MAINT])dnl +] +) + +# Check to see how 'make' treats includes. -*- Autoconf -*- + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_MAKE_INCLUDE() +# ----------------- +# Check to see how make treats includes. +AC_DEFUN([AM_MAKE_INCLUDE], +[am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +AC_MSG_CHECKING([for style of include used by $am_make]) +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi +AC_SUBST([am__include]) +AC_SUBST([am__quote]) +AC_MSG_RESULT([$_am_result]) +rm -f confinc confmf +]) + +# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- + +# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_MISSING_PROG(NAME, PROGRAM) +# ------------------------------ +AC_DEFUN([AM_MISSING_PROG], +[AC_REQUIRE([AM_MISSING_HAS_RUN]) +$1=${$1-"${am_missing_run}$2"} +AC_SUBST($1)]) + +# AM_MISSING_HAS_RUN +# ------------------ +# Define MISSING if not defined so far and test if it is modern enough. +# If it is, set am_missing_run to use it, otherwise, to nothing. +AC_DEFUN([AM_MISSING_HAS_RUN], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([missing])dnl +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + AC_MSG_WARN(['missing' script is too old or missing]) +fi +]) + +# Helper functions for option handling. -*- Autoconf -*- + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_MANGLE_OPTION(NAME) +# ----------------------- +AC_DEFUN([_AM_MANGLE_OPTION], +[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) + +# _AM_SET_OPTION(NAME) +# -------------------- +# Set option NAME. Presently that only means defining a flag for this option. +AC_DEFUN([_AM_SET_OPTION], +[m4_define(_AM_MANGLE_OPTION([$1]), [1])]) + +# _AM_SET_OPTIONS(OPTIONS) +# ------------------------ +# OPTIONS is a space-separated list of Automake options. +AC_DEFUN([_AM_SET_OPTIONS], +[m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) + +# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) +# ------------------------------------------- +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +AC_DEFUN([_AM_IF_OPTION], +[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_PROG_CC_C_O +# --------------- +# Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC +# to automatically call this. +AC_DEFUN([_AM_PROG_CC_C_O], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([compile])dnl +AC_LANG_PUSH([C])dnl +AC_CACHE_CHECK( + [whether $CC understands -c and -o together], + [am_cv_prog_cc_c_o], + [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i]) +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +AC_LANG_POP([C])]) + +# For backward compatibility. +AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_RUN_LOG(COMMAND) +# ------------------- +# Run COMMAND, save the exit status in ac_status, and log it. +# (This has been adapted from Autoconf's _AC_RUN_LOG macro.) +AC_DEFUN([AM_RUN_LOG], +[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD + ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + (exit $ac_status); }]) + +# Check to make sure that the build environment is sane. -*- Autoconf -*- + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_SANITY_CHECK +# --------------- +AC_DEFUN([AM_SANITY_CHECK], +[AC_MSG_CHECKING([whether build environment is sane]) +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[[\\\"\#\$\&\'\`$am_lf]]*) + AC_MSG_ERROR([unsafe absolute working directory name]);; +esac +case $srcdir in + *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) + AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$[*]" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$[*]" != "X $srcdir/configure conftest.file" \ + && test "$[*]" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken + alias in your environment]) + fi + if test "$[2]" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$[2]" = conftest.file + ) +then + # Ok. + : +else + AC_MSG_ERROR([newly created file is older than distributed files! +Check your system clock]) +fi +AC_MSG_RESULT([yes]) +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi +AC_CONFIG_COMMANDS_PRE( + [AC_MSG_CHECKING([that generated files are newer than configure]) + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + AC_MSG_RESULT([done])]) +rm -f conftest.file +]) + +# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_SILENT_RULES([DEFAULT]) +# -------------------------- +# Enable less verbose build rules; with the default set to DEFAULT +# ("yes" being less verbose, "no" or empty being verbose). +AC_DEFUN([AM_SILENT_RULES], +[AC_ARG_ENABLE([silent-rules], [dnl +AS_HELP_STRING( + [--enable-silent-rules], + [less verbose build output (undo: "make V=1")]) +AS_HELP_STRING( + [--disable-silent-rules], + [verbose build output (undo: "make V=0")])dnl +]) +case $enable_silent_rules in @%:@ ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);; +esac +dnl +dnl A few 'make' implementations (e.g., NonStop OS and NextStep) +dnl do not support nested variable expansions. +dnl See automake bug#9928 and bug#10237. +am_make=${MAKE-make} +AC_CACHE_CHECK([whether $am_make supports nested variables], + [am_cv_make_support_nested_variables], + [if AS_ECHO([['TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi]) +if test $am_cv_make_support_nested_variables = yes; then + dnl Using '$V' instead of '$(V)' breaks IRIX make. + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AC_SUBST([AM_V])dnl +AM_SUBST_NOTMAKE([AM_V])dnl +AC_SUBST([AM_DEFAULT_V])dnl +AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl +AC_SUBST([AM_DEFAULT_VERBOSITY])dnl +AM_BACKSLASH='\' +AC_SUBST([AM_BACKSLASH])dnl +_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl +]) + +# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_PROG_INSTALL_STRIP +# --------------------- +# One issue with vendor 'install' (even GNU) is that you can't +# specify the program used to strip binaries. This is especially +# annoying in cross-compiling environments, where the build's strip +# is unlikely to handle the host's binaries. +# Fortunately install-sh will honor a STRIPPROG variable, so we +# always use install-sh in "make install-strip", and initialize +# STRIPPROG with the value of the STRIP variable (set by the user). +AC_DEFUN([AM_PROG_INSTALL_STRIP], +[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. +if test "$cross_compiling" != no; then + AC_CHECK_TOOL([STRIP], [strip], :) +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" +AC_SUBST([INSTALL_STRIP_PROGRAM])]) + +# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_SUBST_NOTMAKE(VARIABLE) +# --------------------------- +# Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. +# This macro is traced by Automake. +AC_DEFUN([_AM_SUBST_NOTMAKE]) + +# AM_SUBST_NOTMAKE(VARIABLE) +# -------------------------- +# Public sister of _AM_SUBST_NOTMAKE. +AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) + +# Check how to create a tarball. -*- Autoconf -*- + +# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_PROG_TAR(FORMAT) +# -------------------- +# Check how to create a tarball in format FORMAT. +# FORMAT should be one of 'v7', 'ustar', or 'pax'. +# +# Substitute a variable $(am__tar) that is a command +# writing to stdout a FORMAT-tarball containing the directory +# $tardir. +# tardir=directory && $(am__tar) > result.tar +# +# Substitute a variable $(am__untar) that extract such +# a tarball read from stdin. +# $(am__untar) < result.tar +# +AC_DEFUN([_AM_PROG_TAR], +[# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AC_SUBST([AMTAR], ['$${TAR-tar}']) + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' + +m4_if([$1], [v7], + [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], + + [m4_case([$1], + [ustar], + [# The POSIX 1988 'ustar' format is defined with fixed-size fields. + # There is notably a 21 bits limit for the UID and the GID. In fact, + # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 + # and bug#13588). + am_max_uid=2097151 # 2^21 - 1 + am_max_gid=$am_max_uid + # The $UID and $GID variables are not portable, so we need to resort + # to the POSIX-mandated id(1) utility. Errors in the 'id' calls + # below are definitely unexpected, so allow the users to see them + # (that is, avoid stderr redirection). + am_uid=`id -u || echo unknown` + am_gid=`id -g || echo unknown` + AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) + if test $am_uid -le $am_max_uid; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + _am_tools=none + fi + AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) + if test $am_gid -le $am_max_gid; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + _am_tools=none + fi], + + [pax], + [], + + [m4_fatal([Unknown tar format])]) + + AC_MSG_CHECKING([how to create a $1 tar archive]) + + # Go ahead even if we have the value already cached. We do so because we + # need to set the values for the 'am__tar' and 'am__untar' variables. + _am_tools=${am_cv_prog_tar_$1-$_am_tools} + + for _am_tool in $_am_tools; do + case $_am_tool in + gnutar) + for _am_tar in tar gnutar gtar; do + AM_RUN_LOG([$_am_tar --version]) && break + done + am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' + am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' + am__untar="$_am_tar -xf -" + ;; + plaintar) + # Must skip GNU tar: if it does not support --format= it doesn't create + # ustar tarball either. + (tar --version) >/dev/null 2>&1 && continue + am__tar='tar chf - "$$tardir"' + am__tar_='tar chf - "$tardir"' + am__untar='tar xf -' + ;; + pax) + am__tar='pax -L -x $1 -w "$$tardir"' + am__tar_='pax -L -x $1 -w "$tardir"' + am__untar='pax -r' + ;; + cpio) + am__tar='find "$$tardir" -print | cpio -o -H $1 -L' + am__tar_='find "$tardir" -print | cpio -o -H $1 -L' + am__untar='cpio -i -H $1 -d' + ;; + none) + am__tar=false + am__tar_=false + am__untar=false + ;; + esac + + # If the value was cached, stop now. We just wanted to have am__tar + # and am__untar set. + test -n "${am_cv_prog_tar_$1}" && break + + # tar/untar a dummy directory, and stop if the command works. + rm -rf conftest.dir + mkdir conftest.dir + echo GrepMe > conftest.dir/file + AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) + rm -rf conftest.dir + if test -s conftest.tar; then + AM_RUN_LOG([$am__untar /dev/null 2>&1 && break + fi + done + rm -rf conftest.dir + + AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) + AC_MSG_RESULT([$am_cv_prog_tar_$1])]) + +AC_SUBST([am__tar]) +AC_SUBST([am__untar]) +]) # _AM_PROG_TAR + +m4_include([m4macros/gsl.m4]) +m4_include([m4macros/libtool.m4]) +m4_include([m4macros/ltoptions.m4]) +m4_include([m4macros/ltsugar.m4]) +m4_include([m4macros/ltversion.m4]) +m4_include([m4macros/lt~obsolete.m4]) +m4_include([acinclude.m4]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/compile cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/compile --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/compile 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/compile 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,347 @@ +#! /bin/sh +# Wrapper for compilers which do not understand '-c -o'. + +scriptversion=2012-10-14.11; # UTC + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Written by Tom Tromey . +# +# 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, 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, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +nl=' +' + +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent tools from complaining about whitespace usage. +IFS=" "" $nl" + +file_conv= + +# func_file_conv build_file lazy +# Convert a $build file to $host form and store it in $file +# Currently only supports Windows hosts. If the determined conversion +# type is listed in (the comma separated) LAZY, no conversion will +# take place. +func_file_conv () +{ + file=$1 + case $file in + / | /[!/]*) # absolute file, and not a UNC file + if test -z "$file_conv"; then + # lazily determine how to convert abs files + case `uname -s` in + MINGW*) + file_conv=mingw + ;; + CYGWIN*) + file_conv=cygwin + ;; + *) + file_conv=wine + ;; + esac + fi + case $file_conv/,$2, in + *,$file_conv,*) + ;; + mingw/*) + file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` + ;; + cygwin/*) + file=`cygpath -m "$file" || echo "$file"` + ;; + wine/*) + file=`winepath -w "$file" || echo "$file"` + ;; + esac + ;; + esac +} + +# func_cl_dashL linkdir +# Make cl look for libraries in LINKDIR +func_cl_dashL () +{ + func_file_conv "$1" + if test -z "$lib_path"; then + lib_path=$file + else + lib_path="$lib_path;$file" + fi + linker_opts="$linker_opts -LIBPATH:$file" +} + +# func_cl_dashl library +# Do a library search-path lookup for cl +func_cl_dashl () +{ + lib=$1 + found=no + save_IFS=$IFS + IFS=';' + for dir in $lib_path $LIB + do + IFS=$save_IFS + if $shared && test -f "$dir/$lib.dll.lib"; then + found=yes + lib=$dir/$lib.dll.lib + break + fi + if test -f "$dir/$lib.lib"; then + found=yes + lib=$dir/$lib.lib + break + fi + if test -f "$dir/lib$lib.a"; then + found=yes + lib=$dir/lib$lib.a + break + fi + done + IFS=$save_IFS + + if test "$found" != yes; then + lib=$lib.lib + fi +} + +# func_cl_wrapper cl arg... +# Adjust compile command to suit cl +func_cl_wrapper () +{ + # Assume a capable shell + lib_path= + shared=: + linker_opts= + for arg + do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + eat=1 + case $2 in + *.o | *.[oO][bB][jJ]) + func_file_conv "$2" + set x "$@" -Fo"$file" + shift + ;; + *) + func_file_conv "$2" + set x "$@" -Fe"$file" + shift + ;; + esac + ;; + -I) + eat=1 + func_file_conv "$2" mingw + set x "$@" -I"$file" + shift + ;; + -I*) + func_file_conv "${1#-I}" mingw + set x "$@" -I"$file" + shift + ;; + -l) + eat=1 + func_cl_dashl "$2" + set x "$@" "$lib" + shift + ;; + -l*) + func_cl_dashl "${1#-l}" + set x "$@" "$lib" + shift + ;; + -L) + eat=1 + func_cl_dashL "$2" + ;; + -L*) + func_cl_dashL "${1#-L}" + ;; + -static) + shared=false + ;; + -Wl,*) + arg=${1#-Wl,} + save_ifs="$IFS"; IFS=',' + for flag in $arg; do + IFS="$save_ifs" + linker_opts="$linker_opts $flag" + done + IFS="$save_ifs" + ;; + -Xlinker) + eat=1 + linker_opts="$linker_opts $2" + ;; + -*) + set x "$@" "$1" + shift + ;; + *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) + func_file_conv "$1" + set x "$@" -Tp"$file" + shift + ;; + *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) + func_file_conv "$1" mingw + set x "$@" "$file" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift + done + if test -n "$linker_opts"; then + linker_opts="-link$linker_opts" + fi + exec "$@" $linker_opts + exit 1 +} + +eat= + +case $1 in + '') + echo "$0: No command. Try '$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: compile [--help] [--version] PROGRAM [ARGS] + +Wrapper for compilers which do not understand '-c -o'. +Remove '-o dest.o' from ARGS, run PROGRAM with the remaining +arguments, and rename the output as expected. + +If you are trying to build a whole package this is not the +right script to run: please start by reading the file 'INSTALL'. + +Report bugs to . +EOF + exit $? + ;; + -v | --v*) + echo "compile $scriptversion" + exit $? + ;; + cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) + func_cl_wrapper "$@" # Doesn't return... + ;; +esac + +ofile= +cfile= + +for arg +do + if test -n "$eat"; then + eat= + else + case $1 in + -o) + # configure might choose to run compile as 'compile cc -o foo foo.c'. + # So we strip '-o arg' only if arg is an object. + eat=1 + case $2 in + *.o | *.obj) + ofile=$2 + ;; + *) + set x "$@" -o "$2" + shift + ;; + esac + ;; + *.c) + cfile=$1 + set x "$@" "$1" + shift + ;; + *) + set x "$@" "$1" + shift + ;; + esac + fi + shift +done + +if test -z "$ofile" || test -z "$cfile"; then + # If no '-o' option was seen then we might have been invoked from a + # pattern rule where we don't need one. That is ok -- this is a + # normal compilation that the losing compiler can handle. If no + # '.c' file was seen then we are probably linking. That is also + # ok. + exec "$@" +fi + +# Name of file we expect compiler to create. +cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` + +# Create the lock directory. +# Note: use '[/\\:.-]' here to ensure that we don't use the same name +# that we are using for the .o file. Also, base the name on the expected +# object file name, since that is what matters with a parallel build. +lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d +while true; do + if mkdir "$lockdir" >/dev/null 2>&1; then + break + fi + sleep 1 +done +# FIXME: race condition here if user kills between mkdir and trap. +trap "rmdir '$lockdir'; exit 1" 1 2 15 + +# Run the compile. +"$@" +ret=$? + +if test -f "$cofile"; then + test "$cofile" = "$ofile" || mv "$cofile" "$ofile" +elif test -f "${cofile}bj"; then + test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" +fi + +rmdir "$lockdir" +exit $ret + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/config.guess cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/config.guess --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/config.guess 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/config.guess 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,1421 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright 1992-2015 Free Software Foundation, Inc. + +timestamp='2015-01-01' + +# This file 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 3 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, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). +# +# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. +# +# You can get the latest version of this script from: +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD +# +# Please send patches to . + + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of the system \`$me' is run on. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.guess ($timestamp) + +Originally written by Per Bothner. +Copyright 1992-2015 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" >&2 + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +trap 'exit 1' 1 2 15 + +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a +# compiler to aid in system detection is discouraged as it requires +# temporary files to be created and, as you can see below, it is a +# headache to deal with in a portable fashion. + +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still +# use `HOST_CC' if defined, but it is deprecated. + +# Portable tmp directory creation inspired by the Autoconf team. + +set_cc_for_build=' +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; +: ${TMPDIR=/tmp} ; + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; +dummy=$tmp/dummy ; +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; +case $CC_FOR_BUILD,$HOST_CC,$CC in + ,,) echo "int x;" > $dummy.c ; + for c in cc gcc c89 c99 ; do + if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then + CC_FOR_BUILD="$c"; break ; + fi ; + done ; + if test x"$CC_FOR_BUILD" = x ; then + CC_FOR_BUILD=no_compiler_found ; + fi + ;; + ,,*) CC_FOR_BUILD=$CC ;; + ,*,*) CC_FOR_BUILD=$HOST_CC ;; +esac ; set_cc_for_build= ;' + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 1994-08-24) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +case "${UNAME_SYSTEM}" in +Linux|GNU|GNU/*) + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + LIBC=gnu + + eval $set_cc_for_build + cat <<-EOF > $dummy.c + #include + #if defined(__UCLIBC__) + LIBC=uclibc + #elif defined(__dietlibc__) + LIBC=dietlibc + #else + LIBC=gnu + #endif + EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + ;; +esac + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # NetBSD (nbsd) targets should (where applicable) match one or + # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # + # Note: NetBSD doesn't particularly care about the vendor + # portion of the name. We always set it to "unknown". + sysctl="sysctl -n hw.machine_arch" + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` + case "${UNAME_MACHINE_ARCH}" in + armeb) machine=armeb-unknown ;; + arm*) machine=arm-unknown ;; + sh3el) machine=shl-unknown ;; + sh3eb) machine=sh-unknown ;; + sh5el) machine=sh5le-unknown ;; + *) machine=${UNAME_MACHINE_ARCH}-unknown ;; + esac + # The Operating System including object format, if it has switched + # to ELF recently, or will in the future. + case "${UNAME_MACHINE_ARCH}" in + arm*|i386|m68k|ns32k|sh3*|sparc|vax) + eval $set_cc_for_build + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ELF__ + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + ;; + *) + os=netbsd + ;; + esac + # The OS release + # Debian GNU/NetBSD machines have a different userland, and + # thus, need a distinct triplet. However, they do not need + # kernel version information, so it can be replaced with a + # suitable tag, in the style of linux-gnu. + case "${UNAME_VERSION}" in + Debian*) + release='-gnu' + ;; + *) + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + ;; + esac + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit ;; + *:Bitrig:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE} + exit ;; + *:OpenBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` + echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} + exit ;; + *:ekkoBSD:*:*) + echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} + exit ;; + *:SolidBSD:*:*) + echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} + exit ;; + macppc:MirBSD:*:*) + echo powerpc-unknown-mirbsd${UNAME_RELEASE} + exit ;; + *:MirBSD:*:*) + echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} + exit ;; + alpha:OSF1:*:*) + case $UNAME_RELEASE in + *4.0) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + ;; + *5.*) + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + ;; + esac + # According to Compaq, /usr/sbin/psrinfo has been available on + # OSF/1 and Tru64 systems produced since 1995. I hope that + # covers most systems running today. This code pipes the CPU + # types through head -n 1, so we only detect the type of CPU 0. + ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` + case "$ALPHA_CPU_TYPE" in + "EV4 (21064)") + UNAME_MACHINE="alpha" ;; + "EV4.5 (21064)") + UNAME_MACHINE="alpha" ;; + "LCA4 (21066/21068)") + UNAME_MACHINE="alpha" ;; + "EV5 (21164)") + UNAME_MACHINE="alphaev5" ;; + "EV5.6 (21164A)") + UNAME_MACHINE="alphaev56" ;; + "EV5.6 (21164PC)") + UNAME_MACHINE="alphapca56" ;; + "EV5.7 (21164PC)") + UNAME_MACHINE="alphapca57" ;; + "EV6 (21264)") + UNAME_MACHINE="alphaev6" ;; + "EV6.7 (21264A)") + UNAME_MACHINE="alphaev67" ;; + "EV6.8CB (21264C)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8AL (21264B)") + UNAME_MACHINE="alphaev68" ;; + "EV6.8CX (21264D)") + UNAME_MACHINE="alphaev68" ;; + "EV6.9A (21264/EV69A)") + UNAME_MACHINE="alphaev69" ;; + "EV7 (21364)") + UNAME_MACHINE="alphaev7" ;; + "EV7.9 (21364A)") + UNAME_MACHINE="alphaev79" ;; + esac + # A Pn.n version is a patched version. + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + exitcode=$? + trap '' 0 + exit $exitcode ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix + exit ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-unknown-sysv4 + exit ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit ;; + *:[Mm]orph[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-morphos + exit ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit ;; + *:z/VM:*:*) + echo s390-ibm-zvmoe + exit ;; + *:OS400:*:*) + echo powerpc-ibm-os400 + exit ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit ;; + arm*:riscos:*:*|arm*:RISCOS:*:*) + echo arm-unknown-riscos + exit ;; + SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit ;; + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit ;; + NILE*:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit ;; + DRS?6000:unix:4.0:6*) + echo sparc-icl-nx6 + exit ;; + DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) + case `/usr/bin/uname -p` in + sparc) echo sparc-icl-nx7; exit ;; + esac ;; + s390x:SunOS:*:*) + echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) + echo i386-pc-auroraux${UNAME_RELEASE} + exit ;; + i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) + eval $set_cc_for_build + SUN_ARCH="i386" + # If there is a compiler, see if it is configured for 64-bit objects. + # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. + # This test works for both compilers. + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + SUN_ARCH="x86_64" + fi + fi + echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit ;; + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit ;; + m68k:machten:*:*) + echo m68k-apple-machten${UNAME_RELEASE} + exit ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit ;; + 2020:CLIX:*:* | 2430:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && + dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && + SYSTEM_NAME=`$dummy $dummyarg` && + { echo "$SYSTEM_NAME"; exit; } + echo mips-mips-riscos${UNAME_RELEASE} + exit ;; + Motorola:PowerMAX_OS:*:*) + echo powerpc-motorola-powermax + exit ;; + Motorola:*:4.3:PL8-*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) + echo powerpc-harris-powermax + exit ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} + fi + exit ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i*86:AIX:*:*) + echo i386-ibm-aix + exit ;; + ia64:AIX:*:*) + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + exit ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + then + echo "$SYSTEM_NAME" + else + echo rs6000-ibm-aix3.2.5 + fi + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit ;; + *:AIX:*:[4567]) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` + if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/lslpp ] ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | + awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` + else + IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit ;; + 9000/[34678]??:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/[678][0-9][0-9]) + if [ -x /usr/bin/getconf ]; then + sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` + sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` + case "${sc_cpu_version}" in + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 + 532) # CPU_PA_RISC2_0 + case "${sc_kernel_bits}" in + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 + esac ;; + esac + fi + if [ "${HP_ARCH}" = "" ]; then + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE + #include + #include + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + case 32: puts ("hppa2.0n"); break; + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + test -z "$HP_ARCH" && HP_ARCH=hppa + fi ;; + esac + if [ ${HP_ARCH} = "hppa2.0w" ] + then + eval $set_cc_for_build + + # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating + # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler + # generating 64-bit code. GNU and HP use different nomenclature: + # + # $ CC_FOR_BUILD=cc ./config.guess + # => hppa2.0w-hp-hpux11.23 + # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess + # => hppa64-hp-hpux11.23 + + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | + grep -q __LP64__ + then + HP_ARCH="hppa2.0w" + else + HP_ARCH="hppa64" + fi + fi + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit ;; + ia64:HP-UX:*:*) + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ia64-hp-hpux${HPUX_REV} + exit ;; + 3050*:HI-UX:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + echo unknown-hitachi-hiuxwe2 + exit ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit ;; + *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit ;; + i*86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ + -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*T3E:*:*:*) + echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + *:UNICOS/mp:*:*) + echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit ;; + F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + 5000:UNIX_System_V:4.*:*) + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` + echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit ;; + i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit ;; + *:FreeBSD:*:*) + UNAME_PROCESSOR=`/usr/bin/uname -p` + case ${UNAME_PROCESSOR} in + amd64) + echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + *) + echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; + esac + exit ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit ;; + *:MINGW64*:*) + echo ${UNAME_MACHINE}-pc-mingw64 + exit ;; + *:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit ;; + *:MSYS*:*) + echo ${UNAME_MACHINE}-pc-msys + exit ;; + i*:windows32*:*) + # uname -m includes "-pc" on this system. + echo ${UNAME_MACHINE}-mingw32 + exit ;; + i*:PW*:*) + echo ${UNAME_MACHINE}-pc-pw32 + exit ;; + *:Interix*:*) + case ${UNAME_MACHINE} in + x86) + echo i586-pc-interix${UNAME_RELEASE} + exit ;; + authenticamd | genuineintel | EM64T) + echo x86_64-unknown-interix${UNAME_RELEASE} + exit ;; + IA64) + echo ia64-unknown-interix${UNAME_RELEASE} + exit ;; + esac ;; + [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) + echo i${UNAME_MACHINE}-pc-mks + exit ;; + 8664:Windows_NT:*) + echo x86_64-pc-mks + exit ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i586-pc-interix + exit ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit ;; + amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) + echo x86_64-unknown-cygwin + exit ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit ;; + *:GNU:*:*) + # the GNU system + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit ;; + *:GNU/*:*:*) + # other systems with GNU libc and userland + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} + exit ;; + i*86:Minix:*:*) + echo ${UNAME_MACHINE}-pc-minix + exit ;; + aarch64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + aarch64_be:Linux:*:*) + UNAME_MACHINE=aarch64_be + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + alpha:Linux:*:*) + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + EV5) UNAME_MACHINE=alphaev5 ;; + EV56) UNAME_MACHINE=alphaev56 ;; + PCA56) UNAME_MACHINE=alphapca56 ;; + PCA57) UNAME_MACHINE=alphapca56 ;; + EV6) UNAME_MACHINE=alphaev6 ;; + EV67) UNAME_MACHINE=alphaev67 ;; + EV68*) UNAME_MACHINE=alphaev68 ;; + esac + objdump --private-headers /bin/sh | grep -q ld.so.1 + if test "$?" = 0 ; then LIBC="gnulibc1" ; fi + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + arc:Linux:*:* | arceb:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + arm*:Linux:*:*) + eval $set_cc_for_build + if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_EABI__ + then + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + else + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi + else + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf + fi + fi + exit ;; + avr32*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + cris:Linux:*:*) + echo ${UNAME_MACHINE}-axis-linux-${LIBC} + exit ;; + crisv32:Linux:*:*) + echo ${UNAME_MACHINE}-axis-linux-${LIBC} + exit ;; + frv:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + hexagon:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + i*86:Linux:*:*) + echo ${UNAME_MACHINE}-pc-linux-${LIBC} + exit ;; + ia64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + m68*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + mips:Linux:*:* | mips64:Linux:*:*) + eval $set_cc_for_build + sed 's/^ //' << EOF >$dummy.c + #undef CPU + #undef ${UNAME_MACHINE} + #undef ${UNAME_MACHINE}el + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) + CPU=${UNAME_MACHINE}el + #else + #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) + CPU=${UNAME_MACHINE} + #else + CPU= + #endif + #endif +EOF + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` + test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } + ;; + openrisc*:Linux:*:*) + echo or1k-unknown-linux-${LIBC} + exit ;; + or32:Linux:*:* | or1k*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + padre:Linux:*:*) + echo sparc-unknown-linux-${LIBC} + exit ;; + parisc64:Linux:*:* | hppa64:Linux:*:*) + echo hppa64-unknown-linux-${LIBC} + exit ;; + parisc:Linux:*:* | hppa:Linux:*:*) + # Look for CPU level + case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in + PA7*) echo hppa1.1-unknown-linux-${LIBC} ;; + PA8*) echo hppa2.0-unknown-linux-${LIBC} ;; + *) echo hppa-unknown-linux-${LIBC} ;; + esac + exit ;; + ppc64:Linux:*:*) + echo powerpc64-unknown-linux-${LIBC} + exit ;; + ppc:Linux:*:*) + echo powerpc-unknown-linux-${LIBC} + exit ;; + ppc64le:Linux:*:*) + echo powerpc64le-unknown-linux-${LIBC} + exit ;; + ppcle:Linux:*:*) + echo powerpcle-unknown-linux-${LIBC} + exit ;; + s390:Linux:*:* | s390x:Linux:*:*) + echo ${UNAME_MACHINE}-ibm-linux-${LIBC} + exit ;; + sh64*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + sh*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + sparc:Linux:*:* | sparc64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + tile*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + vax:Linux:*:*) + echo ${UNAME_MACHINE}-dec-linux-${LIBC} + exit ;; + x86_64:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + xtensa*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} + exit ;; + i*86:DYNIX/ptx:4*:*) + # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. + # earlier versions are messed up and put the nodename in both + # sysname and nodename. + echo i386-sequent-sysv4 + exit ;; + i*86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit ;; + i*86:OS/2:*:*) + # If we were able to find `uname', then EMX Unix compatibility + # is probably installed. + echo ${UNAME_MACHINE}-pc-os2-emx + exit ;; + i*86:XTS-300:*:STOP) + echo ${UNAME_MACHINE}-unknown-stop + exit ;; + i*86:atheos:*:*) + echo ${UNAME_MACHINE}-unknown-atheos + exit ;; + i*86:syllable:*:*) + echo ${UNAME_MACHINE}-pc-syllable + exit ;; + i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit ;; + i*86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp + exit ;; + i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit ;; + i*86:*:5:[678]*) + # UnixWare 7.x, OpenUNIX and OpenServer 6. + case `/bin/uname -X | grep "^Machine"` in + *486*) UNAME_MACHINE=i486 ;; + *Pentium) UNAME_MACHINE=i586 ;; + *Pent*|*Celeron) UNAME_MACHINE=i686 ;; + esac + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + exit ;; + i*86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` + (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit ;; + pc:*:*:*) + # Left here for compatibility: + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i586. + # Note: whatever this is, it MUST be the same as what config.sub + # prints for the "djgpp" host, or else GDB configury will decide that + # this is a cross-build. + echo i586-pc-msdosdjgpp + exit ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit ;; + mc68k:UNIX:SYSTEM5:3.51m) + echo m68k-convergent-sysv + exit ;; + M680?0:D-NIX:5.3:*) + echo m68k-diab-dnix + exit ;; + M68*:*:R3V[5678]*:*) + test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; + 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4; exit; } ;; + NCR*:*:4.2:* | MPRAS*:*:4.2:*) + OS_REL='.3' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && { echo i486-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } + /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ + && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; + m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit ;; + rs6000:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit ;; + PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) + echo powerpc-unknown-lynxos${UNAME_RELEASE} + exit ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit ;; + PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says + echo i586-unisys-sysv4 + exit ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes . + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit ;; + i*86:VOS:*:*) + # From Paul.Green@stratus.com. + echo ${UNAME_MACHINE}-stratus-vos + exit ;; + *:VOS:*:*) + # From Paul.Green@stratus.com. + echo hppa1.1-stratus-vos + exit ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit ;; + news*:NEWS-OS:6*:*) + echo mips-sony-newsos6 + exit ;; + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit ;; + BePC:Haiku:*:*) # Haiku running on Intel PC compatible. + echo i586-pc-haiku + exit ;; + x86_64:Haiku:*:*) + echo x86_64-unknown-haiku + exit ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit ;; + SX-6:SUPER-UX:*:*) + echo sx6-nec-superux${UNAME_RELEASE} + exit ;; + SX-7:SUPER-UX:*:*) + echo sx7-nec-superux${UNAME_RELEASE} + exit ;; + SX-8:SUPER-UX:*:*) + echo sx8-nec-superux${UNAME_RELEASE} + exit ;; + SX-8R:SUPER-UX:*:*) + echo sx8r-nec-superux${UNAME_RELEASE} + exit ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit ;; + *:Darwin:*:*) + UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown + eval $set_cc_for_build + if test "$UNAME_PROCESSOR" = unknown ; then + UNAME_PROCESSOR=powerpc + fi + if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac + fi + fi + elif test "$UNAME_PROCESSOR" = i386 ; then + # Avoid executing cc on OS X 10.9, as it ships with a stub + # that puts up a graphical alert prompting to install + # developer tools. Any system running Mac OS X 10.7 or + # later (Darwin 11 and later) is required to have a 64-bit + # processor. This is not true of the ARM version of Darwin + # that Apple uses in portable devices. + UNAME_PROCESSOR=x86_64 + fi + echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + exit ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + UNAME_PROCESSOR=`uname -p` + if test "$UNAME_PROCESSOR" = "x86"; then + UNAME_PROCESSOR=i386 + UNAME_MACHINE=pc + fi + echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} + exit ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit ;; + NEO-?:NONSTOP_KERNEL:*:*) + echo neo-tandem-nsk${UNAME_RELEASE} + exit ;; + NSE-*:NONSTOP_KERNEL:*:*) + echo nse-tandem-nsk${UNAME_RELEASE} + exit ;; + NSR-?:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit ;; + *:NonStop-UX:*:*) + echo mips-compaq-nonstopux + exit ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + exit ;; + *:Plan9:*:*) + # "uname -m" is not consistent, so use $cputype instead. 386 + # is converted to i386 for consistency with other x86 + # operating systems. + if test "$cputype" = "386"; then + UNAME_MACHINE=i386 + else + UNAME_MACHINE="$cputype" + fi + echo ${UNAME_MACHINE}-unknown-plan9 + exit ;; + *:TOPS-10:*:*) + echo pdp10-unknown-tops10 + exit ;; + *:TENEX:*:*) + echo pdp10-unknown-tenex + exit ;; + KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) + echo pdp10-dec-tops20 + exit ;; + XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) + echo pdp10-xkl-tops20 + exit ;; + *:TOPS-20:*:*) + echo pdp10-unknown-tops20 + exit ;; + *:ITS:*:*) + echo pdp10-unknown-its + exit ;; + SEI:*:*:SEIUX) + echo mips-sei-seiux${UNAME_RELEASE} + exit ;; + *:DragonFly:*:*) + echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit ;; + *:*VMS:*:*) + UNAME_MACHINE=`(uname -p) 2>/dev/null` + case "${UNAME_MACHINE}" in + A*) echo alpha-dec-vms ; exit ;; + I*) echo ia64-dec-vms ; exit ;; + V*) echo vax-dec-vms ; exit ;; + esac ;; + *:XENIX:*:SysV) + echo i386-pc-xenix + exit ;; + i*86:skyos:*:*) + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' + exit ;; + i*86:rdos:*:*) + echo ${UNAME_MACHINE}-pc-rdos + exit ;; + i*86:AROS:*:*) + echo ${UNAME_MACHINE}-pc-aros + exit ;; + x86_64:VMkernel:*:*) + echo ${UNAME_MACHINE}-unknown-esx + exit ;; +esac + +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess timestamp = $timestamp + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF + +exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/config.sub cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/config.sub --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/config.sub 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/config.sub 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,1807 @@ +#! /bin/sh +# Configuration validation subroutine script. +# Copyright 1992-2015 Free Software Foundation, Inc. + +timestamp='2015-01-01' + +# This file 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 3 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, see . +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that +# program. This Exception is an additional permission under section 7 +# of the GNU General Public License, version 3 ("GPLv3"). + + +# Please send patches to . +# +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# You can get the latest version of this script from: +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -t, --time-stamp print date of last modification, then exit + -v, --version print version number, then exit + +Report bugs and patches to ." + +version="\ +GNU config.sub ($timestamp) + +Copyright 1992-2015 Free Software Foundation, Inc. + +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case $1 in + --time-stamp | --time* | -t ) + echo "$timestamp" ; exit ;; + --version | -v ) + echo "$version" ; exit ;; + --help | --h* | -h ) + echo "$usage"; exit ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + echo "$me: invalid option $1$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit ;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ + linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ + knetbsd*-gnu* | netbsd*-gnu* | \ + kopensolaris*-gnu* | \ + storm-chaos* | os2-emx* | rtmk-nova*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + android-linux) + os=-linux-android + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple | -axis | -knuth | -cray | -microblaze*) + os= + basic_machine=$1 + ;; + -bluegene*) + os=-cnk + ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; + -chorusos*) + os=-chorusos + basic_machine=$1 + ;; + -chorusrdb) + os=-chorusrdb + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco6) + os=-sco5v6 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5) + os=-sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*178) + os=-lynxos178 + ;; + -lynx*5) + os=-lynxos5 + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + 1750a | 580 \ + | a29k \ + | aarch64 | aarch64_be \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ + | am33_2.0 \ + | arc | arceb \ + | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ + | avr | avr32 \ + | be32 | be64 \ + | bfin \ + | c4x | c8051 | clipper \ + | d10v | d30v | dlx | dsp16xx \ + | epiphany \ + | fido | fr30 | frv | ft32 \ + | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ + | i370 | i860 | i960 | ia64 \ + | ip2k | iq2000 \ + | k1om \ + | le32 | le64 \ + | lm32 \ + | m32c | m32r | m32rle | m68000 | m68k | m88k \ + | maxq | mb | microblaze | microblazeel | mcore | mep | metag \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64el \ + | mips64octeon | mips64octeonel \ + | mips64orion | mips64orionel \ + | mips64r5900 | mips64r5900el \ + | mips64vr | mips64vrel \ + | mips64vr4100 | mips64vr4100el \ + | mips64vr4300 | mips64vr4300el \ + | mips64vr5000 | mips64vr5000el \ + | mips64vr5900 | mips64vr5900el \ + | mipsisa32 | mipsisa32el \ + | mipsisa32r2 | mipsisa32r2el \ + | mipsisa32r6 | mipsisa32r6el \ + | mipsisa64 | mipsisa64el \ + | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64r6 | mipsisa64r6el \ + | mipsisa64sb1 | mipsisa64sb1el \ + | mipsisa64sr71k | mipsisa64sr71kel \ + | mipsr5900 | mipsr5900el \ + | mipstx39 | mipstx39el \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ + | nds32 | nds32le | nds32be \ + | nios | nios2 | nios2eb | nios2el \ + | ns16k | ns32k \ + | open8 | or1k | or1knd | or32 \ + | pdp10 | pdp11 | pj | pjl \ + | powerpc | powerpc64 | powerpc64le | powerpcle \ + | pyramid \ + | riscv32 | riscv64 \ + | rl78 | rx \ + | score \ + | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ + | spu \ + | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ + | ubicom32 \ + | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ + | visium \ + | we32k \ + | x86 | xc16x | xstormy16 | xtensa \ + | z8k | z80) + basic_machine=$basic_machine-unknown + ;; + c54x) + basic_machine=tic54x-unknown + ;; + c55x) + basic_machine=tic55x-unknown + ;; + c6x) + basic_machine=tic6x-unknown + ;; + leon|leon[3-9]) + basic_machine=sparc-$basic_machine + ;; + m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) + basic_machine=$basic_machine-unknown + os=-none + ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + ;; + ms1) + basic_machine=mt-unknown + ;; + + strongarm | thumb | xscale) + basic_machine=arm-unknown + ;; + xgate) + basic_machine=$basic_machine-unknown + os=-none + ;; + xscaleeb) + basic_machine=armeb-unknown + ;; + + xscaleel) + basic_machine=armel-unknown + ;; + + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i*86 | x86_64) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + 580-* \ + | a29k-* \ + | aarch64-* | aarch64_be-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ + | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ + | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ + | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ + | avr-* | avr32-* \ + | be32-* | be64-* \ + | bfin-* | bs2000-* \ + | c[123]* | c30-* | [cjt]90-* | c4x-* \ + | c8051-* | clipper-* | craynv-* | cydra-* \ + | d10v-* | d30v-* | dlx-* \ + | elxsi-* \ + | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ + | h8300-* | h8500-* \ + | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ + | hexagon-* \ + | i*86-* | i860-* | i960-* | ia64-* \ + | ip2k-* | iq2000-* \ + | k1om-* \ + | le32-* | le64-* \ + | lm32-* \ + | m32c-* | m32r-* | m32rle-* \ + | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ + | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ + | microblaze-* | microblazeel-* \ + | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ + | mips16-* \ + | mips64-* | mips64el-* \ + | mips64octeon-* | mips64octeonel-* \ + | mips64orion-* | mips64orionel-* \ + | mips64r5900-* | mips64r5900el-* \ + | mips64vr-* | mips64vrel-* \ + | mips64vr4100-* | mips64vr4100el-* \ + | mips64vr4300-* | mips64vr4300el-* \ + | mips64vr5000-* | mips64vr5000el-* \ + | mips64vr5900-* | mips64vr5900el-* \ + | mipsisa32-* | mipsisa32el-* \ + | mipsisa32r2-* | mipsisa32r2el-* \ + | mipsisa32r6-* | mipsisa32r6el-* \ + | mipsisa64-* | mipsisa64el-* \ + | mipsisa64r2-* | mipsisa64r2el-* \ + | mipsisa64r6-* | mipsisa64r6el-* \ + | mipsisa64sb1-* | mipsisa64sb1el-* \ + | mipsisa64sr71k-* | mipsisa64sr71kel-* \ + | mipsr5900-* | mipsr5900el-* \ + | mipstx39-* | mipstx39el-* \ + | mmix-* \ + | mt-* \ + | msp430-* \ + | nds32-* | nds32le-* | nds32be-* \ + | nios-* | nios2-* | nios2eb-* | nios2el-* \ + | none-* | np1-* | ns16k-* | ns32k-* \ + | open8-* \ + | or1k*-* \ + | orion-* \ + | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ + | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ + | pyramid-* \ + | rl78-* | romp-* | rs6000-* | rx-* \ + | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ + | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ + | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ + | sparclite-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \ + | tahoe-* \ + | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ + | tile*-* \ + | tron-* \ + | ubicom32-* \ + | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ + | vax-* \ + | visium-* \ + | we32k-* \ + | x86-* | x86_64-* | xc16x-* | xps100-* \ + | xstormy16-* | xtensa*-* \ + | ymp-* \ + | z8k-* | z80-*) + ;; + # Recognize the basic CPU types without company name, with glob match. + xtensa*) + basic_machine=$basic_machine-unknown + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + abacus) + basic_machine=abacus-unknown + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amd64) + basic_machine=x86_64-pc + ;; + amd64-*) + basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-unknown + ;; + amigaos | amigados) + basic_machine=m68k-unknown + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; + aros) + basic_machine=i386-pc + os=-aros + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + blackfin) + basic_machine=bfin-unknown + os=-linux + ;; + blackfin-*) + basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + bluegene*) + basic_machine=powerpc-ibm + os=-cnk + ;; + c54x-*) + basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + c55x-*) + basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + c6x-*) + basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + c90) + basic_machine=c90-cray + os=-unicos + ;; + cegcc) + basic_machine=arm-unknown + os=-cegcc + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | j90) + basic_machine=j90-cray + os=-unicos + ;; + craynv) + basic_machine=craynv-cray + os=-unicosmp + ;; + cr16 | cr16-*) + basic_machine=cr16-unknown + os=-elf + ;; + crds | unos) + basic_machine=m68k-crds + ;; + crisv32 | crisv32-* | etraxfs*) + basic_machine=crisv32-axis + ;; + cris | cris-* | etrax*) + basic_machine=cris-axis + ;; + crx) + basic_machine=crx-unknown + os=-elf + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + decsystem10* | dec10*) + basic_machine=pdp10-dec + os=-tops10 + ;; + decsystem20* | dec20*) + basic_machine=pdp10-dec + os=-tops20 + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dicos) + basic_machine=i686-pc + os=-dicos + ;; + djgpp) + basic_machine=i586-pc + os=-msdosdjgpp + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + go32) + basic_machine=i386-pc + os=-go32 + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + ;; + i*86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i*86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i*86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i*86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + leon-*|leon[3-9]-*) + basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'` + ;; + m68knommu) + basic_machine=m68k-unknown + os=-linux + ;; + m68knommu-*) + basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + microblaze*) + basic_machine=microblaze-xilinx + ;; + mingw64) + basic_machine=x86_64-pc + os=-mingw64 + ;; + mingw32) + basic_machine=i686-pc + os=-mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + os=-mingw32ce + ;; + miniframe) + basic_machine=m68000-convergent + ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + morphos) + basic_machine=powerpc-unknown + os=-morphos + ;; + moxiebox) + basic_machine=moxie-unknown + os=-moxiebox + ;; + msdos) + basic_machine=i386-pc + os=-msdos + ;; + ms1-*) + basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` + ;; + msys) + basic_machine=i686-pc + os=-msys + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; + nacl) + basic_machine=le32-unknown + os=-nacl + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; + nonstopux) + basic_machine=mips-compaq + os=-nonstopux + ;; + np1) + basic_machine=np1-gould + ;; + neo-tandem) + basic_machine=neo-tandem + ;; + nse-tandem) + basic_machine=nse-tandem + ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + openrisc | openrisc-*) + basic_machine=or32-unknown + ;; + os400) + basic_machine=powerpc-ibm + os=-os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + parisc) + basic_machine=hppa-unknown + os=-linux + ;; + parisc-*) + basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` + os=-linux + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pc98) + basic_machine=i386-pc + ;; + pc98-*) + basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium | p5 | k5 | k6 | nexgen | viac3) + basic_machine=i586-pc + ;; + pentiumpro | p6 | 6x86 | athlon | athlon_*) + basic_machine=i686-pc + ;; + pentiumii | pentium2 | pentiumiii | pentium3) + basic_machine=i686-pc + ;; + pentium4) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | 6x86-* | athlon-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentium4-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=power-ibm + ;; + ppc | ppcbe) basic_machine=powerpc-unknown + ;; + ppc-* | ppcbe-*) + basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64) basic_machine=powerpc64-unknown + ;; + ppc64-* | ppc64p7-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppc64le | powerpc64little | ppc64-le | powerpc64-little) + basic_machine=powerpc64le-unknown + ;; + ppc64le-* | powerpc64little-*) + basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + pw32) + basic_machine=i586-unknown + os=-pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + os=-rdos + ;; + rdos32) + basic_machine=i386-pc + os=-rdos + ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + s390 | s390-*) + basic_machine=s390-ibm + ;; + s390x | s390x-*) + basic_machine=s390x-ibm + ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; + sb1) + basic_machine=mipsisa64sb1-unknown + ;; + sb1el) + basic_machine=mipsisa64sb1el-unknown + ;; + sde) + basic_machine=mipsisa32-sde + os=-elf + ;; + sei) + basic_machine=mips-sei + os=-seiux + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sh5el) + basic_machine=sh5le-unknown + ;; + sh64) + basic_machine=sh64-unknown + ;; + sparclite-wrs | simso-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; + strongarm-* | thumb-*) + basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + t3e) + basic_machine=alphaev5-cray + os=-unicos + ;; + t90) + basic_machine=t90-cray + os=-unicos + ;; + tile*) + basic_machine=$basic_machine-unknown + os=-linux-gnu + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + toad1) + basic_machine=pdp10-xkl + os=-tops20 + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + tpf) + basic_machine=s390x-ibm + os=-tpf + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; + xbox) + basic_machine=i686-pc + os=-mingw32 + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + xscale-* | xscalee[bl]-*) + basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'` + ;; + ymp) + basic_machine=ymp-cray + os=-unicos + ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; + z80-*-coff) + basic_machine=z80-unknown + os=-sim + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; + romp) + basic_machine=romp-ibm + ;; + mmix) + basic_machine=mmix-knuth + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp10) + # there are many clones, so DEC is not a safe bet + basic_machine=pdp10-unknown + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) + basic_machine=sh-unknown + ;; + sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + *-unknown) + # Make sure to match an already-canonicalized machine name. + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -auroraux) + os=-auroraux + ;; + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ + | -sym* | -kopensolaris* | -plan9* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* | -aros* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ + | -bitrig* | -openbsd* | -solidbsd* \ + | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ + | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -chorusos* | -chorusrdb* | -cegcc* \ + | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ + | -linux-newlib* | -linux-musl* | -linux-uclibc* \ + | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ + | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ + | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ + | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ + | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ + | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -qnx*) + case $basic_machine in + x86-* | i*86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto-qnx*) + ;; + -nto*) + os=`echo $os | sed -e 's|nto|nto-qnx|'` + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; + -linux-dietlibc) + os=-linux-dietlibc + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -opened*) + os=-openedition + ;; + -os400*) + os=-os400 + ;; + -wince*) + os=-wince + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -atheos*) + os=-atheos + ;; + -syllable*) + os=-syllable + ;; + -386bsd) + os=-bsd + ;; + -ctix* | -uts*) + os=-sysv + ;; + -nova*) + os=-rtmk-nova + ;; + -ns2 ) + os=-nextstep2 + ;; + -nsk*) + os=-nsk + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -tpf*) + os=-tpf + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; + -xenix) + os=-xenix + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + os=-mint + ;; + -aros*) + os=-aros + ;; + -zvmoe) + os=-zvmoe + ;; + -dicos*) + os=-dicos + ;; + -nacl*) + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + score-*) + os=-elf + ;; + spu-*) + os=-elf + ;; + *-acorn) + os=-riscix1.2 + ;; + arm*-rebel) + os=-linux + ;; + arm*-semi) + os=-aout + ;; + c4x-* | tic4x-*) + os=-coff + ;; + c8051-*) + os=-elf + ;; + hexagon-*) + os=-elf + ;; + tic54x-*) + os=-coff + ;; + tic55x-*) + os=-coff + ;; + tic6x-*) + os=-coff + ;; + # This must come before the *-dec entry. + pdp10-*) + os=-tops20 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + ;; + m68*-cisco) + os=-aout + ;; + mep-*) + os=-elf + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; + or32-*) + os=-coff + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-haiku) + os=-haiku + ;; + *-ibm) + os=-aix + ;; + *-knuth) + os=-mmixware + ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f30[01]-fujitsu | f700-fujitsu) + os=-uxpv + ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -cnk*|-aix*) + vendor=ibm + ;; + -beos*) + vendor=be + ;; + -hpux*) + vendor=hp + ;; + -mpeix*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs* | -opened*) + vendor=ibm + ;; + -os400*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -tpf*) + vendor=ibm + ;; + -vxsim* | -vxworks* | -windiss*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + vendor=atari + ;; + -vos*) + vendor=stratus + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os +exit + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "timestamp='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/depcomp cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/depcomp --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/depcomp 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/depcomp 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,791 @@ +#! /bin/sh +# depcomp - compile a program generating dependencies as side-effects + +scriptversion=2013-05-30.07; # UTC + +# Copyright (C) 1999-2014 Free Software Foundation, Inc. + +# 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, 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, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva . + +case $1 in + '') + echo "$0: No command. Try '$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: depcomp [--help] [--version] PROGRAM [ARGS] + +Run PROGRAMS ARGS to compile a file, generating dependencies +as side-effects. + +Environment variables: + depmode Dependency tracking mode. + source Source file read by 'PROGRAMS ARGS'. + object Object file output by 'PROGRAMS ARGS'. + DEPDIR directory where to store dependencies. + depfile Dependency file to output. + tmpdepfile Temporary file to use when outputting dependencies. + libtool Whether libtool is used (yes/no). + +Report bugs to . +EOF + exit $? + ;; + -v | --v*) + echo "depcomp $scriptversion" + exit $? + ;; +esac + +# Get the directory component of the given path, and save it in the +# global variables '$dir'. Note that this directory component will +# be either empty or ending with a '/' character. This is deliberate. +set_dir_from () +{ + case $1 in + */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; + *) dir=;; + esac +} + +# Get the suffix-stripped basename of the given path, and save it the +# global variable '$base'. +set_base_from () +{ + base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` +} + +# If no dependency file was actually created by the compiler invocation, +# we still have to create a dummy depfile, to avoid errors with the +# Makefile "include basename.Plo" scheme. +make_dummy_depfile () +{ + echo "#dummy" > "$depfile" +} + +# Factor out some common post-processing of the generated depfile. +# Requires the auxiliary global variable '$tmpdepfile' to be set. +aix_post_process_depfile () +{ + # If the compiler actually managed to produce a dependency file, + # post-process it. + if test -f "$tmpdepfile"; then + # Each line is of the form 'foo.o: dependency.h'. + # Do two passes, one to just change these to + # $object: dependency.h + # and one to simply output + # dependency.h: + # which is needed to avoid the deleted-header problem. + { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" + sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" + } > "$depfile" + rm -f "$tmpdepfile" + else + make_dummy_depfile + fi +} + +# A tabulation character. +tab=' ' +# A newline character. +nl=' +' +# Character ranges might be problematic outside the C locale. +# These definitions help. +upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ +lower=abcdefghijklmnopqrstuvwxyz +digits=0123456789 +alpha=${upper}${lower} + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi + +# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. +depfile=${depfile-`echo "$object" | + sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Avoid interferences from the environment. +gccflag= dashmflag= + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +cygpath_u="cygpath -u -f -" +if test "$depmode" = msvcmsys; then + # This is just like msvisualcpp but w/o cygpath translation. + # Just convert the backslash-escaped backslashes to single forward + # slashes to satisfy depend.m4 + cygpath_u='sed s,\\\\,/,g' + depmode=msvisualcpp +fi + +if test "$depmode" = msvc7msys; then + # This is just like msvc7 but w/o cygpath translation. + # Just convert the backslash-escaped backslashes to single forward + # slashes to satisfy depend.m4 + cygpath_u='sed s,\\\\,/,g' + depmode=msvc7 +fi + +if test "$depmode" = xlc; then + # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. + gccflag=-qmakedep=gcc,-MF + depmode=gcc +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. +## Unfortunately, FreeBSD c89 acceptance of flags depends upon +## the command line argument order; so add the flags where they +## appear in depend2.am. Note that the slowdown incurred here +## affects only configure: in makefiles, %FASTDEP% shortcuts this. + for arg + do + case $arg in + -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; + *) set fnord "$@" "$arg" ;; + esac + shift # fnord + shift # $arg + done + "$@" + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. +## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. +## (see the conditional assignment to $gccflag above). +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). Also, it might not be +## supported by the other compilers which use the 'gcc' depmode. +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + # The second -e expression handles DOS-style file names with drive + # letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the "deleted header file" problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. +## Some versions of gcc put a space before the ':'. On the theory +## that the space means something, we add a space to the output as +## well. hp depmode also adds that space, but also prefixes the VPATH +## to the object. Take care to not repeat it in the output. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like '#:fec' to the end of the + # dependency line. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ + | tr "$nl" ' ' >> "$depfile" + echo >> "$depfile" + # The second pass generates a dummy entry for each header file. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> "$depfile" + else + make_dummy_depfile + fi + rm -f "$tmpdepfile" + ;; + +xlc) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. In older versions, this file always lives in the + # current directory. Also, the AIX compiler puts '$object:' at the + # start of each line; $object doesn't have directory information. + # Version 6 uses the directory in both cases. + set_dir_from "$object" + set_base_from "$object" + if test "$libtool" = yes; then + tmpdepfile1=$dir$base.u + tmpdepfile2=$base.u + tmpdepfile3=$dir.libs/$base.u + "$@" -Wc,-M + else + tmpdepfile1=$dir$base.u + tmpdepfile2=$dir$base.u + tmpdepfile3=$dir$base.u + "$@" -M + fi + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + do + test -f "$tmpdepfile" && break + done + aix_post_process_depfile + ;; + +tcc) + # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 + # FIXME: That version still under development at the moment of writing. + # Make that this statement remains true also for stable, released + # versions. + # It will wrap lines (doesn't matter whether long or short) with a + # trailing '\', as in: + # + # foo.o : \ + # foo.c \ + # foo.h \ + # + # It will put a trailing '\' even on the last line, and will use leading + # spaces rather than leading tabs (at least since its commit 0394caf7 + # "Emit spaces for -MD"). + "$@" -MD -MF "$tmpdepfile" + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. + # We have to change lines of the first kind to '$object: \'. + sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" + # And for each line of the second kind, we have to emit a 'dep.h:' + # dummy dependency, to avoid the deleted-header problem. + sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" + rm -f "$tmpdepfile" + ;; + +## The order of this option in the case statement is important, since the +## shell code in configure will try each of these formats in the order +## listed in this file. A plain '-MD' option would be understood by many +## compilers, so we must ensure this comes after the gcc and icc options. +pgcc) + # Portland's C compiler understands '-MD'. + # Will always output deps to 'file.d' where file is the root name of the + # source file under compilation, even if file resides in a subdirectory. + # The object file name does not affect the name of the '.d' file. + # pgcc 10.2 will output + # foo.o: sub/foo.c sub/foo.h + # and will wrap long lines using '\' : + # foo.o: sub/foo.c ... \ + # sub/foo.h ... \ + # ... + set_dir_from "$object" + # Use the source, not the object, to determine the base name, since + # that's sadly what pgcc will do too. + set_base_from "$source" + tmpdepfile=$base.d + + # For projects that build the same source file twice into different object + # files, the pgcc approach of using the *source* file root name can cause + # problems in parallel builds. Use a locking strategy to avoid stomping on + # the same $tmpdepfile. + lockdir=$base.d-lock + trap " + echo '$0: caught signal, cleaning up...' >&2 + rmdir '$lockdir' + exit 1 + " 1 2 13 15 + numtries=100 + i=$numtries + while test $i -gt 0; do + # mkdir is a portable test-and-set. + if mkdir "$lockdir" 2>/dev/null; then + # This process acquired the lock. + "$@" -MD + stat=$? + # Release the lock. + rmdir "$lockdir" + break + else + # If the lock is being held by a different process, wait + # until the winning process is done or we timeout. + while test -d "$lockdir" && test $i -gt 0; do + sleep 1 + i=`expr $i - 1` + done + fi + i=`expr $i - 1` + done + trap - 1 2 13 15 + if test $i -le 0; then + echo "$0: failed to acquire lock after $numtries attempts" >&2 + echo "$0: check lockdir '$lockdir'" >&2 + exit 1 + fi + + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + # Each line is of the form `foo.o: dependent.h', + # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process this invocation + # correctly. Breaking it into two sed invocations is a workaround. + sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp2) + # The "hp" stanza above does not work with aCC (C++) and HP's ia64 + # compilers, which have integrated preprocessors. The correct option + # to use with these is +Maked; it writes dependencies to a file named + # 'foo.d', which lands next to the object file, wherever that + # happens to be. + # Much of this is similar to the tru64 case; see comments there. + set_dir_from "$object" + set_base_from "$object" + if test "$libtool" = yes; then + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir.libs/$base.d + "$@" -Wc,+Maked + else + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir$base.d + "$@" +Maked + fi + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" + do + test -f "$tmpdepfile" && break + done + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" + # Add 'dependent.h:' lines. + sed -ne '2,${ + s/^ *// + s/ \\*$// + s/$/:/ + p + }' "$tmpdepfile" >> "$depfile" + else + make_dummy_depfile + fi + rm -f "$tmpdepfile" "$tmpdepfile2" + ;; + +tru64) + # The Tru64 compiler uses -MD to generate dependencies as a side + # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in 'foo.d' instead, so we check for that too. + # Subdirectories are respected. + set_dir_from "$object" + set_base_from "$object" + + if test "$libtool" = yes; then + # Libtool generates 2 separate objects for the 2 libraries. These + # two compilations output dependencies in $dir.libs/$base.o.d and + # in $dir$base.o.d. We have to check for both files, because + # one of the two compilations can be disabled. We should prefer + # $dir$base.o.d over $dir.libs/$base.o.d because the latter is + # automatically cleaned when .libs/ is deleted, while ignoring + # the former would cause a distcleancheck panic. + tmpdepfile1=$dir$base.o.d # libtool 1.5 + tmpdepfile2=$dir.libs/$base.o.d # Likewise. + tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 + "$@" -Wc,-MD + else + tmpdepfile1=$dir$base.d + tmpdepfile2=$dir$base.d + tmpdepfile3=$dir$base.d + "$@" -MD + fi + + stat=$? + if test $stat -ne 0; then + rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + exit $stat + fi + + for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" + do + test -f "$tmpdepfile" && break + done + # Same post-processing that is required for AIX mode. + aix_post_process_depfile + ;; + +msvc7) + if test "$libtool" = yes; then + showIncludes=-Wc,-showIncludes + else + showIncludes=-showIncludes + fi + "$@" $showIncludes > "$tmpdepfile" + stat=$? + grep -v '^Note: including file: ' "$tmpdepfile" + if test $stat -ne 0; then + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + # The first sed program below extracts the file names and escapes + # backslashes for cygpath. The second sed program outputs the file + # name when reading, but also accumulates all include files in the + # hold buffer in order to output them again at the end. This only + # works with sed implementations that can handle large buffers. + sed < "$tmpdepfile" -n ' +/^Note: including file: *\(.*\)/ { + s//\1/ + s/\\/\\\\/g + p +}' | $cygpath_u | sort -u | sed -n ' +s/ /\\ /g +s/\(.*\)/'"$tab"'\1 \\/p +s/.\(.*\) \\/\1:/ +H +$ { + s/.*/'"$tab"'/ + G + p +}' >> "$depfile" + echo >> "$depfile" # make sure the fragment doesn't end with a backslash + rm -f "$tmpdepfile" + ;; + +msvc7msys) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout, regardless of -o. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + # Remove '-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + test -z "$dashmflag" && dashmflag=-M + # Require at least two characters before searching for ':' + # in the target name. This is to cope with DOS-style filenames: + # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. + "$@" $dashmflag | + sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process this sed invocation + # correctly. Breaking it into two sed invocations is a workaround. + tr ' ' "$nl" < "$tmpdepfile" \ + | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + "$@" || exit $? + # Remove any Libtool call + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + # X makedepend + shift + cleared=no eat=no + for arg + do + case $cleared in + no) + set ""; shift + cleared=yes ;; + esac + if test $eat = yes; then + eat=no + continue + fi + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift ;; + # Strip any option that makedepend may not understand. Remove + # the object too, otherwise makedepend will parse it as a source file. + -arch) + eat=yes ;; + -*|$object) + ;; + *) + set fnord "$@" "$arg"; shift ;; + esac + done + obj_suffix=`echo "$object" | sed 's/^.*\././'` + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" + rm -f "$depfile" + # makedepend may prepend the VPATH from the source file name to the object. + # No need to regex-escape $object, excess matching of '.' is harmless. + sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" + # Some versions of the HPUX 10.20 sed can't process the last invocation + # correctly. Breaking it into two sed invocations is a workaround. + sed '1,2d' "$tmpdepfile" \ + | tr ' ' "$nl" \ + | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ + | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + # Remove '-o $object'. + IFS=" " + for arg + do + case $arg in + -o) + shift + ;; + $object) + shift + ;; + *) + set fnord "$@" "$arg" + shift # fnord + shift # $arg + ;; + esac + done + + "$@" -E \ + | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ + -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ + | sed '$ s: \\$::' > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the preprocessed file to stdout. + "$@" || exit $? + + # Remove the call to Libtool. + if test "$libtool" = yes; then + while test "X$1" != 'X--mode=compile'; do + shift + done + shift + fi + + IFS=" " + for arg + do + case "$arg" in + -o) + shift + ;; + $object) + shift + ;; + "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") + set fnord "$@" + shift + shift + ;; + *) + set fnord "$@" "$arg" + shift + shift + ;; + esac + done + "$@" -E 2>/dev/null | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" + rm -f "$depfile" + echo "$object : \\" > "$depfile" + sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" + echo "$tab" >> "$depfile" + sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvcmsys) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/install-sh cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/install-sh --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/install-sh 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/install-sh 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,501 @@ +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2013-12-25.23; # UTC + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# 'make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. + +tab=' ' +nl=' +' +IFS=" $tab$nl" + +# Set DOITPROG to "echo" to test this script. + +doit=${DOITPROG-} +doit_exec=${doit:-exec} + +# Put in absolute file names if you don't have them in your path; +# or use environment vars. + +chgrpprog=${CHGRPPROG-chgrp} +chmodprog=${CHMODPROG-chmod} +chownprog=${CHOWNPROG-chown} +cmpprog=${CMPPROG-cmp} +cpprog=${CPPROG-cp} +mkdirprog=${MKDIRPROG-mkdir} +mvprog=${MVPROG-mv} +rmprog=${RMPROG-rm} +stripprog=${STRIPPROG-strip} + +posix_mkdir= + +# Desired mode of installed file. +mode=0755 + +chgrpcmd= +chmodcmd=$chmodprog +chowncmd= +mvcmd=$mvprog +rmcmd="$rmprog -f" +stripcmd= + +src= +dst= +dir_arg= +dst_arg= + +copy_on_change=false +is_target_a_directory=possibly + +usage="\ +Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: + --help display this help and exit. + --version display version info and exit. + + -c (ignored) + -C install only if different (preserve the last data modification time) + -d create directories instead of installing files. + -g GROUP $chgrpprog installed files to GROUP. + -m MODE $chmodprog installed files to MODE. + -o USER $chownprog installed files to USER. + -s $stripprog installed files. + -t DIRECTORY install into DIRECTORY. + -T report an error if DSTFILE is a directory. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG + RMPROG STRIPPROG +" + +while test $# -ne 0; do + case $1 in + -c) ;; + + -C) copy_on_change=true;; + + -d) dir_arg=true;; + + -g) chgrpcmd="$chgrpprog $2" + shift;; + + --help) echo "$usage"; exit $?;; + + -m) mode=$2 + case $mode in + *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) + echo "$0: invalid mode: $mode" >&2 + exit 1;; + esac + shift;; + + -o) chowncmd="$chownprog $2" + shift;; + + -s) stripcmd=$stripprog;; + + -t) + is_target_a_directory=always + dst_arg=$2 + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + shift;; + + -T) is_target_a_directory=never;; + + --version) echo "$0 $scriptversion"; exit $?;; + + --) shift + break;; + + -*) echo "$0: invalid option: $1" >&2 + exit 1;; + + *) break;; + esac + shift +done + +# We allow the use of options -d and -T together, by making -d +# take the precedence; this is for compatibility with GNU install. + +if test -n "$dir_arg"; then + if test -n "$dst_arg"; then + echo "$0: target directory not allowed when installing a directory." >&2 + exit 1 + fi +fi + +if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then + # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dst_arg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dst_arg" + shift # fnord + fi + shift # arg + dst_arg=$arg + # Protect names problematic for 'test' and other utilities. + case $dst_arg in + -* | [=\(\)!]) dst_arg=./$dst_arg;; + esac + done +fi + +if test $# -eq 0; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call 'install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +if test -z "$dir_arg"; then + if test $# -gt 1 || test "$is_target_a_directory" = always; then + if test ! -d "$dst_arg"; then + echo "$0: $dst_arg: Is not a directory." >&2 + exit 1 + fi + fi +fi + +if test -z "$dir_arg"; then + do_exit='(exit $ret); exit $ret' + trap "ret=129; $do_exit" 1 + trap "ret=130; $do_exit" 2 + trap "ret=141; $do_exit" 13 + trap "ret=143; $do_exit" 15 + + # Set umask so as not to create temps with too-generous modes. + # However, 'strip' requires both read and write access to temps. + case $mode in + # Optimize common cases. + *644) cp_umask=133;; + *755) cp_umask=22;; + + *[0-7]) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw='% 200' + fi + cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; + *) + if test -z "$stripcmd"; then + u_plus_rw= + else + u_plus_rw=,u+rw + fi + cp_umask=$mode$u_plus_rw;; + esac +fi + +for src +do + # Protect names problematic for 'test' and other utilities. + case $src in + -* | [=\(\)!]) src=./$src;; + esac + + if test -n "$dir_arg"; then + dst=$src + dstdir=$dst + test -d "$dstdir" + dstdir_status=$? + else + + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dst_arg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + dst=$dst_arg + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test "$is_target_a_directory" = never; then + echo "$0: $dst_arg: Is a directory" >&2 + exit 1 + fi + dstdir=$dst + dst=$dstdir/`basename "$src"` + dstdir_status=0 + else + dstdir=`dirname "$dst"` + test -d "$dstdir" + dstdir_status=$? + fi + fi + + obsolete_mkdir_used=false + + if test $dstdir_status != 0; then + case $posix_mkdir in + '') + # Create intermediate dirs using mode 755 as modified by the umask. + # This is like FreeBSD 'install' as of 1997-10-28. + umask=`umask` + case $stripcmd.$umask in + # Optimize common cases. + *[2367][2367]) mkdir_umask=$umask;; + .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; + + *[0-7]) + mkdir_umask=`expr $umask + 22 \ + - $umask % 100 % 40 + $umask % 20 \ + - $umask % 10 % 4 + $umask % 2 + `;; + *) mkdir_umask=$umask,go-w;; + esac + + # With -d, create the new directory with the user-specified mode. + # Otherwise, rely on $mkdir_umask. + if test -n "$dir_arg"; then + mkdir_mode=-m$mode + else + mkdir_mode= + fi + + posix_mkdir=false + case $umask in + *[123567][0-7][0-7]) + # POSIX mkdir -p sets u+wx bits regardless of umask, which + # is incompatible with FreeBSD 'install' when (umask & 300) != 0. + ;; + *) + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 + + if (umask $mkdir_umask && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + ls_ld_tmpdir=`ls -ld "$tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/d" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null + fi + trap '' 0;; + esac;; + esac + + if + $posix_mkdir && ( + umask $mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" + ) + then : + else + + # The umask is ridiculous, or mkdir does not conform to POSIX, + # or it failed possibly due to a race condition. Create the + # directory the slow way, step by step, checking for races as we go. + + case $dstdir in + /*) prefix='/';; + [-=\(\)!]*) prefix='./';; + *) prefix='';; + esac + + oIFS=$IFS + IFS=/ + set -f + set fnord $dstdir + shift + set +f + IFS=$oIFS + + prefixes= + + for d + do + test X"$d" = X && continue + + prefix=$prefix$d + if test -d "$prefix"; then + prefixes= + else + if $posix_mkdir; then + (umask=$mkdir_umask && + $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break + # Don't fail if two instances are running concurrently. + test -d "$prefix" || exit 1 + else + case $prefix in + *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; + *) qprefix=$prefix;; + esac + prefixes="$prefixes '$qprefix'" + fi + fi + prefix=$prefix/ + done + + if test -n "$prefixes"; then + # Don't fail if two instances are running concurrently. + (umask $mkdir_umask && + eval "\$doit_exec \$mkdirprog $prefixes") || + test -d "$dstdir" || exit 1 + obsolete_mkdir_used=true + fi + fi + fi + + if test -n "$dir_arg"; then + { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && + { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || + test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 + else + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 + + # Copy the file name to the temp name. + (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && + { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && + { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && + { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && + + # If -C, don't bother to copy if it wouldn't change the file. + if $copy_on_change && + old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && + new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && + set -f && + set X $old && old=:$2:$4:$5:$6 && + set X $new && new=:$2:$4:$5:$6 && + set +f && + test "$old" = "$new" && + $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 + then + rm -f "$dsttmp" + else + # Rename the file to the real destination. + $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || + + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + { + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + test ! -f "$dst" || + $doit $rmcmd -f "$dst" 2>/dev/null || + { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && + { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + } || + { echo "$0: cannot unlink or rename $dst" >&2 + (exit 1); exit 1 + } + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dst" + } + fi || exit 1 + + trap '' 0 + fi +done + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/ltmain.sh cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/ltmain.sh --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/ltmain.sh 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/ltmain.sh 2016-12-22 14:07:29.000000000 +0000 @@ -0,0 +1,11147 @@ +#! /bin/sh +## DO NOT EDIT - This file generated from ./build-aux/ltmain.in +## by inline-source v2014-01-03.01 + +# libtool (GNU libtool) 2.4.6 +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit , 1996 + +# Copyright (C) 1996-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool 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. +# +# As a special exception to the GNU General Public License, +# if you distribute this file as part of a program or library that +# is built using GNU Libtool, you may include this file under the +# same distribution terms that you use for the rest of that program. +# +# GNU Libtool 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, see . + + +PROGRAM=libtool +PACKAGE=libtool +VERSION=2.4.6 +package_revision=2.4.6 + + +## ------ ## +## Usage. ## +## ------ ## + +# Run './libtool --help' for help with using this script from the +# command line. + + +## ------------------------------- ## +## User overridable command paths. ## +## ------------------------------- ## + +# After configure completes, it has a better idea of some of the +# shell tools we need than the defaults used by the functions shared +# with bootstrap, so set those here where they can still be over- +# ridden by the user, but otherwise take precedence. + +: ${AUTOCONF="autoconf"} +: ${AUTOMAKE="automake"} + + +## -------------------------- ## +## Source external libraries. ## +## -------------------------- ## + +# Much of our low-level functionality needs to be sourced from external +# libraries, which are installed to $pkgauxdir. + +# Set a version string for this script. +scriptversion=2015-01-20.17; # UTC + +# General shell script boiler plate, and helper functions. +# Written by Gary V. Vaughan, 2004 + +# Copyright (C) 2004-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# 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 3 of the License, or +# (at your option) any later version. + +# As a special exception to the GNU General Public License, if you distribute +# this file as part of a program or library that is built using GNU Libtool, +# you may include this file under the same distribution terms that you use +# for the rest of that program. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNES 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, see . + +# Please report bugs or propose patches to gary@gnu.org. + + +## ------ ## +## Usage. ## +## ------ ## + +# Evaluate this file near the top of your script to gain access to +# the functions and variables defined here: +# +# . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh +# +# If you need to override any of the default environment variable +# settings, do that before evaluating this file. + + +## -------------------- ## +## Shell normalisation. ## +## -------------------- ## + +# Some shells need a little help to be as Bourne compatible as possible. +# Before doing anything else, make sure all that help has been provided! + +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac +fi + +# NLS nuisances: We save the old values in case they are required later. +_G_user_locale= +_G_safe_locale= +for _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES +do + eval "if test set = \"\${$_G_var+set}\"; then + save_$_G_var=\$$_G_var + $_G_var=C + export $_G_var + _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\" + _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\" + fi" +done + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Make sure IFS has a sensible default +sp=' ' +nl=' +' +IFS="$sp $nl" + +# There are apparently some retarded systems that use ';' as a PATH separator! +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + + +## ------------------------- ## +## Locate command utilities. ## +## ------------------------- ## + + +# func_executable_p FILE +# ---------------------- +# Check that FILE is an executable regular file. +func_executable_p () +{ + test -f "$1" && test -x "$1" +} + + +# func_path_progs PROGS_LIST CHECK_FUNC [PATH] +# -------------------------------------------- +# Search for either a program that responds to --version with output +# containing "GNU", or else returned by CHECK_FUNC otherwise, by +# trying all the directories in PATH with each of the elements of +# PROGS_LIST. +# +# CHECK_FUNC should accept the path to a candidate program, and +# set $func_check_prog_result if it truncates its output less than +# $_G_path_prog_max characters. +func_path_progs () +{ + _G_progs_list=$1 + _G_check_func=$2 + _G_PATH=${3-"$PATH"} + + _G_path_prog_max=0 + _G_path_prog_found=false + _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:} + for _G_dir in $_G_PATH; do + IFS=$_G_save_IFS + test -z "$_G_dir" && _G_dir=. + for _G_prog_name in $_G_progs_list; do + for _exeext in '' .EXE; do + _G_path_prog=$_G_dir/$_G_prog_name$_exeext + func_executable_p "$_G_path_prog" || continue + case `"$_G_path_prog" --version 2>&1` in + *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;; + *) $_G_check_func $_G_path_prog + func_path_progs_result=$func_check_prog_result + ;; + esac + $_G_path_prog_found && break 3 + done + done + done + IFS=$_G_save_IFS + test -z "$func_path_progs_result" && { + echo "no acceptable sed could be found in \$PATH" >&2 + exit 1 + } +} + + +# We want to be able to use the functions in this file before configure +# has figured out where the best binaries are kept, which means we have +# to search for them ourselves - except when the results are already set +# where we skip the searches. + +# Unless the user overrides by setting SED, search the path for either GNU +# sed, or the sed that truncates its output the least. +test -z "$SED" && { + _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for _G_i in 1 2 3 4 5 6 7; do + _G_sed_script=$_G_sed_script$nl$_G_sed_script + done + echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed + _G_sed_script= + + func_check_prog_sed () + { + _G_path_prog=$1 + + _G_count=0 + printf 0123456789 >conftest.in + while : + do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo '' >> conftest.nl + "$_G_path_prog" -f conftest.sed conftest.out 2>/dev/null || break + diff conftest.out conftest.nl >/dev/null 2>&1 || break + _G_count=`expr $_G_count + 1` + if test "$_G_count" -gt "$_G_path_prog_max"; then + # Best one so far, save it but keep looking for a better one + func_check_prog_result=$_G_path_prog + _G_path_prog_max=$_G_count + fi + # 10*(2^10) chars as input seems more than enough + test 10 -lt "$_G_count" && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out + } + + func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin + rm -f conftest.sed + SED=$func_path_progs_result +} + + +# Unless the user overrides by setting GREP, search the path for either GNU +# grep, or the grep that truncates its output the least. +test -z "$GREP" && { + func_check_prog_grep () + { + _G_path_prog=$1 + + _G_count=0 + _G_path_prog_max=0 + printf 0123456789 >conftest.in + while : + do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo 'GREP' >> conftest.nl + "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' conftest.out 2>/dev/null || break + diff conftest.out conftest.nl >/dev/null 2>&1 || break + _G_count=`expr $_G_count + 1` + if test "$_G_count" -gt "$_G_path_prog_max"; then + # Best one so far, save it but keep looking for a better one + func_check_prog_result=$_G_path_prog + _G_path_prog_max=$_G_count + fi + # 10*(2^10) chars as input seems more than enough + test 10 -lt "$_G_count" && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out + } + + func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin + GREP=$func_path_progs_result +} + + +## ------------------------------- ## +## User overridable command paths. ## +## ------------------------------- ## + +# All uppercase variable names are used for environment variables. These +# variables can be overridden by the user before calling a script that +# uses them if a suitable command of that name is not already available +# in the command search PATH. + +: ${CP="cp -f"} +: ${ECHO="printf %s\n"} +: ${EGREP="$GREP -E"} +: ${FGREP="$GREP -F"} +: ${LN_S="ln -s"} +: ${MAKE="make"} +: ${MKDIR="mkdir"} +: ${MV="mv -f"} +: ${RM="rm -f"} +: ${SHELL="${CONFIG_SHELL-/bin/sh}"} + + +## -------------------- ## +## Useful sed snippets. ## +## -------------------- ## + +sed_dirname='s|/[^/]*$||' +sed_basename='s|^.*/||' + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s|\([`"$\\]\)|\\\1|g' + +# Same as above, but do not quote variable references. +sed_double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution that turns a string into a regex matching for the +# string literally. +sed_make_literal_regex='s|[].[^$\\*\/]|\\&|g' + +# Sed substitution that converts a w32 file name or path +# that contains forward slashes, into one that contains +# (escaped) backslashes. A very naive implementation. +sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' + +# Re-'\' parameter expansions in output of sed_double_quote_subst that +# were '\'-ed in input to the same. If an odd number of '\' preceded a +# '$' in input to sed_double_quote_subst, that '$' was protected from +# expansion. Since each input '\' is now two '\'s, look for any number +# of runs of four '\'s followed by two '\'s and then a '$'. '\' that '$'. +_G_bs='\\' +_G_bs2='\\\\' +_G_bs4='\\\\\\\\' +_G_dollar='\$' +sed_double_backslash="\ + s/$_G_bs4/&\\ +/g + s/^$_G_bs2$_G_dollar/$_G_bs&/ + s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g + s/\n//g" + + +## ----------------- ## +## Global variables. ## +## ----------------- ## + +# Except for the global variables explicitly listed below, the following +# functions in the '^func_' namespace, and the '^require_' namespace +# variables initialised in the 'Resource management' section, sourcing +# this file will not pollute your global namespace with anything +# else. There's no portable way to scope variables in Bourne shell +# though, so actually running these functions will sometimes place +# results into a variable named after the function, and often use +# temporary variables in the '^_G_' namespace. If you are careful to +# avoid using those namespaces casually in your sourcing script, things +# should continue to work as you expect. And, of course, you can freely +# overwrite any of the functions or variables defined here before +# calling anything to customize them. + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 +EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. +EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. + +# Allow overriding, eg assuming that you follow the convention of +# putting '$debug_cmd' at the start of all your functions, you can get +# bash to show function call trace with: +# +# debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name +debug_cmd=${debug_cmd-":"} +exit_cmd=: + +# By convention, finish your script with: +# +# exit $exit_status +# +# so that you can set exit_status to non-zero if you want to indicate +# something went wrong during execution without actually bailing out at +# the point of failure. +exit_status=$EXIT_SUCCESS + +# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh +# is ksh but when the shell is invoked as "sh" and the current value of +# the _XPG environment variable is not equal to 1 (one), the special +# positional parameter $0, within a function call, is the name of the +# function. +progpath=$0 + +# The name of this program. +progname=`$ECHO "$progpath" |$SED "$sed_basename"` + +# Make sure we have an absolute progpath for reexecution: +case $progpath in + [\\/]*|[A-Za-z]:\\*) ;; + *[\\/]*) + progdir=`$ECHO "$progpath" |$SED "$sed_dirname"` + progdir=`cd "$progdir" && pwd` + progpath=$progdir/$progname + ;; + *) + _G_IFS=$IFS + IFS=${PATH_SEPARATOR-:} + for progdir in $PATH; do + IFS=$_G_IFS + test -x "$progdir/$progname" && break + done + IFS=$_G_IFS + test -n "$progdir" || progdir=`pwd` + progpath=$progdir/$progname + ;; +esac + + +## ----------------- ## +## Standard options. ## +## ----------------- ## + +# The following options affect the operation of the functions defined +# below, and should be set appropriately depending on run-time para- +# meters passed on the command line. + +opt_dry_run=false +opt_quiet=false +opt_verbose=false + +# Categories 'all' and 'none' are always available. Append any others +# you will pass as the first argument to func_warning from your own +# code. +warning_categories= + +# By default, display warnings according to 'opt_warning_types'. Set +# 'warning_func' to ':' to elide all warnings, or func_fatal_error to +# treat the next displayed warning as a fatal error. +warning_func=func_warn_and_continue + +# Set to 'all' to display all warnings, 'none' to suppress all +# warnings, or a space delimited list of some subset of +# 'warning_categories' to display only the listed warnings. +opt_warning_types=all + + +## -------------------- ## +## Resource management. ## +## -------------------- ## + +# This section contains definitions for functions that each ensure a +# particular resource (a file, or a non-empty configuration variable for +# example) is available, and if appropriate to extract default values +# from pertinent package files. Call them using their associated +# 'require_*' variable to ensure that they are executed, at most, once. +# +# It's entirely deliberate that calling these functions can set +# variables that don't obey the namespace limitations obeyed by the rest +# of this file, in order that that they be as useful as possible to +# callers. + + +# require_term_colors +# ------------------- +# Allow display of bold text on terminals that support it. +require_term_colors=func_require_term_colors +func_require_term_colors () +{ + $debug_cmd + + test -t 1 && { + # COLORTERM and USE_ANSI_COLORS environment variables take + # precedence, because most terminfo databases neglect to describe + # whether color sequences are supported. + test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"} + + if test 1 = "$USE_ANSI_COLORS"; then + # Standard ANSI escape sequences + tc_reset='' + tc_bold=''; tc_standout='' + tc_red=''; tc_green='' + tc_blue=''; tc_cyan='' + else + # Otherwise trust the terminfo database after all. + test -n "`tput sgr0 2>/dev/null`" && { + tc_reset=`tput sgr0` + test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold` + tc_standout=$tc_bold + test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso` + test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1` + test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2` + test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4` + test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5` + } + fi + } + + require_term_colors=: +} + + +## ----------------- ## +## Function library. ## +## ----------------- ## + +# This section contains a variety of useful functions to call in your +# scripts. Take note of the portable wrappers for features provided by +# some modern shells, which will fall back to slower equivalents on +# less featureful shells. + + +# func_append VAR VALUE +# --------------------- +# Append VALUE onto the existing contents of VAR. + + # We should try to minimise forks, especially on Windows where they are + # unreasonably slow, so skip the feature probes when bash or zsh are + # being used: + if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then + : ${_G_HAVE_ARITH_OP="yes"} + : ${_G_HAVE_XSI_OPS="yes"} + # The += operator was introduced in bash 3.1 + case $BASH_VERSION in + [12].* | 3.0 | 3.0*) ;; + *) + : ${_G_HAVE_PLUSEQ_OP="yes"} + ;; + esac + fi + + # _G_HAVE_PLUSEQ_OP + # Can be empty, in which case the shell is probed, "yes" if += is + # useable or anything else if it does not work. + test -z "$_G_HAVE_PLUSEQ_OP" \ + && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \ + && _G_HAVE_PLUSEQ_OP=yes + +if test yes = "$_G_HAVE_PLUSEQ_OP" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_append () + { + $debug_cmd + + eval "$1+=\$2" + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_append () + { + $debug_cmd + + eval "$1=\$$1\$2" + } +fi + + +# func_append_quoted VAR VALUE +# ---------------------------- +# Quote VALUE and append to the end of shell variable VAR, separated +# by a space. +if test yes = "$_G_HAVE_PLUSEQ_OP"; then + eval 'func_append_quoted () + { + $debug_cmd + + func_quote_for_eval "$2" + eval "$1+=\\ \$func_quote_for_eval_result" + }' +else + func_append_quoted () + { + $debug_cmd + + func_quote_for_eval "$2" + eval "$1=\$$1\\ \$func_quote_for_eval_result" + } +fi + + +# func_append_uniq VAR VALUE +# -------------------------- +# Append unique VALUE onto the existing contents of VAR, assuming +# entries are delimited by the first character of VALUE. For example: +# +# func_append_uniq options " --another-option option-argument" +# +# will only append to $options if " --another-option option-argument " +# is not already present somewhere in $options already (note spaces at +# each end implied by leading space in second argument). +func_append_uniq () +{ + $debug_cmd + + eval _G_current_value='`$ECHO $'$1'`' + _G_delim=`expr "$2" : '\(.\)'` + + case $_G_delim$_G_current_value$_G_delim in + *"$2$_G_delim"*) ;; + *) func_append "$@" ;; + esac +} + + +# func_arith TERM... +# ------------------ +# Set func_arith_result to the result of evaluating TERMs. + test -z "$_G_HAVE_ARITH_OP" \ + && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \ + && _G_HAVE_ARITH_OP=yes + +if test yes = "$_G_HAVE_ARITH_OP"; then + eval 'func_arith () + { + $debug_cmd + + func_arith_result=$(( $* )) + }' +else + func_arith () + { + $debug_cmd + + func_arith_result=`expr "$@"` + } +fi + + +# func_basename FILE +# ------------------ +# Set func_basename_result to FILE with everything up to and including +# the last / stripped. +if test yes = "$_G_HAVE_XSI_OPS"; then + # If this shell supports suffix pattern removal, then use it to avoid + # forking. Hide the definitions single quotes in case the shell chokes + # on unsupported syntax... + _b='func_basename_result=${1##*/}' + _d='case $1 in + */*) func_dirname_result=${1%/*}$2 ;; + * ) func_dirname_result=$3 ;; + esac' + +else + # ...otherwise fall back to using sed. + _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`' + _d='func_dirname_result=`$ECHO "$1" |$SED "$sed_dirname"` + if test "X$func_dirname_result" = "X$1"; then + func_dirname_result=$3 + else + func_append func_dirname_result "$2" + fi' +fi + +eval 'func_basename () +{ + $debug_cmd + + '"$_b"' +}' + + +# func_dirname FILE APPEND NONDIR_REPLACEMENT +# ------------------------------------------- +# Compute the dirname of FILE. If nonempty, add APPEND to the result, +# otherwise set result to NONDIR_REPLACEMENT. +eval 'func_dirname () +{ + $debug_cmd + + '"$_d"' +}' + + +# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT +# -------------------------------------------------------- +# Perform func_basename and func_dirname in a single function +# call: +# dirname: Compute the dirname of FILE. If nonempty, +# add APPEND to the result, otherwise set result +# to NONDIR_REPLACEMENT. +# value returned in "$func_dirname_result" +# basename: Compute filename of FILE. +# value retuned in "$func_basename_result" +# For efficiency, we do not delegate to the functions above but instead +# duplicate the functionality here. +eval 'func_dirname_and_basename () +{ + $debug_cmd + + '"$_b"' + '"$_d"' +}' + + +# func_echo ARG... +# ---------------- +# Echo program name prefixed message. +func_echo () +{ + $debug_cmd + + _G_message=$* + + func_echo_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_IFS + $ECHO "$progname: $_G_line" + done + IFS=$func_echo_IFS +} + + +# func_echo_all ARG... +# -------------------- +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "$*" +} + + +# func_echo_infix_1 INFIX ARG... +# ------------------------------ +# Echo program name, followed by INFIX on the first line, with any +# additional lines not showing INFIX. +func_echo_infix_1 () +{ + $debug_cmd + + $require_term_colors + + _G_infix=$1; shift + _G_indent=$_G_infix + _G_prefix="$progname: $_G_infix: " + _G_message=$* + + # Strip color escape sequences before counting printable length + for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan" + do + test -n "$_G_tc" && { + _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"` + _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"` + } + done + _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`" " ## exclude from sc_prohibit_nested_quotes + + func_echo_infix_1_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_infix_1_IFS + $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2 + _G_prefix=$_G_indent + done + IFS=$func_echo_infix_1_IFS +} + + +# func_error ARG... +# ----------------- +# Echo program name prefixed message to standard error. +func_error () +{ + $debug_cmd + + $require_term_colors + + func_echo_infix_1 " $tc_standout${tc_red}error$tc_reset" "$*" >&2 +} + + +# func_fatal_error ARG... +# ----------------------- +# Echo program name prefixed message to standard error, and exit. +func_fatal_error () +{ + $debug_cmd + + func_error "$*" + exit $EXIT_FAILURE +} + + +# func_grep EXPRESSION FILENAME +# ----------------------------- +# Check whether EXPRESSION matches any line of FILENAME, without output. +func_grep () +{ + $debug_cmd + + $GREP "$1" "$2" >/dev/null 2>&1 +} + + +# func_len STRING +# --------------- +# Set func_len_result to the length of STRING. STRING may not +# start with a hyphen. + test -z "$_G_HAVE_XSI_OPS" \ + && (eval 'x=a/b/c; + test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ + && _G_HAVE_XSI_OPS=yes + +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_len () + { + $debug_cmd + + func_len_result=${#1} + }' +else + func_len () + { + $debug_cmd + + func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len` + } +fi + + +# func_mkdir_p DIRECTORY-PATH +# --------------------------- +# Make sure the entire path to DIRECTORY-PATH is available. +func_mkdir_p () +{ + $debug_cmd + + _G_directory_path=$1 + _G_dir_list= + + if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then + + # Protect directory names starting with '-' + case $_G_directory_path in + -*) _G_directory_path=./$_G_directory_path ;; + esac + + # While some portion of DIR does not yet exist... + while test ! -d "$_G_directory_path"; do + # ...make a list in topmost first order. Use a colon delimited + # list incase some portion of path contains whitespace. + _G_dir_list=$_G_directory_path:$_G_dir_list + + # If the last portion added has no slash in it, the list is done + case $_G_directory_path in */*) ;; *) break ;; esac + + # ...otherwise throw away the child directory and loop + _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"` + done + _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'` + + func_mkdir_p_IFS=$IFS; IFS=: + for _G_dir in $_G_dir_list; do + IFS=$func_mkdir_p_IFS + # mkdir can fail with a 'File exist' error if two processes + # try to create one of the directories concurrently. Don't + # stop in that case! + $MKDIR "$_G_dir" 2>/dev/null || : + done + IFS=$func_mkdir_p_IFS + + # Bail out if we (or some other process) failed to create a directory. + test -d "$_G_directory_path" || \ + func_fatal_error "Failed to create '$1'" + fi +} + + +# func_mktempdir [BASENAME] +# ------------------------- +# Make a temporary directory that won't clash with other running +# libtool processes, and avoids race conditions if possible. If +# given, BASENAME is the basename for that directory. +func_mktempdir () +{ + $debug_cmd + + _G_template=${TMPDIR-/tmp}/${1-$progname} + + if test : = "$opt_dry_run"; then + # Return a directory name, but don't create it in dry-run mode + _G_tmpdir=$_G_template-$$ + else + + # If mktemp works, use that first and foremost + _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null` + + if test ! -d "$_G_tmpdir"; then + # Failing that, at least try and use $RANDOM to avoid a race + _G_tmpdir=$_G_template-${RANDOM-0}$$ + + func_mktempdir_umask=`umask` + umask 0077 + $MKDIR "$_G_tmpdir" + umask $func_mktempdir_umask + fi + + # If we're not in dry-run mode, bomb out on failure + test -d "$_G_tmpdir" || \ + func_fatal_error "cannot create temporary directory '$_G_tmpdir'" + fi + + $ECHO "$_G_tmpdir" +} + + +# func_normal_abspath PATH +# ------------------------ +# Remove doubled-up and trailing slashes, "." path components, +# and cancel out any ".." path components in PATH after making +# it an absolute path. +func_normal_abspath () +{ + $debug_cmd + + # These SED scripts presuppose an absolute path with a trailing slash. + _G_pathcar='s|^/\([^/]*\).*$|\1|' + _G_pathcdr='s|^/[^/]*||' + _G_removedotparts=':dotsl + s|/\./|/|g + t dotsl + s|/\.$|/|' + _G_collapseslashes='s|/\{1,\}|/|g' + _G_finalslash='s|/*$|/|' + + # Start from root dir and reassemble the path. + func_normal_abspath_result= + func_normal_abspath_tpath=$1 + func_normal_abspath_altnamespace= + case $func_normal_abspath_tpath in + "") + # Empty path, that just means $cwd. + func_stripname '' '/' "`pwd`" + func_normal_abspath_result=$func_stripname_result + return + ;; + # The next three entries are used to spot a run of precisely + # two leading slashes without using negated character classes; + # we take advantage of case's first-match behaviour. + ///*) + # Unusual form of absolute path, do nothing. + ;; + //*) + # Not necessarily an ordinary path; POSIX reserves leading '//' + # and for example Cygwin uses it to access remote file shares + # over CIFS/SMB, so we conserve a leading double slash if found. + func_normal_abspath_altnamespace=/ + ;; + /*) + # Absolute path, do nothing. + ;; + *) + # Relative path, prepend $cwd. + func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath + ;; + esac + + # Cancel out all the simple stuff to save iterations. We also want + # the path to end with a slash for ease of parsing, so make sure + # there is one (and only one) here. + func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"` + while :; do + # Processed it all yet? + if test / = "$func_normal_abspath_tpath"; then + # If we ascended to the root using ".." the result may be empty now. + if test -z "$func_normal_abspath_result"; then + func_normal_abspath_result=/ + fi + break + fi + func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_pathcar"` + func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ + -e "$_G_pathcdr"` + # Figure out what to do with it + case $func_normal_abspath_tcomponent in + "") + # Trailing empty path component, ignore it. + ;; + ..) + # Parent dir; strip last assembled component from result. + func_dirname "$func_normal_abspath_result" + func_normal_abspath_result=$func_dirname_result + ;; + *) + # Actual path component, append it. + func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent" + ;; + esac + done + # Restore leading double-slash if one was found on entry. + func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result +} + + +# func_notquiet ARG... +# -------------------- +# Echo program name prefixed message only when not in quiet mode. +func_notquiet () +{ + $debug_cmd + + $opt_quiet || func_echo ${1+"$@"} + + # A bug in bash halts the script if the last line of a function + # fails when set -e is in force, so we need another command to + # work around that: + : +} + + +# func_relative_path SRCDIR DSTDIR +# -------------------------------- +# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR. +func_relative_path () +{ + $debug_cmd + + func_relative_path_result= + func_normal_abspath "$1" + func_relative_path_tlibdir=$func_normal_abspath_result + func_normal_abspath "$2" + func_relative_path_tbindir=$func_normal_abspath_result + + # Ascend the tree starting from libdir + while :; do + # check if we have found a prefix of bindir + case $func_relative_path_tbindir in + $func_relative_path_tlibdir) + # found an exact match + func_relative_path_tcancelled= + break + ;; + $func_relative_path_tlibdir*) + # found a matching prefix + func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir" + func_relative_path_tcancelled=$func_stripname_result + if test -z "$func_relative_path_result"; then + func_relative_path_result=. + fi + break + ;; + *) + func_dirname $func_relative_path_tlibdir + func_relative_path_tlibdir=$func_dirname_result + if test -z "$func_relative_path_tlibdir"; then + # Have to descend all the way to the root! + func_relative_path_result=../$func_relative_path_result + func_relative_path_tcancelled=$func_relative_path_tbindir + break + fi + func_relative_path_result=../$func_relative_path_result + ;; + esac + done + + # Now calculate path; take care to avoid doubling-up slashes. + func_stripname '' '/' "$func_relative_path_result" + func_relative_path_result=$func_stripname_result + func_stripname '/' '/' "$func_relative_path_tcancelled" + if test -n "$func_stripname_result"; then + func_append func_relative_path_result "/$func_stripname_result" + fi + + # Normalisation. If bindir is libdir, return '.' else relative path. + if test -n "$func_relative_path_result"; then + func_stripname './' '' "$func_relative_path_result" + func_relative_path_result=$func_stripname_result + fi + + test -n "$func_relative_path_result" || func_relative_path_result=. + + : +} + + +# func_quote_for_eval ARG... +# -------------------------- +# Aesthetically quote ARGs to be evaled later. +# This function returns two values: +# i) func_quote_for_eval_result +# double-quoted, suitable for a subsequent eval +# ii) func_quote_for_eval_unquoted_result +# has all characters that are still active within double +# quotes backslashified. +func_quote_for_eval () +{ + $debug_cmd + + func_quote_for_eval_unquoted_result= + func_quote_for_eval_result= + while test 0 -lt $#; do + case $1 in + *[\\\`\"\$]*) + _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;; + *) + _G_unquoted_arg=$1 ;; + esac + if test -n "$func_quote_for_eval_unquoted_result"; then + func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg" + else + func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg" + fi + + case $_G_unquoted_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting, command substitution and variable expansion + # for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + _G_quoted_arg=\"$_G_unquoted_arg\" + ;; + *) + _G_quoted_arg=$_G_unquoted_arg + ;; + esac + + if test -n "$func_quote_for_eval_result"; then + func_append func_quote_for_eval_result " $_G_quoted_arg" + else + func_append func_quote_for_eval_result "$_G_quoted_arg" + fi + shift + done +} + + +# func_quote_for_expand ARG +# ------------------------- +# Aesthetically quote ARG to be evaled later; same as above, +# but do not quote variable references. +func_quote_for_expand () +{ + $debug_cmd + + case $1 in + *[\\\`\"]*) + _G_arg=`$ECHO "$1" | $SED \ + -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;; + *) + _G_arg=$1 ;; + esac + + case $_G_arg in + # Double-quote args containing shell metacharacters to delay + # word splitting and command substitution for a subsequent eval. + # Many Bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + _G_arg=\"$_G_arg\" + ;; + esac + + func_quote_for_expand_result=$_G_arg +} + + +# func_stripname PREFIX SUFFIX NAME +# --------------------------------- +# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_stripname () + { + $debug_cmd + + # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are + # positional parameters, so assign one to ordinary variable first. + func_stripname_result=$3 + func_stripname_result=${func_stripname_result#"$1"} + func_stripname_result=${func_stripname_result%"$2"} + }' +else + func_stripname () + { + $debug_cmd + + case $2 in + .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;; + *) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;; + esac + } +fi + + +# func_show_eval CMD [FAIL_EXP] +# ----------------------------- +# Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. +func_show_eval () +{ + $debug_cmd + + _G_cmd=$1 + _G_fail_exp=${2-':'} + + func_quote_for_expand "$_G_cmd" + eval "func_notquiet $func_quote_for_expand_result" + + $opt_dry_run || { + eval "$_G_cmd" + _G_status=$? + if test 0 -ne "$_G_status"; then + eval "(exit $_G_status); $_G_fail_exp" + fi + } +} + + +# func_show_eval_locale CMD [FAIL_EXP] +# ------------------------------------ +# Unless opt_quiet is true, then output CMD. Then, if opt_dryrun is +# not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP +# is given, then evaluate it. Use the saved locale for evaluation. +func_show_eval_locale () +{ + $debug_cmd + + _G_cmd=$1 + _G_fail_exp=${2-':'} + + $opt_quiet || { + func_quote_for_expand "$_G_cmd" + eval "func_echo $func_quote_for_expand_result" + } + + $opt_dry_run || { + eval "$_G_user_locale + $_G_cmd" + _G_status=$? + eval "$_G_safe_locale" + if test 0 -ne "$_G_status"; then + eval "(exit $_G_status); $_G_fail_exp" + fi + } +} + + +# func_tr_sh +# ---------- +# Turn $1 into a string suitable for a shell variable name. +# Result is stored in $func_tr_sh_result. All characters +# not in the set a-zA-Z0-9_ are replaced with '_'. Further, +# if $1 begins with a digit, a '_' is prepended as well. +func_tr_sh () +{ + $debug_cmd + + case $1 in + [0-9]* | *[!a-zA-Z0-9_]*) + func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'` + ;; + * ) + func_tr_sh_result=$1 + ;; + esac +} + + +# func_verbose ARG... +# ------------------- +# Echo program name prefixed message in verbose mode only. +func_verbose () +{ + $debug_cmd + + $opt_verbose && func_echo "$*" + + : +} + + +# func_warn_and_continue ARG... +# ----------------------------- +# Echo program name prefixed warning message to standard error. +func_warn_and_continue () +{ + $debug_cmd + + $require_term_colors + + func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2 +} + + +# func_warning CATEGORY ARG... +# ---------------------------- +# Echo program name prefixed warning message to standard error. Warning +# messages can be filtered according to CATEGORY, where this function +# elides messages where CATEGORY is not listed in the global variable +# 'opt_warning_types'. +func_warning () +{ + $debug_cmd + + # CATEGORY must be in the warning_categories list! + case " $warning_categories " in + *" $1 "*) ;; + *) func_internal_error "invalid warning category '$1'" ;; + esac + + _G_category=$1 + shift + + case " $opt_warning_types " in + *" $_G_category "*) $warning_func ${1+"$@"} ;; + esac +} + + +# func_sort_ver VER1 VER2 +# ----------------------- +# 'sort -V' is not generally available. +# Note this deviates from the version comparison in automake +# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a +# but this should suffice as we won't be specifying old +# version formats or redundant trailing .0 in bootstrap.conf. +# If we did want full compatibility then we should probably +# use m4_version_compare from autoconf. +func_sort_ver () +{ + $debug_cmd + + printf '%s\n%s\n' "$1" "$2" \ + | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n +} + +# func_lt_ver PREV CURR +# --------------------- +# Return true if PREV and CURR are in the correct order according to +# func_sort_ver, otherwise false. Use it like this: +# +# func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..." +func_lt_ver () +{ + $debug_cmd + + test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q` +} + + +# Local variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-time-zone: "UTC" +# End: +#! /bin/sh + +# Set a version string for this script. +scriptversion=2014-01-07.03; # UTC + +# A portable, pluggable option parser for Bourne shell. +# Written by Gary V. Vaughan, 2010 + +# Copyright (C) 2010-2015 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# 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 3 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, see . + +# Please report bugs or propose patches to gary@gnu.org. + + +## ------ ## +## Usage. ## +## ------ ## + +# This file is a library for parsing options in your shell scripts along +# with assorted other useful supporting features that you can make use +# of too. +# +# For the simplest scripts you might need only: +# +# #!/bin/sh +# . relative/path/to/funclib.sh +# . relative/path/to/options-parser +# scriptversion=1.0 +# func_options ${1+"$@"} +# eval set dummy "$func_options_result"; shift +# ...rest of your script... +# +# In order for the '--version' option to work, you will need to have a +# suitably formatted comment like the one at the top of this file +# starting with '# Written by ' and ending with '# warranty; '. +# +# For '-h' and '--help' to work, you will also need a one line +# description of your script's purpose in a comment directly above the +# '# Written by ' line, like the one at the top of this file. +# +# The default options also support '--debug', which will turn on shell +# execution tracing (see the comment above debug_cmd below for another +# use), and '--verbose' and the func_verbose function to allow your script +# to display verbose messages only when your user has specified +# '--verbose'. +# +# After sourcing this file, you can plug processing for additional +# options by amending the variables from the 'Configuration' section +# below, and following the instructions in the 'Option parsing' +# section further down. + +## -------------- ## +## Configuration. ## +## -------------- ## + +# You should override these variables in your script after sourcing this +# file so that they reflect the customisations you have added to the +# option parser. + +# The usage line for option parsing errors and the start of '-h' and +# '--help' output messages. You can embed shell variables for delayed +# expansion at the time the message is displayed, but you will need to +# quote other shell meta-characters carefully to prevent them being +# expanded when the contents are evaled. +usage='$progpath [OPTION]...' + +# Short help message in response to '-h' and '--help'. Add to this or +# override it after sourcing this library to reflect the full set of +# options your script accepts. +usage_message="\ + --debug enable verbose shell tracing + -W, --warnings=CATEGORY + report the warnings falling in CATEGORY [all] + -v, --verbose verbosely report processing + --version print version information and exit + -h, --help print short or long help message and exit +" + +# Additional text appended to 'usage_message' in response to '--help'. +long_help_message=" +Warning categories include: + 'all' show all warnings + 'none' turn off all the warnings + 'error' warnings are treated as fatal errors" + +# Help message printed before fatal option parsing errors. +fatal_help="Try '\$progname --help' for more information." + + + +## ------------------------- ## +## Hook function management. ## +## ------------------------- ## + +# This section contains functions for adding, removing, and running hooks +# to the main code. A hook is just a named list of of function, that can +# be run in order later on. + +# func_hookable FUNC_NAME +# ----------------------- +# Declare that FUNC_NAME will run hooks added with +# 'func_add_hook FUNC_NAME ...'. +func_hookable () +{ + $debug_cmd + + func_append hookable_fns " $1" +} + + +# func_add_hook FUNC_NAME HOOK_FUNC +# --------------------------------- +# Request that FUNC_NAME call HOOK_FUNC before it returns. FUNC_NAME must +# first have been declared "hookable" by a call to 'func_hookable'. +func_add_hook () +{ + $debug_cmd + + case " $hookable_fns " in + *" $1 "*) ;; + *) func_fatal_error "'$1' does not accept hook functions." ;; + esac + + eval func_append ${1}_hooks '" $2"' +} + + +# func_remove_hook FUNC_NAME HOOK_FUNC +# ------------------------------------ +# Remove HOOK_FUNC from the list of functions called by FUNC_NAME. +func_remove_hook () +{ + $debug_cmd + + eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`' +} + + +# func_run_hooks FUNC_NAME [ARG]... +# --------------------------------- +# Run all hook functions registered to FUNC_NAME. +# It is assumed that the list of hook functions contains nothing more +# than a whitespace-delimited list of legal shell function names, and +# no effort is wasted trying to catch shell meta-characters or preserve +# whitespace. +func_run_hooks () +{ + $debug_cmd + + case " $hookable_fns " in + *" $1 "*) ;; + *) func_fatal_error "'$1' does not support hook funcions.n" ;; + esac + + eval _G_hook_fns=\$$1_hooks; shift + + for _G_hook in $_G_hook_fns; do + eval $_G_hook '"$@"' + + # store returned options list back into positional + # parameters for next 'cmd' execution. + eval _G_hook_result=\$${_G_hook}_result + eval set dummy "$_G_hook_result"; shift + done + + func_quote_for_eval ${1+"$@"} + func_run_hooks_result=$func_quote_for_eval_result +} + + + +## --------------- ## +## Option parsing. ## +## --------------- ## + +# In order to add your own option parsing hooks, you must accept the +# full positional parameter list in your hook function, remove any +# options that you action, and then pass back the remaining unprocessed +# options in '_result', escaped suitably for +# 'eval'. Like this: +# +# my_options_prep () +# { +# $debug_cmd +# +# # Extend the existing usage message. +# usage_message=$usage_message' +# -s, --silent don'\''t print informational messages +# ' +# +# func_quote_for_eval ${1+"$@"} +# my_options_prep_result=$func_quote_for_eval_result +# } +# func_add_hook func_options_prep my_options_prep +# +# +# my_silent_option () +# { +# $debug_cmd +# +# # Note that for efficiency, we parse as many options as we can +# # recognise in a loop before passing the remainder back to the +# # caller on the first unrecognised argument we encounter. +# while test $# -gt 0; do +# opt=$1; shift +# case $opt in +# --silent|-s) opt_silent=: ;; +# # Separate non-argument short options: +# -s*) func_split_short_opt "$_G_opt" +# set dummy "$func_split_short_opt_name" \ +# "-$func_split_short_opt_arg" ${1+"$@"} +# shift +# ;; +# *) set dummy "$_G_opt" "$*"; shift; break ;; +# esac +# done +# +# func_quote_for_eval ${1+"$@"} +# my_silent_option_result=$func_quote_for_eval_result +# } +# func_add_hook func_parse_options my_silent_option +# +# +# my_option_validation () +# { +# $debug_cmd +# +# $opt_silent && $opt_verbose && func_fatal_help "\ +# '--silent' and '--verbose' options are mutually exclusive." +# +# func_quote_for_eval ${1+"$@"} +# my_option_validation_result=$func_quote_for_eval_result +# } +# func_add_hook func_validate_options my_option_validation +# +# You'll alse need to manually amend $usage_message to reflect the extra +# options you parse. It's preferable to append if you can, so that +# multiple option parsing hooks can be added safely. + + +# func_options [ARG]... +# --------------------- +# All the functions called inside func_options are hookable. See the +# individual implementations for details. +func_hookable func_options +func_options () +{ + $debug_cmd + + func_options_prep ${1+"$@"} + eval func_parse_options \ + ${func_options_prep_result+"$func_options_prep_result"} + eval func_validate_options \ + ${func_parse_options_result+"$func_parse_options_result"} + + eval func_run_hooks func_options \ + ${func_validate_options_result+"$func_validate_options_result"} + + # save modified positional parameters for caller + func_options_result=$func_run_hooks_result +} + + +# func_options_prep [ARG]... +# -------------------------- +# All initialisations required before starting the option parse loop. +# Note that when calling hook functions, we pass through the list of +# positional parameters. If a hook function modifies that list, and +# needs to propogate that back to rest of this script, then the complete +# modified list must be put in 'func_run_hooks_result' before +# returning. +func_hookable func_options_prep +func_options_prep () +{ + $debug_cmd + + # Option defaults: + opt_verbose=false + opt_warning_types= + + func_run_hooks func_options_prep ${1+"$@"} + + # save modified positional parameters for caller + func_options_prep_result=$func_run_hooks_result +} + + +# func_parse_options [ARG]... +# --------------------------- +# The main option parsing loop. +func_hookable func_parse_options +func_parse_options () +{ + $debug_cmd + + func_parse_options_result= + + # this just eases exit handling + while test $# -gt 0; do + # Defer to hook functions for initial option parsing, so they + # get priority in the event of reusing an option name. + func_run_hooks func_parse_options ${1+"$@"} + + # Adjust func_parse_options positional parameters to match + eval set dummy "$func_run_hooks_result"; shift + + # Break out of the loop if we already parsed every option. + test $# -gt 0 || break + + _G_opt=$1 + shift + case $_G_opt in + --debug|-x) debug_cmd='set -x' + func_echo "enabling shell trace mode" + $debug_cmd + ;; + + --no-warnings|--no-warning|--no-warn) + set dummy --warnings none ${1+"$@"} + shift + ;; + + --warnings|--warning|-W) + test $# = 0 && func_missing_arg $_G_opt && break + case " $warning_categories $1" in + *" $1 "*) + # trailing space prevents matching last $1 above + func_append_uniq opt_warning_types " $1" + ;; + *all) + opt_warning_types=$warning_categories + ;; + *none) + opt_warning_types=none + warning_func=: + ;; + *error) + opt_warning_types=$warning_categories + warning_func=func_fatal_error + ;; + *) + func_fatal_error \ + "unsupported warning category: '$1'" + ;; + esac + shift + ;; + + --verbose|-v) opt_verbose=: ;; + --version) func_version ;; + -\?|-h) func_usage ;; + --help) func_help ;; + + # Separate optargs to long options (plugins may need this): + --*=*) func_split_equals "$_G_opt" + set dummy "$func_split_equals_lhs" \ + "$func_split_equals_rhs" ${1+"$@"} + shift + ;; + + # Separate optargs to short options: + -W*) + func_split_short_opt "$_G_opt" + set dummy "$func_split_short_opt_name" \ + "$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + # Separate non-argument short options: + -\?*|-h*|-v*|-x*) + func_split_short_opt "$_G_opt" + set dummy "$func_split_short_opt_name" \ + "-$func_split_short_opt_arg" ${1+"$@"} + shift + ;; + + --) break ;; + -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + esac + done + + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + func_parse_options_result=$func_quote_for_eval_result +} + + +# func_validate_options [ARG]... +# ------------------------------ +# Perform any sanity checks on option settings and/or unconsumed +# arguments. +func_hookable func_validate_options +func_validate_options () +{ + $debug_cmd + + # Display all warnings if -W was not given. + test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" + + func_run_hooks func_validate_options ${1+"$@"} + + # Bail if the options were screwed! + $exit_cmd $EXIT_FAILURE + + # save modified positional parameters for caller + func_validate_options_result=$func_run_hooks_result +} + + + +## ----------------- ## +## Helper functions. ## +## ----------------- ## + +# This section contains the helper functions used by the rest of the +# hookable option parser framework in ascii-betical order. + + +# func_fatal_help ARG... +# ---------------------- +# Echo program name prefixed message to standard error, followed by +# a help hint, and exit. +func_fatal_help () +{ + $debug_cmd + + eval \$ECHO \""Usage: $usage"\" + eval \$ECHO \""$fatal_help"\" + func_error ${1+"$@"} + exit $EXIT_FAILURE +} + + +# func_help +# --------- +# Echo long help message to standard output and exit. +func_help () +{ + $debug_cmd + + func_usage_message + $ECHO "$long_help_message" + exit 0 +} + + +# func_missing_arg ARGNAME +# ------------------------ +# Echo program name prefixed message to standard error and set global +# exit_cmd. +func_missing_arg () +{ + $debug_cmd + + func_error "Missing argument for '$1'." + exit_cmd=exit +} + + +# func_split_equals STRING +# ------------------------ +# Set func_split_equals_lhs and func_split_equals_rhs shell variables after +# splitting STRING at the '=' sign. +test -z "$_G_HAVE_XSI_OPS" \ + && (eval 'x=a/b/c; + test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ + && _G_HAVE_XSI_OPS=yes + +if test yes = "$_G_HAVE_XSI_OPS" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_split_equals () + { + $debug_cmd + + func_split_equals_lhs=${1%%=*} + func_split_equals_rhs=${1#*=} + test "x$func_split_equals_lhs" = "x$1" \ + && func_split_equals_rhs= + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_split_equals () + { + $debug_cmd + + func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'` + func_split_equals_rhs= + test "x$func_split_equals_lhs" = "x$1" \ + || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'` + } +fi #func_split_equals + + +# func_split_short_opt SHORTOPT +# ----------------------------- +# Set func_split_short_opt_name and func_split_short_opt_arg shell +# variables after splitting SHORTOPT after the 2nd character. +if test yes = "$_G_HAVE_XSI_OPS" +then + # This is an XSI compatible shell, allowing a faster implementation... + eval 'func_split_short_opt () + { + $debug_cmd + + func_split_short_opt_arg=${1#??} + func_split_short_opt_name=${1%"$func_split_short_opt_arg"} + }' +else + # ...otherwise fall back to using expr, which is often a shell builtin. + func_split_short_opt () + { + $debug_cmd + + func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'` + func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'` + } +fi #func_split_short_opt + + +# func_usage +# ---------- +# Echo short help message to standard output and exit. +func_usage () +{ + $debug_cmd + + func_usage_message + $ECHO "Run '$progname --help |${PAGER-more}' for full usage" + exit 0 +} + + +# func_usage_message +# ------------------ +# Echo short help message to standard output. +func_usage_message () +{ + $debug_cmd + + eval \$ECHO \""Usage: $usage"\" + echo + $SED -n 's|^# || + /^Written by/{ + x;p;x + } + h + /^Written by/q' < "$progpath" + echo + eval \$ECHO \""$usage_message"\" +} + + +# func_version +# ------------ +# Echo version message to standard output and exit. +func_version () +{ + $debug_cmd + + printf '%s\n' "$progname $scriptversion" + $SED -n ' + /(C)/!b go + :more + /\./!{ + N + s|\n# | | + b more + } + :go + /^# Written by /,/# warranty; / { + s|^# || + s|^# *$|| + s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| + p + } + /^# Written by / { + s|^# || + p + } + /^warranty; /q' < "$progpath" + + exit $? +} + + +# Local variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-time-zone: "UTC" +# End: + +# Set a version string. +scriptversion='(GNU libtool) 2.4.6' + + +# func_echo ARG... +# ---------------- +# Libtool also displays the current mode in messages, so override +# funclib.sh func_echo with this custom definition. +func_echo () +{ + $debug_cmd + + _G_message=$* + + func_echo_IFS=$IFS + IFS=$nl + for _G_line in $_G_message; do + IFS=$func_echo_IFS + $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line" + done + IFS=$func_echo_IFS +} + + +# func_warning ARG... +# ------------------- +# Libtool warnings are not categorized, so override funclib.sh +# func_warning with this simpler definition. +func_warning () +{ + $debug_cmd + + $warning_func ${1+"$@"} +} + + +## ---------------- ## +## Options parsing. ## +## ---------------- ## + +# Hook in the functions to make sure our own options are parsed during +# the option parsing loop. + +usage='$progpath [OPTION]... [MODE-ARG]...' + +# Short help message in response to '-h'. +usage_message="Options: + --config show all configuration variables + --debug enable verbose shell tracing + -n, --dry-run display commands without modifying any files + --features display basic configuration information and exit + --mode=MODE use operation mode MODE + --no-warnings equivalent to '-Wnone' + --preserve-dup-deps don't remove duplicate dependency libraries + --quiet, --silent don't print informational messages + --tag=TAG use configuration variables from tag TAG + -v, --verbose print more informational messages than default + --version print version information + -W, --warnings=CATEGORY report the warnings falling in CATEGORY [all] + -h, --help, --help-all print short, long, or detailed help message +" + +# Additional text appended to 'usage_message' in response to '--help'. +func_help () +{ + $debug_cmd + + func_usage_message + $ECHO "$long_help_message + +MODE must be one of the following: + + clean remove files from the build directory + compile compile a source file into a libtool object + execute automatically set library path, then run a program + finish complete the installation of libtool libraries + install install libraries or executables + link create a library or an executable + uninstall remove libraries from an installed directory + +MODE-ARGS vary depending on the MODE. When passed as first option, +'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that. +Try '$progname --help --mode=MODE' for a more detailed description of MODE. + +When reporting a bug, please describe a test case to reproduce it and +include the following information: + + host-triplet: $host + shell: $SHELL + compiler: $LTCC + compiler flags: $LTCFLAGS + linker: $LD (gnu? $with_gnu_ld) + version: $progname (GNU libtool) 2.4.6 + automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` + autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` + +Report bugs to . +GNU libtool home page: . +General help using GNU software: ." + exit 0 +} + + +# func_lo2o OBJECT-NAME +# --------------------- +# Transform OBJECT-NAME from a '.lo' suffix to the platform specific +# object suffix. + +lo2o=s/\\.lo\$/.$objext/ +o2lo=s/\\.$objext\$/.lo/ + +if test yes = "$_G_HAVE_XSI_OPS"; then + eval 'func_lo2o () + { + case $1 in + *.lo) func_lo2o_result=${1%.lo}.$objext ;; + * ) func_lo2o_result=$1 ;; + esac + }' + + # func_xform LIBOBJ-OR-SOURCE + # --------------------------- + # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise) + # suffix to a '.lo' libtool-object suffix. + eval 'func_xform () + { + func_xform_result=${1%.*}.lo + }' +else + # ...otherwise fall back to using sed. + func_lo2o () + { + func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"` + } + + func_xform () + { + func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'` + } +fi + + +# func_fatal_configuration ARG... +# ------------------------------- +# Echo program name prefixed message to standard error, followed by +# a configuration failure hint, and exit. +func_fatal_configuration () +{ + func__fatal_error ${1+"$@"} \ + "See the $PACKAGE documentation for more information." \ + "Fatal configuration error." +} + + +# func_config +# ----------- +# Display the configuration for all the tags in this script. +func_config () +{ + re_begincf='^# ### BEGIN LIBTOOL' + re_endcf='^# ### END LIBTOOL' + + # Default configuration. + $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath" + + # Now print the configurations for the tags. + for tagname in $taglist; do + $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath" + done + + exit $? +} + + +# func_features +# ------------- +# Display the features supported by this script. +func_features () +{ + echo "host: $host" + if test yes = "$build_libtool_libs"; then + echo "enable shared libraries" + else + echo "disable shared libraries" + fi + if test yes = "$build_old_libs"; then + echo "enable static libraries" + else + echo "disable static libraries" + fi + + exit $? +} + + +# func_enable_tag TAGNAME +# ----------------------- +# Verify that TAGNAME is valid, and either flag an error and exit, or +# enable the TAGNAME tag. We also add TAGNAME to the global $taglist +# variable here. +func_enable_tag () +{ + # Global variable: + tagname=$1 + + re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$" + re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$" + sed_extractcf=/$re_begincf/,/$re_endcf/p + + # Validate tagname. + case $tagname in + *[!-_A-Za-z0-9,/]*) + func_fatal_error "invalid tag name: $tagname" + ;; + esac + + # Don't test for the "default" C tag, as we know it's + # there but not specially marked. + case $tagname in + CC) ;; + *) + if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then + taglist="$taglist $tagname" + + # Evaluate the configuration. Be careful to quote the path + # and the sed script, to avoid splitting on whitespace, but + # also don't use non-portable quotes within backquotes within + # quotes we have to do it in 2 steps: + extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` + eval "$extractedcf" + else + func_error "ignoring unknown tag $tagname" + fi + ;; + esac +} + + +# func_check_version_match +# ------------------------ +# Ensure that we are using m4 macros, and libtool script from the same +# release of libtool. +func_check_version_match () +{ + if test "$package_revision" != "$macro_revision"; then + if test "$VERSION" != "$macro_version"; then + if test -z "$macro_version"; then + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from an older release. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, but the +$progname: definition of this LT_INIT comes from $PACKAGE $macro_version. +$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION +$progname: and run autoconf again. +_LT_EOF + fi + else + cat >&2 <<_LT_EOF +$progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, +$progname: but the definition of this LT_INIT comes from revision $macro_revision. +$progname: You should recreate aclocal.m4 with macros from revision $package_revision +$progname: of $PACKAGE $VERSION and run autoconf again. +_LT_EOF + fi + + exit $EXIT_MISMATCH + fi +} + + +# libtool_options_prep [ARG]... +# ----------------------------- +# Preparation for options parsed by libtool. +libtool_options_prep () +{ + $debug_mode + + # Option defaults: + opt_config=false + opt_dlopen= + opt_dry_run=false + opt_help=false + opt_mode= + opt_preserve_dup_deps=false + opt_quiet=false + + nonopt= + preserve_args= + + # Shorthand for --mode=foo, only valid as the first argument + case $1 in + clean|clea|cle|cl) + shift; set dummy --mode clean ${1+"$@"}; shift + ;; + compile|compil|compi|comp|com|co|c) + shift; set dummy --mode compile ${1+"$@"}; shift + ;; + execute|execut|execu|exec|exe|ex|e) + shift; set dummy --mode execute ${1+"$@"}; shift + ;; + finish|finis|fini|fin|fi|f) + shift; set dummy --mode finish ${1+"$@"}; shift + ;; + install|instal|insta|inst|ins|in|i) + shift; set dummy --mode install ${1+"$@"}; shift + ;; + link|lin|li|l) + shift; set dummy --mode link ${1+"$@"}; shift + ;; + uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) + shift; set dummy --mode uninstall ${1+"$@"}; shift + ;; + esac + + # Pass back the list of options. + func_quote_for_eval ${1+"$@"} + libtool_options_prep_result=$func_quote_for_eval_result +} +func_add_hook func_options_prep libtool_options_prep + + +# libtool_parse_options [ARG]... +# --------------------------------- +# Provide handling for libtool specific options. +libtool_parse_options () +{ + $debug_cmd + + # Perform our own loop to consume as many options as possible in + # each iteration. + while test $# -gt 0; do + _G_opt=$1 + shift + case $_G_opt in + --dry-run|--dryrun|-n) + opt_dry_run=: + ;; + + --config) func_config ;; + + --dlopen|-dlopen) + opt_dlopen="${opt_dlopen+$opt_dlopen +}$1" + shift + ;; + + --preserve-dup-deps) + opt_preserve_dup_deps=: ;; + + --features) func_features ;; + + --finish) set dummy --mode finish ${1+"$@"}; shift ;; + + --help) opt_help=: ;; + + --help-all) opt_help=': help-all' ;; + + --mode) test $# = 0 && func_missing_arg $_G_opt && break + opt_mode=$1 + case $1 in + # Valid mode arguments: + clean|compile|execute|finish|install|link|relink|uninstall) ;; + + # Catch anything else as an error + *) func_error "invalid argument for $_G_opt" + exit_cmd=exit + break + ;; + esac + shift + ;; + + --no-silent|--no-quiet) + opt_quiet=false + func_append preserve_args " $_G_opt" + ;; + + --no-warnings|--no-warning|--no-warn) + opt_warning=false + func_append preserve_args " $_G_opt" + ;; + + --no-verbose) + opt_verbose=false + func_append preserve_args " $_G_opt" + ;; + + --silent|--quiet) + opt_quiet=: + opt_verbose=false + func_append preserve_args " $_G_opt" + ;; + + --tag) test $# = 0 && func_missing_arg $_G_opt && break + opt_tag=$1 + func_append preserve_args " $_G_opt $1" + func_enable_tag "$1" + shift + ;; + + --verbose|-v) opt_quiet=false + opt_verbose=: + func_append preserve_args " $_G_opt" + ;; + + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + esac + done + + + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + libtool_parse_options_result=$func_quote_for_eval_result +} +func_add_hook func_parse_options libtool_parse_options + + + +# libtool_validate_options [ARG]... +# --------------------------------- +# Perform any sanity checks on option settings and/or unconsumed +# arguments. +libtool_validate_options () +{ + # save first non-option argument + if test 0 -lt $#; then + nonopt=$1 + shift + fi + + # preserve --debug + test : = "$debug_cmd" || func_append preserve_args " --debug" + + case $host in + # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452 + # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788 + *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*) + # don't eliminate duplications in $postdeps and $predeps + opt_duplicate_compiler_generated_deps=: + ;; + *) + opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps + ;; + esac + + $opt_help || { + # Sanity checks first: + func_check_version_match + + test yes != "$build_libtool_libs" \ + && test yes != "$build_old_libs" \ + && func_fatal_configuration "not configured to build any kind of library" + + # Darwin sucks + eval std_shrext=\"$shrext_cmds\" + + # Only execute mode is allowed to have -dlopen flags. + if test -n "$opt_dlopen" && test execute != "$opt_mode"; then + func_error "unrecognized option '-dlopen'" + $ECHO "$help" 1>&2 + exit $EXIT_FAILURE + fi + + # Change the help message to a mode-specific one. + generic_help=$help + help="Try '$progname --help --mode=$opt_mode' for more information." + } + + # Pass back the unparsed argument list + func_quote_for_eval ${1+"$@"} + libtool_validate_options_result=$func_quote_for_eval_result +} +func_add_hook func_validate_options libtool_validate_options + + +# Process options as early as possible so that --help and --version +# can return quickly. +func_options ${1+"$@"} +eval set dummy "$func_options_result"; shift + + + +## ----------- ## +## Main. ## +## ----------- ## + +magic='%%%MAGIC variable%%%' +magic_exe='%%%MAGIC EXE variable%%%' + +# Global variables. +extracted_archives= +extracted_serial=0 + +# If this variable is set in any of the actions, the command in it +# will be execed at the end. This prevents here-documents from being +# left over by shells. +exec_cmd= + + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + +# func_generated_by_libtool +# True iff stdin has been generated by Libtool. This function is only +# a basic sanity check; it will hardly flush out determined imposters. +func_generated_by_libtool_p () +{ + $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 +} + +# func_lalib_p file +# True iff FILE is a libtool '.la' library or '.lo' object file. +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_lalib_p () +{ + test -f "$1" && + $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p +} + +# func_lalib_unsafe_p file +# True iff FILE is a libtool '.la' library or '.lo' object file. +# This function implements the same check as func_lalib_p without +# resorting to external programs. To this end, it redirects stdin and +# closes it afterwards, without saving the original file descriptor. +# As a safety measure, use it only where a negative result would be +# fatal anyway. Works if 'file' does not exist. +func_lalib_unsafe_p () +{ + lalib_p=no + if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then + for lalib_p_l in 1 2 3 4 + do + read lalib_p_line + case $lalib_p_line in + \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; + esac + done + exec 0<&5 5<&- + fi + test yes = "$lalib_p" +} + +# func_ltwrapper_script_p file +# True iff FILE is a libtool wrapper script +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_script_p () +{ + test -f "$1" && + $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p +} + +# func_ltwrapper_executable_p file +# True iff FILE is a libtool wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_executable_p () +{ + func_ltwrapper_exec_suffix= + case $1 in + *.exe) ;; + *) func_ltwrapper_exec_suffix=.exe ;; + esac + $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 +} + +# func_ltwrapper_scriptname file +# Assumes file is an ltwrapper_executable +# uses $file to determine the appropriate filename for a +# temporary ltwrapper_script. +func_ltwrapper_scriptname () +{ + func_dirname_and_basename "$1" "" "." + func_stripname '' '.exe' "$func_basename_result" + func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper +} + +# func_ltwrapper_p file +# True iff FILE is a libtool wrapper script or wrapper executable +# This function is only a basic sanity check; it will hardly flush out +# determined imposters. +func_ltwrapper_p () +{ + func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" +} + + +# func_execute_cmds commands fail_cmd +# Execute tilde-delimited COMMANDS. +# If FAIL_CMD is given, eval that upon failure. +# FAIL_CMD may read-access the current command in variable CMD! +func_execute_cmds () +{ + $debug_cmd + + save_ifs=$IFS; IFS='~' + for cmd in $1; do + IFS=$sp$nl + eval cmd=\"$cmd\" + IFS=$save_ifs + func_show_eval "$cmd" "${2-:}" + done + IFS=$save_ifs +} + + +# func_source file +# Source FILE, adding directory component if necessary. +# Note that it is not necessary on cygwin/mingw to append a dot to +# FILE even if both FILE and FILE.exe exist: automatic-append-.exe +# behavior happens only for exec(3), not for open(2)! Also, sourcing +# 'FILE.' does not work on cygwin managed mounts. +func_source () +{ + $debug_cmd + + case $1 in + */* | *\\*) . "$1" ;; + *) . "./$1" ;; + esac +} + + +# func_resolve_sysroot PATH +# Replace a leading = in PATH with a sysroot. Store the result into +# func_resolve_sysroot_result +func_resolve_sysroot () +{ + func_resolve_sysroot_result=$1 + case $func_resolve_sysroot_result in + =*) + func_stripname '=' '' "$func_resolve_sysroot_result" + func_resolve_sysroot_result=$lt_sysroot$func_stripname_result + ;; + esac +} + +# func_replace_sysroot PATH +# If PATH begins with the sysroot, replace it with = and +# store the result into func_replace_sysroot_result. +func_replace_sysroot () +{ + case $lt_sysroot:$1 in + ?*:"$lt_sysroot"*) + func_stripname "$lt_sysroot" '' "$1" + func_replace_sysroot_result='='$func_stripname_result + ;; + *) + # Including no sysroot. + func_replace_sysroot_result=$1 + ;; + esac +} + +# func_infer_tag arg +# Infer tagged configuration to use if any are available and +# if one wasn't chosen via the "--tag" command line option. +# Only attempt this if the compiler in the base compile +# command doesn't match the default compiler. +# arg is usually of the form 'gcc ...' +func_infer_tag () +{ + $debug_cmd + + if test -n "$available_tags" && test -z "$tagname"; then + CC_quoted= + for arg in $CC; do + func_append_quoted CC_quoted "$arg" + done + CC_expanded=`func_echo_all $CC` + CC_quoted_expanded=`func_echo_all $CC_quoted` + case $@ in + # Blanks in the command may have been stripped by the calling shell, + # but not from the CC environment variable when configure was run. + " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ + " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;; + # Blanks at the start of $base_compile will cause this to fail + # if we don't check for them as well. + *) + for z in $available_tags; do + if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then + # Evaluate the configuration. + eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" + CC_quoted= + for arg in $CC; do + # Double-quote args containing other shell metacharacters. + func_append_quoted CC_quoted "$arg" + done + CC_expanded=`func_echo_all $CC` + CC_quoted_expanded=`func_echo_all $CC_quoted` + case "$@ " in + " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ + " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) + # The compiler in the base compile command matches + # the one in the tagged configuration. + # Assume this is the tagged configuration we want. + tagname=$z + break + ;; + esac + fi + done + # If $tagname still isn't set, then no tagged configuration + # was found and let the user know that the "--tag" command + # line option must be used. + if test -z "$tagname"; then + func_echo "unable to infer tagged configuration" + func_fatal_error "specify a tag with '--tag'" +# else +# func_verbose "using $tagname tagged configuration" + fi + ;; + esac + fi +} + + + +# func_write_libtool_object output_name pic_name nonpic_name +# Create a libtool object file (analogous to a ".la" file), +# but don't create it if we're doing a dry run. +func_write_libtool_object () +{ + write_libobj=$1 + if test yes = "$build_libtool_libs"; then + write_lobj=\'$2\' + else + write_lobj=none + fi + + if test yes = "$build_old_libs"; then + write_oldobj=\'$3\' + else + write_oldobj=none + fi + + $opt_dry_run || { + cat >${write_libobj}T </dev/null` + if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then + func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" | + $SED -e "$sed_naive_backslashify"` + else + func_convert_core_file_wine_to_w32_result= + fi + fi +} +# end: func_convert_core_file_wine_to_w32 + + +# func_convert_core_path_wine_to_w32 ARG +# Helper function used by path conversion functions when $build is *nix, and +# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly +# configured wine environment available, with the winepath program in $build's +# $PATH. Assumes ARG has no leading or trailing path separator characters. +# +# ARG is path to be converted from $build format to win32. +# Result is available in $func_convert_core_path_wine_to_w32_result. +# Unconvertible file (directory) names in ARG are skipped; if no directory names +# are convertible, then the result may be empty. +func_convert_core_path_wine_to_w32 () +{ + $debug_cmd + + # unfortunately, winepath doesn't convert paths, only file names + func_convert_core_path_wine_to_w32_result= + if test -n "$1"; then + oldIFS=$IFS + IFS=: + for func_convert_core_path_wine_to_w32_f in $1; do + IFS=$oldIFS + func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f" + if test -n "$func_convert_core_file_wine_to_w32_result"; then + if test -z "$func_convert_core_path_wine_to_w32_result"; then + func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result + else + func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result" + fi + fi + done + IFS=$oldIFS + fi +} +# end: func_convert_core_path_wine_to_w32 + + +# func_cygpath ARGS... +# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when +# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2) +# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or +# (2), returns the Cygwin file name or path in func_cygpath_result (input +# file name or path is assumed to be in w32 format, as previously converted +# from $build's *nix or MSYS format). In case (3), returns the w32 file name +# or path in func_cygpath_result (input file name or path is assumed to be in +# Cygwin format). Returns an empty string on error. +# +# ARGS are passed to cygpath, with the last one being the file name or path to +# be converted. +# +# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH +# environment variable; do not put it in $PATH. +func_cygpath () +{ + $debug_cmd + + if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then + func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null` + if test "$?" -ne 0; then + # on failure, ensure result is empty + func_cygpath_result= + fi + else + func_cygpath_result= + func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'" + fi +} +#end: func_cygpath + + +# func_convert_core_msys_to_w32 ARG +# Convert file name or path ARG from MSYS format to w32 format. Return +# result in func_convert_core_msys_to_w32_result. +func_convert_core_msys_to_w32 () +{ + $debug_cmd + + # awkward: cmd appends spaces to result + func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null | + $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"` +} +#end: func_convert_core_msys_to_w32 + + +# func_convert_file_check ARG1 ARG2 +# Verify that ARG1 (a file name in $build format) was converted to $host +# format in ARG2. Otherwise, emit an error message, but continue (resetting +# func_to_host_file_result to ARG1). +func_convert_file_check () +{ + $debug_cmd + + if test -z "$2" && test -n "$1"; then + func_error "Could not determine host file name corresponding to" + func_error " '$1'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback: + func_to_host_file_result=$1 + fi +} +# end func_convert_file_check + + +# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH +# Verify that FROM_PATH (a path in $build format) was converted to $host +# format in TO_PATH. Otherwise, emit an error message, but continue, resetting +# func_to_host_file_result to a simplistic fallback value (see below). +func_convert_path_check () +{ + $debug_cmd + + if test -z "$4" && test -n "$3"; then + func_error "Could not determine the host path corresponding to" + func_error " '$3'" + func_error "Continuing, but uninstalled executables may not work." + # Fallback. This is a deliberately simplistic "conversion" and + # should not be "improved". See libtool.info. + if test "x$1" != "x$2"; then + lt_replace_pathsep_chars="s|$1|$2|g" + func_to_host_path_result=`echo "$3" | + $SED -e "$lt_replace_pathsep_chars"` + else + func_to_host_path_result=$3 + fi + fi +} +# end func_convert_path_check + + +# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG +# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT +# and appending REPL if ORIG matches BACKPAT. +func_convert_path_front_back_pathsep () +{ + $debug_cmd + + case $4 in + $1 ) func_to_host_path_result=$3$func_to_host_path_result + ;; + esac + case $4 in + $2 ) func_append func_to_host_path_result "$3" + ;; + esac +} +# end func_convert_path_front_back_pathsep + + +################################################## +# $build to $host FILE NAME CONVERSION FUNCTIONS # +################################################## +# invoked via '$to_host_file_cmd ARG' +# +# In each case, ARG is the path to be converted from $build to $host format. +# Result will be available in $func_to_host_file_result. + + +# func_to_host_file ARG +# Converts the file name ARG from $build format to $host format. Return result +# in func_to_host_file_result. +func_to_host_file () +{ + $debug_cmd + + $to_host_file_cmd "$1" +} +# end func_to_host_file + + +# func_to_tool_file ARG LAZY +# converts the file name ARG from $build format to toolchain format. Return +# result in func_to_tool_file_result. If the conversion in use is listed +# in (the comma separated) LAZY, no conversion takes place. +func_to_tool_file () +{ + $debug_cmd + + case ,$2, in + *,"$to_tool_file_cmd",*) + func_to_tool_file_result=$1 + ;; + *) + $to_tool_file_cmd "$1" + func_to_tool_file_result=$func_to_host_file_result + ;; + esac +} +# end func_to_tool_file + + +# func_convert_file_noop ARG +# Copy ARG to func_to_host_file_result. +func_convert_file_noop () +{ + func_to_host_file_result=$1 +} +# end func_convert_file_noop + + +# func_convert_file_msys_to_w32 ARG +# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic +# conversion to w32 is not available inside the cwrapper. Returns result in +# func_to_host_file_result. +func_convert_file_msys_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_msys_to_w32 "$1" + func_to_host_file_result=$func_convert_core_msys_to_w32_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_msys_to_w32 + + +# func_convert_file_cygwin_to_w32 ARG +# Convert file name ARG from Cygwin to w32 format. Returns result in +# func_to_host_file_result. +func_convert_file_cygwin_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + # because $build is cygwin, we call "the" cygpath in $PATH; no need to use + # LT_CYGPATH in this case. + func_to_host_file_result=`cygpath -m "$1"` + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_cygwin_to_w32 + + +# func_convert_file_nix_to_w32 ARG +# Convert file name ARG from *nix to w32 format. Requires a wine environment +# and a working winepath. Returns result in func_to_host_file_result. +func_convert_file_nix_to_w32 () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_file_wine_to_w32 "$1" + func_to_host_file_result=$func_convert_core_file_wine_to_w32_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_nix_to_w32 + + +# func_convert_file_msys_to_cygwin ARG +# Convert file name ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. +# Returns result in func_to_host_file_result. +func_convert_file_msys_to_cygwin () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + func_convert_core_msys_to_w32 "$1" + func_cygpath -u "$func_convert_core_msys_to_w32_result" + func_to_host_file_result=$func_cygpath_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_msys_to_cygwin + + +# func_convert_file_nix_to_cygwin ARG +# Convert file name ARG from *nix to Cygwin format. Requires Cygwin installed +# in a wine environment, working winepath, and LT_CYGPATH set. Returns result +# in func_to_host_file_result. +func_convert_file_nix_to_cygwin () +{ + $debug_cmd + + func_to_host_file_result=$1 + if test -n "$1"; then + # convert from *nix to w32, then use cygpath to convert from w32 to cygwin. + func_convert_core_file_wine_to_w32 "$1" + func_cygpath -u "$func_convert_core_file_wine_to_w32_result" + func_to_host_file_result=$func_cygpath_result + fi + func_convert_file_check "$1" "$func_to_host_file_result" +} +# end func_convert_file_nix_to_cygwin + + +############################################# +# $build to $host PATH CONVERSION FUNCTIONS # +############################################# +# invoked via '$to_host_path_cmd ARG' +# +# In each case, ARG is the path to be converted from $build to $host format. +# The result will be available in $func_to_host_path_result. +# +# Path separators are also converted from $build format to $host format. If +# ARG begins or ends with a path separator character, it is preserved (but +# converted to $host format) on output. +# +# All path conversion functions are named using the following convention: +# file name conversion function : func_convert_file_X_to_Y () +# path conversion function : func_convert_path_X_to_Y () +# where, for any given $build/$host combination the 'X_to_Y' value is the +# same. If conversion functions are added for new $build/$host combinations, +# the two new functions must follow this pattern, or func_init_to_host_path_cmd +# will break. + + +# func_init_to_host_path_cmd +# Ensures that function "pointer" variable $to_host_path_cmd is set to the +# appropriate value, based on the value of $to_host_file_cmd. +to_host_path_cmd= +func_init_to_host_path_cmd () +{ + $debug_cmd + + if test -z "$to_host_path_cmd"; then + func_stripname 'func_convert_file_' '' "$to_host_file_cmd" + to_host_path_cmd=func_convert_path_$func_stripname_result + fi +} + + +# func_to_host_path ARG +# Converts the path ARG from $build format to $host format. Return result +# in func_to_host_path_result. +func_to_host_path () +{ + $debug_cmd + + func_init_to_host_path_cmd + $to_host_path_cmd "$1" +} +# end func_to_host_path + + +# func_convert_path_noop ARG +# Copy ARG to func_to_host_path_result. +func_convert_path_noop () +{ + func_to_host_path_result=$1 +} +# end func_convert_path_noop + + +# func_convert_path_msys_to_w32 ARG +# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic +# conversion to w32 is not available inside the cwrapper. Returns result in +# func_to_host_path_result. +func_convert_path_msys_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # Remove leading and trailing path separator characters from ARG. MSYS + # behavior is inconsistent here; cygpath turns them into '.;' and ';.'; + # and winepath ignores them completely. + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" + func_to_host_path_result=$func_convert_core_msys_to_w32_result + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_msys_to_w32 + + +# func_convert_path_cygwin_to_w32 ARG +# Convert path ARG from Cygwin to w32 format. Returns result in +# func_to_host_file_result. +func_convert_path_cygwin_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"` + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_cygwin_to_w32 + + +# func_convert_path_nix_to_w32 ARG +# Convert path ARG from *nix to w32 format. Requires a wine environment and +# a working winepath. Returns result in func_to_host_file_result. +func_convert_path_nix_to_w32 () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" + func_to_host_path_result=$func_convert_core_path_wine_to_w32_result + func_convert_path_check : ";" \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" + fi +} +# end func_convert_path_nix_to_w32 + + +# func_convert_path_msys_to_cygwin ARG +# Convert path ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. +# Returns result in func_to_host_file_result. +func_convert_path_msys_to_cygwin () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # See func_convert_path_msys_to_w32: + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" + func_cygpath -u -p "$func_convert_core_msys_to_w32_result" + func_to_host_path_result=$func_cygpath_result + func_convert_path_check : : \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" : "$1" + fi +} +# end func_convert_path_msys_to_cygwin + + +# func_convert_path_nix_to_cygwin ARG +# Convert path ARG from *nix to Cygwin format. Requires Cygwin installed in a +# a wine environment, working winepath, and LT_CYGPATH set. Returns result in +# func_to_host_file_result. +func_convert_path_nix_to_cygwin () +{ + $debug_cmd + + func_to_host_path_result=$1 + if test -n "$1"; then + # Remove leading and trailing path separator characters from + # ARG. msys behavior is inconsistent here, cygpath turns them + # into '.;' and ';.', and winepath ignores them completely. + func_stripname : : "$1" + func_to_host_path_tmp1=$func_stripname_result + func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" + func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result" + func_to_host_path_result=$func_cygpath_result + func_convert_path_check : : \ + "$func_to_host_path_tmp1" "$func_to_host_path_result" + func_convert_path_front_back_pathsep ":*" "*:" : "$1" + fi +} +# end func_convert_path_nix_to_cygwin + + +# func_dll_def_p FILE +# True iff FILE is a Windows DLL '.def' file. +# Keep in sync with _LT_DLL_DEF_P in libtool.m4 +func_dll_def_p () +{ + $debug_cmd + + func_dll_def_p_tmp=`$SED -n \ + -e 's/^[ ]*//' \ + -e '/^\(;.*\)*$/d' \ + -e 's/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p' \ + -e q \ + "$1"` + test DEF = "$func_dll_def_p_tmp" +} + + +# func_mode_compile arg... +func_mode_compile () +{ + $debug_cmd + + # Get the compilation command and the source file. + base_compile= + srcfile=$nonopt # always keep a non-empty value in "srcfile" + suppress_opt=yes + suppress_output= + arg_mode=normal + libobj= + later= + pie_flag= + + for arg + do + case $arg_mode in + arg ) + # do not "continue". Instead, add this to base_compile + lastarg=$arg + arg_mode=normal + ;; + + target ) + libobj=$arg + arg_mode=normal + continue + ;; + + normal ) + # Accept any command-line options. + case $arg in + -o) + test -n "$libobj" && \ + func_fatal_error "you cannot specify '-o' more than once" + arg_mode=target + continue + ;; + + -pie | -fpie | -fPIE) + func_append pie_flag " $arg" + continue + ;; + + -shared | -static | -prefer-pic | -prefer-non-pic) + func_append later " $arg" + continue + ;; + + -no-suppress) + suppress_opt=no + continue + ;; + + -Xcompiler) + arg_mode=arg # the next one goes into the "base_compile" arg list + continue # The current "srcfile" will either be retained or + ;; # replaced later. I would guess that would be a bug. + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + lastarg= + save_ifs=$IFS; IFS=, + for arg in $args; do + IFS=$save_ifs + func_append_quoted lastarg "$arg" + done + IFS=$save_ifs + func_stripname ' ' '' "$lastarg" + lastarg=$func_stripname_result + + # Add the arguments to base_compile. + func_append base_compile " $lastarg" + continue + ;; + + *) + # Accept the current argument as the source file. + # The previous "srcfile" becomes the current argument. + # + lastarg=$srcfile + srcfile=$arg + ;; + esac # case $arg + ;; + esac # case $arg_mode + + # Aesthetically quote the previous argument. + func_append_quoted base_compile "$lastarg" + done # for arg + + case $arg_mode in + arg) + func_fatal_error "you must specify an argument for -Xcompile" + ;; + target) + func_fatal_error "you must specify a target with '-o'" + ;; + *) + # Get the name of the library object. + test -z "$libobj" && { + func_basename "$srcfile" + libobj=$func_basename_result + } + ;; + esac + + # Recognize several different file suffixes. + # If the user specifies -o file.o, it is replaced with file.lo + case $libobj in + *.[cCFSifmso] | \ + *.ada | *.adb | *.ads | *.asm | \ + *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \ + *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup) + func_xform "$libobj" + libobj=$func_xform_result + ;; + esac + + case $libobj in + *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;; + *) + func_fatal_error "cannot determine name of library object from '$libobj'" + ;; + esac + + func_infer_tag $base_compile + + for arg in $later; do + case $arg in + -shared) + test yes = "$build_libtool_libs" \ + || func_fatal_configuration "cannot build a shared library" + build_old_libs=no + continue + ;; + + -static) + build_libtool_libs=no + build_old_libs=yes + continue + ;; + + -prefer-pic) + pic_mode=yes + continue + ;; + + -prefer-non-pic) + pic_mode=no + continue + ;; + esac + done + + func_quote_for_eval "$libobj" + test "X$libobj" != "X$func_quote_for_eval_result" \ + && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ + && func_warning "libobj name '$libobj' may not contain shell special characters." + func_dirname_and_basename "$obj" "/" "" + objname=$func_basename_result + xdir=$func_dirname_result + lobj=$xdir$objdir/$objname + + test -z "$base_compile" && \ + func_fatal_help "you must specify a compilation command" + + # Delete any leftover library objects. + if test yes = "$build_old_libs"; then + removelist="$obj $lobj $libobj ${libobj}T" + else + removelist="$lobj $libobj ${libobj}T" + fi + + # On Cygwin there's no "real" PIC flag so we must build both object types + case $host_os in + cygwin* | mingw* | pw32* | os2* | cegcc*) + pic_mode=default + ;; + esac + if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then + # non-PIC code in shared libraries is not supported + pic_mode=default + fi + + # Calculate the filename of the output object if compiler does + # not support -o with -c + if test no = "$compiler_c_o"; then + output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext + lockfile=$output_obj.lock + else + output_obj= + need_locks=no + lockfile= + fi + + # Lock this critical section if it is needed + # We use this script file to make the link, it avoids creating a new file + if test yes = "$need_locks"; then + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + elif test warn = "$need_locks"; then + if test -f "$lockfile"; then + $ECHO "\ +*** ERROR, $lockfile exists and contains: +`cat $lockfile 2>/dev/null` + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + func_append removelist " $output_obj" + $ECHO "$srcfile" > "$lockfile" + fi + + $opt_dry_run || $RM $removelist + func_append removelist " $lockfile" + trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 + + func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 + srcfile=$func_to_tool_file_result + func_quote_for_eval "$srcfile" + qsrcfile=$func_quote_for_eval_result + + # Only build a PIC object if we are building libtool libraries. + if test yes = "$build_libtool_libs"; then + # Without this assignment, base_compile gets emptied. + fbsd_hideous_sh_bug=$base_compile + + if test no != "$pic_mode"; then + command="$base_compile $qsrcfile $pic_flag" + else + # Don't build PIC code + command="$base_compile $qsrcfile" + fi + + func_mkdir_p "$xdir$objdir" + + if test -z "$output_obj"; then + # Place PIC objects in $objdir + func_append command " -o $lobj" + fi + + func_show_eval_locale "$command" \ + 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' + + if test warn = "$need_locks" && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed, then go on to compile the next one + if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then + func_show_eval '$MV "$output_obj" "$lobj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + + # Allow error messages only from the first compilation. + if test yes = "$suppress_opt"; then + suppress_output=' >/dev/null 2>&1' + fi + fi + + # Only build a position-dependent object if we build old libraries. + if test yes = "$build_old_libs"; then + if test yes != "$pic_mode"; then + # Don't build PIC code + command="$base_compile $qsrcfile$pie_flag" + else + command="$base_compile $qsrcfile $pic_flag" + fi + if test yes = "$compiler_c_o"; then + func_append command " -o $obj" + fi + + # Suppress compiler output if we already did a PIC compilation. + func_append command "$suppress_output" + func_show_eval_locale "$command" \ + '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' + + if test warn = "$need_locks" && + test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then + $ECHO "\ +*** ERROR, $lockfile contains: +`cat $lockfile 2>/dev/null` + +but it should contain: +$srcfile + +This indicates that another process is trying to use the same +temporary object file, and libtool could not work around it because +your compiler does not support '-c' and '-o' together. If you +repeat this compilation, it may succeed, by chance, but you had better +avoid parallel builds (make -j) in this platform, or get a better +compiler." + + $opt_dry_run || $RM $removelist + exit $EXIT_FAILURE + fi + + # Just move the object if needed + if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then + func_show_eval '$MV "$output_obj" "$obj"' \ + 'error=$?; $opt_dry_run || $RM $removelist; exit $error' + fi + fi + + $opt_dry_run || { + func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" + + # Unlock the critical section if it was locked + if test no != "$need_locks"; then + removelist=$lockfile + $RM "$lockfile" + fi + } + + exit $EXIT_SUCCESS +} + +$opt_help || { + test compile = "$opt_mode" && func_mode_compile ${1+"$@"} +} + +func_mode_help () +{ + # We need to display help for each of the modes. + case $opt_mode in + "") + # Generic help is extracted from the usage comments + # at the start of this file. + func_help + ;; + + clean) + $ECHO \ +"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... + +Remove files from the build directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed +to RM. + +If FILE is a libtool library, object or program, all the files associated +with it are deleted. Otherwise, only FILE itself is deleted using RM." + ;; + + compile) + $ECHO \ +"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE + +Compile a source file into a libtool library object. + +This mode accepts the following additional options: + + -o OUTPUT-FILE set the output file name to OUTPUT-FILE + -no-suppress do not suppress compiler output for multiple passes + -prefer-pic try to build PIC objects only + -prefer-non-pic try to build non-PIC objects only + -shared do not build a '.o' file suitable for static linking + -static only build a '.o' file suitable for static linking + -Wc,FLAG pass FLAG directly to the compiler + +COMPILE-COMMAND is a command to be used in creating a 'standard' object file +from the given SOURCEFILE. + +The output file name is determined by removing the directory component from +SOURCEFILE, then substituting the C source code suffix '.c' with the +library object suffix, '.lo'." + ;; + + execute) + $ECHO \ +"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... + +Automatically set library path, then run a program. + +This mode accepts the following additional options: + + -dlopen FILE add the directory containing FILE to the library path + +This mode sets the library path environment variable according to '-dlopen' +flags. + +If any of the ARGS are libtool executable wrappers, then they are translated +into their corresponding uninstalled binary, and any of their required library +directories are added to the library path. + +Then, COMMAND is executed, with ARGS as arguments." + ;; + + finish) + $ECHO \ +"Usage: $progname [OPTION]... --mode=finish [LIBDIR]... + +Complete the installation of libtool libraries. + +Each LIBDIR is a directory that contains libtool libraries. + +The commands that this mode executes may require superuser privileges. Use +the '--dry-run' option if you just want to see what would be executed." + ;; + + install) + $ECHO \ +"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... + +Install executables or libraries. + +INSTALL-COMMAND is the installation command. The first component should be +either the 'install' or 'cp' program. + +The following components of INSTALL-COMMAND are treated specially: + + -inst-prefix-dir PREFIX-DIR Use PREFIX-DIR as a staging area for installation + +The rest of the components are interpreted as arguments to that command (only +BSD-compatible install options are recognized)." + ;; + + link) + $ECHO \ +"Usage: $progname [OPTION]... --mode=link LINK-COMMAND... + +Link object files or libraries together to form another library, or to +create an executable program. + +LINK-COMMAND is a command using the C compiler that you would use to create +a program from several object files. + +The following components of LINK-COMMAND are treated specially: + + -all-static do not do any dynamic linking at all + -avoid-version do not add a version suffix if possible + -bindir BINDIR specify path to binaries directory (for systems where + libraries must be found in the PATH setting at runtime) + -dlopen FILE '-dlpreopen' FILE if it cannot be dlopened at runtime + -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols + -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) + -export-symbols SYMFILE + try to export only the symbols listed in SYMFILE + -export-symbols-regex REGEX + try to export only the symbols matching REGEX + -LLIBDIR search LIBDIR for required installed libraries + -lNAME OUTPUT-FILE requires the installed library libNAME + -module build a library that can dlopened + -no-fast-install disable the fast-install mode + -no-install link a not-installable executable + -no-undefined declare that a library does not refer to external symbols + -o OUTPUT-FILE create OUTPUT-FILE from the specified objects + -objectlist FILE use a list of object files found in FILE to specify objects + -os2dllname NAME force a short DLL name on OS/2 (no effect on other OSes) + -precious-files-regex REGEX + don't remove output files matching REGEX + -release RELEASE specify package release information + -rpath LIBDIR the created library will eventually be installed in LIBDIR + -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries + -shared only do dynamic linking of libtool libraries + -shrext SUFFIX override the standard shared library file extension + -static do not do any dynamic linking of uninstalled libtool libraries + -static-libtool-libs + do not do any dynamic linking of libtool libraries + -version-info CURRENT[:REVISION[:AGE]] + specify library version info [each variable defaults to 0] + -weak LIBNAME declare that the target provides the LIBNAME interface + -Wc,FLAG + -Xcompiler FLAG pass linker-specific FLAG directly to the compiler + -Wl,FLAG + -Xlinker FLAG pass linker-specific FLAG directly to the linker + -XCClinker FLAG pass link-specific FLAG to the compiler driver (CC) + +All other options (arguments beginning with '-') are ignored. + +Every other argument is treated as a filename. Files ending in '.la' are +treated as uninstalled libtool libraries, other files are standard or library +object files. + +If the OUTPUT-FILE ends in '.la', then a libtool library is created, +only library objects ('.lo' files) may be specified, and '-rpath' is +required, except when creating a convenience library. + +If OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created +using 'ar' and 'ranlib', or on Windows using 'lib'. + +If OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file +is created, otherwise an executable program is created." + ;; + + uninstall) + $ECHO \ +"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... + +Remove libraries from an installation directory. + +RM is the name of the program to use to delete files associated with each FILE +(typically '/bin/rm'). RM-OPTIONS are options (such as '-f') to be passed +to RM. + +If FILE is a libtool library, all the files associated with it are deleted. +Otherwise, only FILE itself is deleted using RM." + ;; + + *) + func_fatal_help "invalid operation mode '$opt_mode'" + ;; + esac + + echo + $ECHO "Try '$progname --help' for more information about other modes." +} + +# Now that we've collected a possible --mode arg, show help if necessary +if $opt_help; then + if test : = "$opt_help"; then + func_mode_help + else + { + func_help noexit + for opt_mode in compile link execute install finish uninstall clean; do + func_mode_help + done + } | $SED -n '1p; 2,$s/^Usage:/ or: /p' + { + func_help noexit + for opt_mode in compile link execute install finish uninstall clean; do + echo + func_mode_help + done + } | + $SED '1d + /^When reporting/,/^Report/{ + H + d + } + $x + /information about other modes/d + /more detailed .*MODE/d + s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/' + fi + exit $? +fi + + +# func_mode_execute arg... +func_mode_execute () +{ + $debug_cmd + + # The first argument is the command name. + cmd=$nonopt + test -z "$cmd" && \ + func_fatal_help "you must specify a COMMAND" + + # Handle -dlopen flags immediately. + for file in $opt_dlopen; do + test -f "$file" \ + || func_fatal_help "'$file' is not a file" + + dir= + case $file in + *.la) + func_resolve_sysroot "$file" + file=$func_resolve_sysroot_result + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "'$lib' is not a valid libtool archive" + + # Read the libtool library. + dlname= + library_names= + func_source "$file" + + # Skip this library if it cannot be dlopened. + if test -z "$dlname"; then + # Warn if it was a shared library. + test -n "$library_names" && \ + func_warning "'$file' was not linked with '-export-dynamic'" + continue + fi + + func_dirname "$file" "" "." + dir=$func_dirname_result + + if test -f "$dir/$objdir/$dlname"; then + func_append dir "/$objdir" + else + if test ! -f "$dir/$dlname"; then + func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'" + fi + fi + ;; + + *.lo) + # Just add the directory containing the .lo file. + func_dirname "$file" "" "." + dir=$func_dirname_result + ;; + + *) + func_warning "'-dlopen' is ignored for non-libtool libraries and objects" + continue + ;; + esac + + # Get the absolute pathname. + absdir=`cd "$dir" && pwd` + test -n "$absdir" && dir=$absdir + + # Now add the directory to shlibpath_var. + if eval "test -z \"\$$shlibpath_var\""; then + eval "$shlibpath_var=\"\$dir\"" + else + eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" + fi + done + + # This variable tells wrapper scripts just to set shlibpath_var + # rather than running their programs. + libtool_execute_magic=$magic + + # Check if any of the arguments is a wrapper script. + args= + for file + do + case $file in + -* | *.la | *.lo ) ;; + *) + # Do a test to see if this is really a libtool program. + if func_ltwrapper_script_p "$file"; then + func_source "$file" + # Transform arg to wrapped name. + file=$progdir/$program + elif func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + func_source "$func_ltwrapper_scriptname_result" + # Transform arg to wrapped name. + file=$progdir/$program + fi + ;; + esac + # Quote arguments (to preserve shell metacharacters). + func_append_quoted args "$file" + done + + if $opt_dry_run; then + # Display what would be done. + if test -n "$shlibpath_var"; then + eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" + echo "export $shlibpath_var" + fi + $ECHO "$cmd$args" + exit $EXIT_SUCCESS + else + if test -n "$shlibpath_var"; then + # Export the shlibpath_var. + eval "export $shlibpath_var" + fi + + # Restore saved environment variables + for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES + do + eval "if test \"\${save_$lt_var+set}\" = set; then + $lt_var=\$save_$lt_var; export $lt_var + else + $lt_unset $lt_var + fi" + done + + # Now prepare to actually exec the command. + exec_cmd=\$cmd$args + fi +} + +test execute = "$opt_mode" && func_mode_execute ${1+"$@"} + + +# func_mode_finish arg... +func_mode_finish () +{ + $debug_cmd + + libs= + libdirs= + admincmds= + + for opt in "$nonopt" ${1+"$@"} + do + if test -d "$opt"; then + func_append libdirs " $opt" + + elif test -f "$opt"; then + if func_lalib_unsafe_p "$opt"; then + func_append libs " $opt" + else + func_warning "'$opt' is not a valid libtool archive" + fi + + else + func_fatal_error "invalid argument '$opt'" + fi + done + + if test -n "$libs"; then + if test -n "$lt_sysroot"; then + sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"` + sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;" + else + sysroot_cmd= + fi + + # Remove sysroot references + if $opt_dry_run; then + for lib in $libs; do + echo "removing references to $lt_sysroot and '=' prefixes from $lib" + done + else + tmpdir=`func_mktempdir` + for lib in $libs; do + $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \ + > $tmpdir/tmp-la + mv -f $tmpdir/tmp-la $lib + done + ${RM}r "$tmpdir" + fi + fi + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + for libdir in $libdirs; do + if test -n "$finish_cmds"; then + # Do each command in the finish commands. + func_execute_cmds "$finish_cmds" 'admincmds="$admincmds +'"$cmd"'"' + fi + if test -n "$finish_eval"; then + # Do the single finish_eval. + eval cmds=\"$finish_eval\" + $opt_dry_run || eval "$cmds" || func_append admincmds " + $cmds" + fi + done + fi + + # Exit here if they wanted silent mode. + $opt_quiet && exit $EXIT_SUCCESS + + if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then + echo "----------------------------------------------------------------------" + echo "Libraries have been installed in:" + for libdir in $libdirs; do + $ECHO " $libdir" + done + echo + echo "If you ever happen to want to link against installed libraries" + echo "in a given directory, LIBDIR, you must either use libtool, and" + echo "specify the full pathname of the library, or use the '-LLIBDIR'" + echo "flag during linking and do at least one of the following:" + if test -n "$shlibpath_var"; then + echo " - add LIBDIR to the '$shlibpath_var' environment variable" + echo " during execution" + fi + if test -n "$runpath_var"; then + echo " - add LIBDIR to the '$runpath_var' environment variable" + echo " during linking" + fi + if test -n "$hardcode_libdir_flag_spec"; then + libdir=LIBDIR + eval flag=\"$hardcode_libdir_flag_spec\" + + $ECHO " - use the '$flag' linker flag" + fi + if test -n "$admincmds"; then + $ECHO " - have your system administrator run these commands:$admincmds" + fi + if test -f /etc/ld.so.conf; then + echo " - have your system administrator add LIBDIR to '/etc/ld.so.conf'" + fi + echo + + echo "See any operating system documentation about shared libraries for" + case $host in + solaris2.[6789]|solaris2.1[0-9]) + echo "more information, such as the ld(1), crle(1) and ld.so(8) manual" + echo "pages." + ;; + *) + echo "more information, such as the ld(1) and ld.so(8) manual pages." + ;; + esac + echo "----------------------------------------------------------------------" + fi + exit $EXIT_SUCCESS +} + +test finish = "$opt_mode" && func_mode_finish ${1+"$@"} + + +# func_mode_install arg... +func_mode_install () +{ + $debug_cmd + + # There may be an optional sh(1) argument at the beginning of + # install_prog (especially on Windows NT). + if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" || + # Allow the use of GNU shtool's install command. + case $nonopt in *shtool*) :;; *) false;; esac + then + # Aesthetically quote it. + func_quote_for_eval "$nonopt" + install_prog="$func_quote_for_eval_result " + arg=$1 + shift + else + install_prog= + arg=$nonopt + fi + + # The real first argument should be the name of the installation program. + # Aesthetically quote it. + func_quote_for_eval "$arg" + func_append install_prog "$func_quote_for_eval_result" + install_shared_prog=$install_prog + case " $install_prog " in + *[\\\ /]cp\ *) install_cp=: ;; + *) install_cp=false ;; + esac + + # We need to accept at least all the BSD install flags. + dest= + files= + opts= + prev= + install_type= + isdir=false + stripme= + no_mode=: + for arg + do + arg2= + if test -n "$dest"; then + func_append files " $dest" + dest=$arg + continue + fi + + case $arg in + -d) isdir=: ;; + -f) + if $install_cp; then :; else + prev=$arg + fi + ;; + -g | -m | -o) + prev=$arg + ;; + -s) + stripme=" -s" + continue + ;; + -*) + ;; + *) + # If the previous option needed an argument, then skip it. + if test -n "$prev"; then + if test X-m = "X$prev" && test -n "$install_override_mode"; then + arg2=$install_override_mode + no_mode=false + fi + prev= + else + dest=$arg + continue + fi + ;; + esac + + # Aesthetically quote the argument. + func_quote_for_eval "$arg" + func_append install_prog " $func_quote_for_eval_result" + if test -n "$arg2"; then + func_quote_for_eval "$arg2" + fi + func_append install_shared_prog " $func_quote_for_eval_result" + done + + test -z "$install_prog" && \ + func_fatal_help "you must specify an install program" + + test -n "$prev" && \ + func_fatal_help "the '$prev' option requires an argument" + + if test -n "$install_override_mode" && $no_mode; then + if $install_cp; then :; else + func_quote_for_eval "$install_override_mode" + func_append install_shared_prog " -m $func_quote_for_eval_result" + fi + fi + + if test -z "$files"; then + if test -z "$dest"; then + func_fatal_help "no file or destination specified" + else + func_fatal_help "you must specify a destination" + fi + fi + + # Strip any trailing slash from the destination. + func_stripname '' '/' "$dest" + dest=$func_stripname_result + + # Check to see that the destination is a directory. + test -d "$dest" && isdir=: + if $isdir; then + destdir=$dest + destname= + else + func_dirname_and_basename "$dest" "" "." + destdir=$func_dirname_result + destname=$func_basename_result + + # Not a directory, so check to see that there is only one file specified. + set dummy $files; shift + test "$#" -gt 1 && \ + func_fatal_help "'$dest' is not a directory" + fi + case $destdir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + for file in $files; do + case $file in + *.lo) ;; + *) + func_fatal_help "'$destdir' must be an absolute directory name" + ;; + esac + done + ;; + esac + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic=$magic + + staticlibs= + future_libdirs= + current_libdirs= + for file in $files; do + + # Do each installation. + case $file in + *.$libext) + # Do the static libraries later. + func_append staticlibs " $file" + ;; + + *.la) + func_resolve_sysroot "$file" + file=$func_resolve_sysroot_result + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$file" \ + || func_fatal_help "'$file' is not a valid libtool archive" + + library_names= + old_library= + relink_command= + func_source "$file" + + # Add the libdir to current_libdirs if it is the destination. + if test "X$destdir" = "X$libdir"; then + case "$current_libdirs " in + *" $libdir "*) ;; + *) func_append current_libdirs " $libdir" ;; + esac + else + # Note the libdir as a future libdir. + case "$future_libdirs " in + *" $libdir "*) ;; + *) func_append future_libdirs " $libdir" ;; + esac + fi + + func_dirname "$file" "/" "" + dir=$func_dirname_result + func_append dir "$objdir" + + if test -n "$relink_command"; then + # Determine the prefix the user has applied to our future dir. + inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"` + + # Don't allow the user to place us outside of our expected + # location b/c this prevents finding dependent libraries that + # are installed to the same prefix. + # At present, this check doesn't affect windows .dll's that + # are installed into $libdir/../bin (currently, that works fine) + # but it's something to keep an eye on. + test "$inst_prefix_dir" = "$destdir" && \ + func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir" + + if test -n "$inst_prefix_dir"; then + # Stick the inst_prefix_dir data into the link command. + relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` + else + relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"` + fi + + func_warning "relinking '$file'" + func_show_eval "$relink_command" \ + 'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"' + fi + + # See the names of the shared library. + set dummy $library_names; shift + if test -n "$1"; then + realname=$1 + shift + + srcname=$realname + test -n "$relink_command" && srcname=${realname}T + + # Install the shared library and build the symlinks. + func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \ + 'exit $?' + tstripme=$stripme + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + case $realname in + *.dll.a) + tstripme= + ;; + esac + ;; + os2*) + case $realname in + *_dll.a) + tstripme= + ;; + esac + ;; + esac + if test -n "$tstripme" && test -n "$striplib"; then + func_show_eval "$striplib $destdir/$realname" 'exit $?' + fi + + if test "$#" -gt 0; then + # Delete the old symlinks, and create new ones. + # Try 'ln -sf' first, because the 'ln' binary might depend on + # the symlink we replace! Solaris /bin/ln does not understand -f, + # so we also need to try rm && ln -s. + for linkname + do + test "$linkname" != "$realname" \ + && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" + done + fi + + # Do each command in the postinstall commands. + lib=$destdir/$realname + func_execute_cmds "$postinstall_cmds" 'exit $?' + fi + + # Install the pseudo-library for information purposes. + func_basename "$file" + name=$func_basename_result + instname=$dir/${name}i + func_show_eval "$install_prog $instname $destdir/$name" 'exit $?' + + # Maybe install the static library, too. + test -n "$old_library" && func_append staticlibs " $dir/$old_library" + ;; + + *.lo) + # Install (i.e. copy) a libtool object. + + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile=$destdir/$destname + else + func_basename "$file" + destfile=$func_basename_result + destfile=$destdir/$destfile + fi + + # Deduce the name of the destination old-style object file. + case $destfile in + *.lo) + func_lo2o "$destfile" + staticdest=$func_lo2o_result + ;; + *.$objext) + staticdest=$destfile + destfile= + ;; + *) + func_fatal_help "cannot copy a libtool object to '$destfile'" + ;; + esac + + # Install the libtool object if requested. + test -n "$destfile" && \ + func_show_eval "$install_prog $file $destfile" 'exit $?' + + # Install the old object if enabled. + if test yes = "$build_old_libs"; then + # Deduce the name of the old-style object file. + func_lo2o "$file" + staticobj=$func_lo2o_result + func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?' + fi + exit $EXIT_SUCCESS + ;; + + *) + # Figure out destination file name, if it wasn't already specified. + if test -n "$destname"; then + destfile=$destdir/$destname + else + func_basename "$file" + destfile=$func_basename_result + destfile=$destdir/$destfile + fi + + # If the file is missing, and there is a .exe on the end, strip it + # because it is most likely a libtool script we actually want to + # install + stripped_ext= + case $file in + *.exe) + if test ! -f "$file"; then + func_stripname '' '.exe' "$file" + file=$func_stripname_result + stripped_ext=.exe + fi + ;; + esac + + # Do a test to see if this is really a libtool program. + case $host in + *cygwin* | *mingw*) + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + wrapper=$func_ltwrapper_scriptname_result + else + func_stripname '' '.exe' "$file" + wrapper=$func_stripname_result + fi + ;; + *) + wrapper=$file + ;; + esac + if func_ltwrapper_script_p "$wrapper"; then + notinst_deplibs= + relink_command= + + func_source "$wrapper" + + # Check the variables that should have been set. + test -z "$generated_by_libtool_version" && \ + func_fatal_error "invalid libtool wrapper script '$wrapper'" + + finalize=: + for lib in $notinst_deplibs; do + # Check to see that each library is installed. + libdir= + if test -f "$lib"; then + func_source "$lib" + fi + libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'` + if test -n "$libdir" && test ! -f "$libfile"; then + func_warning "'$lib' has not been installed in '$libdir'" + finalize=false + fi + done + + relink_command= + func_source "$wrapper" + + outputname= + if test no = "$fast_install" && test -n "$relink_command"; then + $opt_dry_run || { + if $finalize; then + tmpdir=`func_mktempdir` + func_basename "$file$stripped_ext" + file=$func_basename_result + outputname=$tmpdir/$file + # Replace the output file specification. + relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` + + $opt_quiet || { + func_quote_for_expand "$relink_command" + eval "func_echo $func_quote_for_expand_result" + } + if eval "$relink_command"; then : + else + func_error "error: relink '$file' with the above command before installing it" + $opt_dry_run || ${RM}r "$tmpdir" + continue + fi + file=$outputname + else + func_warning "cannot relink '$file'" + fi + } + else + # Install the binary that we compiled earlier. + file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"` + fi + fi + + # remove .exe since cygwin /usr/bin/install will append another + # one anyway + case $install_prog,$host in + */usr/bin/install*,*cygwin*) + case $file:$destfile in + *.exe:*.exe) + # this is ok + ;; + *.exe:*) + destfile=$destfile.exe + ;; + *:*.exe) + func_stripname '' '.exe' "$destfile" + destfile=$func_stripname_result + ;; + esac + ;; + esac + func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' + $opt_dry_run || if test -n "$outputname"; then + ${RM}r "$tmpdir" + fi + ;; + esac + done + + for file in $staticlibs; do + func_basename "$file" + name=$func_basename_result + + # Set up the ranlib parameters. + oldlib=$destdir/$name + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result + + func_show_eval "$install_prog \$file \$oldlib" 'exit $?' + + if test -n "$stripme" && test -n "$old_striplib"; then + func_show_eval "$old_striplib $tool_oldlib" 'exit $?' + fi + + # Do each command in the postinstall commands. + func_execute_cmds "$old_postinstall_cmds" 'exit $?' + done + + test -n "$future_libdirs" && \ + func_warning "remember to run '$progname --finish$future_libdirs'" + + if test -n "$current_libdirs"; then + # Maybe just do a dry run. + $opt_dry_run && current_libdirs=" -n$current_libdirs" + exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs' + else + exit $EXIT_SUCCESS + fi +} + +test install = "$opt_mode" && func_mode_install ${1+"$@"} + + +# func_generate_dlsyms outputname originator pic_p +# Extract symbols from dlprefiles and create ${outputname}S.o with +# a dlpreopen symbol table. +func_generate_dlsyms () +{ + $debug_cmd + + my_outputname=$1 + my_originator=$2 + my_pic_p=${3-false} + my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'` + my_dlsyms= + + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + if test -n "$NM" && test -n "$global_symbol_pipe"; then + my_dlsyms=${my_outputname}S.c + else + func_error "not configured to extract global symbols from dlpreopened files" + fi + fi + + if test -n "$my_dlsyms"; then + case $my_dlsyms in + "") ;; + *.c) + # Discover the nlist of each of the dlfiles. + nlist=$output_objdir/$my_outputname.nm + + func_show_eval "$RM $nlist ${nlist}S ${nlist}T" + + # Parse the name list into a source file. + func_verbose "creating $output_objdir/$my_dlsyms" + + $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ +/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */ +/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */ + +#ifdef __cplusplus +extern \"C\" { +#endif + +#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4)) +#pragma GCC diagnostic ignored \"-Wstrict-prototypes\" +#endif + +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + +#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) + +/* External symbol declarations for the compiler. */\ +" + + if test yes = "$dlself"; then + func_verbose "generating symbol list for '$output'" + + $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" + + # Add our own program objects to the symbol list. + progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP` + for progfile in $progfiles; do + func_to_tool_file "$progfile" func_convert_file_msys_to_w32 + func_verbose "extracting global C symbols from '$func_to_tool_file_result'" + $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'" + done + + if test -n "$exclude_expsyms"; then + $opt_dry_run || { + eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + if test -n "$export_symbols_regex"; then + $opt_dry_run || { + eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + } + fi + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + export_symbols=$output_objdir/$outputname.exp + $opt_dry_run || { + $RM $export_symbols + eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' + ;; + esac + } + else + $opt_dry_run || { + eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' + eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' + eval '$MV "$nlist"T "$nlist"' + case $host in + *cygwin* | *mingw* | *cegcc* ) + eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' + eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' + ;; + esac + } + fi + fi + + for dlprefile in $dlprefiles; do + func_verbose "extracting global C symbols from '$dlprefile'" + func_basename "$dlprefile" + name=$func_basename_result + case $host in + *cygwin* | *mingw* | *cegcc* ) + # if an import library, we need to obtain dlname + if func_win32_import_lib_p "$dlprefile"; then + func_tr_sh "$dlprefile" + eval "curr_lafile=\$libfile_$func_tr_sh_result" + dlprefile_dlbasename= + if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then + # Use subshell, to avoid clobbering current variable values + dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"` + if test -n "$dlprefile_dlname"; then + func_basename "$dlprefile_dlname" + dlprefile_dlbasename=$func_basename_result + else + # no lafile. user explicitly requested -dlpreopen . + $sharedlib_from_linklib_cmd "$dlprefile" + dlprefile_dlbasename=$sharedlib_from_linklib_result + fi + fi + $opt_dry_run || { + if test -n "$dlprefile_dlbasename"; then + eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"' + else + func_warning "Could not compute DLL name from $name" + eval '$ECHO ": $name " >> "$nlist"' + fi + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | + $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" + } + else # not an import lib + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + fi + ;; + *) + $opt_dry_run || { + eval '$ECHO ": $name " >> "$nlist"' + func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" + } + ;; + esac + done + + $opt_dry_run || { + # Make sure we have at least an empty file. + test -f "$nlist" || : > "$nlist" + + if test -n "$exclude_expsyms"; then + $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T + $MV "$nlist"T "$nlist" + fi + + # Try sorting and uniquifying the output. + if $GREP -v "^: " < "$nlist" | + if sort -k 3 /dev/null 2>&1; then + sort -k 3 + else + sort +2 + fi | + uniq > "$nlist"S; then + : + else + $GREP -v "^: " < "$nlist" > "$nlist"S + fi + + if test -f "$nlist"S; then + eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' + else + echo '/* NONE */' >> "$output_objdir/$my_dlsyms" + fi + + func_show_eval '$RM "${nlist}I"' + if test -n "$global_symbol_to_import"; then + eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I' + fi + + echo >> "$output_objdir/$my_dlsyms" "\ + +/* The mapping between symbol names and symbols. */ +typedef struct { + const char *name; + void *address; +} lt_dlsymlist; +extern LT_DLSYM_CONST lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[];\ +" + + if test -s "$nlist"I; then + echo >> "$output_objdir/$my_dlsyms" "\ +static void lt_syminit(void) +{ + LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols; + for (; symbol->name; ++symbol) + {" + $SED 's/.*/ if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms" + echo >> "$output_objdir/$my_dlsyms" "\ + } +}" + fi + echo >> "$output_objdir/$my_dlsyms" "\ +LT_DLSYM_CONST lt_dlsymlist +lt_${my_prefix}_LTX_preloaded_symbols[] = +{ {\"$my_originator\", (void *) 0}," + + if test -s "$nlist"I; then + echo >> "$output_objdir/$my_dlsyms" "\ + {\"@INIT@\", (void *) <_syminit}," + fi + + case $need_lib_prefix in + no) + eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + *) + eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" + ;; + esac + echo >> "$output_objdir/$my_dlsyms" "\ + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt_${my_prefix}_LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif\ +" + } # !$opt_dry_run + + pic_flag_for_symtable= + case "$compile_command " in + *" -static "*) ;; + *) + case $host in + # compiling the symbol table file with pic_flag works around + # a FreeBSD bug that causes programs to crash when -lm is + # linked before any other PIC object. But we must not use + # pic_flag when linking with -static. The problem exists in + # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. + *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) + pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; + *-*-hpux*) + pic_flag_for_symtable=" $pic_flag" ;; + *) + $my_pic_p && pic_flag_for_symtable=" $pic_flag" + ;; + esac + ;; + esac + symtab_cflags= + for arg in $LTCFLAGS; do + case $arg in + -pie | -fpie | -fPIE) ;; + *) func_append symtab_cflags " $arg" ;; + esac + done + + # Now compile the dynamic symbol file. + func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' + + # Clean up the generated files. + func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"' + + # Transform the symbol file into the correct name. + symfileobj=$output_objdir/${my_outputname}S.$objext + case $host in + *cygwin* | *mingw* | *cegcc* ) + if test -f "$output_objdir/$my_outputname.def"; then + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` + else + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` + fi + ;; + *) + compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` + ;; + esac + ;; + *) + func_fatal_error "unknown suffix for '$my_dlsyms'" + ;; + esac + else + # We keep going just in case the user didn't refer to + # lt_preloaded_symbols. The linker will fail if global_symbol_pipe + # really was required. + + # Nullify the symbol file. + compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"` + finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"` + fi +} + +# func_cygming_gnu_implib_p ARG +# This predicate returns with zero status (TRUE) if +# ARG is a GNU/binutils-style import library. Returns +# with nonzero status (FALSE) otherwise. +func_cygming_gnu_implib_p () +{ + $debug_cmd + + func_to_tool_file "$1" func_convert_file_msys_to_w32 + func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'` + test -n "$func_cygming_gnu_implib_tmp" +} + +# func_cygming_ms_implib_p ARG +# This predicate returns with zero status (TRUE) if +# ARG is an MS-style import library. Returns +# with nonzero status (FALSE) otherwise. +func_cygming_ms_implib_p () +{ + $debug_cmd + + func_to_tool_file "$1" func_convert_file_msys_to_w32 + func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'` + test -n "$func_cygming_ms_implib_tmp" +} + +# func_win32_libid arg +# return the library type of file 'arg' +# +# Need a lot of goo to handle *both* DLLs and import libs +# Has to be a shell function in order to 'eat' the argument +# that is supplied when $file_magic_command is called. +# Despite the name, also deal with 64 bit binaries. +func_win32_libid () +{ + $debug_cmd + + win32_libid_type=unknown + win32_fileres=`file -L $1 2>/dev/null` + case $win32_fileres in + *ar\ archive\ import\ library*) # definitely import + win32_libid_type="x86 archive import" + ;; + *ar\ archive*) # could be an import, or static + # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. + if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | + $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then + case $nm_interface in + "MS dumpbin") + if func_cygming_ms_implib_p "$1" || + func_cygming_gnu_implib_p "$1" + then + win32_nmres=import + else + win32_nmres= + fi + ;; + *) + func_to_tool_file "$1" func_convert_file_msys_to_w32 + win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" | + $SED -n -e ' + 1,100{ + / I /{ + s|.*|import| + p + q + } + }'` + ;; + esac + case $win32_nmres in + import*) win32_libid_type="x86 archive import";; + *) win32_libid_type="x86 archive static";; + esac + fi + ;; + *DLL*) + win32_libid_type="x86 DLL" + ;; + *executable*) # but shell scripts are "executable" too... + case $win32_fileres in + *MS\ Windows\ PE\ Intel*) + win32_libid_type="x86 DLL" + ;; + esac + ;; + esac + $ECHO "$win32_libid_type" +} + +# func_cygming_dll_for_implib ARG +# +# Platform-specific function to extract the +# name of the DLL associated with the specified +# import library ARG. +# Invoked by eval'ing the libtool variable +# $sharedlib_from_linklib_cmd +# Result is available in the variable +# $sharedlib_from_linklib_result +func_cygming_dll_for_implib () +{ + $debug_cmd + + sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"` +} + +# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs +# +# The is the core of a fallback implementation of a +# platform-specific function to extract the name of the +# DLL associated with the specified import library LIBNAME. +# +# SECTION_NAME is either .idata$6 or .idata$7, depending +# on the platform and compiler that created the implib. +# +# Echos the name of the DLL associated with the +# specified import library. +func_cygming_dll_for_implib_fallback_core () +{ + $debug_cmd + + match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"` + $OBJDUMP -s --section "$1" "$2" 2>/dev/null | + $SED '/^Contents of section '"$match_literal"':/{ + # Place marker at beginning of archive member dllname section + s/.*/====MARK====/ + p + d + } + # These lines can sometimes be longer than 43 characters, but + # are always uninteresting + /:[ ]*file format pe[i]\{,1\}-/d + /^In archive [^:]*:/d + # Ensure marker is printed + /^====MARK====/p + # Remove all lines with less than 43 characters + /^.\{43\}/!d + # From remaining lines, remove first 43 characters + s/^.\{43\}//' | + $SED -n ' + # Join marker and all lines until next marker into a single line + /^====MARK====/ b para + H + $ b para + b + :para + x + s/\n//g + # Remove the marker + s/^====MARK====// + # Remove trailing dots and whitespace + s/[\. \t]*$// + # Print + /./p' | + # we now have a list, one entry per line, of the stringified + # contents of the appropriate section of all members of the + # archive that possess that section. Heuristic: eliminate + # all those that have a first or second character that is + # a '.' (that is, objdump's representation of an unprintable + # character.) This should work for all archives with less than + # 0x302f exports -- but will fail for DLLs whose name actually + # begins with a literal '.' or a single character followed by + # a '.'. + # + # Of those that remain, print the first one. + $SED -e '/^\./d;/^.\./d;q' +} + +# func_cygming_dll_for_implib_fallback ARG +# Platform-specific function to extract the +# name of the DLL associated with the specified +# import library ARG. +# +# This fallback implementation is for use when $DLLTOOL +# does not support the --identify-strict option. +# Invoked by eval'ing the libtool variable +# $sharedlib_from_linklib_cmd +# Result is available in the variable +# $sharedlib_from_linklib_result +func_cygming_dll_for_implib_fallback () +{ + $debug_cmd + + if func_cygming_gnu_implib_p "$1"; then + # binutils import library + sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"` + elif func_cygming_ms_implib_p "$1"; then + # ms-generated import library + sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"` + else + # unknown + sharedlib_from_linklib_result= + fi +} + + +# func_extract_an_archive dir oldlib +func_extract_an_archive () +{ + $debug_cmd + + f_ex_an_ar_dir=$1; shift + f_ex_an_ar_oldlib=$1 + if test yes = "$lock_old_archive_extraction"; then + lockfile=$f_ex_an_ar_oldlib.lock + until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do + func_echo "Waiting for $lockfile to be removed" + sleep 2 + done + fi + func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \ + 'stat=$?; rm -f "$lockfile"; exit $stat' + if test yes = "$lock_old_archive_extraction"; then + $opt_dry_run || rm -f "$lockfile" + fi + if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then + : + else + func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" + fi +} + + +# func_extract_archives gentop oldlib ... +func_extract_archives () +{ + $debug_cmd + + my_gentop=$1; shift + my_oldlibs=${1+"$@"} + my_oldobjs= + my_xlib= + my_xabs= + my_xdir= + + for my_xlib in $my_oldlibs; do + # Extract the objects. + case $my_xlib in + [\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;; + *) my_xabs=`pwd`"/$my_xlib" ;; + esac + func_basename "$my_xlib" + my_xlib=$func_basename_result + my_xlib_u=$my_xlib + while :; do + case " $extracted_archives " in + *" $my_xlib_u "*) + func_arith $extracted_serial + 1 + extracted_serial=$func_arith_result + my_xlib_u=lt$extracted_serial-$my_xlib ;; + *) break ;; + esac + done + extracted_archives="$extracted_archives $my_xlib_u" + my_xdir=$my_gentop/$my_xlib_u + + func_mkdir_p "$my_xdir" + + case $host in + *-darwin*) + func_verbose "Extracting $my_xabs" + # Do not bother doing anything if just a dry run + $opt_dry_run || { + darwin_orig_dir=`pwd` + cd $my_xdir || exit $? + darwin_archive=$my_xabs + darwin_curdir=`pwd` + func_basename "$darwin_archive" + darwin_base_archive=$func_basename_result + darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` + if test -n "$darwin_arches"; then + darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` + darwin_arch= + func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" + for darwin_arch in $darwin_arches; do + func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch" + $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive" + cd "unfat-$$/$darwin_base_archive-$darwin_arch" + func_extract_an_archive "`pwd`" "$darwin_base_archive" + cd "$darwin_curdir" + $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" + done # $darwin_arches + ## Okay now we've a bunch of thin objects, gotta fatten them up :) + darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u` + darwin_file= + darwin_files= + for darwin_file in $darwin_filelist; do + darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP` + $LIPO -create -output "$darwin_file" $darwin_files + done # $darwin_filelist + $RM -rf unfat-$$ + cd "$darwin_orig_dir" + else + cd $darwin_orig_dir + func_extract_an_archive "$my_xdir" "$my_xabs" + fi # $darwin_arches + } # !$opt_dry_run + ;; + *) + func_extract_an_archive "$my_xdir" "$my_xabs" + ;; + esac + my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP` + done + + func_extract_archives_result=$my_oldobjs +} + + +# func_emit_wrapper [arg=no] +# +# Emit a libtool wrapper script on stdout. +# Don't directly open a file because we may want to +# incorporate the script contents within a cygwin/mingw +# wrapper executable. Must ONLY be called from within +# func_mode_link because it depends on a number of variables +# set therein. +# +# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR +# variable will take. If 'yes', then the emitted script +# will assume that the directory where it is stored is +# the $objdir directory. This is a cygwin/mingw-specific +# behavior. +func_emit_wrapper () +{ + func_emit_wrapper_arg1=${1-no} + + $ECHO "\ +#! $SHELL + +# $output - temporary wrapper script for $objdir/$outputname +# Generated by $PROGRAM (GNU $PACKAGE) $VERSION +# +# The $output program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='$sed_quote_subst' + +# Be Bourne compatible +if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command=\"$relink_command\" + +# This environment variable determines our operation mode. +if test \"\$libtool_install_magic\" = \"$magic\"; then + # install mode needs the following variables: + generated_by_libtool_version='$macro_version' + notinst_deplibs='$notinst_deplibs' +else + # When we are sourced in execute mode, \$file and \$ECHO are already set. + if test \"\$libtool_execute_magic\" != \"$magic\"; then + file=\"\$0\"" + + qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"` + $ECHO "\ + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + ECHO=\"$qECHO\" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ that is used only on +# windows platforms, and (c) all begin with the string "--lt-" +# (application programs are unlikely to have options that match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's $0 value, followed by "$@". +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=\$0 + shift + for lt_opt + do + case \"\$lt_opt\" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\` + test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=. + lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\` + cat \"\$lt_dump_D/\$lt_dump_F\" + exit 0 + ;; + --lt-*) + \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n \"\$lt_option_debug\"; then + echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\" + lt_dump_args_N=\`expr \$lt_dump_args_N + 1\` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ +" + case $host in + # Backslashes separate directories on plain windows + *-*-mingw | *-*-os2* | *-cegcc*) + $ECHO "\ + if test -n \"\$lt_option_debug\"; then + \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2 + func_lt_dump_args \${1+\"\$@\"} 1>&2 + fi + exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} +" + ;; + + *) + $ECHO "\ + if test -n \"\$lt_option_debug\"; then + \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2 + func_lt_dump_args \${1+\"\$@\"} 1>&2 + fi + exec \"\$progdir/\$program\" \${1+\"\$@\"} +" + ;; + esac + $ECHO "\ + \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from \$@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case \" \$* \" in + *\\ --lt-*) + for lt_wr_arg + do + case \$lt_wr_arg in + --lt-*) ;; + *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; + esac + shift + done ;; + esac + func_exec_program_core \${1+\"\$@\"} +} + + # Parse options + func_parse_lt_options \"\$0\" \${1+\"\$@\"} + + # Find the directory that this script lives in. + thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\` + test \"x\$thisdir\" = \"x\$file\" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\` + while test -n \"\$file\"; do + destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\` + + # If there was a directory component, then change thisdir. + if test \"x\$destdir\" != \"x\$file\"; then + case \"\$destdir\" in + [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; + *) thisdir=\"\$thisdir/\$destdir\" ;; + esac + fi + + file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\` + file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 + if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then + # special case for '.' + if test \"\$thisdir\" = \".\"; then + thisdir=\`pwd\` + fi + # remove .libs from thisdir + case \"\$thisdir\" in + *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;; + $objdir ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=\`cd \"\$thisdir\" && pwd\` + test -n \"\$absdir\" && thisdir=\"\$absdir\" +" + + if test yes = "$fast_install"; then + $ECHO "\ + program=lt-'$outputname'$exeext + progdir=\"\$thisdir/$objdir\" + + if test ! -f \"\$progdir/\$program\" || + { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\ + test \"X\$file\" != \"X\$progdir/\$program\"; }; then + + file=\"\$\$-\$program\" + + if test ! -d \"\$progdir\"; then + $MKDIR \"\$progdir\" + else + $RM \"\$progdir/\$file\" + fi" + + $ECHO "\ + + # relink executable if necessary + if test -n \"\$relink_command\"; then + if relink_command_output=\`eval \$relink_command 2>&1\`; then : + else + \$ECHO \"\$relink_command_output\" >&2 + $RM \"\$progdir/\$file\" + exit 1 + fi + fi + + $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || + { $RM \"\$progdir/\$program\"; + $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } + $RM \"\$progdir/\$file\" + fi" + else + $ECHO "\ + program='$outputname' + progdir=\"\$thisdir/$objdir\" +" + fi + + $ECHO "\ + + if test -f \"\$progdir/\$program\"; then" + + # fixup the dll searchpath if we need to. + # + # Fix the DLL searchpath if we need to. Do this before prepending + # to shlibpath, because on Windows, both are PATH and uninstalled + # libraries must come first. + if test -n "$dllsearchpath"; then + $ECHO "\ + # Add the dll search path components to the executable PATH + PATH=$dllsearchpath:\$PATH +" + fi + + # Export our shlibpath_var if we have one. + if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then + $ECHO "\ + # Add our own library path to $shlibpath_var + $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" + + # Some systems cannot cope with colon-terminated $shlibpath_var + # The second colon is a workaround for a bug in BeOS R4 sed + $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\` + + export $shlibpath_var +" + fi + + $ECHO "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then + # Run the actual program with our arguments. + func_exec_program \${1+\"\$@\"} + fi + else + # The program doesn't exist. + \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2 + \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 + \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 + exit 1 + fi +fi\ +" +} + + +# func_emit_cwrapperexe_src +# emit the source code for a wrapper executable on stdout +# Must ONLY be called from within func_mode_link because +# it depends on a number of variable set therein. +func_emit_cwrapperexe_src () +{ + cat < +#include +#ifdef _MSC_VER +# include +# include +# include +#else +# include +# include +# ifdef __CYGWIN__ +# include +# endif +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0) + +/* declarations of non-ANSI functions */ +#if defined __MINGW32__ +# ifdef __STRICT_ANSI__ +int _putenv (const char *); +# endif +#elif defined __CYGWIN__ +# ifdef __STRICT_ANSI__ +char *realpath (const char *, char *); +int putenv (char *); +int setenv (const char *, const char *, int); +# endif +/* #elif defined other_platform || defined ... */ +#endif + +/* portability defines, excluding path handling macros */ +#if defined _MSC_VER +# define setmode _setmode +# define stat _stat +# define chmod _chmod +# define getcwd _getcwd +# define putenv _putenv +# define S_IXUSR _S_IEXEC +#elif defined __MINGW32__ +# define setmode _setmode +# define stat _stat +# define chmod _chmod +# define getcwd _getcwd +# define putenv _putenv +#elif defined __CYGWIN__ +# define HAVE_SETENV +# define FOPEN_WB "wb" +/* #elif defined other platforms ... */ +#endif + +#if defined PATH_MAX +# define LT_PATHMAX PATH_MAX +#elif defined MAXPATHLEN +# define LT_PATHMAX MAXPATHLEN +#else +# define LT_PATHMAX 1024 +#endif + +#ifndef S_IXOTH +# define S_IXOTH 0 +#endif +#ifndef S_IXGRP +# define S_IXGRP 0 +#endif + +/* path handling portability macros */ +#ifndef DIR_SEPARATOR +# define DIR_SEPARATOR '/' +# define PATH_SEPARATOR ':' +#endif + +#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \ + defined __OS2__ +# define HAVE_DOS_BASED_FILE_SYSTEM +# define FOPEN_WB "wb" +# ifndef DIR_SEPARATOR_2 +# define DIR_SEPARATOR_2 '\\' +# endif +# ifndef PATH_SEPARATOR_2 +# define PATH_SEPARATOR_2 ';' +# endif +#endif + +#ifndef DIR_SEPARATOR_2 +# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +# define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + +#ifndef PATH_SEPARATOR_2 +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) +#else /* PATH_SEPARATOR_2 */ +# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) +#endif /* PATH_SEPARATOR_2 */ + +#ifndef FOPEN_WB +# define FOPEN_WB "w" +#endif +#ifndef _O_BINARY +# define _O_BINARY 0 +#endif + +#define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) +#define XFREE(stale) do { \ + if (stale) { free (stale); stale = 0; } \ +} while (0) + +#if defined LT_DEBUGWRAPPER +static int lt_debug = 1; +#else +static int lt_debug = 0; +#endif + +const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */ + +void *xmalloc (size_t num); +char *xstrdup (const char *string); +const char *base_name (const char *name); +char *find_executable (const char *wrapper); +char *chase_symlinks (const char *pathspec); +int make_executable (const char *path); +int check_executable (const char *path); +char *strendzap (char *str, const char *pat); +void lt_debugprintf (const char *file, int line, const char *fmt, ...); +void lt_fatal (const char *file, int line, const char *message, ...); +static const char *nonnull (const char *s); +static const char *nonempty (const char *s); +void lt_setenv (const char *name, const char *value); +char *lt_extend_str (const char *orig_value, const char *add, int to_end); +void lt_update_exe_path (const char *name, const char *value); +void lt_update_lib_path (const char *name, const char *value); +char **prepare_spawn (char **argv); +void lt_dump_script (FILE *f); +EOF + + cat <= 0) + && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) + return 1; + else + return 0; +} + +int +make_executable (const char *path) +{ + int rval = 0; + struct stat st; + + lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n", + nonempty (path)); + if ((!path) || (!*path)) + return 0; + + if (stat (path, &st) >= 0) + { + rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); + } + return rval; +} + +/* Searches for the full path of the wrapper. Returns + newly allocated full path name if found, NULL otherwise + Does not chase symlinks, even on platforms that support them. +*/ +char * +find_executable (const char *wrapper) +{ + int has_slash = 0; + const char *p; + const char *p_next; + /* static buffer for getcwd */ + char tmp[LT_PATHMAX + 1]; + size_t tmp_len; + char *concat_name; + + lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n", + nonempty (wrapper)); + + if ((wrapper == NULL) || (*wrapper == '\0')) + return NULL; + + /* Absolute path? */ +#if defined HAVE_DOS_BASED_FILE_SYSTEM + if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + else + { +#endif + if (IS_DIR_SEPARATOR (wrapper[0])) + { + concat_name = xstrdup (wrapper); + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } +#if defined HAVE_DOS_BASED_FILE_SYSTEM + } +#endif + + for (p = wrapper; *p; p++) + if (*p == '/') + { + has_slash = 1; + break; + } + if (!has_slash) + { + /* no slashes; search PATH */ + const char *path = getenv ("PATH"); + if (path != NULL) + { + for (p = path; *p; p = p_next) + { + const char *q; + size_t p_len; + for (q = p; *q; q++) + if (IS_PATH_SEPARATOR (*q)) + break; + p_len = (size_t) (q - p); + p_next = (*q == '\0' ? q : q + 1); + if (p_len == 0) + { + /* empty path: current directory */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", + nonnull (strerror (errno))); + tmp_len = strlen (tmp); + concat_name = + XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + } + else + { + concat_name = + XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, p, p_len); + concat_name[p_len] = '/'; + strcpy (concat_name + p_len + 1, wrapper); + } + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + } + } + /* not found in PATH; assume curdir */ + } + /* Relative path | not found in path: prepend cwd */ + if (getcwd (tmp, LT_PATHMAX) == NULL) + lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", + nonnull (strerror (errno))); + tmp_len = strlen (tmp); + concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); + memcpy (concat_name, tmp, tmp_len); + concat_name[tmp_len] = '/'; + strcpy (concat_name + tmp_len + 1, wrapper); + + if (check_executable (concat_name)) + return concat_name; + XFREE (concat_name); + return NULL; +} + +char * +chase_symlinks (const char *pathspec) +{ +#ifndef S_ISLNK + return xstrdup (pathspec); +#else + char buf[LT_PATHMAX]; + struct stat s; + char *tmp_pathspec = xstrdup (pathspec); + char *p; + int has_symlinks = 0; + while (strlen (tmp_pathspec) && !has_symlinks) + { + lt_debugprintf (__FILE__, __LINE__, + "checking path component for symlinks: %s\n", + tmp_pathspec); + if (lstat (tmp_pathspec, &s) == 0) + { + if (S_ISLNK (s.st_mode) != 0) + { + has_symlinks = 1; + break; + } + + /* search backwards for last DIR_SEPARATOR */ + p = tmp_pathspec + strlen (tmp_pathspec) - 1; + while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + p--; + if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) + { + /* no more DIR_SEPARATORS left */ + break; + } + *p = '\0'; + } + else + { + lt_fatal (__FILE__, __LINE__, + "error accessing file \"%s\": %s", + tmp_pathspec, nonnull (strerror (errno))); + } + } + XFREE (tmp_pathspec); + + if (!has_symlinks) + { + return xstrdup (pathspec); + } + + tmp_pathspec = realpath (pathspec, buf); + if (tmp_pathspec == 0) + { + lt_fatal (__FILE__, __LINE__, + "could not follow symlinks for %s", pathspec); + } + return xstrdup (tmp_pathspec); +#endif +} + +char * +strendzap (char *str, const char *pat) +{ + size_t len, patlen; + + assert (str != NULL); + assert (pat != NULL); + + len = strlen (str); + patlen = strlen (pat); + + if (patlen <= len) + { + str += len - patlen; + if (STREQ (str, pat)) + *str = '\0'; + } + return str; +} + +void +lt_debugprintf (const char *file, int line, const char *fmt, ...) +{ + va_list args; + if (lt_debug) + { + (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line); + va_start (args, fmt); + (void) vfprintf (stderr, fmt, args); + va_end (args); + } +} + +static void +lt_error_core (int exit_status, const char *file, + int line, const char *mode, + const char *message, va_list ap) +{ + fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode); + vfprintf (stderr, message, ap); + fprintf (stderr, ".\n"); + + if (exit_status >= 0) + exit (exit_status); +} + +void +lt_fatal (const char *file, int line, const char *message, ...) +{ + va_list ap; + va_start (ap, message); + lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap); + va_end (ap); +} + +static const char * +nonnull (const char *s) +{ + return s ? s : "(null)"; +} + +static const char * +nonempty (const char *s) +{ + return (s && !*s) ? "(empty)" : nonnull (s); +} + +void +lt_setenv (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_setenv) setting '%s' to '%s'\n", + nonnull (name), nonnull (value)); + { +#ifdef HAVE_SETENV + /* always make a copy, for consistency with !HAVE_SETENV */ + char *str = xstrdup (value); + setenv (name, str, 1); +#else + size_t len = strlen (name) + 1 + strlen (value) + 1; + char *str = XMALLOC (char, len); + sprintf (str, "%s=%s", name, value); + if (putenv (str) != EXIT_SUCCESS) + { + XFREE (str); + } +#endif + } +} + +char * +lt_extend_str (const char *orig_value, const char *add, int to_end) +{ + char *new_value; + if (orig_value && *orig_value) + { + size_t orig_value_len = strlen (orig_value); + size_t add_len = strlen (add); + new_value = XMALLOC (char, add_len + orig_value_len + 1); + if (to_end) + { + strcpy (new_value, orig_value); + strcpy (new_value + orig_value_len, add); + } + else + { + strcpy (new_value, add); + strcpy (new_value + add_len, orig_value); + } + } + else + { + new_value = xstrdup (add); + } + return new_value; +} + +void +lt_update_exe_path (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_update_exe_path) modifying '%s' by prepending '%s'\n", + nonnull (name), nonnull (value)); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + /* some systems can't cope with a ':'-terminated path #' */ + size_t len = strlen (new_value); + while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1])) + { + new_value[--len] = '\0'; + } + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +void +lt_update_lib_path (const char *name, const char *value) +{ + lt_debugprintf (__FILE__, __LINE__, + "(lt_update_lib_path) modifying '%s' by prepending '%s'\n", + nonnull (name), nonnull (value)); + + if (name && *name && value && *value) + { + char *new_value = lt_extend_str (getenv (name), value, 0); + lt_setenv (name, new_value); + XFREE (new_value); + } +} + +EOF + case $host_os in + mingw*) + cat <<"EOF" + +/* Prepares an argument vector before calling spawn(). + Note that spawn() does not by itself call the command interpreter + (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") : + ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&v); + v.dwPlatformId == VER_PLATFORM_WIN32_NT; + }) ? "cmd.exe" : "command.com"). + Instead it simply concatenates the arguments, separated by ' ', and calls + CreateProcess(). We must quote the arguments since Win32 CreateProcess() + interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a + special way: + - Space and tab are interpreted as delimiters. They are not treated as + delimiters if they are surrounded by double quotes: "...". + - Unescaped double quotes are removed from the input. Their only effect is + that within double quotes, space and tab are treated like normal + characters. + - Backslashes not followed by double quotes are not special. + - But 2*n+1 backslashes followed by a double quote become + n backslashes followed by a double quote (n >= 0): + \" -> " + \\\" -> \" + \\\\\" -> \\" + */ +#define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" +#define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" +char ** +prepare_spawn (char **argv) +{ + size_t argc; + char **new_argv; + size_t i; + + /* Count number of arguments. */ + for (argc = 0; argv[argc] != NULL; argc++) + ; + + /* Allocate new argument vector. */ + new_argv = XMALLOC (char *, argc + 1); + + /* Put quoted arguments into the new argument vector. */ + for (i = 0; i < argc; i++) + { + const char *string = argv[i]; + + if (string[0] == '\0') + new_argv[i] = xstrdup ("\"\""); + else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL) + { + int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL); + size_t length; + unsigned int backslashes; + const char *s; + char *quoted_string; + char *p; + + length = 0; + backslashes = 0; + if (quote_around) + length++; + for (s = string; *s != '\0'; s++) + { + char c = *s; + if (c == '"') + length += backslashes + 1; + length++; + if (c == '\\') + backslashes++; + else + backslashes = 0; + } + if (quote_around) + length += backslashes + 1; + + quoted_string = XMALLOC (char, length + 1); + + p = quoted_string; + backslashes = 0; + if (quote_around) + *p++ = '"'; + for (s = string; *s != '\0'; s++) + { + char c = *s; + if (c == '"') + { + unsigned int j; + for (j = backslashes + 1; j > 0; j--) + *p++ = '\\'; + } + *p++ = c; + if (c == '\\') + backslashes++; + else + backslashes = 0; + } + if (quote_around) + { + unsigned int j; + for (j = backslashes; j > 0; j--) + *p++ = '\\'; + *p++ = '"'; + } + *p = '\0'; + + new_argv[i] = quoted_string; + } + else + new_argv[i] = (char *) string; + } + new_argv[argc] = NULL; + + return new_argv; +} +EOF + ;; + esac + + cat <<"EOF" +void lt_dump_script (FILE* f) +{ +EOF + func_emit_wrapper yes | + $SED -n -e ' +s/^\(.\{79\}\)\(..*\)/\1\ +\2/ +h +s/\([\\"]\)/\\\1/g +s/$/\\n/ +s/\([^\n]*\).*/ fputs ("\1", f);/p +g +D' + cat <<"EOF" +} +EOF +} +# end: func_emit_cwrapperexe_src + +# func_win32_import_lib_p ARG +# True if ARG is an import lib, as indicated by $file_magic_cmd +func_win32_import_lib_p () +{ + $debug_cmd + + case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in + *import*) : ;; + *) false ;; + esac +} + +# func_suncc_cstd_abi +# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!! +# Several compiler flags select an ABI that is incompatible with the +# Cstd library. Avoid specifying it if any are in CXXFLAGS. +func_suncc_cstd_abi () +{ + $debug_cmd + + case " $compile_command " in + *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*) + suncc_use_cstd_abi=no + ;; + *) + suncc_use_cstd_abi=yes + ;; + esac +} + +# func_mode_link arg... +func_mode_link () +{ + $debug_cmd + + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + # It is impossible to link a dll without this setting, and + # we shouldn't force the makefile maintainer to figure out + # what system we are compiling for in order to pass an extra + # flag for every libtool invocation. + # allow_undefined=no + + # FIXME: Unfortunately, there are problems with the above when trying + # to make a dll that has undefined symbols, in which case not + # even a static library is built. For now, we need to specify + # -no-undefined on the libtool link line when we can be certain + # that all symbols are satisfied, otherwise we get a static library. + allow_undefined=yes + ;; + *) + allow_undefined=yes + ;; + esac + libtool_args=$nonopt + base_compile="$nonopt $@" + compile_command=$nonopt + finalize_command=$nonopt + + compile_rpath= + finalize_rpath= + compile_shlibpath= + finalize_shlibpath= + convenience= + old_convenience= + deplibs= + old_deplibs= + compiler_flags= + linker_flags= + dllsearchpath= + lib_search_path=`pwd` + inst_prefix_dir= + new_inherited_linker_flags= + + avoid_version=no + bindir= + dlfiles= + dlprefiles= + dlself=no + export_dynamic=no + export_symbols= + export_symbols_regex= + generated= + libobjs= + ltlibs= + module=no + no_install=no + objs= + os2dllname= + non_pic_objects= + precious_files_regex= + prefer_static_libs=no + preload=false + prev= + prevarg= + release= + rpath= + xrpath= + perm_rpath= + temp_rpath= + thread_safe=no + vinfo= + vinfo_number=no + weak_libs= + single_module=$wl-single_module + func_infer_tag $base_compile + + # We need to know -static, to get the right output filenames. + for arg + do + case $arg in + -shared) + test yes != "$build_libtool_libs" \ + && func_fatal_configuration "cannot build a shared library" + build_old_libs=no + break + ;; + -all-static | -static | -static-libtool-libs) + case $arg in + -all-static) + if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then + func_warning "complete static linking is impossible in this configuration" + fi + if test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + -static) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=built + ;; + -static-libtool-libs) + if test -z "$pic_flag" && test -n "$link_static_flag"; then + dlopen_self=$dlopen_self_static + fi + prefer_static_libs=yes + ;; + esac + build_libtool_libs=no + build_old_libs=yes + break + ;; + esac + done + + # See if our shared archives depend on static archives. + test -n "$old_archive_from_new_cmds" && build_old_libs=yes + + # Go through the arguments, transforming them on the way. + while test "$#" -gt 0; do + arg=$1 + shift + func_quote_for_eval "$arg" + qarg=$func_quote_for_eval_unquoted_result + func_append libtool_args " $func_quote_for_eval_result" + + # If the previous option needs an argument, assign it. + if test -n "$prev"; then + case $prev in + output) + func_append compile_command " @OUTPUT@" + func_append finalize_command " @OUTPUT@" + ;; + esac + + case $prev in + bindir) + bindir=$arg + prev= + continue + ;; + dlfiles|dlprefiles) + $preload || { + # Add the symbol object into the linking commands. + func_append compile_command " @SYMFILE@" + func_append finalize_command " @SYMFILE@" + preload=: + } + case $arg in + *.la | *.lo) ;; # We handle these cases below. + force) + if test no = "$dlself"; then + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + self) + if test dlprefiles = "$prev"; then + dlself=yes + elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then + dlself=yes + else + dlself=needless + export_dynamic=yes + fi + prev= + continue + ;; + *) + if test dlfiles = "$prev"; then + func_append dlfiles " $arg" + else + func_append dlprefiles " $arg" + fi + prev= + continue + ;; + esac + ;; + expsyms) + export_symbols=$arg + test -f "$arg" \ + || func_fatal_error "symbol file '$arg' does not exist" + prev= + continue + ;; + expsyms_regex) + export_symbols_regex=$arg + prev= + continue + ;; + framework) + case $host in + *-*-darwin*) + case "$deplibs " in + *" $qarg.ltframework "*) ;; + *) func_append deplibs " $qarg.ltframework" # this is fixed later + ;; + esac + ;; + esac + prev= + continue + ;; + inst_prefix) + inst_prefix_dir=$arg + prev= + continue + ;; + mllvm) + # Clang does not use LLVM to link, so we can simply discard any + # '-mllvm $arg' options when doing the link step. + prev= + continue + ;; + objectlist) + if test -f "$arg"; then + save_arg=$arg + moreargs= + for fil in `cat "$save_arg"` + do +# func_append moreargs " $fil" + arg=$fil + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test none = "$pic_object" && + test none = "$non_pic_object"; then + func_fatal_error "cannot find name of object for '$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + if test none != "$pic_object"; then + # Prepend the subdirectory the object is found in. + pic_object=$xdir$pic_object + + if test dlfiles = "$prev"; then + if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then + func_append dlfiles " $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test dlprefiles = "$prev"; then + # Preload the old-style object. + func_append dlprefiles " $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg=$pic_object + fi + + # Non-PIC object. + if test none != "$non_pic_object"; then + # Prepend the subdirectory the object is found in. + non_pic_object=$xdir$non_pic_object + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test none = "$pic_object"; then + arg=$non_pic_object + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object=$pic_object + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "'$arg' is not a valid libtool object" + fi + fi + done + else + func_fatal_error "link input file '$arg' does not exist" + fi + arg=$save_arg + prev= + continue + ;; + os2dllname) + os2dllname=$arg + prev= + continue + ;; + precious_regex) + precious_files_regex=$arg + prev= + continue + ;; + release) + release=-$arg + prev= + continue + ;; + rpath | xrpath) + # We need an absolute path. + case $arg in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + if test rpath = "$prev"; then + case "$rpath " in + *" $arg "*) ;; + *) func_append rpath " $arg" ;; + esac + else + case "$xrpath " in + *" $arg "*) ;; + *) func_append xrpath " $arg" ;; + esac + fi + prev= + continue + ;; + shrext) + shrext_cmds=$arg + prev= + continue + ;; + weak) + func_append weak_libs " $arg" + prev= + continue + ;; + xcclinker) + func_append linker_flags " $qarg" + func_append compiler_flags " $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xcompiler) + func_append compiler_flags " $qarg" + prev= + func_append compile_command " $qarg" + func_append finalize_command " $qarg" + continue + ;; + xlinker) + func_append linker_flags " $qarg" + func_append compiler_flags " $wl$qarg" + prev= + func_append compile_command " $wl$qarg" + func_append finalize_command " $wl$qarg" + continue + ;; + *) + eval "$prev=\"\$arg\"" + prev= + continue + ;; + esac + fi # test -n "$prev" + + prevarg=$arg + + case $arg in + -all-static) + if test -n "$link_static_flag"; then + # See comment for -static flag below, for more details. + func_append compile_command " $link_static_flag" + func_append finalize_command " $link_static_flag" + fi + continue + ;; + + -allow-undefined) + # FIXME: remove this flag sometime in the future. + func_fatal_error "'-allow-undefined' must not be used because it is the default" + ;; + + -avoid-version) + avoid_version=yes + continue + ;; + + -bindir) + prev=bindir + continue + ;; + + -dlopen) + prev=dlfiles + continue + ;; + + -dlpreopen) + prev=dlprefiles + continue + ;; + + -export-dynamic) + export_dynamic=yes + continue + ;; + + -export-symbols | -export-symbols-regex) + if test -n "$export_symbols" || test -n "$export_symbols_regex"; then + func_fatal_error "more than one -exported-symbols argument is not allowed" + fi + if test X-export-symbols = "X$arg"; then + prev=expsyms + else + prev=expsyms_regex + fi + continue + ;; + + -framework) + prev=framework + continue + ;; + + -inst-prefix-dir) + prev=inst_prefix + continue + ;; + + # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* + # so, if we see these flags be careful not to treat them like -L + -L[A-Z][A-Z]*:*) + case $with_gcc/$host in + no/*-*-irix* | /*-*-irix*) + func_append compile_command " $arg" + func_append finalize_command " $arg" + ;; + esac + continue + ;; + + -L*) + func_stripname "-L" '' "$arg" + if test -z "$func_stripname_result"; then + if test "$#" -gt 0; then + func_fatal_error "require no space between '-L' and '$1'" + else + func_fatal_error "need path for '-L' option" + fi + fi + func_resolve_sysroot "$func_stripname_result" + dir=$func_resolve_sysroot_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + *) + absdir=`cd "$dir" && pwd` + test -z "$absdir" && \ + func_fatal_error "cannot determine absolute directory name of '$dir'" + dir=$absdir + ;; + esac + case "$deplibs " in + *" -L$dir "* | *" $arg "*) + # Will only happen for absolute or sysroot arguments + ;; + *) + # Preserve sysroot, but never include relative directories + case $dir in + [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;; + *) func_append deplibs " -L$dir" ;; + esac + func_append lib_search_path " $dir" + ;; + esac + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$dir:"*) ;; + ::) dllsearchpath=$dir;; + *) func_append dllsearchpath ":$dir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) func_append dllsearchpath ":$testbindir";; + esac + ;; + esac + continue + ;; + + -l*) + if test X-lc = "X$arg" || test X-lm = "X$arg"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) + # These systems don't actually have a C or math library (as such) + continue + ;; + *-*-os2*) + # These systems don't actually have a C library (as such) + test X-lc = "X$arg" && continue + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + # Do not include libc due to us having libc/libc_r. + test X-lc = "X$arg" && continue + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C and math libraries are in the System framework + func_append deplibs " System.ltframework" + continue + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + test X-lc = "X$arg" && continue + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + test X-lc = "X$arg" && continue + ;; + esac + elif test X-lc_r = "X$arg"; then + case $host in + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + # Do not include libc_r directly, use -pthread flag. + continue + ;; + esac + fi + func_append deplibs " $arg" + continue + ;; + + -mllvm) + prev=mllvm + continue + ;; + + -module) + module=yes + continue + ;; + + # Tru64 UNIX uses -model [arg] to determine the layout of C++ + # classes, name mangling, and exception handling. + # Darwin uses the -arch flag to determine output architecture. + -model|-arch|-isysroot|--sysroot) + func_append compiler_flags " $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + prev=xcompiler + continue + ;; + + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + func_append compiler_flags " $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case "$new_inherited_linker_flags " in + *" $arg "*) ;; + * ) func_append new_inherited_linker_flags " $arg" ;; + esac + continue + ;; + + -multi_module) + single_module=$wl-multi_module + continue + ;; + + -no-fast-install) + fast_install=no + continue + ;; + + -no-install) + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) + # The PATH hackery in wrapper scripts is required on Windows + # and Darwin in order for the loader to find any dlls it needs. + func_warning "'-no-install' is ignored for $host" + func_warning "assuming '-no-fast-install' instead" + fast_install=no + ;; + *) no_install=yes ;; + esac + continue + ;; + + -no-undefined) + allow_undefined=no + continue + ;; + + -objectlist) + prev=objectlist + continue + ;; + + -os2dllname) + prev=os2dllname + continue + ;; + + -o) prev=output ;; + + -precious-files-regex) + prev=precious_regex + continue + ;; + + -release) + prev=release + continue + ;; + + -rpath) + prev=rpath + continue + ;; + + -R) + prev=xrpath + continue + ;; + + -R*) + func_stripname '-R' '' "$arg" + dir=$func_stripname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) ;; + =*) + func_stripname '=' '' "$dir" + dir=$lt_sysroot$func_stripname_result + ;; + *) + func_fatal_error "only absolute run-paths are allowed" + ;; + esac + case "$xrpath " in + *" $dir "*) ;; + *) func_append xrpath " $dir" ;; + esac + continue + ;; + + -shared) + # The effects of -shared are defined in a previous loop. + continue + ;; + + -shrext) + prev=shrext + continue + ;; + + -static | -static-libtool-libs) + # The effects of -static are defined in a previous loop. + # We used to do the same as -all-static on platforms that + # didn't have a PIC flag, but the assumption that the effects + # would be equivalent was wrong. It would break on at least + # Digital Unix and AIX. + continue + ;; + + -thread-safe) + thread_safe=yes + continue + ;; + + -version-info) + prev=vinfo + continue + ;; + + -version-number) + prev=vinfo + vinfo_number=yes + continue + ;; + + -weak) + prev=weak + continue + ;; + + -Wc,*) + func_stripname '-Wc,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs=$IFS; IFS=, + for flag in $args; do + IFS=$save_ifs + func_quote_for_eval "$flag" + func_append arg " $func_quote_for_eval_result" + func_append compiler_flags " $func_quote_for_eval_result" + done + IFS=$save_ifs + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Wl,*) + func_stripname '-Wl,' '' "$arg" + args=$func_stripname_result + arg= + save_ifs=$IFS; IFS=, + for flag in $args; do + IFS=$save_ifs + func_quote_for_eval "$flag" + func_append arg " $wl$func_quote_for_eval_result" + func_append compiler_flags " $wl$func_quote_for_eval_result" + func_append linker_flags " $func_quote_for_eval_result" + done + IFS=$save_ifs + func_stripname ' ' '' "$arg" + arg=$func_stripname_result + ;; + + -Xcompiler) + prev=xcompiler + continue + ;; + + -Xlinker) + prev=xlinker + continue + ;; + + -XCClinker) + prev=xcclinker + continue + ;; + + # -msg_* for osf cc + -msg_*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + + # Flags to be passed through unchanged, with rationale: + # -64, -mips[0-9] enable 64-bit mode for the SGI compiler + # -r[0-9][0-9]* specify processor for the SGI compiler + # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler + # +DA*, +DD* enable 64-bit mode for the HP compiler + # -q* compiler args for the IBM compiler + # -m*, -t[45]*, -txscale* architecture-specific flags for GCC + # -F/path path to uninstalled frameworks, gcc on darwin + # -p, -pg, --coverage, -fprofile-* profiling flags for GCC + # -fstack-protector* stack protector flags for GCC + # @file GCC response files + # -tp=* Portland pgcc target processor selection + # --sysroot=* for sysroot support + # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization + # -stdlib=* select c++ std lib with clang + -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ + -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + func_append compile_command " $arg" + func_append finalize_command " $arg" + func_append compiler_flags " $arg" + continue + ;; + + -Z*) + if test os2 = "`expr $host : '.*\(os2\)'`"; then + # OS/2 uses -Zxxx to specify OS/2-specific options + compiler_flags="$compiler_flags $arg" + func_append compile_command " $arg" + func_append finalize_command " $arg" + case $arg in + -Zlinker | -Zstack) + prev=xcompiler + ;; + esac + continue + else + # Otherwise treat like 'Some other compiler flag' below + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + fi + ;; + + # Some other compiler flag. + -* | +*) + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + + *.$objext) + # A standard object. + func_append objs " $arg" + ;; + + *.lo) + # A libtool-controlled object. + + # Check to see that this really is a libtool object. + if func_lalib_unsafe_p "$arg"; then + pic_object= + non_pic_object= + + # Read the .lo file + func_source "$arg" + + if test -z "$pic_object" || + test -z "$non_pic_object" || + test none = "$pic_object" && + test none = "$non_pic_object"; then + func_fatal_error "cannot find name of object for '$arg'" + fi + + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + test none = "$pic_object" || { + # Prepend the subdirectory the object is found in. + pic_object=$xdir$pic_object + + if test dlfiles = "$prev"; then + if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then + func_append dlfiles " $pic_object" + prev= + continue + else + # If libtool objects are unsupported, then we need to preload. + prev=dlprefiles + fi + fi + + # CHECK ME: I think I busted this. -Ossama + if test dlprefiles = "$prev"; then + # Preload the old-style object. + func_append dlprefiles " $pic_object" + prev= + fi + + # A PIC object. + func_append libobjs " $pic_object" + arg=$pic_object + } + + # Non-PIC object. + if test none != "$non_pic_object"; then + # Prepend the subdirectory the object is found in. + non_pic_object=$xdir$non_pic_object + + # A standard non-PIC object + func_append non_pic_objects " $non_pic_object" + if test -z "$pic_object" || test none = "$pic_object"; then + arg=$non_pic_object + fi + else + # If the PIC object exists, use it instead. + # $xdir was prepended to $pic_object above. + non_pic_object=$pic_object + func_append non_pic_objects " $non_pic_object" + fi + else + # Only an error if not doing a dry-run. + if $opt_dry_run; then + # Extract subdirectory from the argument. + func_dirname "$arg" "/" "" + xdir=$func_dirname_result + + func_lo2o "$arg" + pic_object=$xdir$objdir/$func_lo2o_result + non_pic_object=$xdir$func_lo2o_result + func_append libobjs " $pic_object" + func_append non_pic_objects " $non_pic_object" + else + func_fatal_error "'$arg' is not a valid libtool object" + fi + fi + ;; + + *.$libext) + # An archive. + func_append deplibs " $arg" + func_append old_deplibs " $arg" + continue + ;; + + *.la) + # A libtool-controlled library. + + func_resolve_sysroot "$arg" + if test dlfiles = "$prev"; then + # This library was specified with -dlopen. + func_append dlfiles " $func_resolve_sysroot_result" + prev= + elif test dlprefiles = "$prev"; then + # The library was specified with -dlpreopen. + func_append dlprefiles " $func_resolve_sysroot_result" + prev= + else + func_append deplibs " $func_resolve_sysroot_result" + fi + continue + ;; + + # Some other compiler argument. + *) + # Unknown arguments in both finalize_command and compile_command need + # to be aesthetically quoted because they are evaled later. + func_quote_for_eval "$arg" + arg=$func_quote_for_eval_result + ;; + esac # arg + + # Now actually substitute the argument into the commands. + if test -n "$arg"; then + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + done # argument parsing loop + + test -n "$prev" && \ + func_fatal_help "the '$prevarg' option requires an argument" + + if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then + eval arg=\"$export_dynamic_flag_spec\" + func_append compile_command " $arg" + func_append finalize_command " $arg" + fi + + oldlibs= + # calculate the name of the file, without its directory + func_basename "$output" + outputname=$func_basename_result + libobjs_save=$libobjs + + if test -n "$shlibpath_var"; then + # get the directories listed in $shlibpath_var + eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\` + else + shlib_search_path= + fi + eval sys_lib_search_path=\"$sys_lib_search_path_spec\" + eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" + + # Definition is injected by LT_CONFIG during libtool generation. + func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH" + + func_dirname "$output" "/" "" + output_objdir=$func_dirname_result$objdir + func_to_tool_file "$output_objdir/" + tool_output_objdir=$func_to_tool_file_result + # Create the object directory. + func_mkdir_p "$output_objdir" + + # Determine the type of output + case $output in + "") + func_fatal_help "you must specify an output file" + ;; + *.$libext) linkmode=oldlib ;; + *.lo | *.$objext) linkmode=obj ;; + *.la) linkmode=lib ;; + *) linkmode=prog ;; # Anything else should be a program. + esac + + specialdeplibs= + + libs= + # Find all interdependent deplibs by searching for libraries + # that are linked more than once (e.g. -la -lb -la) + for deplib in $deplibs; do + if $opt_preserve_dup_deps; then + case "$libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append libs " $deplib" + done + + if test lib = "$linkmode"; then + libs="$predeps $libs $compiler_lib_search_path $postdeps" + + # Compute libraries that are listed more than once in $predeps + # $postdeps and mark them as special (i.e., whose duplicates are + # not to be eliminated). + pre_post_deps= + if $opt_duplicate_compiler_generated_deps; then + for pre_post_dep in $predeps $postdeps; do + case "$pre_post_deps " in + *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;; + esac + func_append pre_post_deps " $pre_post_dep" + done + fi + pre_post_deps= + fi + + deplibs= + newdependency_libs= + newlib_search_path= + need_relink=no # whether we're linking any uninstalled libtool libraries + notinst_deplibs= # not-installed libtool libraries + notinst_path= # paths that contain not-installed libtool libraries + + case $linkmode in + lib) + passes="conv dlpreopen link" + for file in $dlfiles $dlprefiles; do + case $file in + *.la) ;; + *) + func_fatal_help "libraries can '-dlopen' only libtool libraries: $file" + ;; + esac + done + ;; + prog) + compile_deplibs= + finalize_deplibs= + alldeplibs=false + newdlfiles= + newdlprefiles= + passes="conv scan dlopen dlpreopen link" + ;; + *) passes="conv" + ;; + esac + + for pass in $passes; do + # The preopen pass in lib mode reverses $deplibs; put it back here + # so that -L comes before libs that need it for instance... + if test lib,link = "$linkmode,$pass"; then + ## FIXME: Find the place where the list is rebuilt in the wrong + ## order, and fix it there properly + tmp_deplibs= + for deplib in $deplibs; do + tmp_deplibs="$deplib $tmp_deplibs" + done + deplibs=$tmp_deplibs + fi + + if test lib,link = "$linkmode,$pass" || + test prog,scan = "$linkmode,$pass"; then + libs=$deplibs + deplibs= + fi + if test prog = "$linkmode"; then + case $pass in + dlopen) libs=$dlfiles ;; + dlpreopen) libs=$dlprefiles ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; + esac + fi + if test lib,dlpreopen = "$linkmode,$pass"; then + # Collect and forward deplibs of preopened libtool libs + for lib in $dlprefiles; do + # Ignore non-libtool-libs + dependency_libs= + func_resolve_sysroot "$lib" + case $lib in + *.la) func_source "$func_resolve_sysroot_result" ;; + esac + + # Collect preopened libtool deplibs, except any this library + # has declared as weak libs + for deplib in $dependency_libs; do + func_basename "$deplib" + deplib_base=$func_basename_result + case " $weak_libs " in + *" $deplib_base "*) ;; + *) func_append deplibs " $deplib" ;; + esac + done + done + libs=$dlprefiles + fi + if test dlopen = "$pass"; then + # Collect dlpreopened libraries + save_deplibs=$deplibs + deplibs= + fi + + for deplib in $libs; do + lib= + found=false + case $deplib in + -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + func_append compiler_flags " $deplib" + if test lib = "$linkmode"; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) func_append new_inherited_linker_flags " $deplib" ;; + esac + fi + fi + continue + ;; + -l*) + if test lib != "$linkmode" && test prog != "$linkmode"; then + func_warning "'-l' is ignored for archives/objects" + continue + fi + func_stripname '-l' '' "$deplib" + name=$func_stripname_result + if test lib = "$linkmode"; then + searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" + else + searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" + fi + for searchdir in $searchdirs; do + for search_ext in .la $std_shrext .so .a; do + # Search the libtool library + lib=$searchdir/lib$name$search_ext + if test -f "$lib"; then + if test .la = "$search_ext"; then + found=: + else + found=false + fi + break 2 + fi + done + done + if $found; then + # deplib is a libtool library + # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, + # We need to do some special things here, and not later. + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + case " $predeps $postdeps " in + *" $deplib "*) + if func_lalib_p "$lib"; then + library_names= + old_library= + func_source "$lib" + for l in $old_library $library_names; do + ll=$l + done + if test "X$ll" = "X$old_library"; then # only static version available + found=false + func_dirname "$lib" "" "." + ladir=$func_dirname_result + lib=$ladir/$old_library + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + fi + ;; + *) ;; + esac + fi + else + # deplib doesn't seem to be a libtool library + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs" + fi + continue + fi + ;; # -l + *.ltframework) + if test prog,link = "$linkmode,$pass"; then + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + deplibs="$deplib $deplibs" + if test lib = "$linkmode"; then + case "$new_inherited_linker_flags " in + *" $deplib "*) ;; + * ) func_append new_inherited_linker_flags " $deplib" ;; + esac + fi + fi + continue + ;; + -L*) + case $linkmode in + lib) + deplibs="$deplib $deplibs" + test conv = "$pass" && continue + newdependency_libs="$deplib $newdependency_libs" + func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + prog) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + continue + fi + if test scan = "$pass"; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + *) + func_warning "'-L' is ignored for archives/objects" + ;; + esac # linkmode + continue + ;; # -L + -R*) + if test link = "$pass"; then + func_stripname '-R' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + dir=$func_resolve_sysroot_result + # Make sure the xrpath contains only unique directories. + case "$xrpath " in + *" $dir "*) ;; + *) func_append xrpath " $dir" ;; + esac + fi + deplibs="$deplib $deplibs" + continue + ;; + *.la) + func_resolve_sysroot "$deplib" + lib=$func_resolve_sysroot_result + ;; + *.$libext) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + continue + fi + case $linkmode in + lib) + # Linking convenience modules into shared libraries is allowed, + # but linking other static libraries is non-portable. + case " $dlpreconveniencelibs " in + *" $deplib "*) ;; + *) + valid_a_lib=false + case $deplibs_check_method in + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \ + | $EGREP "$match_pattern_regex" > /dev/null; then + valid_a_lib=: + fi + ;; + pass_all) + valid_a_lib=: + ;; + esac + if $valid_a_lib; then + echo + $ECHO "*** Warning: Linking the shared library $output against the" + $ECHO "*** static library $deplib is not portable!" + deplibs="$deplib $deplibs" + else + echo + $ECHO "*** Warning: Trying to link with static lib archive $deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because the file extensions .$libext of this argument makes me believe" + echo "*** that it is just a static archive that I should not use here." + fi + ;; + esac + continue + ;; + prog) + if test link != "$pass"; then + deplibs="$deplib $deplibs" + else + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + fi + continue + ;; + esac # linkmode + ;; # *.$libext + *.lo | *.$objext) + if test conv = "$pass"; then + deplibs="$deplib $deplibs" + elif test prog = "$linkmode"; then + if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then + # If there is no dlopen support or we're linking statically, + # we need to preload. + func_append newdlprefiles " $deplib" + compile_deplibs="$deplib $compile_deplibs" + finalize_deplibs="$deplib $finalize_deplibs" + else + func_append newdlfiles " $deplib" + fi + fi + continue + ;; + %DEPLIBS%) + alldeplibs=: + continue + ;; + esac # case $deplib + + $found || test -f "$lib" \ + || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'" + + # Check to see that this really is a libtool archive. + func_lalib_unsafe_p "$lib" \ + || func_fatal_error "'$lib' is not a valid libtool archive" + + func_dirname "$lib" "" "." + ladir=$func_dirname_result + + dlname= + dlopen= + dlpreopen= + libdir= + library_names= + old_library= + inherited_linker_flags= + # If the library was installed with an old release of libtool, + # it will not redefine variables installed, or shouldnotlink + installed=yes + shouldnotlink=no + avoidtemprpath= + + + # Read the .la file + func_source "$lib" + + # Convert "-framework foo" to "foo.ltframework" + if test -n "$inherited_linker_flags"; then + tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'` + for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do + case " $new_inherited_linker_flags " in + *" $tmp_inherited_linker_flag "*) ;; + *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";; + esac + done + fi + dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + if test lib,link = "$linkmode,$pass" || + test prog,scan = "$linkmode,$pass" || + { test prog != "$linkmode" && test lib != "$linkmode"; }; then + test -n "$dlopen" && func_append dlfiles " $dlopen" + test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen" + fi + + if test conv = "$pass"; then + # Only check for convenience libraries + deplibs="$lib $deplibs" + if test -z "$libdir"; then + if test -z "$old_library"; then + func_fatal_error "cannot find name of link library for '$lib'" + fi + # It is a libtool convenience library, so add in its objects. + func_append convenience " $ladir/$objdir/$old_library" + func_append old_convenience " $ladir/$objdir/$old_library" + elif test prog != "$linkmode" && test lib != "$linkmode"; then + func_fatal_error "'$lib' is not a convenience library" + fi + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done + continue + fi # $pass = conv + + + # Get the name of the library we link against. + linklib= + if test -n "$old_library" && + { test yes = "$prefer_static_libs" || + test built,no = "$prefer_static_libs,$installed"; }; then + linklib=$old_library + else + for l in $old_library $library_names; do + linklib=$l + done + fi + if test -z "$linklib"; then + func_fatal_error "cannot find name of link library for '$lib'" + fi + + # This library was specified with -dlopen. + if test dlopen = "$pass"; then + test -z "$libdir" \ + && func_fatal_error "cannot -dlopen a convenience library: '$lib'" + if test -z "$dlname" || + test yes != "$dlopen_support" || + test no = "$build_libtool_libs" + then + # If there is no dlname, no dlopen support or we're linking + # statically, we need to preload. We also need to preload any + # dependent libraries so libltdl's deplib preloader doesn't + # bomb out in the load deplibs phase. + func_append dlprefiles " $lib $dependency_libs" + else + func_append newdlfiles " $lib" + fi + continue + fi # $pass = dlopen + + # We need an absolute path. + case $ladir in + [\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;; + *) + abs_ladir=`cd "$ladir" && pwd` + if test -z "$abs_ladir"; then + func_warning "cannot determine absolute directory name of '$ladir'" + func_warning "passing it literally to the linker, although it might fail" + abs_ladir=$ladir + fi + ;; + esac + func_basename "$lib" + laname=$func_basename_result + + # Find the relevant object directory and library name. + if test yes = "$installed"; then + if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then + func_warning "library '$lib' was moved." + dir=$ladir + absdir=$abs_ladir + libdir=$abs_ladir + else + dir=$lt_sysroot$libdir + absdir=$lt_sysroot$libdir + fi + test yes = "$hardcode_automatic" && avoidtemprpath=yes + else + if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then + dir=$ladir + absdir=$abs_ladir + # Remove this search path later + func_append notinst_path " $abs_ladir" + else + dir=$ladir/$objdir + absdir=$abs_ladir/$objdir + # Remove this search path later + func_append notinst_path " $abs_ladir" + fi + fi # $installed = yes + func_stripname 'lib' '.la' "$laname" + name=$func_stripname_result + + # This library was specified with -dlpreopen. + if test dlpreopen = "$pass"; then + if test -z "$libdir" && test prog = "$linkmode"; then + func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'" + fi + case $host in + # special handling for platforms with PE-DLLs. + *cygwin* | *mingw* | *cegcc* ) + # Linker will automatically link against shared library if both + # static and shared are present. Therefore, ensure we extract + # symbols from the import library if a shared library is present + # (otherwise, the dlopen module name will be incorrect). We do + # this by putting the import library name into $newdlprefiles. + # We recover the dlopen module name by 'saving' the la file + # name in a special purpose variable, and (later) extracting the + # dlname from the la file. + if test -n "$dlname"; then + func_tr_sh "$dir/$linklib" + eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname" + func_append newdlprefiles " $dir/$linklib" + else + func_append newdlprefiles " $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + func_append dlpreconveniencelibs " $dir/$old_library" + fi + ;; + * ) + # Prefer using a static library (so that no silly _DYNAMIC symbols + # are required to link). + if test -n "$old_library"; then + func_append newdlprefiles " $dir/$old_library" + # Keep a list of preopened convenience libraries to check + # that they are being used correctly in the link pass. + test -z "$libdir" && \ + func_append dlpreconveniencelibs " $dir/$old_library" + # Otherwise, use the dlname, so that lt_dlopen finds it. + elif test -n "$dlname"; then + func_append newdlprefiles " $dir/$dlname" + else + func_append newdlprefiles " $dir/$linklib" + fi + ;; + esac + fi # $pass = dlpreopen + + if test -z "$libdir"; then + # Link the convenience library + if test lib = "$linkmode"; then + deplibs="$dir/$old_library $deplibs" + elif test prog,link = "$linkmode,$pass"; then + compile_deplibs="$dir/$old_library $compile_deplibs" + finalize_deplibs="$dir/$old_library $finalize_deplibs" + else + deplibs="$lib $deplibs" # used for prog,scan pass + fi + continue + fi + + + if test prog = "$linkmode" && test link != "$pass"; then + func_append newlib_search_path " $ladir" + deplibs="$lib $deplibs" + + linkalldeplibs=false + if test no != "$link_all_deplibs" || test -z "$library_names" || + test no = "$build_libtool_libs"; then + linkalldeplibs=: + fi + + tmp_libs= + for deplib in $dependency_libs; do + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result" + func_append newlib_search_path " $func_resolve_sysroot_result" + ;; + esac + # Need to link against all dependency_libs? + if $linkalldeplibs; then + deplibs="$deplib $deplibs" + else + # Need to hardcode shared library paths + # or/and link against static libraries + newdependency_libs="$deplib $newdependency_libs" + fi + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done # for deplib + continue + fi # $linkmode = prog... + + if test prog,link = "$linkmode,$pass"; then + if test -n "$library_names" && + { { test no = "$prefer_static_libs" || + test built,yes = "$prefer_static_libs,$installed"; } || + test -z "$old_library"; }; then + # We need to hardcode the library path + if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then + # Make sure the rpath contains only unique directories. + case $temp_rpath: in + *"$absdir:"*) ;; + *) func_append temp_rpath "$absdir:" ;; + esac + fi + + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) func_append compile_rpath " $absdir" ;; + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + ;; + esac + fi # $linkmode,$pass = prog,link... + + if $alldeplibs && + { test pass_all = "$deplibs_check_method" || + { test yes = "$build_libtool_libs" && + test -n "$library_names"; }; }; then + # We only need to search for static libraries + continue + fi + fi + + link_static=no # Whether the deplib will be linked statically + use_static_libs=$prefer_static_libs + if test built = "$use_static_libs" && test yes = "$installed"; then + use_static_libs=no + fi + if test -n "$library_names" && + { test no = "$use_static_libs" || test -z "$old_library"; }; then + case $host in + *cygwin* | *mingw* | *cegcc* | *os2*) + # No point in relinking DLLs because paths are not encoded + func_append notinst_deplibs " $lib" + need_relink=no + ;; + *) + if test no = "$installed"; then + func_append notinst_deplibs " $lib" + need_relink=yes + fi + ;; + esac + # This is a shared library + + # Warn about portability, can't link against -module's on some + # systems (darwin). Don't bleat about dlopened modules though! + dlopenmodule= + for dlpremoduletest in $dlprefiles; do + if test "X$dlpremoduletest" = "X$lib"; then + dlopenmodule=$dlpremoduletest + break + fi + done + if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then + echo + if test prog = "$linkmode"; then + $ECHO "*** Warning: Linking the executable $output against the loadable module" + else + $ECHO "*** Warning: Linking the shared library $output against the loadable module" + fi + $ECHO "*** $linklib is not portable!" + fi + if test lib = "$linkmode" && + test yes = "$hardcode_into_libs"; then + # Hardcode the library path. + # Skip directories that are in the system default run-time + # search path. + case " $sys_lib_dlsearch_path " in + *" $absdir "*) ;; + *) + case "$compile_rpath " in + *" $absdir "*) ;; + *) func_append compile_rpath " $absdir" ;; + esac + ;; + esac + case " $sys_lib_dlsearch_path " in + *" $libdir "*) ;; + *) + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + ;; + esac + fi + + if test -n "$old_archive_from_expsyms_cmds"; then + # figure out the soname + set dummy $library_names + shift + realname=$1 + shift + libname=`eval "\\$ECHO \"$libname_spec\""` + # use dlname if we got it. it's perfectly good, no? + if test -n "$dlname"; then + soname=$dlname + elif test -n "$soname_spec"; then + # bleh windows + case $host in + *cygwin* | mingw* | *cegcc* | *os2*) + func_arith $current - $age + major=$func_arith_result + versuffix=-$major + ;; + esac + eval soname=\"$soname_spec\" + else + soname=$realname + fi + + # Make a new name for the extract_expsyms_cmds to use + soroot=$soname + func_basename "$soroot" + soname=$func_basename_result + func_stripname 'lib' '.dll' "$soname" + newlib=libimp-$func_stripname_result.a + + # If the library has no export list, then create one now + if test -f "$output_objdir/$soname-def"; then : + else + func_verbose "extracting exported symbol list from '$soname'" + func_execute_cmds "$extract_expsyms_cmds" 'exit $?' + fi + + # Create $newlib + if test -f "$output_objdir/$newlib"; then :; else + func_verbose "generating import library for '$soname'" + func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?' + fi + # make sure the library variables are pointing to the new library + dir=$output_objdir + linklib=$newlib + fi # test -n "$old_archive_from_expsyms_cmds" + + if test prog = "$linkmode" || test relink != "$opt_mode"; then + add_shlibpath= + add_dir= + add= + lib_linked=yes + case $hardcode_action in + immediate | unsupported) + if test no = "$hardcode_direct"; then + add=$dir/$linklib + case $host in + *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;; + *-*-sysv4*uw2*) add_dir=-L$dir ;; + *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ + *-*-unixware7*) add_dir=-L$dir ;; + *-*-darwin* ) + # if the lib is a (non-dlopened) module then we cannot + # link against it, someone is ignoring the earlier warnings + if /usr/bin/file -L $add 2> /dev/null | + $GREP ": [^:]* bundle" >/dev/null; then + if test "X$dlopenmodule" != "X$lib"; then + $ECHO "*** Warning: lib $linklib is a module, not a shared library" + if test -z "$old_library"; then + echo + echo "*** And there doesn't seem to be a static archive available" + echo "*** The link will probably fail, sorry" + else + add=$dir/$old_library + fi + elif test -n "$old_library"; then + add=$dir/$old_library + fi + fi + esac + elif test no = "$hardcode_minus_L"; then + case $host in + *-*-sunos*) add_shlibpath=$dir ;; + esac + add_dir=-L$dir + add=-l$name + elif test no = "$hardcode_shlibpath_var"; then + add_shlibpath=$dir + add=-l$name + else + lib_linked=no + fi + ;; + relink) + if test yes = "$hardcode_direct" && + test no = "$hardcode_direct_absolute"; then + add=$dir/$linklib + elif test yes = "$hardcode_minus_L"; then + add_dir=-L$absdir + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + func_append add_dir " -L$inst_prefix_dir$libdir" + ;; + esac + fi + add=-l$name + elif test yes = "$hardcode_shlibpath_var"; then + add_shlibpath=$dir + add=-l$name + else + lib_linked=no + fi + ;; + *) lib_linked=no ;; + esac + + if test yes != "$lib_linked"; then + func_fatal_configuration "unsupported hardcode properties" + fi + + if test -n "$add_shlibpath"; then + case :$compile_shlibpath: in + *":$add_shlibpath:"*) ;; + *) func_append compile_shlibpath "$add_shlibpath:" ;; + esac + fi + if test prog = "$linkmode"; then + test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" + test -n "$add" && compile_deplibs="$add $compile_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + if test yes != "$hardcode_direct" && + test yes != "$hardcode_minus_L" && + test yes = "$hardcode_shlibpath_var"; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) func_append finalize_shlibpath "$libdir:" ;; + esac + fi + fi + fi + + if test prog = "$linkmode" || test relink = "$opt_mode"; then + add_shlibpath= + add_dir= + add= + # Finalize command for both is simple: just hardcode it. + if test yes = "$hardcode_direct" && + test no = "$hardcode_direct_absolute"; then + add=$libdir/$linklib + elif test yes = "$hardcode_minus_L"; then + add_dir=-L$libdir + add=-l$name + elif test yes = "$hardcode_shlibpath_var"; then + case :$finalize_shlibpath: in + *":$libdir:"*) ;; + *) func_append finalize_shlibpath "$libdir:" ;; + esac + add=-l$name + elif test yes = "$hardcode_automatic"; then + if test -n "$inst_prefix_dir" && + test -f "$inst_prefix_dir$libdir/$linklib"; then + add=$inst_prefix_dir$libdir/$linklib + else + add=$libdir/$linklib + fi + else + # We cannot seem to hardcode it, guess we'll fake it. + add_dir=-L$libdir + # Try looking first in the location we're being installed to. + if test -n "$inst_prefix_dir"; then + case $libdir in + [\\/]*) + func_append add_dir " -L$inst_prefix_dir$libdir" + ;; + esac + fi + add=-l$name + fi + + if test prog = "$linkmode"; then + test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" + test -n "$add" && finalize_deplibs="$add $finalize_deplibs" + else + test -n "$add_dir" && deplibs="$add_dir $deplibs" + test -n "$add" && deplibs="$add $deplibs" + fi + fi + elif test prog = "$linkmode"; then + # Here we assume that one of hardcode_direct or hardcode_minus_L + # is not unsupported. This is valid on all known static and + # shared platforms. + if test unsupported != "$hardcode_direct"; then + test -n "$old_library" && linklib=$old_library + compile_deplibs="$dir/$linklib $compile_deplibs" + finalize_deplibs="$dir/$linklib $finalize_deplibs" + else + compile_deplibs="-l$name -L$dir $compile_deplibs" + finalize_deplibs="-l$name -L$dir $finalize_deplibs" + fi + elif test yes = "$build_libtool_libs"; then + # Not a shared library + if test pass_all != "$deplibs_check_method"; then + # We're trying link a shared library against a static one + # but the system doesn't support it. + + # Just print a warning and add the library to dependency_libs so + # that the program can be linked against the static library. + echo + $ECHO "*** Warning: This system cannot link to static lib archive $lib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have." + if test yes = "$module"; then + echo "*** But as you try to build a module library, libtool will still create " + echo "*** a static module, that should work as long as the dlopening application" + echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + if test -z "$global_symbol_pipe"; then + echo + echo "*** However, this would only work if libtool was able to extract symbol" + echo "*** lists from a program, using 'nm' or equivalent, but libtool could" + echo "*** not find such a program. So, this module is probably useless." + echo "*** 'nm' from GNU binutils and a full rebuild may help." + fi + if test no = "$build_old_libs"; then + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + else + deplibs="$dir/$old_library $deplibs" + link_static=yes + fi + fi # link shared/static library? + + if test lib = "$linkmode"; then + if test -n "$dependency_libs" && + { test yes != "$hardcode_into_libs" || + test yes = "$build_old_libs" || + test yes = "$link_static"; }; then + # Extract -R from dependency_libs + temp_deplibs= + for libdir in $dependency_libs; do + case $libdir in + -R*) func_stripname '-R' '' "$libdir" + temp_xrpath=$func_stripname_result + case " $xrpath " in + *" $temp_xrpath "*) ;; + *) func_append xrpath " $temp_xrpath";; + esac;; + *) func_append temp_deplibs " $libdir";; + esac + done + dependency_libs=$temp_deplibs + fi + + func_append newlib_search_path " $absdir" + # Link against this library + test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs" + # ... and its dependency_libs + tmp_libs= + for deplib in $dependency_libs; do + newdependency_libs="$deplib $newdependency_libs" + case $deplib in + -L*) func_stripname '-L' '' "$deplib" + func_resolve_sysroot "$func_stripname_result";; + *) func_resolve_sysroot "$deplib" ;; + esac + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $func_resolve_sysroot_result "*) + func_append specialdeplibs " $func_resolve_sysroot_result" ;; + esac + fi + func_append tmp_libs " $func_resolve_sysroot_result" + done + + if test no != "$link_all_deplibs"; then + # Add the search paths of all dependency libraries + for deplib in $dependency_libs; do + path= + case $deplib in + -L*) path=$deplib ;; + *.la) + func_resolve_sysroot "$deplib" + deplib=$func_resolve_sysroot_result + func_dirname "$deplib" "" "." + dir=$func_dirname_result + # We need an absolute path. + case $dir in + [\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;; + *) + absdir=`cd "$dir" && pwd` + if test -z "$absdir"; then + func_warning "cannot determine absolute directory name of '$dir'" + absdir=$dir + fi + ;; + esac + if $GREP "^installed=no" $deplib > /dev/null; then + case $host in + *-*-darwin*) + depdepl= + eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` + if test -n "$deplibrary_names"; then + for tmp in $deplibrary_names; do + depdepl=$tmp + done + if test -f "$absdir/$objdir/$depdepl"; then + depdepl=$absdir/$objdir/$depdepl + darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + if test -z "$darwin_install_name"; then + darwin_install_name=`$OTOOL64 -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` + fi + func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl" + func_append linker_flags " -dylib_file $darwin_install_name:$depdepl" + path= + fi + fi + ;; + *) + path=-L$absdir/$objdir + ;; + esac + else + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" + test "$absdir" != "$libdir" && \ + func_warning "'$deplib' seems to be moved" + + path=-L$absdir + fi + ;; + esac + case " $deplibs " in + *" $path "*) ;; + *) deplibs="$path $deplibs" ;; + esac + done + fi # link_all_deplibs != no + fi # linkmode = lib + done # for deplib in $libs + if test link = "$pass"; then + if test prog = "$linkmode"; then + compile_deplibs="$new_inherited_linker_flags $compile_deplibs" + finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs" + else + compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + fi + fi + dependency_libs=$newdependency_libs + if test dlpreopen = "$pass"; then + # Link the dlpreopened libraries before other libraries + for deplib in $save_deplibs; do + deplibs="$deplib $deplibs" + done + fi + if test dlopen != "$pass"; then + test conv = "$pass" || { + # Make sure lib_search_path contains only unique directories. + lib_search_path= + for dir in $newlib_search_path; do + case "$lib_search_path " in + *" $dir "*) ;; + *) func_append lib_search_path " $dir" ;; + esac + done + newlib_search_path= + } + + if test prog,link = "$linkmode,$pass"; then + vars="compile_deplibs finalize_deplibs" + else + vars=deplibs + fi + for var in $vars dependency_libs; do + # Add libraries to $var in reverse order + eval tmp_libs=\"\$$var\" + new_libs= + for deplib in $tmp_libs; do + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: + #new_libs="$deplib $new_libs" + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; + *) + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; + esac + done + tmp_libs= + for deplib in $new_libs; do + case $deplib in + -L*) + case " $tmp_libs " in + *" $deplib "*) ;; + *) func_append tmp_libs " $deplib" ;; + esac + ;; + *) func_append tmp_libs " $deplib" ;; + esac + done + eval $var=\"$tmp_libs\" + done # for var + fi + + # Add Sun CC postdeps if required: + test CXX = "$tagname" && { + case $host_os in + linux*) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C++ 5.9 + func_suncc_cstd_abi + + if test no != "$suncc_use_cstd_abi"; then + func_append postdeps ' -library=Cstd -library=Crun' + fi + ;; + esac + ;; + + solaris*) + func_cc_basename "$CC" + case $func_cc_basename_result in + CC* | sunCC*) + func_suncc_cstd_abi + + if test no != "$suncc_use_cstd_abi"; then + func_append postdeps ' -library=Cstd -library=Crun' + fi + ;; + esac + ;; + esac + } + + # Last step: remove runtime libs from dependency_libs + # (they stay in deplibs) + tmp_libs= + for i in $dependency_libs; do + case " $predeps $postdeps $compiler_lib_search_path " in + *" $i "*) + i= + ;; + esac + if test -n "$i"; then + func_append tmp_libs " $i" + fi + done + dependency_libs=$tmp_libs + done # for pass + if test prog = "$linkmode"; then + dlfiles=$newdlfiles + fi + if test prog = "$linkmode" || test lib = "$linkmode"; then + dlprefiles=$newdlprefiles + fi + + case $linkmode in + oldlib) + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + func_warning "'-dlopen' is ignored for archives" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "'-l' and '-L' are ignored for archives" ;; + esac + + test -n "$rpath" && \ + func_warning "'-rpath' is ignored for archives" + + test -n "$xrpath" && \ + func_warning "'-R' is ignored for archives" + + test -n "$vinfo" && \ + func_warning "'-version-info/-version-number' is ignored for archives" + + test -n "$release" && \ + func_warning "'-release' is ignored for archives" + + test -n "$export_symbols$export_symbols_regex" && \ + func_warning "'-export-symbols' is ignored for archives" + + # Now set the variables for building old libraries. + build_libtool_libs=no + oldlibs=$output + func_append objs "$old_deplibs" + ;; + + lib) + # Make sure we only generate libraries of the form 'libNAME.la'. + case $outputname in + lib*) + func_stripname 'lib' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + ;; + *) + test no = "$module" \ + && func_fatal_help "libtool library '$output' must begin with 'lib'" + + if test no != "$need_lib_prefix"; then + # Add the "lib" prefix for modules if required + func_stripname '' '.la' "$outputname" + name=$func_stripname_result + eval shared_ext=\"$shrext_cmds\" + eval libname=\"$libname_spec\" + else + func_stripname '' '.la' "$outputname" + libname=$func_stripname_result + fi + ;; + esac + + if test -n "$objs"; then + if test pass_all != "$deplibs_check_method"; then + func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs" + else + echo + $ECHO "*** Warning: Linking the shared library $output against the non-libtool" + $ECHO "*** objects $objs is not portable!" + func_append libobjs " $objs" + fi + fi + + test no = "$dlself" \ + || func_warning "'-dlopen self' is ignored for libtool libraries" + + set dummy $rpath + shift + test 1 -lt "$#" \ + && func_warning "ignoring multiple '-rpath's for a libtool library" + + install_libdir=$1 + + oldlibs= + if test -z "$rpath"; then + if test yes = "$build_libtool_libs"; then + # Building a libtool convenience library. + # Some compilers have problems with a '.al' extension so + # convenience libraries should have the same extension an + # archive normally would. + oldlibs="$output_objdir/$libname.$libext $oldlibs" + build_libtool_libs=convenience + build_old_libs=yes + fi + + test -n "$vinfo" && \ + func_warning "'-version-info/-version-number' is ignored for convenience libraries" + + test -n "$release" && \ + func_warning "'-release' is ignored for convenience libraries" + else + + # Parse the version information argument. + save_ifs=$IFS; IFS=: + set dummy $vinfo 0 0 0 + shift + IFS=$save_ifs + + test -n "$7" && \ + func_fatal_help "too many parameters to '-version-info'" + + # convert absolute version numbers to libtool ages + # this retains compatibility with .la files and attempts + # to make the code below a bit more comprehensible + + case $vinfo_number in + yes) + number_major=$1 + number_minor=$2 + number_revision=$3 + # + # There are really only two kinds -- those that + # use the current revision as the major version + # and those that subtract age and use age as + # a minor version. But, then there is irix + # that has an extra 1 added just for fun + # + case $version_type in + # correct linux to gnu/linux during the next big refactor + darwin|freebsd-elf|linux|osf|windows|none) + func_arith $number_major + $number_minor + current=$func_arith_result + age=$number_minor + revision=$number_revision + ;; + freebsd-aout|qnx|sunos) + current=$number_major + revision=$number_minor + age=0 + ;; + irix|nonstopux) + func_arith $number_major + $number_minor + current=$func_arith_result + age=$number_minor + revision=$number_minor + lt_irix_increment=no + ;; + esac + ;; + no) + current=$1 + revision=$2 + age=$3 + ;; + esac + + # Check that each of the things are valid numbers. + case $current in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "CURRENT '$current' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + case $revision in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "REVISION '$revision' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + case $age in + 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; + *) + func_error "AGE '$age' must be a nonnegative integer" + func_fatal_error "'$vinfo' is not valid version information" + ;; + esac + + if test "$age" -gt "$current"; then + func_error "AGE '$age' is greater than the current interface number '$current'" + func_fatal_error "'$vinfo' is not valid version information" + fi + + # Calculate the version variables. + major= + versuffix= + verstring= + case $version_type in + none) ;; + + darwin) + # Like Linux, but with the current version available in + # verstring for coding it into the library header + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + # Darwin ld doesn't like 0 for these options... + func_arith $current + 1 + minor_current=$func_arith_result + xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision" + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + # On Darwin other compilers + case $CC in + nagfor*) + verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision" + ;; + *) + verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" + ;; + esac + ;; + + freebsd-aout) + major=.$current + versuffix=.$current.$revision + ;; + + freebsd-elf) + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + ;; + + irix | nonstopux) + if test no = "$lt_irix_increment"; then + func_arith $current - $age + else + func_arith $current - $age + 1 + fi + major=$func_arith_result + + case $version_type in + nonstopux) verstring_prefix=nonstopux ;; + *) verstring_prefix=sgi ;; + esac + verstring=$verstring_prefix$major.$revision + + # Add in all the interfaces that we are compatible with. + loop=$revision + while test 0 -ne "$loop"; do + func_arith $revision - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring=$verstring_prefix$major.$iface:$verstring + done + + # Before this point, $major must not contain '.'. + major=.$major + versuffix=$major.$revision + ;; + + linux) # correct to gnu/linux during the next big refactor + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision + ;; + + osf) + func_arith $current - $age + major=.$func_arith_result + versuffix=.$current.$age.$revision + verstring=$current.$age.$revision + + # Add in all the interfaces that we are compatible with. + loop=$age + while test 0 -ne "$loop"; do + func_arith $current - $loop + iface=$func_arith_result + func_arith $loop - 1 + loop=$func_arith_result + verstring=$verstring:$iface.0 + done + + # Make executables depend on our current version. + func_append verstring ":$current.0" + ;; + + qnx) + major=.$current + versuffix=.$current + ;; + + sco) + major=.$current + versuffix=.$current + ;; + + sunos) + major=.$current + versuffix=.$current.$revision + ;; + + windows) + # Use '-' rather than '.', since we only want one + # extension on DOS 8.3 file systems. + func_arith $current - $age + major=$func_arith_result + versuffix=-$major + ;; + + *) + func_fatal_configuration "unknown library version type '$version_type'" + ;; + esac + + # Clear the version info if we defaulted, and they specified a release. + if test -z "$vinfo" && test -n "$release"; then + major= + case $version_type in + darwin) + # we can't check for "0.0" in archive_cmds due to quoting + # problems, so we reset it completely + verstring= + ;; + *) + verstring=0.0 + ;; + esac + if test no = "$need_version"; then + versuffix= + else + versuffix=.0.0 + fi + fi + + # Remove version info from name if versioning should be avoided + if test yes,no = "$avoid_version,$need_version"; then + major= + versuffix= + verstring= + fi + + # Check to see if the archive will have undefined symbols. + if test yes = "$allow_undefined"; then + if test unsupported = "$allow_undefined_flag"; then + if test yes = "$build_old_libs"; then + func_warning "undefined symbols not allowed in $host shared libraries; building static only" + build_libtool_libs=no + else + func_fatal_error "can't build $host shared library unless -no-undefined is specified" + fi + fi + else + # Don't allow undefined symbols. + allow_undefined_flag=$no_undefined_flag + fi + + fi + + func_generate_dlsyms "$libname" "$libname" : + func_append libobjs " $symfileobj" + test " " = "$libobjs" && libobjs= + + if test relink != "$opt_mode"; then + # Remove our outputs, but don't remove object files since they + # may have been created when compiling PIC objects. + removelist= + tempremovelist=`$ECHO "$output_objdir/*"` + for p in $tempremovelist; do + case $p in + *.$objext | *.gcno) + ;; + $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*) + if test -n "$precious_files_regex"; then + if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 + then + continue + fi + fi + func_append removelist " $p" + ;; + *) ;; + esac + done + test -n "$removelist" && \ + func_show_eval "${RM}r \$removelist" + fi + + # Now set the variables for building old libraries. + if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then + func_append oldlibs " $output_objdir/$libname.$libext" + + # Transform .lo files to .o files. + oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP` + fi + + # Eliminate all temporary directories. + #for path in $notinst_path; do + # lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"` + # deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"` + # dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"` + #done + + if test -n "$xrpath"; then + # If the user specified any rpath flags, then add them. + temp_xrpath= + for libdir in $xrpath; do + func_replace_sysroot "$libdir" + func_append temp_xrpath " -R$func_replace_sysroot_result" + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + done + if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then + dependency_libs="$temp_xrpath $dependency_libs" + fi + fi + + # Make sure dlfiles contains only unique files that won't be dlpreopened + old_dlfiles=$dlfiles + dlfiles= + for lib in $old_dlfiles; do + case " $dlprefiles $dlfiles " in + *" $lib "*) ;; + *) func_append dlfiles " $lib" ;; + esac + done + + # Make sure dlprefiles contains only unique files + old_dlprefiles=$dlprefiles + dlprefiles= + for lib in $old_dlprefiles; do + case "$dlprefiles " in + *" $lib "*) ;; + *) func_append dlprefiles " $lib" ;; + esac + done + + if test yes = "$build_libtool_libs"; then + if test -n "$rpath"; then + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) + # these systems don't actually have a c library (as such)! + ;; + *-*-rhapsody* | *-*-darwin1.[012]) + # Rhapsody C library is in the System framework + func_append deplibs " System.ltframework" + ;; + *-*-netbsd*) + # Don't link with libc until the a.out ld.so is fixed. + ;; + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + # Do not include libc due to us having libc/libc_r. + ;; + *-*-sco3.2v5* | *-*-sco5v6*) + # Causes problems with __ctype + ;; + *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) + # Compiler inserts libc in the correct place for threads to work + ;; + *) + # Add libc to deplibs on all other systems if necessary. + if test yes = "$build_libtool_need_lc"; then + func_append deplibs " -lc" + fi + ;; + esac + fi + + # Transform deplibs into only deplibs that can be linked in shared. + name_save=$name + libname_save=$libname + release_save=$release + versuffix_save=$versuffix + major_save=$major + # I'm not sure if I'm treating the release correctly. I think + # release should show up in the -l (ie -lgmp5) so we don't want to + # add it in twice. Is that correct? + release= + versuffix= + major= + newdeplibs= + droppeddeps=no + case $deplibs_check_method in + pass_all) + # Don't check for shared/static. Everything works. + # This might be a little naive. We might want to check + # whether the library exists or not. But this is on + # osf3 & osf4 and I'm not really sure... Just + # implementing what was already the behavior. + newdeplibs=$deplibs + ;; + test_compile) + # This code stresses the "libraries are programs" paradigm to its + # limits. Maybe even breaks it. We compile a program, linking it + # against the deplibs as a proxy for the library. Then we can check + # whether they linked in statically or dynamically with ldd. + $opt_dry_run || $RM conftest.c + cat > conftest.c </dev/null` + $nocaseglob + else + potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null` + fi + for potent_lib in $potential_libs; do + # Follow soft links. + if ls -lLd "$potent_lib" 2>/dev/null | + $GREP " -> " >/dev/null; then + continue + fi + # The statement above tries to avoid entering an + # endless loop below, in case of cyclic links. + # We might still enter an endless loop, since a link + # loop can be closed while we follow links, + # but so what? + potlib=$potent_lib + while test -h "$potlib" 2>/dev/null; do + potliblink=`ls -ld $potlib | $SED 's/.* -> //'` + case $potliblink in + [\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;; + *) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";; + esac + done + if eval $file_magic_cmd \"\$potlib\" 2>/dev/null | + $SED -e 10q | + $EGREP "$file_magic_regex" > /dev/null; then + func_append newdeplibs " $a_deplib" + a_deplib= + break 2 + fi + done + done + fi + if test -n "$a_deplib"; then + droppeddeps=yes + echo + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib"; then + $ECHO "*** with $libname but no candidates were found. (...for file magic test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a file magic. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + func_append newdeplibs " $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + match_pattern*) + set dummy $deplibs_check_method; shift + match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` + for a_deplib in $deplibs; do + case $a_deplib in + -l*) + func_stripname -l '' "$a_deplib" + name=$func_stripname_result + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + case " $predeps $postdeps " in + *" $a_deplib "*) + func_append newdeplibs " $a_deplib" + a_deplib= + ;; + esac + fi + if test -n "$a_deplib"; then + libname=`eval "\\$ECHO \"$libname_spec\""` + for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do + potential_libs=`ls $i/$libname[.-]* 2>/dev/null` + for potent_lib in $potential_libs; do + potlib=$potent_lib # see symlink-check above in file_magic test + if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \ + $EGREP "$match_pattern_regex" > /dev/null; then + func_append newdeplibs " $a_deplib" + a_deplib= + break 2 + fi + done + done + fi + if test -n "$a_deplib"; then + droppeddeps=yes + echo + $ECHO "*** Warning: linker path does not have real file for library $a_deplib." + echo "*** I have the capability to make that library automatically link in when" + echo "*** you link to this library. But I can only do this if you have a" + echo "*** shared version of the library, which you do not appear to have" + echo "*** because I did check the linker path looking for a file starting" + if test -z "$potlib"; then + $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" + else + $ECHO "*** with $libname and none of the candidates passed a file format test" + $ECHO "*** using a regex pattern. Last file checked: $potlib" + fi + fi + ;; + *) + # Add a -L argument. + func_append newdeplibs " $a_deplib" + ;; + esac + done # Gone through all deplibs. + ;; + none | unknown | *) + newdeplibs= + tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'` + if test yes = "$allow_libtool_libs_with_static_runtimes"; then + for i in $predeps $postdeps; do + # can't use Xsed below, because $i might contain '/' + tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"` + done + fi + case $tmp_deplibs in + *[!\ \ ]*) + echo + if test none = "$deplibs_check_method"; then + echo "*** Warning: inter-library dependencies are not supported in this platform." + else + echo "*** Warning: inter-library dependencies are not known to be supported." + fi + echo "*** All declared inter-library dependencies are being dropped." + droppeddeps=yes + ;; + esac + ;; + esac + versuffix=$versuffix_save + major=$major_save + release=$release_save + libname=$libname_save + name=$name_save + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library with the System framework + newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'` + ;; + esac + + if test yes = "$droppeddeps"; then + if test yes = "$module"; then + echo + echo "*** Warning: libtool could not satisfy all declared inter-library" + $ECHO "*** dependencies of module $libname. Therefore, libtool will create" + echo "*** a static module, that should work as long as the dlopening" + echo "*** application is linked with the -dlopen flag." + if test -z "$global_symbol_pipe"; then + echo + echo "*** However, this would only work if libtool was able to extract symbol" + echo "*** lists from a program, using 'nm' or equivalent, but libtool could" + echo "*** not find such a program. So, this module is probably useless." + echo "*** 'nm' from GNU binutils and a full rebuild may help." + fi + if test no = "$build_old_libs"; then + oldlibs=$output_objdir/$libname.$libext + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + else + echo "*** The inter-library dependencies that have been dropped here will be" + echo "*** automatically added whenever a program is linked with this library" + echo "*** or is declared to -dlopen it." + + if test no = "$allow_undefined"; then + echo + echo "*** Since this library must not contain undefined symbols," + echo "*** because either the platform does not support them or" + echo "*** it was explicitly requested with -no-undefined," + echo "*** libtool will only create a static version of it." + if test no = "$build_old_libs"; then + oldlibs=$output_objdir/$libname.$libext + build_libtool_libs=module + build_old_libs=yes + else + build_libtool_libs=no + fi + fi + fi + fi + # Done checking deplibs! + deplibs=$newdeplibs + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + case $host in + *-*-darwin*) + newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $deplibs " in + *" -L$path/$objdir "*) + func_append new_libs " -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) func_append new_libs " $deplib" ;; + esac + ;; + *) func_append new_libs " $deplib" ;; + esac + done + deplibs=$new_libs + + # All the library-specific variables (install_libdir is set above). + library_names= + old_library= + dlname= + + # Test again, we may have decided not to build it any more + if test yes = "$build_libtool_libs"; then + # Remove $wl instances when linking with ld. + # FIXME: should test the right _cmds variable. + case $archive_cmds in + *\$LD\ *) wl= ;; + esac + if test yes = "$hardcode_into_libs"; then + # Hardcode the library paths + hardcode_libdirs= + dep_rpath= + rpath=$finalize_rpath + test relink = "$opt_mode" || rpath=$compile_rpath$rpath + for libdir in $rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + func_replace_sysroot "$libdir" + libdir=$func_replace_sysroot_result + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append dep_rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) func_append perm_rpath " $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval "dep_rpath=\"$hardcode_libdir_flag_spec\"" + fi + if test -n "$runpath_var" && test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + func_append rpath "$dir:" + done + eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" + fi + test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" + fi + + shlibpath=$finalize_shlibpath + test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath + if test -n "$shlibpath"; then + eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" + fi + + # Get the real and link names of the library. + eval shared_ext=\"$shrext_cmds\" + eval library_names=\"$library_names_spec\" + set dummy $library_names + shift + realname=$1 + shift + + if test -n "$soname_spec"; then + eval soname=\"$soname_spec\" + else + soname=$realname + fi + if test -z "$dlname"; then + dlname=$soname + fi + + lib=$output_objdir/$realname + linknames= + for link + do + func_append linknames " $link" + done + + # Use standard objects if they are pic + test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP` + test "X$libobjs" = "X " && libobjs= + + delfiles= + if test -n "$export_symbols" && test -n "$include_expsyms"; then + $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp" + export_symbols=$output_objdir/$libname.uexp + func_append delfiles " $export_symbols" + fi + + orig_export_symbols= + case $host_os in + cygwin* | mingw* | cegcc*) + if test -n "$export_symbols" && test -z "$export_symbols_regex"; then + # exporting using user supplied symfile + func_dll_def_p "$export_symbols" || { + # and it's NOT already a .def file. Must figure out + # which of the given symbols are data symbols and tag + # them as such. So, trigger use of export_symbols_cmds. + # export_symbols gets reassigned inside the "prepare + # the list of exported symbols" if statement, so the + # include_expsyms logic still works. + orig_export_symbols=$export_symbols + export_symbols= + always_export_symbols=yes + } + fi + ;; + esac + + # Prepare the list of exported symbols + if test -z "$export_symbols"; then + if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then + func_verbose "generating symbol list for '$libname.la'" + export_symbols=$output_objdir/$libname.exp + $opt_dry_run || $RM $export_symbols + cmds=$export_symbols_cmds + save_ifs=$IFS; IFS='~' + for cmd1 in $cmds; do + IFS=$save_ifs + # Take the normal branch if the nm_file_list_spec branch + # doesn't work or if tool conversion is not needed. + case $nm_file_list_spec~$to_tool_file_cmd in + *~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*) + try_normal_branch=yes + eval cmd=\"$cmd1\" + func_len " $cmd" + len=$func_len_result + ;; + *) + try_normal_branch=no + ;; + esac + if test yes = "$try_normal_branch" \ + && { test "$len" -lt "$max_cmd_len" \ + || test "$max_cmd_len" -le -1; } + then + func_show_eval "$cmd" 'exit $?' + skipped_export=false + elif test -n "$nm_file_list_spec"; then + func_basename "$output" + output_la=$func_basename_result + save_libobjs=$libobjs + save_output=$output + output=$output_objdir/$output_la.nm + func_to_tool_file "$output" + libobjs=$nm_file_list_spec$func_to_tool_file_result + func_append delfiles " $output" + func_verbose "creating $NM input file list: $output" + for obj in $save_libobjs; do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" + done > "$output" + eval cmd=\"$cmd1\" + func_show_eval "$cmd" 'exit $?' + output=$save_output + libobjs=$save_libobjs + skipped_export=false + else + # The command line is too long to execute in one step. + func_verbose "using reloadable object file for export list..." + skipped_export=: + # Break out early, otherwise skipped_export may be + # set to false by a later but shorter cmd. + break + fi + done + IFS=$save_ifs + if test -n "$export_symbols_regex" && test : != "$skipped_export"; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + fi + + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols=$export_symbols + test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols + $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' + fi + + if test : != "$skipped_export" && test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for '$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands, which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + func_append delfiles " $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + + tmp_deplibs= + for test_deplib in $deplibs; do + case " $convenience " in + *" $test_deplib "*) ;; + *) + func_append tmp_deplibs " $test_deplib" + ;; + esac + done + deplibs=$tmp_deplibs + + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec" && + test yes = "$compiler_needs_object" && + test -z "$libobjs"; then + # extract the archives, so we have objects to list. + # TODO: could optimize this to just extract one archive. + whole_archive_flag_spec= + fi + if test -n "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + else + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $convenience + func_append libobjs " $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + fi + + if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then + eval flag=\"$thread_safe_flag_spec\" + func_append linker_flags " $flag" + fi + + # Make a backup of the uninstalled library when relinking + if test relink = "$opt_mode"; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $? + fi + + # Do each of the archive commands. + if test yes = "$module" && test -n "$module_cmds"; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + eval test_cmds=\"$module_expsym_cmds\" + cmds=$module_expsym_cmds + else + eval test_cmds=\"$module_cmds\" + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + eval test_cmds=\"$archive_expsym_cmds\" + cmds=$archive_expsym_cmds + else + eval test_cmds=\"$archive_cmds\" + cmds=$archive_cmds + fi + fi + + if test : != "$skipped_export" && + func_len " $test_cmds" && + len=$func_len_result && + test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + : + else + # The command line is too long to link in one step, link piecewise + # or, if using GNU ld and skipped_export is not :, use a linker + # script. + + # Save the value of $output and $libobjs because we want to + # use them later. If we have whole_archive_flag_spec, we + # want to use save_libobjs as it was before + # whole_archive_flag_spec was expanded, because we can't + # assume the linker understands whole_archive_flag_spec. + # This may have to be revisited, in case too many + # convenience libraries get linked in and end up exceeding + # the spec. + if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then + save_libobjs=$libobjs + fi + save_output=$output + func_basename "$output" + output_la=$func_basename_result + + # Clear the reloadable object creation command queue and + # initialize k to one. + test_cmds= + concat_cmds= + objlist= + last_robj= + k=1 + + if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then + output=$output_objdir/$output_la.lnkscript + func_verbose "creating GNU ld script: $output" + echo 'INPUT (' > $output + for obj in $save_libobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + echo ')' >> $output + func_append delfiles " $output" + func_to_tool_file "$output" + output=$func_to_tool_file_result + elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then + output=$output_objdir/$output_la.lnk + func_verbose "creating linker input file list: $output" + : > $output + set x $save_libobjs + shift + firstobj= + if test yes = "$compiler_needs_object"; then + firstobj="$1 " + shift + fi + for obj + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" >> $output + done + func_append delfiles " $output" + func_to_tool_file "$output" + output=$firstobj\"$file_list_spec$func_to_tool_file_result\" + else + if test -n "$save_libobjs"; then + func_verbose "creating reloadable object files..." + output=$output_objdir/$output_la-$k.$objext + eval test_cmds=\"$reload_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + + # Loop over the list of objects to be linked. + for obj in $save_libobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + if test -z "$objlist" || + test "$len" -lt "$max_cmd_len"; then + func_append objlist " $obj" + else + # The command $test_cmds is almost too long, add a + # command to the queue. + if test 1 -eq "$k"; then + # The first file doesn't have a previous command to add. + reload_objs=$objlist + eval concat_cmds=\"$reload_cmds\" + else + # All subsequent reloadable object files will link in + # the last one created. + reload_objs="$objlist $last_robj" + eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\" + fi + last_robj=$output_objdir/$output_la-$k.$objext + func_arith $k + 1 + k=$func_arith_result + output=$output_objdir/$output_la-$k.$objext + objlist=" $obj" + func_len " $last_robj" + func_arith $len0 + $func_len_result + len=$func_arith_result + fi + done + # Handle the remaining objects by creating one last + # reloadable object file. All subsequent reloadable object + # files will link in the last one created. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + reload_objs="$objlist $last_robj" + eval concat_cmds=\"\$concat_cmds$reload_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + func_append delfiles " $output" + + else + output= + fi + + ${skipped_export-false} && { + func_verbose "generating symbol list for '$libname.la'" + export_symbols=$output_objdir/$libname.exp + $opt_dry_run || $RM $export_symbols + libobjs=$output + # Append the command to create the export file. + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\" + if test -n "$last_robj"; then + eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" + fi + } + + test -n "$save_libobjs" && + func_verbose "creating a temporary reloadable object file: $output" + + # Loop through the commands generated above and execute them. + save_ifs=$IFS; IFS='~' + for cmd in $concat_cmds; do + IFS=$save_ifs + $opt_quiet || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS=$save_ifs + + if test -n "$export_symbols_regex" && ${skipped_export-false}; then + func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' + func_show_eval '$MV "${export_symbols}T" "$export_symbols"' + fi + fi + + ${skipped_export-false} && { + if test -n "$export_symbols" && test -n "$include_expsyms"; then + tmp_export_symbols=$export_symbols + test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols + $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' + fi + + if test -n "$orig_export_symbols"; then + # The given exports_symbols file has to be filtered, so filter it. + func_verbose "filter symbol list for '$libname.la' to tag DATA exports" + # FIXME: $output_objdir/$libname.filter potentially contains lots of + # 's' commands, which not all seds can handle. GNU sed should be fine + # though. Also, the filter scales superlinearly with the number of + # global variables. join(1) would be nice here, but unfortunately + # isn't a blessed tool. + $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter + func_append delfiles " $export_symbols $output_objdir/$libname.filter" + export_symbols=$output_objdir/$libname.def + $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols + fi + } + + libobjs=$output + # Restore the value of output. + output=$save_output + + if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then + eval libobjs=\"\$libobjs $whole_archive_flag_spec\" + test "X$libobjs" = "X " && libobjs= + fi + # Expand the library linking commands again to reset the + # value of $libobjs for piecewise linking. + + # Do each of the archive commands. + if test yes = "$module" && test -n "$module_cmds"; then + if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then + cmds=$module_expsym_cmds + else + cmds=$module_cmds + fi + else + if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then + cmds=$archive_expsym_cmds + else + cmds=$archive_cmds + fi + fi + fi + + if test -n "$delfiles"; then + # Append the command to remove temporary files to $cmds. + eval cmds=\"\$cmds~\$RM $delfiles\" + fi + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $dlprefiles + func_append libobjs " $func_extract_archives_result" + test "X$libobjs" = "X " && libobjs= + fi + + save_ifs=$IFS; IFS='~' + for cmd in $cmds; do + IFS=$sp$nl + eval cmd=\"$cmd\" + IFS=$save_ifs + $opt_quiet || { + func_quote_for_expand "$cmd" + eval "func_echo $func_quote_for_expand_result" + } + $opt_dry_run || eval "$cmd" || { + lt_exit=$? + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + ( cd "$output_objdir" && \ + $RM "${realname}T" && \ + $MV "${realname}U" "$realname" ) + fi + + exit $lt_exit + } + done + IFS=$save_ifs + + # Restore the uninstalled library and exit + if test relink = "$opt_mode"; then + $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $? + + if test -n "$convenience"; then + if test -z "$whole_archive_flag_spec"; then + func_show_eval '${RM}r "$gentop"' + fi + fi + + exit $EXIT_SUCCESS + fi + + # Create links to the real library. + for linkname in $linknames; do + if test "$realname" != "$linkname"; then + func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?' + fi + done + + # If -module or -export-dynamic was specified, set the dlname. + if test yes = "$module" || test yes = "$export_dynamic"; then + # On all known operating systems, these are identical. + dlname=$soname + fi + fi + ;; + + obj) + if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then + func_warning "'-dlopen' is ignored for objects" + fi + + case " $deplibs" in + *\ -l* | *\ -L*) + func_warning "'-l' and '-L' are ignored for objects" ;; + esac + + test -n "$rpath" && \ + func_warning "'-rpath' is ignored for objects" + + test -n "$xrpath" && \ + func_warning "'-R' is ignored for objects" + + test -n "$vinfo" && \ + func_warning "'-version-info' is ignored for objects" + + test -n "$release" && \ + func_warning "'-release' is ignored for objects" + + case $output in + *.lo) + test -n "$objs$old_deplibs" && \ + func_fatal_error "cannot build library object '$output' from non-libtool objects" + + libobj=$output + func_lo2o "$libobj" + obj=$func_lo2o_result + ;; + *) + libobj= + obj=$output + ;; + esac + + # Delete the old objects. + $opt_dry_run || $RM $obj $libobj + + # Objects from convenience libraries. This assumes + # single-version convenience libraries. Whenever we create + # different ones for PIC/non-PIC, this we'll have to duplicate + # the extraction. + reload_conv_objs= + gentop= + # if reload_cmds runs $LD directly, get rid of -Wl from + # whole_archive_flag_spec and hope we can get by with turning comma + # into space. + case $reload_cmds in + *\$LD[\ \$]*) wl= ;; + esac + if test -n "$convenience"; then + if test -n "$whole_archive_flag_spec"; then + eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" + test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'` + reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags + else + gentop=$output_objdir/${obj}x + func_append generated " $gentop" + + func_extract_archives $gentop $convenience + reload_conv_objs="$reload_objs $func_extract_archives_result" + fi + fi + + # If we're not building shared, we need to use non_pic_objs + test yes = "$build_libtool_libs" || libobjs=$non_pic_objects + + # Create the old-style object. + reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs + + output=$obj + func_execute_cmds "$reload_cmds" 'exit $?' + + # Exit if we aren't doing a library object file. + if test -z "$libobj"; then + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + fi + + test yes = "$build_libtool_libs" || { + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + # Create an invalid libtool object if no PIC, so that we don't + # accidentally link it into a program. + # $show "echo timestamp > $libobj" + # $opt_dry_run || eval "echo timestamp > $libobj" || exit $? + exit $EXIT_SUCCESS + } + + if test -n "$pic_flag" || test default != "$pic_mode"; then + # Only do commands if we really have different PIC objects. + reload_objs="$libobjs $reload_conv_objs" + output=$libobj + func_execute_cmds "$reload_cmds" 'exit $?' + fi + + if test -n "$gentop"; then + func_show_eval '${RM}r "$gentop"' + fi + + exit $EXIT_SUCCESS + ;; + + prog) + case $host in + *cygwin*) func_stripname '' '.exe' "$output" + output=$func_stripname_result.exe;; + esac + test -n "$vinfo" && \ + func_warning "'-version-info' is ignored for programs" + + test -n "$release" && \ + func_warning "'-release' is ignored for programs" + + $preload \ + && test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \ + && func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support." + + case $host in + *-*-rhapsody* | *-*-darwin1.[012]) + # On Rhapsody replace the C library is the System framework + compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'` + finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'` + ;; + esac + + case $host in + *-*-darwin*) + # Don't allow lazy linking, it breaks C++ global constructors + # But is supposedly fixed on 10.4 or later (yay!). + if test CXX = "$tagname"; then + case ${MACOSX_DEPLOYMENT_TARGET-10.0} in + 10.[0123]) + func_append compile_command " $wl-bind_at_load" + func_append finalize_command " $wl-bind_at_load" + ;; + esac + fi + # Time to change all our "foo.ltframework" stuff back to "-framework foo" + compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` + ;; + esac + + + # move library search paths that coincide with paths to not yet + # installed libraries to the beginning of the library search list + new_libs= + for path in $notinst_path; do + case " $new_libs " in + *" -L$path/$objdir "*) ;; + *) + case " $compile_deplibs " in + *" -L$path/$objdir "*) + func_append new_libs " -L$path/$objdir" ;; + esac + ;; + esac + done + for deplib in $compile_deplibs; do + case $deplib in + -L*) + case " $new_libs " in + *" $deplib "*) ;; + *) func_append new_libs " $deplib" ;; + esac + ;; + *) func_append new_libs " $deplib" ;; + esac + done + compile_deplibs=$new_libs + + + func_append compile_command " $compile_deplibs" + func_append finalize_command " $finalize_deplibs" + + if test -n "$rpath$xrpath"; then + # If the user specified any rpath flags, then add them. + for libdir in $rpath $xrpath; do + # This is the magic to use -rpath. + case "$finalize_rpath " in + *" $libdir "*) ;; + *) func_append finalize_rpath " $libdir" ;; + esac + done + fi + + # Now hardcode the library paths + rpath= + hardcode_libdirs= + for libdir in $compile_rpath $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$perm_rpath " in + *" $libdir "*) ;; + *) func_append perm_rpath " $libdir" ;; + esac + fi + case $host in + *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'` + case :$dllsearchpath: in + *":$libdir:"*) ;; + ::) dllsearchpath=$libdir;; + *) func_append dllsearchpath ":$libdir";; + esac + case :$dllsearchpath: in + *":$testbindir:"*) ;; + ::) dllsearchpath=$testbindir;; + *) func_append dllsearchpath ":$testbindir";; + esac + ;; + esac + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + compile_rpath=$rpath + + rpath= + hardcode_libdirs= + for libdir in $finalize_rpath; do + if test -n "$hardcode_libdir_flag_spec"; then + if test -n "$hardcode_libdir_separator"; then + if test -z "$hardcode_libdirs"; then + hardcode_libdirs=$libdir + else + # Just accumulate the unique libdirs. + case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in + *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) + ;; + *) + func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" + ;; + esac + fi + else + eval flag=\"$hardcode_libdir_flag_spec\" + func_append rpath " $flag" + fi + elif test -n "$runpath_var"; then + case "$finalize_perm_rpath " in + *" $libdir "*) ;; + *) func_append finalize_perm_rpath " $libdir" ;; + esac + fi + done + # Substitute the hardcoded libdirs into the rpath. + if test -n "$hardcode_libdir_separator" && + test -n "$hardcode_libdirs"; then + libdir=$hardcode_libdirs + eval rpath=\" $hardcode_libdir_flag_spec\" + fi + finalize_rpath=$rpath + + if test -n "$libobjs" && test yes = "$build_old_libs"; then + # Transform all the library objects into standard objects. + compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP` + finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP` + fi + + func_generate_dlsyms "$outputname" "@PROGRAM@" false + + # template prelinking step + if test -n "$prelink_cmds"; then + func_execute_cmds "$prelink_cmds" 'exit $?' + fi + + wrappers_required=: + case $host in + *cegcc* | *mingw32ce*) + # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway. + wrappers_required=false + ;; + *cygwin* | *mingw* ) + test yes = "$build_libtool_libs" || wrappers_required=false + ;; + *) + if test no = "$need_relink" || test yes != "$build_libtool_libs"; then + wrappers_required=false + fi + ;; + esac + $wrappers_required || { + # Replace the output file specification. + compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'` + link_command=$compile_command$compile_rpath + + # We have no uninstalled library dependencies, so finalize right now. + exit_status=0 + func_show_eval "$link_command" 'exit_status=$?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + # Delete the generated files. + if test -f "$output_objdir/${outputname}S.$objext"; then + func_show_eval '$RM "$output_objdir/${outputname}S.$objext"' + fi + + exit $exit_status + } + + if test -n "$compile_shlibpath$finalize_shlibpath"; then + compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" + fi + if test -n "$finalize_shlibpath"; then + finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" + fi + + compile_var= + finalize_var= + if test -n "$runpath_var"; then + if test -n "$perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $perm_rpath; do + func_append rpath "$dir:" + done + compile_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + if test -n "$finalize_perm_rpath"; then + # We should set the runpath_var. + rpath= + for dir in $finalize_perm_rpath; do + func_append rpath "$dir:" + done + finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " + fi + fi + + if test yes = "$no_install"; then + # We don't need to create a wrapper script. + link_command=$compile_var$compile_command$compile_rpath + # Replace the output file specification. + link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'` + # Delete the old output file. + $opt_dry_run || $RM $output + # Link the executable and exit + func_show_eval "$link_command" 'exit $?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + exit $EXIT_SUCCESS + fi + + case $hardcode_action,$fast_install in + relink,*) + # Fast installation is not supported + link_command=$compile_var$compile_command$compile_rpath + relink_command=$finalize_var$finalize_command$finalize_rpath + + func_warning "this platform does not like uninstalled shared libraries" + func_warning "'$output' will be relinked during installation" + ;; + *,yes) + link_command=$finalize_var$compile_command$finalize_rpath + relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'` + ;; + *,no) + link_command=$compile_var$compile_command$compile_rpath + relink_command=$finalize_var$finalize_command$finalize_rpath + ;; + *,needless) + link_command=$finalize_var$compile_command$finalize_rpath + relink_command= + ;; + esac + + # Replace the output file specification. + link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` + + # Delete the old output files. + $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname + + func_show_eval "$link_command" 'exit $?' + + if test -n "$postlink_cmds"; then + func_to_tool_file "$output_objdir/$outputname" + postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` + func_execute_cmds "$postlink_cmds" 'exit $?' + fi + + # Now create the wrapper script. + func_verbose "creating $output" + + # Quote the relink command for shipping. + if test -n "$relink_command"; then + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + relink_command="(cd `pwd`; $relink_command)" + relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + fi + + # Only actually do things if not in dry run mode. + $opt_dry_run || { + # win32 will think the script is a binary if it has + # a .exe suffix, so we strip it off here. + case $output in + *.exe) func_stripname '' '.exe' "$output" + output=$func_stripname_result ;; + esac + # test for cygwin because mv fails w/o .exe extensions + case $host in + *cygwin*) + exeext=.exe + func_stripname '' '.exe' "$outputname" + outputname=$func_stripname_result ;; + *) exeext= ;; + esac + case $host in + *cygwin* | *mingw* ) + func_dirname_and_basename "$output" "" "." + output_name=$func_basename_result + output_path=$func_dirname_result + cwrappersource=$output_path/$objdir/lt-$output_name.c + cwrapper=$output_path/$output_name.exe + $RM $cwrappersource $cwrapper + trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 + + func_emit_cwrapperexe_src > $cwrappersource + + # The wrapper executable is built using the $host compiler, + # because it contains $host paths and files. If cross- + # compiling, it, like the target executable, must be + # executed on the $host or under an emulation environment. + $opt_dry_run || { + $LTCC $LTCFLAGS -o $cwrapper $cwrappersource + $STRIP $cwrapper + } + + # Now, create the wrapper script for func_source use: + func_ltwrapper_scriptname $cwrapper + $RM $func_ltwrapper_scriptname_result + trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15 + $opt_dry_run || { + # note: this script will not be executed, so do not chmod. + if test "x$build" = "x$host"; then + $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result + else + func_emit_wrapper no > $func_ltwrapper_scriptname_result + fi + } + ;; + * ) + $RM $output + trap "$RM $output; exit $EXIT_FAILURE" 1 2 15 + + func_emit_wrapper no > $output + chmod +x $output + ;; + esac + } + exit $EXIT_SUCCESS + ;; + esac + + # See if we need to build an old-fashioned archive. + for oldlib in $oldlibs; do + + case $build_libtool_libs in + convenience) + oldobjs="$libobjs_save $symfileobj" + addlibs=$convenience + build_libtool_libs=no + ;; + module) + oldobjs=$libobjs_save + addlibs=$old_convenience + build_libtool_libs=no + ;; + *) + oldobjs="$old_deplibs $non_pic_objects" + $preload && test -f "$symfileobj" \ + && func_append oldobjs " $symfileobj" + addlibs=$old_convenience + ;; + esac + + if test -n "$addlibs"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $addlibs + func_append oldobjs " $func_extract_archives_result" + fi + + # Do each command in the archive commands. + if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then + cmds=$old_archive_from_new_cmds + else + + # Add any objects from preloaded convenience libraries + if test -n "$dlprefiles"; then + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + + func_extract_archives $gentop $dlprefiles + func_append oldobjs " $func_extract_archives_result" + fi + + # POSIX demands no paths to be encoded in archives. We have + # to avoid creating archives with duplicate basenames if we + # might have to extract them afterwards, e.g., when creating a + # static archive out of a convenience library, or when linking + # the entirety of a libtool archive into another (currently + # not supported by libtool). + if (for obj in $oldobjs + do + func_basename "$obj" + $ECHO "$func_basename_result" + done | sort | sort -uc >/dev/null 2>&1); then + : + else + echo "copying selected object files to avoid basename conflicts..." + gentop=$output_objdir/${outputname}x + func_append generated " $gentop" + func_mkdir_p "$gentop" + save_oldobjs=$oldobjs + oldobjs= + counter=1 + for obj in $save_oldobjs + do + func_basename "$obj" + objbase=$func_basename_result + case " $oldobjs " in + " ") oldobjs=$obj ;; + *[\ /]"$objbase "*) + while :; do + # Make sure we don't pick an alternate name that also + # overlaps. + newobj=lt$counter-$objbase + func_arith $counter + 1 + counter=$func_arith_result + case " $oldobjs " in + *[\ /]"$newobj "*) ;; + *) if test ! -f "$gentop/$newobj"; then break; fi ;; + esac + done + func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" + func_append oldobjs " $gentop/$newobj" + ;; + *) func_append oldobjs " $obj" ;; + esac + done + fi + func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 + tool_oldlib=$func_to_tool_file_result + eval cmds=\"$old_archive_cmds\" + + func_len " $cmds" + len=$func_len_result + if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then + cmds=$old_archive_cmds + elif test -n "$archiver_list_spec"; then + func_verbose "using command file archive linking..." + for obj in $oldobjs + do + func_to_tool_file "$obj" + $ECHO "$func_to_tool_file_result" + done > $output_objdir/$libname.libcmd + func_to_tool_file "$output_objdir/$libname.libcmd" + oldobjs=" $archiver_list_spec$func_to_tool_file_result" + cmds=$old_archive_cmds + else + # the command line is too long to link in one step, link in parts + func_verbose "using piecewise archive linking..." + save_RANLIB=$RANLIB + RANLIB=: + objlist= + concat_cmds= + save_oldobjs=$oldobjs + oldobjs= + # Is there a better way of finding the last object in the list? + for obj in $save_oldobjs + do + last_oldobj=$obj + done + eval test_cmds=\"$old_archive_cmds\" + func_len " $test_cmds" + len0=$func_len_result + len=$len0 + for obj in $save_oldobjs + do + func_len " $obj" + func_arith $len + $func_len_result + len=$func_arith_result + func_append objlist " $obj" + if test "$len" -lt "$max_cmd_len"; then + : + else + # the above command should be used before it gets too long + oldobjs=$objlist + if test "$obj" = "$last_oldobj"; then + RANLIB=$save_RANLIB + fi + test -z "$concat_cmds" || concat_cmds=$concat_cmds~ + eval concat_cmds=\"\$concat_cmds$old_archive_cmds\" + objlist= + len=$len0 + fi + done + RANLIB=$save_RANLIB + oldobjs=$objlist + if test -z "$oldobjs"; then + eval cmds=\"\$concat_cmds\" + else + eval cmds=\"\$concat_cmds~\$old_archive_cmds\" + fi + fi + fi + func_execute_cmds "$cmds" 'exit $?' + done + + test -n "$generated" && \ + func_show_eval "${RM}r$generated" + + # Now create the libtool archive. + case $output in + *.la) + old_library= + test yes = "$build_old_libs" && old_library=$libname.$libext + func_verbose "creating $output" + + # Preserve any variables that may affect compiler behavior + for var in $variables_saved_for_relink; do + if eval test -z \"\${$var+set}\"; then + relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" + elif eval var_value=\$$var; test -z "$var_value"; then + relink_command="$var=; export $var; $relink_command" + else + func_quote_for_eval "$var_value" + relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + fi + done + # Quote the link command for shipping. + relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` + if test yes = "$hardcode_automatic"; then + relink_command= + fi + + # Only create the output if not a dry run. + $opt_dry_run || { + for installed in no yes; do + if test yes = "$installed"; then + if test -z "$install_libdir"; then + break + fi + output=$output_objdir/${outputname}i + # Replace all uninstalled libtool libraries with the installed ones + newdependency_libs= + for deplib in $dependency_libs; do + case $deplib in + *.la) + func_basename "$deplib" + name=$func_basename_result + func_resolve_sysroot "$deplib" + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result` + test -z "$libdir" && \ + func_fatal_error "'$deplib' is not a valid libtool archive" + func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name" + ;; + -L*) + func_stripname -L '' "$deplib" + func_replace_sysroot "$func_stripname_result" + func_append newdependency_libs " -L$func_replace_sysroot_result" + ;; + -R*) + func_stripname -R '' "$deplib" + func_replace_sysroot "$func_stripname_result" + func_append newdependency_libs " -R$func_replace_sysroot_result" + ;; + *) func_append newdependency_libs " $deplib" ;; + esac + done + dependency_libs=$newdependency_libs + newdlfiles= + + for lib in $dlfiles; do + case $lib in + *.la) + func_basename "$lib" + name=$func_basename_result + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "'$lib' is not a valid libtool archive" + func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name" + ;; + *) func_append newdlfiles " $lib" ;; + esac + done + dlfiles=$newdlfiles + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + *.la) + # Only pass preopened files to the pseudo-archive (for + # eventual linking with the app. that links it) if we + # didn't already link the preopened objects directly into + # the library: + func_basename "$lib" + name=$func_basename_result + eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib` + test -z "$libdir" && \ + func_fatal_error "'$lib' is not a valid libtool archive" + func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name" + ;; + esac + done + dlprefiles=$newdlprefiles + else + newdlfiles= + for lib in $dlfiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;; + *) abs=`pwd`"/$lib" ;; + esac + func_append newdlfiles " $abs" + done + dlfiles=$newdlfiles + newdlprefiles= + for lib in $dlprefiles; do + case $lib in + [\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;; + *) abs=`pwd`"/$lib" ;; + esac + func_append newdlprefiles " $abs" + done + dlprefiles=$newdlprefiles + fi + $RM $output + # place dlname in correct position for cygwin + # In fact, it would be nice if we could use this code for all target + # systems that can't hard-code library paths into their executables + # and that have no shared library path variable independent of PATH, + # but it turns out we can't easily determine that from inspecting + # libtool variables, so we have to hard-code the OSs to which it + # applies here; at the moment, that means platforms that use the PE + # object format with DLL files. See the long comment at the top of + # tests/bindir.at for full details. + tdlname=$dlname + case $host,$output,$installed,$module,$dlname in + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) + # If a -bindir argument was supplied, place the dll there. + if test -n "$bindir"; then + func_relative_path "$install_libdir" "$bindir" + tdlname=$func_relative_path_result/$dlname + else + # Otherwise fall back on heuristic. + tdlname=../bin/$dlname + fi + ;; + esac + $ECHO > $output "\ +# $outputname - a libtool library file +# Generated by $PROGRAM (GNU $PACKAGE) $VERSION +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='$tdlname' + +# Names of this library. +library_names='$library_names' + +# The name of the static archive. +old_library='$old_library' + +# Linker flags that cannot go in dependency_libs. +inherited_linker_flags='$new_inherited_linker_flags' + +# Libraries that this one depends upon. +dependency_libs='$dependency_libs' + +# Names of additional weak libraries provided by this library +weak_library_names='$weak_libs' + +# Version information for $libname. +current=$current +age=$age +revision=$revision + +# Is this an already installed library? +installed=$installed + +# Should we warn about portability when linking against -modules? +shouldnotlink=$module + +# Files to dlopen/dlpreopen +dlopen='$dlfiles' +dlpreopen='$dlprefiles' + +# Directory that this library needs to be installed in: +libdir='$install_libdir'" + if test no,yes = "$installed,$need_relink"; then + $ECHO >> $output "\ +relink_command=\"$relink_command\"" + fi + done + } + + # Do a symbolic link so that the libtool archive can be found in + # LD_LIBRARY_PATH before the program is installed. + func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?' + ;; + esac + exit $EXIT_SUCCESS +} + +if test link = "$opt_mode" || test relink = "$opt_mode"; then + func_mode_link ${1+"$@"} +fi + + +# func_mode_uninstall arg... +func_mode_uninstall () +{ + $debug_cmd + + RM=$nonopt + files= + rmforce=false + exit_status=0 + + # This variable tells wrapper scripts just to set variables rather + # than running their programs. + libtool_install_magic=$magic + + for arg + do + case $arg in + -f) func_append RM " $arg"; rmforce=: ;; + -*) func_append RM " $arg" ;; + *) func_append files " $arg" ;; + esac + done + + test -z "$RM" && \ + func_fatal_help "you must specify an RM program" + + rmdirs= + + for file in $files; do + func_dirname "$file" "" "." + dir=$func_dirname_result + if test . = "$dir"; then + odir=$objdir + else + odir=$dir/$objdir + fi + func_basename "$file" + name=$func_basename_result + test uninstall = "$opt_mode" && odir=$dir + + # Remember odir for removal later, being careful to avoid duplicates + if test clean = "$opt_mode"; then + case " $rmdirs " in + *" $odir "*) ;; + *) func_append rmdirs " $odir" ;; + esac + fi + + # Don't error if the file doesn't exist and rm -f was used. + if { test -L "$file"; } >/dev/null 2>&1 || + { test -h "$file"; } >/dev/null 2>&1 || + test -f "$file"; then + : + elif test -d "$file"; then + exit_status=1 + continue + elif $rmforce; then + continue + fi + + rmfiles=$file + + case $name in + *.la) + # Possibly a libtool archive, so verify it. + if func_lalib_p "$file"; then + func_source $dir/$name + + # Delete the libtool libraries and symlinks. + for n in $library_names; do + func_append rmfiles " $odir/$n" + done + test -n "$old_library" && func_append rmfiles " $odir/$old_library" + + case $opt_mode in + clean) + case " $library_names " in + *" $dlname "*) ;; + *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;; + esac + test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i" + ;; + uninstall) + if test -n "$library_names"; then + # Do each command in the postuninstall commands. + func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1' + fi + + if test -n "$old_library"; then + # Do each command in the old_postuninstall commands. + func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1' + fi + # FIXME: should reinstall the best remaining shared library. + ;; + esac + fi + ;; + + *.lo) + # Possibly a libtool object, so verify it. + if func_lalib_p "$file"; then + + # Read the .lo file + func_source $dir/$name + + # Add PIC object to the list of files to remove. + if test -n "$pic_object" && test none != "$pic_object"; then + func_append rmfiles " $dir/$pic_object" + fi + + # Add non-PIC object to the list of files to remove. + if test -n "$non_pic_object" && test none != "$non_pic_object"; then + func_append rmfiles " $dir/$non_pic_object" + fi + fi + ;; + + *) + if test clean = "$opt_mode"; then + noexename=$name + case $file in + *.exe) + func_stripname '' '.exe' "$file" + file=$func_stripname_result + func_stripname '' '.exe' "$name" + noexename=$func_stripname_result + # $file with .exe has already been added to rmfiles, + # add $file without .exe + func_append rmfiles " $file" + ;; + esac + # Do a test to see if this is a libtool program. + if func_ltwrapper_p "$file"; then + if func_ltwrapper_executable_p "$file"; then + func_ltwrapper_scriptname "$file" + relink_command= + func_source $func_ltwrapper_scriptname_result + func_append rmfiles " $func_ltwrapper_scriptname_result" + else + relink_command= + func_source $dir/$noexename + fi + + # note $name still contains .exe if it was in $file originally + # as does the version of $file that was added into $rmfiles + func_append rmfiles " $odir/$name $odir/${name}S.$objext" + if test yes = "$fast_install" && test -n "$relink_command"; then + func_append rmfiles " $odir/lt-$name" + fi + if test "X$noexename" != "X$name"; then + func_append rmfiles " $odir/lt-$noexename.c" + fi + fi + fi + ;; + esac + func_show_eval "$RM $rmfiles" 'exit_status=1' + done + + # Try to remove the $objdir's in the directories where we deleted files + for dir in $rmdirs; do + if test -d "$dir"; then + func_show_eval "rmdir $dir >/dev/null 2>&1" + fi + done + + exit $exit_status +} + +if test uninstall = "$opt_mode" || test clean = "$opt_mode"; then + func_mode_uninstall ${1+"$@"} +fi + +test -z "$opt_mode" && { + help=$generic_help + func_fatal_help "you must specify a MODE" +} + +test -z "$exec_cmd" && \ + func_fatal_help "invalid operation mode '$opt_mode'" + +if test -n "$exec_cmd"; then + eval exec "$exec_cmd" + exit $EXIT_FAILURE +fi + +exit $exit_status + + +# The TAGs below are defined such that we never get into a situation +# where we disable both kinds of libraries. Given conflicting +# choices, we go for a static library, that is the most portable, +# since we can't tell whether shared libraries were disabled because +# the user asked for that or because the platform doesn't support +# them. This is particularly important on AIX, because we don't +# support having both static and shared libraries enabled at the same +# time on that platform, so we default to a shared-only configuration. +# If a disable-shared tag is given, we'll fallback to a static-only +# configuration. But we'll never go from static-only to shared-only. + +# ### BEGIN LIBTOOL TAG CONFIG: disable-shared +build_libtool_libs=no +build_old_libs=yes +# ### END LIBTOOL TAG CONFIG: disable-shared + +# ### BEGIN LIBTOOL TAG CONFIG: disable-static +build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` +# ### END LIBTOOL TAG CONFIG: disable-static + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/missing cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/missing --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/missing 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/missing 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,215 @@ +#! /bin/sh +# Common wrapper for a few potentially missing GNU programs. + +scriptversion=2013-10-28.13; # UTC + +# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Originally written by Fran,cois Pinard , 1996. + +# 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, 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, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try '$0 --help' for more information" + exit 1 +fi + +case $1 in + + --is-lightweight) + # Used by our autoconf macros to check whether the available missing + # script is modern enough. + exit 0 + ;; + + --run) + # Back-compat with the calling convention used by older automake. + shift + ;; + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due +to PROGRAM being missing or too old. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + +Supported PROGRAM values: + aclocal autoconf autoheader autom4te automake makeinfo + bison yacc flex lex help2man + +Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and +'g' are ignored when checking the name. + +Send bug reports to ." + exit $? + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing $scriptversion (GNU Automake)" + exit $? + ;; + + -*) + echo 1>&2 "$0: unknown '$1' option" + echo 1>&2 "Try '$0 --help' for more information" + exit 1 + ;; + +esac + +# Run the given program, remember its exit status. +"$@"; st=$? + +# If it succeeded, we are done. +test $st -eq 0 && exit 0 + +# Also exit now if we it failed (or wasn't found), and '--version' was +# passed; such an option is passed most likely to detect whether the +# program is present and works. +case $2 in --version|--help) exit $st;; esac + +# Exit code 63 means version mismatch. This often happens when the user +# tries to use an ancient version of a tool on a file that requires a +# minimum version. +if test $st -eq 63; then + msg="probably too old" +elif test $st -eq 127; then + # Program was missing. + msg="missing on your system" +else + # Program was found and executed, but failed. Give up. + exit $st +fi + +perl_URL=http://www.perl.org/ +flex_URL=http://flex.sourceforge.net/ +gnu_software_URL=http://www.gnu.org/software + +program_details () +{ + case $1 in + aclocal|automake) + echo "The '$1' program is part of the GNU Automake package:" + echo "<$gnu_software_URL/automake>" + echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" + echo "<$gnu_software_URL/autoconf>" + echo "<$gnu_software_URL/m4/>" + echo "<$perl_URL>" + ;; + autoconf|autom4te|autoheader) + echo "The '$1' program is part of the GNU Autoconf package:" + echo "<$gnu_software_URL/autoconf/>" + echo "It also requires GNU m4 and Perl in order to run:" + echo "<$gnu_software_URL/m4/>" + echo "<$perl_URL>" + ;; + esac +} + +give_advice () +{ + # Normalize program name to check for. + normalized_program=`echo "$1" | sed ' + s/^gnu-//; t + s/^gnu//; t + s/^g//; t'` + + printf '%s\n' "'$1' is $msg." + + configure_deps="'configure.ac' or m4 files included by 'configure.ac'" + case $normalized_program in + autoconf*) + echo "You should only need it if you modified 'configure.ac'," + echo "or m4 files included by it." + program_details 'autoconf' + ;; + autoheader*) + echo "You should only need it if you modified 'acconfig.h' or" + echo "$configure_deps." + program_details 'autoheader' + ;; + automake*) + echo "You should only need it if you modified 'Makefile.am' or" + echo "$configure_deps." + program_details 'automake' + ;; + aclocal*) + echo "You should only need it if you modified 'acinclude.m4' or" + echo "$configure_deps." + program_details 'aclocal' + ;; + autom4te*) + echo "You might have modified some maintainer files that require" + echo "the 'autom4te' program to be rebuilt." + program_details 'autom4te' + ;; + bison*|yacc*) + echo "You should only need it if you modified a '.y' file." + echo "You may want to install the GNU Bison package:" + echo "<$gnu_software_URL/bison/>" + ;; + lex*|flex*) + echo "You should only need it if you modified a '.l' file." + echo "You may want to install the Fast Lexical Analyzer package:" + echo "<$flex_URL>" + ;; + help2man*) + echo "You should only need it if you modified a dependency" \ + "of a man page." + echo "You may want to install the GNU Help2man package:" + echo "<$gnu_software_URL/help2man/>" + ;; + makeinfo*) + echo "You should only need it if you modified a '.texi' file, or" + echo "any other file indirectly affecting the aspect of the manual." + echo "You might want to install the Texinfo package:" + echo "<$gnu_software_URL/texinfo/>" + echo "The spurious makeinfo call might also be the consequence of" + echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" + echo "want to install GNU make:" + echo "<$gnu_software_URL/make/>" + ;; + *) + echo "You might have modified some files without having the proper" + echo "tools for further handling them. Check the 'README' file, it" + echo "often tells you about the needed prerequisites for installing" + echo "this package. You may also peek at any GNU archive site, in" + echo "case some other package contains this missing '$1' program." + ;; + esac +} + +give_advice "$1" | sed -e '1s/^/WARNING: /' \ + -e '2,$s/^/ /' >&2 + +# Propagate the correct exit status (expected to be 127 for a program +# not found, 63 for a program that failed due to version mismatch). +exit $st + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/test-driver cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/test-driver --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/admin/test-driver 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/admin/test-driver 2016-02-03 17:37:24.000000000 +0000 @@ -0,0 +1,148 @@ +#! /bin/sh +# test-driver - basic testsuite driver script. + +scriptversion=2013-07-13.22; # UTC + +# Copyright (C) 2011-2014 Free Software Foundation, Inc. +# +# 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, 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, see . + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +# Make unconditional expansion of undefined variables an error. This +# helps a lot in preventing typo-related bugs. +set -u + +usage_error () +{ + echo "$0: $*" >&2 + print_usage >&2 + exit 2 +} + +print_usage () +{ + cat <$log_file 2>&1 +estatus=$? + +if test $enable_hard_errors = no && test $estatus -eq 99; then + tweaked_estatus=1 +else + tweaked_estatus=$estatus +fi + +case $tweaked_estatus:$expect_failure in + 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; + 0:*) col=$grn res=PASS recheck=no gcopy=no;; + 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; + 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; + *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; + *:*) col=$red res=FAIL recheck=yes gcopy=yes;; +esac + +# Report the test outcome and exit status in the logs, so that one can +# know whether the test passed or failed simply by looking at the '.log' +# file, without the need of also peaking into the corresponding '.trs' +# file (automake bug#11814). +echo "$res $test_name (exit status: $estatus)" >>$log_file + +# Report outcome to console. +echo "${col}${res}${std}: $test_name" + +# Register the test result, and other relevant metadata. +echo ":test-result: $res" > $trs_file +echo ":global-test-result: $res" >> $trs_file +echo ":recheck: $recheck" >> $trs_file +echo ":copy-in-global-log: $gcopy" >> $trs_file + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC" +# time-stamp-end: "; # UTC" +# End: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,272 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_apclust.h" + +#include "hdrl_cat_terminate.h" + + +/*** Prototypes ***/ +static void minmax_xy( cpl_size np, plstruct *plstr, + cpl_size *ix1, cpl_size *ix2, + cpl_size *iy1, cpl_size *iy2); + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_apclust hdrl_apclust + * @ingroup Catalogue + * + * @brief Detect multiple objects from a given Plessey array + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Detect multiple objects from a given Plessey array + * + * @param ap The new input ap structure + * @param np The number of pixels within the input Plessey array + * @param plstr The Plessey array from the original structure with the + * lower detection threshold. + * Purpose: + * Detect multiple peaks in a Plessey array and write to a new ap structure. + * + * Description: + * The Plessey array is given from an ap structure for a single object. + * Given a second ap structure with a revised threshold this routine + * will attempt to detect multiple objects within that Plessey array. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_apclust(ap_t *ap, cpl_size np, plstruct *plstr) +{ + /* A couple of useful things */ + double i2compare = ap->thresh; + double icompare = i2compare * (double)ap->multiply; + + /* Get the min and max positions. Create a raster with the IDs of the + * pixels in the pixel list (algorithm prefers data to be in a raster) */ + cpl_size ix1, ix2, iy1, iy2; + minmax_xy(np, plstr, &ix1, &ix2, &iy1, &iy2); + + cpl_size nx = ix2 - ix1 + 1; + cpl_size ny = iy2 - iy1 + 1; + + cpl_size nwork = nx * ny; + cpl_size *work = cpl_malloc(nwork * sizeof(cpl_size)); + + for (cpl_size i = 0; i < nwork; i++) { + work[i] = -1; + } + + for (cpl_size k = 0; k < np; k++) { + + cpl_size i = plstr[k].x - 1; + cpl_size j = plstr[k].y - 1; + + cpl_size kk = (j - iy1) * nx + i - ix1; + work[kk] = k; + } + + /* Now do the job */ + for (cpl_size j = iy1; j <= iy2; j++) { + + for (cpl_size i = ix1; i <= ix2; i++) { + + cpl_size kk = (j - iy1) * nx + i - ix1; + cpl_size k = work[kk]; + + if (k < 0) { + + ap->lastline[i + 1] = 0; + + } else { + + if (plstr[k].zsm > icompare) { + + /* Pixel is above threshold, find which parent it belongs to. */ + cpl_size is = ap->lastline[i]; /* Parent last pixel this line */ + cpl_size ip = ap->lastline[i + 1]; /* Guess belongs to above line */ + + if (ip == 0) { + + /* New parent, or, horizontal slice: */ + if (is == 0) { + + /* Ah - new parent. */ + if (ap->ipstack > ap->maxpa * 3 / 4) { + for (cpl_size ik = 0; ik < ap->maxpa * 3 / 8; ik++) { + hdrl_apfu(ap); + } + } + + ip = ap->pstack[ap->ipstack++]; + + ap->parent[ip].first = ap->bstack[ap->ibstack]; + ap->parent[ip].pnop = 0; + ap->parent[ip].pnbp = 0; + ap->parent[ip].growing = 0; + + if (j == 0) { + ap->parent[ip].touch = 1; /* It touches first line */ + } else { + ap->parent[ip].touch = 0; + } + + /* For hunt thru list for terminates: */ + if (ip > ap->maxip) { + ap->maxip = ip; + } + + } else { + + /* Slice with no vertical join: */ + ip = is; + } + + } else if ((ip > 0 && is > 0) && (ip != is)) { + + /* Merge: Join linked lists: */ + ap->blink[ap->parent[ip].last] = ap->parent[is].first; + + /* Copy `last block': */ + ap->parent[ip].last = ap->parent[is].last; + ap->parent[ip].pnop += ap->parent[is].pnop; + ap->parent[ip].pnbp += ap->parent[is].pnbp; + + /* Fix `lastline' correlator array: */ + cpl_size ib = ap->parent[is].first; + + cpl_size loop = 1; + while (loop) { + + cpl_size i1 = ap->plessey[ib].x; + + if (ap->lastline[i1 + 1] == is) { + ap->lastline[i1 + 1] = ip; + } + + if (ap->parent[is].last == ib) { + loop = 0; + } else { + ib = ap->blink[ib]; + } + } + + /* Mark parent inactive: */ + ap->parent[is].pnop = -1; + ap->parent[is].pnbp = -1; + + /* return name to stack: */ + ap->pstack[--ap->ipstack] = is; + } + + /* Add in pixel to linked list: */ + cpl_size ib = ap->bstack[ap->ibstack++]; + + /* Patch forward link into last data block: */ + if (ap->parent[ip].pnop > 0) { + ap->blink[ap->parent[ip].last] = ib; + } + + /* Remember last block in chain: */ + ap->parent[ip].last = ib; + + /* Store the data: */ + ap->plessey[ib].x = i; + ap->plessey[ib].y = j; + ap->plessey[ib].z = plstr[k].z; + ap->plessey[ib].zsm = plstr[k].zsm; + + /* increment active count: */ + ap->parent[ip].pnop++; + + /* remember which parent this pixel was for next line: */ + ap->lastline[i + 1] = ip; + + } else { + + /* Pixel was below threshold, mark lastline: */ + ap->lastline[i + 1] = 0; + } + } + } + } + + /* Check for images touching left & right edges: + * OR the touch flag with 2 for left, 4 for right: */ + + if (ap->lastline[1] > 0) { + ap->parent[ap->lastline[1]].touch |= 2; + } + + if (ap->lastline[ap->lsiz] > 0) { + ap->parent[ap->lastline[ap->lsiz]].touch |= 4; + } + + cpl_free(work); +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief minmax_xy + * + * @param np The number of pixels in the Plessey array + * @param plstr The Plessey array from the original structure with the + * lower detection threshold. + * @param ix1 The min x-coordinate + * @param ix2 The max x-coordinate + * @param iy1 The min y-coordinate + * @param iy2 The max y-coordinate + * + * Purpose: + * Work out the min and max x,y positions within a Plessey array + * Description: + * All the pixels within the given Plessey array are searched and the + * min and max positions are returned. These values have 1 subtracted + * off so they can be used as array indices. + */ +/* ---------------------------------------------------------------------------*/ +static void minmax_xy( cpl_size np, plstruct *plstr, + cpl_size *ix1, cpl_size *ix2, + cpl_size *iy1, cpl_size *iy2) +{ + + /* Get the minmax of the positions of the pixels in a plstruct. + * Take 1 away from each position so that it runs from 0 rather than 1 */ + + *ix1 = plstr[0].x - 1; + *ix2 = plstr[0].x - 1; + + *iy1 = plstr[0].y - 1; + *iy2 = plstr[0].y - 1; + + for (cpl_size i = 1; i < np; i++) { + + *ix1 = CPL_MIN(*ix1, plstr[i].x - 1); + *ix2 = CPL_MAX(*ix2, plstr[i].x - 1); + *iy1 = CPL_MIN(*iy1, plstr[i].y - 1); + *iy2 = CPL_MAX(*iy2, plstr[i].y - 1); + } +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apclust.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,30 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_APCLUST_H +#define HDRL_APCLUST_H + + +#include "hdrl_cat_def.h" + + +void hdrl_apclust(ap_t *ap, cpl_size np, plstruct *plstr); + + +#endif /* HDRL_APCLUST_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apio.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apio.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apio.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apio.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,178 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_apio.h" + + +/*** DEFINES ***/ +#define MAXBL 250000 + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_apio hdrl_apio + * @ingroup Catalogue + * + * @brief Initialize the ap structure + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Initialize the ap structure + * + * @param ap The input ap structure + * + * Purpose: + * Initialize the ap structure given some pre-existing information + * + * Description: + * The ap structure is initialized. In order for this to be done + * properly the value of ap->lsiz (the length of the image rows) + * must be set before calling this routine. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_apinit(ap_t *ap) { + + /* max possible parents */ + cpl_size maxpa = ap->lsiz / 2; + + ap->lastline = cpl_calloc(ap->lsiz + 1, sizeof(*ap->lastline)); + ap->maxip = 0; + ap->maxpa = maxpa; + ap->pstack = cpl_malloc(maxpa * sizeof(*ap->pstack)); + ap->parent = cpl_malloc(maxpa * sizeof(*ap->parent)); + + for (cpl_size i = 0; i < maxpa; i++) { + ap->pstack[i] = i; + ap->parent[i].pnop = -1; /* mark all parents inactive */ + ap->parent[i].pnbp = -1; /* mark all parents inactive */ + } + + ap->ipstack = 1; + ap->maxbl = MAXBL; + ap->bstack = cpl_malloc(ap->maxbl * sizeof(*ap->bstack)); + ap->blink = cpl_malloc(ap->maxbl * sizeof(*ap->blink)); + ap->plessey = cpl_malloc(ap->maxbl * sizeof(*ap->plessey)); + + for (cpl_size i = 0; i < MAXBL; i++) { + ap->bstack[i] = i; + } + + ap->ibstack = 2; /* block 1 will get overwritten; don't use it */ + ap->nimages = 0; + + /* set up exponential areal-profile levels: */ + ap->areal[0] = 1; + cpl_size maxAreal = 8; + for (cpl_size i = 1; i < maxAreal; i++) { + ap->areal[i] = ap->areal[i - 1] * 2; + } + + /* allocate some space for a processing array */ + ap->npl = ap->lsiz; + ap->npl_pix = 0; + ap->plarray = cpl_malloc(ap->npl * sizeof(*ap->plarray)); + + /* set these to null values as you may not need the background structure */ + ap->backmap.nby = -1; + ap->backmap.bvals = NULL; + + /* Initialise some info about the input images */ + ap->indata = NULL; + ap->confdata = NULL; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Re-initialize the ap structure + * + * @param ap The input ap structure + * + * Purpose: + * Re-initialize the ap structure + * + * Description: + * The ap structure is reinitialized to the state it was in before + * we started detecting objects in it. All information about detected + * objects is erased. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_apreinit(ap_t *ap) { + + for (cpl_size i = 0; i < ap->lsiz + 1; i++) { + ap->lastline[i] = 0; + } + + ap->maxip = 0; + + for (cpl_size i = 0; i < ap->maxpa; i++) { + ap->pstack[i] = i; + ap->parent[i].pnop = -1; /* mark all parents inactive */ + ap->parent[i].pnbp = -1; /* mark all parents inactive */ + } + + ap->ipstack = 1; + ap->ibstack = 2; /* block 1 will get overwritten; don't use it */ + ap->nimages = 0; + ap->npl_pix = 0; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Close ap structure + * + * @param ap The input ap structure + * + * Purpose: + * Close the ap structure + * + * Description: + * The ap structure has all of its allocated memory freed. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_apclose(ap_t *ap) { + + if (ap->lastline) {cpl_free(ap->lastline); ap->lastline = NULL;} + if (ap->pstack ) {cpl_free(ap->pstack ); ap->pstack = NULL;} + if (ap->parent ) {cpl_free(ap->parent ); ap->parent = NULL;} + if (ap->bstack ) {cpl_free(ap->bstack ); ap->bstack = NULL;} + if (ap->blink ) {cpl_free(ap->blink ); ap->blink = NULL;} + if (ap->plessey ) {cpl_free(ap->plessey ); ap->plessey = NULL;} + if (ap->plarray ) {cpl_free(ap->plarray ); ap->plarray = NULL;} + + if (ap->backmap.bvals) { + + for (cpl_size i = 0; i < ap->backmap.nby; i++) { + + if (ap->backmap.bvals[i]) { + cpl_free(ap->backmap.bvals[i]); + ap->backmap.bvals[i] = NULL; + } + } + + cpl_free(ap->backmap.bvals); + ap->backmap.bvals = NULL; + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apio.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apio.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apio.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apio.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_APIO_H +#define HDRL_APIO_H + + +#include "hdrl_cat_def.h" + + +void hdrl_apinit( ap_t *ap); +void hdrl_apreinit(ap_t *ap); +void hdrl_apclose( ap_t *ap); + + +#endif /* HDRL_APIO_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apline.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apline.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apline.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apline.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,191 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_apline.h" + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_apline hdrl_apline + * @ingroup Catalogue + * + * + * @brief Detect objects on a line of data + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Detect objects on a line of data + * + * @param ap The input ap structure + * @param dat The line of data + * @param conf The confidence map for the line of data + * @param smoothed A smoothed version of the data line + * @param smoothedc A smoothed version of the confidence map line + * @param j A number that tells you which row this is in the image + * @param bpm A bad pixel mask for that line + * + * Purpose: + * Detect objects on a line of data + * + * Description: + * Pixels above the defined threshold are detected on a line of data. + * A search is done in the ap structure to see if the pixel forms part + * of an object that is already known or whether this is part of a new + * object. The information is stored in the ap structure linked list. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_apline( ap_t *ap, double dat[], double conf[], double smoothed[], + double smoothedc[], cpl_size j, unsigned char *bpm) +{ + double i2compare = ap->thresh; + double icompare = i2compare * (double)ap->multiply; + unsigned char *mflag = ap->mflag; + + for (cpl_size i = 0; i < ap->lsiz; i++) { + + if (smoothedc[i] > icompare && conf[i] != 0) { + + /* Pixel is above threshold, find which parent it belongs to. */ + cpl_size is = ap->lastline[i]; /* Parent last pixel this line */ + cpl_size ip = ap->lastline[i + 1]; /* Guess belongs to above line */ + + if (ip == 0) { + + /* New parent, or, horizontal slice: */ + if (is == 0) { + + /* Ah - new parent. */ + ip = ap->pstack[ap->ipstack++]; + + ap->parent[ip].first = ap->bstack[ap->ibstack]; + ap->parent[ip].pnop = 0; + ap->parent[ip].pnbp = 0; + ap->parent[ip].growing = 0; + + if (j == 0) { + ap->parent[ip].touch = 1; /* It touches first line */ + } else { + ap->parent[ip].touch = 0; + } + + /* For hunt thru list for terminates: */ + if (ip > ap->maxip) { + ap->maxip = ip; + } + + } else { + + /* Slice with no vertical join: */ + ip = is; + } + + } else if ((ip > 0 && is > 0) && (ip != is)) { + + /* merge: Join linked lists: */ + ap->blink[ap->parent[ip].last] = ap->parent[is].first; + + /* Copy `last block': */ + ap->parent[ip].last = ap->parent[is].last; + ap->parent[ip].pnop += ap->parent[is].pnop; + ap->parent[ip].pnbp += ap->parent[is].pnbp; + + /* Fix `lastline' correlator array: */ + cpl_size ib = ap->parent[is].first; + + cpl_size loop = 1; + while (loop) { + + cpl_size i1 = ap->plessey[ib].x; + + if (ap->lastline[i1 + 1] == is) { + ap->lastline[i1 + 1] = ip; + } + + if (ap->parent[is].last == ib) { + loop = 0; + } else { + ib = ap->blink[ib]; + } + } + + /* Mark parent inactive: */ + ap->parent[is].pnop = -1; + ap->parent[is].pnbp = -1; + + /* return name to stack: */ + ap->pstack[--ap->ipstack] = is; + } + + /* Add in pixel to linked list: */ + cpl_size ib = ap->bstack[ap->ibstack++]; + + /* Patch forward link into last data block: */ + if (ap->parent[ip].pnop > 0) { + ap->blink[ap->parent[ip].last] = ib; + } + + /* Remember last block in chain: */ + ap->parent[ip].last = ib; + + /* Store the data: */ + ap->plessey[ib].x = i; + ap->plessey[ib].y = j; + ap->plessey[ib].z = dat[i]; + + cpl_size nn = j*ap->lsiz + i; + if (mflag[nn] != MF_SATURATED) { + ap->plessey[ib].zsm = CPL_MIN(ap->saturation,smoothed[i]); + } else { + ap->plessey[ib].zsm = ap->saturation; + } + mflag[nn] = MF_POSSIBLEOBJ; + + /* increment active count: */ + ap->parent[ip].pnop++; + if (bpm != NULL) { + ap->parent[ip].pnbp += bpm[i]; + } + + /* remember which parent this pixel was for next line: */ + ap->lastline[i + 1] = ip; + + } else { + + /* Pixel was below threshold, mark lastline: */ + ap->lastline[i + 1] = 0; + } + } + + /* Check for images touching left & right edges: + OR the touch flag with 2 for left, 4 for right: */ + if (ap->lastline[1] > 0 ) { + ap->parent[ap->lastline[1]].touch |= 2; + } + + if (ap->lastline[ap->lsiz] > 0) { + ap->parent[ap->lastline[ap->lsiz]].touch |= 4; + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apline.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apline.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_apline.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_apline.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,31 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_APLINE_H +#define HDRL_APLINE_H + + +#include "hdrl_cat_def.h" + + +void hdrl_apline( ap_t *ap, double dat[], double conf[], double smoothed[], + double smoothedc[], cpl_size j, unsigned char *bpm); + + +#endif /* HDRL_APLINE_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_areals.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_areals.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_areals.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_areals.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,81 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "hdrl_cat_areals.h" + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_areals hdrl_areals + * @ingroup Catalogue + * + * @brief Work out the areal profiles for an object + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the areal profiles for an object + * + * @param ap The input ap structure + * @param areal areal profile array + * + * Purpose: + * Work out the areal profiles for an object + * + * Description: + * The pixel list for an object is used to define the areal profiles + * for that object and a given detection threshold. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_areals(ap_t *ap, cpl_size iareal[NAREAL]) +{ + + /* Initialise some stuff */ + cpl_size np = ap->npl_pix; + plstruct *plarray = ap->plarray; + double thresh = ap->thresh; + double fconst = ap->fconst; + double offset = ap->areal_offset; + + /* Zero the areal profile array */ + memset(iareal, 0, NAREAL * sizeof(cpl_size)); + + /* Loop through the array and form the areal profiles */ + for (cpl_size i = 0; i < np; i++) { + + double t = plarray[i].z; + + if (t > thresh) { + + cpl_size nup = CPL_MAX(1, CPL_MIN(NAREAL, (cpl_size)(log(t) * fconst - offset) + 1)); + + for (cpl_size j = 0; j < nup; j++) { + iareal[j]++; + } + } + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_areals.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_areals.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_areals.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_areals.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,30 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_AREALS_H +#define HDRL_AREALS_H + + +#include "hdrl_cat_def.h" + + +void hdrl_areals(ap_t *ap, cpl_size iareal[NAREAL]); + + +#endif /* HDRL_AREALS_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_background.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_background.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_background.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_background.c 2017-11-28 10:12:38.000000000 +0000 @@ -0,0 +1,455 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_background.h" + +#include "hdrl_cat_filter.h" +#include "hdrl_cat_utils_sort.h" + +#include "hdrl_image.h" + + +/*** Prototypes ***/ + +static cpl_image * hdrl_sigclipfilter_image_grid( + const cpl_image *ima, cpl_matrix *x, cpl_matrix *y, + cpl_size filtersize_x, cpl_size filtersize_y); + +static cpl_matrix * matrix_linspace(cpl_size start, cpl_size stop, cpl_size step); + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_background hdrl_background + * @ingroup Catalogue + * + * @brief Model and create background map + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Model and create background map + * + * @param ap The current ap structure + * @param nbsize The size of the cells in pixels + * @param nullval A null value used to flag bad pixels + * @param bkg_subtr switch: if bkg_subtr !=0 fill background map + * @param res + * + * @return CPL_ERROR_CODE if all went well (this is currently the only value). + * + * Description: + * The image data array is split into cells. In each cell a robust + * background estimate is obtained. The cell raster is gently smoothed + * and then used to create a full background map with a bi-linear + * interpolation scheme. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_background( + ap_t *ap, cpl_size nbsize, double nullval, cpl_size bkg_subtr, hdrl_casu_result *res) +{ + /* Set up some variables */ + double *map = ap->indata; + cpl_size nx = ap->lsiz; + cpl_size ny = ap->csiz; + unsigned char *mflag = ap->mflag; + + /* check to see if nbsize is close to exact divisor */ + nbsize = CPL_MIN(CPL_MIN(nx, ny), nbsize); + + double fracx = (double)nx / (double)nbsize; + double fracy = (double)ny / (double)nbsize; + + cpl_size ifracx = (cpl_size)(fracx + 0.1); + cpl_size ifracy = (cpl_size)(fracy + 0.1); + + cpl_size nbsizx = nx / ifracx; + cpl_size nbsizy = ny / ifracy; + + /* trap for small maps */ + double a = 0.9 * nbsize; + cpl_size aux = (cpl_size)(a + (a < 0 ? -0.5 : 0.5)); + nbsize = CPL_MAX(aux, CPL_MIN(nbsize, CPL_MIN(nbsizx, nbsizy))); + nbsize = CPL_MIN( nx, CPL_MIN(ny, nbsize )); + + /* Divide the map into partitions */ + cpl_size nbx = nx / nbsize; + cpl_size nby = ny / nbsize; + + /* Same for background values array */ + double **bvals = cpl_malloc(nby * sizeof(double *)); + for (cpl_size l = 0; l < nby; l++) { + bvals[l] = cpl_malloc(nbx * sizeof(double)); + } + + /* Store some of this away for use later */ + ap->backmap.nbx = nbx; + ap->backmap.nby = nby; + ap->backmap.nbsize = nbsize; + ap->backmap.bvals = bvals; + + /* create cpl image with mask from raw data */ + cpl_image *image = cpl_image_wrap_double(nx, ny, map); + cpl_mask *image_mask = cpl_image_get_bpm(image); + cpl_binary *image_mask_data = cpl_mask_get_data(image_mask); + + /* Add additional bad pixels if present*/ + for (cpl_size i = 0; i < nx * ny ; i++){ + if ( map[i] == nullval + || mflag[i] == MF_ZEROCONF + || mflag[i] == MF_STUPID_VALUE + || mflag[i] == MF_SATURATED ) + { + image_mask_data[i] = CPL_BINARY_1; + } + } + + /* sigclip stepped grid */ + cpl_size steps_x = nbx; + cpl_size steps_y = nby; + cpl_size sx = CPL_MAX(nx / steps_x, 1); + cpl_size sy = CPL_MAX(ny / steps_y, 1); + cpl_matrix *x = matrix_linspace(sx / 2, nx, sx); + cpl_matrix *y = matrix_linspace(sy / 2, ny, sy); + cpl_size filter_size_x = nbsize / 2; + cpl_size filter_size_y = nbsize / 2; + cpl_image *imgtmp_mod = hdrl_sigclipfilter_image_grid(image, x, y, filter_size_x, filter_size_y); + + /* interpolate remaining bad pixels */ + cpl_detector_interpolate_rejected(imgtmp_mod); + + cpl_matrix_delete(x); + cpl_matrix_delete(y); + + for (cpl_size l = 0; l < nby; l++) { + for (cpl_size j = 0; j < nbx; j++) { + int rej; + bvals[l][j] = cpl_image_get(imgtmp_mod, j + 1, l + 1, &rej); + } + } + + cpl_image_delete(imgtmp_mod); + cpl_image_unwrap(image); + + /* filter raw background values */ + hdrl_bfilt(bvals, nbx, nby); + + /* compute average sky level */ + double *work = cpl_malloc(nbx * nby * sizeof(double)); + + cpl_size k = 0; + for (cpl_size l = 0; l < nby; l++) { + for (cpl_size j = 0; j < nbx; j++) { + work[k++] = bvals[l][j]; + } + } + + sort_array((void *)work, k, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + double avsky = work[(k) / 2]; + cpl_free(work); + + /* ok now correct map for background variations and put avsky back on */ + cpl_size nbsizo2 = nbsize / 2; + double fnbsize = 1. / (double)nbsize; + for (k = 0; k < ny; k++) { + + cpl_size kk = k * nx; + + /* Nearest background pixel vertically */ + cpl_size iby = (k + 1 + nbsizo2) / nbsize; + cpl_size ibyp1 = iby + 1; + iby = CPL_MIN(nby, CPL_MAX(1, iby)); + ibyp1 = CPL_MIN(nby, ibyp1); + + double dely = (k + 1. - nbsize*iby + nbsizo2) * fnbsize; + + for (cpl_size j = 0; j < nx; j++) { + + if (map[kk+j] == nullval) + continue; + + /* nearest background pixel across */ + cpl_size ibx = (j + 1 + nbsizo2) / nbsize; + cpl_size ibxp1 = ibx + 1; + ibx = CPL_MIN(nbx, CPL_MAX(1, ibx)); + ibxp1 = CPL_MIN(nbx, ibxp1); + + double delx = (j + 1. - nbsize * ibx + nbsizo2) * fnbsize; + + /* bilinear interpolation to find background */ + double t1 = (1. - dely) * bvals[iby - 1][ibx - 1] + dely * bvals[ibyp1 - 1][ibx - 1]; + double t2 = (1. - dely) * bvals[iby - 1][ibxp1 - 1] + dely * bvals[ibyp1 - 1][ibxp1 - 1]; + double dsky = avsky - (1. - delx) * t1 - delx * t2; + + if (bkg_subtr) { + + map[kk+j] += dsky; + + /* Fill the background map */ + if (res->background) { + cpl_image_set(res->background, j + 1, k + 1, avsky - dsky); + } + } + } + } + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out robust background estimate over a whole input image + * + * @param ap The current ap structure + * @param nullval A null value used to flag bad pixels + * @param skymed Output sky median + * @param skysig Output sky noise + * + * @return CPL_ERROR_NONE if all went well and CPL_ERROR_ILLEGAL_INPUT + * if there aren't enough good values to do the calculation. + * + * Description: + * The image is analysed to work out a robust estimate of the background + * median, and sigma. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_backstats( + ap_t *ap, double nullval, double *skymed, double *skysig) +{ + /* Get some info from the ap structure */ + double *map = ap->indata; + cpl_size nx = ap->lsiz; + cpl_size ny = ap->csiz; + unsigned char *mflag = ap->mflag; + + cpl_image *ima_wrp = cpl_image_wrap_double(nx, ny, map); + cpl_mask *image_mask = cpl_image_get_bpm(ima_wrp); + cpl_binary *image_mask_data = cpl_mask_get_data(image_mask); + + /* Add additional bad pixels if present*/ + for (cpl_size i = 0; i < nx * ny ; i++){ + if ( map[i] == nullval + || mflag[i] == MF_ZEROCONF + || mflag[i] == MF_STUPID_VALUE + || mflag[i] == MF_SATURATED ) + { + image_mask_data[i] = CPL_BINARY_1; + } + } + + /* do kappa-sigma clipping to thresh out basic outliers */ + cpl_size rej_new; + + cpl_size niter = 30; + for (cpl_size i = 0; i < niter; i++ ) { + + double mad; + double median = cpl_image_get_mad(ima_wrp, &mad); + double stdev = mad * CPL_MATH_STD_MAD; + + double kappa_low = 2.5; + double lo_cut = median - kappa_low * stdev; + + double kappa_high = 2.5; + double hi_cut = median + kappa_high * stdev; + + cpl_size rej_orig = cpl_image_count_rejected(ima_wrp); + + if (lo_cut < hi_cut) { + cpl_mask_threshold_image(image_mask, ima_wrp, lo_cut, hi_cut, CPL_BINARY_0); + } + rej_new = cpl_image_count_rejected(ima_wrp); + + if (rej_orig == rej_new){ + break; + } + } + + /* Set the final answer. Here the normal mean and standard deviation is used + * as all outliers should be masked and thus the mean is more accurate */ + cpl_error_code e; + if (rej_new == nx * ny) { + *skymed = 0.; + *skysig = 0.; + e = CPL_ERROR_ILLEGAL_INPUT; + } else { + *skymed = cpl_image_get_mean( ima_wrp); + *skysig = cpl_image_get_stdev(ima_wrp); + e = CPL_ERROR_NONE; + } + + cpl_image_unwrap(ima_wrp); + + return e; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out estimated sky for a pixel position + * + * @param ap The current ap structure + * @param x The X position in question + * @param y The Y position in question + * @param skylev Output sky level at x, y + * @param skyrms Output sky noise at x, y + * + * Description: + * Given the coarse background grid, calculate the background at a + * given image pixel position by doing a bi-linear interpolation of + * it's position within the grid. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_backest( + ap_t *ap, double x, double y, double *skylev, double *skyrms) +{ + /* Define some local variables */ + cpl_size nbx = ap->backmap.nbx; + cpl_size nby = ap->backmap.nby; + cpl_size nbsize = ap->backmap.nbsize; + double **bvals = ap->backmap.bvals; + + /* Get closest pixel to the input location */ + cpl_size i = (cpl_size)(x + (x < 0 ? -0.5 : 0.5)); + cpl_size j = (cpl_size)(y + (y < 0 ? -0.5 : 0.5)); + + /* Now, work out where in the map to do the interpolation */ + cpl_size nbsizo2 = nbsize / 2; + + cpl_size ibx = (i + nbsizo2) / nbsize; + cpl_size ibxp1 = ibx + 1; + ibx = CPL_MIN(nbx, CPL_MAX(1, ibx)); + ibxp1 = CPL_MIN(nbx, ibxp1); + + cpl_size iby = (j + nbsizo2) / nbsize; + cpl_size ibyp1 = iby + 1; + iby = CPL_MIN(nby, CPL_MAX(1, iby)); + ibyp1 = CPL_MIN(nby, ibyp1); + + double fnbsize = 1. / (double)nbsize; + double delx = (i - nbsize * ibx + nbsizo2) * fnbsize; + double dely = (j - nbsize * iby + nbsizo2) * fnbsize; + + /* Now do a linear interpolation to find the background. Calculate MAD of + * the four adjacent background cells as an estimate of the RMS */ + + double t1 = (1. - dely) * bvals[iby - 1][ibx - 1] + dely * bvals[ibyp1 - 1][ibx - 1]; + double t2 = (1. - dely) * bvals[iby - 1][ibxp1 - 1] + dely * bvals[ibyp1 - 1][ibxp1 - 1]; + + *skylev = (1. - delx) * t1 + delx * t2; + + *skyrms = 0.25 * ( fabs(bvals[iby - 1][ibx - 1] - *skylev) + + fabs(bvals[ibyp1 - 1][ibx - 1] - *skylev) + + fabs(bvals[iby - 1][ibxp1 - 1] - *skylev) + + fabs(bvals[ibyp1 - 1][ibxp1 - 1] - *skylev) + ); +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief filter image on a grid + * + * @param ima image to filter + * @param x row vector of coordinates to filter on + * @param y row vector of coordinates to filter on + * @param filtersize_x size of the median filter + * @param filtersize_y size of the median filter + * + * @return filtered image of size of the grid + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_image * hdrl_sigclipfilter_image_grid( + const cpl_image *ima, cpl_matrix *x, cpl_matrix *y, + cpl_size filtersize_x, cpl_size filtersize_y) +{ + cpl_error_ensure(ima != NULL, CPL_ERROR_NULL_INPUT, + return NULL, "NULL input image"); + + cpl_error_ensure(filtersize_x > 0 && filtersize_y > 0 , CPL_ERROR_INCOMPATIBLE_INPUT, + return NULL, "All function parameters must be greater then Zero"); + + const cpl_size nx = cpl_image_get_size_x(ima); + const cpl_size ny = cpl_image_get_size_y(ima); + + const cpl_size steps_x = cpl_matrix_get_nrow(x); + const cpl_size steps_y = cpl_matrix_get_nrow(y); + + cpl_image *ima_local = cpl_image_new(steps_x, steps_y, CPL_TYPE_DOUBLE); + cpl_image_get_bpm(ima_local); + + HDRL_OMP(omp parallel for) + for (cpl_size iy = 0; iy < steps_y; iy++) { + + cpl_size middlep_y = cpl_matrix_get(y, iy, 0); + + for (cpl_size ix = 0; ix < steps_x; ix++) { + + cpl_size middlep_x = cpl_matrix_get(x, ix, 0); + + cpl_size lowerlimit_x = CPL_MAX(middlep_x - filtersize_x, 1 ); + cpl_size lowerlimit_y = CPL_MAX(middlep_y - filtersize_y, 1 ); + cpl_size upperlimit_x = CPL_MIN(middlep_x + filtersize_x, nx); + cpl_size upperlimit_y = CPL_MIN(middlep_y + filtersize_y, ny); + + cpl_image *ima_cut = cpl_image_extract(ima, lowerlimit_x, lowerlimit_y, upperlimit_x, upperlimit_y); + hdrl_image *ima_cut_hdrl = hdrl_image_create(ima_cut, NULL); + hdrl_value median = hdrl_image_get_sigclip_mean(ima_cut_hdrl, 2.5 ,2.5 ,3); + + cpl_image_set(ima_local, ix + 1, iy + 1, median.data); + + /* reject also if less than one 4th bad pixels as in original catalogue code */ + if ( isnan(median.data) + || cpl_image_count_rejected(ima_cut) >= 0.25 * 2 * (filtersize_x * filtersize_y)) + { + cpl_image_reject(ima_local, ix + 1, iy + 1); + } + + cpl_image_delete(ima_cut); + hdrl_image_delete(ima_cut_hdrl); + } + } + + return ima_local; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create linear space row vector + * @param start starting point + * @param stop end point, exclusive + * @param step step size + * + * @returns matrix with one row filled equally spaced points from start to end + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_matrix * matrix_linspace(cpl_size start, cpl_size stop, cpl_size step) +{ + cpl_matrix * x = cpl_matrix_new(stop / step, 1); + for (intptr_t i = 0; start + i * step < stop && i < stop / step; i++) { + cpl_matrix_set(x, i, 0, start + i * step); + } + return x; +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_background.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_background.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_background.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_background.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,35 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_BACKGROUND_H +#define HDRL_BACKGROUND_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_background( + ap_t *ap, cpl_size nbsize, double nullval, cpl_size bkg_subtr, hdrl_casu_result *res); +cpl_error_code hdrl_backstats( + ap_t *ap, double nullval, double *skymed, double *skysig); +void hdrl_backest( + ap_t *ap, double x, double y, double *skylev, double *skyrms); + + +#endif /* HDRL_BACKGROUND_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_casu.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_casu.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_casu.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_casu.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,427 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_conf.h" + +#include "hdrl_cat_classify.h" + + +/*** Prototypes ***/ + +static void hdrl_casu_xytoradec(const cpl_wcs *wcs, double x, double y, double *ra, double *dec); + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_casu hdrl_casu + * @ingroup Catalogue + * + * @brief Generic functions + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Wrap an table in a hdrl_casu_tfits wrapper + * + * @param tab The input cpl_table + * @param ehu The input propertylist for the extension header for the new object. + * + * @return The new hdrl_casu_tfits structure. + * + * Description: + * The input table is inserted into a hdrl_casu_tfits wrapper. A model + * hdrl_casu_tfits object may be provided to give the new object + * headers. If the ehu parameters are not null then they will + * be used as the propertylists for the new object. If not, then + * an attempt will be made to copy the propertylists from the model. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_casu_tfits * hdrl_casu_tfits_wrap(cpl_table *tab, cpl_propertylist *ehu) +{ + /* Check for nonsense input */ + if (tab == NULL) { + return NULL; + } + + /* Get the hdrl_casu_tfits structure */ + hdrl_casu_tfits *p = cpl_malloc(sizeof(hdrl_casu_tfits)); + + /* Load stuff in */ + p->table = tab; + + if (ehu != NULL) { + p->ehu = ehu; + } else { + p->ehu = cpl_propertylist_new(); + } + + return p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the propertylist for the extension header for a given + * hdrl_casu_tfits image. + * + * @param p The input hdrl_casu_tfits object + * + * @return The propertylist represeting the extension header of the input table + * (NULL if there is an error). + * + * Description: + * Get the propertylist for the extension header for a given hdrl_casu_tfits + * image. This is the extension that is relevant of the image. + * This should only need to be read once and then can be used to add + * things to the primary header. + */ +/* ---------------------------------------------------------------------------*/ +cpl_propertylist * hdrl_casu_tfits_get_ehu(hdrl_casu_tfits *p) +{ + /* Check for nonsense input */ + if (p == NULL) { + return NULL; + } + + return p->ehu; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the CPL table from the hdrl_casu_tfits object + * + * @param p The input hdrl_casu_tfits object + * + * @return The cpl_image object. NULL if there was an error. + * + * Description: + * Return the CPL table from the input hdrl_casu_tfits object. This table is + * suitable for use in all cpl_table routines. + */ +/* ---------------------------------------------------------------------------*/ +cpl_table * hdrl_casu_tfits_get_table(hdrl_casu_tfits *p) +{ + /* Check for nonsense input */ + if (p == NULL) { + return NULL; + } + + return p->table; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Free all the workspace associated with a hdrl_casu_fits object + * + * @param p The input hdrl_casu_tfits object + * + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_casu_tfits_delete(hdrl_casu_tfits *p) +{ + /* Check for nonsense input */ + if (p != NULL) { + + /* Free up workspace if it's been used */ + if (p->table ) cpl_table_delete(p->table); + if (p->ehu ) cpl_propertylist_delete(p->ehu); + + cpl_free(p); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Wrap an image in a hdrl_casu_fits wrapper + * + * @param im The input cpl_image + * + * @return The new hdrl_casu_tfits structure. + * + * Description: + * The input image is inserted into a hdrl_casu_fits wrapper. A model + * hdrl_casu_fits object may be provided to give the new object header. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_casu_fits * hdrl_casu_fits_wrap(cpl_image *im) +{ + /* Check for nonsense input */ + if (im == NULL) { + return NULL; + } + + /* Get the hdrl_casu_fits structure */ + hdrl_casu_fits *p = cpl_malloc(sizeof(hdrl_casu_fits)); + + /* Load stuff in */ + p->image = im; + p->ehu = cpl_propertylist_new(); + + return p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Copy a hdrl_casu_fits structure into another one. + * + * @param in The input hdrl_casu_fits object + * + * @return The output hdrl_casu_fits object. + * + * Description: + * An input hdrl_casu_fits structure is duplcated and returned + */ +/* ---------------------------------------------------------------------------*/ +hdrl_casu_fits * hdrl_casu_fits_duplicate(hdrl_casu_fits *in) +{ + /* Check for nonsense input */ + if (in == NULL) { + return NULL; + } + + /* Copy the hdrl_casu_fits structure */ + hdrl_casu_fits *p = cpl_malloc(sizeof(hdrl_casu_fits)); + p->image = cpl_image_duplicate(in->image); + p->ehu = cpl_propertylist_duplicate(hdrl_casu_fits_get_ehu(in)); + + return p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the propertylist for the extension header for a given + * hdrl_casu_fits image. + * + * @param p The input hdrl_casu_fits object + * + * @return The propertylist representing the extension header of the input + * image (NULL if there is an error). + * + * Description: + * Get the propertylist for the extension header for a given hdrl_casu_fits + * image. This is the extension that is relevant of the image. + * This should only need to be read once and then can be used to add + * things to the primary header. + */ +/* ---------------------------------------------------------------------------*/ +cpl_propertylist * hdrl_casu_fits_get_ehu(hdrl_casu_fits *p) +{ + /* Check for nonsense input */ + if (p == NULL) { + return NULL; + } + + return p->ehu; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the CPL image from the hdrl_casu_fits object + * + * @param p The input hdrl_casu_tfits object + * + * @return The cpl_image object. NULL if there was an error. + * + * Description: + * Return the CPL image from the input hdrl_casu_fits object. This image is + * suitable for use in all cpl_image routines. + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * hdrl_casu_fits_get_image(hdrl_casu_fits *p) +{ + /* Check for nonsense input */ + if (p == NULL) { + return NULL; + } + + return p->image; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Free all the workspace associated with a hdrl_casu_fits object + * + * @param p The input hdrl_casu_tfits object + * + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_casu_fits_delete(hdrl_casu_fits *p) +{ + /* Check for nonsense input */ + if (p != NULL) { + + /* Free up workspace if it's been used */ + if (p->image ) cpl_image_delete(p->image); + if (p->ehu ) cpl_propertylist_delete(p->ehu); + + cpl_free(p); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Generate object catalogues from input images + * + * @param infile The input frame with the image to be analysed + * @param conf The input frame with the confidence map + * @param wcs Input WCS structure + * @param ipix The minimum allowable size of an object + * @param threshold The detection threshold in sigma above sky + * @param icrowd If set then the deblending software will be used + * @param rcore The core radius in pixels + * @param nbsize The smoothing box size for background map estimation + * @param cattype The type of catalogue to be produced + * @param filtfwhm The FWHM of the smoothing kernel in the detection algorithm + * @param outtab The output table of object + * @param gainloc The detector gain in e-/ADU + * @param res + * + * @return CPL_ERROR_NONE if everything is ok or the concret error in other case + * + * Description: + * A frame and its confidence map are given. Detection thresholds and + * various other parameters are also given. Output is a table with all + * the extracted objects with object classifications included. + * + * @note QC headers: + * The following values will go into the extension propertylist + * - \b SATURATION: Saturation level in ADU + * - \b MEAN_SKY: Mean sky brightness in ADU + * - \b SKY_NOISE: Pixel noise at sky level in ADU + * - \b IMAGE_SIZE: The average FWHM of stellar objects in pixels + * - \b ELLIPTICITY: The average stellar ellipticity (1 - b/a) + * - \b APERTURE_CORR: The stellar aperture correction for 1x core flux + * - \b NOISE_OBJ: The number of noise objects + * @note Other headers: + * The following values will go into the extension propertylist + * - \b APCORxx: A series of aperture correction values for each of the core radius apertures. + * - \b SYMBOLx: A series of keywords to be used by GAIA for plotting ellipses + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_casu_catalogue( + hdrl_casu_fits *infile, hdrl_casu_fits *conf, + const cpl_wcs *wcs, cpl_size ipix, + double threshold, cpl_size icrowd, double rcore, + cpl_size bkg_subtr, cpl_size nbsize, + hdrl_catalogue_options cattype, + double filtfwhm, double gainloc, double saturation, + hdrl_casu_result *res) +{ + /* Inherited status */ + res->catalogue = NULL; + + /* Copy the input, the background is subtracted in-place */ + hdrl_casu_fits *in = hdrl_casu_fits_duplicate(infile); + + /* Call the main processing routine and get the catalogue */ + if(hdrl_catalogue_conf(in, conf, ipix, threshold, icrowd, rcore, bkg_subtr, + nbsize, cattype, filtfwhm, gainloc, saturation, res) != CPL_ERROR_NONE) { + hdrl_casu_fits_delete(in); + return cpl_error_get_code(); + } + + if (cpl_table_get_nrow(hdrl_casu_tfits_get_table(res->catalogue)) == 0) { + hdrl_casu_fits_delete(in); + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, "hdrl_cat_casu_catalogue - No objects found in image"); + return CPL_ERROR_DATA_NOT_FOUND; + } + + /* Do the classification */ + if (cattype & HDRL_CATALOGUE_CAT_COMPLETE) { + + if (hdrl_classify(res->catalogue, 16.) != CPL_ERROR_NONE) { + hdrl_casu_fits_delete(in); + return cpl_error_get_code(); + } + + + /* Update the RA and DEC of the objects in the object catalogue */ + if (wcs) { + + /* Update the RA and DEC of the objects in the object catalogue */ + cpl_table* cat = hdrl_casu_tfits_get_table(res->catalogue); + + double* x = cpl_table_get_data_double(cat, "X_coordinate"); + double* y = cpl_table_get_data_double(cat, "Y_coordinate"); + double* ra = cpl_table_get_data_double(cat, "RA"); + double* dec = cpl_table_get_data_double(cat, "DEC"); + + cpl_size n = cpl_table_get_nrow(cat); + for (cpl_size i = 0; i < n; i++) { + hdrl_casu_xytoradec(wcs, x[i], y[i], &(ra[i]), &(dec[i])); + } + } + + cpl_propertylist_set_comment(hdrl_casu_tfits_get_ehu(res->catalogue), + "ESO QC IMAGE_SIZE", "[pixel] Average FWHM of stellar objects"); + + } else { + + cpl_table_select_all( hdrl_casu_tfits_get_table(res->catalogue)); + cpl_table_erase_selected(hdrl_casu_tfits_get_table(res->catalogue)); + } + + hdrl_casu_fits_delete(in); + + return CPL_ERROR_NONE; +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Convert x,y -> ra,dec + * + * @param wcs Input WCS structure + * @param x Input X + * @param y Input Y + * @param ra Output RA + * @param dec Output Dec + * + * Description: + * A WCS structure is used to convert input x,y coordinates + * to equatorial coordinates. + */ +/* ---------------------------------------------------------------------------*/ +static void hdrl_casu_xytoradec(const cpl_wcs *wcs, double x, double y, double *ra, double *dec) +{ + /* Load up the information */ + cpl_matrix *from = cpl_matrix_new(1, 2); + double *xy = cpl_matrix_get_data(from); + xy[0] = x; + xy[1] = y; + + /* Call the conversion routine */ + cpl_matrix *to = NULL; + cpl_array *status = NULL; + cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD); + + /* Pass it back now */ + double *radec = cpl_matrix_get_data(to); + *ra = radec[0]; + *dec = radec[1]; + + /* Tidy and exit */ + cpl_matrix_delete(from); + cpl_matrix_delete(to); + cpl_array_delete(status); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_casu.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_casu.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_casu.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_casu.h 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,48 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_CASU_H +#define HDRL_CASU_H + + +#include "hdrl_cat_def.h" + + +hdrl_casu_fits * hdrl_casu_fits_wrap( cpl_image *im); +hdrl_casu_fits * hdrl_casu_fits_duplicate( hdrl_casu_fits *in); +cpl_propertylist * hdrl_casu_fits_get_ehu( hdrl_casu_fits *p); +cpl_image * hdrl_casu_fits_get_image( hdrl_casu_fits *p); +void hdrl_casu_fits_delete( hdrl_casu_fits *p); + +hdrl_casu_tfits * hdrl_casu_tfits_wrap( cpl_table *tab, cpl_propertylist *ehu); +cpl_propertylist * hdrl_casu_tfits_get_ehu( hdrl_casu_tfits *p); +cpl_table * hdrl_casu_tfits_get_table(hdrl_casu_tfits *p); +void hdrl_casu_tfits_delete( hdrl_casu_tfits *p); + +cpl_error_code hdrl_casu_catalogue( + hdrl_casu_fits *infile, hdrl_casu_fits *conf, + const cpl_wcs *wcs, cpl_size ipix, + double threshold, cpl_size icrowd, double rcore, + cpl_size bkg_subtr, cpl_size nbsize, + hdrl_catalogue_options cattype, + double filtfwhm, double gainloc, double saturation, + hdrl_casu_result *res); + + +#endif /* HDRL_CASU_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_classify.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_classify.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_classify.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_classify.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,1575 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_classify.h" + +#include "hdrl_cat_casu.h" +#include "hdrl_cat_table.h" +#include "hdrl_cat_utils_sort.h" + + +/*** DEFINES ***/ + +#define STEP 0.05 /* */ +#define NSAMPLE 150 /* */ +#define MAXLOOP 5 /* */ + +#define NCOLFULL 15 /* */ +#define FRAMECUT 0.05 /* */ + + +/*** GLOBAL VARIABLES (INTO FILE) ***/ + +/* Make the data arrays and header values global */ +static cpl_size g_nrows; +static double g_thresh; +static double g_skylevel; +static double g_skynoise; +static double g_rcore; + +/* Derived values */ +static cpl_size g_poor; +static double g_sigell, g_fitell, g_elllim, g_sigellf, g_fitellf, g_sigpa, g_fitpa; +static double g_blim, g_flim, g_cmin, g_cmax; +static double g_fit1, g_fit2, g_fit3, g_fit4, g_fit5, g_fit6, g_fit7; +static double g_fit_final, g_sigma_final; +static double *g_lower1, *g_lower2, *g_lower3, *g_upper1, *g_upper2, *g_upper3, *g_uppere; +static double g_avsig1, g_avsig2, g_avsig3, g_wt1, g_wt2, g_wt3; + +/* Classification values */ +static cpl_size g_nstar, g_ngal, g_njunk, g_ncmp; + +/* Values for the data quality and aperture corrections */ +static double g_avsat, g_corlim, g_cormin, g_apcpkht; +static double g_apcor1, g_apcor2, g_apcor3, g_apcor4, g_apcor5; +static double g_apcor6, g_apcor7; + +/* Data arrays */ +static double *g_workspace = NULL; +static cpl_table *g_catcopy = NULL; +static double *g_areal[NAREAL]; +static double *g_core_flux, *g_core1_flux, *g_core2_flux, *g_core3_flux; +static double *g_core4_flux, *g_core5_flux, *g_core6_flux; +static double *g_peak_height, *g_peak_mag, *g_ellipticity, *g_iso_flux; +static double *g_total_flux, *g_cls, *g_sig, *g_xpos, *g_ypos, *g_pa, *g_skylev; + +/* Column definitions */ +static double g_xmin, g_xmax, g_ymin, g_ymax; +static double g_pixlim; +static const char *g_colsfull[NCOLFULL] = { + "Aper_flux_3", "Aper_flux_1", "Aper_flux_4", "Aper_flux_5", "Aper_flux_6", + "Peak_height", "Ellipticity", "Isophotal_flux", "Isophotal_flux", + "Aper_flux_7", "X_coordinate","Y_coordinate", "Position_angle","Sky_level", + "Aper_flux_2"}; + + +/*** PROTOTYPES ***/ + +static void anhist(double *data, cpl_size n, double *medval, double *sigma); + +static void boundaries(double *core1, double *core2, double *core3, double medval1, + double sigma1, double medval2, double sigma2, cpl_size small, + double area1, double area2, + double *wt, double *avsig, double *lower, double *upper); +static void boundpk( double *core, double *pkht, double medval, double sigma, + double *wt, double *avsig, double *lower, double *upper); + +static void classify_run(void); + +static void classstats( double *core1, double *core2, cpl_size small, double cutlev, + double *medval, double *sigma); +static void classstats_ap0( double *medval, double *sigma); +static void classstats_ap67( double *mag1, double *mag2, double *medval, double *sigma); +static void classstats_el( void); +static void classstats_pa( void); +static void classstats_ellf( double); +static void classstats_final(void); + +static void medstat(double *array, cpl_size n, double *medval, double *sigval); + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_classify hdrl_classify + * @ingroup Catalogue + * + * @brief Do star/galaxy classification + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do star/galaxy classification + * + * @param catalogue The input catalogue + * @param minsize The minimum size in pixels of objects to be used in the analysis + * + * @return CPL_ERROR_CODE if everything is OK, the concrete error in other case + * + * Description: + * The information in an catalogue is scanned and each object + * is classified based on a number of shape criteria. + * + * @note QC headers: + * The following QC parameters are read from the catalogue extension. + * - \b MEAN_SKY: The mean sky found by catalogue. + * - \b SKY_NOISE: The sky noise found by catalogue. + * The following QC parameters are written to the catalogue extension. + * - \b IMAGE_SIZE: The average FWHM of stellar objects in the catalogue + * - \b ELLIPTICITY: The average stellar ellipticity. + * - \b POSANG: The average position angle on the image. + * - \b APERTURE_CORR: The aperture correction for an aperture with a radius of Rcore. + * - \b NOISE_OBJ: The number of noise objects detected on the image + * @note DRS headers: + * The following DRS parameters are read from the catalogue extension. + * - \b THRESHOL: The detection threshold used by catalogue + * - \b RCORE: The core radius used by catalogue + * - \b SEEING: The averaged seeing found by catalogue + * - \b NXOUT: The number of pixels in a row of the original image + * - \b NYOUT: The number of pixels in a column of the original image + * The following DRS parameters are written to the catalogue extension + * - \b CLASSIFD: Set if the catalogue has been classified + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_classify(hdrl_casu_tfits *catalogue, double minsize) +{ + /* Get the number of columns and decide which column labels to use */ + cpl_table *cat = hdrl_casu_tfits_get_table(catalogue); + if (cpl_table_get_ncol(cat) != NCOLS) { + return CPL_ERROR_INCOMPATIBLE_INPUT; + } + + /* Get some DQC info from the extra propertylist generated by catalogue */ + cpl_propertylist *extra = hdrl_casu_tfits_get_ehu(catalogue); + + double fwhm = cpl_propertylist_get_double(extra, "ESO DRS SEEING" ); + cpl_size nxout = cpl_propertylist_get_int( extra, "ESO DRS NXOUT" ); + cpl_size nyout = cpl_propertylist_get_int( extra, "ESO DRS NYOUT" ); + + g_thresh = cpl_propertylist_get_double(extra, "ESO DRS THRESHOL"); + g_skylevel = cpl_propertylist_get_double(extra, "ESO QC MEAN_SKY" ); + g_skynoise = cpl_propertylist_get_double(extra, "ESO QC SKY_NOISE"); + g_rcore = cpl_propertylist_get_double(extra, "ESO DRS RCORE" ); + + g_xmin = FRAMECUT * (double)nxout; + g_xmax = (1. - FRAMECUT) * (double)nxout; + g_ymin = FRAMECUT * (double)nyout; + g_ymax = (1. - FRAMECUT) * (double)nyout; + g_pixlim = minsize; + + /* Make a copy of the table as you are going to muck about with the + * column values. Get the column data */ + g_catcopy = cpl_table_duplicate(cat); + g_nrows = cpl_table_get_nrow(cat); + + g_cls = cpl_table_get_data_double(cat, "Classification"); + g_sig = cpl_table_get_data_double(cat, "Statistic"); + + const char *cols[ NCOLFULL]; + for (cpl_size i = 0; i < NCOLFULL; i++) { + cols[ i] = g_colsfull[ i]; + } + + g_core_flux = cpl_table_get_data_double(g_catcopy, cols[ 0]); + g_core1_flux = cpl_table_get_data_double(g_catcopy, cols[ 1]); + g_core2_flux = cpl_table_get_data_double(g_catcopy, cols[ 2]); + g_core3_flux = cpl_table_get_data_double(g_catcopy, cols[ 3]); + g_core4_flux = cpl_table_get_data_double(g_catcopy, cols[ 4]); + g_peak_height = cpl_table_get_data_double(g_catcopy, cols[ 5]); + g_ellipticity = cpl_table_get_data_double(g_catcopy, cols[ 6]); + g_iso_flux = cpl_table_get_data_double(g_catcopy, cols[ 7]); + g_total_flux = cpl_table_get_data_double(g_catcopy, cols[ 8]); + g_core5_flux = cpl_table_get_data_double(g_catcopy, cols[ 9]); + g_xpos = cpl_table_get_data_double(g_catcopy, cols[10]); + g_ypos = cpl_table_get_data_double(g_catcopy, cols[11]); + g_pa = cpl_table_get_data_double(g_catcopy, cols[12]); + g_skylev = cpl_table_get_data_double(g_catcopy, cols[13]); + g_core6_flux = cpl_table_get_data_double(g_catcopy, cols[14]); + + /* Get some workspace */ + g_workspace = cpl_malloc(2 * g_nrows * sizeof(*g_workspace)); + g_peak_mag = g_workspace; + + double *work = g_workspace + g_nrows; + + /* Convert fluxes to "magnitudes" */ + for (cpl_size i = 0; i < g_nrows; i++) { + + g_core_flux[i] = 2.5 * log10(CPL_MAX(g_core_flux[i], 1.)); + g_core1_flux[i] = 2.5 * log10(CPL_MAX(g_core1_flux[i], 1.)); + g_core2_flux[i] = 2.5 * log10(CPL_MAX(g_core2_flux[i], 1.)); + g_core3_flux[i] = 2.5 * log10(CPL_MAX(g_core3_flux[i], 1.)); + g_core4_flux[i] = 2.5 * log10(CPL_MAX(g_core4_flux[i], 1.)); + g_core5_flux[i] = 2.5 * log10(CPL_MAX(g_core5_flux[i], 1.)); + + double moff = 1. / (1. - pow((g_thresh / CPL_MAX(g_peak_height[i] ,g_thresh)), 0.6)); + g_iso_flux[i] = 2.5 * log10(CPL_MAX(moff *g_iso_flux[i], 1.)); + + g_peak_mag[i] = 2.5 * log10(CPL_MAX(g_peak_height[i] - g_skynoise, 0.1)); + } + + if (g_core6_flux != NULL) { + for (cpl_size i = 0; i < g_nrows; i++) { + g_core6_flux[i] = 2.5 * log10(CPL_MAX(g_core6_flux[i], 1.)); + } + } + + /* Now get the g_areal profile information. You'll need this in a sec */ + for (cpl_size i = 0; i < NAREAL; i++) { + char colname[32]; + sprintf(colname, "Areal_%ld_profile", (long int)i + 1); + g_areal[i] = cpl_table_get_data_double(g_catcopy, colname); + } + + /* What is the seeing like? */ + g_poor = 0; + if (fwhm > CPL_MAX(5., g_rcore * sqrt(2.))) g_poor = 1; + + /* Ok, now call the routine that does all the work */ + classify_run(); + + /* Right, now get a better estimate of the seeing */ + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + double ell = g_ellipticity[i]; + double core = g_core_flux[ i]; + double pkht = g_peak_height[i]; + + if (g_cls[i] == -1. && ell < g_elllim && core < g_corlim && pkht > 10. * g_thresh) { + + double ap = log(0.5 * pkht / g_thresh) / log(2.) + 1.; + cpl_size iap = (cpl_size)ap; + double delap = ap - (double)iap; + + if (iap > 0 && iap < NAREAL && g_areal[1][i] > 0.) { + + double area = g_areal[iap - 1][i]*(1. - delap) + g_areal[iap][i] * delap; + work[n++] = 2. * sqrt(area / CPL_MATH_PI); + } + } + } + + if (n > 2) { + + double junk; + medstat(work, n, &fwhm, &junk); + + /* Allow for finite pixel size */ + double arg = (0.25 * CPL_MATH_PI * fwhm * fwhm) - 1; + fwhm = 2. * sqrt(CPL_MAX(0., arg / CPL_MATH_PI)); + + } else { + fwhm = -1.; + } + + if (g_catcopy != NULL) { + cpl_table_delete(g_catcopy); + g_catcopy = NULL; + } + + + /* Qc keywords */ + cpl_propertylist_update_double(extra, "ESO QC IMAGE_SIZE", fwhm); + cpl_propertylist_update_double(extra, "ESO QC ELLIPTICITY", g_fitell); + cpl_propertylist_update_double(extra, "ESO QC POSANG", g_fitpa); + cpl_propertylist_update_double(extra, "ESO QC APERTURE_CORR", g_apcor3); + cpl_propertylist_update_int( extra, "ESO QC NOISE_OBJ", g_njunk); + cpl_propertylist_update_double(extra, "ESO QC SATURATION", g_avsat); + + cpl_propertylist_set_comment( extra, "ESO QC IMAGE_SIZE", "[pixels] Average FWHM of stellar objects"); + cpl_propertylist_set_comment( extra, "ESO QC ELLIPTICITY", "Average stellar ellipticity (1-b/a)"); + cpl_propertylist_set_comment( extra, "ESO QC POSANG", "[degrees] Median position angle"); + cpl_propertylist_set_comment( extra, "ESO QC APERTURE_CORR", "Stellar ap-corr 1x core flux"); + cpl_propertylist_set_comment( extra, "ESO QC NOISE_OBJ", "Number of noise objects"); + + + /* DRS keywords */ + cpl_propertylist_update_bool( extra, "ESO DRS CLASSIFD", 1); + + cpl_propertylist_set_comment( extra, "ESO DRS CLASSIFD", "Catalogue has been classified"); + + + /* Aperture correction keywords */ + cpl_propertylist_update_double(extra, "APCORPK", g_apcpkht); + cpl_propertylist_update_double(extra, "APCOR1", g_apcor1); + cpl_propertylist_update_double(extra, "APCOR2", g_apcor2); + cpl_propertylist_update_double(extra, "APCOR3", g_apcor3); + cpl_propertylist_update_double(extra, "APCOR4", g_apcor4); + cpl_propertylist_update_double(extra, "APCOR5", g_apcor5); + cpl_propertylist_update_double(extra, "APCOR6", g_apcor6); + cpl_propertylist_update_double(extra, "APCOR7", g_apcor7); + + cpl_propertylist_set_comment( extra, "APCORPK", "Stellar aperture correction - peak height"); + cpl_propertylist_set_comment( extra, "APCOR1", "Stellar aperture correction - 1/2x core flux"); + cpl_propertylist_set_comment( extra, "APCOR2", "Stellar aperture correction - core/sqrt(2) flux"); + cpl_propertylist_set_comment( extra, "APCOR3", "Stellar aperture correction - 1x core flux"); + cpl_propertylist_set_comment( extra, "APCOR4", "Stellar aperture correction - sqrt(2)x core flux"); + cpl_propertylist_set_comment( extra, "APCOR5", "Stellar aperture correction - 2x core flux"); + cpl_propertylist_set_comment( extra, "APCOR6", "Stellar aperture correction - 2*sqrt(2)x core flux"); + cpl_propertylist_set_comment( extra, "APCOR7", "Stellar aperture correction - 4x core flux"); + + + /* Write header information to help GAIA */ + cpl_propertylist_update_string(extra, "SYMBOL1", "{Ellipticity Position_angle Areal_1_profile Classification} {el"); + cpl_propertylist_update_string(extra, "SYMBOL2", "lipse blue (1.0-$Ellipticity) $Position_angle+90 {} $Classific"); + cpl_propertylist_update_string(extra, "SYMBOL3", "ation==1} {sqrt($Areal_1_profile*(1.0-$Ellipticity)/3.142)} : {"); + cpl_propertylist_update_string(extra, "SYMBOL4", "Ellipticity Position_angle Areal_1_profile Classification} {el"); + cpl_propertylist_update_string(extra, "SYMBOL5", "lipse red (1.0-$Ellipticity) $Position_angle+90 {} $Classific"); + cpl_propertylist_update_string(extra, "SYMBOL6", "ation==-1} {sqrt($Areal_1_profile*(1.0-$Ellipticity)/3.142)} :"); + cpl_propertylist_update_string(extra, "SYMBOL7", "{Ellipticity Position_angle Areal_1_profile Classification} {el"); + cpl_propertylist_update_string(extra, "SYMBOL8", "lipse green (1.0-$Ellipticity) $Position_angle+90 {} $Classifi"); + cpl_propertylist_update_string(extra, "SYMBOL9", "cation==0} {sqrt($Areal_1_profile*(1.0-$Ellipticity)/3.142)}"); + + + /* Clean up */ + if (g_workspace != NULL) { + cpl_free(g_workspace); + g_workspace = NULL; + } + + return CPL_ERROR_NONE; +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Analyse a histogram to give a median and sigma + * + * @param data The input data array + * @param n The size of the input data array + * @param medval The output median value + * @param sigma The output sigma value + * + * Description: + * The entries in a data array are histogrammed. The histogram is + * analsyed to work out a median and a sigma. A certain amount of + * smoothing is done and extra searches are also done to make sure + * that they median position estimate is the best it can be. + */ +/* ---------------------------------------------------------------------------*/ +static void anhist(double *data, cpl_size n, double *medval, double *sigma) +{ + #define MAXHIST 66536 /* maximum size of histogram array */ + + /* Get some workspace for the histogram */ + cpl_size *histo = cpl_calloc(MAXHIST, sizeof(cpl_size)); + double *sval = cpl_calloc(MAXHIST, sizeof(double)); + + /* Sort data into the histogram */ + for (cpl_size i = 0; i < n; i++) { + + double aux = data[i] / STEP; + cpl_size ilev = (cpl_size)(aux + (aux < 0. ? -0.5 : 0.5)); + + if (ilev >= -10 && ilev <= 100) { + ilev += 10; + histo[ilev] += 1; + } + } + + /* Now find the maximum of the histogram and its position ... */ + double hmax = 0.; + cpl_size imax = 0; + for (cpl_size i = 0; i < MAXHIST; i++) { + if (histo[i] > hmax) { + hmax = (double)(histo[i]); + imax = i; + } + } + + /* Trap for hmax == 0 */ + if (hmax == 0.) { + + if (n >= 10) { + *medval = data[(n+1)/2-1]; + *sigma = CPL_MATH_STD_MAD * 0.5 * (data[(3 * n + 3) / 4 - 1] - data[(n + 3) / 4 - 1]); + } else { + *medval = 0.; + *sigma = 1.; + } + + } else { + + /* Now do three point running average to see if there are other local maxime */ + double smax = 0.; + cpl_size ismax = 0; + for (cpl_size i = 1; i < MAXHIST-1; i++) { + sval[i] = (histo[i - 1] + histo[i] + histo[i + 1]) / 3.; + if (sval[i] > smax) { + smax = sval[i]; + ismax = i; + } + } + + if (ismax < imax) { + imax = ismax; + hmax = (double)(histo[imax]); + } + + /* Now check for lower local maxima */ + for (cpl_size i = imax-1; i > 0; i--) { + if (sval[i] >= sval[i + 1] && sval[i] >= sval[i - 1]) { + if (sval[i] > 0.5 * smax) + ismax = i; + } + } + + if (ismax < imax) { + imax = ismax; + hmax = (double)(histo[imax]); + } + + /* Now work out where the peak is */ + *medval = CPL_MIN((double)(imax - 10) * STEP, data[(n + 1) / 2 - 1]); + + double aux = 0.5 * hmax; + double hlim = (cpl_size)(aux + (aux < 0. ? -0.5 : 0.5)); + + cpl_size i = 1; + while (imax - i > 1 && histo[imax - i] > hlim) { + i++; + } + + if (imax - i >= 0) { + double ratio = hmax / CPL_MAX(1., (double)(histo[imax - i])); + *sigma = (double)i * STEP / (sqrt(2.) * CPL_MAX(1., log(ratio))); + *sigma = CPL_MAX(*sigma, 0.5 * STEP); + } else { + *sigma = 1.; + } + } + + /* Clean up */ + if (histo) cpl_free(histo); + if (sval) cpl_free(sval); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out boundaries of the stellar locus + * + * @param core1 The flux array for the primary aperture (in magnitudes) + * @param core2 The flux array for the secondary aperture in the case of good seeing + * @param core3 The flux array for the secondary aperture in the case of poor seeing + * @param medval1 The median of magnitude difference of core1 and core2 + * @param sigma1 The sigma of magnitude difference of core1 and core2 + * @param medval2 The median of magnitude difference of core1 and core3 + * @param sigma2 The sigma of magnitude difference of core1 and core3 + * @param small This parameter changes sign in internal computation + * @param area1 The area of the larger of the apertures for core1,core2 comparison + * @param area2 The area of the larger of the apertures for core1,core3 comparison + * @param wt An output weight for the estimate based on the scatter in the + * magnitude differences + * @param avsig An output average magnitude difference for the apertures used. + * @param lower An array delimiting the lower boundary + * @param upper An array delimiting the upper boundary + * + * Description: + * A number of flux estimates are given along with comparison statistics + * between those fluxes. + */ +/* ---------------------------------------------------------------------------*/ +static void boundaries(double *core1, double *core2, double *core3, double medval1, + double sigma1, double medval2, double sigma2, cpl_size small, + double area1, double area2, + double *wt, double *avsig, double *lower, double *upper) +{ + /* Get a workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + + /* Initialise the lower boundary */ + lower[0] = g_cmin; + lower[1] = g_cmax; + + double asign = (small == 1 ? -1. : 1.); + + /* Now collect the data */ + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + double c1 = core1[i]; + + if (!g_poor) { + + double c2 = core2[i]; + double dc = asign * (c2 - c1); + + if (dc > medval1 - 3. * sigma1 && c1 < g_blim - 3.) { + work[n++] = dc - medval1; + } + + } else { + + double c2 = core3[i]; + double dc = c2 - c1; + + if (dc > medval2 - 3. * sigma2 && c1 < g_blim - 3.) { + work[n++] = dc - medval2; + } + } + } + + /* Find the median */ + double junk; + medstat(work, n, avsig, &junk); + cpl_free(work); + + /* Work out sigma levels for both types of seeing */ + double xnoise; + if (! g_poor) { + *wt = CPL_MIN(5., CPL_MAX(1., * avsig / sigma1)); + xnoise = sqrt(area1) * g_skynoise; + } else { + *wt = CPL_MIN(2.5, CPL_MAX(1., * avsig / sigma2)); + xnoise = sqrt(area2) * g_skynoise; + } + + /* Now work out the boundaries */ + /* The term pow(10.0,(double)(0.4*xmag)); comes from the magitude formula */ + for (cpl_size i = 0; i < NSAMPLE; i++) { + + double xmag = 5. + (double)(i + 1) * 0.1; + double xflux = pow(10., (double)(0.4 * xmag)); + double ratio = 2.5 * log10(CPL_MAX(1. + xnoise / xflux, 0.)); + + if (! g_poor) { + lower[i] = medval1 - 3. * sqrt(sigma1 * sigma1 + ratio * ratio); + upper[i] = medval1 + 3. * sqrt(sigma1 * sigma1 + 0.5 * ratio * ratio); + } else { + lower[i] = medval2 - 3. * sqrt(sigma2 * sigma2 + ratio * ratio); + upper[i] = medval2 + 3. * sqrt(sigma2 * sigma2 + 0.5 * ratio * ratio); + } + } + + upper[0] = (g_poor == 0 ? medval1 : medval2); + upper[1] = upper[0]; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out boundaries of the stellar locus using peak flux + * + * @param core The flux array for the primary aperture (in magnitudes) + * @param pkht The array of magnitudes based on the peak height + * @param medval The median of magnitude difference of core and pkht + * @param sigma The sigma of magnitude difference of core and pkht + * @param wt An output weight for the estimate based on the scatter in the + * magnitude differences + * @param avsig An output average magnitude difference for the two estimates + * @param lower An array delimiting the lower boundary + * @param upper An array delimiting the upper boundary + * + * Description: + * The boundaries of the stellar locus are located using the core + * flux and the peak flux. + */ +/* ---------------------------------------------------------------------------*/ +static void boundpk(double *core, double *pkht, double medval, double sigma, + double *wt, double *avsig, double *lower, double *upper) +{ + /* Get the space for the boundry lines and a workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + + /* Collect the data */ + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + double c = core[i]; + double p = pkht[i]; + + if (c - p > medval - 3. * sigma && c < g_blim - 3.) { + work[n++] = c - p - medval; + } + } + + /* Find the median */ + double junk; + medstat(work, n, avsig, &junk); + cpl_free(work); + + *wt = CPL_MIN(5., CPL_MAX(1., *avsig / sigma)); + + /* Now work out boundaries */ + double xnoise = sqrt(CPL_MATH_PI * g_rcore * g_rcore) * g_skynoise; + for (cpl_size i = 0; i < NSAMPLE; i++) { + + double xmag = 5.0 + (double)(i + 1) * 0.1; + double pmag = xmag - medval; + + /* The term pow(10.0,(double)(0.4*xmag)) comes from the magnitude formula */ + double xflux = pow(10., (double)(0.4 * xmag)); + double pflux = pow(10., (double)(0.4 * pmag)); + + /* The term 2.5*log10 comes from the magnitude formula */ + double ratio = 2.5 * log10((double)(1. + CPL_MAX(xnoise / xflux, g_skynoise / pflux))); + + lower[i] = medval - 3. * sqrt(sigma * sigma + ratio * ratio); + upper[i] = medval + 3. * sqrt(sigma * sigma + 0.5 * ratio * ratio); + } + + upper[0] = medval; + upper[1] = upper[0]; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Main driver routine + * + * Description: + * This is the main driver routine for classify. It calls all the + * statistical routines and the boundary finding routines. It works + * out the aperture corrections and does the final classification for + * all objects in the catalogue. + */ +/* ---------------------------------------------------------------------------*/ +static void classify_run(void) +{ + #define BLIMDEF 15. + #define FLIMDEF 11. + #define CMINDEF 7.5 + #define CMAXDEF 15. + + /* Update faint limit to cope with short exposures */ + g_blim = BLIMDEF; + g_flim = FLIMDEF; + + /* the following formula comes from the magnitude computation */ + double fluxlim = 2.5 * log10((double)(5. * sqrt(CPL_MATH_PI * g_rcore * g_rcore) * g_skynoise)); + + g_flim = CPL_MIN(g_flim, CPL_MAX( 6., fluxlim + 3.)); + g_corlim = CPL_MIN(g_blim, CPL_MAX(12.5, fluxlim + 5.)); + g_cormin = CPL_MIN(g_blim, CPL_MAX(12.5, fluxlim + 5.)); + + /* Work out min and max core flux */ + g_cmin = CMINDEF; + g_cmax = CMAXDEF; + for (cpl_size i = 0; i < g_nrows; i++) { + double xflux = g_core_flux[i]; + g_cmin = CPL_MIN(g_cmin, xflux); + g_cmax = CPL_MAX(g_cmax, xflux); + } + g_cmin = CPL_MAX(fluxlim - 0.5, g_cmin); + g_cmax += 0.1; + g_cmax = CPL_MIN(g_cmax, 20.); + + /* Work out g_ellipticity stats for likely stellar objects */ + classstats_el(); + + /* Get the classification statistics for each of the tests */ + double sigma1, sigma2, sigma3, sigma4, sigma5, sigma6, sigma7; + classstats(g_core_flux, g_core1_flux, 1, 0.2, &g_fit1, &sigma1); /* Core flux vs 1/2 * core flux */ + classstats(g_core_flux, g_core3_flux, 0, 0.1, &g_fit2, &sigma2); /* Core flux vs 2 * core flux */ + classstats(g_core_flux, g_core2_flux, 0, 0.0, &g_fit4, &sigma4); /* Core flux vs sqrt(2) * core flux */ + classstats(g_core_flux, g_core4_flux, 0, 0.1, &g_fit5, &sigma5); /* Core flux vs 2 * sqrt(2) * core flux */ + classstats(g_core_flux, g_peak_mag, 1, 0.2, &g_fit3, &sigma3); /* Core flux vs Peak height */ + + /* Faint end g_ellipticity */ + classstats_ellf(fluxlim); + + /* Work out position angle stats for likely stellar objects */ + classstats_pa(); + + /* Get workspace for the boundary arrays */ + g_lower1 = cpl_malloc(NSAMPLE * sizeof(*g_lower1)); + g_lower2 = cpl_malloc(NSAMPLE * sizeof(*g_lower2)); + g_lower3 = cpl_malloc(NSAMPLE * sizeof(*g_lower3)); + g_upper1 = cpl_malloc(NSAMPLE * sizeof(*g_upper1)); + g_upper2 = cpl_malloc(NSAMPLE * sizeof(*g_upper2)); + g_upper3 = cpl_malloc(NSAMPLE * sizeof(*g_upper3)); + + /* Boundaries: (Core vs sqrt(2) * Core) or (Core vs 0.5 * Core) */ + boundaries(g_core_flux, g_core1_flux, g_core2_flux, g_fit1, + sigma1, g_fit4, sigma4, 1, + CPL_MATH_PI * g_rcore * g_rcore, 2. * CPL_MATH_PI * g_rcore * g_rcore, + &g_wt1, &g_avsig1, g_lower1, g_upper1); + + /* Boundaries: (Core vs 2 * Core) or (Core vs 2 * sqrt(2) * Core) */ + boundaries(g_core_flux, g_core3_flux, g_core4_flux, g_fit2, + sigma2, g_fit5, sigma5, 0, + 4. * CPL_MATH_PI * g_rcore * g_rcore, 8. * CPL_MATH_PI * g_rcore * g_rcore, + &g_wt2, &g_avsig2, g_lower2, g_upper2); + + /* Boundaries: (Core vs peak height) */ + boundpk(g_core_flux, g_peak_mag, g_fit3, sigma3, &g_wt3, &g_avsig3, g_lower3, g_upper3); + + /* Do final classification statistics and find the saturation limit */ + classstats_final(); + + /* Define final boundaries: The term pow(10.0,(0.4*fluxlim+1.5)); comes from the magitude formula */ + double *lower = cpl_malloc(NSAMPLE * sizeof(double)); + double *upper = cpl_malloc(NSAMPLE * sizeof(double)); + g_uppere = cpl_malloc(NSAMPLE * sizeof(*g_uppere)); + + double xnoise = sqrt(CPL_MATH_PI * g_rcore * g_rcore) * g_skynoise; + + double ratell; + ratell = xnoise / pow(10., 0.4 * (fluxlim + 1.5)); + ratell = 2.5 * log10(CPL_MAX(1. + ratell, 0.)); + + double ratscl; + ratscl = (pow((g_fitellf + 2. * g_sigellf - g_fitell), 2.) - 4. * g_sigell * g_sigell) / (4. * ratell * ratell); + ratscl = CPL_MAX(0.25, CPL_MIN(10., ratscl)); + + for (cpl_size i = 0; i < NSAMPLE; i++) { + + double xmag = 5. + 0.1 * (double)(i + 1); + double xflux = pow(10., 0.4 * xmag); + double ratio = 2.5 * log10(1. + xnoise / xflux); + + /* TODO: Check if it's correct the assign to upper[i] --> exist a factor multiply by zero */ + lower[i] = g_fit_final - 5. * sqrt( g_sigma_final * g_sigma_final + ratio * ratio); + upper[i] = g_fit_final + sqrt(9. * g_sigma_final * g_sigma_final + 0. * ratio * ratio); + + g_uppere[i] = g_fitell + 2. * sqrt(g_sigell * g_sigell + ratscl * ratio * ratio); + g_uppere[i] = CPL_MIN(0.5, g_uppere[i]); + } + + g_elllim = CPL_MIN(0.5, CPL_MAX(0.2, g_fitell + 2. * g_sigell)); + fluxlim = 2.5 * log10((double)(2.5 * sqrt(CPL_MATH_PI * g_rcore * g_rcore) * g_skynoise)); + + g_nstar = 0; + g_ngal = 0; + g_njunk = 0; + g_ncmp = 0; + + for (cpl_size i = 0; i < g_nrows; i++) { + + double ell = g_ellipticity[i]; + double core = g_core_flux[i]; + double pkht = g_peak_mag[i]; + + double aux1 = 10. * (core - 5.); + + cpl_size iarg = CPL_MAX(1, CPL_MIN(NSAMPLE, (cpl_size)(aux1 + (aux1 < 0. ? -0.5 : 0.5)))) - 1; + + double sig1; + double sig2; + if (! g_poor) { + sig1 = CPL_MAX(0.01, (g_fit1 - g_lower1[iarg]) / 3.); + sig2 = CPL_MAX(0.01, (g_fit2 - g_lower2[iarg]) / 3.); + } else { + sig1 = CPL_MAX(0.01, (g_fit4 - g_lower1[iarg]) / 3.); + sig2 = CPL_MAX(0.01, (g_fit5 - g_lower2[iarg]) / 3.); + } + double sig3 = CPL_MAX(0.01, (g_fit3 - g_lower3[iarg]) / 3.); + + double denom = (g_wt1 / sig1 + g_wt2 / sig2 + g_wt3 / sig3); + + double w1 = (g_wt1 / sig1) / denom; + double w2 = (g_wt2 / sig2) / denom; + double w3 = (g_wt3 / sig3) / denom; + + double statistic; + if (! g_poor) { + + double core_small = g_core1_flux[i]; + double core_large = g_core3_flux[i]; + + statistic = ( core - core_small - g_fit1 ) * w1 + + (CPL_MAX(core_large - core - g_fit2, -3. * sig2)) * w2 + + ( core - pkht - g_fit3 ) * w3; + } else { + + double core_midd = g_core2_flux[i]; + double core_large = g_core4_flux[i]; + + statistic = ( core_midd - core - g_fit4 ) * w1 + + (CPL_MAX(core_large - core - g_fit5, -3. * sig2)) * w2 + + ( core - pkht - g_fit3 ) * w3; + } + + g_cls[i] = -1.; + double aux2 = exp(CPL_MAX(0., core - g_corlim + 1.)); + double statcut = upper[iarg] + 3. * g_sigma_final * (aux2 - 1.); + if (statistic >= statcut) { + g_cls[i] = 1.; + } else if (statistic <= lower[iarg]) { + g_cls[i] = 0.; + } + + /* Save distance from the stellar locus */ + g_sig[i] = (statistic - g_fit_final) / ((g_fit_final - lower[iarg]) / 5.); + + /* Right, now here are lots of overrides for special circumstances */ + + /* Too spikey? -> junk */ + if (core - pkht - g_fit3 < -4. * sig3) g_cls[i] = 0.; + + /* Elliptical star? -> compact */ + double ellbound = CPL_MAX(g_elllim, g_uppere[iarg]); + if (ell > ellbound && g_cls[i] == -1. && core < g_flim && g_sig[i] > -2.) g_cls[i] = -2.; + + /* Saturated? -> star */ + if (core > g_corlim && statistic >= lower[iarg]) g_cls[i] = -1.; + + /* Too elliptical? -> junk */ + if (ell > 0.9 && core < g_corlim) g_cls[i] = 0.; + + /* Too faint? -> junk */ + if (core < fluxlim) g_cls[i] = 0.; + + + /* Now count how many you have of each */ + if (g_cls[i] == -1.) { + g_nstar++; + } else if (g_cls[i] == 1.) { + g_ngal++; + } else if (g_cls[i] == -2.) { + g_ncmp++; + } else { + g_njunk++; + } + } + cpl_free(lower); + cpl_free(upper); + + /* Do stats to get the aperture corrections */ + classstats_ap67(g_core5_flux, g_core3_flux, &g_fit6, &sigma6); + classstats_ap67(g_core_flux, g_core6_flux, &g_fit7, &sigma7); + g_fit6 += g_fit2; + + double fit0; + double sigma0; + classstats_ap0(&fit0, &sigma0); + fit0 = CPL_MAX(g_fit6, fit0); + + /* pkht */ + g_apcpkht = fit0 + g_fit3; + + g_apcor1 = fit0 + g_fit1; /* 0.5 * core */ + g_apcor2 = fit0 + g_fit7; /* 1 / sqrt(2) * core */ + g_apcor3 = fit0; /* core */ + g_apcor4 = fit0 - g_fit4; /* sqrt(2) * core */ + g_apcor5 = fit0 - g_fit2; /* 2 * core */ + g_apcor6 = fit0 - g_fit5; /* 2 * sqrt(2) * core */ + g_apcor7 = fit0 - g_fit6; /* 4 * core */ + + /* Now do a better job on the saturation */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + + cpl_size ii = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + double ell = g_ellipticity[i]; + double core = g_core_flux[i]; + double pkht = CPL_MAX(g_thresh, g_peak_height[i]) + g_skylev[i]; + + if ( ( ( ell < g_elllim + && core > g_flim + && g_cls[i] == -1 + && g_sig[i] >= 5. + && g_areal[0][i] >= g_pixlim + ) + || pkht >= 0.9 * g_avsat + ) + && g_xpos[i] >= g_xmin + && g_xpos[i] <= g_xmax + && g_ypos[i] >= g_ymin + && g_ypos[i] <= g_ymax + ){ + work[ii++] = pkht; + } + } + + double avsatnew; + if (ii > 0) { + double junk; + medstat(work,ii,&avsatnew,&junk); + avsatnew = CPL_MAX(10000.0+g_skylevel,avsatnew); + } else { + avsatnew = 10000.0 + g_skylevel; + } + + g_avsat = avsatnew; + + /* Clean up */ + cpl_free(work); + + if (g_lower1 != NULL) {cpl_free(g_lower1); g_lower1 = NULL;} + if (g_lower2 != NULL) {cpl_free(g_lower2); g_lower2 = NULL;} + if (g_lower3 != NULL) {cpl_free(g_lower3); g_lower3 = NULL;} + + if (g_upper1 != NULL) {cpl_free(g_upper1); g_upper1 = NULL;} + if (g_upper2 != NULL) {cpl_free(g_upper2); g_upper2 = NULL;} + if (g_upper3 != NULL) {cpl_free(g_upper3); g_upper3 = NULL;} + + if (g_uppere != NULL) {cpl_free(g_uppere); g_uppere = NULL;} +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median difference between two magnitude estimates + * + * @param core1 The flux array for the first aperture (in magnitudes) + * @param core2 The flux array for the second aperture (in magnitudes) + * @param small Set if the second aperture is smaller than the first + * @param cutlev An upper limit to the allowed value of the magnitude difference + * @param medval The output median magnitude difference + * @param sigma The output sigma in magnitude difference + * + * Description: + * The difference between the magnitudes of two different apertures + * is calculated for all objects in a list. + */ +/* ---------------------------------------------------------------------------*/ +static void classstats(double *core1, double *core2, cpl_size small, double cutlev, + double *medval, double *sigma) { + + /* Initialise the output values to something stupid */ + *medval = 0.0; + *sigma = 1.0e6; + + double amult = (small == 1 ? -1. : 1.); + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + double *dc = cpl_malloc(g_nrows * sizeof(double)); + + /* Work out differences */ + for (cpl_size i = 0; i < g_nrows; i++) { + dc[i] = amult * (core2[i] - core1[i]); + } + + /* Do an iteration loop */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + double sigmaold = *sigma; + + /* Ok, gather up all the stats */ + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + /* Clipping criteria */ + if ( g_ellipticity[i] < g_elllim + && core1[i] < g_blim + && core1[i] > g_flim + && fabs(dc[i] - *medval) < 3.*(*sigma) + && g_xpos[i] >= g_xmin + && g_xpos[i] <= g_xmax + && g_ypos[i] >= g_ymin + && g_ypos[i] <= g_ymax + && g_areal[0][i] >= g_pixlim) + { + if (iloop > 0 || (iloop == 0 && dc[i] >= cutlev)) { + work[n++] = dc[i]; + } + } + } + + /* Sort the work array and find the median and sigma */ + if (n > 0) { + + sort_array(work, n, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + if (iloop == 0) { + + anhist( work, n, medval, sigma); + + } else { + + medstat(work, n, medval, sigma); + + *sigma = CPL_MIN(sigmaold, *sigma); + } + + } else { + + *medval = 0.; + *sigma = 0.01; + } + + /* Just in case ... */ + *sigma = CPL_MAX(*sigma, 0.01); + } + + /* Clean up */ + cpl_free(work); + cpl_free(dc); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median ellipticity of the sample + * + * Description: + * The median ellipticity of the sample is calculated interatively + */ +/* ---------------------------------------------------------------------------*/ +static void classstats_el(void) +{ + /* Initialise the mean and sigma to something stupid */ + g_sigell = 1.e6; + g_fitell = 0.; + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + + /* Do iteration loop */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + if ( g_ellipticity[i] < 0.5 + && g_core_flux[i] < g_blim + && g_core_flux[i] > g_flim + && fabs(g_ellipticity[i] - g_fitell) < 2. * g_sigell + && g_xpos[i] >= g_xmin + && g_xpos[i] <= g_xmax + && g_ypos[i] >= g_ymin + && g_ypos[i] <= g_ymax + && g_areal[0][i] >= g_pixlim) + { + work[n++] = g_ellipticity[i]; + } + } + + if (n > 2) { + medstat(work, n, &g_fitell, &g_sigell); + } else { + g_fitell = 0.25; + g_sigell = 0.05; + } + } + + g_elllim = CPL_MIN(0.5, CPL_MAX(0.2, g_fitell + 2. * g_sigell)); + + /* Clean up */ + cpl_free(work); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median position angle of the sample + * + * Description: + * The median position angle of the sample is calculated interactively + */ +/* ---------------------------------------------------------------------------*/ +static void classstats_pa(void) +{ + /* Initialise the mean and sigma to something stupid */ + g_sigpa = 1.e6; + g_fitpa = 0.; + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + + /* Do iteration loop */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + if ( g_core_flux[i] < g_blim + && g_core_flux[i] > g_flim + && fabs(g_pa[i] - g_fitpa) < 2. * g_sigpa + && g_xpos[i] >= g_xmin + && g_xpos[i] <= g_xmax + && g_ypos[i] >= g_ymin + && g_ypos[i] <= g_ymax + && g_areal[0][i] >= g_pixlim) + { + work[n++] = g_pa[i]; + } + } + + if (n > 2) { + medstat(work, n, &g_fitpa, &g_sigpa); + } else { + g_fitpa = 0.; + g_sigpa = 0.05; + } + } + + /* Get out of here */ + cpl_free(work); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median ellipticity for faint objects + * + * @param fluxlim The flux limit (in magnitudes) + * + * Description: + * The median ellipticity is calculated for objects that are fainter + * than a given flux limit. + */ +/* ---------------------------------------------------------------------------*/ +static void classstats_ellf(double fluxlim) +{ + /* Initialise the mean and sigma to something stupid */ + g_sigellf = 1.e6; + g_fitellf = 0.; + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + + /* Do iteration loop */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + if ( g_ellipticity[i] < 0.75 + && g_core_flux[i] > fluxlim + 1. + && g_core_flux[i] < fluxlim + 2. + && fabs(g_ellipticity[i] - g_fitellf) < 2. * g_sigellf) + { + work[n++] = g_ellipticity[i]; + } + } + + if (n > 2) { + medstat(work, n, &g_fitellf, &g_sigellf); + } else { + g_fitellf = 0.25; + g_sigellf = 0.05; + } + } + + /* Get out of here */ + cpl_free(work); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median magnitude difference for large apertures + * + * @param medval The output median magnitude difference + * @param sigma The output sigma of the magnitude difference + * + * Description: + * The median magnitude difference for isophotal fluxes and a large + * aperture is calculated. + */ +/* ---------------------------------------------------------------------------*/ +static void classstats_ap0(double *medval, double *sigma) +{ + /* Initialise the output values to something stupid */ + *medval = 0.; + *sigma = 1.e6; + g_elllim = CPL_MIN(0.5, CPL_MAX(0.2, g_fitell + 2. * g_sigell)); + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + double *dc = cpl_malloc(g_nrows * sizeof(double)); + + /* Work out differences */ + for (cpl_size i = 0; i < g_nrows; i++) { + dc[i] = CPL_MAX(0., CPL_MAX(g_iso_flux[i], g_core5_flux[i])) - g_core_flux[i]; + } + + /* Do an iteration loop */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + /* Ok, gather up all the stats */ + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + /* Clipping criteria */ + if ( g_ellipticity[i] < g_elllim + && g_core_flux[i] < g_blim + && g_core_flux[i] > g_flim + && fabs(dc[i] - *medval) < 3. * (*sigma) + && g_cls[i] == -1. + && g_sig[i] < 5. + && g_xpos[i] >= g_xmin + && g_xpos[i] <= g_xmax + && g_ypos[i] >= g_ymin + && g_ypos[i] <= g_ymax + && g_areal[0][i] >= g_pixlim) + { + if (iloop > 0 || (iloop == 0 && dc[i] >= 0.)) { + work[n++] = dc[i]; + } + } + } + + /* Sort the work array and find the median and sigma */ + if (n > 0) { + + sort_array(work, n, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + if (iloop == 0) { + + anhist(work, n, medval, sigma); + + *sigma = CPL_MATH_STD_MAD * (*medval - work[(cpl_size)(0.25 * (double)(n + 3)) - 1]); + *sigma = CPL_MAX(0.025, *sigma); + + } else { + + double sigmanew; + medstat(work, n, medval, &sigmanew); + + *sigma = CPL_MIN(*sigma, sigmanew); + *sigma = CPL_MAX(0.01, *sigma); + } + + } else { + + *medval = 0.; + *sigma = 0.01; + } + + /* Just in case ... */ + *sigma = CPL_MAX(*sigma, 0.01); + } + + /* Clean up */ + cpl_free(work); + cpl_free(dc); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief + * + * @param mag1 + * @param mag2 + * @param medval The output median magnitude difference + * @param sigma The output sigma of the magnitude difference + * + * Description: + * + */ +/* ---------------------------------------------------------------------------*/ +static void classstats_ap67(double *mag1, double *mag2, double *medval, double *sigma) +{ + /* Initialise the output values to something stupid */ + *medval = 0.; + *sigma = 1.e6; + g_elllim = CPL_MIN(0.5, CPL_MAX(0.2, g_fitell + 2. * g_sigell)); + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + double *dc = cpl_malloc(g_nrows * sizeof(double)); + + /* Work out differences */ + for (cpl_size i = 0; i < g_nrows; i++) { + dc[i] = mag1[i] - mag2[i]; + } + + /* Do an iteration loop */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + /* Ok, gather up all the stats */ + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + /* Clipping criteria */ + if ( g_ellipticity[i] < g_elllim + && g_core_flux[i] < g_blim + && g_core_flux[i] > g_flim + && fabs(dc[i] - *medval) < 3. * (*sigma) + && g_cls[i] == -1. && g_sig[i] < 5. + && g_xpos[i] >= g_xmin + && g_xpos[i] <= g_xmax + && g_ypos[i] >= g_ymin + && g_ypos[i] <= g_ymax + && g_areal[0][i] >= g_pixlim) + { + if (iloop > 0 || (iloop == 0 && dc[i] >= 0.)) { + work[n++] = dc[i]; + } + } + } + + /* Sort the work array and find the median and sigma */ + if (n > 0) { + + sort_array(work, n, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + if (iloop == 0) { + + anhist(work, n, medval, sigma); + + *sigma = CPL_MATH_STD_MAD * (*medval - work[(cpl_size)(0.25 * (double)(n + 3)) - 1]); + *sigma = CPL_MAX(0.025, *sigma); + + } else { + + double sigmanew; + medstat(work, n, medval, &sigmanew); + + *sigma = CPL_MIN(*sigma, sigmanew); + *sigma = CPL_MAX(0.01, *sigma); + } + + } else { + *medval = 0.; + *sigma = 0.01; + } + + /* Just in case ... */ + *sigma = CPL_MAX(*sigma, 0.01); + } + + /* Clean up */ + cpl_free(work); + cpl_free(dc); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Routine to define the median classification statistic + * + * Description: + * The result of the previous boundary and statistical routines are + * combined to define the median classification statistic and its + * sigma. The curve is also investigated to see where saturation occurs + */ +/* ---------------------------------------------------------------------------*/ +static void classstats_final(void) +{ + /* Initialise */ + g_sigma_final = 1.e6; + g_fit_final = 0.; + + cpl_size ncls = 0; + + /* Get some workspace */ + double *work = cpl_malloc(g_nrows * sizeof(double)); + double *work1 = cpl_malloc(g_nrows * sizeof(double)); + double *statistic = cpl_malloc(g_nrows * sizeof(double)); + + /* Calculate the statistic now */ + for (cpl_size i = 0; i < g_nrows; i++) { + + double pkht = g_peak_mag[i]; + double core = g_core_flux[i]; + + double aux = 10. * (core - 5.); + cpl_size iarg = CPL_MAX(1, CPL_MIN(NSAMPLE, (cpl_size)(aux + (aux < 0. ? -0.5 : 0.5)))) - 1; + + double sig1; + double sig2; + if (!g_poor) { + sig1 = CPL_MAX(0.01, (g_fit1 - g_lower1[iarg]) / 3.); + sig2 = CPL_MAX(0.01, (g_fit2 - g_lower2[iarg]) / 3.); + } else { + sig1 = CPL_MAX(0.01, (g_fit4 - g_lower1[iarg]) / 3.); + sig2 = CPL_MAX(0.01, (g_fit5 - g_lower2[iarg]) / 3.); + } + double sig3 = CPL_MAX(0.01, (g_fit3 - g_lower3[iarg]) / 3.); + + double denom = (g_wt1 / sig1 + g_wt2 / sig2 + g_wt3 / sig3); + + double w1 = (g_wt1 / sig1) / denom; + double w2 = (g_wt2 / sig2) / denom; + double w3 = (g_wt3 / sig3) / denom; + + if (! g_poor) { + + double core_small = g_core1_flux[i]; + double core_large = g_core3_flux[i]; + + statistic[i] = (core - core_small - g_fit1) * w1 + + (core_large - core - g_fit2) * w2 + + (core - pkht - g_fit3) * w3; + + } else { + + double core_midd = g_core2_flux[i]; + double core_large = g_core4_flux[i]; + + statistic[i] = (core_midd - core - g_fit4) * w1 + + (core_large - core - g_fit5) * w2 + + (core - pkht - g_fit3) * w3; + } + } + + /* Iteration loop. Use only lower g_ellipticity images and relevant peak height range */ + for (cpl_size iloop = 0; iloop < MAXLOOP; iloop++) { + + double sigmaold = g_sigma_final; + + cpl_size n = 0; + for (cpl_size i = 0; i < g_nrows ; i++) { + + double ell = g_ellipticity[i]; + double core = g_core_flux[i]; + + if ( ell < g_elllim + && core < g_blim + && core > g_flim + && fabs((double)(statistic[i] - g_fit_final)) < 3. * g_sigma_final + && g_areal[0][i] >= g_pixlim) + { + work[n++] = statistic[i]; + } + + /* This information is to be used later to find the curvature of saturated region */ + if (core > g_corlim && iloop == MAXLOOP - 2) { + g_cls[ncls] = statistic[i]; + g_sig[ncls++] = core; + } + } + + /* Median defines general fit */ + if (n > 2) { + + sort_array(work, n, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + if (iloop == 0 && n > 10) { + anhist( work, n, &g_fit_final, &g_sigma_final); + } else { + medstat(work, n, &g_fit_final, &g_sigma_final); + } + + g_sigma_final = CPL_MAX(0.01, CPL_MIN(sigmaold, g_sigma_final)); + + } else { + + g_fit_final = 0.; + g_sigma_final = 0.01; + } + } + + /* Now work out the curvature in the saturated region */ + sort_array_index(g_sig, ncls, g_cls, HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + cpl_size ii = 0; + cpl_size idx = -1; + cpl_size iend = 0; + + double xcor = 12.5; + double corlim1 = 0.; + double corlim2 = 0.; + double corval1 = 0.; + double corval2 = 0.; + + while (iend == 0 && idx < ncls-1) { + + idx++; + if (g_sig[idx] > xcor+0.25 && ii >= 3) { + + double cfit; + double csig; + medstat(work, ii, &cfit, &csig); + + for (cpl_size iloop = 0; iloop < 3; iloop++) { + + cpl_size kk = 0; + for (cpl_size k = 0; k < ii; k++) { + if (work[k] <= cfit + 3. * csig) + work1[kk++] = work[k]; + } + + double junk; + medstat(work1, kk, &cfit, &junk); + } + + if (cfit <= g_fit_final + 3. * g_sigma_final) { + + corlim1 = xcor; + corval1 = cfit; + + } else { + + corlim2 = xcor; + corval2 = cfit; + + iend = 1; + } + + } else { + + work[ii++] = g_cls[idx]; + } + } + + /* Estimate where core measure and statistic become unreliable */ + if (iend == 1) { + g_corlim = corlim2 - 0.5 * (corval2 - g_fit_final - 3. * g_sigma_final) / (corval2 - corval1); + } else { + g_corlim = corlim1; + } + g_corlim = CPL_MAX(g_cormin, g_corlim); + + cpl_size kk = 0; + for (cpl_size i = 0; i < g_nrows; i++) { + + double core = g_core_flux[i]; + if (core >= g_corlim) { + work[kk++] = g_peak_height[i] + g_skylevel; + } + } + + if (kk > 0) { + + double junk; + medstat(work, kk, &g_avsat, &junk); + + g_avsat = CPL_MAX(10000. + g_skylevel, g_avsat); + + } else { + g_avsat = 10000. + g_skylevel; + } + + /* Clean up */ + cpl_free(work); + cpl_free(work1); + cpl_free(statistic); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median and sigma of an array + * + * @param array The input data array + * @param n The number of values in the data array + * @param medval The output median value + * @param sigma The output sigma value + * + * Description: + * The median of an array is calculated by sorting and choosing the + * middle value. The sigma is estimated by halving the space between + * the first and third quartiles and scaling by the appropriate factor + */ +/* ---------------------------------------------------------------------------*/ +static void medstat(double *array, cpl_size n, double *medval, double *sigval) +{ + /* Sort the array first, then choose the median. The sigma is defined + * as half the distance between the two quartile points multiplied by + * the appropriate scaling factor (1.48) */ + + if (n == 0) { + + *medval = 0.; + *sigval = 0.; + + } else { + + sort_array(array, n, sizeof(*array), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + cpl_size lev1 = ( n + 1) / 2; + cpl_size lev2 = (3 * n + 3) / 4; + cpl_size lev3 = ( n + 3) / 4; + + *medval = array[lev1 - 1]; + *sigval = CPL_MATH_STD_MAD * 0.5 * (array[lev2 - 1] - array[lev3 - 1]); + } +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_classify.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_classify.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_classify.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_classify.h 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,30 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_CLASSIFY_H +#define HDRL_CLASSIFY_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_classify(hdrl_casu_tfits *catalogue, double minsize); + + +#endif /* HDRL_CLASSIFY_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_conf.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_conf.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_conf.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_conf.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,500 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "hdrl_cat_conf.h" + +#include "hdrl_cat_apio.h" +#include "hdrl_cat_apline.h" +#include "hdrl_cat_table.h" +#include "hdrl_cat_background.h" +#include "hdrl_cat_terminate.h" + + +/*** Defines ***/ +#define NW 5 /* */ +#define STUPID_VALUE -1000 /* Minimum value of a pixel */ + + +/*** Internal global variables **/ + +static double *g_smoothed = NULL; +static double *g_smoothedc = NULL; +static unsigned char *g_mflag = NULL; +static double *g_indata = NULL; +static double *g_confdata = NULL; +static double *g_confsqrt = NULL; + +static ap_t g_ap; +static cpl_size g_freeconf = 0; + +static double g_weights[NW*NW]; +static cpl_size g_nx; +static cpl_size g_ny; + + +/*** Prototypes ***/ + +static void crweights(double filtfwhm); +static void convolve( cpl_size ir ); +static void clean_up( cpl_table *tab ); + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup Catalogue Catalogue + * + * @brief Main function of the catalogue + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do source extraction + * + * @param infile The input image + * @param conf The input confidence map + * @param ipix The minimum allowable size of an object + * @param threshold The detection threshold in sigma above sky + * @param icrowd If set then the deblending software will be used + * @param rcore The core radius in pixels + * @param nbsize The smoothing box size for background map estimation + * @param cattype The type of catalogue to be produced + * @param filtfwhm The FWHM of the smoothing kernel in the detection algorithm + * @param gain The header keyword with the gain in e-/ADU + * @param outcat The output table of object + * @param res + * + * @return CPL_ERROR_NONE if everything is ok. The concrete error in other case. + * + * @note QC headers: + * The following values will go into the image extension propertylist. + * - \b SATURATION: Saturation level in ADU. + * - \b MEAN_SKY: Mean sky brightness in ADU. + * - \b SKY_NOISE: Pixel noise at sky level in ADU. + * @note DRS headers: + * The following values will go into the image extension propertylist + * - \b SKYLEVEL: Mean sky brightness in ADU + * - \b SKYNOISE: Pixel noise at sky level in ADU + * The following values will go into the table extension propertylist + * - \b THRESHOL: The detection threshold in ADU + * - \b MINPIX: The minimum number of pixels per image + * - \b CROWDED: Flag for crowded field analysis + * - \b RCORE: The core radius for default profile fit in pixels + * - \b FILTFWHM: The FWHM of the smoothing kernel in the detection algorithm + * - \b SEEING: The average FWHM of stellar objects in pixels + * - \b XCOL: The column containing the X position + * - \b YCOL: The column containing the Y position + * - \b NXOUT: The X dimension of the original image array + * - \b NYOUT: The Y dimension of the original image array + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_catalogue_conf( + hdrl_casu_fits *infile, hdrl_casu_fits *conf, cpl_size ipix, + double threshold, cpl_size icrowd, double rcore, + cpl_size bkg_subtr, cpl_size nbsize, + cpl_size cattype, double filtfwhm, double gain, + double saturation, hdrl_casu_result *res) +{ + /* Initialize output */ + res->catalogue = NULL; + + /* Useful constants */ + double fconst = CPL_MATH_LOG2E; + double nullval = 0.; + cpl_size nobjects = 0; + + /* Open input image */ + cpl_table *tab = NULL; + cpl_image *map = hdrl_casu_fits_get_image(infile); + + if ((g_indata = cpl_image_get_data_double(map)) == NULL) { + clean_up(tab); + cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT, + "hdrl_cat_catalogue_conf - Error getting image data"); + return CPL_ERROR_NULL_INPUT; + } + + g_nx = cpl_image_get_size_x(map); + g_ny = cpl_image_get_size_y(map); + + cpl_size npts = g_nx * g_ny; + cpl_size npix = g_nx * g_ny; + + /* Open the associated confidence map, if it exists */ + cpl_image *cmap; + if (conf != NULL) { + + cmap = hdrl_casu_fits_get_image(conf); + if ((g_confdata = cpl_image_get_data(cmap)) == NULL) { + clean_up(tab); + cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT, + "hdrl_cat_catalogue_conf - Error getting confidence map data"); + return CPL_ERROR_NULL_INPUT; + } + + cpl_size nxc = cpl_image_get_size_x(cmap); + cpl_size nyc = cpl_image_get_size_y(cmap); + if ((g_nx != nxc) || (g_ny != nyc)) { + clean_up(tab); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "hdrl_cat_catalogue_conf - Input image and confidence dimensions don't match"); + return CPL_ERROR_INCOMPATIBLE_INPUT; + } + + g_freeconf = 0; + } else { + g_confdata = cpl_malloc(npts * sizeof(*g_confdata)); + for (cpl_size i = 0; i < npts; i++) { + g_confdata[i] = 100; + } + g_freeconf = 1; + cmap = NULL; + } + + /* Get g_mflag array for flagging saturated pixels */ + g_mflag = cpl_calloc(npix, sizeof(*g_mflag)); + + /* Open the g_ap structure and define some stuff in it */ + g_ap.lsiz = g_nx; + g_ap.csiz = g_ny; + g_ap.inframe = map; + g_ap.conframe = cmap; + + hdrl_apinit(&g_ap); + + g_ap.indata = g_indata; + g_ap.confdata = g_confdata; + g_ap.multiply = 1; + g_ap.ipnop = ipix; + g_ap.mflag = g_mflag; + g_ap.rcore = rcore; + g_ap.filtfwhm = filtfwhm; + g_ap.icrowd = icrowd; + g_ap.fconst = fconst; + + /* Open the output catalogue FITS table */ + cpl_size hdrl_xcol; + cpl_size hdrl_ycol; + hdrl_tabinit(&g_ap, &hdrl_xcol, &hdrl_ycol, cattype, &tab, res); + + /* Set up the data flags */ + for (cpl_size i = 0; i < npix; i++) { + if (g_confdata[i] == 0) { + g_mflag[i] = MF_ZEROCONF; + } else if (g_indata[i] < STUPID_VALUE) { + g_mflag[i] = MF_STUPID_VALUE; + } else { + g_mflag[i] = MF_CLEANPIX; + } + } + + /* Flag up regions where the value is above the saturation level*/ + for (cpl_size i = 0; i < npix ; i++) { + if (g_mflag[i] == MF_CLEANPIX && g_indata[i] > saturation) { + g_mflag[i] = MF_SATURATED; + } + } + + /* Compute the background variation and remove it from the data*/ + if (hdrl_background(&g_ap, nbsize, nullval, bkg_subtr, res) != CPL_ERROR_NONE) { + clean_up(tab); + return cpl_error_get_code(); + } + + /* Compute background statistics */ + double skymed; + double skysig; + if (hdrl_backstats(&g_ap, nullval, &skymed, &skysig) != CPL_ERROR_NONE) { + clean_up(tab); + return cpl_error_get_code(); + } + + /* Take mean sky level out of data. */ + if (bkg_subtr) { + for (cpl_size i = 0; i < g_nx * g_ny; i++) { + g_indata[i] -= skymed; + } + } + + /* Work out isophotal detection threshold levels */ + double thresh = threshold * skysig; + if (!bkg_subtr && thresh < skymed) { + clean_up(tab); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Bad background corrected input. Background estimation disabled " + "but image median larger than threshold * sigma."); + return CPL_ERROR_INCOMPATIBLE_INPUT; + } + + /* Minimum intensity for consideration */ + double xintmin = 1.5 * thresh * (double)ipix; + + /* Actual areal profile levels: T, 2T, 4T, 8T,...but written wrt T i.e. threshold as a power of 2 */ + double offset = log(thresh)*fconst; + + /* Get a bit of workspace for buffers */ + g_smoothed = cpl_malloc(g_nx * sizeof(*g_smoothed)); + g_smoothedc = cpl_malloc(g_nx * sizeof(*g_smoothedc)); + + /* Minimum size for considering multiple images */ + cpl_size mulpix = CPL_MAX(8, 2 * ipix); + + /* Define a few things more things in g_ap structure */ + g_ap.mulpix = mulpix; + g_ap.areal_offset = offset; + g_ap.thresh = thresh; + g_ap.xintmin = xintmin; + g_ap.sigma = skysig; + + if (bkg_subtr) { + g_ap.background = skymed; + g_ap.saturation = saturation - skymed; + } else { + g_ap.background = 0.; + g_ap.saturation = saturation; + } + + /* Set the weights */ + crweights(filtfwhm); + cpl_size nw2 = NW / 2; + + /* sqrt confdata, need as many rows as the convolution is wide */ + g_confsqrt = cpl_malloc(g_nx * NW * sizeof(*g_confsqrt)); + for (cpl_size j = 0; j < NW; j++) { + for (cpl_size i = 0; i < g_nx; i++) { + g_confsqrt[j * g_nx + i] = sqrt(0.01 * (double)(g_confdata[j * g_nx + i])); + } + } + + /* Right, now for the extraction loop. Begin by defining a group of three rows of data and confidence */ + for (cpl_size j = nw2; j < g_ny-nw2; j++) { + + double *current = g_indata + j * g_nx; + + if (j != nw2) { + + /* rotate buffer, could be a more efficient structure, but this sufficent for now */ + memmove(g_confsqrt, g_confsqrt + g_nx, g_nx * (NW - 1) * sizeof(*g_confsqrt)); + + /* fill last row of buffer */ + for (cpl_size i = 0; i < g_nx; i++) { + g_confsqrt[(NW - 1) * g_nx + i] = sqrt(0.01 * (double)(g_confdata[(j + nw2) * g_nx + i])); + } + } + + /* current row is the center of the buffer */ + double *currentc = g_confsqrt + nw2 * g_nx; + convolve(j); + + /* Do the detection now */ + hdrl_apline(&g_ap, current, currentc, g_smoothed, g_smoothedc, j, NULL); + + /* Make sure we're not overruning the stacks */ + if (g_ap.ibstack > g_ap.maxbl - g_ap.lsiz) hdrl_apfu(&g_ap); + if (g_ap.ipstack > g_ap.maxpa * 3 / 4 ) hdrl_apfu(&g_ap); + + /* See if there are any images to terminate */ + if (g_ap.ipstack > 1) { + hdrl_terminate(&g_ap, gain, &nobjects, tab, res); + } + } + + /* Post process. First truncate the cpl_table to the correct size and then work out an estimate of the seeing */ + cpl_table_set_size(tab, nobjects); + + if (hdrl_do_seeing(&g_ap, nobjects, tab) != CPL_ERROR_NONE) { + clean_up(tab); + return cpl_error_get_code(); + } + + /* Create a property list with extra parameters. First QC parameters */ + cpl_propertylist *extra = cpl_propertylist_duplicate(hdrl_casu_fits_get_ehu(infile)); + + + /* QC parameters */ + cpl_propertylist_update_double(extra, "ESO QC SATURATION", g_ap.saturation); + cpl_propertylist_update_double(extra, "ESO QC MEAN_SKY", g_ap.background); + cpl_propertylist_update_double(extra, "ESO QC SKY_NOISE", g_ap.sigma); + + cpl_propertylist_set_comment( extra, "ESO QC SATURATION", "[adu] Saturation level"); + cpl_propertylist_set_comment( extra, "ESO QC MEAN_SKY", "[adu] Median sky brightness"); + cpl_propertylist_set_comment( extra, "ESO QC SKY_NOISE", "[adu] Pixel noise at sky level"); + + + /* DRS parameters */ + cpl_propertylist_update_double(extra, "ESO DRS THRESHOL", g_ap.thresh); + cpl_propertylist_update_int( extra, "ESO DRS MINPIX", g_ap.ipnop); + cpl_propertylist_update_int( extra, "ESO DRS CROWDED", g_ap.icrowd); + cpl_propertylist_update_double(extra, "ESO DRS RCORE", g_ap.rcore); + cpl_propertylist_update_double(extra, "ESO DRS SEEING", g_ap.fwhm); + cpl_propertylist_update_double(extra, "ESO DRS FILTFWHM", g_ap.filtfwhm); + cpl_propertylist_update_int( extra, "ESO DRS XCOL", hdrl_xcol); + cpl_propertylist_update_int( extra, "ESO DRS YCOL", hdrl_ycol); + cpl_propertylist_update_int( extra, "ESO DRS NXOUT", g_nx); + cpl_propertylist_update_int( extra, "ESO DRS NYOUT", g_ny); + + cpl_propertylist_set_comment( extra, "ESO DRS THRESHOL", "[adu] Isophotal analysis threshold"); + cpl_propertylist_set_comment( extra, "ESO DRS MINPIX", "[pixels] Minimum size for images"); + cpl_propertylist_set_comment( extra, "ESO DRS CROWDED", "Crowded field analysis flag"); + cpl_propertylist_set_comment( extra, "ESO DRS RCORE", "[pixels] Core radius for default profile fit"); + cpl_propertylist_set_comment( extra, "ESO DRS SEEING", "[pixels] Average FWHM"); + cpl_propertylist_set_comment( extra, "ESO DRS FILTFWHM", "[pixels] FWHM of smoothing kernel"); + cpl_propertylist_set_comment( extra, "ESO DRS XCOL", "Column for X position"); + cpl_propertylist_set_comment( extra, "ESO DRS YCOL", "Column for Y position"); + cpl_propertylist_set_comment( extra, "ESO DRS NXOUT", "X Dimension of input image"); + cpl_propertylist_set_comment( extra, "ESO DRS NYOUT", "Y Dimension of input image"); + + res->catalogue = hdrl_casu_tfits_wrap(tab, extra); + + /* Clean up */ + clean_up(NULL); + + return CPL_ERROR_NONE; +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Create convolution kernel g_weights + * + * @param filtfwhm The FWHM of the Gaussian kernel + * + * Description: + * The convolution kernel for a Gaussian with a given FWHM is created. + */ +/* ---------------------------------------------------------------------------*/ +static void crweights(double filtfwhm) +{ + /* Get the kernel size */ + cpl_size nw2 = NW / 2; + + /* Set the normalisation constants: 2, 2.35 one should use CPL_MATH_FWHM_SIG */ + double gsigsq = 1. / (2. * pow(CPL_MAX(1., (double)filtfwhm) / 2.35, 2.)); + double renorm = 0.; + + /* Now work out the weights */ + cpl_size n = -1; + for (cpl_size i = -nw2; i <= nw2; i++) { + + double di = (double)i; + di *= gsigsq * di; + + for (cpl_size j = -nw2; j <= nw2; j++) { + + double dj = (double)j; + dj *= gsigsq * dj; + + n++; + + g_weights[n] = exp(-(di + dj)); + + renorm += g_weights[n]; + } + } + + /* Now normalise the weights */ + cpl_size nn = -1; + for (cpl_size i = -nw2; i <= nw2; i++) { + for (cpl_size j = -nw2; j <= nw2; j++) { + + nn++; + + g_weights[nn] /= renorm; + } + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Smooth the original data and confidence + * + * @param ir The row number of the input image to smooth + * + * Description: + * Smooth a line of original data and confidence by convolving with a Gaussian kernel. + */ +/* ---------------------------------------------------------------------------*/ +static void convolve(cpl_size ir) +{ + /* Zero the summations */ + for (cpl_size i = 0; i < g_nx; i++) { + + g_smoothed[i] = 0.; + g_smoothedc[i] = 0.; + } + + /* Now big is the smoothing kernel? */ + cpl_size nw2 = NW / 2; + + /* Now loop for each column */ + for (cpl_size ix = nw2; ix < g_nx - nw2; ix++) { + + + double sum = 0.; + double sumc = 0.; + + cpl_size n = -1; + for (cpl_size jy = ir - nw2; jy <= ir + nw2; jy++) { + + /* g_confsqrt [0..NW] rows */ + double *cdata = g_confsqrt + (jy - ir + nw2) * g_nx; + double *idata = g_indata + jy * g_nx; + + for (cpl_size jx = ix - nw2; jx <= ix + nw2; jx++) { + + n++; + + sum += g_weights[n] * idata[jx]; + sumc += g_weights[n] * idata[jx] * cdata[jx]; + } + } + + g_smoothed[ix] = sum; + g_smoothedc[ix] = sumc; + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Clean up the global variables + * + * Description: + * + */ +/* ---------------------------------------------------------------------------*/ +static void clean_up(cpl_table *tab) { + + if (tab) cpl_table_delete(tab); + + if (g_freeconf) { + if (g_confdata) {cpl_free(g_confdata); g_confdata = NULL;} + } + + if (g_confsqrt ) {cpl_free(g_confsqrt); g_confsqrt = NULL;} + if (g_smoothed ) {cpl_free(g_smoothed); g_smoothed = NULL;} + if (g_smoothedc) {cpl_free(g_smoothedc); g_smoothedc = NULL;} + if (g_mflag ) {cpl_free(g_mflag); g_mflag = NULL;} + + hdrl_apclose(&g_ap); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_conf.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_conf.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_conf.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_conf.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,36 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_CATALOGUE_CONF_H +#define HDRL_CATALOGUE_CONF_H + + +#include "hdrl_cat_def.h" +#include "hdrl_cat_casu.h" + + +cpl_error_code hdrl_catalogue_conf( + hdrl_casu_fits *infile, hdrl_casu_fits *conf, cpl_size ipix, + double threshold, cpl_size icrowd, double rcore, + cpl_size bkg_subtr, cpl_size nbsize, + cpl_size cattype, double filtfwhm, double gain, + double saturation, hdrl_casu_result *res); + + +#endif /* HDRL_CATALOGUE_CONF_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_def.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_def.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_def.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_def.h 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,168 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_CATALOGUE_DEF_H +#define HDRL_CATALOGUE_DEF_H + + +#include +#include + + +/*** DEFINES ***/ + +/* must not be followed by a semicolon! gcc on mac has omp + * but it doesn't work for nontrivial cases as libc lacks allocate */ +#if defined (_OPENMP) && !defined( __APPLE__) +#define HDRL_OMP(x) _Pragma (#x) +#else +#define HDRL_OMP(x) +#endif + +/* Catalogue generation parameters */ +#define IMNUM 200 /* Maximum number of images to be deblended */ +#define NPAR 16 /* Number of parameters in a basic results array */ +#define NRADS 13 /* Number of RANDS (RADII) */ +#define NAREAL 8 /* Number of areals profiles */ + +/* MFLAG values used for tracking the quality of individual pixels */ +#define MF_CLEANPIX 0 /* */ +#define MF_OBJPIX 1 /* */ +#define MF_SATURATED 2 /* */ +#define MF_ZEROCONF 3 /* */ +#define MF_STUPID_VALUE 4 /* */ +#define MF_POSSIBLEOBJ 5 /* */ + + +/*** DATA TYPES ***/ + +typedef struct { + cpl_size x; /* */ + cpl_size y; /* */ + double z; /* */ + double zsm; /* */ + cpl_size iobj; /* */ +} plstruct; + +typedef struct { + + cpl_size areal[NAREAL]; /* height above thresh of areal-prof cuts */ + + cpl_size lsiz; /* size of a line */ + cpl_size csiz; /* size of a column */ + cpl_size maxip; /* max no. of parents ever used. */ + cpl_size maxbl; /* size of pixel-storage block stack */ + cpl_size maxpa; /* size of parent-stack. */ + cpl_size ipnop; /* parent-number-of-pixels, min size of image */ + cpl_size nimages; /* count of images */ + cpl_size ipstack; /* parent-name stack pointer */ + cpl_size ibstack; /* pixel-block name stack pointer */ + double thresh; /* threshold for image detection */ + double background; /* background value */ + double sigma; /* median background sigma */ + cpl_size multiply; /* smoothing multiplication */ + double xintmin; /* minimum intensity for consideration */ + cpl_size mulpix; /* minimum size for considering multiple images */ + double areal_offset; /* offset in areal profile levels */ + double fconst; /* Normalisation constant for areal profiles */ + double saturation; /* saturation level from background analysis */ + cpl_size icrowd; /* true if deblending routine is to be used */ + + cpl_size *blink; /* block-link array */ + cpl_size *bstack; /* stack of pixel names */ + + struct { /* Image control block array */ + cpl_size first; /* link to first data block */ + cpl_size last; /* current last block */ + cpl_size pnop; /* Parent no. pixels (-1 = inactive) */ + cpl_size growing; + cpl_size touch; /* 0 = does not touch an edge */ + cpl_size pnbp; /* Parent no of bad pixels */ + } *parent; + + cpl_size *pstack; /* stack of parent names */ + plstruct *plessey; /* x,y,i storage array */ + cpl_size *lastline; /* Parents on last line */ + + cpl_image *inframe; /* Pointer to original image data frame */ + cpl_image *conframe; /* Pointer to original confidence map frame */ + double *indata; /* Pointer to original image data */ + double *confdata; /* Pointer to original confidence map data */ + unsigned char *mflag; /* Pointer to mflag array for tracking merges */ + cpl_mask *opmask; /* Object pixel mask */ + double rcore; /* Core radius for aperture photometry */ + double filtfwhm; /* FWHM of smoothing kernel in detection algorithm */ + plstruct *plarray; /* Plessey structure workspace for passing data to various processing routines */ + cpl_size npl; /* Size of the above */ + cpl_size npl_pix; /* Number of pixels in the above structure */ + double fwhm; /* Value of the seeing */ + + struct { + cpl_size nbx; /* X dimension of background map */ + cpl_size nby; /* Y dimension of background map */ + cpl_size nbsize; /* Size of a side of background map cell */ + double **bvals; /* Pointer to background map */ + } backmap; +} ap_t; + +typedef struct { + double x; /* x position */ + double y; /* y position */ + double total; /* total integrated intensity */ + cpl_size area; /* image area in pixels */ + double peak; /* peak image intensity above sky */ + double xx; /* 2nd moment x */ + double xy; /* 2nd moment cross term */ + double yy; /* 2nd moment y */ + double ecc; /* Eccentricity */ + cpl_size areal[NAREAL]; /* areal profile of image */ +} apmCat_t; + + +/* cpl_image functions */ +typedef struct { + cpl_image *image; /* */ + cpl_propertylist *ehu; /* */ +} hdrl_casu_fits; + +/* cpl_table functions */ +typedef struct { + cpl_table *table; /* */ + cpl_propertylist *ehu; /* */ +} hdrl_casu_tfits; + + +#define HDRL_SATURATION_INIT INFINITY + +typedef enum { + HDRL_CATALOGUE_BKG = 1, + HDRL_CATALOGUE_SEGMAP = 2, + HDRL_CATALOGUE_CAT_COMPLETE = 4, + HDRL_CATALOGUE_ALL = 7 +} hdrl_catalogue_options; + +/* Catalogue structure */ +typedef struct { + hdrl_casu_tfits *catalogue; /* cpl_table and property list */ + cpl_image *segmentation_map; /* */ + cpl_image *background; /* */ +} hdrl_casu_result; + + +#endif /* HDRL_CATALOGUE_DEF_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_extend.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_extend.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_extend.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_extend.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,241 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "hdrl_cat_extend.h" + +#include "hdrl_cat_statistics.h" +#include "hdrl_cat_polynm.h" + + +/*** Defines ***/ + +#define NACC 10 /* */ +#define NCOEF 4 /* Number of coeficients using in the call to the polynm */ + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_extend hdrl_extend + * @ingroup Catalogue + * + * @brief Do aperture integration + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do aperture integration + * + * @param ap The current ap structure + * @param xniso The isophotal flux + * @param xbar The X position of the object + * @param ybar The Y position of the object + * @param sxx Second moment in X + * @param syy Second moment in Y + * @param sxy Second moment cross term + * @param areal0 The first areal profile + * @param tmax The peak flux of the object + * @param ttotal The output total integrated flux + * + * @return CPL_ERROR_NONE if all went OK (Currently this is the only value). + * + * Description: + * The integrated flux of an object is calculated using matched. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_extend( + ap_t *ap, double xniso, double xbar, double ybar, + double sxx, double sxy, double syy, double areal0, double tmax, double *ttotal) +{ + /* Initialise a few things */ + double *map = ap->indata; + cpl_size nx = ap->lsiz; + cpl_size ny = ap->csiz; + double skysig = ap->sigma; + double thresh = ap->thresh; + unsigned char *mflag = ap->mflag; + + /* Calculate the eccentricity and position angle of the object + * CONSTANTS: 0.5, 4, 16, 0.9, 5, 3, 2 */ + double srr = CPL_MAX(0.5, sxx + syy); + double ecc = CPL_MIN(0.9, sqrt((syy - sxx) * (syy - sxx) + 4. * sxy * sxy) / srr); + double xx = 0.5 * (1. + ecc) * srr - sxx; + + double theta; + if (sxy == 0) { + theta = 0.; + } else if (xx == 0.) { + theta = CPL_MATH_PI_2; + } else { + theta = atan(sxy / xx); + } + + double ctheta = cos(theta); + double stheta = sin(theta); + + /* Eccentricity modified by noise effect. NB: 50 == 16*pi */ + ecc = CPL_MIN(0.9, sqrt( CPL_MAX( (syy - sxx) * (syy - sxx) + - 16. * CPL_MATH_PI * skysig * srr * srr * srr / (xniso * xniso) + + 4. * sxy * sxy, + 0.) ) / srr); + + /* Set initial aperture to be isophotal area */ + double a = sqrt(srr * (1. + ecc)); + double b = sqrt(srr * (1. - ecc)); + double stretch = sqrt(areal0 / (CPL_MATH_PI * a * b)); + + /* Number of isophotal radii to extend */ + double rad = CPL_MAX(1.1, (tmax - skysig) / thresh); + double sfac = CPL_MIN(5., CPL_MAX(2., 3. / sqrt(log(rad)))); + + a *= sfac * stretch; + b *= sfac * stretch; + + /* Clear accumulator */ + double accum[NACC]; + memset(accum, 0, NACC * sizeof(double)); + + /* Generate image boundaries. First for y */ + double climsq = CPL_MAX(1., (a * ctheta) * (a * ctheta) + (b * stheta) * (b * stheta)); + double clim = sqrt(climsq); + + double pt1 = sin(2. * theta) * (b * b - a * a); + double pt2 = (b * ctheta) * (b * ctheta) + (a * stheta) * (a * stheta); + double pt3 = (a * b) * (a * b); + + cpl_size jmin = CPL_MAX( 1, (cpl_size)(ybar - clim)); + cpl_size jmax = CPL_MIN(ny, (cpl_size)(ybar + clim + 1.)); + for (cpl_size jj = jmin; jj <= jmax; jj++) { + + /* Now for x */ + cpl_size kk = (jj-1)*nx; + + double c = (double)jj - ybar; + + double pa = climsq; + double pb = pt1 * c; + double pc = pt2 * c * c - pt3; + + double arg1 = sqrt(CPL_MAX(0., pb * pb - 4. * pa * pc)); + + double xliml = (-pb - arg1) / (2. * pa); + double xlimu = (-pb + arg1) / (2. * pa); + + cpl_size imin = CPL_MAX( 1, (cpl_size)(xbar + xliml )); + cpl_size imax = CPL_MIN(nx, (cpl_size)(xbar + xlimu + 1.)); + + double y = c; + + for (cpl_size ii = imin; ii <= imax; ii++) { + + if ( mflag[kk + ii - 1] == MF_CLEANPIX + || mflag[kk + ii - 1] == MF_OBJPIX + || mflag[kk + ii - 1] == MF_SATURATED) + { + double t = map[kk + ii - 1]; + double x = (double)ii - xbar; + + /* Accumulate elliptical isophotal areas */ + double xnew = x * ctheta - y * stheta; + double ynew = x * stheta + y * ctheta; + + double ellrad = 2. * sqrt( (ynew / a) * (ynew / a) + + (xnew / b) * (xnew / b)); + + cpl_size iupd = CPL_MIN(NACC, CPL_MAX(1, (cpl_size)((2. - ellrad) * (double)NACC) + 1)); + + for (cpl_size idx = 1; idx <= iupd; idx++) { + accum[NACC - idx] += t; + } + } + } + } + + /* Now find limiting intensity */ + if (xniso < 0.) { + for (cpl_size i = 0; i < NACC; i++) { + accum[i] = -accum[i]; + } + } + + hdrl_median(accum, NACC, 3); + + double xmax = 0.; + double xlim1 = -1.; + double xlim2 = -1.; + + double xcord[NACC]; + double xdat[NACC]; + for (cpl_size i = 0; i < NACC; i++) { + xcord[i] = i + 1; + xmax = CPL_MAX(xmax, accum[i]); + xdat[i] = accum[i]; + } + + double polycf[NCOEF]; + hdrl_polynm(xdat, xcord, NACC, polycf, NCOEF, 0); + + double pa = polycf[1]; + double pb = polycf[2] * 2.; + double pc = polycf[3] * 3.; + + double arg1 = sqrt(CPL_MAX(0., pb * pb - 4. * pa * pc)); + + if (pc != 0.) { + + double rt1 = (-pb + arg1) / (2. * pc); + double rt2 = (-pb - arg1) / (2. * pc); + + if (rt1 < (double)NACC && rt1 > 1.) { + + cpl_size ir = (cpl_size)rt1; + double t1 = rt1 - (double)ir; + + xlim1 = (1. - t1) * accum[ir - 1] + t1 * accum[ir]; + } + + if (rt2 < (double)NACC && rt2 > 1.) { + + cpl_size ir = (cpl_size)rt2; + double t1 = rt2 - ir; + + xlim2 = (1. - t1) * accum[ir - 1] + t1 * accum[ir]; + } + } + + double xlimit = CPL_MAX(xlim1, xlim2); + if (xlimit < 0.) { + xlimit = xmax; + } + + /* Update total intensity */ + if (xniso < 0.) { + xlimit = -xlimit; + } + *ttotal = xlimit; + + return CPL_ERROR_NONE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_extend.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_extend.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_extend.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_extend.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_EXTEND_H +#define HDRL_EXTEND_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_extend( + ap_t *ap, double xniso, double xbar, double ybar, + double sxx, double sxy, double syy, double areal0, double tmax, double *ttotal); + + +#endif /* HDRL_EXTEND_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_filter.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_filter.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_filter.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_filter.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,328 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_filter.h" + +#include "hdrl_cat_statistics.h" + + +/*** Prototypes ***/ + +static void filt1d( double ybuf[], cpl_size mpt, cpl_size mfilt); +static void hanning(double xbuf[], cpl_size npt); + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_filter hdrl_filter + * @ingroup Catalogue + * + * @brief Do bilinear median and linear filtering on background values + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do bilinear median and linear filtering on background values + * + * @param xbuf The input map to be smoothed + * @param nx The X dimension of the map + * @param ny The Y dimension of the map + * + * @return CPL_ERROR_NONE if all went well (Currently it's the only value). + * + * Description: + * A map is smoothed using sliding median and mean filters. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_bfilt(double **xbuf, cpl_size nx, cpl_size ny) +{ + /* Allocate temporary storage */ + double *ybuf = (double *)cpl_malloc(CPL_MAX(nx, ny) * sizeof(double)); + double *save = (double *)cpl_malloc((nx + 1) * ny * sizeof(double)); + + cpl_size mfilt = 5; + + /* median filter across */ + for (cpl_size k = 0; k < ny; k++) { + + for (cpl_size j = 0; j < nx; j++) { + + save[(nx + 1) * k + j] = xbuf[k][j]; + + ybuf[j] = xbuf[k][j]; + } + + filt1d(ybuf, nx, mfilt); + + for (cpl_size j = 0; j < nx; j++) { + xbuf[k][j] = ybuf[j]; + } + } + + /* and now down */ + for (cpl_size k = 0; k < nx; k++) { + + for (cpl_size j = 0; j < ny; j++) { + ybuf[j] = xbuf[j][k]; + } + + filt1d(ybuf, ny, mfilt); + + for (cpl_size j = 0; j < ny; j++) { + + /* make sure median filtered values are not large than original */ + if (save[(nx + 1) * j + k] > -1000.) { + xbuf[j][k] = CPL_MIN(save[(nx + 1) * j + k], ybuf[j]); + } + } + } + + /* now repeat with linear filters across */ + for (cpl_size k = 0; k < ny; k++) { + + for (cpl_size j = 0; j < nx; j++) { + ybuf[j] = xbuf[k][j]; + } + + hanning(ybuf, nx); + + for (cpl_size j = 0; j < nx; j++) { + xbuf[k][j] = ybuf[j]; + } + } + + /* and now down */ + for (cpl_size k = 0; k < nx; k++) { + + for (cpl_size j = 0; j < ny; j++) { + ybuf[j] = xbuf[j][k]; + } + + hanning(ybuf, ny); + + for (cpl_size j = 0; j < ny; j++) { + xbuf[j][k] = ybuf[j]; + } + } + + /* Free temporary storage */ + cpl_free((void *)ybuf); + cpl_free((void *)save); + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Pads out array with missing points and linearly extrapolates the ends + * + * @param x . + * @param n . + * + * Description: + * . + */ +/* ---------------------------------------------------------------------------*/ +void padext(double x[], cpl_size n) +{ + /* elements <= -1000.0 are treated as missing */ + cpl_size ii = 0; + while (ii < n && x[ii] <= -1000.) { + ii++; + } + cpl_size ilow = ii; + cpl_size ihih = 0; + + for (cpl_size i = ilow + 1; i < n; i++){ + + if (x[i] <= -1000.) { + + cpl_size ic = 1; + if (i < n - 1) { + + while (x[i + ic] <= -1000.) { + + ic++; + + if (i + ic >= n - 1) { + break; + } + } + } + + if (i + ic < n - 1){ + + double xlow = x[i - 1]; + double xhih = x[i + ic]; + + for (cpl_size j = 0; j < ic; j++){ + + double t2 = ((double)j + 1.) / ((double)ic + 1.); + double t1 = 1. - t2; + + x[i + j] = t1 * xlow + t2 * xhih; + } + } + + } else { + + ihih = i; + } + } + + + /* linear extrapolation of ends */ + if (ilow > 0 && ilow < n){ + + double slope; + if (ilow < n - 1) { + slope = x[ilow + 1] - x[ilow]; + } else { + slope = 0.; + } + + for (cpl_size i = 0; i < ilow; i++) { + x[i] = x[ilow] - slope * (ilow - i); + } + } + + if (ihih < n - 1) { + + double slope; + if (ihih > 0) { + slope = x[ihih] - x[ihih - 1]; + } else { + slope = 0.; + } + + for (cpl_size i = ihih + 1; i < n; i++) { + x[i] = x[ihih] + slope * (i - ihih); + } + } +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Does median filtering allowing for unmeasured entries + * + * @param ybuf . + * @param mpt . + * @param mfilt . + * + * Description: + * . + */ +/* ---------------------------------------------------------------------------*/ +static void filt1d(double ybuf[], cpl_size mpt, cpl_size mfilt) +{ + /* Allocate temporary storage */ + double *wbuf = (double *)cpl_malloc(mpt * sizeof(double)); + + cpl_size irc = 0; + for (cpl_size i = 0; i < mpt; i++){ + if (ybuf[i] > -1000.){ + wbuf[irc] = ybuf[i]; + irc++; + } + } + + if (irc != 0) { + + hdrl_median(wbuf, irc, mfilt); + + irc = 0; + for (cpl_size i = 0; i < mpt; i++){ + if (ybuf[i] > -1000.){ + ybuf[i] = wbuf[irc]; + irc++; + } + } + + padext(ybuf, mpt); + } + + /* Free temporary storage */ + cpl_free((void *)wbuf); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Performs linear filtering on array xbuf + * + * @param xbuf . + * @param npt . + * + * Description: + * . + */ +/* ---------------------------------------------------------------------------*/ +static void hanning(double xbuf[], cpl_size npt) +{ + cpl_size nfilt = 3; + if (npt <= nfilt) { + return; + } + + /* set first and last edges equal */ + cpl_size il = nfilt / 2; + + cpl_size ilow = CPL_MAX(3, nfilt / 4); + ilow = (ilow / 2) * 2 + 1; + + double sum = 0.; + for (cpl_size i = 0; i < ilow; i++) { + sum += xbuf[i]; + } + double xmns = sum / (double)ilow; + + sum = 0.; + for (cpl_size i = 0; i < ilow; i++) { + sum += xbuf[npt - 1 - i]; + } + double xmnf = sum / (double)ilow; + + /* allocate ybuf array */ + cpl_size nelem = npt + nfilt; /* Max. number of elements req'd */ + double *ybuf = (double *)cpl_malloc(nelem * sizeof(double)); + + /* reflect edges before filtering */ + for (cpl_size i = 0; i < il; i++) { + ybuf[i] = 2. * xmns - xbuf[il + ilow - 1 - i]; + ybuf[npt + i + il] = 2. * xmnf - xbuf[npt - i - ilow - 1]; + } + + for (cpl_size i = 0; i < npt; i++) { + ybuf[i + il] = xbuf[i]; + } + + /* do linear filtering on rest */ + for (cpl_size i = 0; i < npt; i++) { + /* 1-2-1 Hanning weighting */ + xbuf[i] = 0.25 * (ybuf[i] + 2. * ybuf[i + 1] + ybuf[i + 2]); + } + + /* clean up */ + cpl_free((void *) ybuf); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_filter.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_filter.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_filter.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_filter.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_FILTER_H +#define HDRL_FILTER_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_bfilt(double **xbuf, cpl_size nx, cpl_size ny); + +void padext(double x[], cpl_size n); + + +#endif /* HDRL_FILTER_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_moments.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_moments.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_moments.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_moments.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,124 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_moments.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_moments hdrl_moments + * @ingroup Catalogue + * + * @brief Do moments analysis on an object + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do moments analysis on an object in a Plessey array + * + * @param ap The current ap structure + * @param results The output array with the moments results. + * + * Description: + * The Plessey array is given from an ap structure for a single object. + * This routine does a basic zeroth, first and second moments analysis. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_moments(ap_t *ap, double results[]) { + + /* Initialise a few things */ + double xintmin = ap->xintmin; + plstruct *plarray = ap->plarray; + cpl_size np = ap->npl_pix; + + double xoff = (double)(plarray[0].x); + double yoff = (double)(plarray[0].y); + + double tmax = plarray[0].z; + + double xsum = 0.; + double ysum = 0.; + double tsum = 0.; + double xsum_w = 0.; + double ysum_w = 0.; + double wsum = 0.; + double xsumsq = 0.; + double ysumsq = 0.; + double xysum = 0.; + + /* Do a moments analysis on an object */ + for (cpl_size i = 0; i < np; i++) { + + double t = plarray[i].z; + if (t >= 0.) { + + double w = plarray[i].zsm; + + double x = (double)(plarray[i].x) - xoff; + double y = (double)(plarray[i].y) - yoff; + + xsum += t * x; + ysum += t * y; + tsum += t; + + xsum_w += w * t * x; + ysum_w += w * t * y; + wsum += w * t; + + xsumsq += x * x * t; + ysumsq += y * y * t; + xysum += x * y * t; + + tmax = CPL_MAX(tmax, plarray[i].z); + } + } + + /* Check that the total intensity is enough and if it is, then do the final results */ + if (tsum >= xintmin) { + + double xbar = xsum / tsum; + double ybar = ysum / tsum; + + double sxx = CPL_MAX(0., (xsumsq / tsum - xbar * xbar)); + double syy = CPL_MAX(0., (ysumsq / tsum - ybar * ybar)); + double sxy = xysum / tsum - xbar * ybar; + + xbar = CPL_MAX(1., CPL_MIN(ap->lsiz, xoff + xsum_w / wsum)); + ybar = CPL_MAX(1., CPL_MIN(ap->csiz, yoff + ysum_w / wsum)); + + results[0] = 1.; + results[1] = xbar; + results[2] = ybar; + results[3] = tsum; + results[4] = sxx; + results[5] = sxy; + results[6] = syy; + results[7] = tmax; + + } else { + + results[0] = -1.; + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_moments.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_moments.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_moments.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_moments.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,30 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_MOMENTS_H +#define HDRL_MOMENTS_H + + +#include "hdrl_cat_def.h" + + +void hdrl_moments(ap_t *ap, double results[]); + + +#endif /* HDRL_MOMENTS_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,760 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_overlp.h" + +#include "hdrl_cat_apio.h" +#include "hdrl_cat_apclust.h" +#include "hdrl_cat_polynm.h" +#include "hdrl_cat_terminate.h" +#include "hdrl_cat_utils_sort.h" + + +/*** Defines ***/ + +#define IDBLIM 10000 /* Maximum number of pixels to use in deblending */ +#define NITER 6 /* Number of iterations */ + + +/*** Internal global variables ***/ + +static double oldthr; +static double curthr; +static double nexthr; +static double lasthr; +static double xbar_start; +static double ybar_start; + + +/*** Prototypes ***/ + +static void moments_thr(ap_t *ap, double results[NPAR+1], cpl_size ipk[2]); +static void update_ov( double iap[NAREAL], double t, double thresh, double fconst, double offset); +static void check_term( ap_t *ap, cpl_size *nobj, double parm[IMNUM][NPAR+1], + cpl_size peaks[IMNUM][2], cpl_size *toomany); + +static int cmp_plstruct(const void *a, const void *b); + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_overlp hdrl_overlp + * @ingroup Catalogue + * + * @brief Deblend overlapping images + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Deblend overlapping images + * + * @param ap The current ap structure + * @param parm The parameter array for the deblended objects + * @param nbit The output number of objects found in the deblended object + * @param xbar The X position of the input object + * @param ybar The Y position of the input object + * @param total The total flux of the input object + * @param npix The number of pixels in the original object + * @param tmax The peak flux of the original object + * + * @return CPL_ERROR_NONE if all went OK (Currently this is the only value). + * + * Description: + * An array of pixels that are believed to be part of a single large + * object are analyzed with successively higher thresholds to see if + * they resolve into multiple objects. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_overlp( + ap_t *ap, double parm[IMNUM][NPAR], cpl_size *nbit, + double xbar, double ybar, double total, cpl_size npix, double tmax) +{ + /* Initialize a few variables */ + plstruct *pl = ap->plarray; + cpl_size npl = ap->npl_pix; + cpl_size ipix = ap->ipnop; + double fconst = ap->fconst; + double offset = ap->areal_offset; + + oldthr = ap->thresh; + xbar_start = xbar; + ybar_start = ybar; + + /* Initialize some constants that you might need later */ + double tmul = 1.2589678; /* 1/4 mag deblending contour increment */ + double smul = 2.5; /* starting contour increment */ + cpl_size ipixo2 = CPL_MAX(2, (ipix + 1) / 2); /* ipix is the minimum image pixel size */ + double xintmn = oldthr * ipixo2; /* minimum intensity for fragments */ + double itmaxlim = 0.9 * tmax; /* upper limit deblending 90% of peak */ + + lasthr = itmaxlim; + curthr = smul * oldthr; + + /* Get a maximum of IDBLIM points brighter than the new detection threshold + * by reverse sorting the input array. If there are still more than IDBLIM + * above the threshold, then revise the threshold until there aren't. Then + * use the variable npl2 to stop the rest of the routine accessing any of + * the fainter pixels in the list. This is to restrict processing time + * for large extended objects */ + + sort_array_f(pl, npl, sizeof(*pl), &cmp_plstruct); + + cpl_size npl2; + while (1) { + + npl2 = 0; + while (npl2 < npl - 1 && pl[npl2].zsm > curthr) { + npl2++; + } + + if (npl2 > IDBLIM) curthr += oldthr; + else break; + } + + /* If there are fewer pixels above the new threshold than the minimum + * specified in the input parameters, then you have no reason to be here */ + if (npl2 < ipix) { + *nbit = 1; + return CPL_ERROR_NONE; + } + + /* Get a new ap structure */ + ap_t ap2; + ap2.lsiz = ap->lsiz; + ap2.csiz = ap->csiz; + ap2.multiply = 1; + ap2.ipnop = ipixo2; + ap2.areal_offset = offset; + ap2.fconst = fconst; + ap2.mflag = cpl_calloc((ap2.lsiz) * (ap2.csiz), sizeof(*ap2.mflag)); + + hdrl_apinit(&ap2); + + /* Main analysis loop at new thresholds */ + *nbit = 0; + + /* TODO: it could be problems???, it's checked (in the while) before initialize */ + cpl_size ibitx[IMNUM]; + cpl_size ibity[IMNUM]; + + cpl_size iupdate[IMNUM]; + double parmnew[IMNUM][NPAR]; + + cpl_size nbitprev = 0; + while (1) { + + nexthr = CPL_MAX(curthr + oldthr, curthr * tmul); + + /* Locate objects in this cluster */ + ap2.thresh = curthr; + hdrl_apclust(&ap2, npl2, pl); + + cpl_size nobj; + double results[IMNUM][NPAR+1]; + cpl_size ipks[ IMNUM][2]; + cpl_size toomany; + check_term(&ap2, &nobj, results, ipks, &toomany); + + hdrl_apreinit(&ap2); + + if (nobj == 0) { + break; + } + + /* For each image check the number of points above the next threshold + * and flag. Do a moments analysis of each object */ + for (cpl_size i = 0; i < nobj; i++) { + + /* Ok, has this object already been detected? If so, then + * load the new results into the parmnew array. We'll check + * whether it's worthwhile updating the master parameters + * list later */ + + cpl_size isnew = 1; + + double xb = results[i][1]; + double yb = results[i][2]; + double sxx = CPL_MAX(1., results[i][4]); + double syy = CPL_MAX(1., results[i][6]); + + for (cpl_size k = 0; k < nbitprev; k++) { + + double dx = xb - parm[k][1]; + double dy = yb - parm[k][2]; + + double radius2 = dx * dx / sxx + dy * dy / syy; + + if ( (ibitx[k] == ipks[i][0] && ibity[k] == ipks[i][1]) || radius2 < 1.) { + + isnew = 0; + + for (cpl_size kk = 0; kk < NPAR; kk++) { + parmnew[k][kk] = results[i][kk]; + } + + break; + } + } + + /* If this is a new one and it's above the minimum threshold + then check to make sure you don't already have too many. + If you do, then flag this and break out to the next iteration. + If there is room for another, then store the moments analysis + profile */ + + if (isnew && results[i][0] > xintmn) { + + if (*nbit >= IMNUM) { + + *nbit = IMNUM; + toomany = 1; + + break; + } + + ibitx[*nbit] = ipks[i][0]; + ibity[*nbit] = ipks[i][1]; + + for (cpl_size kk = 0; kk < NPAR; kk++) { + parm[*nbit][kk] = results[i][kk]; + } + + (*nbit)++; + } + + } /* End of object loop */ + + + /* If too many objects were found, then skip the next bit...otherwise + go through and update parameters if necessary. This block of + code is a bit of a place holder waiting for something better to + be worked out...*/ + if (!toomany) { + + if (*nbit > nbitprev && nbitprev > 0) { + + for (cpl_size i = 0; i < nbitprev; i++) iupdate[i] = 0; + + for (cpl_size j = nbitprev; j < *nbit; j++) { + + double distmax = 0.; + cpl_size iwas = 0; + + for (cpl_size i = 0; i < nbitprev; i++) { + + if (parmnew[i][0] > 0.) { + + double radius2 = pow(parmnew[i][1] - parm[i][1], 2.) + pow(parmnew[i][2] - parm[i][2], 2.); + + if (radius2 > distmax) { + iwas = i; + distmax = radius2; + } + } + } + iupdate[iwas] = 1; + } + + for (cpl_size i = 0; i < nbitprev; i++) { + if (iupdate[i] == 1 && parmnew[i][0] > 0.) { + for (cpl_size j = 0; j < NPAR; j++) parm[i][j] = parmnew[i][j]; + } + } + } + + /* Reset the update flag and prepare for next iteration*/ + for (cpl_size i = 0; i <= *nbit; i++) { + parmnew[i][0] = -1.; + } + nbitprev = *nbit; + } + + /* Where do we cut in the list now? */ + cpl_size npl3 = 0; + while (npl3 < npl2-1 && pl[npl3].zsm > nexthr) { + npl3++; + } + npl2 = npl3; + + /* Now, do we need to move onto the next threshold? */ + if (npl2 == 0 || toomany || nexthr >= itmaxlim) { + break; + } + + /* If so, then reset some variables and continue */ + + curthr = nexthr; + + } /* End of main analysis loop */ + + + /* Free up some workspace */ + cpl_free(ap2.mflag); + hdrl_apclose(&ap2); + + /* If there isn't only one --> continue program, in other case we can exit */ + if (*nbit != 1) return hdrl_overlp_2orMore( ap, parm, nbit, xbar, ybar, total, + npix, curthr, nexthr, lasthr); + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Deblend overlapping images 2 or more. + * If you know that exist more than 1 (come to the previous version). + * + * @param ap The current ap structure + * @param parm The parameter array for the deblended objects + * @param nbit The output number of objects found in the deblended object + * @param xbar The X position of the input object + * @param ybar The Y position of the input object + * @param total The total flux of the input object + * @param npix The number of pixels in the original object + * @param tmax The peak flux of the original object + * + * @return CPL_ERROR_NONE if all went OK (Currently this is the only value). + * + * Description: + * An array of pixels that are believed to be part of a single large + * object are analyzed with successively higher thresholds to see if + * they resolve into multiple objects. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_overlp_2orMore( + ap_t *ap, double parm[IMNUM][NPAR], cpl_size *nbit, + double xbar, double ybar, double total, cpl_size npix, + double curthr_prev, double nexthr_prev, double lasthr_prev) +{ + /* Initialize a few variables */ + cpl_size ipix = ap->ipnop; + double offset = ap->areal_offset; + + oldthr = ap->thresh; + curthr = curthr_prev; + nexthr = nexthr_prev; + lasthr = lasthr_prev; + xbar_start = xbar; + ybar_start = ybar; + + /* Initialize some constants that you might need later */ + cpl_size ipixo2 = CPL_MAX(2, (ipix + 1) / 2); /* ipix is the minimum image pixel size */ + double xintmn = oldthr * ipixo2; /* minimum intensity for fragments */ + double algthr = log(oldthr); /* Convenient bit of shorthand */ + double radmax = sqrt((double)npix / CPL_MATH_PI); /* Isophotal size of input data array */ + + /* Find out which images terminated properly and remove those that didn't */ + cpl_size j = -1; + for (cpl_size k = 0; k < *nbit; k++) { + + /* Commented this out as checking for terminations seems to miss some + * if the total flux above the threshold for an object is negative */ + if (parm[k][0] > xintmn) { + + j++; + if (j != k) { + for (cpl_size i = 0; i < NPAR; i++) parm[j][i] = parm[k][i]; + } + } + } + + double bitx[IMNUM]; + double bitl[IMNUM]; + *nbit = j + 1; + for (cpl_size jj = 0; jj < *nbit; jj++) { + bitx[jj] = 0.; + bitl[jj] = 0.; + } + + /* For each image find true areal profile levels and iterate to find local continuum */ + double xdat[NAREAL + 1]; + double xcor[NAREAL + 1]; + cpl_size lastone = 0; + cpl_size iter = 0; + double sumint = 0.; + while (iter < NITER) { + + iter++; + + /* Loop for each of the objects and create a level vs radius array */ + for (cpl_size k = 0; k < *nbit; k++) { + + if (parm[k][0] >= 0.) { + + /* Pk + newthresh - cont */ + double xlevol = log(parm[k][7] + parm[k][3] - bitl[k]); + double xlevel = xlevol; + + double radold = 0.; + double radius = radold; + double slope = 1.; + cpl_size ic = 0; + + for (cpl_size i = 1; i <= NAREAL; i++) { + + cpl_size jj = NPAR - i; + cpl_size ii = NAREAL - i; + + double xx = (double)ii + offset; + + if (parm[k][jj] > 0.5) { + + if (ii == 0) { + xlevel = log(parm[k][3] - bitl[k] + 0.5); + } else { + xlevel = log(pow(2., xx) - oldthr + parm[k][3] - bitl[k] - 0.5); + } + + radius = sqrt(parm[k][jj] / CPL_MATH_PI); + xdat[ic] = xlevel; + xcor[ic++] = radius; + + double dlbydr = (xlevol - xlevel) / CPL_MAX(0.01, radius - radold); + + double wt = CPL_MIN(1., CPL_MAX((radius - radold) * 5., 0.1)); + + slope = (1. - 0.5 * wt) * slope + 0.5 * wt * CPL_MIN(5., dlbydr); + + radold = radius; + xlevol = xlevel; + } + } + + /* If this is not the last iteration then work out the effect on the local continuum from each image */ + if (!lastone) { + + for (cpl_size i = 0; i < *nbit; i++) { + + if (parm[i][0] >= 0.0 && i != k) { + + double dist = sqrt(pow(parm[k][1] - parm[i][1], 2.) + pow(parm[k][2] - parm[i][2], 2.)); + + double xeff = xlevel - CPL_MAX(0., CPL_MIN(50., slope * (dist - radius))); + + bitx[i] += exp(xeff); + } + } + + } else { + + /* If this is the last iteration loop, then update the parameters before exiting*/ + double ttt; + if (ic > 2) { + double polycf[3]; + hdrl_polynm(xdat, xcor, ic, polycf, 3, 0); + ttt = polycf[1] + 2. * polycf[2] * radius; + } else { + ttt = 0.; + } + + slope = CPL_MAX(0.1, CPL_MAX(-ttt, slope)); + + double radthr = radius + (xlevel - algthr) / slope; + if (radthr > radmax) { + slope = 1.; + radthr = radmax; + } + + /* Pixel area */ + double delb = parm[k][8] * (parm[k][3] - bitl[k]); + parm[k][8] = CPL_MATH_PI * radthr * radthr; + + /* Peak height */ + parm[k][7] += (parm[k][3] - bitl[k]); + + /* Intensity */ + double deli = 2. * CPL_MATH_PI * ( (parm[k][3] - bitl[k]) * (1. + slope * radius) + - oldthr * (1. + slope*radthr) + ) / (slope * slope); + + parm[k][0] += delb + CPL_MAX(0., deli); + + for (cpl_size i = 0; i < 7; i++) { + parm[k][i+9] = -1.; + } + + if (parm[k][0] > xintmn) { + sumint += parm[k][0]; + } + } + } + } + + /* If this is not the last iteration then check and see how the + * continuum estimates are converging. If they appear to be converging + * then let the next iteration be the last one. */ + if (!lastone) { + + cpl_size conv = 1; + + for (cpl_size i = 0; i < *nbit; i++) { + + if (parm[i][0] >= 0.) { + + if (fabs(bitx[i] - bitl[i]) > 3.) conv = 0; + + bitl[i] = bitx[i]; + bitx[i] = 0; + + /* FIXME Possible font of problems in the cast. Is it necessary ? */ + double a = parm[i][3] - oldthr; + bitl[i] = CPL_MIN(bitl[i], (cpl_size)(a + (a < 0 ? -0.5 : 0.5))); + + //bitl[i] = CPL_MIN(bitl[i], parm[i][3] - oldthr); + } + } + + lastone = (conv || (iter == NITER - 1)); + + } else { + break; + } + } + + /* Find the scaling if needed */ + if (sumint == 0.) *nbit = 1; + else { + double ratio = total / sumint; + for (cpl_size i = 0; i < *nbit; i++) { + parm[i][0] = ratio * parm[i][0]; + } + } + + return CPL_ERROR_NONE; +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out moments for an object with the current threshold. + * + * @param ap The current ap structure + * @param results The moments results + * @param ipk The x,y coordinates of the peak pixel + * + * Description: + * The moments an object in the current Plessey array are calculated + * for pixels above the current threshold. + */ +/* ---------------------------------------------------------------------------*/ +static void moments_thr(ap_t *ap, double results[NPAR + 1], cpl_size ipk[2]) +{ + /* Copy some stuff to local variables */ + double fconst = ap->fconst; + double offset = ap->areal_offset; + plstruct *plarray = ap->plarray; + cpl_size np = ap->npl_pix; + + /* Initialize a few things */ + double xoff = xbar_start; + double yoff = ybar_start; + double xsum = 0.; + double ysum = 0.; + double xsum_w = 0.; + double ysum_w = 0.; + double wsum = 0.; + double xsumsq = 0.; + double ysumsq = 0.; + double tsum = 0.; + double xysum = 0.; + double tmax = plarray[0].z - curthr; + + ipk[0] = plarray[0].x; + ipk[1] = plarray[0].y; + + for (cpl_size i = 8; i < NPAR; i++) { + results[i] = 0.; + } + + /* Do a moments analysis on an object */ + cpl_size nnext = 0; + for (cpl_size i = 0; i < np; i++) { + + double x = (double)(plarray[i].x) - xoff; + double y = (double)(plarray[i].y) - yoff; + + double t = plarray[i].z - curthr; + double w = plarray[i].zsm - curthr; + + if (w > nexthr) { + nnext++; + } + + xsum += t * x; + ysum += t * y; + tsum += t; + + xsum_w += w * t * x; + ysum_w += w * t * y; + + wsum += w * t; + + xsumsq += (x * x) * t; + ysumsq += (y * y) * t; + + xysum += x * y * t; + + update_ov(results + 8, t, oldthr, fconst, offset); + + if (t > tmax) { + + ipk[0] = plarray[i].x; + ipk[1] = plarray[i].y; + + tmax = t; + } + } + + /* Check that the total intensity is enough and if it is, then do + * the final results. Use negative total counts to signal an error */ + if (tsum > 0.) { + results[0] = tsum; + } else { + results[0] = -1.; + tsum = 1.; + } + + double xbar = xsum / tsum; + double ybar = ysum / tsum; + + double sxx = CPL_MAX(0., (xsumsq / tsum - xbar * xbar)); + double syy = CPL_MAX(0., (ysumsq / tsum - ybar * ybar)); + double sxy = xysum / tsum - xbar * ybar; + + wsum = CPL_MAX(1., wsum); + + xbar = xsum_w / wsum; + ybar = ysum_w / wsum; + + xbar += xoff; + ybar += yoff; + + xbar = CPL_MAX(1., CPL_MIN(xbar, ap->lsiz)); + ybar = CPL_MAX(1., CPL_MIN(ybar, ap->csiz)); + + /* Store the results now */ + results[1] = xbar; + results[2] = ybar; + results[3] = curthr; + results[4] = sxx; + results[5] = sxy; + results[6] = syy; + results[7] = tmax; + results[NPAR] = ((nnext > ap->ipnop && nexthr < lasthr) ? 0 : 1); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Update areal profiles for a given threshold + * + * @param iap The areal profile array + * @param t The input flux + * @param thresh The current detection threshold + * @param fconst Scaling parameter (log_2(e)) + * @param offset The offset between areal levels + * + * Description: + * The areal profiles are updated for a given flux and threshold. + */ +/* ---------------------------------------------------------------------------*/ +static void update_ov(double iap[NAREAL], double t, double thresh, double fconst, double offset) +{ + /* if the intensity is positive */ + if (t > 0.) { + + /* update the relevant profile counts */ + cpl_size nup = CPL_MAX(1, CPL_MIN(NAREAL, (cpl_size)(log(t + thresh) * fconst - offset) + 1)); + + for (cpl_size i = 0; i < nup; i++) { + iap[i] += 1.; + } + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Check for terminations in ap structure + * + * @param ap The current ap structure + * @param nobj The output number of objects detected + * @param parm The parameter array for all objects + * @param peaks The location of the peaks for each of the objects + * @param toomany If set, then too many objects have been detected + * + * Description: + * The ap structure is analyzed to see if there are any objects that can be terminated. + */ +/* ---------------------------------------------------------------------------*/ +static void check_term( ap_t *ap, cpl_size *nobj, double parm[IMNUM][NPAR+1], + cpl_size peaks[IMNUM][2], cpl_size *toomany) +{ + /* Search through all possible parents */ + *nobj = 0; + *toomany = 0; + + double momresults[NPAR + 1]; + cpl_size ipks[2]; + + for (cpl_size ip = 1; ip <= ap->maxip; ip++) { + + if (ap->parent[ip].pnop != -1) { + + if ( ap->parent[ip].pnop >= ap->ipnop + && ap->parent[ip].touch == 0) + { + hdrl_extract_data(ap, ip); + + moments_thr(ap, momresults, ipks); + if (momresults[0] > 0.) { + + if (*nobj == IMNUM - 1) { + *toomany = 1; + break; + } + + for (cpl_size i = 0; i <= NPAR; i++) { + parm[*nobj][i] = momresults[i]; + } + + for (cpl_size i = 0; i < 2; i++) { + peaks[*nobj][i] = ipks[i]; + } + + (*nobj)++; + } + } + + hdrl_restack(ap, ip); + } + } +} + +static int cmp_plstruct(const void *a, const void *b) { + + const plstruct *a_d = (const plstruct*)a; + const plstruct *b_d = (const plstruct*)b; + + /* Descending order */ + return -(a_d->zsm < b_d->zsm ? -1 : (a_d->zsm > b_d->zsm ? 1 : 0)); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_overlp.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,37 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_OVERLP_H +#define HDRL_OVERLP_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_overlp( + ap_t *ap, double parm[IMNUM][NPAR], cpl_size *nbit, + double xbar, double ybar, double total, cpl_size npix, double tmax); + +cpl_error_code hdrl_overlp_2orMore( + ap_t *ap, double parm[IMNUM][NPAR], cpl_size *nbit, + double xbar, double ybar, double total, cpl_size npix, + double curthr_prev, double nexthr_prev, double lasthr_prev); + + +#endif /* HDRL_OVERLP_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,213 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_phopt.h" + +#include "hdrl_cat_utils.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_phopt hdrl_phopt + * @ingroup Catalogue + * + * @brief Does multiple profile fitting to determine intensities + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Does multiple profile fitting to determine intensities + * + * @param ap The current ap structure + * @param parm The input/output object parameters + * @param nbit The number of objects detected in the current Plessey structure + * @param naper The number of apertures + * @param apertures Array of aperture radii + * @param cflux Array of aperture fluxes + * @param badpix Array saying how many bad pixels were included in the data for each object at each radius + * @param nrcore The index of the apertures array that defines where the radius = Rcore + * @param avconf + * + * @return CPL_ERROR_NONE if all went OK (Currently this is the only value). + * + * Description: + * Given a Plessey array and some parameters determined from a moments + * analysis for each of the objects detected in the array, this routine + * does multiple profile fitting for the given aperture set + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_phopt( + ap_t *ap, double parm[IMNUM][NPAR], cpl_size nbit, cpl_size naper, + double apertures[], double cflux[], double badpix[], cpl_size nrcore, double avconf[]) +{ + /* Set up some local variables */ + double *map = ap->indata; + double *conf = ap->confdata; + unsigned char *mflag = ap->mflag; + cpl_size nx = ap->lsiz; + cpl_size ny = ap->csiz; + + /* Loop for each of the apertures */ + double aa[IMNUM+1][IMNUM+1]; + double bb[IMNUM+1]; + + for (cpl_size iaper = 0; iaper < naper; iaper++) { + + double rcirc = apertures[iaper]; + double parrad = rcirc + 0.5; + + /* profile normalising constant */ + double cn = 1. / (CPL_MATH_PI * rcirc * rcirc); + double cnsq = cn * cn; + + /* set up covariance matrix - analytic special case for cores */ + for (cpl_size i = 0; i < nbit; i++) { + + /* overlaps totally area=pi*r**2 */ + aa[i][i] = cn; + + if (nbit > 1) { + + double xi = parm[i][1]; + double yi = parm[i][2]; + + for (cpl_size j = i + 1; j < nbit; j++) { + + double d = sqrt( (xi - parm[j][1]) * (xi - parm[j][1]) + + (yi - parm[j][2]) * (yi - parm[j][2])); + + if (d >= 2. * rcirc) { + aa[j][i] = 0.; + } else { + double arg = d / (2. * rcirc); + aa[j][i] = cnsq * 2. * rcirc * rcirc * (acos(arg) + - arg * (sqrt(1. - arg * arg))); + } + + aa[i][j] = aa[j][i]; + } + } + } + + /* clear accumulators */ + for (cpl_size i = 0; i < nbit; i++) { + bb[i] = 0.; + } + + /* generate image-blend outer boundaries */ + double xmin = DBL_MAX; + double xmax = DBL_MIN; + double ymin = DBL_MAX; + double ymax = DBL_MIN; + + for (cpl_size i = 0; i < nbit; i++) { + + double xi = parm[i][1]; + double yi = parm[i][2]; + + xmin = CPL_MIN(xmin, xi); + xmax = CPL_MAX(xmax, xi); + ymin = CPL_MIN(ymin, yi); + ymax = CPL_MAX(ymax, yi); + } + + double ix1 = CPL_MAX( 0, (cpl_size)(xmin - parrad) - 1); + double ix2 = CPL_MIN(nx - 1, (cpl_size)(xmax + parrad) ); + + double iy1 = CPL_MAX( 0, (cpl_size)(ymin - parrad) - 1); + double iy2 = CPL_MIN(ny - 1, (cpl_size)(ymax + parrad) ); + + /* now go through pixel region */ + for (cpl_size ii = iy1; ii <= iy2; ii++) { + + cpl_size kk = ii * nx; + + for (cpl_size i = ix1; i <= ix2; i++) { + + unsigned char mf = mflag[kk+i]; + + if (mf == MF_ZEROCONF || mf == MF_STUPID_VALUE) { + + for (cpl_size j = 0; j < nbit; j++) { + + double xj = i - parm[j][1] + 1.; + double yj = ii - parm[j][2] + 1.; + double tj = fraction(xj, yj, rcirc); + + aa[j][j] -= tj * tj * cnsq; + + for (cpl_size k = j + 1; k < nbit; k++) { + double tk = fraction( i - parm[k][1] + 1., ii - parm[k][2] + 1., rcirc); + aa[k][j] -= tk * tj * cnsq; + aa[j][k] = aa[k][j]; + } + + if (iaper == nrcore) badpix[j] += tj; + } + + } else if (mf == MF_CLEANPIX || mf == MF_OBJPIX || mf == MF_SATURATED) { + + double t = map[kk+i]; + + for (cpl_size j = 0; j < nbit; j++) { + + double xj = i - parm[j][1] + 1.; + double yj = ii - parm[j][2] + 1.; + + double ff = fraction(xj, yj, rcirc); + + bb[j] += ff * t; + + if (iaper == nrcore) { + avconf[j] += ff * conf[kk + i]; + } + } + } + } + } + + if (nbit == 1) { + + /* Trivial solution for single object */ + cflux[iaper] = bb[0]; + + } else { + + /* solve for profile intensities */ + for (cpl_size i = 0; i < nbit; i++) { + aa[i][i] = CPL_MAX(aa[i][i], cnsq); + } + + /* Could be better to call --> cpl_matrix_decomp_chol(...); */ + dchole(aa, bb, nbit); + + for (cpl_size i = 0; i < nbit; i++) { + cflux[i * naper + iaper] = cn * bb[i]; + } + } + } + + return CPL_ERROR_NONE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_phopt.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_PHOPT_H +#define HDRL_PHOPT_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_phopt( + ap_t *ap, double parm[IMNUM][NPAR], cpl_size nbit, cpl_size naper, + double apertures[], double cflux[], double badpix[], cpl_size nrcore, double avconf[]); + + +#endif /* HDRL_PHOPT_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,112 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_polynm.h" + +#include "hdrl_cat_solve.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_polynm hdrl_polynm + * @ingroup Catalogue + * + * @brief Work out the median seeing + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median seeing + * + * @param xdat x data points + * @param xcor + * @param n Number of data + * @param polycf polynomial coefficients + * @param m number of coefficients + * @param ilim + * + * @return CPL_ERROR_NONE if all went well (Currently it's the only value). + * + * Description: + * Determine polynomial coefficients + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_polynm( + double xdat[], double xcor[], cpl_size n, double polycf[], cpl_size m, cpl_size ilim) +{ + /* Clear arrays */ + #define sizeAray 25 + double a[sizeAray][sizeAray]; + double b[sizeAray]; + for (cpl_size i = 0; i < sizeAray; i++) { + + b[i] = 0.; + + for (cpl_size j = 0; j < sizeAray; j++) { + a[i][j] = 0.; + } + } + + /* Acumulate sums */ + for (cpl_size i = 0; i < n; i++) { + + for (cpl_size k = 0; k < m; k++) { + + double temp = 1.; + + if (k+ilim != 0) { + temp = pow(xcor[i], (double)(k + ilim)); + } + + b[k] += xdat[i] * temp; + + for (cpl_size j = 0; j <= k; j++) { + + temp = 1.; + + if (k+j+2*ilim != 0) { + temp = pow(xcor[i], (double)(k + j + 2 * ilim)); + } + + a[j][k] += temp; + } + } + } + + for (cpl_size k = 1; k < m; k++) { + for (cpl_size j = 0; j < k; j++) { + a[k][j] = a[j][k]; + } + } + + /* solve linear equations */ + hdrl_solve(a, b, m); + + for (cpl_size i = 0; i < m; i++) { + polycf[i] = b[i]; + } + + return CPL_ERROR_NONE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_polynm.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,31 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_POLYNM_H +#define HDRL_POLYNM_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_polynm( + double xdat[], double xcor[], cpl_size n, double polycf[], cpl_size m, cpl_size ilim); + + +#endif /* HDRL_POLYNM_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_radii.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_radii.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_radii.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_radii.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,302 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_radii.h" + +#include "hdrl_cat_utils.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_radii hdrl_radii + * @ingroup Catalogue + * + * @brief Work out the fluxes for special radii + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the half-light radius for an object + * + * @param rcores The list of aperture radii used + * @param cflux The list of fluxes through the aperture radii + * @param halflight An estimate of half the light of the object + * @param peak The peak flux of the object + * @param naper The number of radii used + * + * @return The half-light radius of the object + * + * Description: + * Given the the array of core apertures and core fluxes, work out + * the half light radius + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_halflight(double rcores[], double cflux[], double halflight, double peak, cpl_size naper) +{ + /* Work out the half-light value from either isophotal flux or the flux at + * Rcore. The find out roughly where the curve of growth exceeds this */ + + cpl_size gotone = 0; + cpl_size i; + for (i = 0; i < naper; i++) { + if (cflux[i] > halflight) { + gotone = 1; + break; + } + } + + if (gotone == 0) i = naper - 1; + + /* Now work out what the radius of half light is */ + double halfrad; + if (i == 0) { + + double delr = (cflux[i] - halflight) / CPL_MAX(1., cflux[i] - peak); + + halfrad = rcores[0] * (1. - delr) + delr * sqrt(1. / CPL_MATH_PI); + + } else { + + double delr = (cflux[i] - halflight) / CPL_MAX(1., (cflux[i] - cflux[i - 1])); + + halfrad = rcores[i - 1] * delr + rcores[i] * (1. - delr); + } + + return halfrad; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the exponential radius for an object + * + * @param thresh The detection threshold + * @param peak The peak flux of the object + * @param areal0 The lowest level areal profile for the object + * @param rcores The list of aperture radii used + * @param naper The number of radii used + * + * @return The exponential radius of the object + * + * Description: + * Given the detection threshold, peak flux and lowest areal + * profile, work out the exponential radius for an object + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_exprad(double thresh, double peak, double areal0, double rcores[], cpl_size naper) +{ + double pk = CPL_MAX(1.5 * thresh, peak); + + double r_t = sqrt(areal0 / CPL_MATH_PI); + + double rad = CPL_MAX(r_t, CPL_MIN(5. * r_t, CPL_MIN(5. * r_t / log(pk / thresh), rcores[naper - 1]))); + + return rad; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the Kron radius for an object + * + * @param areal0 The lowest level areal profile for the object + * @param rcores The list of aperture radii used + * @param cflux The aperture fluxes for each radius + * @param naper The number of radii used + * + * @return The Kron radius of the object + * + * Description: + * Given the lowest areal profile and the circular aperture fluxes + * already done, calculate the Kron radius + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_kronrad(double areal0, double rcores[], double cflux[], cpl_size naper) +{ + double r_t = sqrt(areal0 / CPL_MATH_PI); + double rad = 0.5 * rcores[0] * cflux[0]; + double sum = cflux[0]; + + cpl_size imax = CPL_MIN(naper, 7); + for (cpl_size i = 1; i < imax; i++) { + + double wt = CPL_MAX(0., cflux[i] - cflux[i - 1]); + + rad += 0.5 * (rcores[i] + rcores[i - 1]) * wt; + sum += wt; + } + rad /= sum; + + rad = CPL_MAX(r_t, CPL_MIN(5. * r_t, CPL_MIN(2. * rad, rcores[naper - 1]))); + + return rad; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the Petrosian radius for an object + * + * @param areal0 The lowest level areal profile for the object + * @param rcores The list of aperture radii used + * @param cflux The aperture fluxes for each radius + * @param naper The number of radii used + * + * @return The Petrosian radius of the object + * + * Description: + * Given the lowest areal profile and the circular aperture fluxes + * already done, calculate the Petrosian radius + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_petrad(double areal0, double rcores[], double cflux[], cpl_size naper) +{ + double r_t = sqrt(areal0 / CPL_MATH_PI); + + double eta = 1.; + double etaold = eta; + + cpl_size j = 1; + while (eta > 0.2 && j < naper) { + + etaold = eta; + + double r1 = rcores[j] * rcores[j] / (rcores[j - 1] * rcores[j - 1]) - 1.; + double r2 = cflux[j] / cflux[j - 1] - 1.; + + eta = r2 / r1; + + j++; + } + + double r_petr = rcores[naper - 1]; + if (j != naper) { + + double r1 = rcores[j] * rcores[j]; + double r2 = rcores[j - 1] * rcores[j - 1]; + double r3 = rcores[j - 2] * rcores[j - 2]; + double r4 = (etaold - 0.2) / (etaold - eta); + double r5 = (0.2 - eta) / (etaold - eta); + + r_petr = r4 * sqrt(0.5 * (r1 + r2)) + r5 * sqrt(0.5 * (r2 + r3)); + } + + r_petr = CPL_MAX(r_t, CPL_MIN(5. * r_t, CPL_MIN(2. * r_petr, rcores[naper-1]))); + + return r_petr; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the fluxes for special radii + * + * @param ap The current ap structure + * @param parm The parameters for each object already detected + * @param nbit The number of detected objects in the current Plessey structure. + * @param apers The radii of the standard apertures + * @param fluxes The fluxes computed through the standard apertures + * @param nr The number of special apertures + * @param rcores The radii the special apertures + * @param rfluxes The fluxes computed through the special apertures. + * + * Description: + * The fluxes for the 'special' radii (Kron etc) are worked out + * by an interpolation of the pre-existing aperture photometry to the + * new radius. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_flux(ap_t *ap, double parm[IMNUM][NPAR], cpl_size nbit, double apers[], + double fluxes[], cpl_size nr, double rcores[], double rfluxes[]) +{ + /* Set up some local variables */ + double *map = ap->indata; + unsigned char *mflag = ap->mflag; + + cpl_size nx = ap->lsiz; + cpl_size ny = ap->csiz; + + /* Section for nbit == 1 */ + if (nbit == 1) { + + /* Generate image-blend outer boundaries */ + + double xmin = parm[0][1] - apers[0] - 0.5; + double xmax = parm[0][1] + apers[0] + 0.5; + double ymin = parm[0][2] - apers[0] - 0.5; + double ymax = parm[0][2] + apers[0] + 0.5; + + cpl_size ix1 = CPL_MAX( 0, (cpl_size)xmin - 1); + cpl_size ix2 = CPL_MIN(nx - 1, (cpl_size)xmax ); + cpl_size iy1 = CPL_MAX( 0, (cpl_size)ymin - 1); + cpl_size iy2 = CPL_MIN(ny - 1, (cpl_size)ymax ); + + /* Now go through pixel region and add up the contributions inside the aperture */ + fluxes[0] = 0.; + for (cpl_size j = iy1; j <= iy2; j++) { + + cpl_size kk = j * nx; + + for (cpl_size i = ix1; i <= ix2; i++) { + + unsigned char mf = mflag[kk + i]; + + if (mf == MF_CLEANPIX || mf == MF_OBJPIX || mf == MF_SATURATED) { + + double t = map[kk+i]; + double xj = (double)i - parm[0][1] + 1.; + double yj = (double)j - parm[0][2] + 1.; + fluxes[0] += fraction(xj, yj, apers[0]) * t; + } + } + } + + if (fluxes[0] <= 0) fluxes[0] = parm[0][0]; + + } else { /* Section for blended images */ + + /* Interpolate circular aperture fluxes */ + double sumiso = 0.; + double sumcf = 0.; + + for (cpl_size j = 0; j < nbit; j++) { + + sumiso += parm[j][0]; + + cpl_size n = 1; + while (n < nr - 1 && rcores[n] < apers[j]) n++; + + double delr = (rcores[n] - apers[j]) / (rcores[n] - rcores[n - 1]); + + fluxes[j] = rfluxes[j * nr + n]*(1. - delr) + rfluxes[j * nr + n - 1] * delr; + + sumcf += fluxes[j]; + } + + /* Constrain the result so that the ratios are the same as for the isophotal fluxes */ + for (cpl_size j = 0; j < nbit; j++) { + + fluxes[j] = sumcf * parm[j][0] / CPL_MAX(1., sumiso); + + if (fluxes[j] < 0.) fluxes[j] = parm[j][0]; + } + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_radii.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_radii.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_radii.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_radii.h 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,36 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_RADII_H +#define HDRL_RADII_H + + +#include "hdrl_cat_def.h" + + +double hdrl_halflight(double rcores[], double cflux[], double halflight, double peak, cpl_size naper); +double hdrl_exprad( double thresh, double peak, double areal0, double rcores[], cpl_size naper); +double hdrl_kronrad( double areal0, double rcores[], double cflux[], cpl_size naper); +double hdrl_petrad( double areal0, double rcores[], double cflux[], cpl_size naper); + +void hdrl_flux( ap_t *ap, double parm[IMNUM][NPAR], cpl_size nbit, double apers[], + double fluxes[], cpl_size nr, double rcores[], double rfluxes[]); + + +#endif /* HDRL_RADII_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,103 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_seeing.h" + +#include "hdrl_cat_utils_sort.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_seeing hdrl_seeing + * @ingroup Catalogue + * + * @brief Work out the median seeing + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Work out the median seeing + * + * @param ap The current ap structure + * @param nrows The number rows in the object catalogue + * @param ellipt The array of ellipticities from the object catalogue + * @param pkht The array of peak heights from the object catalogue + * @param areal The array of areal profiles from the object catalogue + * @param work A work array (should probably allocate this local at some stage) + * @param fwhm The output FWHM estimate + * + * @return CPL_ERROR_NONE if all went OK (Currently this is the only value). + * + * Description: + * The areal profiles for an array of objects is examined. The point + * where the areal profile falls to half its peak value is found for + * each object and the final seeing estimate is the median of these results + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_seeing( + ap_t *ap, cpl_size nrows, double *ellipt, double *pkht, + double **areal, double *work, double *fwhm) +{ + double log5t = log(0.5 / ap->thresh); + double log2 = log(2.); + + /* Do the seeing calculation */ + cpl_size ii = 0; + for (cpl_size i = 0; i < nrows; i++) { + if (ellipt[i] < 0.2 && pkht[i] < 30000. && pkht[i] > 10. * ap->thresh) { + + double aper = (log5t + log(pkht[i])) / log2 + 1.; + cpl_size iaper = (cpl_size)aper; + + double delaper = aper - iaper; + + if (iaper > 0 && iaper < NAREAL && areal[1][i] > 0.) { + + double area = (1. - delaper) * areal[iaper - 1][i] + delaper * areal[iaper][i]; + + work[ii++] = CPL_MATH_2_SQRTPI * sqrt(area); + } + } + } + + /* Sort the resulting array and choose a location that allows for contamination by galaxies */ + if (ii >= 3) { + + sort_array(work, ii, sizeof(*work), HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + + *fwhm = work[ii / 3 - 1]; + + /* Allow for finite pixel size */ + double arg = 0.25 * CPL_MATH_PI * pow(*fwhm, 2.) - 1; + + *fwhm = 2. * sqrt(CPL_MAX(0., arg / CPL_MATH_PI)); + + } else { + + *fwhm = 0.; + } + + return CPL_ERROR_NONE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_seeing.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_SEEING_H +#define HDRL_SEEING_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_seeing( + ap_t *ap, cpl_size nrows, double *ellipt, double *pkht, + double **areal, double *work, double *fwhm); + + +#endif /* HDRL_SEEING_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_solve.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_solve.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_solve.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_solve.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,133 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_solve.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_solve hdrl_solve + * @ingroup Catalogue + * + * @brief Use Gauss-Jordan elimination to solve ax=b + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Use Gauss-Jordan elimination to solve ax=b + * + * @param a Input matrix + * @param b Input vector + * @param m rank of matrix + * + * @return CPL_ERROR_NONE if all went well (Currently it's the only value). + * + * Description: + * Use Gauss-Jordan elimination to solve ax=b Standard algorithm + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_solve(double a[25][25], double b[25], cpl_size m) +{ + cpl_size l = 0; + cpl_size iu = m - 1; + + for (cpl_size i = 0; i < iu; i++) { + + /* find largest remaining term in i-th column for pivot */ + double big = 0.; + for (cpl_size k = i; k < m; k++) { + + double rmax = fabs(a[i][k]); + if (rmax > big) { + big = rmax; + l = k; + } + } + + /* check for non-zero term */ + if (big == 0.) { + for (cpl_size ib = 0; ib < m; ib++) { + b[ib] = 0.; + } + return CPL_ERROR_NONE; + } + + if (i != l) { + + /* switch rows */ + for (cpl_size j = 0; j < m; j++) { + + double temp = a[j][i]; + a[j][i] = a[j][l]; + a[j][l] = temp; + } + + double temp = b[i]; + b[i] = b[l]; + b[l] = temp; + } + + /* pivotal reduction */ + double pivot = a[i][i]; + + cpl_size jl = i + 1; + for (cpl_size j = jl; j < m; j++) { + + double temp = a[i][j] / pivot; + + b[j] -= temp * b[i]; + + for (cpl_size k = i; k < m; k++) { + a[k][j] -= temp * a[k][i]; + } + } + } + + /* back substitution for solution */ + for (cpl_size i = 0; i < m; i++) { + + cpl_size ir = m - 1 - i; + if (a[ir][ir] != 0.) { + + double temp = b[ir]; + if (ir != m-1) { + + for (cpl_size j = 1; j <= i; j++) { + cpl_size k = m - j; + temp -= a[k][ir] * b[k]; + } + } + + b[ir] = temp / a[ir][ir]; + + } else { + + b[ir] = 0.; + } + } + + return CPL_ERROR_NONE; +} + +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_solve.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_solve.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_solve.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_solve.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,30 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_SOLVE_H +#define HDRL_SOLVE_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_solve(double a[25][25], double b[25], cpl_size m); + + +#endif /* HDRL_SOLVE_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.c 2017-10-20 14:15:44.000000000 +0000 @@ -0,0 +1,173 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_statistics.h" + +#include "hdrl_cat_utils_sort.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_statistics hdrl_statistics + * @ingroup Catalogue + * + * @brief Compute statistics + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief compute median + * + * @param xbuf buffer + * @param npt number of points + * @param nfilt size of median filter + * + * @return CPL_ERROR_NONE if all went well, CPL_ERROR_INCOMPATIBLE_INPUT if there isn't enough size. + * + * Description: + * performs median filtering on array xbuf + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_median(double xbuf[], cpl_size npt, cpl_size nfilt) +{ + if ((nfilt / 2) * 2 == nfilt) { + nfilt++; + } + + if (npt <= nfilt) { + return CPL_ERROR_INCOMPATIBLE_INPUT; + } + + cpl_size nfo2p1 = nfilt / 2; + + /* allocate ybuf, array, point */ + cpl_size nelem = npt + nfilt; /* Max. number of elements req'd */ + double *ybuf = (double * )cpl_malloc(nelem * sizeof(double )); + double *array = (double * )cpl_malloc(nfilt * sizeof(double )); + cpl_size *point = (cpl_size *)cpl_malloc(nfilt * sizeof(cpl_size)); + + /* set first and last edges equal */ + cpl_size il = nfilt / 2; + cpl_size ilow = (CPL_MAX(3, nfilt / 4) / 2) * 2 + 1; + + + /* Calculation of xmns */ + for (cpl_size i = 0; i < ilow; i++) { + array[i] = xbuf[i]; + } + sort_array_index(array, ilow, point, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING); + double xmns = array[ilow / 2]; + + + /* Calculation of xmnf */ + for (cpl_size i = 0; i < ilow; i++) { + array[i] = xbuf[npt - 1 - i]; + } + sort_array_index(array, ilow, point, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING); + double xmnf = array[ilow / 2]; + + + /* reflect edges before filtering */ + for (cpl_size i = 0; i < il; i++) { + ybuf[i] = 2. * xmns - xbuf[il - i - 1 + ilow]; + ybuf[npt + i + il] = 2. * xmnf - xbuf[npt - i - 1 - ilow]; + } + + for (cpl_size i = 0; i < npt; i++) { + ybuf[i + il] = xbuf[i]; + } + + /* do median filtering on rest */ + for (cpl_size i = 0; i < nfilt; i++) { + array[i] = ybuf[i]; + point[i] = i + 1; + } + + sort_array_index(array, nfilt, point, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING); + xbuf[0] = array[nfo2p1]; + + cpl_size jl = nfilt; + cpl_size jh = nfilt + npt - 1; + + cpl_size l = 0; + for (cpl_size j = jl; j < jh; j++) { + + for (cpl_size i = 0; i < nfilt; i++) { + if (point[i] != 1) { + point[i]--; + } else { + point[i] = nfilt; + array[i] = ybuf[j]; + l = i; + } + } + + cpl_size jj = nfilt; + for (cpl_size i = 0; i < nfilt; i++) { + if (i != l && array[l] <= array[i]) { + jj = i; + break; + } + } + + if (jj - 1 != l) { + + double temp = array[l]; + cpl_size it = point[l]; + + if (jj < l) { + + for (cpl_size i = 0; i < l - jj; i++) { + cpl_size ii = l - i - 1; + array[ii + 1] = array[ii]; + point[ii + 1] = point[ii]; + } + + } else if (jj > l) { + + jj--; + if (npt != 0) { + for (cpl_size i = 0; i < jj - l; i++) { + cpl_size ii = l + i + 1; + array[ii - 1] = array[ii]; + point[ii - 1] = point[ii]; + } + } + } + + array[jj] = temp; + point[jj] = it; + } + + xbuf[j - jl + 1] = array[nfo2p1]; + } + + /* Free temporary arrays */ + cpl_free((void *) point); + cpl_free((void *) array); + cpl_free((void *) ybuf); + + return CPL_ERROR_NONE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_statistics.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,30 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_STATISTICS_H +#define HDRL_STATISTICS_H + + +#include "hdrl_cat_def.h" + + +cpl_error_code hdrl_median(double xbuf[], cpl_size npt, cpl_size nfilt); + + +#endif /* HDRL_STATISTICS_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_table.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_table.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_table.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_table.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,748 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_table.h" + +#include "hdrl_cat_areals.h" +#include "hdrl_cat_radii.h" +#include "hdrl_cat_phopt.h" +#include "hdrl_cat_seeing.h" +#include "hdrl_cat_overlp.h" +#include "hdrl_cat_moments.h" +#include "hdrl_cat_extend.h" +#include "hdrl_cat_background.h" + + +#define INITROWS 2048 /* Allocation size for rows in the output table */ + +/* Number assigned of columns in the table */ +#define COL_NUMBER 1 +#define COL_FLUXISO 2 +#define COL_X 3 +#define COL_XERR 4 +#define COL_Y 5 +#define COL_YERR 6 +#define COL_SIGMA 7 +#define COL_ELLIPT 8 +#define COL_PA 9 +#define COL_AREAL1 10 +#define COL_AREAL2 11 +#define COL_AREAL3 12 +#define COL_AREAL4 13 +#define COL_AREAL5 14 +#define COL_AREAL6 15 +#define COL_AREAL7 16 +#define COL_AREAL8 17 +#define COL_PEAKHEIGHT 18 +#define COL_PKHTERR 19 +#define COL_APFLUX1 20 +#define COL_APFLUX1ERR 21 +#define COL_APFLUX2 22 +#define COL_APFLUX2ERR 23 +#define COL_APFLUX3 24 +#define COL_APFLUX3ERR 25 +#define COL_APFLUX4 26 +#define COL_APFLUX4ERR 27 +#define COL_APFLUX5 28 +#define COL_APFLUX5ERR 29 +#define COL_APFLUX6 30 +#define COL_APFLUX6ERR 31 +#define COL_APFLUX7 32 +#define COL_APFLUX7ERR 33 +#define COL_APFLUX8 34 +#define COL_APFLUX8ERR 35 +#define COL_APFLUX9 36 +#define COL_APFLUX9ERR 37 +#define COL_APFLUX10 38 +#define COL_APFLUX10ERR 39 +#define COL_APFLUX11 40 +#define COL_APFLUX11ERR 41 +#define COL_APFLUX12 42 +#define COL_APFLUX12ERR 43 +#define COL_APFLUX13 44 +#define COL_APFLUX13ERR 45 +#define COL_PETRAD 46 +#define COL_KRONRAD 47 +#define COL_HALFRAD 48 +#define COL_PETFLUX 49 +#define COL_PETFLUXERR 50 +#define COL_KRONFLUX 51 +#define COL_KRONFLUXERR 52 +#define COL_HALFFLUX 53 +#define COL_HALFFLUXERR 54 +#define COL_ERRFLAG 55 +#define COL_SKYLEVEL 56 +#define COL_SKYSIGMA 57 +#define COL_AVCONF 58 +#define COL_RA 59 +#define COL_DEC 60 +#define COL_CLASS 61 +#define COL_STAT 62 +#define COL_FWHM 63 + +/* Name assigned of columns in the table */ +static const char *ttype[NCOLS]={"Sequence_number","Isophotal_flux", + "X_coordinate","X_coordinate_err", + "Y_coordinate","Y_coordinate_err", + "Gaussian_sigma","Ellipticity","Position_angle", + "Areal_1_profile","Areal_2_profile","Areal_3_profile", + "Areal_4_profile","Areal_5_profile","Areal_6_profile", + "Areal_7_profile","Areal_8_profile", + "Peak_height","Peak_height_err", + "Aper_flux_1","Aper_flux_1_err", + "Aper_flux_2","Aper_flux_2_err", + "Aper_flux_3","Aper_flux_3_err", + "Aper_flux_4","Aper_flux_4_err", + "Aper_flux_5","Aper_flux_5_err", + "Aper_flux_6","Aper_flux_6_err", + "Aper_flux_7","Aper_flux_7_err", + "Aper_flux_8","Aper_flux_8_err", + "Aper_flux_9","Aper_flux_9_err", + "Aper_flux_10","Aper_flux_10_err", + "Aper_flux_11","Aper_flux_11_err", + "Aper_flux_12","Aper_flux_12_err", + "Aper_flux_13","Aper_flux_13_err", + "Petr_radius","Kron_radius","Half_radius", + "Petr_flux","Petr_flux_err", + "Kron_flux","Kron_flux_err","Half_flux","Half_flux_err", + "Error_bit_flag","Sky_level","Sky_rms", + "Av_conf", + "RA","DEC","Classification","Statistic", + "FWHM"}; + +static const char *tunit[NCOLS]={"Number","ADU", + "Pixels","Pixels", + "Pixels","Pixels", + "Pixels","Number","Degrees", + "Pixels","Pixels","Pixels", + "Pixels","Pixels","Pixels", + "Pixels","Pixels", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "ADU","ADU", + "Pixels","Pixels","Pixels", + "ADU","ADU", + "ADU","ADU","ADU","ADU", + "Number","ADU","ADU","Number", + "Degrees","Degrees","Flag","N-sigma", + "Pixels"}; + +static cpl_type g_tform[NCOLS]={CPL_TYPE_INT, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE}; + +/* Apertures and areals */ +static double g_apertures[NRADS]; + +static double g_rmults[] = {0.5, + 1. / CPL_MATH_SQRT2, + 1., + CPL_MATH_SQRT2, + 2., + 2. * CPL_MATH_SQRT2, + 4., 5., 6., 7., 8., 10., 12.0}; + +static cpl_size g_nrcore = 2; +static cpl_size g_n2rcore = 4; + +static cpl_size g_areal_cols[NAREAL] = {COL_AREAL1, COL_AREAL2, COL_AREAL3, + COL_AREAL4, COL_AREAL5, COL_AREAL6, + COL_AREAL7, COL_AREAL8}; + + +/*** Prototypes ***/ + +static cpl_error_code hdrl_do_seeing_gen( + ap_t *ap, const char *col_ellipt, const char *col_pkht, + const char *col_areals[NAREAL], cpl_size nobjects, cpl_table *tab); + +static cpl_error_code hdrl_tabinit_gen( + cpl_size ncols, cpl_type tform[], cpl_table **tab); + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_catalogue_table hdrl_catalogue_table + * @ingroup Catalogue + * + * @brief Table for the catalogue + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Initialize catalogues + * + * @param ap The current ap structure + * @param xcol + * @param ycol + * @param cattype The type of catalogue to be produced + * @param tab + * @param res + * + * @return CPL_ERROR_NONE if all went well and CPL_ERROR_ILLEGAL_INPUT if catalogue type is unrecognised. + * + * Description: + * Wrapper routine to call the relevant initialisation routine for + * each of the allowed types of catalogues. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_tabinit( + ap_t *ap, cpl_size *xcol, cpl_size *ycol, hdrl_catalogue_options cattype, + cpl_table **tab, hdrl_casu_result *res) +{ + /* Define RA and Dec columns */ + *xcol = COL_X; + *ycol = COL_Y; + + /* Call the generic routine to open a new output table */ + cpl_error_code e = hdrl_tabinit_gen(NCOLS, g_tform, tab); + if (e == CPL_ERROR_NONE){ + + if (cattype & HDRL_CATALOGUE_SEGMAP) { + res->segmentation_map = cpl_image_new(ap->lsiz, ap->csiz, CPL_TYPE_INT); + } else { + res->segmentation_map = NULL; + } + + if (cattype & HDRL_CATALOGUE_BKG) { + res->background = cpl_image_new(ap->lsiz, ap->csiz, CPL_TYPE_DOUBLE); + } else { + res->background = NULL; + } + } + + return e; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do seeing estimate + * + * @param ap The current ap structure + * @param nobjects Number of objects + * @param tab + * + * @return CPL_ERROR_NONE if all went well (Currently it's the only value). + * + * Description: + * Wrapper routine to call the relevant routine to work out the seeing + * for each of the allowed types of catalogues. + * Areal profiles are analysed and a seeing estimate is extracted. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_do_seeing( + ap_t *ap, cpl_size nobjects, cpl_table *tab) +{ + /* Sort out the areal profile column names */ + const char *areal_colnames[NAREAL]; + for (cpl_size i = 0; i < NAREAL; i++) { + areal_colnames[i] = (const char *)ttype[g_areal_cols[i] - 1]; + } + + /* Just call the generic seeing routine */ + return hdrl_do_seeing_gen( ap, + ttype[COL_ELLIPT - 1], + ttype[COL_PEAKHEIGHT - 1], + areal_colnames, nobjects, tab); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Process the results for each object and store them in the table + * + * @param ap The current ap structure + * @param gain The header keyword with the gain in e-/ADU + * @param nobjects + * @param tab + * @param res + * + * @return CPL_ERROR_NONE if all is well. CPL_ERROR_ILLEGAL_INPUT if peak flux < 0 + * + * Description: + * Wrapper routine to call the relevant routine to work out the results + * for each of the allowed types of catalogues. + * The pixel processing is done for all the parameters wanted. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_process_results( + ap_t *ap, double gain, cpl_size *nobjects, cpl_table *tab, hdrl_casu_result *res) +{ + /* Do a basic moments analysis and work out the areal profiles*/ + double momresults[8]; + hdrl_moments(ap, momresults); + if (momresults[0] < 0) { + return CPL_ERROR_ILLEGAL_INPUT; + } + + cpl_size iareal[NAREAL]; + hdrl_areals(ap, iareal); + + /* See if this object makes the cut in terms of its size. If not, then just return with good status */ + if (iareal[0] < ap->ipnop || momresults[3] < ap->xintmin) { + return CPL_ERROR_NONE; + } + + /* Work out the total flux */ + double ttotal; + hdrl_extend( ap, momresults[3], momresults[1], momresults[2], + momresults[4], momresults[5], momresults[6], (double)(iareal[0]), + momresults[7], &ttotal); + + /* Try and deblend the images if it is requested and justified */ + cpl_size nbit; + double parmall[IMNUM][NPAR]; + if (iareal[0] >= ap->mulpix && ap->icrowd) { + hdrl_overlp( ap, + parmall, + &nbit, + momresults[1], + momresults[2], + momresults[3], + iareal[0], + momresults[7]); + } else { + nbit = 1; + } + + if (nbit == 1) { + + parmall[0][0] = momresults[3]; + parmall[0][1] = momresults[1]; + parmall[0][2] = momresults[2]; + parmall[0][3] = ap->thresh; + + for (cpl_size i = 4; i < 8; i++) { + parmall[0][i] = momresults[i]; + } + + for (cpl_size i = 0; i < NAREAL; i++) { + parmall[0][i + 8] = (double)(iareal[i]); + } + + } else { + + cpl_size mbit = 0; + for (cpl_size i = 0; i < nbit; i++) { + + if ( parmall[i][1] > 1. && parmall[i][1] < ap->lsiz + && parmall[i][2] > 1. && parmall[i][2] < ap->csiz) { + + for (cpl_size j = 0; j < NPAR; j++) { + parmall[mbit][j] = parmall[i][j]; + } + + mbit++; + } + } + nbit = mbit; + + if (nbit == 0) { + return CPL_ERROR_NONE; + } + } + + /* Create a list of g_apertures */ + double badpix[IMNUM]; + double skyvar[IMNUM]; + double avconf[IMNUM]; + for (cpl_size i = 0; i < NRADS; i++) { + g_apertures[i] = g_rmults[i] * (ap->rcore); + skyvar[i] = CPL_MATH_PI * g_apertures[i] * g_apertures[i]; + } + + double rcore_area = CPL_MATH_PI * pow(ap->rcore, 2.); + + /* Initialise the badpix accumulator */ + for (cpl_size i = 0; i < nbit; i++) { + badpix[i] = 0.; + avconf[i] = 0.; + } + + /* Get the core fluxes in all g_apertures */ + double cflux[NRADS * IMNUM]; + hdrl_phopt(ap, parmall, nbit, NRADS, g_apertures, cflux, badpix, g_nrcore, avconf); + for (cpl_size i = 0; i < nbit; i++) { + avconf[i] /= rcore_area; + } + + /* Get half-light radius for all images */ + double half_flux[IMNUM]; + double half_rad[ IMNUM]; + for (cpl_size k = 0; k < nbit; k++) { + + half_flux[k] = 0.5 * (CPL_MAX(parmall[k][0], cflux[k * NRADS + g_n2rcore])); + + half_rad[k] = hdrl_halflight( g_apertures, + cflux+k*NRADS, + half_flux[k], + parmall[k][7], + NRADS); + } + + /* Get Kron radius for all images and get the flux */ + double areal; + double kron_flux[IMNUM]; + double kron_rad[ IMNUM]; + for (cpl_size k = 0; k < nbit; k++) { + areal = parmall[k][8]; + kron_rad[k] = hdrl_kronrad(areal, g_apertures, cflux + k * NRADS, NRADS); + } + hdrl_flux(ap, parmall, nbit, kron_rad, kron_flux, NRADS, g_apertures, cflux); + + /* Get Petrosian radius for all images and get the flux */ + double petr_flux[IMNUM]; + double petr_rad[ IMNUM]; + for (cpl_size k = 0; k < nbit; k++) { + areal = parmall[k][8]; + petr_rad[k] = hdrl_petrad(areal, g_apertures, cflux + k * NRADS, NRADS); + } + hdrl_flux(ap, parmall, nbit, petr_rad, petr_flux, NRADS, g_apertures, cflux); + + /* Massage the results and write them to the fits table */ + double sigsq = pow(ap->sigma, 2.); + double radeg = 180. / CPL_MATH_PI; + + for (cpl_size k = 0; k < nbit; k++) { + + double sxx = parmall[k][4]; + double sxy = parmall[k][5]; + double syy = parmall[k][6]; + + double srr = CPL_MAX(0.5, sxx + syy); + + if (sxy > 0.) { + sxy = CPL_MAX( 1.e-4, CPL_MIN(sxy, sqrt(sxx * syy))); + } else { + sxy = CPL_MIN(-1.e-4, CPL_MAX(sxy, -sqrt(sxx * syy))); + } + + double ecc = sqrt((syy - sxx) * (syy - sxx) + 4. * sxy * sxy) / srr; + + double temp = CPL_MAX((1. - ecc) / (1. + ecc), 0.); + double ell = CPL_MIN(0.99, CPL_MAX(0., 1. - sqrt(temp))); + + double xx = 0.5 * (1. + ecc) * srr - sxx; + double yy; + + double theta; + if (xx == 0.) { + theta = 0.; + } else { + theta = 90. - radeg * atan(sxy / xx); + } + double theta_ra = theta/radeg; + + double cc = (1. + ecc) * pow(cos(theta_ra), 2.) + (1. - ecc) * pow(sin(theta_ra), 2.); + double dd = (1. + ecc) * pow(sin(theta_ra), 2.) + (1. - ecc) * pow(cos(theta_ra), 2.); + + /* Create a list of values */ + cpl_size nrows = cpl_table_get_nrow(tab); + + (*nobjects)++; + if (*nobjects > nrows) { + cpl_table_set_size(tab, nrows + INITROWS); + } + cpl_size nr = *nobjects - 1; + + double iso_flux = parmall[k][0]; + + double apflux1 = cflux[k * NRADS + 0]; + double apflux2 = cflux[k * NRADS + 1]; + double apflux3 = cflux[k * NRADS + 2]; + double apflux4 = cflux[k * NRADS + 3]; + double apflux5 = cflux[k * NRADS + 4]; + double apflux6 = cflux[k * NRADS + 5]; + double apflux7 = cflux[k * NRADS + 6]; + double apflux8 = cflux[k * NRADS + 7]; + double apflux9 = cflux[k * NRADS + 8]; + double apflux10 = cflux[k * NRADS + 9]; + double apflux11 = cflux[k * NRADS + 10]; + double apflux12 = cflux[k * NRADS + 11]; + double apflux13 = cflux[k * NRADS + 12]; + + double peak = parmall[k][7]; + + xx = parmall[k][1]; + yy = parmall[k][2]; + + double xxe = sqrt( (2. * sigsq / (CPL_MATH_PI * peak * peak)) + + cc / (2. * CPL_MATH_PI * gain * peak) + + 0.0001); + + double yye = sqrt( (2. * sigsq / (CPL_MATH_PI * peak * peak)) + + dd / (2. * CPL_MATH_PI * gain * peak) + + 0.0001); + + double sigma = sqrt(srr); + double fwhm = sqrt(sigma * sigma / 2.) * CPL_MATH_FWHM_SIG; + /* heuristic correction of moment based fwhm obtained via simulated 2d gaussians, + * with gaussians 4.3 corrects slighltly better but it is not very + * significant and 4.0 is the same factor sextractor uses */ + fwhm -= 1. / (4. * fwhm); + + double areal1 = parmall[k][8]; + double areal2 = parmall[k][9]; + double areal3 = parmall[k][10]; + double areal4 = parmall[k][11]; + double areal5 = parmall[k][12]; + double areal6 = parmall[k][13]; + double areal7 = parmall[k][14]; + + double areal8; + if (nbit > 1 && k == 0) { + areal8 = 0.; + } else { + areal8 = parmall[k][15]; + } + + double skylev; + double skyrms; + hdrl_backest(ap, xx, yy, &skylev, &skyrms); + + double kron_fluxe = sqrt(kron_flux[k] / gain + (sigsq + skyrms * skyrms) * CPL_MATH_PI * pow(kron_rad[k], 2.)); + double petr_fluxe = sqrt(petr_flux[k] / gain + (sigsq + skyrms * skyrms) * CPL_MATH_PI * pow(petr_rad[k], 2.)); + double half_fluxe = sqrt(CPL_MAX(0., half_flux[k]) / gain + (sigsq + skyrms * skyrms) * CPL_MATH_PI * pow(half_rad[k], 2.)); + + double apflux1e = sqrt(CPL_MAX(0., apflux1 / gain) + skyvar[0 ] * (sigsq + skyrms * skyrms)); + double apflux2e = sqrt(CPL_MAX(0., apflux2 / gain) + skyvar[1 ] * (sigsq + skyrms * skyrms)); + double apflux3e = sqrt(CPL_MAX(0., apflux3 / gain) + skyvar[2 ] * (sigsq + skyrms * skyrms)); + double apflux4e = sqrt(CPL_MAX(0., apflux4 / gain) + skyvar[3 ] * (sigsq + skyrms * skyrms)); + double apflux5e = sqrt(CPL_MAX(0., apflux5 / gain) + skyvar[4 ] * (sigsq + skyrms * skyrms)); + double apflux6e = sqrt(CPL_MAX(0., apflux6 / gain) + skyvar[5 ] * (sigsq + skyrms * skyrms)); + double apflux7e = sqrt(CPL_MAX(0., apflux7 / gain) + skyvar[6 ] * (sigsq + skyrms * skyrms)); + double apflux8e = sqrt(CPL_MAX(0., apflux8 / gain) + skyvar[7 ] * (sigsq + skyrms * skyrms)); + double apflux9e = sqrt(CPL_MAX(0., apflux9 / gain) + skyvar[8 ] * (sigsq + skyrms * skyrms)); + double apflux10e = sqrt(CPL_MAX(0., apflux10 / gain) + skyvar[9 ] * (sigsq + skyrms * skyrms)); + double apflux11e = sqrt(CPL_MAX(0., apflux11 / gain) + skyvar[10] * (sigsq + skyrms * skyrms)); + double apflux12e = sqrt(CPL_MAX(0., apflux12 / gain) + skyvar[11] * (sigsq + skyrms * skyrms)); + double apflux13e = sqrt(CPL_MAX(0., apflux13 / gain) + skyvar[12] * (sigsq + skyrms * skyrms)); + + double peake = sqrt(peak / gain + sigsq + skyrms * skyrms) ; + + /* Store away the results for this object */ + cpl_table_set_int( tab, ttype[COL_NUMBER - 1], nr, *nobjects); + cpl_table_set_double(tab, ttype[COL_FLUXISO - 1], nr, iso_flux); + cpl_table_set_double(tab, ttype[COL_X - 1], nr, xx); + cpl_table_set_double(tab, ttype[COL_XERR - 1], nr, xxe); + cpl_table_set_double(tab, ttype[COL_Y - 1], nr, yy); + cpl_table_set_double(tab, ttype[COL_YERR - 1], nr, yye); + cpl_table_set_double(tab, ttype[COL_SIGMA - 1], nr, sigma); + cpl_table_set_double(tab, ttype[COL_ELLIPT - 1], nr, ell); + cpl_table_set_double(tab, ttype[COL_PA - 1], nr, theta); + cpl_table_set_double(tab, ttype[COL_AREAL1 - 1], nr, areal1); + cpl_table_set_double(tab, ttype[COL_AREAL2 - 1], nr, areal2); + cpl_table_set_double(tab, ttype[COL_AREAL3 - 1], nr, areal3); + cpl_table_set_double(tab, ttype[COL_AREAL4 - 1], nr, areal4); + cpl_table_set_double(tab, ttype[COL_AREAL5 - 1], nr, areal5); + cpl_table_set_double(tab, ttype[COL_AREAL6 - 1], nr, areal6); + cpl_table_set_double(tab, ttype[COL_AREAL7 - 1], nr, areal7); + cpl_table_set_double(tab, ttype[COL_AREAL8 - 1], nr, areal8); + cpl_table_set_double(tab, ttype[COL_PEAKHEIGHT - 1], nr, peak); + cpl_table_set_double(tab, ttype[COL_PKHTERR - 1], nr, peake); + cpl_table_set_double(tab, ttype[COL_APFLUX1 - 1], nr, apflux1); + cpl_table_set_double(tab, ttype[COL_APFLUX1ERR - 1], nr, apflux1e); + cpl_table_set_double(tab, ttype[COL_APFLUX2 - 1], nr, apflux2); + cpl_table_set_double(tab, ttype[COL_APFLUX2ERR - 1], nr, apflux2e); + cpl_table_set_double(tab, ttype[COL_APFLUX3 - 1], nr, apflux3); + cpl_table_set_double(tab, ttype[COL_APFLUX3ERR - 1], nr, apflux3e); + cpl_table_set_double(tab, ttype[COL_APFLUX4 - 1], nr, apflux4); + cpl_table_set_double(tab, ttype[COL_APFLUX4ERR - 1], nr, apflux4e); + cpl_table_set_double(tab, ttype[COL_APFLUX5 - 1], nr, apflux5); + cpl_table_set_double(tab, ttype[COL_APFLUX5ERR - 1], nr, apflux5e); + cpl_table_set_double(tab, ttype[COL_APFLUX6 - 1], nr, apflux6); + cpl_table_set_double(tab, ttype[COL_APFLUX6ERR - 1], nr, apflux6e); + cpl_table_set_double(tab, ttype[COL_APFLUX7 - 1], nr, apflux7); + cpl_table_set_double(tab, ttype[COL_APFLUX7ERR - 1], nr, apflux7e); + cpl_table_set_double(tab, ttype[COL_APFLUX8 - 1], nr, apflux8); + cpl_table_set_double(tab, ttype[COL_APFLUX8ERR - 1], nr, apflux8e); + cpl_table_set_double(tab, ttype[COL_APFLUX9 - 1], nr, apflux9); + cpl_table_set_double(tab, ttype[COL_APFLUX9ERR - 1], nr, apflux9e); + cpl_table_set_double(tab, ttype[COL_APFLUX10 - 1], nr, apflux10); + cpl_table_set_double(tab, ttype[COL_APFLUX10ERR - 1], nr, apflux10e); + cpl_table_set_double(tab, ttype[COL_APFLUX11 - 1], nr, apflux11); + cpl_table_set_double(tab, ttype[COL_APFLUX11ERR - 1], nr, apflux11e); + cpl_table_set_double(tab, ttype[COL_APFLUX12 - 1], nr, apflux12); + cpl_table_set_double(tab, ttype[COL_APFLUX12ERR - 1], nr, apflux12e); + cpl_table_set_double(tab, ttype[COL_APFLUX13 - 1], nr, apflux13); + cpl_table_set_double(tab, ttype[COL_APFLUX13ERR - 1], nr, apflux13e); + cpl_table_set_double(tab, ttype[COL_PETRAD - 1], nr, 0.5 * petr_rad[k]); + cpl_table_set_double(tab, ttype[COL_KRONRAD - 1], nr, 0.5 * kron_rad[k]); + cpl_table_set_double(tab, ttype[COL_HALFRAD - 1], nr, half_rad[k]); + cpl_table_set_double(tab, ttype[COL_PETFLUX - 1], nr, petr_flux[k]); + cpl_table_set_double(tab, ttype[COL_PETFLUXERR - 1], nr, petr_fluxe); + cpl_table_set_double(tab, ttype[COL_KRONFLUX - 1], nr, kron_flux[k]); + cpl_table_set_double(tab, ttype[COL_KRONFLUXERR - 1], nr, kron_fluxe); + cpl_table_set_double(tab, ttype[COL_HALFFLUX - 1], nr, half_flux[k]); + cpl_table_set_double(tab, ttype[COL_HALFFLUXERR - 1], nr, half_fluxe); + cpl_table_set_double(tab, ttype[COL_ERRFLAG - 1], nr, badpix[k]); + cpl_table_set_double(tab, ttype[COL_SKYLEVEL - 1], nr, skylev); + cpl_table_set_double(tab, ttype[COL_SKYSIGMA - 1], nr, skyrms); + cpl_table_set_double(tab, ttype[COL_AVCONF - 1], nr, avconf[k]); + cpl_table_set_double(tab, ttype[COL_FWHM - 1], nr, fwhm); + + /* Store away some dummy values to avoid problems later on */ + double zero = 0.; + cpl_table_set_double(tab, ttype[COL_RA - 1], nr, zero); + cpl_table_set_double(tab, ttype[COL_DEC - 1], nr, zero); + cpl_table_set_double(tab, ttype[COL_CLASS - 1], nr, 100.); + cpl_table_set_double(tab, ttype[COL_STAT - 1], nr, zero); + } + + /* Now that everything is okay - fill in the segmenataion map */ + cpl_msg_info(cpl_func, "Num objects found in catalogue: %lld", *nobjects); + if (res->segmentation_map) { + for (cpl_size index = 0; index < ap->npl_pix; index++) { + cpl_image_set( res->segmentation_map, + ap->plarray[index].x, + ap->plarray[index].y, + *nobjects); + } + } + + return CPL_ERROR_NONE; +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Initialise tables (generic) + * + * @param ncols The number of columns in the table + * @param ttype Array of column names for FITS table + * @param tunit Array of units for each of the columns + * @param tform Array of formats for each of the columns as defined in the FITS standard + * @param tab + * + * @return CPL_ERROR_NONE if all is well, CPL_ERROR_ILLEGAL_INPUT in other case + * + * Description: + * Generic routine to create FITS tables for the output catalogues. + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code hdrl_tabinit_gen( + cpl_size ncols, cpl_type tform[], cpl_table **tab) +{ + /* First, create the table with a default number of rows. */ + if ((*tab = cpl_table_new(0)) == NULL) { + + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "hdrl_cat_tabinit_gen - Unable to open cpl table!"); + return CPL_ERROR_ILLEGAL_INPUT; + + } else { + + /* Now define all of the columns */ + for (cpl_size i = 0; i < ncols; i++) { + + cpl_table_new_column( *tab, ttype[i], tform[i]); + cpl_table_set_column_unit(*tab, ttype[i], tunit[i]); + } + + return CPL_ERROR_NONE; + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Do seeing estimate (generic) + * + * @param ap The current ap structure + * @param col_ellipt The name of the column for ellipticity + * @param col_pkht The name of the column for the peak height + * @param col_areals The array of names of the areal profile columns + * @param nobjects + * @param tab + * + * @return CPL_ERROR_NONE if all it's ok (This is currently the only value.) + * + * Description: + * Wrapper routine for doing the seeing estimate + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code hdrl_do_seeing_gen( + ap_t *ap, const char *col_ellipt, const char *col_pkht, + const char *col_areals[NAREAL], cpl_size nobjects, cpl_table *tab) +{ + /* Get some space and read the relevant columns */ + double fwhm; + if (nobjects >= 3) { + + double *areal[NAREAL]; + for (cpl_size i = 0; i < NAREAL; i++) { + areal[i] = cpl_table_get_data_double(tab, col_areals[i]); + } + + double *ellipt = cpl_table_get_data_double(tab, col_ellipt); + double *pkht = cpl_table_get_data_double(tab, col_pkht); + + /* Do the seeing calculation */ + double *work = cpl_malloc(nobjects * sizeof(double)); + hdrl_seeing(ap, nobjects, ellipt, pkht, areal, work, &fwhm); + cpl_free(work); + + } else { + fwhm = 0.; + } + + ap->fwhm = fwhm; + + return CPL_ERROR_NONE; +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_table.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_table.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_table.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_table.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,41 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_TABLE_H +#define HDRL_TABLE_H + + +#include "hdrl_cat_def.h" + + +#define NCOLS 63 /* Number of columns in the table */ + + +cpl_error_code hdrl_tabinit( + ap_t *ap, cpl_size *xcol, cpl_size *ycol, hdrl_catalogue_options cattype, + cpl_table **tab, hdrl_casu_result *res); + +cpl_error_code hdrl_do_seeing( + ap_t *ap, cpl_size nobjects, cpl_table *tab); + +cpl_error_code hdrl_process_results( + ap_t *ap, double gain, cpl_size *nobjects, cpl_table *tab, hdrl_casu_result *res); + + +#endif /* HDRL_TABLE_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,215 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_terminate.h" + +#include "hdrl_cat_table.h" + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_terminate hdrl_terminate + * @ingroup Catalogue + * + * @brief Check for objects that have terminated + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Check for objects that have terminated + * + * @param ap The current ap structure + * @param gain The header keyword with the gain in e-/ADU + * @param nobjects Number of detected objects + * @param tab Output catalogue table + * @param res + * + * Description: + * The parents in the current ap structure are examined to see which + * have not grown since the last pass. Any that have not grown are + * sent to the processing routine. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_terminate(ap_t *ap, double gain, cpl_size *nobjects, + cpl_table *tab, hdrl_casu_result *res) +{ + + /* Search through all possible parents! */ + for (cpl_size ip = 1; ip <= ap->maxip; ip++) { + + if (ap->parent[ip].pnop != -1) { + + if (ap->parent[ip].pnop == ap->parent[ip].growing) { + + /* That's a termination: */ + if (( ap->parent[ip].pnop >= ap->ipnop && + ap->parent[ip].touch == 0) && + (ap->parent[ip].pnbp < (ap->parent[ip].pnop)/2) ){ + + /* Call the processing routine */ + hdrl_extract_data(ap, ip); + hdrl_process_results(ap, gain, nobjects, tab, res); + } + + hdrl_restack(ap,ip); + + } else { + + /* This parent still active: */ + ap->parent[ip].growing = ap->parent[ip].pnop; + } + } + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Free information for an object from the ap structure + * + * @param ap The current ap structure + * @param ip The parent number for the object + * + * Description: + * The starting address for an object in the ap structure is given. + * Information relating to that object is erased and the space made available + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_restack(ap_t *ap, cpl_size ip) +{ + /* Reset the mflag */ + unsigned char *mflag = ap->mflag; + + cpl_size np = ap->parent[ip].pnop; + cpl_size ib = ap->parent[ip].first; + + for (cpl_size i = 0; i < np; i++) { + cpl_size nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x; + mflag[nn] = MF_POSSIBLEOBJ; + ib = ap->blink[ib]; + } + + /* Stash all blocks back in a burst */ + ib = ap->parent[ip].first; + for (cpl_size i = ap->ibstack - ap->parent[ip].pnop; i < ap->ibstack-1; i++) { + ap->bstack[i] = ib; + ib = ap->blink[ib]; + } + + /* and the last one */ + ap->bstack[ap->ibstack-1] = ib; + ap->ibstack -= ap->parent[ip].pnop; + + /* Put parent name back on stack */ + ap->pstack[--ap->ipstack] = ip; + + /* Mark that parent inactive */ + ap->parent[ip].pnop = -1; + ap->parent[ip].pnbp = -1; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get rid of the largest contributor in an ap structure + * + * @param ap The current ap structure + * + * Description: + * The parents in the current ap structure are examined to see which + * has the largest number of pixels. That parent is junked. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_apfu(ap_t *ap) +{ + /* Search through all possible parents and just junk the biggest one to free space: */ + cpl_size big = 0; + cpl_size ipbig = 0; + + for (cpl_size ip = 1; ip <= ap->maxip; ip++) { + + if (ap->parent[ip].pnop != -1) { + + if (ap->parent[ip].pnop > big) { + big = ap->parent[ip].pnop; + ipbig = ip; + } + } + } + + if (big > 0) { + + hdrl_restack(ap, ipbig); + + /* clearout lastline references to this parent: */ + for (cpl_size ip = 0; ip <= ap->lsiz; ip++) { + + if (ap->lastline[ip] == ipbig) ap->lastline[ip] = 0; + } + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Put data into the Plessey array for an object + * + * @param ap The current ap structure + * @param ip The parent in question + * + * Description: + * The information for the object from a given parent is extracted from + * the link list in the ap structure and put into the Plessey array in + * preparation for analysis. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_extract_data(ap_t *ap, cpl_size ip) +{ + /* Check the size of the workspace and see if it's big enough. If it + isn't then increase the size until it is */ + + unsigned char *mflag = ap->mflag; + + cpl_size np = ap->parent[ip].pnop; + if (ap->npl < np) { + ap->plarray = cpl_realloc(ap->plarray, np * sizeof(*ap->plarray)); + ap->npl = np; + } + + /* Pull the info out now */ + cpl_size ib = ap->parent[ip].first; + ap->npl_pix = np; + for (cpl_size i = 0; i < np; i++) { + + ap->plarray[i].x = ap->plessey[ib].x + 1; + ap->plarray[i].y = ap->plessey[ib].y + 1; + + ap->plarray[i].z = ap->plessey[ib].z; + ap->plarray[i].zsm = ap->plessey[ib].zsm; + + cpl_size nn = ap->plessey[ib].y*ap->lsiz + ap->plessey[ib].x; + + mflag[nn] = MF_OBJPIX; + + ib = ap->blink[ib]; + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_terminate.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,34 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_TERMINATE_H +#define HDRL_TERMINATE_H + + +#include "hdrl_cat_def.h" + + +void hdrl_terminate( ap_t *ap, double gain, cpl_size *nobjects, + cpl_table *tab, hdrl_casu_result *res); +void hdrl_apfu( ap_t *ap); +void hdrl_extract_data(ap_t *ap, cpl_size ip); +void hdrl_restack( ap_t *ap, cpl_size ip); + + +#endif /* HDRL_RADII_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils.c 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,194 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "hdrl_cat_utils_sort.h" + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_utils_catalogue hdrl_utils_catalogue + * @ingroup Catalogue + * + * @brief Common functions + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Fraction of pixel bounded + * + * @param x X Cordinate relative to center + * @param y Y Cordinate relative to center + * @param r_out + * + * @return fraction of pixel bounded by 0 - r_out + * + * Description: + * Returns fraction of pixel bounded by 0 - r_out x,y coordinates relative to centre. + * Uses linear approximation ok if pixel located >>1 away from centre. + */ +/* ---------------------------------------------------------------------------*/ +double fraction(double x, double y, double r_out) +{ + double r = sqrt(x * x + y * y); + double sqrt2o2 = 0.5 * CPL_MATH_SQRT2; + + if (r > r_out + sqrt2o2) { /* Is it worth bothering? */ + return 0.; + } else if (r < r_out - sqrt2o2) { /* Is it trivially all in? */ + return(1.); + } + + /* bugger - have to do some work then ... ok first ... + * use 8-fold symmetry to convert to 0-45 degree range */ + x = fabs(x); + y = fabs(y); + if (y > x) { + double t = x; + x = y; + y = t; + } + + /* If the angles are too close to cardinal points, then fudge something */ + double tanao2; + double tanp2a; + double cosa; + if (x > 0. && y > 0.) { + tanao2 = 0.5 * y / x; + tanp2a = x / y; + cosa = x / sqrt(x * x + y * y); + } else { + tanao2 = 0.00005; + tanp2a = 10000.; + cosa = 1.; + } + + /* only outer radius - compute linear intersections top and bot of pixel */ + double frac; + + double x_a = x - tanao2 + (r_out - r) / cosa; + if (x_a < x + 0.5) { + + /* intersects */ + double x_b = x + tanao2 + (r_out - r) / cosa; + + /* three cases to consider */ + if (x_a < x - 0.5) { + frac = 0.5 * CPL_MAX(0., x_b - (x - 0.5)) * CPL_MAX(0., x_b - (x - 0.5)) * tanp2a; + } else if (x_b > x + 0.5) { + frac = 1. - 0.5 * (x + 0.5 - x_a) * (x + 0.5 - x_a) * tanp2a; + } else { + frac = 0.5 - (x - x_a) + 0.5 * (x_b - x_a); + } + + } else { /* missed entirely */ + frac = 1.; + } + + return frac; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Cholesky decomposition of definite symmetric matrix to solve Ax = b + * + * @param a . + * @param b . + * @param n . + * + * Description: + * . + */ +/* ---------------------------------------------------------------------------*/ +void dchole(double a[IMNUM+1][IMNUM+1], double b[IMNUM+1], cpl_size n) +{ + double l[IMNUM + 1][IMNUM + 1]; + + cpl_boolean restart = CPL_FALSE; + do { + + l[0][0] = sqrt(a[0][0]); + + for (cpl_size k = 1; k < n && !restart; k++) { + + for (cpl_size j = 0; j <= k - 1; j++) { + + double sum = a[j][k]; + if (j != 0) { + for (cpl_size i = 0; i <= j - 1; i++) sum -= l[i][k] * l[i][j]; + } + + l[j][k] = sum / l[j][j]; + } + + double sum = a[k][k]; + for (cpl_size i = 0; i <= k - 1; i++) { + sum -= l[i][k] * l[i][k]; + } + + /* if true -> warning: matrix ill-conditioned. max eigenvalue < trace. Offset added to diagonal */ + if (sum <= 0.) { + + double aveigv = a[0][0]; + for (cpl_size i = 1; i < n; i++) aveigv += a[i][i]; + + double offset = 0.1 * aveigv / (double)n; + for (cpl_size i = 0; i < n; i++) a[i][i] += offset; + + restart = CPL_TRUE; + } + + if (!restart) { + l[k][k] = sqrt(sum); + } + } + + } while (restart); + + + double y[IMNUM + 1]; + + /* solve Ly = b */ + y[0] = b[0] / l[0][0]; + for (cpl_size i = 1; i < n; i++) { + + double sum = b[i]; + for (cpl_size k = 0; k <= i - 1; k++) { + sum -= l[k][i] * y[k]; + } + + y[i] = sum / l[i][i]; + } + + /* solve L(T)x = y */ + b[n - 1] = y[n - 1] / l[n - 1][n - 1]; + for (cpl_size i = n - 2; i >= 0; i--) { + + double sum = y[i]; + for (cpl_size k = i+1; k < n; k++) { + sum -= l[i][k] * b[k]; + } + + b[i] = sum / l[i][i]; + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,31 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_UTILS_CATALOGUE_H +#define HDRL_UTILS_CATALOGUE_H + + +#include "hdrl_cat_def.h" + + +double fraction(double x, double y, double r_out); +void dchole( double a[IMNUM+1][IMNUM+1], double b[IMNUM+1], cpl_size n); + + + #endif /* HDRL_UTILS_CATALOGUE_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.c 2018-01-12 09:58:52.000000000 +0000 @@ -0,0 +1,534 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "hdrl_cat_utils_sort.h" + +#include "hdrl_types.h" + + +/*** Datatypes ***/ + +typedef struct { + double data; + int index; +} sort_index; + + +/*** Prototypes ***/ + +static int cmp_index_asc( const void *a, const void *b); +static int cmp_int_asc( const void *a, const void *b); +static int cmp_double_asc( const void *a, const void *b); +static int cmp_cpl_size_asc( const void *a, const void *b); +static int cmp_hdrl_value_asc(const void *a, const void *b); + +static int cmp_index_des( const void *a, const void *b); +static int cmp_int_des( const void *a, const void *b); +static int cmp_double_des( const void *a, const void *b); +static int cmp_cpl_size_des( const void *a, const void *b); +static int cmp_hdrl_value_des(const void *a, const void *b); + +static cpl_error_code sort_and_gen_index(double *a, cpl_size nE, sort_index *a_index, cpl_sort_direction dir); +static cpl_error_code sort_array_using_index(sort_index *a_index, cpl_size nE, void *b, hdrl_sort_type type); + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_utils_sort hdrl_utils_sort + * @ingroup Catalogue + * + * @brief Sort functions for differents data types + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief sort_array_f Core sort algorith that it's called with the + * other sort function. If you need to changed the + * the method of sort this is the function that + * you need modified. + * + * @param a generic pointer array with one unknown datatype + * @param nE Number of elements in the array + * @param sE Size of element in the array + * @param f Function for evaluate the comparison between elements + * + * @return cpl_error_code. Whit qsort() always return CPL_ERROR_NONE because + * qsort only return a void. If it change maybe it + * is possible to check it. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code sort_array_f(void *a, cpl_size nE, cpl_size sE, f_compare f) +{ + /* Generic funtion in C99 STD standard. + * All the rest of the functions call, at the end, this function. + * If you need to change the method of sort and affect all of hdrl library, + * you need to change only that part. */ + qsort(a, nE, sE, f); + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief sort_array hdrl function for order arrays with know types. + * Using the type parameter for select the comparation function + * + * @param a generic pointer array with one unknown datatype + * @param nE Number of elements in the array + * @param sE Size of element in the array + * @param type Datatype of elements in the 'a' generic array. Standard type in hdrl_sort_type + * @param dir Direction of sort array (Ascending or Descending) + * + * @return cpl_error_code. Return the error code provided by the sort function. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code sort_array(void *a, cpl_size nE, cpl_size sE, hdrl_sort_type type, cpl_sort_direction dir) +{ + f_compare f; + + if (dir == CPL_SORT_ASCENDING) { + + /* Ascending order hdrl_sort_type functions */ + switch(type) { + case HDRL_SORT_INT : f = &cmp_int_asc; break; + case HDRL_SORT_DOUBLE : f = &cmp_double_asc; break; + case HDRL_SORT_CPL_SIZE : f = &cmp_cpl_size_asc; break; + case HDRL_SORT_HDRL_VALUE : f = &cmp_hdrl_value_asc; break; + default : return CPL_ERROR_ILLEGAL_INPUT; + } + + } else { + + /* Descending order hdrl_sort_type functions */ + switch(type) { + case HDRL_SORT_INT : f = &cmp_int_des; break; + case HDRL_SORT_DOUBLE : f = &cmp_double_des; break; + case HDRL_SORT_CPL_SIZE : f = &cmp_cpl_size_des; break; + case HDRL_SORT_HDRL_VALUE : f = &cmp_hdrl_value_des; break; + default : return CPL_ERROR_ILLEGAL_INPUT; + } + } + + /* Sort the generic vector */ + return sort_array_f(a, nE, sE, f); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief sort_array_index hdrl function for sort two arrays + * The alghorithm sort 'a' and in the same way + * sort the other generic array by the index of 'a'. + * + * @param a generic pointer array with doubles + * @param nE Number of elements in the array of doubles + * @param b generic array that you need to order by index of the first array + * @param type Datatype of elements in the 'b' generic array. Standard type in hdrl_sort_type + * @param dir Direction of sort the array (Ascending or Descending) + * + * @return cpl_error_code. Return the error code provided by the sort functions. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code sort_array_index(double *a, cpl_size nE, void *b, hdrl_sort_type type, cpl_sort_direction dir) +{ + /* Reserve memory for the index */ + sort_index *a_index = cpl_malloc(nE * sizeof(sort_index)); + + /* Sort 'a' double array and generate the index sort */ + cpl_error_code e = sort_and_gen_index(a, nE, a_index, dir); + if (e == CPL_ERROR_NONE) { + + /* Sort the 'b' generic array with the index sort in 'a' */ + e = sort_array_using_index(a_index, nE, b, type); + } + + /* Cleanup */ + cpl_free(a_index); + + return e; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief sort_arrays_index hdrl function for sort several arrays + * The alghorithm sort 'a' and in the same way + * sort the others generic arrays by the index of 'a'. + * + * @param a generic pointer array with doubles + * @param nE Number of elements in the array of doubles + * @param bs generic arrays that you need to order by index of the first array + * @param nA Number of generic arrays + * @param types Datatypes of elements in the 'bs' generic arrays. Standard type in hdrl_sort_type + * @param dir Direction of sort the arrays (Ascending or Descending) + * + * @return cpl_error_code. Return the error code provided by the sort functions. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code sort_arrays_index(double *a, cpl_size nE, void **bs, cpl_size nA, hdrl_sort_type *types, cpl_sort_direction dir) +{ + /* Reserve memory for the index */ + sort_index *a_index = cpl_malloc(nE * sizeof(sort_index)); + + /* Sort 'a' double array and generate the index sort */ + cpl_error_code e = sort_and_gen_index(a, nE, a_index, dir); + for (cpl_size i = 0; i < nA && e == CPL_ERROR_NONE; i++) { + + /* Sort the 'bs[i]' generic array with the index sort in 'a' */ + e = sort_array_using_index(a_index, nE, bs[i], types[i]); + } + + /* Cleanup */ + cpl_free(a_index); + + return e; +} + +/**@}*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_index_asc Function for sort in ascending order elements of + * the type sort_index (data field). + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is less than 'b' + * 1: If 'a' element is greater than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_index_asc(const void *a, const void *b) { + + const sort_index *a_d = (const sort_index*)a; + const sort_index *b_d = (const sort_index*)b; + + return a_d->data < b_d->data ? -1 : (a_d->data > b_d->data ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_int_asc Function for sort in ascending order elements of + * the type int + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is less than 'b' + * 1: If 'a' element is greater than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_int_asc(const void * a, const void * b) +{ + const int a_d = *(const int *)a; + const int b_d = *(const int *)b; + + return a_d < b_d ? -1 : (a_d > b_d ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_double_asc Function for sort in ascending order elements of + * the type double + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is less than 'b' + * 1: If 'a' element is greater than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_double_asc(const void * a, const void * b) +{ + const double a_d = *(const double *)a; + const double b_d = *(const double *)b; + + return a_d < b_d ? -1 : (a_d > b_d ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_cpl_size_asc Function for sort in ascending order elements of + * the type cpl_size + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is less than 'b' + * 1: If 'a' element is greater than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_cpl_size_asc(const void *a, const void *b) +{ + const cpl_size a_cs = *(const cpl_size *)a; + const cpl_size b_cs = *(const cpl_size *)b; + + return a_cs < b_cs ? -1 : (a_cs > b_cs ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_hdrl_value_asc Function for sort in ascending order elements of + * the type hdrl_value (data field). + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is less than 'b' + * 1: If 'a' element is greater than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_hdrl_value_asc(const void *a, const void *b) +{ + const hdrl_value *a_hv = (const hdrl_value*)a; + const hdrl_value *b_hv = (const hdrl_value*)b; + + return a_hv->data < b_hv->data ? -1 : (a_hv->data > b_hv->data ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_index_des Function for sort in descending order elements of + * the type sort_index (data field). + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is greater than 'b' + * 1: If 'a' element is less than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_index_des(const void *a, const void *b) { + + const sort_index *a_d = (const sort_index*)a; + const sort_index *b_d = (const sort_index*)b; + + return a_d->data > b_d->data ? -1 : (a_d->data < b_d->data ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_int_des Function for sort in descending order elements of + * the type int + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is greater than 'b' + * 1: If 'a' element is less than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_int_des(const void * a, const void * b) +{ + const int a_d = *(const int *)a; + const int b_d = *(const int *)b; + + return a_d > b_d ? -1 : (a_d < b_d ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_double_des Function for sort in descending order elements of + * the type double + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is greater than 'b' + * 1: If 'a' element is less than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_double_des(const void * a, const void * b) +{ + const double a_d = *(const double *)a; + const double b_d = *(const double *)b; + + return a_d > b_d ? -1 : (a_d < b_d ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_cpl_size_des Function for sort in descending order elements of + * the type cpl_size + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is greater than 'b' + * 1: If 'a' element is less than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_cpl_size_des(const void *a, const void *b) +{ + const cpl_size a_cs = *(const cpl_size *)a; + const cpl_size b_cs = *(const cpl_size *)b; + + return a_cs > b_cs ? -1 : (a_cs < b_cs ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief cmp_hdrl_value_des Function for sort in descending order elements of + * the type hdrl_value (data field). + * + * @param a generic pointer to an element of the array (first in the comparison) + * @param b generic pointer to an element of the array (second in the comparison) + * + * @return result -1: If 'a' element is greater than 'b' + * 1: If 'a' element is less than 'b' + * 0: If 'a' element is equal than 'b' + */ +/* ---------------------------------------------------------------------------*/ +static int cmp_hdrl_value_des(const void *a, const void *b) +{ + const hdrl_value *a_hv = (const hdrl_value*)a; + const hdrl_value *b_hv = (const hdrl_value*)b; + + return a_hv->data > b_hv->data ? -1 : (a_hv->data < b_hv->data ? 1 : 0); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief sort_and_gen_index hdrl function for sort the 'a' double array + * and fill the in/out array with index (type sort_index[]) + * + * @param a pointer to an double array + * @param nE Number of elements in the array of doubles + * @param a_index Output vector that it's necessary to fill with the index order. + * @param dir Direction of sort the arrays (Ascending or Descending) + * + * @return cpl_error_code. Return the error code provided by the sort functions. + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code sort_and_gen_index(double *a, cpl_size nE, sort_index *a_index, cpl_sort_direction dir){ + + /* Update the a_index vector with the values in 'a' array and your position + * in the array for sort with index */ + for (cpl_size i = 0; i < nE; i++) { + a_index[i].data = a[i]; + a_index[i].index = i; + } + + /* Sort array in ascending/descending order the array with data and index */ + cpl_error_code e; + if (dir == CPL_SORT_ASCENDING) { + e = sort_array_f(a_index, nE, sizeof(*a_index), &cmp_index_asc); + } else { + e = sort_array_f(a_index, nE, sizeof(*a_index), &cmp_index_des); + } + + /* Update the original 'a' double array and keep the sort apply in a_index array */ + if (e == CPL_ERROR_NONE ) { + for (cpl_size i = 0; i < nE; i++) { + a[i] = a_index[i].data; + } + } + + return e; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief sort_array_using_index + * hdrl function for sort several arrays following the input index + * + * @param a_index pointer to an sort_index array with the index to order the 'b' array. + * @param nE Number of elements in the array 'a_index' and 'b' + * @param type Datatype of elements in the 'b' generic array. Standard type in hdrl_sort_type + * + * @return cpl_error_code. Return the error code provided by the sort functions. + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code sort_array_using_index(sort_index *a_index, cpl_size nE, void *b, hdrl_sort_type type) +{ + if (type == HDRL_SORT_INT) { + + /* Cast generic 'b' array to int + * Copy the values in a auxiliary vector + * and apply the sort in the a_index array using the copy values */ + int *b_cast = (int *)b; + int b_aux[nE]; + for (cpl_size i = 0; i < nE; i++) { + b_aux[i] = b_cast[i]; + } + for (cpl_size i = 0; i < nE; i++) { + b_cast[i] = b_aux[a_index[i].index]; + } + + } else if (type == HDRL_SORT_DOUBLE) { + + /* Cast generic 'b' array to double + * Copy the values in a auxiliary vector + * and apply the sort in the a_index array using the copy values */ + double *b_cast = (double *)b; + double b_aux[nE]; + for (cpl_size i = 0; i < nE; i++) { + b_aux[i] = b_cast[i]; + } + for (cpl_size i = 0; i < nE; i++) { + b_cast[i] = b_aux[a_index[i].index]; + } + + } else if (type == HDRL_SORT_CPL_SIZE) { + + /* Cast generic 'b' array to cpl_size + * Copy the values in a auxiliary vector + * and apply the sort in the a_index array using the copy values */ + cpl_size *b_cast = (cpl_size *)b; + cpl_size b_aux[nE]; + for (cpl_size i = 0; i < nE; i++) { + b_aux[i] = b_cast[i]; + } + for (cpl_size i = 0; i < nE; i++) { + b_cast[i] = b_aux[a_index[i].index]; + } + + } else if (type == HDRL_SORT_HDRL_VALUE) { + + /* Cast generic 'b' array to hdrl_value + * Copy the values in a auxiliary vector + * and apply the sort in the a_index array using the copy values */ + hdrl_value *b_cast = (hdrl_value *)b; + hdrl_value b_aux[nE]; + for (cpl_size i = 0; i < nE; i++) { + b_aux[i] = b_cast[i]; + } + for (cpl_size i = 0; i < nE; i++) { + b_cast[i] = b_aux[a_index[i].index]; + } + + } else { + return CPL_ERROR_ILLEGAL_INPUT; + } + + return CPL_ERROR_NONE; +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/hdrl_cat_utils_sort.h 2018-01-12 09:58:52.000000000 +0000 @@ -0,0 +1,43 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef HDRL_UTILS_SORT_H +#define HDRL_UTILS_SORT_H + + +#include "hdrl_cat_def.h" + + +typedef enum { + HDRL_SORT_INT = 1, + HDRL_SORT_DOUBLE, + HDRL_SORT_CPL_SIZE, + HDRL_SORT_HDRL_VALUE, +} hdrl_sort_type; + +typedef int (*f_compare)(const void *, const void *); + +cpl_error_code sort_array_f(void *a, cpl_size nE, cpl_size sE, f_compare f); +cpl_error_code sort_array( void *a, cpl_size nE, cpl_size sE, hdrl_sort_type type, cpl_sort_direction dir); + +cpl_error_code sort_array_index( double *a, cpl_size nE, void *b, hdrl_sort_type type, cpl_sort_direction dir); +cpl_error_code sort_arrays_index( double *a, cpl_size nE, void **bs, cpl_size nA, hdrl_sort_type *types, cpl_sort_direction dir); + + + #endif /* HDRL_UTILS_SORT_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/Makefile.am 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/Makefile.am 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,85 @@ +## Process this file with automake to produce Makefile.in + +## This file is part of the HDRL Pipeline +## Copyright (C) 2012,2013 European Southern Observatory + +## This library 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 + +AUTOMAKE_OPTIONS = 1.8 foreign + +DISTCLEANFILES = *~ + +# NOTE: Only build this directory. The tests subdir is built from the top level +# Makefile to maintain the correct build order and break the circular dependency +# between libcatalogue, libhdrl and the unit test binaries. +SUBDIRS = . + +if MAINTAINER_MODE + +MAINTAINERCLEANFILES = Makefile.in + +endif + +AM_CPPFLAGS = -DCX_LOG_DOMAIN=\"HdrlLib\" -DHDRL_USE_PRIVATE $(CPL_INCLUDES) -I$(top_srcdir) + +noinst_LTLIBRARIES = libcatalogue.la + +noinst_HEADERS = \ + hdrl_cat_def.h \ + hdrl_cat_apclust.h \ + hdrl_cat_apio.h \ + hdrl_cat_apline.h \ + hdrl_cat_areals.h \ + hdrl_cat_casu.h \ + hdrl_cat_conf.h \ + hdrl_cat_utils_sort.h \ + hdrl_cat_utils.h \ + hdrl_cat_classify.h \ + hdrl_cat_terminate.h \ + hdrl_cat_background.h \ + hdrl_cat_extend.h \ + hdrl_cat_overlp.h \ + hdrl_cat_phopt.h \ + hdrl_cat_radii.h \ + hdrl_cat_filter.h \ + hdrl_cat_statistics.h \ + hdrl_cat_table.h \ + hdrl_cat_moments.h \ + hdrl_cat_solve.h \ + hdrl_cat_polynm.h \ + hdrl_cat_seeing.h + +libcatalogue_la_SOURCES = \ + hdrl_cat_apclust.c \ + hdrl_cat_apio.c \ + hdrl_cat_apline.c \ + hdrl_cat_areals.c \ + hdrl_cat_casu.c \ + hdrl_cat_conf.c \ + hdrl_cat_utils_sort.c \ + hdrl_cat_utils.c \ + hdrl_cat_classify.c \ + hdrl_cat_terminate.c \ + hdrl_cat_background.c \ + hdrl_cat_extend.c \ + hdrl_cat_overlp.c \ + hdrl_cat_phopt.c \ + hdrl_cat_radii.c \ + hdrl_cat_filter.c \ + hdrl_cat_statistics.c \ + hdrl_cat_table.c \ + hdrl_cat_moments.c \ + hdrl_cat_solve.c \ + hdrl_cat_polynm.c \ + hdrl_cat_seeing.c diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/Makefile.in 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/Makefile.in 2018-04-13 15:46:32.000000000 +0000 @@ -0,0 +1,828 @@ +# Makefile.in generated by automake 1.15 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2014 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = catalogue +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/m4macros/cpl-pipeline.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libcatalogue_la_LIBADD = +am_libcatalogue_la_OBJECTS = hdrl_cat_apclust.lo hdrl_cat_apio.lo \ + hdrl_cat_apline.lo hdrl_cat_areals.lo hdrl_cat_casu.lo \ + hdrl_cat_conf.lo hdrl_cat_utils_sort.lo hdrl_cat_utils.lo \ + hdrl_cat_classify.lo hdrl_cat_terminate.lo \ + hdrl_cat_background.lo hdrl_cat_extend.lo hdrl_cat_overlp.lo \ + hdrl_cat_phopt.lo hdrl_cat_radii.lo hdrl_cat_filter.lo \ + hdrl_cat_statistics.lo hdrl_cat_table.lo hdrl_cat_moments.lo \ + hdrl_cat_solve.lo hdrl_cat_polynm.lo hdrl_cat_seeing.lo +libcatalogue_la_OBJECTS = $(am_libcatalogue_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/admin/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libcatalogue_la_SOURCES) +DIST_SOURCES = $(libcatalogue_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + distdir +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/admin/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPL_INCLUDES = @CPL_INCLUDES@ +CPL_LDFLAGS = @CPL_LDFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DOXYGEN = @DOXYGEN@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_BINARY_AGE = @HDRL_BINARY_AGE@ +HDRL_BINARY_VERSION = @HDRL_BINARY_VERSION@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERFACE_AGE = @HDRL_INTERFACE_AGE@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_MAJOR_VERSION = @HDRL_MAJOR_VERSION@ +HDRL_MICRO_VERSION = @HDRL_MICRO_VERSION@ +HDRL_MINOR_VERSION = @HDRL_MINOR_VERSION@ +HDRL_VERSION = @HDRL_VERSION@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LATEX = @LATEX@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBCEXT = @LIBCEXT@ +LIBCPLCORE = @LIBCPLCORE@ +LIBCPLDFS = @LIBCPLDFS@ +LIBCPLDRS = @LIBCPLDRS@ +LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_AGE = @LT_AGE@ +LT_CURRENT = @LT_CURRENT@ +LT_REVISION = @LT_REVISION@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +all_includes = @all_includes@ +all_ldflags = @all_ldflags@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AUTOMAKE_OPTIONS = 1.8 foreign +DISTCLEANFILES = *~ + +# NOTE: Only build this directory. The tests subdir is built from the top level +# Makefile to maintain the correct build order and break the circular dependency +# between libcatalogue, libhdrl and the unit test binaries. +SUBDIRS = . +@MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in +AM_CPPFLAGS = -DCX_LOG_DOMAIN=\"HdrlLib\" -DHDRL_USE_PRIVATE $(CPL_INCLUDES) -I$(top_srcdir) +noinst_LTLIBRARIES = libcatalogue.la +noinst_HEADERS = \ + hdrl_cat_def.h \ + hdrl_cat_apclust.h \ + hdrl_cat_apio.h \ + hdrl_cat_apline.h \ + hdrl_cat_areals.h \ + hdrl_cat_casu.h \ + hdrl_cat_conf.h \ + hdrl_cat_utils_sort.h \ + hdrl_cat_utils.h \ + hdrl_cat_classify.h \ + hdrl_cat_terminate.h \ + hdrl_cat_background.h \ + hdrl_cat_extend.h \ + hdrl_cat_overlp.h \ + hdrl_cat_phopt.h \ + hdrl_cat_radii.h \ + hdrl_cat_filter.h \ + hdrl_cat_statistics.h \ + hdrl_cat_table.h \ + hdrl_cat_moments.h \ + hdrl_cat_solve.h \ + hdrl_cat_polynm.h \ + hdrl_cat_seeing.h + +libcatalogue_la_SOURCES = \ + hdrl_cat_apclust.c \ + hdrl_cat_apio.c \ + hdrl_cat_apline.c \ + hdrl_cat_areals.c \ + hdrl_cat_casu.c \ + hdrl_cat_conf.c \ + hdrl_cat_utils_sort.c \ + hdrl_cat_utils.c \ + hdrl_cat_classify.c \ + hdrl_cat_terminate.c \ + hdrl_cat_background.c \ + hdrl_cat_extend.c \ + hdrl_cat_overlp.c \ + hdrl_cat_phopt.c \ + hdrl_cat_radii.c \ + hdrl_cat_filter.c \ + hdrl_cat_statistics.c \ + hdrl_cat_table.c \ + hdrl_cat_moments.c \ + hdrl_cat_solve.c \ + hdrl_cat_polynm.c \ + hdrl_cat_seeing.c + +all: all-recursive + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign catalogue/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign catalogue/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libcatalogue.la: $(libcatalogue_la_OBJECTS) $(libcatalogue_la_DEPENDENCIES) $(EXTRA_libcatalogue_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libcatalogue_la_OBJECTS) $(libcatalogue_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_apclust.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_apio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_apline.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_areals.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_background.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_casu.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_classify.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_conf.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_extend.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_filter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_moments.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_overlp.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_phopt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_polynm.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_radii.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_seeing.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_solve.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_statistics.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_table.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_terminate.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_utils.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_utils_sort.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-recursive + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-recursive + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: + +.MAKE: $(am__recursive_targets) install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ + check-am clean clean-generic clean-libtool \ + clean-noinstLTLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_apio-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_apio-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_apio-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_apio-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,69 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + /* Create an input apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.inframe = NULL; + ap.conframe = NULL; + + /* Initialize */ + hdrl_apinit(&ap); + + /* Test some of the various bits of the structure to see if they are the correct values */ + cpl_test_eq( ap.maxpa, 1024); + cpl_test_eq( ap.maxip, 0); + cpl_test_nonnull( ap.lastline); + cpl_test_nonnull( ap.pstack); + cpl_test_nonnull( ap.parent); + cpl_test_eq( ap.pstack[10], 10); + cpl_test_eq( ap.parent[10].pnop, -1); + cpl_test_eq( ap.parent[10].pnbp, -1); + cpl_test_eq( ap.ipstack, 1); + cpl_test_nonnull( ap.bstack); + cpl_test_nonnull( ap.blink); + cpl_test_nonnull( ap.plessey); + cpl_test_eq( ap.bstack[10], 10); + cpl_test_eq( ap.ibstack, 2); + cpl_test_eq( ap.nimages, 0); + cpl_test_eq( ap.areal[1], 2 * ap.areal[0]); + cpl_test_eq( ap.npl, ap.lsiz); + cpl_test_eq( ap.npl_pix, 0); + cpl_test_nonnull( ap.plarray); + cpl_test_eq( ap.backmap.nby, -1); + cpl_test_null( ap.backmap.bvals); + cpl_test_null( ap.indata); + cpl_test_null( ap.confdata); + + /* Clean up */ + hdrl_apclose(&ap); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_areals-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_areals-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_areals-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_areals-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,110 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_areals.h" + + +#define NT 117 + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + cpl_size x[] = {398,399,400,397,398,399,400,401,402,403,396,397,398,399,400, + 401,402,403,404,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,395,396,397,398,399,400,401,402, + 403,404,405,406,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,396,397,398,399,400,401,402,403, + 404,397,398,399,400,401,402,403,398,399,400,401}; + + cpl_size y[] = {394,394,394,395,395,395,395,395,395,395,396,396,396,396,396, + 396,396,396,396,397,397,397,397,397,397,397,397,397,397,397, + 398,398,398,398,398,398,398,398,398,398,398,399,399,399,399, + 399,399,399,399,399,399,399,400,400,400,400,400,400,400,400, + 400,400,400,400,401,401,401,401,401,401,401,401,401,401,401, + 402,402,402,402,402,402,402,402,402,402,402,403,403,403,403, + 403,403,403,403,403,403,403,404,404,404,404,404,404,404,404, + 404,405,405,405,405,405,405,405,406,406,406,406}; + + double z[] = {8.87152,12.515,7.69699,10.8527,22.2509,21.7368,13.0388, + 12.1853,17.1976,7.43948,15.2245,29.1964,37.9117,57.9371, + 71.5542,57.1288,34.7726,15.5934,11.5374,15.995,21.3606, + 60.4006,103.46,147.55,168.274,147.476,98.9157,51.7186,20.188, + 3.04248,5.77832,49.3103,98.2057,187.557,268.353,310.638, + 274.295,183.969,94.6933,47.9889,20.245,26.3758,59.1781, + 152.389,275.916,395.107,450.251,397.53,272.322,147.053,54.767, + 11.8971,13.3888,73.3689,165.899,298.455,449.707,493.25,441.585, + 299.31,157.474,70.1224,15.5313,8.76074,20.7188,54.5798,141.249, + 264.87,382.736,435.452,393.871,268.175,138.485,65.9307,28.7812, + 19.379,36.6449,93.5458,186.823,270.95,305.093,260.879,183.683, + 100.676,32.6281,16.6497,5.94965,17.8105,57.256,106.32,145.264, + 164.271,137.093,88.9384,60.7841,31.8582,10.0435,4.69162, + 15.2187,32.5385,61.0381,74.5399,67.3727,43.3964,25.0956, + 16.7595,-0.37323,21.3832,19.2497,18.5883,9.37448,19.6048, + 11.5006,13.0159,14.5852,13.66,-1.04889}; + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.inframe = NULL; + ap.conframe = NULL; + + /* Initialize */ + hdrl_apinit(&ap); + + ap.npl_pix = NT; + ap.plarray = cpl_realloc(ap.plarray, NT * sizeof(*ap.plarray)); + for (cpl_size i = 0; i < NT; i++) { + ap.plarray[i].x = x[i]; + ap.plarray[i].y = y[i]; + ap.plarray[i].z = z[i]; + ap.plarray[i].zsm = z[i]; + } + + ap.xintmin = 0.; + ap.areal_offset = 3.47165; + ap.thresh = 11.0936; + ap.fconst = 1.4427; + + /* Run the test */ + cpl_size iareal[NAREAL]; + hdrl_areals(&ap, iareal); + + cpl_test_eq(iareal[0], 104); + cpl_test_eq(iareal[1], 75); + cpl_test_eq(iareal[2], 63); + cpl_test_eq(iareal[3], 45); + cpl_test_eq(iareal[4], 25); + cpl_test_eq(iareal[5], 9); + cpl_test_eq(iareal[6], 0); + cpl_test_eq(iareal[7], 0); + + /* Clean up */ + hdrl_apclose(&ap); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_background-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_background-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_background-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_background-test.c 2018-01-17 15:37:05.000000000 +0000 @@ -0,0 +1,88 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_background.h" + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + /* Create an input apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.inframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE); + ap.conframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE); + + /* Initialize */ + hdrl_apinit(&ap); + + ap.indata = cpl_image_get_data_double(ap.inframe); + ap.confdata = cpl_image_get_data_double(ap.conframe); + ap.mflag = cpl_malloc(ap.lsiz * ap.csiz * sizeof(*ap.mflag)); + + double null_value = -100.; + for (cpl_size i = 0; i < ap.lsiz * ap.csiz; i++) { + ap.mflag[i] = null_value; + } + + /* Create a background */ + cpl_image_fill_noise_uniform(ap.inframe, -10., 10.); + cpl_image_add_scalar( ap.inframe, 5000.); + cpl_image_fill_noise_uniform(ap.conframe, 99, 101); + + /* Get the background value */ + double skymed; + double skysig; + cpl_test_eq(hdrl_backstats(&ap, null_value, &skymed, &skysig), CPL_ERROR_NONE); + cpl_test_rel(skymed, 5000., 0.01); + cpl_test_rel(skysig, 20 / sqrt(12), 0.1); + + /* Create a background map */ + hdrl_casu_result *res = cpl_malloc(sizeof(hdrl_casu_result)); + res->background = cpl_image_new(ap.lsiz, ap.csiz, CPL_TYPE_DOUBLE); + cpl_test_eq(hdrl_background(&ap, 64, -100., 1, res), CPL_ERROR_NONE); + + for (cpl_size j = 0; j < ap.backmap.nby; j++) { + for (cpl_size i = 0; i < ap.backmap.nbx; i++) { + cpl_test_rel((ap.backmap.bvals)[i][j], 5000., 0.01); + } + } + cpl_test_rel(cpl_image_get_median(ap.inframe), 5000., 0.1); + + /* TODO: Check results */ + hdrl_backest(&ap, 1000., 1000., &skymed, &skysig); + cpl_test_rel(skymed, 5000., 0.01); + cpl_test_lt(0., skysig); + cpl_image_delete(res->background); + cpl_free(res); + + /* Clean up */ + hdrl_apclose(&ap); + cpl_free(ap.mflag); + cpl_image_delete(ap.inframe); + cpl_image_delete(ap.conframe); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_addmul-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_addmul-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_addmul-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_addmul-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,319 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_casu.h" + + +#define COMP_TOL_REL 1e-4 +#define COMP_TOL_ABS 1e-2 +#define IMG_XSIZE 110 * 2 +#define IMG_YSIZE 150 * 2 +#define CELL_SIZE 32 +#define APER_FLUX_NUM "Aper_flux_3" +#define NUM_FACTORS 5 +#define NUM_BIASES 5 +#define BIASES {2., 100., 5000., 5.e4, 5.e5} +#define FACTORS {2., 10., 100., 1.e4, 1.e6} + + +/*----------------------------------------------------------------------------*/ +/** + * @brief Check effect of multiplication on a given "Aper_flux", + * "Isophotal_flux", "FWHM", "Kron_radius", "Classification", + * "X_coordinate", "X_coordinate_err", "Y_coordinate" and "Y_coordinate_err". + * + * @note Magic numerical constants inherited from 'hdrl_casu_catalogue-test.c' + * + * @return cpl_error_code + * + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_casumul_compute(double factor) +{ + /* Check inherited status */ + hdrl_casu_result *res1 = cpl_calloc(1, sizeof(hdrl_casu_result)); + hdrl_casu_result *res_p2 = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(NULL, NULL, NULL, 5, 1.5, 1, 3.5, 1, + CELL_SIZE, 6, 1.0, 2.0, HDRL_SATURATION_INIT, res1), CPL_ERROR_NULL_INPUT); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null( res1->catalogue); + hdrl_casu_tfits_delete(res1->catalogue); + cpl_image_delete( res1->segmentation_map); + cpl_image_delete( res1->background); + cpl_free(res1); + + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + cpl_image_fill_noise_uniform(bkg, -10., 10.); + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + + double xpos = 100.; + double ypos = 100.; + double norm = 5000.; + cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma); + cpl_image_add(bkg, im); + cpl_image_delete(im); + + /* Mult */ + cpl_image *bkg2 = cpl_image_duplicate(bkg); + cpl_image_multiply_scalar(bkg2, factor); + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap( bkg); + hdrl_casu_fits *inf2 = hdrl_casu_fits_wrap(bkg2); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap( cnf); + + /* Give it a WCS */ + cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); + cpl_propertylist_update_int( pl, "NAXIS1", IMG_XSIZE ); + cpl_propertylist_update_int( pl, "NAXIS2", IMG_YSIZE ); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl); + + /* Run casu catalogue */ + hdrl_casu_result * res2 = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(inf, inconf, wcs, 5, 1.5, 0, 5.0, 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res2), CPL_ERROR_NONE); + cpl_test_nonnull(res2->catalogue); + hdrl_casu_fits_delete(inf); + + /* Run casu catalogue for Mul*/ + cpl_test_eq(hdrl_casu_catalogue(inf2, inconf, wcs, 5, 1.5, 0, 5., 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE); + cpl_test_nonnull(res_p2->catalogue); + hdrl_casu_fits_delete(inf2); + hdrl_casu_fits_delete(inconf); + cpl_wcs_delete(wcs); + + /*** Tests ***/ + int nl; + + cpl_test_image_rel(res2->segmentation_map, res_p2->segmentation_map, COMP_TOL_REL); + + cpl_table *tab = hdrl_casu_tfits_get_table(res2->catalogue); + cpl_test_nonnull(tab); + + cpl_table *tab_p2 = hdrl_casu_tfits_get_table(res_p2->catalogue); + cpl_test_nonnull(tab_p2); + + + cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, 0, &nl), + cpl_table_get_double(tab_p2, APER_FLUX_NUM, 0, &nl) / factor, COMP_TOL_REL ); + cpl_test_rel( cpl_table_get_double(tab, "Isophotal_flux", 0, &nl), + cpl_table_get_double(tab_p2, "Isophotal_flux", 0, &nl) / factor, COMP_TOL_REL ); + cpl_test_rel( cpl_table_get_double(tab, "FWHM", 0, &nl), + cpl_table_get_double(tab_p2, "FWHM", 0, &nl), COMP_TOL_REL ); + cpl_test_rel( cpl_table_get_double(tab, "Kron_radius", 0, &nl), + cpl_table_get_double(tab_p2, "Kron_radius", 0, &nl), COMP_TOL_REL ); + cpl_test_eq ( cpl_table_get_double(tab, "Classification", 0, &nl), + cpl_table_get_double(tab_p2, "Classification", 0, &nl) ); + cpl_test_rel( cpl_table_get_double(tab, "X_coordinate", 0, &nl), + cpl_table_get_double(tab_p2, "X_coordinate", 0, &nl), COMP_TOL_REL ); + cpl_test_abs( cpl_table_get_double(tab, "X_coordinate_err", 0, &nl), + cpl_table_get_double(tab_p2, "X_coordinate_err", 0, &nl), COMP_TOL_ABS ); + cpl_test_rel( cpl_table_get_double(tab, "Y_coordinate", 0, &nl), + cpl_table_get_double(tab_p2, "Y_coordinate", 0, &nl), COMP_TOL_REL ); + cpl_test_abs( cpl_table_get_double(tab, "Y_coordinate_err", 0, &nl), + cpl_table_get_double(tab_p2, "Y_coordinate_err", 0, &nl), COMP_TOL_ABS ); + + /* Clean up */ + cpl_image_delete( res2->segmentation_map); + cpl_image_delete( res2->background); + hdrl_casu_tfits_delete(res2->catalogue); + cpl_free(res2); + + cpl_image_delete( res_p2->segmentation_map); + cpl_image_delete( res_p2->background); + hdrl_casu_tfits_delete(res_p2->catalogue); + cpl_free(res_p2); + + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check effect of addition on a given "Aper_flux", + "Isophotal_flux", "FWHM", "Kron_radius", "Classification", "X_coordinate", + "X_coordinate_err", "Y_coordinate" and "Y_coordinate_err". + @note Magic numerical constants inherited from 'hdrl_casu_catalogue-test.c' + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_casuadd_compute(double bias) +{ + /* Check inherited status */ + hdrl_casu_result *res1 = cpl_calloc(1, sizeof(hdrl_casu_result)); + hdrl_casu_result *res_p2 = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(NULL, NULL, NULL, 5, 1.5, 1, 3.5, 1, + CELL_SIZE, 6, 1., 2., HDRL_SATURATION_INIT, res1), CPL_ERROR_NULL_INPUT); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(res1->catalogue); + hdrl_casu_tfits_delete(res1->catalogue); + cpl_image_delete( res1->segmentation_map); + cpl_image_delete( res1->background); + cpl_free(res1); + + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + cpl_image_fill_noise_uniform(bkg, -10., 10.); + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + + double xpos = 100.; + double ypos = 100.; + double norm = 1000.; + cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma); + cpl_image_add(bkg, im); + cpl_image_delete(im); + + /* Add */ + cpl_image *bkg2 = cpl_image_duplicate(bkg); + cpl_image_add_scalar(bkg2, bias); + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap( bkg); + hdrl_casu_fits *inf2 = hdrl_casu_fits_wrap(bkg2); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap( cnf); + + /* Give it a WCS */ + cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); + cpl_propertylist_update_int( pl, "NAXIS1", IMG_XSIZE ); + cpl_propertylist_update_int( pl, "NAXIS2", IMG_YSIZE ); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl); + + /* Run casu catalogue */ + hdrl_casu_result *res2 = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(inf, inconf, wcs, 5, 1.5, 0, 5., 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res2), CPL_ERROR_NONE); + cpl_test_nonnull(res2->catalogue); + hdrl_casu_fits_delete(inf); + + /* Run casu catalogue for ADD*/ + cpl_test_eq(hdrl_casu_catalogue(inf2, inconf, wcs, 5, 1.5, 0, 5., 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE); + cpl_test_nonnull(res_p2->catalogue); + hdrl_casu_fits_delete(inf2); + hdrl_casu_fits_delete(inconf); + cpl_wcs_delete(wcs); + + /*** Tests ***/ + int nl; + + cpl_test_image_rel(res2->segmentation_map, res_p2->segmentation_map, COMP_TOL_REL); + + cpl_table *tab = hdrl_casu_tfits_get_table(res2->catalogue); + cpl_test_nonnull(tab); + + cpl_table *tab_p2 = hdrl_casu_tfits_get_table(res_p2->catalogue); + cpl_test_nonnull(tab_p2); + + cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, 0, &nl), + cpl_table_get_double(tab_p2, APER_FLUX_NUM, 0, &nl), COMP_TOL_REL ); + cpl_test_rel( cpl_table_get_double(tab, "Isophotal_flux", 0, &nl), + cpl_table_get_double(tab_p2, "Isophotal_flux", 0, &nl), COMP_TOL_REL ); + cpl_test_rel( cpl_table_get_double(tab, "FWHM", 0, &nl), + cpl_table_get_double(tab_p2, "FWHM", 0, &nl), COMP_TOL_REL ); + cpl_test_rel( cpl_table_get_double(tab, "Kron_radius", 0, &nl), + cpl_table_get_double(tab_p2, "Kron_radius", 0, &nl), COMP_TOL_REL ); + cpl_test_eq ( cpl_table_get_double(tab, "Classification", 0, &nl), + cpl_table_get_double(tab_p2, "Classification", 0, &nl) ); + cpl_test_rel( cpl_table_get_double(tab, "X_coordinate", 0, &nl), + cpl_table_get_double(tab_p2, "X_coordinate", 0, &nl), COMP_TOL_REL ); + cpl_test_abs( cpl_table_get_double(tab, "X_coordinate_err", 0, &nl), + cpl_table_get_double(tab_p2, "X_coordinate_err", 0, &nl), COMP_TOL_ABS ); + cpl_test_rel( cpl_table_get_double(tab, "Y_coordinate", 0, &nl), + cpl_table_get_double(tab_p2, "Y_coordinate", 0, &nl), COMP_TOL_REL ); + cpl_test_abs( cpl_table_get_double(tab, "Y_coordinate_err", 0, &nl), + cpl_table_get_double(tab_p2, "Y_coordinate_err", 0, &nl), COMP_TOL_ABS ); + + /* Clean up */ + cpl_image_delete( res2->segmentation_map); + cpl_image_delete( res2->background); + hdrl_casu_tfits_delete(res2->catalogue); + cpl_free(res2); + + cpl_image_delete( res_p2->segmentation_map); + cpl_image_delete( res_p2->background); + hdrl_casu_tfits_delete(res_p2->catalogue); + cpl_free(res_p2); + + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of addition or multiplication of some scalar value + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + double bias[] = BIASES; + for (cpl_size i = 0; i < NUM_BIASES; i++) { + hdrl_casuadd_compute(bias[i]); + } + + double factor[] = FACTORS; + for (cpl_size i = 0; i < NUM_FACTORS; i++) { + hdrl_casumul_compute(factor[i]); + } + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_bkg_badpatch-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_bkg_badpatch-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_bkg_badpatch-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu_bkg_badpatch-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,252 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_casu.h" + + +#define NTEST 10 +#define COMP_TOLERANCE 1e-2 +#define CORNER_OFFSET 10 +#define CORNER_REL_TOL 1e-2 +#define X_OS_P1 60 +#define X_OS_P2 95 +#define STAR 7 +#define PATCH_SIZE 100 /* even number (patch is a square) */ +#define IMG_XSIZE 1100 +#define IMG_YSIZE 1500 +#define CELL_SIZE 32 +#define MIN_RAMP 10. +#define MAX_RAMP 100. +#define APER_FLUX_NUM "Aper_flux_3" + +/*----------------------------------------------------------------------------*/ +/** + * @brief Check effect of bad pixel square patches in various conditions + * + * @note Magic numerical constants inherited from 'hdrl_casu_catalogue-test.c' + * + * @return cpl_error_code + * + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_casubkg_badpatch_compute(void) +{ + double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.}; + + /* Check inherited status */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + hdrl_casu_result *res_p1 = cpl_calloc(1, sizeof(hdrl_casu_result)); + hdrl_casu_result *res_p2 = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(NULL, NULL, NULL, 5, 1.5, 1, 3.5, 1, CELL_SIZE, + 6, 1.0, 2.0, HDRL_SATURATION_INIT, res), CPL_ERROR_NULL_INPUT); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(res->catalogue); + + cpl_image_delete(res->segmentation_map); + cpl_image_delete(res->background); + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *aux = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + cpl_image_fill_noise_uniform(bkg, -10., 10.); + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + cpl_image *cnf_p1 = cpl_image_duplicate(cnf); + cpl_image *cnf_p2 = cpl_image_duplicate(cnf); + + double tot[NTEST]; + for (cpl_size i = 0; i < NTEST; i++) { + cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma); + tot[i] = cpl_image_get_flux(im); + cpl_image_add(bkg, im); + } + cpl_image_delete(im); + + /* Add gradient */ + double dlt_ramp = MAX_RAMP - MIN_RAMP; + for (cpl_size i = 1; i <= IMG_XSIZE; i++) { + for (cpl_size j = 1; j <= IMG_YSIZE; j++) { + cpl_image_set(aux, i, j, MIN_RAMP + dlt_ramp * (double)i / IMG_XSIZE); + } + } + cpl_image_add(bkg, aux); + cpl_image_delete(aux); + + cpl_size y_os = 0; + + /* Generation of confidence map "Patch Close" */ + cpl_size x_os = X_OS_P1; + for (cpl_size i = 0; i <= PATCH_SIZE; i++) { + for (cpl_size j = 0; j <= PATCH_SIZE; j++) { + cpl_image_set(cnf_p1, xpos[STAR]-(PATCH_SIZE/2)+i +x_os, + ypos[STAR]-(PATCH_SIZE/2)+j +y_os, 0); + } + } + + /* Generation of confidence map "Patch Away" */ + x_os = X_OS_P2; + for (cpl_size i = 0; i <= PATCH_SIZE; i++) { + for (cpl_size j = 0; j <= PATCH_SIZE; j++) { + cpl_image_set(cnf_p2, xpos[STAR]-(PATCH_SIZE/2)+i +x_os, + ypos[STAR]-(PATCH_SIZE/2)+j +y_os, 0); + } + } + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap( bkg); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap( cnf); + hdrl_casu_fits *inconf_p1 = hdrl_casu_fits_wrap(cnf_p1); + hdrl_casu_fits *inconf_p2 = hdrl_casu_fits_wrap(cnf_p2); + + /* Give it a WCS */ + cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); + cpl_propertylist_update_int( pl, "NAXIS1", IMG_XSIZE ); + cpl_propertylist_update_int( pl, "NAXIS2", IMG_YSIZE ); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl); + + /* Run casu catalogue */ + res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(inf, inconf, wcs, 5, 1.5, 0, 5., 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res), CPL_ERROR_NONE); + cpl_test_nonnull(res->catalogue); + hdrl_casu_fits_delete(inconf); + + /* Run casu catalogue for PC */ + cpl_test_eq(hdrl_casu_catalogue(inf, inconf_p1, wcs, 5, 1.5, 0, 5., 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p1), CPL_ERROR_NONE); + cpl_test_nonnull(res_p1->catalogue); + hdrl_casu_fits_delete(inconf_p1); + + /* Run casu catalogue for PA*/ + cpl_test_eq(hdrl_casu_catalogue(inf, inconf_p2, wcs, 5, 1.5, 0, 5., 1, + CELL_SIZE, HDRL_CATALOGUE_ALL, 3., 1., HDRL_SATURATION_INIT, res_p2), CPL_ERROR_NONE); + cpl_test_nonnull(res_p2->catalogue); + hdrl_casu_fits_delete(inconf_p2); + hdrl_casu_fits_delete(inf); + cpl_wcs_delete(wcs); + + /*** Tests ***/ + + cpl_test_image_rel(res->background, res_p1->background, COMP_TOLERANCE); + cpl_test_image_rel(res->background, res_p2->background, COMP_TOLERANCE); + + cpl_size corner_x = cpl_image_get_size_x(res->background) -CORNER_OFFSET; + cpl_size corner_y = cpl_image_get_size_y(res->background) -CORNER_OFFSET; + + int rej; + cpl_test_abs(cpl_image_get(res ->background, corner_x, corner_y, &rej), + cpl_image_get(res_p1->background, corner_x, corner_y, &rej), CORNER_REL_TOL); + cpl_test_abs(cpl_image_get(res ->background, corner_x, corner_y, &rej), + cpl_image_get(res_p2->background, corner_x, corner_y, &rej), CORNER_REL_TOL); + + cpl_test_image_rel(res->segmentation_map, res_p1->segmentation_map, COMP_TOLERANCE); + cpl_test_image_rel(res->segmentation_map, res_p2->segmentation_map, COMP_TOLERANCE); + + + /* Check the results. Start by checking the number of rows and columns. Sort the table by X */ + cpl_table *tab = hdrl_casu_tfits_get_table(res ->catalogue); + cpl_table *tab_p1 = hdrl_casu_tfits_get_table(res_p1->catalogue); + cpl_table *tab_p2 = hdrl_casu_tfits_get_table(res_p2->catalogue); + cpl_test_nonnull(tab); + cpl_test_nonnull(tab_p1); + cpl_test_nonnull(tab_p2); + + int nl; + for (cpl_size i = 0; i < NTEST; i++) { + cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, i, &nl), + cpl_table_get_double(tab_p1, APER_FLUX_NUM, i, &nl), COMP_TOLERANCE ); + cpl_test_rel( cpl_table_get_double(tab, APER_FLUX_NUM, i, &nl), + cpl_table_get_double(tab_p2, APER_FLUX_NUM, i, &nl), COMP_TOLERANCE ); + } + + cpl_test_eq(cpl_table_get_ncol(tab), 63); + cpl_test_eq(cpl_table_get_nrow(tab), NTEST); + pl = cpl_propertylist_new(); + cpl_propertylist_append_bool(pl, "X_coordinate", 0); + cpl_table_sort(tab, pl); + cpl_propertylist_delete(pl); + + /* Test the column content of the table */ + for (cpl_size i = 0; i < NTEST; i++) { + cpl_test_abs(xpos[i], cpl_table_get_double(tab, "X_coordinate", i, &nl), 0.2); + cpl_test_abs(ypos[i], cpl_table_get_double(tab, "Y_coordinate", i, &nl), 0.2); + double diff = fabs( cpl_table_get_double(tab, "Aper_flux_5", i, &nl) -tot[i]) + / cpl_table_get_double(tab, "Aper_flux_5_err", i, &nl); + cpl_test_lt(diff, 1.5); + cpl_test_eq( cpl_table_get_double(tab, "Classification", i, &nl), -1.); + } + + /* Clean up */ + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + cpl_image_delete( res_p1->segmentation_map); + cpl_image_delete( res_p1->background); + hdrl_casu_tfits_delete(res_p1->catalogue); + cpl_free(res_p1); + + cpl_image_delete( res_p2->segmentation_map); + cpl_image_delete( res_p2->background); + hdrl_casu_tfits_delete(res_p2->catalogue); + cpl_free(res_p2); + + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Unit tests of bad patches in background + */ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_casubkg_badpatch_compute(); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_casu-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,151 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_casu.h" +#include "../hdrl_cat_table.h" + + +#define NTEST 10 + + +int main(void) +{ + /* Initialise */ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.}; + + /* Check inherited status */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_casu_catalogue(NULL, NULL, NULL, 5, 1.5, 1, 3.5, 1, 64, 6, 1., 2., + HDRL_SATURATION_INIT, res), CPL_ERROR_NULL_INPUT); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null( res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + /* tests tfits */ + cpl_table *test_table = NULL; + cpl_propertylist *test_ehu = NULL; + hdrl_casu_tfits *test_tinf = hdrl_casu_tfits_wrap(test_table, test_ehu); + cpl_test_null(test_tinf); + test_table = cpl_table_new(10); + test_tinf = hdrl_casu_tfits_wrap(test_table, test_ehu); + cpl_test_nonnull(test_tinf); + hdrl_casu_tfits_delete(test_tinf); + test_table = cpl_table_new(10); + test_ehu = cpl_propertylist_new(); + test_tinf = hdrl_casu_tfits_wrap(test_table, test_ehu); + cpl_test_nonnull(test_tinf); + hdrl_casu_tfits_delete(test_tinf); + + + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + cpl_image_fill_noise_uniform(bkg, -10., 10.); + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + + double tot[NTEST]; + for (cpl_size i = 0; i < NTEST; i++) { + cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma); + tot[i] = cpl_image_get_flux(im); + cpl_image_add(bkg, im); + } + cpl_image_delete(im); + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap(bkg); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf); + + /* Give it a WCS */ + cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); + cpl_propertylist_update_int( pl, "NAXIS1", 1024 ); + cpl_propertylist_update_int( pl, "NAXIS2", 1024 ); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl); + + /* Run casu catalogue */ + res = cpl_calloc(1, sizeof(*res)); + cpl_test_eq(hdrl_casu_catalogue(inf, inconf, wcs, 5, 1.5, 0, 5., 1, 64, 6, 3., 1., + HDRL_SATURATION_INIT, res), CPL_ERROR_NONE); + cpl_test_nonnull(res->catalogue); + hdrl_casu_fits_delete(inf); + hdrl_casu_fits_delete(inconf); + + cpl_wcs_delete(wcs); + cpl_image_delete(res->segmentation_map); + cpl_image_delete(res->background); + + /* Check the results. Start by checking the number of rows and columns. Sort the table by X */ + cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue); + cpl_test_nonnull(tab); + cpl_test_eq(cpl_table_get_ncol(tab), NCOLS); + cpl_test_eq(cpl_table_get_nrow(tab), NTEST); + + pl = cpl_propertylist_new(); + cpl_propertylist_append_bool(pl, "X_coordinate", 0); + cpl_table_sort(tab, pl); + cpl_propertylist_delete(pl); + + /* Test the column content of the table */ + int nl; + for (cpl_size i = 0; i < NTEST; i++) { + + cpl_test_abs(xpos[i], cpl_table_get_double(tab, "X_coordinate", i, &nl), 0.2); + cpl_test_abs(ypos[i], cpl_table_get_double(tab, "Y_coordinate", i, &nl), 0.2); + + double diff = fabs( cpl_table_get_double(tab, "Aper_flux_5", i, &nl) - tot[i]) + / cpl_table_get_double(tab, "Aper_flux_5_err", i, &nl); + cpl_test_lt(diff, 1.6); + cpl_test_eq( cpl_table_get_double(tab, "Classification", i, &nl), -1.); + } + + /* Compare some header info */ + pl = hdrl_casu_tfits_get_ehu(res->catalogue); + cpl_test_rel( cpl_propertylist_get_double(pl, "ESO QC IMAGE_SIZE") / 2.355, sigma, 0.1); + + /* Clean up*/ + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_classify-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_classify-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_classify-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_classify-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,134 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_classify.h" +#include "../hdrl_cat_conf.h" +#include "../hdrl_cat_table.h" + + +#define NTEST 10 + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + /* Initialize */ + double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.}; + + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + cpl_image_fill_noise_uniform(bkg, -10., 10.); + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + + double tot[NTEST]; + for (cpl_size i = 0; i < NTEST; i++) { + cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma); + tot[i] = cpl_image_get_flux(im); + cpl_image_add(bkg, im); + } + cpl_image_delete(im); + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap(bkg); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf); + + /* Give it a WCS */ + cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); + + /* Run casu catalogue, TODO: check results */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_catalogue_conf(inf, inconf, 5, 1.5, 0, 5., 1, 64, 6, 3., 1., + HDRL_SATURATION_INIT, res), CPL_ERROR_NONE); + cpl_test_nonnull(res->catalogue); + cpl_image_delete(res->segmentation_map); + cpl_image_delete(res->background); + + /* Check the results. Start by checking the number of rows and columns. Sort the table by X */ + cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue); + cpl_test_nonnull(tab); + cpl_test_eq(cpl_table_get_ncol(tab), NCOLS); + cpl_test_eq(cpl_table_get_nrow(tab), NTEST); + + pl = cpl_propertylist_new(); + cpl_propertylist_append_bool(pl, "X_coordinate", 0); + cpl_table_sort(tab, pl); + cpl_propertylist_delete(pl); + + /* Test the column content of the table */ + int nl; + for (cpl_size i = 0; i < NTEST; i++) { + + cpl_test_abs(xpos[i], cpl_table_get_double(tab, "X_coordinate", i, &nl), 0.2); + cpl_test_abs(ypos[i], cpl_table_get_double(tab, "Y_coordinate", i, &nl), 0.2); + + double diff = fabs(cpl_table_get_double(tab, "Aper_flux_5", i, &nl) - tot[i]) + / cpl_table_get_double(tab, "Aper_flux_5_err", i, &nl); + cpl_test_lt(diff, 1.6); + } + + /*** Run classify and test the values of the classification ***/ + + /* Test 1 */ + cpl_test_eq(hdrl_classify(res->catalogue, 5), CPL_ERROR_NONE); + + pl = hdrl_casu_tfits_get_ehu(res->catalogue); + cpl_test_rel(cpl_propertylist_get_double(pl, "ESO QC IMAGE_SIZE"), 4.47, 0.02); + cpl_test_eq( cpl_propertylist_get_bool( pl, "ESO DRS CLASSIFD" ), 1 ); + cpl_test_rel(cpl_propertylist_get_double(pl, "APCOR3" ), 0.132, 0.01); + + for (cpl_size i = 0; i < NTEST; i++) { + double val = cpl_table_get(hdrl_casu_tfits_get_table(res->catalogue), "Classification", i, NULL); + cpl_test_rel(val, -1., 0.001); + } + + /* Test 2 */ + cpl_test_eq(hdrl_classify(res->catalogue, 10), CPL_ERROR_NONE); + + /* Clean up */ + hdrl_casu_fits_delete(inf); + hdrl_casu_fits_delete(inconf); + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_conf-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_conf-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_conf-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_conf-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,303 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_conf.h" +#include "../hdrl_cat_table.h" + + +#define NTEST 10 + + +/*----------------------------------------------------------------------------*/ +/** + * @brief Fill a propertylist with the values that it needed for wcs + */ +/*----------------------------------------------------------------------------*/ +void fill_plist(cpl_propertylist *pl) +{ + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Create a gaussian image + * + * @return cpl_image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * create_gauss(double dx, double dy, double fwhm) +{ + /* sample gaussian on large grid and sum it down to requested fwhm */ + cpl_size factor = 16; + cpl_size nx = fwhm * 20; + cpl_size ny = fwhm * 20; + cpl_size nnx = nx * factor; + cpl_size nny = ny * factor; + double sigma = fwhm * factor / (2 * sqrt(2 * log(2))); + cpl_image *g = cpl_image_new(nnx, nny, CPL_TYPE_DOUBLE); + + dx *= factor; + dy *= factor; + + cpl_image_fill_gaussian( g, + nnx / 2 + dx, + nny / 2 + dx, + 2. * CPL_MATH_PI * sigma * sigma, + sigma, + sigma); + + cpl_image *r = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + double *dg = cpl_image_get_data_double(g); + double *dr = cpl_image_get_data_double(r); + + for (cpl_size y = 0; y < ny; y++) { + for (cpl_size x = 0; x < nx; x++) { + for (cpl_size i = y * factor; i < y * factor + factor; i++) { + for (cpl_size j = x * factor; j < x * factor + factor; j++) { + dr[y * nx + x] += dg[i * nnx + j]; + } + } + } + } + + for (cpl_size y = 0; y < nny; y++) { + for (cpl_size x = 0; x < nnx; x++) { + dr[y / factor * nx + x / factor] += dg[y * nx + x]; + } + } + + cpl_image_divide_scalar(r, factor * factor); + + /* Close up */ + cpl_image_delete(g); + + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Check hdrl_catalogue_conf() in various conditions + * + * @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_catalogue_hdrl_catalogue_conf_basic(void) +{ + /* Initialize */ + double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.}; + + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + + cpl_image_fill_noise_uniform(bkg, -10., 10. ); + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + double tot[NTEST]; + for (cpl_size i = 0; i < NTEST; i++) { + cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma); + tot[i] = cpl_image_get_flux(im); + cpl_image_add(bkg, im); + } + cpl_image_delete(im); + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap(bkg); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf); + + /* Give it a WCS */ + fill_plist(hdrl_casu_fits_get_ehu(inf)); + + /* Run casu catalogue. TODO: Check results */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_catalogue_conf(inf, inconf, 5, 1.5, 0, 5., 1, 64, 6, 3., 1., + HDRL_SATURATION_INIT,res), CPL_ERROR_NONE); + cpl_test_nonnull(res->catalogue); + cpl_image_delete(res->segmentation_map); + cpl_image_delete(res->background); + + /* Check the results. Start by checking the number of rows and columns. Sort the table by X */ + cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue); + cpl_test_nonnull(tab); + cpl_test_eq(cpl_table_get_ncol(tab), NCOLS); + cpl_test_eq(cpl_table_get_nrow(tab), NTEST); + + cpl_propertylist *pl = cpl_propertylist_new(); + cpl_propertylist_append_bool(pl, "X_coordinate", 0); + cpl_table_sort(tab, pl); + cpl_propertylist_delete(pl); + + /* Test the column content of the table */ + int nl; + for (cpl_size i = 0; i < NTEST; i++) { + + cpl_test_abs(xpos[i], cpl_table_get_double(tab, "X_coordinate", i, &nl), 0.2); + cpl_test_abs(ypos[i], cpl_table_get_double(tab, "Y_coordinate", i, &nl), 0.2); + + double diff = fabs(cpl_table_get_double(tab, "Aper_flux_5", i, &nl) - tot[i]) + / cpl_table_get_double(tab, "Aper_flux_5_err", i, &nl); + cpl_test_lt(diff, 1.6); + } + + /* Clean up */ + hdrl_casu_fits_delete(inf); + hdrl_casu_fits_delete(inconf); + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Check background subtraction of hdrl_catalogue_conf() in various conditions + * + * @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_catalogue_hdrl_catalogue_conf_backsub(void) +{ + cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(cnf, 100.); + + cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image_fill_noise_uniform(im, -10., 10. ); + + /*Set a region arround the object to zero*/ + for (cpl_size x = 400; x < 600; x++) { + for (cpl_size y = 400; y < 600; y++) { + cpl_image_set(im, x, y, 0.); + } + } + + /* Insert an tophat object */ + for (cpl_size x = 500; x < 505; x++) { + for (cpl_size y = 500; y < 505; y++) { + cpl_image_set(im, x, y, 4990.); + } + } + + cpl_image_add_scalar(im, 10.); + hdrl_casu_fits *inf = hdrl_casu_fits_wrap( im); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf); + + /* Run casu catalogue */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_catalogue_conf(inf, inconf, 5, 3., 0, 1., 0, 16, 7, 3., 1., + HDRL_SATURATION_INIT,res), CPL_ERROR_NONE); + cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue); + cpl_test_nonnull(tab); + + /* Check the results. */ + cpl_test_eq(cpl_table_get_nrow(tab), 1); + + /* Test the column content of the table */ + int nl; + cpl_test_abs(5000., cpl_table_get_double(tab, "Aper_flux_1", 0, &nl), 0.2); + + /* Clean up */ + hdrl_casu_fits_delete(inf); + hdrl_casu_fits_delete(inconf); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + cpl_free(res); + + + return cpl_error_get_code(); +} + +cpl_error_code test_gaussians(double dx, double dy, double fwhm) +{ + /* Generate a field with some stars and a confidence map */ + cpl_image *im = create_gauss(dx, dy, fwhm); + hdrl_casu_fits *inf = hdrl_casu_fits_wrap(im); + + /* Give it a WCS */ + fill_plist(hdrl_casu_fits_get_ehu(inf)); + + /* Run casu catalogue. TODO: Check results */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_test_eq(hdrl_catalogue_conf(inf, NULL, 5, 2.5, 0, fwhm, 1, fwhm * 3, 6, 3., 1., + HDRL_SATURATION_INIT, res), CPL_ERROR_NONE); + cpl_test_nonnull(res->catalogue); + cpl_image_delete(res->segmentation_map); + cpl_image_delete(res->background); + + /* Check the results. Start by checking the number of rows and columns. Sort the table by X */ + cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue); + cpl_test_nonnull(tab); + cpl_test_eq(cpl_table_get_ncol(tab), NCOLS); + cpl_test_eq(cpl_table_get_nrow(tab), 1 ); + + /* Test the column content of the table */ + int nl; + cpl_test_abs(fwhm, cpl_table_get_double(tab, "FWHM", 0, &nl), 0.006); + + /* Clean up */ + hdrl_casu_fits_delete(inf); + hdrl_casu_tfits_delete(res->catalogue); + cpl_free(res); + + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Unit tests of hdrl_catalogue_conf in the catalogue module + */ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_catalogue_hdrl_catalogue_conf_basic(); + hdrl_catalogue_hdrl_catalogue_conf_backsub(); + + test_gaussians(.5, .5, 3.); + test_gaussians(.0, .5, 4.); + test_gaussians(.5, .5, 5.); + test_gaussians(.8, .5, 6.); + test_gaussians(.1, .2, 7.); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_filter-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_filter-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_filter-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_filter-test.c 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,70 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_filter.h" + + +#define NUM 100 + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + /* Test 1 */ + double x1[NUM]; + for (cpl_size i = 0; i < NUM; i++) { + x1[i] = 0.; + } + padext(x1, NUM); + + /* Test 2 */ + double x2[NUM]; + for (cpl_size i = 0; i < NUM; i++) { + if (i < NUM / 2) { + x2[i] = -2000.; + } else { + x2[i] = 0.; + } + } + padext(x2, NUM); + + /* Test 3 */ + double x3[NUM]; + for (cpl_size i = 0; i < NUM; i++) { + if (i < NUM / 2) { + x3[i] = 0.; + } else { + x3[i] = -2000.; + } + } + padext(x3, NUM); + + /* Test 4 */ + double x4[NUM]; + for (cpl_size i = 0; i < NUM; i++) { + x4[i] = -2000.; + } + padext(x4, NUM); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_moments-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_moments-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_moments-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_moments-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,109 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_moments.h" + + +#define NT 117 + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + /* Initialize */ + + cpl_size x[] = {398,399,400,397,398,399,400,401,402,403,396,397,398,399,400, + 401,402,403,404,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,395,396,397,398,399,400,401,402, + 403,404,405,406,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,396,397,398,399,400,401,402,403, + 404,397,398,399,400,401,402,403,398,399,400,401}; + + cpl_size y[] = {394,394,394,395,395,395,395,395,395,395,396,396,396,396,396, + 396,396,396,396,397,397,397,397,397,397,397,397,397,397,397, + 398,398,398,398,398,398,398,398,398,398,398,399,399,399,399, + 399,399,399,399,399,399,399,400,400,400,400,400,400,400,400, + 400,400,400,400,401,401,401,401,401,401,401,401,401,401,401, + 402,402,402,402,402,402,402,402,402,402,402,403,403,403,403, + 403,403,403,403,403,403,403,404,404,404,404,404,404,404,404, + 404,405,405,405,405,405,405,405,406,406,406,406}; + + double z[] = {8.87152,12.515,7.69699,10.8527,22.2509,21.7368,13.0388, + 12.1853,17.1976,7.43948,15.2245,29.1964,37.9117,57.9371, + 71.5542,57.1288,34.7726,15.5934,11.5374,15.995,21.3606, + 60.4006,103.46,147.55,168.274,147.476,98.9157,51.7186,20.188, + 3.04248,5.77832,49.3103,98.2057,187.557,268.353,310.638, + 274.295,183.969,94.6933,47.9889,20.245,26.3758,59.1781, + 152.389,275.916,395.107,450.251,397.53,272.322,147.053,54.767, + 11.8971,13.3888,73.3689,165.899,298.455,449.707,493.25,441.585, + 299.31,157.474,70.1224,15.5313,8.76074,20.7188,54.5798,141.249, + 264.87,382.736,435.452,393.871,268.175,138.485,65.9307,28.7812, + 19.379,36.6449,93.5458,186.823,270.95,305.093,260.879,183.683, + 100.676,32.6281,16.6497,5.94965,17.8105,57.256,106.32,145.264, + 164.271,137.093,88.9384,60.7841,31.8582,10.0435,4.69162, + 15.2187,32.5385,61.0381,74.5399,67.3727,43.3964,25.0956, + 16.7595,-0.37323,21.3832,19.2497,18.5883,9.37448,19.6048, + 11.5006,13.0159,14.5852,13.66,-1.04889}; + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.inframe = NULL; + ap.conframe = NULL; + + /* Initialize structure */ + hdrl_apinit(&ap); + + ap.npl_pix = NT; + ap.plarray = cpl_realloc(ap.plarray, NT * sizeof(*ap.plarray)); + for (cpl_size i = 0; i < NT; i++) { + ap.plarray[i].x = x[i]; + ap.plarray[i].y = y[i]; + ap.plarray[i].z = z[i]; + ap.plarray[i].zsm = z[i]; + } + + ap.xintmin = 0.; + + /* Run the test */ + double results[8]; + hdrl_moments(&ap, results); + + cpl_test_eq( results[0], 1. ); + cpl_test_rel(results[1], 400. , 0.01); + cpl_test_rel(results[2], 400. , 0.01); + cpl_test_rel(results[3], 12582.7 , 0.01); + cpl_test_rel(results[4], 3.81789, 0.01); + cpl_test_rel(results[5], 0.10806, 0.01); + cpl_test_rel(results[6], 3.97303, 0.01); + cpl_test_rel(results[7], 493.25 , 0.01); + + /* Clean up */ + hdrl_apclose(&ap); + + + return(cpl_test_end(0)); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_overlp-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_overlp-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_overlp-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_overlp-test.c 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,303 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_areals.h" +#include "../hdrl_cat_conf.h" +#include "../hdrl_cat_moments.h" +#include "../hdrl_cat_overlp.h" + + +#define NTEST 10 +#define NT 117 +#define SIZE_IMAGE 512 +#define CENTER_IMAGE 256 + + +void standard_test(void) +{ + /* Intitialize */ + double xpos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double ypos[] = { 100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; + double norm[] = {1000., 100., 200., 500., 550., 600., 650., 700., 750., 800.}; + + /* Create input data */ + cpl_image *im = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *bkg = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(1024, 1024, CPL_TYPE_DOUBLE); + + cpl_image_fill_noise_uniform(bkg, -10., 10. ); + cpl_image_fill_noise_uniform(cnf, 99.9, 100.1); + + hdrl_casu_fits *infErr = hdrl_casu_fits_wrap( im); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf); + hdrl_casu_fits *inf = hdrl_casu_fits_wrap(bkg); + + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + for (cpl_size i = 0; i < NTEST; i++) { + cpl_image_fill_gaussian(im, xpos[i], ypos[i], norm[i] * norm2, sigma, sigma); + cpl_image_add(bkg, im); + } + + /*** Tests ***/ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_size ipix; + cpl_size icrowd; + + /* Test 1: Error input null */ + ipix = 5; + icrowd = 0; + cpl_test_eq(hdrl_catalogue_conf(infErr, NULL, ipix, 2.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 2 */ + ipix = 5; + icrowd = 0; + cpl_test_eq(hdrl_catalogue_conf(infErr, inconf, ipix, 2.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 3 */ + ipix = 10; + icrowd = 10; + cpl_test_eq(hdrl_catalogue_conf(infErr, NULL, ipix, 2.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 4 */ + ipix = 10; + icrowd = 10; + cpl_test_eq(hdrl_catalogue_conf(infErr, inconf, ipix, 2.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 5 */ + ipix = 0; + icrowd = 5; + cpl_test_eq(hdrl_catalogue_conf(inf, NULL, ipix, 1.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 6 */ + ipix = 0; + icrowd = 5; + cpl_test_eq(hdrl_catalogue_conf(inf, inconf, ipix, 1.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 7 */ + ipix = 10; + icrowd = 10; + cpl_test_eq(hdrl_catalogue_conf(inf, NULL, ipix, 1.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Test 8 */ + ipix = 10; + icrowd = 10; + cpl_test_eq(hdrl_catalogue_conf(inf, inconf, ipix, 1.5, icrowd, 5., 1, 64, 6, 3., 1., INFINITY, res), CPL_ERROR_NONE); + cpl_test_nonnull( res->catalogue); + hdrl_casu_tfits_delete(res->catalogue); + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + + /* Clean up */ + hdrl_casu_fits_delete(infErr); + hdrl_casu_fits_delete(inconf); + hdrl_casu_fits_delete(inf); + cpl_free(res); +} + +void advanced_test(void) +{ + cpl_size x[] = {398,399,400,397,398,399,400,401,402,403,396,397,398,399,400, + 401,402,403,404,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,395,396,397,398,399,400,401,402, + 403,404,405,406,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,396,397,398,399,400,401,402,403, + 404,397,398,399,400,401,402,403,398,399,400,401}; + + cpl_size y[] = {394,394,394,395,395,395,395,395,395,395,396,396,396,396,396, + 396,396,396,396,397,397,397,397,397,397,397,397,397,397,397, + 398,398,398,398,398,398,398,398,398,398,398,399,399,399,399, + 399,399,399,399,399,399,399,400,400,400,400,400,400,400,400, + 400,400,400,400,401,401,401,401,401,401,401,401,401,401,401, + 402,402,402,402,402,402,402,402,402,402,402,403,403,403,403, + 403,403,403,403,403,403,403,404,404,404,404,404,404,404,404, + 404,405,405,405,405,405,405,405,406,406,406,406}; + + double z[] = {8.87152,12.515,7.69699,10.8527,22.2509,21.7368,13.0388, + 12.1853,17.1976,7.43948,15.2245,29.1964,37.9117,57.9371, + 71.5542,57.1288,34.7726,15.5934,11.5374,15.995,21.3606, + 60.4006,103.46,147.55,168.274,147.476,98.9157,51.7186,20.188, + 3.04248,5.77832,49.3103,98.2057,187.557,268.353,310.638, + 274.295,183.969,94.6933,47.9889,20.245,26.3758,59.1781, + 152.389,275.916,395.107,450.251,397.53,272.322,147.053,54.767, + 11.8971,13.3888,73.3689,165.899,298.455,449.707,493.25,441.585, + 299.31,157.474,70.1224,15.5313,8.76074,20.7188,54.5798,141.249, + 264.87,382.736,435.452,393.871,268.175,138.485,65.9307,28.7812, + 19.379,36.6449,93.5458,186.823,270.95,305.093,260.879,183.683, + 100.676,32.6281,16.6497,5.94965,17.8105,57.256,106.32,145.264, + 164.271,137.093,88.9384,60.7841,31.8582,10.0435,4.69162, + 15.2187,32.5385,61.0381,74.5399,67.3727,43.3964,25.0956, + 16.7595,-0.37323,21.3832,19.2497,18.5883,9.37448,19.6048, + 11.5006,13.0159,14.5852,13.66,-1.04889}; + + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = SIZE_IMAGE; + ap.csiz = SIZE_IMAGE; + ap.thresh = 11.0936; + ap.inframe = cpl_image_new(SIZE_IMAGE, SIZE_IMAGE, CPL_TYPE_DOUBLE); + ap.conframe = cpl_image_new(SIZE_IMAGE, SIZE_IMAGE, CPL_TYPE_DOUBLE); + + + /* Initialize */ + hdrl_apinit(&ap); + + ap.npl_pix = NT; + ap.plarray = cpl_realloc(ap.plarray, NT * sizeof(*ap.plarray)); + for (cpl_size i = 0; i < NT; i++) { + ap.plarray[i].x = x[i]; + ap.plarray[i].y = y[i]; + ap.plarray[i].z = z[i]; + ap.plarray[i].zsm = z[i]; + } + + ap.xintmin = 0.; + ap.areal_offset = 3.47165; + ap.thresh = 11.0936; + ap.fconst = 1.4427; + + /* Run the test */ + cpl_size iareal[NAREAL]; + hdrl_areals(&ap, iareal); + + ap.indata = cpl_image_get_data_double(ap.inframe); + ap.confdata = cpl_image_get_data_double(ap.conframe); + ap.mflag = cpl_calloc(2048 * 2048, sizeof(*ap.mflag)); + + /* Create a source */ + double tmax = 1000.; + cpl_image_fill_gaussian(ap.inframe, CENTER_IMAGE, CENTER_IMAGE, tmax, 10., 10.); + cpl_image_fill_gaussian(ap.conframe, CENTER_IMAGE, CENTER_IMAGE, tmax, 100., 100.); + + /* Do a basic moments analysis and work out the areal profiles*/ + double momresults[8]; + hdrl_moments(&ap, momresults); + + double parmall[IMNUM][NPAR]; + for (cpl_size i = 0; i < IMNUM; i++) { + for (cpl_size j = 0; j < NPAR; j++) { + parmall[i][j] = 0.; + } + } + + + /*** TESTS ***/ + cpl_size nbit; + cpl_error_code e; + + /* NOTE: Only if (iareal[0] >= ap->mulpix && ap->icrowd) */ + + /* Test 1 */ + nbit = 1; + ap.ipnop = 1; + e = hdrl_overlp( &ap, parmall, &nbit, + momresults[1], momresults[2], momresults[3], + iareal[0], momresults[7]); + cpl_test_eq(e, CPL_ERROR_NONE); + + + /* Test 2 */ + nbit = 1; + ap.ipnop = 1024; + e = hdrl_overlp( &ap, parmall, &nbit, + CENTER_IMAGE, CENTER_IMAGE, momresults[3], + SIZE_IMAGE * SIZE_IMAGE, tmax); + cpl_test_eq(e, CPL_ERROR_NONE); + + + nbit = 2; + ap.ipnop = 2; + ap.areal_offset = 1.5; + ap.thresh = 15.; + ap.fconst = 0.5; + hdrl_areals(&ap, iareal); + for (cpl_size i = 0; i < IMNUM; i++) { + for (cpl_size j = 0; j < NPAR; j++) { + parmall[i][j] = tmax; + } + } + + /* Test 3 */ + e = hdrl_overlp( &ap, parmall, &nbit, + CENTER_IMAGE, CENTER_IMAGE, momresults[3], + SIZE_IMAGE * SIZE_IMAGE, tmax); + cpl_test_eq(e, CPL_ERROR_NONE); + + /* Test 4 */ + e = hdrl_overlp_2orMore( &ap, parmall, &nbit, + CENTER_IMAGE, CENTER_IMAGE, momresults[3], + SIZE_IMAGE * SIZE_IMAGE, 1, 1, 1); + cpl_test_eq(e, CPL_ERROR_NONE); + + + /* Clean up */ + hdrl_apclose(&ap); + cpl_free(ap.mflag); + cpl_image_delete(ap.inframe); + cpl_image_delete(ap.conframe); +} + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + standard_test(); + advanced_test(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_phopt-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_phopt-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_phopt-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_phopt-test.c 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,103 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_phopt.h" + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + /* Initialize */ + double apertures[] = {2.5, 3.53553, 5.0, 7.07107, 10, 14, 20, 25, 30, 35, 40, 50, 60}; + + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.thresh = 11.0936; + ap.inframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE); + ap.conframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE); + + + /* Initialize */ + hdrl_apinit(&ap); + + ap.indata = cpl_image_get_data_double(ap.inframe); + ap.confdata = cpl_image_get_data_double(ap.conframe); + ap.mflag = cpl_calloc(2048 * 2048, sizeof(*ap.mflag)); + + /* Create a background */ + cpl_image_fill_noise_uniform(ap.inframe, -10., 10.); + cpl_image_add_scalar( ap.inframe, 5000.); + cpl_image_fill_noise_uniform(ap.conframe, 99, 101); + + + double parm[IMNUM][NPAR]; + for (cpl_size i = 0; i < IMNUM; i++) { + for (cpl_size j = 0; j < NPAR; j++) { + parm[i][j] = i + j; + } + } + + /* Reserve memory for the fluxes */ + double cflux[NRADS * IMNUM]; + + /* InitialiZe the badpix accumulator */ + double badpix[IMNUM]; + double avconf[IMNUM]; + + cpl_size nrcore = 2; + + /*** TESTS ***/ + cpl_size nbit; + cpl_error_code e; + + /* Test 1 */ + nbit = 1; + for (cpl_size i = 0; i < nbit; i++) { + badpix[i] = 0.; + avconf[i] = 0.; + } + e = hdrl_phopt(&ap, parm, nbit, NRADS, apertures, cflux, badpix, nrcore, avconf); + cpl_test_eq(e, CPL_ERROR_NONE); + + /* Test 2 */ + nbit = 2; + for (cpl_size i = 0; i < nbit; i++) { + badpix[i] = 0.; + avconf[i] = 0.; + } + e = hdrl_phopt(&ap, parm, nbit, NRADS, apertures, cflux, badpix, nrcore, avconf); + cpl_test_eq(e, CPL_ERROR_NONE); + + + /* Clean up */ + hdrl_apclose(&ap); + cpl_free(ap.mflag); + cpl_image_delete(ap.inframe); + cpl_image_delete(ap.conframe); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_polynm-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_polynm-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_polynm-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_polynm-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,47 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_polynm.h" + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + + /* Initialize */ + double x[] = { 1. , 3. , 5. , -10.}; + double y[] = {-0.5, -27.5, -86.5, -424.}; + + double coefs[3] = {1., 2.5, -4.}; + double poly[3]; + + /* Do the test */ + hdrl_polynm(y, x, 4, poly, 3, 0); + + /* Check the results */ + cpl_test_rel(poly[0], coefs[0], 0.01); + cpl_test_rel(poly[1], coefs[1], 0.01); + cpl_test_rel(poly[2], coefs[2], 0.01); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_radii-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_radii-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_radii-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_radii-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,197 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_areals.h" +#include "../hdrl_cat_moments.h" +#include "../hdrl_cat_radii.h" + +#define NT 117 +#define SIZE_IMG 64 + + +static double radii[] = {2.5,3.53553,5.0,7.07107,10,14,20,25,30,35,40,50,60}; + +static double fluxes[] = {13670.3, 19834.4, 23923.2, 25124.0, 25332.3, 25488.9, + 25648.7, 25842.8, 25950.9, 25893.9, 25982,1, 25297.6, 24919.1}; + + +void flux_test(cpl_boolean execute_test) +{ + cpl_size x[] = {398,399,400,397,398,399,400,401,402,403,396,397,398,399,400, + 401,402,403,404,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,395,396,397,398,399,400,401,402, + 403,404,405,406,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,396,397,398,399,400,401,402,403, + 404,397,398,399,400,401,402,403,398,399,400,401}; + + cpl_size y[] = {394,394,394,395,395,395,395,395,395,395,396,396,396,396,396, + 396,396,396,396,397,397,397,397,397,397,397,397,397,397,397, + 398,398,398,398,398,398,398,398,398,398,398,399,399,399,399, + 399,399,399,399,399,399,399,400,400,400,400,400,400,400,400, + 400,400,400,400,401,401,401,401,401,401,401,401,401,401,401, + 402,402,402,402,402,402,402,402,402,402,402,403,403,403,403, + 403,403,403,403,403,403,403,404,404,404,404,404,404,404,404, + 404,405,405,405,405,405,405,405,406,406,406,406}; + + double z[] = {8.87152,12.515,7.69699,10.8527,22.2509,21.7368,13.0388, + 12.1853,17.1976,7.43948,15.2245,29.1964,37.9117,57.9371, + 71.5542,57.1288,34.7726,15.5934,11.5374,15.995,21.3606, + 60.4006,103.46,147.55,168.274,147.476,98.9157,51.7186,20.188, + 3.04248,5.77832,49.3103,98.2057,187.557,268.353,310.638, + 274.295,183.969,94.6933,47.9889,20.245,26.3758,59.1781, + 152.389,275.916,395.107,450.251,397.53,272.322,147.053,54.767, + 11.8971,13.3888,73.3689,165.899,298.455,449.707,493.25,441.585, + 299.31,157.474,70.1224,15.5313,8.76074,20.7188,54.5798,141.249, + 264.87,382.736,435.452,393.871,268.175,138.485,65.9307,28.7812, + 19.379,36.6449,93.5458,186.823,270.95,305.093,260.879,183.683, + 100.676,32.6281,16.6497,5.94965,17.8105,57.256,106.32,145.264, + 164.271,137.093,88.9384,60.7841,31.8582,10.0435,4.69162, + 15.2187,32.5385,61.0381,74.5399,67.3727,43.3964,25.0956, + 16.7595,-0.37323,21.3832,19.2497,18.5883,9.37448,19.6048, + 11.5006,13.0159,14.5852,13.66,-1.04889}; + + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = SIZE_IMG; + ap.csiz = SIZE_IMG; + ap.thresh = 11.0936; + ap.inframe = cpl_image_new(SIZE_IMG, SIZE_IMG, CPL_TYPE_DOUBLE); + ap.conframe = cpl_image_new(SIZE_IMG, SIZE_IMG, CPL_TYPE_DOUBLE); + + /* Initialize */ + hdrl_apinit(&ap); + + ap.npl_pix = NT; + ap.plarray = cpl_realloc(ap.plarray, NT * sizeof(plstruct)); + for (cpl_size i = 0; i < NT; i++) { + ap.plarray[i].x = x[i]; + ap.plarray[i].y = y[i]; + ap.plarray[i].z = z[i]; + ap.plarray[i].zsm = z[i]; + } + + ap.xintmin = 0.; + ap.areal_offset = 3.47165; + ap.thresh = 11.0936; + ap.fconst = 1.4427; + + /* Run the test */ + cpl_size iareal[NAREAL]; + hdrl_areals(&ap, iareal); + + ap.indata = cpl_image_get_data_double(ap.inframe); + ap.confdata = cpl_image_get_data_double(ap.conframe); + ap.mflag = cpl_calloc(SIZE_IMG * SIZE_IMG, sizeof(*ap.mflag)); + + /* Create a background */ + cpl_image_fill_noise_uniform(ap.inframe, -10., 10.); + cpl_image_add_scalar( ap.inframe, 5000.); + cpl_image_fill_noise_uniform(ap.conframe, 99, 101); + + /* Do a basic moments analysis and work out the areal profiles*/ + double momresults[8]; + hdrl_moments(&ap, momresults); + + /* Try and deblend the images if it is requested and justified */ + double parmall[IMNUM][NPAR]; + cpl_size nbit = 10; + for (cpl_size i = 0; i < IMNUM; i++) { + for (cpl_size j = 0; j < NPAR; j++) { + parmall[i][j] = 0.; + } + } + + /* Get Kron radius for all images and get the flux */ + double areal; + double kron_rad[IMNUM]; + for (cpl_size k = 0; k < nbit; k++) { + areal = parmall[k][8]; + kron_rad[k] = hdrl_kronrad(areal, radii, fluxes, NRADS); + } + if (execute_test) { + double kron_flux[IMNUM]; + hdrl_flux(&ap, parmall, nbit, kron_rad, kron_flux, NRADS, radii, fluxes); + } + + /* Get Petrosian radius for all images and get the flux */ + double petr_rad[IMNUM]; + for (cpl_size k = 0; k < nbit; k++) { + areal = parmall[k][8]; + petr_rad[k] = hdrl_petrad(areal, radii, fluxes, NRADS); + } + if (execute_test) { + double petr_flux[IMNUM]; + hdrl_flux(&ap, parmall, nbit, petr_rad, petr_flux, NRADS, radii, fluxes); + } + + /* Clean up */ + hdrl_apclose(&ap); + cpl_free(ap.mflag); + cpl_image_delete(ap.inframe); + cpl_image_delete(ap.conframe); +} + +int main(void) { + + /* Initialize */ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + double halfrad = 2.35; + double exprad = 6.18; + double kronrad = 6.18; + double petrrad = 12.45; + double peak = 1007.07; + double areal = 120.; + + double halflight; + double thresh; + double rad; + + + /* Test halflight */ + halflight = fluxes[4] / 2.; + rad = hdrl_halflight(radii, fluxes, halflight, peak, NRADS); + cpl_test_rel(rad, halfrad, 0.01); + + /* Test exprad */ + thresh = 4.; + rad = hdrl_exprad(thresh, peak, areal, radii, NRADS); + cpl_test_rel(rad, exprad, 0.01); + + /* Test Kron */ + rad = hdrl_kronrad(areal, radii, fluxes, NRADS); + cpl_test_rel(rad, kronrad, 0.01); + + /* Test Petrosian */ + rad = hdrl_petrad(areal, radii, fluxes, NRADS); + cpl_test_rel(rad, petrrad, 0.01); + + /* Flux_test. TODO: Fail in Debian 6.0 [debug - i686] and Debian 7.0 [debug x86_64] + * Maybe for optiomization in the debug compiler mode for this machine. + * Activate the test when this will be solve */ + flux_test(CPL_FALSE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_seeing-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_seeing-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_seeing-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_seeing-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,76 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_seeing.h" + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + + /* Initialize */ + + double ell[] = {0.009, 0.050, 0.025, 0.033, 0.010, 0.012, 0.014, 0.005, 0.011, 0.011}; + + double pk[] = {1007.065, 101.293, 204.195, 493.250, 559.111, 609.799, 642.603, 698.117, 740.227, 797.222}; + + double areal[][10] = { {120., 53., 73., 104., 97., 109., 104., 107., 110., 110.}, + {100., 39., 60., 75., 80., 81., 86., 90., 94., 95.}, + { 75., 21., 42., 63., 66., 64., 68., 69., 69., 70.}, + { 63., 2., 21., 45., 45., 45., 45., 47., 56., 56.}, + { 45., 0., 4., 25., 29., 29., 37., 37., 37., 37.}, + { 25., 0., 0., 9., 9., 13., 14., 21., 21., 21.}, + { 9., 0., 0., 0., 0., 0., 0., 1., 1. }, + { 0., 0., 0., 0., 0., 0., 0., 0. } }; + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.thresh = 11.0936; + + /* Create areals */ + double **areals = cpl_malloc(8 * sizeof(double *)); + for (cpl_size i = 0; i < 8; i++) { + areals[i] = cpl_malloc(10 * sizeof(double)); + + for (cpl_size j = 0; j < 10; j++) { + areals[i][j] = areal[i][j]; + } + } + + /* Run the test */ + double *work = cpl_malloc(10 * sizeof(double)); + double fwhm; + hdrl_seeing(&ap, 10, ell, pk, areals, work, &fwhm); + cpl_test_rel(fwhm, 4.50384, 0.01); + cpl_free(work); + + /* Clean up */ + for (cpl_size i = 0; i < 8; i++) { + cpl_free(areals[i]); + } + cpl_free(areals); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_sim_montecarlo-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_sim_montecarlo-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_sim_montecarlo-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_sim_montecarlo-test.c 2017-11-20 12:02:20.000000000 +0000 @@ -0,0 +1,169 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_casu.h" + +#include "hdrl_random.h" + + +#define COMP_TOL_REL 1. / 3. +#define COMP_TOL_ABS 1e-2 +#define IMG_XSIZE 120 +#define IMG_YSIZE 180 + + +void test_basic(void) +{ + /* Generate a field with some stars and a confidence map */ + cpl_image *bkg = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *im = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + cpl_image *cnf = cpl_image_new(IMG_XSIZE, IMG_YSIZE, CPL_TYPE_DOUBLE); + + /* Generate confidence uniform confidence map */ + cpl_image_add_scalar(cnf, 100.); + + /* Generate sky and a gaussian source without errors */ + double sigma = 2.; + double norm2 = 2. * CPL_MATH_PI * sigma * sigma; + + double sky = 500.; + cpl_image_add_scalar(bkg, sky); + + double xpos = 80.; + double ypos = 100.; + double norm = 3000.; + cpl_image_fill_gaussian(im, xpos, ypos, norm * norm2, sigma, sigma); + cpl_image_add(bkg, im); + + hdrl_casu_fits *inf = hdrl_casu_fits_wrap( im); + hdrl_casu_fits *inconf = hdrl_casu_fits_wrap(cnf); + + /* Give it a WCS */ + cpl_propertylist *pl = hdrl_casu_fits_get_ehu(inf); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN" ); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_update_double(pl, "CRVAL1", 30. ); + cpl_propertylist_update_double(pl, "CRVAL2", 12. ); + cpl_propertylist_update_double(pl, "CRPIX1", 512. ); + cpl_propertylist_update_double(pl, "CRPIX2", 512. ); + cpl_propertylist_update_double(pl, "CD1_1", -1. / 3600.); + cpl_propertylist_update_double(pl, "CD1_2", 0. ); + cpl_propertylist_update_double(pl, "CD2_1", 0. ); + cpl_propertylist_update_double(pl, "CD2_2", 1. / 3600.); + cpl_propertylist_update_int( pl, "NAXIS1", IMG_XSIZE ); + cpl_propertylist_update_int( pl, "NAXIS2", IMG_YSIZE ); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(pl); + + /* Perform the montecarlo simulation */ + hdrl_casu_result *res = cpl_calloc(1, sizeof(hdrl_casu_result)); + cpl_table *tabfinal = NULL; + for (cpl_size iterate = 0; iterate < 100; iterate++) { + + /* Add realistic poisonnian noise */ + hdrl_random_state * rng = hdrl_random_state_new(1, NULL); + cpl_size size = cpl_image_get_size_x(bkg) * cpl_image_get_size_y(bkg); + double *pim = cpl_image_get_data_double(im); + double *pbkg= cpl_image_get_data_double(bkg); + + for (cpl_size i = 0; i < size; i++) { + pim[i] = hdrl_random_poisson(rng, pbkg[i]); + } + hdrl_random_state_delete(rng); + + /* Run casu catalogue */ + hdrl_casu_catalogue(inf, inconf, wcs, 5, 2.5, 0, 3., 1, 32, + HDRL_CATALOGUE_ALL, 3.0, 1.0, HDRL_SATURATION_INIT, res); + + cpl_table *tab = hdrl_casu_tfits_get_table(res->catalogue); + + if (iterate == 0) { + tabfinal = cpl_table_duplicate(tab); + } else { + cpl_table_insert(tabfinal, tab, iterate); + } + + cpl_image_delete( res->segmentation_map); + cpl_image_delete( res->background); + hdrl_casu_tfits_delete(res->catalogue); + } + + /* Do the checks */ + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "X_coordinate_err"), + cpl_table_get_column_stdev(tabfinal, "X_coordinate" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Y_coordinate_err"), + cpl_table_get_column_stdev(tabfinal, "Y_coordinate" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Peak_height_err" ), + cpl_table_get_column_stdev(tabfinal, "Peak_height" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_1_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_1" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_2_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_2" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_3_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_3" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_4_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_4" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_5_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_5" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_6_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_6" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_7_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_7" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_8_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_8" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_9_err" ), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_9" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_10_err"), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_10" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_11_err"), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_11" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_12_err"), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_12" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Aper_flux_13_err"), + cpl_table_get_column_stdev(tabfinal, "Aper_flux_13" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Petr_flux_err" ), + cpl_table_get_column_stdev(tabfinal, "Petr_flux" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Kron_flux_err" ), + cpl_table_get_column_stdev(tabfinal, "Kron_flux" ), COMP_TOL_REL); + cpl_test_rel(cpl_table_get_column_mean( tabfinal, "Half_flux_err" ), + cpl_table_get_column_stdev(tabfinal, "Half_flux" ), COMP_TOL_REL); + + /* Clean up */ + hdrl_casu_fits_delete(inf); + hdrl_casu_fits_delete(inconf); + cpl_wcs_delete(wcs); + cpl_table_delete(tabfinal); + cpl_image_delete(bkg); + cpl_free(res); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Unit tests of hdrl_simulerror_montecarlo + */ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_basic(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_terminate-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_terminate-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_terminate-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_terminate-test.c 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,132 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_apio.h" +#include "../hdrl_cat_areals.h" +#include "../hdrl_cat_moments.h" +#include "../hdrl_cat_terminate.h" + + +#define NT 117 + + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + cpl_size x[] = {398,399,400,397,398,399,400,401,402,403,396,397,398,399,400, + 401,402,403,404,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,395,396,397,398,399,400,401,402, + 403,404,405,406,395,396,397,398,399,400,401,402,403,404,405, + 395,396,397,398,399,400,401,402,403,404,405,395,396,397,398, + 399,400,401,402,403,404,405,396,397,398,399,400,401,402,403, + 404,397,398,399,400,401,402,403,398,399,400,401}; + + cpl_size y[] = {394,394,394,395,395,395,395,395,395,395,396,396,396,396,396, + 396,396,396,396,397,397,397,397,397,397,397,397,397,397,397, + 398,398,398,398,398,398,398,398,398,398,398,399,399,399,399, + 399,399,399,399,399,399,399,400,400,400,400,400,400,400,400, + 400,400,400,400,401,401,401,401,401,401,401,401,401,401,401, + 402,402,402,402,402,402,402,402,402,402,402,403,403,403,403, + 403,403,403,403,403,403,403,404,404,404,404,404,404,404,404, + 404,405,405,405,405,405,405,405,406,406,406,406}; + + double z[] = {8.87152,12.515,7.69699,10.8527,22.2509,21.7368,13.0388, + 12.1853,17.1976,7.43948,15.2245,29.1964,37.9117,57.9371, + 71.5542,57.1288,34.7726,15.5934,11.5374,15.995,21.3606, + 60.4006,103.46,147.55,168.274,147.476,98.9157,51.7186,20.188, + 3.04248,5.77832,49.3103,98.2057,187.557,268.353,310.638, + 274.295,183.969,94.6933,47.9889,20.245,26.3758,59.1781, + 152.389,275.916,395.107,450.251,397.53,272.322,147.053,54.767, + 11.8971,13.3888,73.3689,165.899,298.455,449.707,493.25,441.585, + 299.31,157.474,70.1224,15.5313,8.76074,20.7188,54.5798,141.249, + 264.87,382.736,435.452,393.871,268.175,138.485,65.9307,28.7812, + 19.379,36.6449,93.5458,186.823,270.95,305.093,260.879,183.683, + 100.676,32.6281,16.6497,5.94965,17.8105,57.256,106.32,145.264, + 164.271,137.093,88.9384,60.7841,31.8582,10.0435,4.69162, + 15.2187,32.5385,61.0381,74.5399,67.3727,43.3964,25.0956, + 16.7595,-0.37323,21.3832,19.2497,18.5883,9.37448,19.6048, + 11.5006,13.0159,14.5852,13.66,-1.04889}; + + /* Set up apm structure */ + ap_t ap; + ap.lsiz = 2048; + ap.csiz = 2048; + ap.thresh = 11.0936; + ap.inframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE); + ap.conframe = cpl_image_new(2048, 2048, CPL_TYPE_DOUBLE); + + /* Initialize */ + hdrl_apinit(&ap); + ap.maxip = 100; + ap.ipnop = 2; + ap.areal_offset = 1.5; + ap.multiply = 1; + + ap.npl_pix = NT; + ap.plarray = cpl_realloc(ap.plarray, NT * sizeof(*ap.plarray)); + for (cpl_size i = 0; i < NT; i++) { + ap.plarray[i].x = x[i]; + ap.plarray[i].y = y[i]; + ap.plarray[i].z = z[i]; + ap.plarray[i].zsm = z[i]; + } + + ap.xintmin = 0.; + ap.areal_offset = 3.56; + ap.thresh = 15.; + ap.fconst = 1.4; + + /* Run the test */ + cpl_size iareal[NAREAL]; + hdrl_areals(&ap, iareal); + + ap.indata = cpl_image_get_data_double(ap.inframe); + ap.confdata = cpl_image_get_data_double(ap.conframe); + ap.mflag = cpl_calloc(2048 * 2048, sizeof(*ap.mflag)); + + /* Create a source */ + double tmax = 1000.; + cpl_image_fill_gaussian(ap.inframe, 2048, 2048, tmax, 10., 10.); + cpl_image_fill_gaussian(ap.conframe, 2048, 2048, tmax, 100., 100.); + + /* Do a basic moments analysis and work out the areal profiles*/ + double momresults[8]; + hdrl_moments(&ap, momresults); + + /* Test 1 */ + ap.parent[1].pnop = 0; + ap.parent[1].first = 0; + ap.parent[1].last = 0; + ap.parent[1].growing = 0; + ap.parent[1].touch = 0; + ap.parent[1].pnbp = 0; + hdrl_apfu(&ap); + + /* Clean up */ + hdrl_apclose(&ap); + cpl_free(ap.mflag); + cpl_image_delete(ap.inframe); + cpl_image_delete(ap.conframe); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_utils_sort-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_utils_sort-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/hdrl_cat_utils_sort-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/hdrl_cat_utils_sort-test.c 2017-11-27 14:27:26.000000000 +0000 @@ -0,0 +1,438 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "../hdrl_cat_utils_sort.h" + +#include "hdrl_random.h" +#include "hdrl_types.h" + + +/* Number of elements of arrays in the random test */ +#define N 10000 + +/* The different methods to fill with numbers the random arrays */ +#define RANDOM_INIT 0 +#define RANDOM_UNIFORM_DOBULE 1 +#define RANDOM_NORMAL 2 +#define RANDOM_POISSON 3 +#define RANDOM_END 4 + + +/* Comparing function with ascending sort direction */ +int comparation_asc(const void * a, const void * b) +{ + const double a_d = *(const double *)a; + const double b_d = *(const double *)b; + + return a_d < b_d ? -1 : (a_d > b_d ? 1 : 0); +} + +/* Compraring Function with descending sort direction */ +int comparation_des(const void * a, const void * b) +{ + const double a_d = *(const double *)a; + const double b_d = *(const double *)b; + + return a_d > b_d ? -1 : (a_d < b_d ? 1 : 0); +} + +void test_sort(double *a, double *b, cpl_vector *c_vec, cpl_size random_type, cpl_sort_direction dir) { + + /* Initialize the seed for to have repeteability with the results + * and to be sure of test the same numbers */ + double rd; + hdrl_random_state *state = hdrl_random_state_new(1, NULL); + + /* Depending of the ramdom_type fill the arrays with different kind of random numbers */ + for (cpl_size i = 0; i < N; i++) { + + switch(random_type) { + case RANDOM_UNIFORM_DOBULE : rd = hdrl_random_uniform_double(state, 10., 20.); break; + case RANDOM_NORMAL : rd = hdrl_random_normal(state, 3.5, 1.5); break; + case RANDOM_POISSON : rd = hdrl_random_poisson(state, 100.); break; + default : exit(1); + } + + a[i] = rd; + b[i] = rd; + cpl_vector_set(c_vec, i, rd); + } + hdrl_random_state_delete(state); + + /* Call the functions depending of the ascending/descending sort direction */ + if(dir == CPL_SORT_ASCENDING) { + qsort(a, N, sizeof(*a), comparation_asc); + } else { + qsort(a, N, sizeof(*a), comparation_des); + } + sort_array(b, N, sizeof(*b), HDRL_SORT_DOUBLE, dir); + cpl_vector_sort(c_vec, dir); + + /* Check the results */ + for (cpl_size i = 0; i < N; i++) { + cpl_test_eq(a[i], b[i]); + cpl_test_eq(a[i], cpl_vector_get(c_vec, i)); + cpl_test_eq(b[i], cpl_vector_get(c_vec, i)); + } +} + +void test_cmp_sort_func(cpl_sort_direction dir) +{ + double *a = cpl_malloc(N * sizeof(double)); + double *b = cpl_malloc(N * sizeof(double)); + double *c = cpl_malloc(N * sizeof(double)); + cpl_vector *c_vec = cpl_vector_wrap(N, c); + + /* Sort vector with diferent fill random numbers */ + for(cpl_size i = RANDOM_INIT + 1; i < RANDOM_END; i++) { + test_sort(a, b, c_vec, i, dir); + } + + cpl_vector_unwrap(c_vec); + cpl_free(a); + cpl_free(b); + cpl_free(c); +} + +void test_sort_arrays_random(void) +{ + double *a_asc = cpl_malloc(N * sizeof(double)); + double *a_des = cpl_malloc(N * sizeof(double)); + double *a1 = cpl_malloc(N * sizeof(double)); + double *a2 = cpl_malloc(N * sizeof(double)); + double *a3 = cpl_malloc(N * sizeof(double)); + double *a4 = cpl_malloc(N * sizeof(double)); + double *a6 = cpl_malloc(N * sizeof(double)); + double *a7 = cpl_malloc(N * sizeof(double)); + double *a8 = cpl_malloc(N * sizeof(double)); + double *a9 = cpl_malloc(N * sizeof(double)); + + int *b_asc = cpl_malloc(N * sizeof(int)); + int *b_des = cpl_malloc(N * sizeof(int)); + int *b1 = cpl_malloc(N * sizeof(int)); + int *b6 = cpl_malloc(N * sizeof(int)); + + double *c_asc = cpl_malloc(N * sizeof(double)); + double *c_des = cpl_malloc(N * sizeof(double)); + double *c2 = cpl_malloc(N * sizeof(double)); + double *c7 = cpl_malloc(N * sizeof(double)); + + cpl_size *d_asc = cpl_malloc(N * sizeof(cpl_size)); + cpl_size *d_des = cpl_malloc(N * sizeof(cpl_size)); + cpl_size *d3 = cpl_malloc(N * sizeof(cpl_size)); + cpl_size *d8 = cpl_malloc(N * sizeof(cpl_size)); + + hdrl_value *e_asc = cpl_malloc(N * sizeof(hdrl_value)); + hdrl_value *e_des = cpl_malloc(N * sizeof(hdrl_value)); + hdrl_value *e4 = cpl_malloc(N * sizeof(hdrl_value)); + hdrl_value *e9 = cpl_malloc(N * sizeof(hdrl_value)); + + + /* Fill arrays with random values */ + hdrl_random_state *state = hdrl_random_state_new(1, NULL); + for (cpl_size i = 0; i < N; i++) { + + a_asc[i] = hdrl_random_normal(state, 5.5, 0.5); + a1[i] = a_asc[i]; + a2[i] = a_asc[i]; + a3[i] = a_asc[i]; + a4[i] = a_asc[i]; + a_des[i] = a_asc[i]; + a6[i] = a_des[i]; + a7[i] = a_des[i]; + a8[i] = a_des[i]; + a9[i] = a_des[i]; + + b_asc[i] = hdrl_random_poisson(state, 100.); + b1[i] = b_asc[i]; + b_des[i] = b_asc[i]; + b6[i] = b_des[i]; + + c_asc[i] = hdrl_random_uniform_double(state, 10., 20.); + c2[i] = c_asc[i]; + c_des[i] = c_asc[i]; + c7[i] = c_des[i]; + + d_asc[i] = hdrl_random_poisson(state, 300.); + d3[i] = d_asc[i]; + d_des[i] = d_asc[i]; + d8[i] = d_des[i]; + + e_asc[i] = (hdrl_value){hdrl_random_normal(state, 3.5, 1.5), + hdrl_random_normal(state, 2.5, 1.0) }; + e4[i] = (hdrl_value){e_asc[i].data, e_asc[i].error}; + e_des[i] = (hdrl_value){e_asc[i].data, e_asc[i].error}; + e9[i] = (hdrl_value){e_des[i].data, e_des[i].error}; + } + hdrl_random_state_delete(state); + + /* Prepare arrays for ascending order */ + void * arrs_asc[ 4] = { b_asc, c_asc, d_asc, e_asc}; + hdrl_sort_type types_asc[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE}; + + /* Prepare arrays for descending order */ + void * arrs_des[ 4] = { b_des, c_des, d_des, e_des}; + hdrl_sort_type types_des[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE}; + + + /* Test 1: Random array INT - ASCENDING */ + sort_array_index( a1, N, b1, HDRL_SORT_INT, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 2: Random array DOUBLE - ASCENDING */ + sort_array_index( a2, N, c2, HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 3: Random array CPL_SIZE - ASCENDING */ + sort_array_index( a3, N, d3, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 4: Random array HDRL_VALUE - ASCENDING */ + sort_array_index( a4, N, e4, HDRL_SORT_HDRL_VALUE, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 5: Ramdom arrays --> order all with the same function - ASCENDING */ + sort_arrays_index(a_asc, N, arrs_asc, 4, types_asc, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + + + /* Test 6: Random array INT - DESCENDING */ + sort_array_index( a6, N, b6, HDRL_SORT_INT, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 7: Random array DOUBLE - DESCENDING */ + sort_array_index( a7, N, c7, HDRL_SORT_DOUBLE, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 8: Random array CPL_SIZE - DESCENDING */ + sort_array_index( a8, N, d8, HDRL_SORT_CPL_SIZE, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 9: Random array HDRL_VALUE - DESCENDING */ + sort_array_index( a9, N, e9, HDRL_SORT_HDRL_VALUE, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + + /* Test 10: Ramdom arrays --> order all with the same function - DESCENDING */ + sort_arrays_index(a_des, N, arrs_des, 4, types_des, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + + cpl_free(a_asc); + cpl_free(a_des); + cpl_free(a1); + cpl_free(a2); + cpl_free(a3); + cpl_free(a4); + cpl_free(a6); + cpl_free(a7); + cpl_free(a8); + cpl_free(a9); + + cpl_free(b_asc); + cpl_free(b_des); + cpl_free(b1); + cpl_free(b6); + + + cpl_free(c_asc); + cpl_free(c_des); + cpl_free(c2); + cpl_free(c7); + + cpl_free(d_asc); + cpl_free(d_des); + cpl_free(d3); + cpl_free(d8); + + cpl_free(e_asc); + cpl_free(e_des); + cpl_free(e4); + cpl_free(e9); +} + +void test_sort_arrays_fixed(void) +{ + /*** Testing the results fixed by hand ***/ + + double x_asc[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x_des[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x1[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x2[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x3[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x4[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x6[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x7[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x8[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x9[10] = {-0.5, 0.33, 2.66, -3.5, 5.1, 5.2, 5.3, 5.4, 5.5, 4.4}; + double x_corr_asc[10] = {-3.5, -0.5, 0.33, 2.66, 4.4, 5.1, 5.2, 5.3, 5.4, 5.5}; + double x_corr_des[10] = { 5.5, 5.4, 5.3, 5.2, 5.1, 4.4, 2.66, 0.33,-0.5,-3.5}; + + int i_asc[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int i_des[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int i_1[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int i_6[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int i_corr_asc[10] = { 3, 0, 1, 2, 9, 4, 5, 6, 7, 8}; + int i_corr_des[10] = { 8, 7, 6, 5, 4, 9, 2, 1, 0, 3}; + + double db_asc[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.}; + double db_des[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.}; + double db_2[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.}; + double db_7[10] = { 0.,-1.,-2.,-3.,-4., 5., 6., 7., 8., 9.}; + double db_corr_asc[10] = {-3., 0.,-1.,-2., 9.,-4., 5., 6., 7., 8.}; + double db_corr_des[10] = { 8., 7., 6., 5.,-4., 9.,-2.,-1., 0.,-3.}; + + cpl_size cp_asc[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9}; + cpl_size cp_des[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9}; + cpl_size cp_3[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9}; + cpl_size cp_8[10] = { 0,-1,-2,-3,-4,-5,-6,-7,-8,-9}; + cpl_size cp_corr_asc[10] = {-3, 0,-1,-2,-9,-4,-5,-6,-7,-8}; + cpl_size cp_corr_des[10] = {-8,-7,-6,-5,-4,-9,-2,-1, 0,-3}; + + hdrl_value hv_asc[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5}, + (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} }; + hdrl_value hv_des[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5}, + (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} }; + hdrl_value hv_4[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5}, + (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} }; + hdrl_value hv_9[10] = {(hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){ 1.1, 0.4}, (hdrl_value){1.2, 0.5}, + (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 8.0, 0.9}, (hdrl_value){9.0, 1.0} }; + hdrl_value hv_corr_asc[10] = {(hdrl_value){ 1.1, 0.4}, (hdrl_value){-3.5, 0.1}, (hdrl_value){-0.5, 0.2}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){9.0, 1.0}, + (hdrl_value){ 1.2, 0.5}, (hdrl_value){ 5.0, 0.6}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){8.0, 0.9} }; + hdrl_value hv_corr_des[10] = {(hdrl_value){ 8.0, 0.9}, (hdrl_value){ 7.0, 0.8}, (hdrl_value){ 6.0, 0.7}, (hdrl_value){ 5.0, 0.6}, (hdrl_value){1.2, 0.5}, + (hdrl_value){ 9.0, 1.0}, (hdrl_value){ 0.001, 0.3}, (hdrl_value){-0.5, 0.2}, (hdrl_value){-3.5, 0.1}, (hdrl_value){1.1, 0.4} }; + + /* Prepare arrays for ascending order */ + void * arrs_asc[ 4] = { i_asc, db_asc, cp_asc, hv_asc}; + hdrl_sort_type types_asc[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE}; + + /* Prepare arrays for descending order */ + void * arrs_des[ 4] = { i_des, db_des, cp_des, hv_des}; + hdrl_sort_type types_des[4] = { HDRL_SORT_INT, HDRL_SORT_DOUBLE, HDRL_SORT_CPL_SIZE, HDRL_SORT_HDRL_VALUE}; + + + /* Test 1: Fixed array INT - ASCCENDING */ + sort_array_index(x1, 10, i_1, HDRL_SORT_INT, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x1[ ind], x_corr_asc[ind]); + cpl_test_eq(i_1[ind], i_corr_asc[ind]); + } + + /* Test 2: Fixed array DOUBLE - ASCCENDING */ + sort_array_index(x2, 10, db_2, HDRL_SORT_DOUBLE, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x2[ ind], x_corr_asc[ ind]); + cpl_test_eq(db_2[ind], db_corr_asc[ind]); + } + + /* Test 3: Fixed array CPL_SIZE - ASCCENDING */ + sort_array_index(x3, 10, cp_3, HDRL_SORT_CPL_SIZE, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x3[ ind], x_corr_asc[ ind]); + cpl_test_eq(cp_3[ind], cp_corr_asc[ind]); + } + + /* Test 4: Fixed array HDRL_VALUE - ASCCENDING */ + sort_array_index(x4, 10, hv_4, HDRL_SORT_HDRL_VALUE, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x4[ ind], x_corr_asc[ ind]); + cpl_test_eq(hv_4[ind].data, hv_corr_asc[ind].data); + cpl_test_eq(hv_4[ind].error, hv_corr_asc[ind].error); + } + + /* Test 5: Fixed arrays --> order all with the same function - ASCCENDING */ + sort_arrays_index(x_asc, 10, arrs_asc, 4, types_asc, CPL_SORT_ASCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x_asc[ ind], x_corr_asc[ ind]); + cpl_test_eq(i_asc[ ind], i_corr_asc[ ind]); + cpl_test_eq(db_asc[ind], db_corr_asc[ind]); + cpl_test_eq(cp_asc[ind], cp_corr_asc[ind]); + cpl_test_eq(hv_asc[ind].data, hv_corr_asc[ind].data); + cpl_test_eq(hv_asc[ind].error, hv_corr_asc[ind].error); + } + + + /* Test 6: Fixed array INT - DESCENDING */ + sort_array_index(x6, 10, i_6, HDRL_SORT_INT, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x6[ ind], x_corr_des[ind]); + cpl_test_eq(i_6[ind], i_corr_des[ind]); + } + + /* Test 7: Fixed array DOUBLE - DESCENDING */ + sort_array_index(x7, 10, db_7, HDRL_SORT_DOUBLE, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x7[ ind], x_corr_des[ ind]); + cpl_test_eq(db_7[ind], db_corr_des[ind]); + } + + /* Test 8: Fixed array CPL_SIZE - DESCENDING */ + sort_array_index(x8, 10, cp_8, HDRL_SORT_CPL_SIZE, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x8[ ind], x_corr_des[ ind]); + cpl_test_eq(cp_8[ind], cp_corr_des[ind]); + } + + /* Test 9: Fixed array HDRL_VALUE - DESCENDING */ + sort_array_index(x9, 10, hv_9, HDRL_SORT_HDRL_VALUE, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x9[ ind], x_corr_des[ ind]); + cpl_test_eq(hv_9[ind].data, hv_corr_des[ind].data); + cpl_test_eq(hv_9[ind].error, hv_corr_des[ind].error); + } + + /* Test 10: Fixed arrays --> order all with the same function - DESCENDING */ + sort_arrays_index(x_des, 10, arrs_des, 4, types_des, CPL_SORT_DESCENDING); + cpl_test_error(CPL_ERROR_NONE); + for (cpl_size ind = 0; ind < 10; ind++) { + cpl_test_eq(x_des[ ind], x_corr_des[ ind]); + cpl_test_eq(i_des[ ind], i_corr_des[ ind]); + cpl_test_eq(db_des[ind], db_corr_des[ind]); + cpl_test_eq(cp_des[ind], cp_corr_des[ind]); + cpl_test_eq(hv_des[ind].data, hv_corr_des[ind].data); + cpl_test_eq(hv_des[ind].error, hv_corr_des[ind].error); + } +} + +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + + /* Test 3 diferent functions: qsort in C, hdrl_function and cpl_function + * in ascending and descending order */ + test_cmp_sort_func(CPL_SORT_ASCENDING); + test_cmp_sort_func(CPL_SORT_DESCENDING); + + /* Test sort arrays by index, the first is ordering and the nexts by index */ + test_sort_arrays_random(); + + /* Test sort arrays by index, equal to previously but checking the results */ + test_sort_arrays_fixed(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/Makefile.am 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/Makefile.am 2017-10-19 15:07:43.000000000 +0000 @@ -0,0 +1,105 @@ +## Process this file with automake to produce Makefile.in + +## This file is part of the ESO Common Pipeline Library +## Copyright (C) 2001-2008 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +AUTOMAKE_OPTIONS = 1.8 foreign + +DISTCLEANFILES = *~ + + +if MAINTAINER_MODE + +MAINTAINERCLEANFILES = $(srcdir)/Makefile.in + +endif + +AM_CPPFLAGS = $(all_includes) -DCX_LOG_DOMAIN=\"CasuLib\" -I$(top_srcdir) -DHDRL_USE_PRIVATE +AM_LDFLAGS = $(CPL_LDFLAGS) +LDADD = ../libcatalogue.la $(top_builddir)/libhdrl.la $(LIBCPLCORE) $(LIBCPLDRS) $(LIBCEXT) -lm + +check_PROGRAMS = hdrl_cat_conf-test \ + hdrl_cat_background-test \ + hdrl_cat_utils_sort-test \ + hdrl_cat_apio-test \ + hdrl_cat_classify-test \ + hdrl_cat_phopt-test \ + hdrl_cat_overlp-test \ + hdrl_cat_radii-test \ + hdrl_cat_filter-test \ + hdrl_cat_terminate-test \ + hdrl_cat_moments-test \ + hdrl_cat_areals-test \ + hdrl_cat_seeing-test \ + hdrl_cat_polynm-test \ + hdrl_cat_casu-test \ + hdrl_cat_casu_bkg_badpatch-test \ + hdrl_cat_casu_addmul-test \ + hdrl_cat_sim_montecarlo-test + +hdrl_cat_conf_test_SOURCES = hdrl_cat_conf-test.c +hdrl_cat_background_test_SOURCES = hdrl_cat_background-test.c +hdrl_cat_utils_sort_test_SOURCES = hdrl_cat_utils_sort-test.c +hdrl_cat_apio_test_SOURCES = hdrl_cat_apio-test.c +hdrl_cat_classify_test_SOURCES = hdrl_cat_classify-test.c +hdrl_cat_phopt_test_SOURCES = hdrl_cat_phopt-test.c +hdrl_cat_overlp_test_SOURCES = hdrl_cat_overlp-test.c +hdrl_cat_radii_test_SOURCES = hdrl_cat_radii-test.c +hdrl_cat_filter_test_SOURCES = hdrl_cat_filter-test.c +hdrl_cat_terminate_test_SOURCES = hdrl_cat_terminate-test.c +hdrl_cat_moments_test_SOURCES = hdrl_cat_moments-test.c +hdrl_cat_areals_test_SOURCES = hdrl_cat_areals-test.c +hdrl_cat_seeing_test_SOURCES = hdrl_cat_seeing-test.c +hdrl_cat_polynm_test_SOURCES = hdrl_cat_polynm-test.c +hdrl_cat_casu_test_SOURCES = hdrl_cat_casu-test.c +hdrl_cat_casu_bkg_badpatch_test_SOURCES = hdrl_cat_casu_bkg_badpatch-test.c +hdrl_cat_casu_addmul_test_SOURCES = hdrl_cat_casu_addmul-test.c +hdrl_cat_sim_montecarlo_test_SOURCES = hdrl_cat_sim_montecarlo-test.c + +TESTS = hdrl_cat_conf-test \ + hdrl_cat_background-test \ + hdrl_cat_utils_sort-test \ + hdrl_cat_apio-test \ + hdrl_cat_classify-test \ + hdrl_cat_phopt-test \ + hdrl_cat_overlp-test \ + hdrl_cat_radii-test \ + hdrl_cat_filter-test \ + hdrl_cat_terminate-test \ + hdrl_cat_moments-test \ + hdrl_cat_areals-test \ + hdrl_cat_seeing-test \ + hdrl_cat_polynm-test \ + hdrl_cat_casu-test \ + hdrl_cat_casu_bkg_badpatch-test \ + hdrl_cat_casu_addmul-test \ + hdrl_cat_sim_montecarlo-test + +# Be sure to reexport important environment variables. +TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \ + LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \ + OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \ + MALLOC_PERTURB_=31 MALLOC_CHECK_=2 \ + GOMP_SPINCOUNT=10000 + +XFAIL_TESTS = + +# We need to remove any files that the above tests created. +clean-local: + $(RM) *.fits *.log diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/catalogue/tests/Makefile.in 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/catalogue/tests/Makefile.in 2018-04-13 15:46:32.000000000 +0000 @@ -0,0 +1,1403 @@ +# Makefile.in generated by automake 1.15 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2014 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +check_PROGRAMS = hdrl_cat_conf-test$(EXEEXT) \ + hdrl_cat_background-test$(EXEEXT) \ + hdrl_cat_utils_sort-test$(EXEEXT) hdrl_cat_apio-test$(EXEEXT) \ + hdrl_cat_classify-test$(EXEEXT) hdrl_cat_phopt-test$(EXEEXT) \ + hdrl_cat_overlp-test$(EXEEXT) hdrl_cat_radii-test$(EXEEXT) \ + hdrl_cat_filter-test$(EXEEXT) hdrl_cat_terminate-test$(EXEEXT) \ + hdrl_cat_moments-test$(EXEEXT) hdrl_cat_areals-test$(EXEEXT) \ + hdrl_cat_seeing-test$(EXEEXT) hdrl_cat_polynm-test$(EXEEXT) \ + hdrl_cat_casu-test$(EXEEXT) \ + hdrl_cat_casu_bkg_badpatch-test$(EXEEXT) \ + hdrl_cat_casu_addmul-test$(EXEEXT) \ + hdrl_cat_sim_montecarlo-test$(EXEEXT) +TESTS = hdrl_cat_conf-test$(EXEEXT) hdrl_cat_background-test$(EXEEXT) \ + hdrl_cat_utils_sort-test$(EXEEXT) hdrl_cat_apio-test$(EXEEXT) \ + hdrl_cat_classify-test$(EXEEXT) hdrl_cat_phopt-test$(EXEEXT) \ + hdrl_cat_overlp-test$(EXEEXT) hdrl_cat_radii-test$(EXEEXT) \ + hdrl_cat_filter-test$(EXEEXT) hdrl_cat_terminate-test$(EXEEXT) \ + hdrl_cat_moments-test$(EXEEXT) hdrl_cat_areals-test$(EXEEXT) \ + hdrl_cat_seeing-test$(EXEEXT) hdrl_cat_polynm-test$(EXEEXT) \ + hdrl_cat_casu-test$(EXEEXT) \ + hdrl_cat_casu_bkg_badpatch-test$(EXEEXT) \ + hdrl_cat_casu_addmul-test$(EXEEXT) \ + hdrl_cat_sim_montecarlo-test$(EXEEXT) +XFAIL_TESTS = +subdir = catalogue/tests +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/m4macros/cpl-pipeline.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am_hdrl_cat_apio_test_OBJECTS = hdrl_cat_apio-test.$(OBJEXT) +hdrl_cat_apio_test_OBJECTS = $(am_hdrl_cat_apio_test_OBJECTS) +hdrl_cat_apio_test_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +hdrl_cat_apio_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +am_hdrl_cat_areals_test_OBJECTS = hdrl_cat_areals-test.$(OBJEXT) +hdrl_cat_areals_test_OBJECTS = $(am_hdrl_cat_areals_test_OBJECTS) +hdrl_cat_areals_test_LDADD = $(LDADD) +hdrl_cat_areals_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_background_test_OBJECTS = \ + hdrl_cat_background-test.$(OBJEXT) +hdrl_cat_background_test_OBJECTS = \ + $(am_hdrl_cat_background_test_OBJECTS) +hdrl_cat_background_test_LDADD = $(LDADD) +hdrl_cat_background_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_casu_test_OBJECTS = hdrl_cat_casu-test.$(OBJEXT) +hdrl_cat_casu_test_OBJECTS = $(am_hdrl_cat_casu_test_OBJECTS) +hdrl_cat_casu_test_LDADD = $(LDADD) +hdrl_cat_casu_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_casu_addmul_test_OBJECTS = \ + hdrl_cat_casu_addmul-test.$(OBJEXT) +hdrl_cat_casu_addmul_test_OBJECTS = \ + $(am_hdrl_cat_casu_addmul_test_OBJECTS) +hdrl_cat_casu_addmul_test_LDADD = $(LDADD) +hdrl_cat_casu_addmul_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_casu_bkg_badpatch_test_OBJECTS = \ + hdrl_cat_casu_bkg_badpatch-test.$(OBJEXT) +hdrl_cat_casu_bkg_badpatch_test_OBJECTS = \ + $(am_hdrl_cat_casu_bkg_badpatch_test_OBJECTS) +hdrl_cat_casu_bkg_badpatch_test_LDADD = $(LDADD) +hdrl_cat_casu_bkg_badpatch_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_classify_test_OBJECTS = hdrl_cat_classify-test.$(OBJEXT) +hdrl_cat_classify_test_OBJECTS = $(am_hdrl_cat_classify_test_OBJECTS) +hdrl_cat_classify_test_LDADD = $(LDADD) +hdrl_cat_classify_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_conf_test_OBJECTS = hdrl_cat_conf-test.$(OBJEXT) +hdrl_cat_conf_test_OBJECTS = $(am_hdrl_cat_conf_test_OBJECTS) +hdrl_cat_conf_test_LDADD = $(LDADD) +hdrl_cat_conf_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_filter_test_OBJECTS = hdrl_cat_filter-test.$(OBJEXT) +hdrl_cat_filter_test_OBJECTS = $(am_hdrl_cat_filter_test_OBJECTS) +hdrl_cat_filter_test_LDADD = $(LDADD) +hdrl_cat_filter_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_moments_test_OBJECTS = hdrl_cat_moments-test.$(OBJEXT) +hdrl_cat_moments_test_OBJECTS = $(am_hdrl_cat_moments_test_OBJECTS) +hdrl_cat_moments_test_LDADD = $(LDADD) +hdrl_cat_moments_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_overlp_test_OBJECTS = hdrl_cat_overlp-test.$(OBJEXT) +hdrl_cat_overlp_test_OBJECTS = $(am_hdrl_cat_overlp_test_OBJECTS) +hdrl_cat_overlp_test_LDADD = $(LDADD) +hdrl_cat_overlp_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_phopt_test_OBJECTS = hdrl_cat_phopt-test.$(OBJEXT) +hdrl_cat_phopt_test_OBJECTS = $(am_hdrl_cat_phopt_test_OBJECTS) +hdrl_cat_phopt_test_LDADD = $(LDADD) +hdrl_cat_phopt_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_polynm_test_OBJECTS = hdrl_cat_polynm-test.$(OBJEXT) +hdrl_cat_polynm_test_OBJECTS = $(am_hdrl_cat_polynm_test_OBJECTS) +hdrl_cat_polynm_test_LDADD = $(LDADD) +hdrl_cat_polynm_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_radii_test_OBJECTS = hdrl_cat_radii-test.$(OBJEXT) +hdrl_cat_radii_test_OBJECTS = $(am_hdrl_cat_radii_test_OBJECTS) +hdrl_cat_radii_test_LDADD = $(LDADD) +hdrl_cat_radii_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_seeing_test_OBJECTS = hdrl_cat_seeing-test.$(OBJEXT) +hdrl_cat_seeing_test_OBJECTS = $(am_hdrl_cat_seeing_test_OBJECTS) +hdrl_cat_seeing_test_LDADD = $(LDADD) +hdrl_cat_seeing_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_sim_montecarlo_test_OBJECTS = \ + hdrl_cat_sim_montecarlo-test.$(OBJEXT) +hdrl_cat_sim_montecarlo_test_OBJECTS = \ + $(am_hdrl_cat_sim_montecarlo_test_OBJECTS) +hdrl_cat_sim_montecarlo_test_LDADD = $(LDADD) +hdrl_cat_sim_montecarlo_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_terminate_test_OBJECTS = \ + hdrl_cat_terminate-test.$(OBJEXT) +hdrl_cat_terminate_test_OBJECTS = \ + $(am_hdrl_cat_terminate_test_OBJECTS) +hdrl_cat_terminate_test_LDADD = $(LDADD) +hdrl_cat_terminate_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_cat_utils_sort_test_OBJECTS = \ + hdrl_cat_utils_sort-test.$(OBJEXT) +hdrl_cat_utils_sort_test_OBJECTS = \ + $(am_hdrl_cat_utils_sort_test_OBJECTS) +hdrl_cat_utils_sort_test_LDADD = $(LDADD) +hdrl_cat_utils_sort_test_DEPENDENCIES = ../libcatalogue.la \ + $(top_builddir)/libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/admin/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(hdrl_cat_apio_test_SOURCES) \ + $(hdrl_cat_areals_test_SOURCES) \ + $(hdrl_cat_background_test_SOURCES) \ + $(hdrl_cat_casu_test_SOURCES) \ + $(hdrl_cat_casu_addmul_test_SOURCES) \ + $(hdrl_cat_casu_bkg_badpatch_test_SOURCES) \ + $(hdrl_cat_classify_test_SOURCES) \ + $(hdrl_cat_conf_test_SOURCES) $(hdrl_cat_filter_test_SOURCES) \ + $(hdrl_cat_moments_test_SOURCES) \ + $(hdrl_cat_overlp_test_SOURCES) $(hdrl_cat_phopt_test_SOURCES) \ + $(hdrl_cat_polynm_test_SOURCES) $(hdrl_cat_radii_test_SOURCES) \ + $(hdrl_cat_seeing_test_SOURCES) \ + $(hdrl_cat_sim_montecarlo_test_SOURCES) \ + $(hdrl_cat_terminate_test_SOURCES) \ + $(hdrl_cat_utils_sort_test_SOURCES) +DIST_SOURCES = $(hdrl_cat_apio_test_SOURCES) \ + $(hdrl_cat_areals_test_SOURCES) \ + $(hdrl_cat_background_test_SOURCES) \ + $(hdrl_cat_casu_test_SOURCES) \ + $(hdrl_cat_casu_addmul_test_SOURCES) \ + $(hdrl_cat_casu_bkg_badpatch_test_SOURCES) \ + $(hdrl_cat_classify_test_SOURCES) \ + $(hdrl_cat_conf_test_SOURCES) $(hdrl_cat_filter_test_SOURCES) \ + $(hdrl_cat_moments_test_SOURCES) \ + $(hdrl_cat_overlp_test_SOURCES) $(hdrl_cat_phopt_test_SOURCES) \ + $(hdrl_cat_polynm_test_SOURCES) $(hdrl_cat_radii_test_SOURCES) \ + $(hdrl_cat_seeing_test_SOURCES) \ + $(hdrl_cat_sim_montecarlo_test_SOURCES) \ + $(hdrl_cat_terminate_test_SOURCES) \ + $(hdrl_cat_utils_sort_test_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__tty_colors_dummy = \ + mgn= red= grn= lgn= blu= brg= std=; \ + am__color_tests=no +am__tty_colors = { \ + $(am__tty_colors_dummy); \ + if test "X$(AM_COLOR_TESTS)" = Xno; then \ + am__color_tests=no; \ + elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ + am__color_tests=yes; \ + elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ + am__color_tests=yes; \ + fi; \ + if test $$am__color_tests = yes; then \ + red=''; \ + grn=''; \ + lgn=''; \ + blu=''; \ + mgn=''; \ + brg=''; \ + std=''; \ + fi; \ +} +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__recheck_rx = ^[ ]*:recheck:[ ]* +am__global_test_result_rx = ^[ ]*:global-test-result:[ ]* +am__copy_in_global_log_rx = ^[ ]*:copy-in-global-log:[ ]* +# A command that, given a newline-separated list of test names on the +# standard input, print the name of the tests that are to be re-run +# upon "make recheck". +am__list_recheck_tests = $(AWK) '{ \ + recheck = 1; \ + while ((rc = (getline line < ($$0 ".trs"))) != 0) \ + { \ + if (rc < 0) \ + { \ + if ((getline line2 < ($$0 ".log")) < 0) \ + recheck = 0; \ + break; \ + } \ + else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \ + { \ + recheck = 0; \ + break; \ + } \ + else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \ + { \ + break; \ + } \ + }; \ + if (recheck) \ + print $$0; \ + close ($$0 ".trs"); \ + close ($$0 ".log"); \ +}' +# A command that, given a newline-separated list of test names on the +# standard input, create the global log from their .trs and .log files. +am__create_global_log = $(AWK) ' \ +function fatal(msg) \ +{ \ + print "fatal: making $@: " msg | "cat >&2"; \ + exit 1; \ +} \ +function rst_section(header) \ +{ \ + print header; \ + len = length(header); \ + for (i = 1; i <= len; i = i + 1) \ + printf "="; \ + printf "\n\n"; \ +} \ +{ \ + copy_in_global_log = 1; \ + global_test_result = "RUN"; \ + while ((rc = (getline line < ($$0 ".trs"))) != 0) \ + { \ + if (rc < 0) \ + fatal("failed to read from " $$0 ".trs"); \ + if (line ~ /$(am__global_test_result_rx)/) \ + { \ + sub("$(am__global_test_result_rx)", "", line); \ + sub("[ ]*$$", "", line); \ + global_test_result = line; \ + } \ + else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \ + copy_in_global_log = 0; \ + }; \ + if (copy_in_global_log) \ + { \ + rst_section(global_test_result ": " $$0); \ + while ((rc = (getline line < ($$0 ".log"))) != 0) \ + { \ + if (rc < 0) \ + fatal("failed to read from " $$0 ".log"); \ + print line; \ + }; \ + printf "\n"; \ + }; \ + close ($$0 ".trs"); \ + close ($$0 ".log"); \ +}' +# Restructured Text title. +am__rst_title = { sed 's/.*/ & /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; } +# Solaris 10 'make', and several other traditional 'make' implementations, +# pass "-e" to $(SHELL), and POSIX 2008 even requires this. Work around it +# by disabling -e (using the XSI extension "set +e") if it's set. +am__sh_e_setup = case $$- in *e*) set +e;; esac +# Default flags passed to test drivers. +am__common_driver_flags = \ + --color-tests "$$am__color_tests" \ + --enable-hard-errors "$$am__enable_hard_errors" \ + --expect-failure "$$am__expect_failure" +# To be inserted before the command running the test. Creates the +# directory for the log if needed. Stores in $dir the directory +# containing $f, in $tst the test, in $log the log. Executes the +# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and +# passes TESTS_ENVIRONMENT. Set up options for the wrapper that +# will run the test scripts (or their associated LOG_COMPILER, if +# thy have one). +am__check_pre = \ +$(am__sh_e_setup); \ +$(am__vpath_adj_setup) $(am__vpath_adj) \ +$(am__tty_colors); \ +srcdir=$(srcdir); export srcdir; \ +case "$@" in \ + */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;; \ + *) am__odir=.;; \ +esac; \ +test "x$$am__odir" = x"." || test -d "$$am__odir" \ + || $(MKDIR_P) "$$am__odir" || exit $$?; \ +if test -f "./$$f"; then dir=./; \ +elif test -f "$$f"; then dir=; \ +else dir="$(srcdir)/"; fi; \ +tst=$$dir$$f; log='$@'; \ +if test -n '$(DISABLE_HARD_ERRORS)'; then \ + am__enable_hard_errors=no; \ +else \ + am__enable_hard_errors=yes; \ +fi; \ +case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$f[\ \ ]* | *[\ \ ]$$dir$$f[\ \ ]*) \ + am__expect_failure=yes;; \ + *) \ + am__expect_failure=no;; \ +esac; \ +$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT) +# A shell command to get the names of the tests scripts with any registered +# extension removed (i.e., equivalently, the names of the test logs, with +# the '.log' extension removed). The result is saved in the shell variable +# '$bases'. This honors runtime overriding of TESTS and TEST_LOGS. Sadly, +# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)", +# since that might cause problem with VPATH rewrites for suffix-less tests. +# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'. +am__set_TESTS_bases = \ + bases='$(TEST_LOGS)'; \ + bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ + bases=`echo $$bases` +RECHECK_LOGS = $(TEST_LOGS) +AM_RECURSIVE_TARGETS = check recheck +TEST_SUITE_LOG = test-suite.log +TEST_EXTENSIONS = @EXEEXT@ .test +LOG_DRIVER = $(SHELL) $(top_srcdir)/admin/test-driver +LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS) +am__set_b = \ + case '$@' in \ + */*) \ + case '$*' in \ + */*) b='$*';; \ + *) b=`echo '$@' | sed 's/\.log$$//'`; \ + esac;; \ + *) \ + b='$*';; \ + esac +am__test_logs1 = $(TESTS:=.log) +am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) +TEST_LOGS = $(am__test_logs2:.test.log=.log) +TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/admin/test-driver +TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ + $(TEST_LOG_FLAGS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/admin/depcomp \ + $(top_srcdir)/admin/test-driver +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPL_INCLUDES = @CPL_INCLUDES@ +CPL_LDFLAGS = @CPL_LDFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DOXYGEN = @DOXYGEN@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_BINARY_AGE = @HDRL_BINARY_AGE@ +HDRL_BINARY_VERSION = @HDRL_BINARY_VERSION@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERFACE_AGE = @HDRL_INTERFACE_AGE@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_MAJOR_VERSION = @HDRL_MAJOR_VERSION@ +HDRL_MICRO_VERSION = @HDRL_MICRO_VERSION@ +HDRL_MINOR_VERSION = @HDRL_MINOR_VERSION@ +HDRL_VERSION = @HDRL_VERSION@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LATEX = @LATEX@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBCEXT = @LIBCEXT@ +LIBCPLCORE = @LIBCPLCORE@ +LIBCPLDFS = @LIBCPLDFS@ +LIBCPLDRS = @LIBCPLDRS@ +LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_AGE = @LT_AGE@ +LT_CURRENT = @LT_CURRENT@ +LT_REVISION = @LT_REVISION@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +all_includes = @all_includes@ +all_ldflags = @all_ldflags@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AUTOMAKE_OPTIONS = 1.8 foreign +DISTCLEANFILES = *~ +@MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = $(srcdir)/Makefile.in +AM_CPPFLAGS = $(all_includes) -DCX_LOG_DOMAIN=\"CasuLib\" -I$(top_srcdir) -DHDRL_USE_PRIVATE +AM_LDFLAGS = $(CPL_LDFLAGS) +LDADD = ../libcatalogue.la $(top_builddir)/libhdrl.la $(LIBCPLCORE) $(LIBCPLDRS) $(LIBCEXT) -lm +hdrl_cat_conf_test_SOURCES = hdrl_cat_conf-test.c +hdrl_cat_background_test_SOURCES = hdrl_cat_background-test.c +hdrl_cat_utils_sort_test_SOURCES = hdrl_cat_utils_sort-test.c +hdrl_cat_apio_test_SOURCES = hdrl_cat_apio-test.c +hdrl_cat_classify_test_SOURCES = hdrl_cat_classify-test.c +hdrl_cat_phopt_test_SOURCES = hdrl_cat_phopt-test.c +hdrl_cat_overlp_test_SOURCES = hdrl_cat_overlp-test.c +hdrl_cat_radii_test_SOURCES = hdrl_cat_radii-test.c +hdrl_cat_filter_test_SOURCES = hdrl_cat_filter-test.c +hdrl_cat_terminate_test_SOURCES = hdrl_cat_terminate-test.c +hdrl_cat_moments_test_SOURCES = hdrl_cat_moments-test.c +hdrl_cat_areals_test_SOURCES = hdrl_cat_areals-test.c +hdrl_cat_seeing_test_SOURCES = hdrl_cat_seeing-test.c +hdrl_cat_polynm_test_SOURCES = hdrl_cat_polynm-test.c +hdrl_cat_casu_test_SOURCES = hdrl_cat_casu-test.c +hdrl_cat_casu_bkg_badpatch_test_SOURCES = hdrl_cat_casu_bkg_badpatch-test.c +hdrl_cat_casu_addmul_test_SOURCES = hdrl_cat_casu_addmul-test.c +hdrl_cat_sim_montecarlo_test_SOURCES = hdrl_cat_sim_montecarlo-test.c + +# Be sure to reexport important environment variables. +TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \ + LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \ + OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \ + MALLOC_PERTURB_=31 MALLOC_CHECK_=2 \ + GOMP_SPINCOUNT=10000 + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign catalogue/tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign catalogue/tests/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +hdrl_cat_apio-test$(EXEEXT): $(hdrl_cat_apio_test_OBJECTS) $(hdrl_cat_apio_test_DEPENDENCIES) $(EXTRA_hdrl_cat_apio_test_DEPENDENCIES) + @rm -f hdrl_cat_apio-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_apio_test_OBJECTS) $(hdrl_cat_apio_test_LDADD) $(LIBS) + +hdrl_cat_areals-test$(EXEEXT): $(hdrl_cat_areals_test_OBJECTS) $(hdrl_cat_areals_test_DEPENDENCIES) $(EXTRA_hdrl_cat_areals_test_DEPENDENCIES) + @rm -f hdrl_cat_areals-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_areals_test_OBJECTS) $(hdrl_cat_areals_test_LDADD) $(LIBS) + +hdrl_cat_background-test$(EXEEXT): $(hdrl_cat_background_test_OBJECTS) $(hdrl_cat_background_test_DEPENDENCIES) $(EXTRA_hdrl_cat_background_test_DEPENDENCIES) + @rm -f hdrl_cat_background-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_background_test_OBJECTS) $(hdrl_cat_background_test_LDADD) $(LIBS) + +hdrl_cat_casu-test$(EXEEXT): $(hdrl_cat_casu_test_OBJECTS) $(hdrl_cat_casu_test_DEPENDENCIES) $(EXTRA_hdrl_cat_casu_test_DEPENDENCIES) + @rm -f hdrl_cat_casu-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_casu_test_OBJECTS) $(hdrl_cat_casu_test_LDADD) $(LIBS) + +hdrl_cat_casu_addmul-test$(EXEEXT): $(hdrl_cat_casu_addmul_test_OBJECTS) $(hdrl_cat_casu_addmul_test_DEPENDENCIES) $(EXTRA_hdrl_cat_casu_addmul_test_DEPENDENCIES) + @rm -f hdrl_cat_casu_addmul-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_casu_addmul_test_OBJECTS) $(hdrl_cat_casu_addmul_test_LDADD) $(LIBS) + +hdrl_cat_casu_bkg_badpatch-test$(EXEEXT): $(hdrl_cat_casu_bkg_badpatch_test_OBJECTS) $(hdrl_cat_casu_bkg_badpatch_test_DEPENDENCIES) $(EXTRA_hdrl_cat_casu_bkg_badpatch_test_DEPENDENCIES) + @rm -f hdrl_cat_casu_bkg_badpatch-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_casu_bkg_badpatch_test_OBJECTS) $(hdrl_cat_casu_bkg_badpatch_test_LDADD) $(LIBS) + +hdrl_cat_classify-test$(EXEEXT): $(hdrl_cat_classify_test_OBJECTS) $(hdrl_cat_classify_test_DEPENDENCIES) $(EXTRA_hdrl_cat_classify_test_DEPENDENCIES) + @rm -f hdrl_cat_classify-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_classify_test_OBJECTS) $(hdrl_cat_classify_test_LDADD) $(LIBS) + +hdrl_cat_conf-test$(EXEEXT): $(hdrl_cat_conf_test_OBJECTS) $(hdrl_cat_conf_test_DEPENDENCIES) $(EXTRA_hdrl_cat_conf_test_DEPENDENCIES) + @rm -f hdrl_cat_conf-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_conf_test_OBJECTS) $(hdrl_cat_conf_test_LDADD) $(LIBS) + +hdrl_cat_filter-test$(EXEEXT): $(hdrl_cat_filter_test_OBJECTS) $(hdrl_cat_filter_test_DEPENDENCIES) $(EXTRA_hdrl_cat_filter_test_DEPENDENCIES) + @rm -f hdrl_cat_filter-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_filter_test_OBJECTS) $(hdrl_cat_filter_test_LDADD) $(LIBS) + +hdrl_cat_moments-test$(EXEEXT): $(hdrl_cat_moments_test_OBJECTS) $(hdrl_cat_moments_test_DEPENDENCIES) $(EXTRA_hdrl_cat_moments_test_DEPENDENCIES) + @rm -f hdrl_cat_moments-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_moments_test_OBJECTS) $(hdrl_cat_moments_test_LDADD) $(LIBS) + +hdrl_cat_overlp-test$(EXEEXT): $(hdrl_cat_overlp_test_OBJECTS) $(hdrl_cat_overlp_test_DEPENDENCIES) $(EXTRA_hdrl_cat_overlp_test_DEPENDENCIES) + @rm -f hdrl_cat_overlp-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_overlp_test_OBJECTS) $(hdrl_cat_overlp_test_LDADD) $(LIBS) + +hdrl_cat_phopt-test$(EXEEXT): $(hdrl_cat_phopt_test_OBJECTS) $(hdrl_cat_phopt_test_DEPENDENCIES) $(EXTRA_hdrl_cat_phopt_test_DEPENDENCIES) + @rm -f hdrl_cat_phopt-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_phopt_test_OBJECTS) $(hdrl_cat_phopt_test_LDADD) $(LIBS) + +hdrl_cat_polynm-test$(EXEEXT): $(hdrl_cat_polynm_test_OBJECTS) $(hdrl_cat_polynm_test_DEPENDENCIES) $(EXTRA_hdrl_cat_polynm_test_DEPENDENCIES) + @rm -f hdrl_cat_polynm-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_polynm_test_OBJECTS) $(hdrl_cat_polynm_test_LDADD) $(LIBS) + +hdrl_cat_radii-test$(EXEEXT): $(hdrl_cat_radii_test_OBJECTS) $(hdrl_cat_radii_test_DEPENDENCIES) $(EXTRA_hdrl_cat_radii_test_DEPENDENCIES) + @rm -f hdrl_cat_radii-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_radii_test_OBJECTS) $(hdrl_cat_radii_test_LDADD) $(LIBS) + +hdrl_cat_seeing-test$(EXEEXT): $(hdrl_cat_seeing_test_OBJECTS) $(hdrl_cat_seeing_test_DEPENDENCIES) $(EXTRA_hdrl_cat_seeing_test_DEPENDENCIES) + @rm -f hdrl_cat_seeing-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_seeing_test_OBJECTS) $(hdrl_cat_seeing_test_LDADD) $(LIBS) + +hdrl_cat_sim_montecarlo-test$(EXEEXT): $(hdrl_cat_sim_montecarlo_test_OBJECTS) $(hdrl_cat_sim_montecarlo_test_DEPENDENCIES) $(EXTRA_hdrl_cat_sim_montecarlo_test_DEPENDENCIES) + @rm -f hdrl_cat_sim_montecarlo-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_sim_montecarlo_test_OBJECTS) $(hdrl_cat_sim_montecarlo_test_LDADD) $(LIBS) + +hdrl_cat_terminate-test$(EXEEXT): $(hdrl_cat_terminate_test_OBJECTS) $(hdrl_cat_terminate_test_DEPENDENCIES) $(EXTRA_hdrl_cat_terminate_test_DEPENDENCIES) + @rm -f hdrl_cat_terminate-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_terminate_test_OBJECTS) $(hdrl_cat_terminate_test_LDADD) $(LIBS) + +hdrl_cat_utils_sort-test$(EXEEXT): $(hdrl_cat_utils_sort_test_OBJECTS) $(hdrl_cat_utils_sort_test_DEPENDENCIES) $(EXTRA_hdrl_cat_utils_sort_test_DEPENDENCIES) + @rm -f hdrl_cat_utils_sort-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_cat_utils_sort_test_OBJECTS) $(hdrl_cat_utils_sort_test_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_apio-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_areals-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_background-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_casu-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_casu_addmul-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_casu_bkg_badpatch-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_classify-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_conf-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_filter-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_moments-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_overlp-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_phopt-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_polynm-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_radii-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_seeing-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_sim_montecarlo-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_terminate-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_cat_utils_sort-test.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +# Recover from deleted '.trs' file; this should ensure that +# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create +# both 'foo.log' and 'foo.trs'. Break the recipe in two subshells +# to avoid problems with "make -n". +.log.trs: + rm -f $< $@ + $(MAKE) $(AM_MAKEFLAGS) $< + +# Leading 'am--fnord' is there to ensure the list of targets does not +# expand to empty, as could happen e.g. with make check TESTS=''. +am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck) +am--force-recheck: + @: + +$(TEST_SUITE_LOG): $(TEST_LOGS) + @$(am__set_TESTS_bases); \ + am__f_ok () { test -f "$$1" && test -r "$$1"; }; \ + redo_bases=`for i in $$bases; do \ + am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \ + done`; \ + if test -n "$$redo_bases"; then \ + redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \ + redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \ + if $(am__make_dryrun); then :; else \ + rm -f $$redo_logs && rm -f $$redo_results || exit 1; \ + fi; \ + fi; \ + if test -n "$$am__remaking_logs"; then \ + echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ + "recursion detected" >&2; \ + elif test -n "$$redo_logs"; then \ + am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ + fi; \ + if $(am__make_dryrun); then :; else \ + st=0; \ + errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ + for i in $$redo_bases; do \ + test -f $$i.trs && test -r $$i.trs \ + || { echo "$$errmsg $$i.trs" >&2; st=1; }; \ + test -f $$i.log && test -r $$i.log \ + || { echo "$$errmsg $$i.log" >&2; st=1; }; \ + done; \ + test $$st -eq 0 || exit 1; \ + fi + @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \ + ws='[ ]'; \ + results=`for b in $$bases; do echo $$b.trs; done`; \ + test -n "$$results" || results=/dev/null; \ + all=` grep "^$$ws*:test-result:" $$results | wc -l`; \ + pass=` grep "^$$ws*:test-result:$$ws*PASS" $$results | wc -l`; \ + fail=` grep "^$$ws*:test-result:$$ws*FAIL" $$results | wc -l`; \ + skip=` grep "^$$ws*:test-result:$$ws*SKIP" $$results | wc -l`; \ + xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \ + xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \ + error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \ + if test `expr $$fail + $$xpass + $$error` -eq 0; then \ + success=true; \ + else \ + success=false; \ + fi; \ + br='==================='; br=$$br$$br$$br$$br; \ + result_count () \ + { \ + if test x"$$1" = x"--maybe-color"; then \ + maybe_colorize=yes; \ + elif test x"$$1" = x"--no-color"; then \ + maybe_colorize=no; \ + else \ + echo "$@: invalid 'result_count' usage" >&2; exit 4; \ + fi; \ + shift; \ + desc=$$1 count=$$2; \ + if test $$maybe_colorize = yes && test $$count -gt 0; then \ + color_start=$$3 color_end=$$std; \ + else \ + color_start= color_end=; \ + fi; \ + echo "$${color_start}# $$desc $$count$${color_end}"; \ + }; \ + create_testsuite_report () \ + { \ + result_count $$1 "TOTAL:" $$all "$$brg"; \ + result_count $$1 "PASS: " $$pass "$$grn"; \ + result_count $$1 "SKIP: " $$skip "$$blu"; \ + result_count $$1 "XFAIL:" $$xfail "$$lgn"; \ + result_count $$1 "FAIL: " $$fail "$$red"; \ + result_count $$1 "XPASS:" $$xpass "$$red"; \ + result_count $$1 "ERROR:" $$error "$$mgn"; \ + }; \ + { \ + echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \ + $(am__rst_title); \ + create_testsuite_report --no-color; \ + echo; \ + echo ".. contents:: :depth: 2"; \ + echo; \ + for b in $$bases; do echo $$b; done \ + | $(am__create_global_log); \ + } >$(TEST_SUITE_LOG).tmp || exit 1; \ + mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG); \ + if $$success; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ + fi; \ + echo "$${col}$$br$${std}"; \ + echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}$$br$${std}"; \ + create_testsuite_report --maybe-color; \ + echo "$$col$$br$$std"; \ + if $$success; then :; else \ + echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}"; \ + if test -n "$(PACKAGE_BUGREPORT)"; then \ + echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \ + fi; \ + echo "$$col$$br$$std"; \ + fi; \ + $$success || exit 1 + +check-TESTS: + @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list + @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list + @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + @set +e; $(am__set_TESTS_bases); \ + log_list=`for i in $$bases; do echo $$i.log; done`; \ + trs_list=`for i in $$bases; do echo $$i.trs; done`; \ + log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \ + $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \ + exit $$?; +recheck: all $(check_PROGRAMS) + @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + @set +e; $(am__set_TESTS_bases); \ + bases=`for i in $$bases; do echo $$i; done \ + | $(am__list_recheck_tests)` || exit 1; \ + log_list=`for i in $$bases; do echo $$i.log; done`; \ + log_list=`echo $$log_list`; \ + $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \ + am__force_recheck=am--force-recheck \ + TEST_LOGS="$$log_list"; \ + exit $$? +hdrl_cat_conf-test.log: hdrl_cat_conf-test$(EXEEXT) + @p='hdrl_cat_conf-test$(EXEEXT)'; \ + b='hdrl_cat_conf-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_background-test.log: hdrl_cat_background-test$(EXEEXT) + @p='hdrl_cat_background-test$(EXEEXT)'; \ + b='hdrl_cat_background-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_utils_sort-test.log: hdrl_cat_utils_sort-test$(EXEEXT) + @p='hdrl_cat_utils_sort-test$(EXEEXT)'; \ + b='hdrl_cat_utils_sort-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_apio-test.log: hdrl_cat_apio-test$(EXEEXT) + @p='hdrl_cat_apio-test$(EXEEXT)'; \ + b='hdrl_cat_apio-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_classify-test.log: hdrl_cat_classify-test$(EXEEXT) + @p='hdrl_cat_classify-test$(EXEEXT)'; \ + b='hdrl_cat_classify-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_phopt-test.log: hdrl_cat_phopt-test$(EXEEXT) + @p='hdrl_cat_phopt-test$(EXEEXT)'; \ + b='hdrl_cat_phopt-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_overlp-test.log: hdrl_cat_overlp-test$(EXEEXT) + @p='hdrl_cat_overlp-test$(EXEEXT)'; \ + b='hdrl_cat_overlp-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_radii-test.log: hdrl_cat_radii-test$(EXEEXT) + @p='hdrl_cat_radii-test$(EXEEXT)'; \ + b='hdrl_cat_radii-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_filter-test.log: hdrl_cat_filter-test$(EXEEXT) + @p='hdrl_cat_filter-test$(EXEEXT)'; \ + b='hdrl_cat_filter-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_terminate-test.log: hdrl_cat_terminate-test$(EXEEXT) + @p='hdrl_cat_terminate-test$(EXEEXT)'; \ + b='hdrl_cat_terminate-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_moments-test.log: hdrl_cat_moments-test$(EXEEXT) + @p='hdrl_cat_moments-test$(EXEEXT)'; \ + b='hdrl_cat_moments-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_areals-test.log: hdrl_cat_areals-test$(EXEEXT) + @p='hdrl_cat_areals-test$(EXEEXT)'; \ + b='hdrl_cat_areals-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_seeing-test.log: hdrl_cat_seeing-test$(EXEEXT) + @p='hdrl_cat_seeing-test$(EXEEXT)'; \ + b='hdrl_cat_seeing-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_polynm-test.log: hdrl_cat_polynm-test$(EXEEXT) + @p='hdrl_cat_polynm-test$(EXEEXT)'; \ + b='hdrl_cat_polynm-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_casu-test.log: hdrl_cat_casu-test$(EXEEXT) + @p='hdrl_cat_casu-test$(EXEEXT)'; \ + b='hdrl_cat_casu-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_casu_bkg_badpatch-test.log: hdrl_cat_casu_bkg_badpatch-test$(EXEEXT) + @p='hdrl_cat_casu_bkg_badpatch-test$(EXEEXT)'; \ + b='hdrl_cat_casu_bkg_badpatch-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_casu_addmul-test.log: hdrl_cat_casu_addmul-test$(EXEEXT) + @p='hdrl_cat_casu_addmul-test$(EXEEXT)'; \ + b='hdrl_cat_casu_addmul-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_cat_sim_montecarlo-test.log: hdrl_cat_sim_montecarlo-test$(EXEEXT) + @p='hdrl_cat_sim_montecarlo-test$(EXEEXT)'; \ + b='hdrl_cat_sim_montecarlo-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +.test.log: + @p='$<'; \ + $(am__set_b); \ + $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +@am__EXEEXT_TRUE@.test$(EXEEXT).log: +@am__EXEEXT_TRUE@ @p='$<'; \ +@am__EXEEXT_TRUE@ $(am__set_b); \ +@am__EXEEXT_TRUE@ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ +@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ +@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ +@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + -test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS) + -test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs) + -test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool clean-local \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool clean-local \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + recheck tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# We need to remove any files that the above tests created. +clean-local: + $(RM) *.fits *.log + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/config.h.in cpl-plugin-sinfo-3.1.0+dfsg/hdrl/config.h.in --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/config.h.in 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/config.h.in 2018-04-13 15:46:31.000000000 +0000 @@ -0,0 +1,129 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the `floor' function. */ +#undef HAVE_FLOOR + +/* Define to 1 iff you have GSL */ +#undef HAVE_GSL + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 iff you have GSL */ +#undef HAVE_LIBGSL + +/* Define to 1 if you have the `m' library (-lm). */ +#undef HAVE_LIBM + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `pow' function. */ +#undef HAVE_POW + +/* Define to 1 if you have the `sqrt' function. */ +#undef HAVE_SQRT + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define if you have the `strdup' function */ +#undef HAVE_STRDUP + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* HDRL binary age */ +#undef HDRL_BINARY_AGE + +/* HDRL binary version number */ +#undef HDRL_BINARY_VERSION + +/* HDRL interface age */ +#undef HDRL_INTERFACE_AGE + +/* HDRL major version number */ +#undef HDRL_MAJOR_VERSION + +/* HDRL micro version number */ +#undef HDRL_MICRO_VERSION + +/* HDRL minor version number */ +#undef HDRL_MINOR_VERSION + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#undef LT_OBJDIR + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define if using the dmalloc debugging malloc package */ +#undef WITH_DMALLOC + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#undef inline +#endif + + +#ifndef HAVE_STRDUP +# define strdup cx_strdup +#endif + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/configure cpl-plugin-sinfo-3.1.0+dfsg/hdrl/configure --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/configure 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/configure 2018-04-13 15:46:30.000000000 +0000 @@ -0,0 +1,16520 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.69 for HDRL Pipeline 1.1.0b3. +# +# Report bugs to . +# +# +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} +if test "x$CONFIG_SHELL" = x; then + as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which + # is contrary to our usage. Disable this feature. + alias -g '\${1+\"\$@\"}'='\"\$@\"' + setopt NO_GLOB_SUBST +else + case \`(set -o) 2>/dev/null\` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi +" + as_required="as_fn_return () { (exit \$1); } +as_fn_success () { as_fn_return 0; } +as_fn_failure () { as_fn_return 1; } +as_fn_ret_success () { return 0; } +as_fn_ret_failure () { return 1; } + +exitcode=0 +as_fn_success || { exitcode=1; echo as_fn_success failed.; } +as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } +as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } +as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } +if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : + +else + exitcode=1; echo positional parameters were not saved. +fi +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" + as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO + as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO + eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && + test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 +test \$(( 1 + 1 )) = 2 || exit 1 + + test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ + || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1" + if (eval "$as_required") 2>/dev/null; then : + as_have_required=yes +else + as_have_required=no +fi + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + as_found=: + case $as_dir in #( + /*) + for as_base in sh bash ksh sh5; do + # Try only shells that exist, to save several forks. + as_shell=$as_dir/$as_base + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + CONFIG_SHELL=$as_shell as_have_required=yes + if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + break 2 +fi +fi + done;; + esac + as_found=false +done +$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi; } +IFS=$as_save_IFS + + + if test "x$CONFIG_SHELL" != x; then : + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 +fi + + if test x$as_have_required = xno; then : + $as_echo "$0: This script requires a shell more modern than all" + $as_echo "$0: the shells that I found on your system." + if test x${ZSH_VERSION+set} = xset ; then + $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" + $as_echo "$0: be upgraded to zsh 4.3.4 or later." + else + $as_echo "$0: Please tell bug-autoconf@gnu.org and usd-help@eso.org +$0: about your system, including any error possibly output +$0: before this message. Then install a modern shell, or +$0: manually run the script under such a shell if you do +$0: have one." + fi + exit 1 +fi +fi +fi +SHELL=${CONFIG_SHELL-/bin/sh} +export SHELL +# Unset more variables known to interfere with behavior of common tools. +CLICOLOR_FORCE= GREP_OPTIONS= +unset CLICOLOR_FORCE GREP_OPTIONS + +## --------------------- ## +## M4sh Shell Functions. ## +## --------------------- ## +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + + + as_lineno_1=$LINENO as_lineno_1a=$LINENO + as_lineno_2=$LINENO as_lineno_2a=$LINENO + eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && + test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { + # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + +SHELL=${CONFIG_SHELL-/bin/sh} + + +test -n "$DJDIR" || exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= + +# Identity of this package. +PACKAGE_NAME='HDRL Pipeline' +PACKAGE_TARNAME='hdrl' +PACKAGE_VERSION='1.1.0b3' +PACKAGE_STRING='HDRL Pipeline 1.1.0b3' +PACKAGE_BUGREPORT='usd-help@eso.org' +PACKAGE_URL='' + +ac_unique_file="Makefile.am" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_STRING_H +# if !defined STDC_HEADERS && defined HAVE_MEMORY_H +# include +# endif +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='am__EXEEXT_FALSE +am__EXEEXT_TRUE +LTLIBOBJS +LIBOBJS +all_ldflags +all_includes +LIBHDRL +HDRL_LDFLAGS +HDRL_INCLUDES +GSL_LIBS +GSL_LDFLAGS +GSL_INCLUDES +LIBCEXT +LIBCPLDFS +LIBCPLUI +LIBCPLDRS +LIBCPLCORE +CPL_LDFLAGS +CPL_INCLUDES +LIBTOOL_DEPS +LT_SYS_LIBRARY_PATH +OTOOL64 +OTOOL +LIPO +NMEDIT +DSYMUTIL +MANIFEST_TOOL +RANLIB +ac_ct_AR +AR +DLLTOOL +OBJDUMP +NM +ac_ct_DUMPBIN +DUMPBIN +LD +FGREP +SED +LIBTOOL +LATEX +DOXYGEN +VLTSW_FALSE +VLTSW_TRUE +EGREP +GREP +ESO_DEBUG_FLAGS +LN_S +CPP +am__fastdepCC_FALSE +am__fastdepCC_TRUE +CCDEPMODE +am__nodep +AMDEPBACKSLASH +AMDEP_FALSE +AMDEP_TRUE +am__quote +am__include +DEPDIR +OBJEXT +EXEEXT +ac_ct_CC +CPPFLAGS +LDFLAGS +CFLAGS +CC +LT_AGE +LT_REVISION +LT_CURRENT +HDRL_BINARY_AGE +HDRL_BINARY_VERSION +HDRL_INTERFACE_AGE +HDRL_MICRO_VERSION +HDRL_MINOR_VERSION +HDRL_MAJOR_VERSION +HDRL_VERSION +MAINT +MAINTAINER_MODE_FALSE +MAINTAINER_MODE_TRUE +AM_BACKSLASH +AM_DEFAULT_VERBOSITY +AM_DEFAULT_V +AM_V +am__untar +am__tar +AMTAR +am__leading_dot +SET_MAKE +AWK +mkdir_p +MKDIR_P +INSTALL_STRIP_PROGRAM +STRIP +install_sh +MAKEINFO +AUTOHEADER +AUTOMAKE +AUTOCONF +ACLOCAL +VERSION +PACKAGE +CYGPATH_W +am__isrc +INSTALL_DATA +INSTALL_SCRIPT +INSTALL_PROGRAM +target_os +target_vendor +target_cpu +target +host_os +host_vendor +host_cpu +host +build_os +build_vendor +build_cpu +build +target_alias +host_alias +build_alias +LIBS +ECHO_T +ECHO_N +ECHO_C +DEFS +mandir +localedir +libdir +psdir +pdfdir +dvidir +htmldir +infodir +docdir +oldincludedir +includedir +localstatedir +sharedstatedir +sysconfdir +datadir +datarootdir +libexecdir +sbindir +bindir +program_transform_name +prefix +exec_prefix +PACKAGE_URL +PACKAGE_BUGREPORT +PACKAGE_STRING +PACKAGE_VERSION +PACKAGE_TARNAME +PACKAGE_NAME +PATH_SEPARATOR +SHELL' +ac_subst_files='' +ac_user_opts=' +enable_option_checking +enable_silent_rules +enable_maintainer_mode +enable_dependency_tracking +enable_largefile +enable_debug +enable_strict +enable_openmp +enable_tsan +enable_standalone +enable_static +enable_shared +with_pic +enable_fast_install +with_aix_soname +with_gnu_ld +with_sysroot +enable_libtool_lock +with_cpl +with_cpl_includes +with_cpl_libs +enable_cpl_test +with_gsl +with_gsl_includes +with_gsl_libs +enable_gsl_test +with_dmalloc +' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +LIBS +CPPFLAGS +CPP +DOXYGEN +LATEX +LT_SYS_LIBRARY_PATH' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +ac_unrecognized_opts= +ac_unrecognized_sep= +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid feature name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"enable_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval enable_$ac_useropt=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=\$ac_optarg ;; + + -without-* | --without-*) + ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && + as_fn_error $? "invalid package name: $ac_useropt" + ac_useropt_orig=$ac_useropt + ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + case $ac_user_opts in + *" +"with_$ac_useropt" +"*) ;; + *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" + ac_unrecognized_sep=', ';; + esac + eval with_$ac_useropt=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + case $ac_envvar in #( + '' | [0-9]* | *[!_$as_cr_alnum]* ) + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; + esac + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + as_fn_error $? "missing argument to $ac_option" +fi + +if test -n "$ac_unrecognized_opts"; then + case $enable_option_checking in + no) ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; + *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + esac +fi + +# Check all directory arguments for consistency. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + # Remove trailing slashes. + case $ac_val in + */ ) + ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` + eval $ac_var=\$ac_val;; + esac + # Be sure to have absolute directory names. + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + as_fn_error $? "working directory cannot be determined" +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + as_fn_error $? "pwd does not report name of working directory" + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$as_myself" || +$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_myself" : 'X\(//\)[^/]' \| \ + X"$as_myself" : 'X\(//\)$' \| \ + X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_myself" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures HDRL Pipeline 1.1.0b3 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking ...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/hdrl] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF + +Program names: + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST cross-compile to build programs to run on HOST [BUILD] + --target=TARGET configure for building compilers for TARGET [HOST] +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of HDRL Pipeline 1.1.0b3:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-silent-rules less verbose build output (undo: "make V=1") + --disable-silent-rules verbose build output (undo: "make V=0") + --disable-maintainer-mode + disable make rules and dependencies not useful (and + sometimes confusing) to the casual installer + --enable-dependency-tracking + do not reject slow dependency extractors + --disable-dependency-tracking + speeds up one-time build + --disable-largefile omit support for large files + --enable-debug creates debugging code [default=no] + --enable-strict compiles with strict compiler options (may not + work!) [default=no] + --enable-openmp compiles with openmp compiler options (may not + work!) [[default=yes]] + --enable-tsan compiles with thread sanitizer, may need sanitized + libgomp, cpl and esorex to be effective. + [[default=no]] + --enable-standalone enable standalone installation for VLTSW + [[default=no]] + --enable-static[=PKGS] build static libraries [default=no] + --enable-shared[=PKGS] build shared libraries [default=yes] + --enable-fast-install[=PKGS] + optimize for fast installation [default=yes] + --disable-libtool-lock avoid locking (might break parallel builds) + --disable-cpl-test disables checks for the CPL library and headers + --disable-gsl-test disables checks for the GSL library and headers + +Optional Packages: + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use + both] + --with-aix-soname=aix|svr4|both + shared library versioning (aka "SONAME") variant to + provide on AIX, [default=aix]. + --with-gnu-ld assume the C compiler uses GNU ld [default=no] + --with-sysroot[=DIR] Search for dependent libraries within DIR (or the + compiler's sysroot if not specified). + --with-cpl location where CPL is installed + --with-cpl-includes location of the CPL header files + --with-cpl-libs location of the CPL library + --with-gsl location where GSL is installed + --with-gsl-includes location of the GSL header files + --with-gsl-libs location of the GSL library + --with-dmalloc use dmalloc, as in http://www.dmalloc.com + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + LIBS libraries to pass to the linker, e.g. -l + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + DOXYGEN doxygen command + LATEX latex command + LT_SYS_LIBRARY_PATH + User-defined run-time library search path. + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +Report bugs to . +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || + { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || + continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +HDRL Pipeline configure 1.1.0b3 +generated by GNU Autoconf 2.69 + +Copyright (C) 2012 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi + +## ------------------------ ## +## Autoconf initialization. ## +## ------------------------ ## + +# ac_fn_c_try_compile LINENO +# -------------------------- +# Try to compile conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext + if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_compile + +# ac_fn_c_try_cpp LINENO +# ---------------------- +# Try to preprocess conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_cpp () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } > conftest.i && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_cpp + +# ac_fn_c_try_link LINENO +# ----------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_c_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + test -x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_link + +# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists and can be compiled using the include files in +# INCLUDES, setting the cache variable VAR accordingly. +ac_fn_c_check_header_compile () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_compile + +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes +# that executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then : + ac_retval=0 +else + $as_echo "$as_me: program exited with status $ac_status" >&5 + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_func + +# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES +# ------------------------------------------------------- +# Tests whether HEADER exists, giving a warning if it cannot be compiled using +# the include files in INCLUDES and setting the cache variable VAR +# accordingly. +ac_fn_c_check_header_mongrel () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if eval \${$3+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 +$as_echo_n "checking $2 usability... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +#include <$2> +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_header_compiler=yes +else + ac_header_compiler=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 +$as_echo_n "checking $2 presence... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <$2> +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + ac_header_preproc=yes +else + ac_header_preproc=no +fi +rm -f conftest.err conftest.i conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( + yes:no: ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} + ;; + no:yes:* ) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} +( $as_echo "## ------------------------------- ## +## Report this to usd-help@eso.org ## +## ------------------------------- ##" + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + eval "$3=\$ac_header_compiler" +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } +fi + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_header_mongrel + +# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES +# --------------------------------------------- +# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR +# accordingly. +ac_fn_c_check_decl () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + as_decl_name=`echo $2|sed 's/ *(.*//'` + as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 +$as_echo_n "checking whether $as_decl_name is declared... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +#ifndef $as_decl_name +#ifdef __cplusplus + (void) $as_decl_use; +#else + (void) $as_decl_name; +#endif +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_decl +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by HDRL Pipeline $as_me 1.1.0b3, which was +generated by GNU Autoconf 2.69. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + $as_echo "PATH: $as_dir" + done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; + 2) + as_fn_append ac_configure_args1 " '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + as_fn_append ac_configure_args " '$ac_arg'" + ;; + esac + done +done +{ ac_configure_args0=; unset ac_configure_args0;} +{ ac_configure_args1=; unset ac_configure_args1;} + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + $as_echo "## ---------------- ## +## Cache variables. ## +## ---------------- ##" + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + $as_echo "## ----------------- ## +## Output variables. ## +## ----------------- ##" + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + $as_echo "## ------------------- ## +## File substitutions. ## +## ------------------- ##" + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + $as_echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + $as_echo "## ----------- ## +## confdefs.h. ## +## ----------- ##" + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + $as_echo "$as_me: caught signal $ac_signal" + $as_echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +$as_echo "/* confdefs.h */" > confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_URL "$PACKAGE_URL" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer an explicitly selected file to automatically selected ones. +ac_site_file1=NONE +ac_site_file2=NONE +if test -n "$CONFIG_SITE"; then + # We do not want a PATH search for config.site. + case $CONFIG_SITE in #(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac +elif test "x$prefix" != xNONE; then + ac_site_file1=$prefix/share/config.site + ac_site_file2=$prefix/etc/config.site +else + ac_site_file1=$ac_default_prefix/share/config.site + ac_site_file2=$ac_default_prefix/etc/config.site +fi +for ac_site_file in "$ac_site_file1" "$ac_site_file2" +do + test "x$ac_site_file" = xNONE && continue + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +$as_echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +$as_echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +$as_echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + # differences in whitespace do not lead to failure. + ac_old_val_w=`echo x $ac_old_val` + ac_new_val_w=`echo x $ac_new_val` + if test "$ac_old_val_w" != "$ac_new_val_w"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + ac_cache_corrupted=: + else + { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + eval $ac_var=\$ac_old_val + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) as_fn_append ac_configure_args " '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 +fi +## -------------------- ## +## Main body of script. ## +## -------------------- ## + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + +ac_aux_dir= +for ac_dir in admin "$srcdir"/admin; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + as_fn_error $? "cannot find install-sh, install.sh, or shtool in admin \"$srcdir\"/admin" "$LINENO" 5 +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + + + +# Make sure we can run config.sub. +$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +$as_echo_n "checking build system type... " >&6; } +if ${ac_cv_build+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_build_alias=$build_alias +test "x$ac_build_alias" = x && + ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` +test "x$ac_build_alias" = x && + as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 +ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +$as_echo "$ac_cv_build" >&6; } +case $ac_cv_build in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; +esac +build=$ac_cv_build +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_build +shift +build_cpu=$1 +build_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +build_os=$* +IFS=$ac_save_IFS +case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +$as_echo_n "checking host system type... " >&6; } +if ${ac_cv_host+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "x$host_alias" = x; then + ac_cv_host=$ac_cv_build +else + ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +$as_echo "$ac_cv_host" >&6; } +case $ac_cv_host in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; +esac +host=$ac_cv_host +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_host +shift +host_cpu=$1 +host_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +host_os=$* +IFS=$ac_save_IFS +case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5 +$as_echo_n "checking target system type... " >&6; } +if ${ac_cv_target+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "x$target_alias" = x; then + ac_cv_target=$ac_cv_host +else + ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` || + as_fn_error $? "$SHELL $ac_aux_dir/config.sub $target_alias failed" "$LINENO" 5 +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_target" >&5 +$as_echo "$ac_cv_target" >&6; } +case $ac_cv_target in +*-*-*) ;; +*) as_fn_error $? "invalid value of canonical target" "$LINENO" 5;; +esac +target=$ac_cv_target +ac_save_IFS=$IFS; IFS='-' +set x $ac_cv_target +shift +target_cpu=$1 +target_vendor=$2 +shift; shift +# Remember, the first character of IFS is used to create $*, +# except with old shells: +target_os=$* +IFS=$ac_save_IFS +case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac + + +# The aliases save the names the user supplied, while $host etc. +# will get canonicalized. +test -n "$target_alias" && + test "$program_prefix$program_suffix$program_transform_name" = \ + NONENONEs,x,x, && + program_prefix=${target_alias}- + +am__api_version='1.15' + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +# Reject install programs that cannot install multiple files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +$as_echo_n "checking for a BSD-compatible install... " >&6; } +if test -z "$INSTALL"; then +if ${ac_cv_path_install+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in #(( + ./ | .// | /[cC]/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + rm -rf conftest.one conftest.two conftest.dir + echo one > conftest.one + echo two > conftest.two + mkdir conftest.dir + if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + test -s conftest.one && test -s conftest.two && + test -s conftest.dir/conftest.one && + test -s conftest.dir/conftest.two + then + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + fi + done + done + ;; +esac + + done +IFS=$as_save_IFS + +rm -rf conftest.one conftest.two conftest.dir + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +$as_echo "$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +$as_echo_n "checking whether build environment is sane... " >&6; } +# Reject unsafe characters in $srcdir or the absolute working directory +# name. Accept space and tab only in the latter. +am_lf=' +' +case `pwd` in + *[\\\"\#\$\&\'\`$am_lf]*) + as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; +esac +case $srcdir in + *[\\\"\#\$\&\'\`$am_lf\ \ ]*) + as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; +esac + +# Do 'set' in a subshell so we don't clobber the current shell's +# arguments. Must try -L first in case configure is actually a +# symlink; some systems play weird games with the mod time of symlinks +# (eg FreeBSD returns the mod time of the symlink's containing +# directory). +if ( + am_has_slept=no + for am_try in 1 2; do + echo "timestamp, slept: $am_has_slept" > conftest.file + set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` + if test "$*" = "X"; then + # -L didn't work. + set X `ls -t "$srcdir/configure" conftest.file` + fi + if test "$*" != "X $srcdir/configure conftest.file" \ + && test "$*" != "X conftest.file $srcdir/configure"; then + + # If neither matched, then we have a broken ls. This can happen + # if, for instance, CONFIG_SHELL is bash and it inherits a + # broken ls alias from the environment. This has actually + # happened. Such a system could not be considered "sane". + as_fn_error $? "ls -t appears to fail. Make sure there is not a broken + alias in your environment" "$LINENO" 5 + fi + if test "$2" = conftest.file || test $am_try -eq 2; then + break + fi + # Just in case. + sleep 1 + am_has_slept=yes + done + test "$2" = conftest.file + ) +then + # Ok. + : +else + as_fn_error $? "newly created file is older than distributed files! +Check your system clock" "$LINENO" 5 +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +# If we didn't sleep, we still need to ensure time stamps of config.status and +# generated files are strictly newer. +am_sleep_pid= +if grep 'slept: no' conftest.file >/dev/null 2>&1; then + ( sleep 1 ) & + am_sleep_pid=$! +fi + +rm -f conftest.file + +test "$program_prefix" != NONE && + program_transform_name="s&^&$program_prefix&;$program_transform_name" +# Use a double $ so make ignores it. +test "$program_suffix" != NONE && + program_transform_name="s&\$&$program_suffix&;$program_transform_name" +# Double any \ or $. +# By default was `s,x,x', remove it if useless. +ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' +program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` + +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` + +if test x"${MISSING+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; + *) + MISSING="\${SHELL} $am_aux_dir/missing" ;; + esac +fi +# Use eval to expand $SHELL +if eval "$MISSING --is-lightweight"; then + am_missing_run="$MISSING " +else + am_missing_run= + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} +fi + +if test x"${install_sh+set}" != xset; then + case $am_aux_dir in + *\ * | *\ *) + install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; + *) + install_sh="\${SHELL} $am_aux_dir/install-sh" + esac +fi + +# Installed binaries are usually stripped using 'strip' when the user +# run "make install-strip". However 'strip' might not be the right +# tool to use in cross-compilation environments, therefore Automake +# will honor the 'STRIP' environment variable to overrule this program. +if test "$cross_compiling" != no; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +fi +INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 +$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } +if test -z "$MKDIR_P"; then + if ${ac_cv_path_mkdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in mkdir gmkdir; do + for ac_exec_ext in '' $ac_executable_extensions; do + as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue + case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir (GNU coreutils) '* | \ + 'mkdir (coreutils) '* | \ + 'mkdir (fileutils) '4.1*) + ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + break 3;; + esac + done + done + done +IFS=$as_save_IFS + +fi + + test -d ./--version && rmdir ./--version + if test "${ac_cv_path_mkdir+set}" = set; then + MKDIR_P="$ac_cv_path_mkdir -p" + else + # As a last resort, use the slow shell script. Don't cache a + # value for MKDIR_P within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + MKDIR_P="$ac_install_sh -d" + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +$as_echo "$MKDIR_P" >&6; } + +for ac_prog in gawk mawk nawk awk +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AWK+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AWK"; then + ac_cv_prog_AWK="$AWK" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AWK="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AWK=$ac_cv_prog_AWK +if test -n "$AWK"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +$as_echo "$AWK" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AWK" && break +done + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +set x ${MAKE-make} +ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat >conftest.make <<\_ACEOF +SHELL = /bin/sh +all: + @echo '@@@%%%=$(MAKE)=@@@%%%' +_ACEOF +# GNU make sometimes prints "make[1]: Entering ...", which would confuse us. +case `${MAKE-make} -f conftest.make 2>/dev/null` in + *@@@%%%=?*=@@@%%%*) + eval ac_cv_prog_make_${ac_make}_set=yes;; + *) + eval ac_cv_prog_make_${ac_make}_set=no;; +esac +rm -f conftest.make +fi +if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + SET_MAKE= +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + SET_MAKE="MAKE=${MAKE-make}" +fi + +rm -rf .tst 2>/dev/null +mkdir .tst 2>/dev/null +if test -d .tst; then + am__leading_dot=. +else + am__leading_dot=_ +fi +rmdir .tst 2>/dev/null + +# Check whether --enable-silent-rules was given. +if test "${enable_silent_rules+set}" = set; then : + enableval=$enable_silent_rules; +fi + +case $enable_silent_rules in # ((( + yes) AM_DEFAULT_VERBOSITY=0;; + no) AM_DEFAULT_VERBOSITY=1;; + *) AM_DEFAULT_VERBOSITY=1;; +esac +am_make=${MAKE-make} +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +$as_echo_n "checking whether $am_make supports nested variables... " >&6; } +if ${am_cv_make_support_nested_variables+:} false; then : + $as_echo_n "(cached) " >&6 +else + if $as_echo 'TRUE=$(BAR$(V)) +BAR0=false +BAR1=true +V=1 +am__doit: + @$(TRUE) +.PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then + am_cv_make_support_nested_variables=yes +else + am_cv_make_support_nested_variables=no +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +$as_echo "$am_cv_make_support_nested_variables" >&6; } +if test $am_cv_make_support_nested_variables = yes; then + AM_V='$(V)' + AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' +else + AM_V=$AM_DEFAULT_VERBOSITY + AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY +fi +AM_BACKSLASH='\' + +if test "`cd $srcdir && pwd`" != "`pwd`"; then + # Use -I$(srcdir) only when $(srcdir) != ., so that make's output + # is not polluted with repeated "-I." + am__isrc=' -I$(srcdir)' + # test to see if srcdir already configured + if test -f $srcdir/config.status; then + as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 + fi +fi + +# test whether we have cygpath +if test -z "$CYGPATH_W"; then + if (cygpath --version) >/dev/null 2>/dev/null; then + CYGPATH_W='cygpath -w' + else + CYGPATH_W=echo + fi +fi + + +# Define the identity of the package. + PACKAGE='hdrl' + VERSION='1.1.0b3' + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE "$PACKAGE" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define VERSION "$VERSION" +_ACEOF + +# Some tools Automake needs. + +ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} + + +AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} + + +AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} + + +AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} + + +MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} + +# For better backward compatibility. To be removed once Automake 1.9.x +# dies out for good. For more background, see: +# +# +mkdir_p='$(MKDIR_P)' + +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. +# Always define AMTAR for backward compatibility. Yes, it's still used +# in the wild :-( We should find a proper way to deprecate it ... +AMTAR='$${TAR-tar}' + + +# We'll loop over all known methods to create a tar archive until one works. +_am_tools='gnutar pax cpio none' + +am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' + + + + + + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 + fi +fi + +ac_config_headers="$ac_config_headers config.h" + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } + # Check whether --enable-maintainer-mode was given. +if test "${enable_maintainer_mode+set}" = set; then : + enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval +else + USE_MAINTAINER_MODE=yes +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 +$as_echo "$USE_MAINTAINER_MODE" >&6; } + if test $USE_MAINTAINER_MODE = yes; then + MAINTAINER_MODE_TRUE= + MAINTAINER_MODE_FALSE='#' +else + MAINTAINER_MODE_TRUE='#' + MAINTAINER_MODE_FALSE= +fi + + MAINT=$MAINTAINER_MODE_TRUE + + + +# Immediately before every release do: +#------------------------------------- +# if (the interface is totally unchanged from previous release) +# REVISION++; +# else { +# /* interfaces have been added, removed or changed */ +# REVISION = 0; +# CURRENT++; +# if (any interfaces have been _added_ since last release) +# AGE++; +# if (any interfaces have been _removed_ or incompatibly changed) +# AGE = 0; +# } + +# Order of arguments: VERSION, CURRENT, REVISION, AGE + + hdrldemo_version=`echo "$VERSION" | sed -e 's/[a-z,A-Z].*$//'` + + hdrldemo_major_version=`echo "$hdrldemo_version" | \ + sed 's/\([0-9]*\).\(.*\)/\1/'` + hdrldemo_minor_version=`echo "$hdrldemo_version" | \ + sed 's/\([0-9]*\).\([0-9]*\)\(.*\)/\2/'` + hdrldemo_micro_version=`echo "$hdrldemo_version" | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'` + + if test -z "$hdrldemo_major_version"; then hdrldemo_major_version=0 + fi + + if test -z "$hdrldemo_minor_version"; then hdrldemo_minor_version=0 + fi + + if test -z "$hdrldemo_micro_version"; then hdrldemo_micro_version=0 + fi + + HDRL_VERSION="$hdrldemo_version" + HDRL_MAJOR_VERSION=$hdrldemo_major_version + HDRL_MINOR_VERSION=$hdrldemo_minor_version + HDRL_MICRO_VERSION=$hdrldemo_micro_version + + if test -z "0"; then HDRL_INTERFACE_AGE=0 + else HDRL_INTERFACE_AGE="0" + fi + + HDRL_BINARY_AGE=`expr 100 '*' $HDRL_MINOR_VERSION + $HDRL_MICRO_VERSION` + HDRL_BINARY_VERSION=`expr 10000 '*' $HDRL_MAJOR_VERSION + \ + $HDRL_BINARY_AGE` + + + + + + + + + + +cat >>confdefs.h <<_ACEOF +#define HDRL_MAJOR_VERSION $HDRL_MAJOR_VERSION +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define HDRL_MINOR_VERSION $HDRL_MINOR_VERSION +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define HDRL_MICRO_VERSION $HDRL_MICRO_VERSION +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define HDRL_INTERFACE_AGE $HDRL_INTERFACE_AGE +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define HDRL_BINARY_VERSION $HDRL_BINARY_VERSION +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define HDRL_BINARY_AGE $HDRL_BINARY_AGE +_ACEOF + + + + + if test -z "0"; then + LT_CURRENT=0 + else + LT_CURRENT="0" + fi + + if test -z "0"; then + LT_REVISION=0 + else + LT_REVISION="0" + fi + + if test -z "0"; then + LT_AGE=0 + else + LT_AGE="0" + fi + + + + + + + +# Checks for programs. +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +$as_echo "$CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +$as_echo "$ac_ct_CC" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "no acceptable C compiler found in \$PATH +See \`config.log' for more details" "$LINENO" 5; } + +# Provide some information about the compiler. +$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +set X $ac_compile +ac_compiler=$2 +for ac_option in --version -v -V -qversion; do + { { ac_try="$ac_compiler $ac_option >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compiler $ac_option >&5") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + sed '10a\ +... rest of stderr output deleted ... + 10q' conftest.err >conftest.er1 + cat conftest.er1 >&5 + fi + rm -f conftest.er1 conftest.err + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +done + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +$as_echo_n "checking whether the C compiler works... " >&6; } +ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` + +# The possible output files: +ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" + +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { { ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files '' +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + ac_file='' +fi +if test -z "$ac_file"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "C compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +$as_echo_n "checking for C compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } +ac_exeext=$ac_cv_exeext + +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +$as_echo_n "checking for suffix of executables... " >&6; } +if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest conftest$ac_cv_exeext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +$as_echo "$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +$as_echo_n "checking for suffix of object files... " >&6; } +if ${ac_cv_objext+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { { ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then : + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot compute suffix of object files: cannot compile +See \`config.log' for more details" "$LINENO" 5; } +fi +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +$as_echo "$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 +$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } +if ${ac_cv_c_compiler_gnu+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_compiler_gnu=yes +else + ac_compiler_gnu=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +$as_echo "$ac_cv_c_compiler_gnu" >&6; } +if test $ac_compiler_gnu = yes; then + GCC=yes +else + GCC= +fi +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +$as_echo_n "checking whether $CC accepts -g... " >&6; } +if ${ac_cv_prog_cc_g+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +else + CFLAGS="" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + +else + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_g=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +$as_echo "$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 +$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } +if ${ac_cv_prog_cc_c89+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_prog_cc_c89=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +$as_echo "none needed" >&6; } ;; + xno) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +$as_echo "unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; +esac +if test "x$ac_cv_prog_cc_c89" != xno; then : + +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } +if ${am_cv_prog_cc_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 + ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +$as_echo "$am_cv_prog_cc_c_o" >&6; } +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +DEPDIR="${am__leading_dot}deps" + +ac_config_commands="$ac_config_commands depfiles" + + +am_make=${MAKE-make} +cat > confinc << 'END' +am__doit: + @echo this is the am__doit target +.PHONY: am__doit +END +# If we don't find an include directive, just comment out the code. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for style of include used by $am_make" >&5 +$as_echo_n "checking for style of include used by $am_make... " >&6; } +am__include="#" +am__quote= +_am_result=none +# First try GNU make style include. +echo "include confinc" > confmf +# Ignore all kinds of additional output from 'make'. +case `$am_make -s -f confmf 2> /dev/null` in #( +*the\ am__doit\ target*) + am__include=include + am__quote= + _am_result=GNU + ;; +esac +# Now try BSD make style include. +if test "$am__include" = "#"; then + echo '.include "confinc"' > confmf + case `$am_make -s -f confmf 2> /dev/null` in #( + *the\ am__doit\ target*) + am__include=.include + am__quote="\"" + _am_result=BSD + ;; + esac +fi + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 +$as_echo "$_am_result" >&6; } +rm -f confinc confmf + +# Check whether --enable-dependency-tracking was given. +if test "${enable_dependency_tracking+set}" = set; then : + enableval=$enable_dependency_tracking; +fi + +if test "x$enable_dependency_tracking" != xno; then + am_depcomp="$ac_aux_dir/depcomp" + AMDEPBACKSLASH='\' + am__nodep='_no' +fi + if test "x$enable_dependency_tracking" != xno; then + AMDEP_TRUE= + AMDEP_FALSE='#' +else + AMDEP_TRUE='#' + AMDEP_FALSE= +fi + + + +depcc="$CC" am_compiler_list= + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +$as_echo_n "checking dependency style of $depcc... " >&6; } +if ${am_cv_CC_dependencies_compiler_type+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then + # We make a subdir and do the tests there. Otherwise we can end up + # making bogus files that we don't know about and never remove. For + # instance it was reported that on HP-UX the gcc test will end up + # making a dummy file named 'D' -- because '-MD' means "put the output + # in D". + rm -rf conftest.dir + mkdir conftest.dir + # Copy depcomp to subdir because otherwise we won't find it if we're + # using a relative directory. + cp "$am_depcomp" conftest.dir + cd conftest.dir + # We will build objects and dependencies in a subdirectory because + # it helps to detect inapplicable dependency modes. For instance + # both Tru64's cc and ICC support -MD to output dependencies as a + # side effect of compilation, but ICC will put the dependencies in + # the current directory while Tru64 will put them in the object + # directory. + mkdir sub + + am_cv_CC_dependencies_compiler_type=none + if test "$am_compiler_list" = ""; then + am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` + fi + am__universal=false + case " $depcc " in #( + *\ -arch\ *\ -arch\ *) am__universal=true ;; + esac + + for depmode in $am_compiler_list; do + # Setup a source with many dependencies, because some compilers + # like to wrap large dependency lists on column 80 (with \), and + # we should not choose a depcomp mode which is confused by this. + # + # We need to recreate these files for each test, as the compiler may + # overwrite some of them when testing with obscure command lines. + # This happens at least with the AIX C compiler. + : > sub/conftest.c + for i in 1 2 3 4 5 6; do + echo '#include "conftst'$i'.h"' >> sub/conftest.c + # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with + # Solaris 10 /bin/sh. + echo '/* dummy */' > sub/conftst$i.h + done + echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf + + # We check with '-c' and '-o' for the sake of the "dashmstdout" + # mode. It turns out that the SunPro C++ compiler does not properly + # handle '-M -o', and we need to detect this. Also, some Intel + # versions had trouble with output in subdirs. + am__obj=sub/conftest.${OBJEXT-o} + am__minus_obj="-o $am__obj" + case $depmode in + gcc) + # This depmode causes a compiler race in universal mode. + test "$am__universal" = false || continue + ;; + nosideeffect) + # After this tag, mechanisms are not by side-effect, so they'll + # only be used when explicitly requested. + if test "x$enable_dependency_tracking" = xyes; then + continue + else + break + fi + ;; + msvc7 | msvc7msys | msvisualcpp | msvcmsys) + # This compiler won't grok '-c -o', but also, the minuso test has + # not run yet. These depmodes are late enough in the game, and + # so weak that their functioning should not be impacted. + am__obj=conftest.${OBJEXT-o} + am__minus_obj= + ;; + none) break ;; + esac + if depmode=$depmode \ + source=sub/conftest.c object=$am__obj \ + depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ + $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ + >/dev/null 2>conftest.err && + grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && + grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && + grep $am__obj sub/conftest.Po > /dev/null 2>&1 && + ${MAKE-make} -s -f confmf > /dev/null 2>&1; then + # icc doesn't choke on unknown options, it will just issue warnings + # or remarks (even with -Werror). So we grep stderr for any message + # that says an option was ignored or not supported. + # When given -MP, icc 7.0 and 7.1 complain thusly: + # icc: Command line warning: ignoring option '-M'; no argument required + # The diagnosis changed in icc 8.0: + # icc: Command line remark: option '-MP' not supported + if (grep 'ignoring option' conftest.err || + grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else + am_cv_CC_dependencies_compiler_type=$depmode + break + fi + fi + done + + cd .. + rm -rf conftest.dir +else + am_cv_CC_dependencies_compiler_type=none +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } +CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type + + if + test "x$enable_dependency_tracking" != xno \ + && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then + am__fastdepCC_TRUE= + am__fastdepCC_FALSE='#' +else + am__fastdepCC_TRUE='#' + am__fastdepCC_FALSE= +fi + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +$as_echo_n "checking how to run the C preprocessor... " >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if ${ac_cv_prog_CPP+:} false; then : + $as_echo_n "(cached) " >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +$as_echo "$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + +else + # Broken: fails on valid input. +continue +fi +rm -f conftest.err conftest.i conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +_ACEOF +if ac_fn_c_try_cpp "$LINENO"; then : + # Broken: success on invalid input. +continue +else + # Passes both tests. +ac_preproc_ok=: +break +fi +rm -f conftest.err conftest.i conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.i conftest.err conftest.$ac_ext +if $ac_preproc_ok; then : + +else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details" "$LINENO" 5; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +$as_echo_n "checking whether ln -s works... " >&6; } +LN_S=$as_ln_s +if test "$LN_S" = "ln -s"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +$as_echo "no, using $LN_S" >&6; } +fi + + + +# Check whether --enable-largefile was given. +if test "${enable_largefile+set}" = set; then : + enableval=$enable_largefile; +fi + +if test "$enable_largefile" != no; then + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 +$as_echo_n "checking for special C compiler options needed for large files... " >&6; } +if ${ac_cv_sys_largefile_CC+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_sys_largefile_CC=no + if test "$GCC" != yes; then + ac_save_CC=$CC + while :; do + # IRIX 6.2 and later do not support large files by default, + # so use the C compiler's -n32 option if that helps. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF + if ac_fn_c_try_compile "$LINENO"; then : + break +fi +rm -f core conftest.err conftest.$ac_objext + CC="$CC -n32" + if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_sys_largefile_CC=' -n32'; break +fi +rm -f core conftest.err conftest.$ac_objext + break + done + CC=$ac_save_CC + rm -f conftest.$ac_ext + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 +$as_echo "$ac_cv_sys_largefile_CC" >&6; } + if test "$ac_cv_sys_largefile_CC" != no; then + CC=$CC$ac_cv_sys_largefile_CC + fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 +$as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } +if ${ac_cv_sys_file_offset_bits+:} false; then : + $as_echo_n "(cached) " >&6 +else + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_sys_file_offset_bits=no; break +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _FILE_OFFSET_BITS 64 +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_sys_file_offset_bits=64; break +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cv_sys_file_offset_bits=unknown + break +done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_file_offset_bits" >&5 +$as_echo "$ac_cv_sys_file_offset_bits" >&6; } +case $ac_cv_sys_file_offset_bits in #( + no | unknown) ;; + *) +cat >>confdefs.h <<_ACEOF +#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits +_ACEOF +;; +esac +rm -rf conftest* + if test $ac_cv_sys_file_offset_bits = unknown; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5 +$as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; } +if ${ac_cv_sys_large_files+:} false; then : + $as_echo_n "(cached) " >&6 +else + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_sys_large_files=no; break +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#define _LARGE_FILES 1 +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_sys_large_files=1; break +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_cv_sys_large_files=unknown + break +done +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_large_files" >&5 +$as_echo "$ac_cv_sys_large_files" >&6; } +case $ac_cv_sys_large_files in #( + no | unknown) ;; + *) +cat >>confdefs.h <<_ACEOF +#define _LARGE_FILES $ac_cv_sys_large_files +_ACEOF +;; +esac +rm -rf conftest* + fi + + +fi + + + + + + # Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then : + enableval=$enable_debug; eso_enable_debug=$enableval +else + eso_enable_debug=no +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether debugging code should be created" >&5 +$as_echo_n "checking whether debugging code should be created... " >&6; } +if ${eso_cv_enable_debug+:} false; then : + $as_echo_n "(cached) " >&6 +else + eso_cv_enable_debug=$eso_enable_debug +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_debug" >&5 +$as_echo "$eso_cv_enable_debug" >&6; } + + if test x"$eso_cv_enable_debug" = xyes; then + + eso_clean_CFLAGS="`echo $CFLAGS | sed -e 's/-O[0-9]//g' \ + -e 's/-g[0-9]//g' \ + -e 's/-g[a-z,A-Z]* / /g' \ + -e 's/-[Og]//g'`" + + + + + flag=`echo g3 | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -g3" >&5 +$as_echo_n "checking whether $CC supports -g3... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -g3 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -g3 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -g3" + else + : + + fi + + + if test x"$eso_cv_prog_cc_g3" = xyes; then + CFLAGS="-g3" + else + if test x"$ac_cv_prog_cc_g" = xyes; then + CFLAGS="-g" + else + CFLAGS="" + fi + fi + + + + + flag=`echo ggdb | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -ggdb" >&5 +$as_echo_n "checking whether $CC supports -ggdb... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -ggdb -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -ggdb -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -ggdb" + else + : + + fi + + + + + flag=`echo O0 | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -O0" >&5 +$as_echo_n "checking whether $CC supports -O0... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -O0 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -O0 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -O0" + else + : + + fi + + + + + flag=`echo rdynamic | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -rdynamic" >&5 +$as_echo_n "checking whether $CC supports -rdynamic... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -rdynamic -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -rdynamic -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -rdynamic" + else + : + + fi + + + + + flag=`echo Wall | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wall" >&5 +$as_echo_n "checking whether $CC supports -Wall... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Wall -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Wall -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Wall" + else + : + + fi + + + + + flag=`echo W | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -W" >&5 +$as_echo_n "checking whether $CC supports -W... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -W -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -W -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -W" + else + : + + fi + + + CFLAGS="$CFLAGS $eso_clean_CFLAGS" + ESO_DEBUG_FLAGS="-DESO_ENABLE_DEBUG" + else + ESO_DEBUG_FLAGS="-DNDEBUG" + fi + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +$as_echo_n "checking for grep that handles long lines and -e... " >&6; } +if ${ac_cv_path_GREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$GREP"; then + ac_path_GREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_GREP" || continue +# Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_GREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_GREP"; then + as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_GREP=$GREP +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +$as_echo "$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +$as_echo_n "checking for egrep... " >&6; } +if ${ac_cv_path_EGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + if test -z "$EGREP"; then + ac_path_EGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_EGREP" || continue +# Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_EGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_EGREP"; then + as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_EGREP=$EGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +$as_echo "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + + + + + + # Check whether --enable-strict was given. +if test "${enable_strict+set}" = set; then : + enableval=$enable_strict; eso_enable_strict=$enableval +else + eso_enable_strict=no +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether strict compiler options should be used" >&5 +$as_echo_n "checking whether strict compiler options should be used... " >&6; } +if ${eso_cv_enable_strict+:} false; then : + $as_echo_n "(cached) " >&6 +else + eso_cv_enable_strict=$eso_enable_strict +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_strict" >&5 +$as_echo "$eso_cv_enable_strict" >&6; } + + + if test x"$eso_cv_enable_strict" = xyes; then + + eso_enable_strict_std_set=no + + if test -n "$CFLAGS"; then + echo $CFLAGS | $EGREP '(\-std=|-ansi)' >/dev/null 2>&1 + if test x"$?" = x0; then + eso_enable_strict_std_set=yes + fi + fi + + if test x"$eso_enable_strict_std_set" = xno; then + + + + flag=`echo std=c99 | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +$as_echo_n "checking whether $CC supports -std=c99... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -std=c99 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -std=c99" + else + : + + fi + + fi + + + + + flag=`echo pedantic | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pedantic" >&5 +$as_echo_n "checking whether $CC supports -pedantic... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -pedantic -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -pedantic -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -pedantic" + else + : + + fi + + + fi + + + + + flag=`echo pthread | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pthread" >&5 +$as_echo_n "checking whether $CC supports -pthread... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -pthread -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -pthread -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -pthread" + else + : + + fi + + + + + flag=`echo std=c99 | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +$as_echo_n "checking whether $CC supports -std=c99... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -std=c99 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -std=c99 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -std=c99" + else + : + + fi + + + + + flag=`echo Wall | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wall" >&5 +$as_echo_n "checking whether $CC supports -Wall... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Wall -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Wall -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="-Wall $CFLAGS" + else + : + + fi + + + + + flag=`echo fvisibility=hidden | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fvisibility=hidden" >&5 +$as_echo_n "checking whether $CC supports -fvisibility=hidden... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -fvisibility=hidden -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -fvisibility=hidden -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="-fvisibility=hidden $CFLAGS" + else + : + + fi + + + + + flag=`echo Werror=implicit-function-declaration | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=implicit-function-declaration" >&5 +$as_echo_n "checking whether $CC supports -Werror=implicit-function-declaration... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=implicit-function-declaration -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=implicit-function-declaration -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="-Werror=implicit-function-declaration $CFLAGS" + else + : + + fi + + + + + flag=`echo Werror=incompatible-pointer-types | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Werror=incompatible-pointer-types" >&5 +$as_echo_n "checking whether $CC supports -Werror=incompatible-pointer-types... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -Werror=incompatible-pointer-types -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -Werror=incompatible-pointer-types -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -Werror=incompatible-pointer-types" + else + : + + fi + + +# simple openmp check, the one in eso.m4 is unnecessarily fragile +# ESO_ENABLE_OPENMP(openmp=no) +#----------------------------- + + + + + # Check whether --enable-openmp was given. +if test "${enable_openmp+set}" = set; then : + enableval=$enable_openmp; eso_enable_openmp=$enableval +else + eso_enable_openmp=yes +fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether openmp compiler options should be used" >&5 +$as_echo_n "checking whether openmp compiler options should be used... " >&6; } +if ${eso_cv_enable_openmp+:} false; then : + $as_echo_n "(cached) " >&6 +else + eso_cv_enable_openmp=$eso_enable_openmp +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_openmp" >&5 +$as_echo "$eso_cv_enable_openmp" >&6; } + + + if test x"$eso_cv_enable_openmp" = xyes; then + + + + flag=`echo fopenmp | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fopenmp" >&5 +$as_echo_n "checking whether $CC supports -fopenmp... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -fopenmp -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -fopenmp -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -fopenmp" + LDFLAGS="$LDFLAGS -fopenmp" + else + : + + fi + + + + + flag=`echo xopenmp | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -xopenmp" >&5 +$as_echo_n "checking whether $CC supports -xopenmp... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -xopenmp -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -xopenmp -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -xopenmp" + LDFLAGS="$LDFLAGS -xopenmp" + else + : + + fi + + fi + + + # Check whether --enable-tsan was given. +if test "${enable_tsan+set}" = set; then : + enableval=$enable_tsan; eso_enable_tsan=$enableval +else + eso_enable_tsan=no +fi + + + if test x"$eso_enable_tsan" = xyes; then + + + + flag=`echo fsanitize=thread | sed 'y%.=/+-%___p_%'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fsanitize=thread" >&5 +$as_echo_n "checking whether $CC supports -fsanitize=thread... " >&6; } +if eval \${eso_cv_prog_cc_$flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + + eval "eso_cv_prog_cc_$flag=no" + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -fsanitize=thread -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -fsanitize=thread -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +fi +eval ac_res=\$eso_cv_prog_cc_$flag + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + CFLAGS="$CFLAGS -fsanitize=thread" + LDFLAGS="$LDFLAGS -fsanitize=thread" + else + : + + fi + + fi + + + + + + # Check whether --enable-standalone was given. +if test "${enable_standalone+set}" = set; then : + enableval=$enable_standalone; eso_enable_standalone=$enableval +else + eso_enable_standalone=no +fi + + + if test x"$eso_enable_standalone" = xyes; then + VLTSW_TRUE= + VLTSW_FALSE='#' +else + VLTSW_TRUE='#' + VLTSW_FALSE= +fi + + + + + + # Extract the first word of "doxygen", so it can be a program name with args. +set dummy doxygen; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_DOXYGEN+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $DOXYGEN in + [\\/]* | ?:[\\/]*) + ac_cv_path_DOXYGEN="$DOXYGEN" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_DOXYGEN="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +DOXYGEN=$ac_cv_path_DOXYGEN +if test -n "$DOXYGEN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DOXYGEN" >&5 +$as_echo "$DOXYGEN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + # Extract the first word of "latex", so it can be a program name with args. +set dummy latex; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_LATEX+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $LATEX in + [\\/]* | ?:[\\/]*) + ac_cv_path_LATEX="$LATEX" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_LATEX="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +LATEX=$ac_cv_path_LATEX +if test -n "$LATEX"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LATEX" >&5 +$as_echo "$LATEX" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + if test -z "${DOXYGEN}"; then + DOXYGEN=":" + fi + + if test -z "${LATEX}"; then + LATEX=":" + fi + + + +# Check whether --enable-static was given. +if test "${enable_static+set}" = set; then : + enableval=$enable_static; p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_static=no +fi + + + + + + + + + +# Check whether --enable-shared was given. +if test "${enable_shared+set}" = set; then : + enableval=$enable_shared; p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_shared=yes +fi + + + + + + + + + + +case `pwd` in + *\ * | *\ *) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; +esac + + + +macro_version='2.4.6' +macro_revision='2.4.6' + + + + + + + + + + + + + +ltmain=$ac_aux_dir/ltmain.sh + +# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\(["`$\\]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\(["`\\]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +$as_echo_n "checking how to print strings... " >&6; } +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "" +} + +case $ECHO in + printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +$as_echo "printf" >&6; } ;; + print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +$as_echo "print -r" >&6; } ;; + *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +$as_echo "cat" >&6; } ;; +esac + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +$as_echo_n "checking for a sed that does not truncate output... " >&6; } +if ${ac_cv_path_SED+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ + for ac_i in 1 2 3 4 5 6 7; do + ac_script="$ac_script$as_nl$ac_script" + done + echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed + { ac_script=; unset ac_script;} + if test -z "$SED"; then + ac_path_SED_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_SED" || continue +# Check for GNU ac_path_SED and select it if it is found. + # Check for GNU $ac_path_SED +case `"$ac_path_SED" --version 2>&1` in +*GNU*) + ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo '' >> "conftest.nl" + "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_SED_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_SED="$ac_path_SED" + ac_path_SED_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_SED_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_SED"; then + as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 + fi +else + ac_cv_path_SED=$SED +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +$as_echo "$ac_cv_path_SED" >&6; } + SED="$ac_cv_path_SED" + rm -f conftest.sed + +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +$as_echo_n "checking for fgrep... " >&6; } +if ${ac_cv_path_FGREP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 + then ac_cv_path_FGREP="$GREP -F" + else + if test -z "$FGREP"; then + ac_path_FGREP_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in fgrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_FGREP" || continue +# Check for GNU ac_path_FGREP and select it if it is found. + # Check for GNU $ac_path_FGREP +case `"$ac_path_FGREP" --version 2>&1` in +*GNU*) + ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; +*) + ac_count=0 + $as_echo_n 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + $as_echo 'FGREP' >> "conftest.nl" + "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + as_fn_arith $ac_count + 1 && ac_count=$as_val + if test $ac_count -gt ${ac_path_FGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_FGREP="$ac_path_FGREP" + ac_path_FGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + $ac_path_FGREP_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_FGREP"; then + as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 + fi +else + ac_cv_path_FGREP=$FGREP +fi + + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +$as_echo "$ac_cv_path_FGREP" >&6; } + FGREP="$ac_cv_path_FGREP" + + +test -z "$GREP" && GREP=grep + + + + + + + + + + + + + + + + + + + +# Check whether --with-gnu-ld was given. +if test "${with_gnu_ld+set}" = set; then : + withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes +else + with_gnu_ld=no +fi + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +$as_echo_n "checking for ld used by $CC... " >&6; } + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [\\/]* | ?:[\\/]*) + re_direlt='/[^/][^/]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +$as_echo_n "checking for GNU ld... " >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +$as_echo_n "checking for non-GNU ld... " >&6; } +fi +if ${lt_cv_path_LD+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &5 +$as_echo "$LD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } +if ${lt_cv_prog_gnu_ld+:} false; then : + $as_echo_n "(cached) " >&6 +else + # I'd rather use --version here, but apparently some GNU lds only accept -v. +case `$LD -v 2>&1 &5 +$as_echo "$lt_cv_prog_gnu_ld" >&6; } +with_gnu_ld=$lt_cv_prog_gnu_ld + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if ${lt_cv_path_NM+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +$as_echo "$lt_cv_path_NM" >&6; } +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + if test -n "$ac_tool_prefix"; then + for ac_prog in dumpbin "link -dump" + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DUMPBIN"; then + ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DUMPBIN=$ac_cv_prog_DUMPBIN +if test -n "$DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +$as_echo "$DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$DUMPBIN" && break + done +fi +if test -z "$DUMPBIN"; then + ac_ct_DUMPBIN=$DUMPBIN + for ac_prog in dumpbin "link -dump" +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DUMPBIN"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN +if test -n "$ac_ct_DUMPBIN"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +$as_echo "$ac_ct_DUMPBIN" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_DUMPBIN" && break +done + + if test "x$ac_ct_DUMPBIN" = x; then + DUMPBIN=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DUMPBIN=$ac_ct_DUMPBIN + fi +fi + + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +$as_echo_n "checking the name lister ($NM) interface... " >&6; } +if ${lt_cv_nm_interface+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&5 + (eval echo "\"\$as_me:$LINENO: output\"" >&5) + cat conftest.out >&5 + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +$as_echo "$lt_cv_nm_interface" >&6; } + +# find the maximum length of command line arguments +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +$as_echo_n "checking the maximum length of command line arguments... " >&6; } +if ${lt_cv_sys_max_cmd_len+:} false; then : + $as_echo_n "(cached) " >&6 +else + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac + +fi + +if test -n "$lt_cv_sys_max_cmd_len"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +$as_echo "$lt_cv_sys_max_cmd_len" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 +$as_echo "none" >&6; } +fi +max_cmd_len=$lt_cv_sys_max_cmd_len + + + + + + +: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} + +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi + + + + + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +$as_echo_n "checking how to convert $build file names to $host format... " >&6; } +if ${lt_cv_to_host_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac + +fi + +to_host_file_cmd=$lt_cv_to_host_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +$as_echo "$lt_cv_to_host_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; } +if ${lt_cv_to_tool_file_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + #assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac + +fi + +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +$as_echo "$lt_cv_to_tool_file_cmd" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +$as_echo_n "checking for $LD option to reload object files... " >&6; } +if ${lt_cv_ld_reload_flag+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_reload_flag='-r' +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +$as_echo "$lt_cv_ld_reload_flag" >&6; } +reload_flag=$lt_cv_ld_reload_flag +case $reload_flag in +"" | " "*) ;; +*) reload_flag=" $reload_flag" ;; +esac +reload_cmds='$LD$reload_flag -o $output$reload_objs' +case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + if test yes != "$GCC"; then + reload_cmds=false + fi + ;; + darwin*) + if test yes = "$GCC"; then + reload_cmds='$LTCC $LTCFLAGS -nostdlib $wl-r -o $output$reload_objs' + else + reload_cmds='$LD$reload_flag -o $output$reload_objs' + fi + ;; +esac + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. +set dummy ${ac_tool_prefix}objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJDUMP"; then + ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJDUMP=$ac_cv_prog_OBJDUMP +if test -n "$OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +$as_echo "$OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OBJDUMP"; then + ac_ct_OBJDUMP=$OBJDUMP + # Extract the first word of "objdump", so it can be a program name with args. +set dummy objdump; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OBJDUMP"; then + ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OBJDUMP="objdump" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP +if test -n "$ac_ct_OBJDUMP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +$as_echo "$ac_ct_OBJDUMP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OBJDUMP" = x; then + OBJDUMP="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OBJDUMP=$ac_ct_OBJDUMP + fi +else + OBJDUMP="$ac_cv_prog_OBJDUMP" +fi + +test -z "$OBJDUMP" && OBJDUMP=objdump + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +$as_echo_n "checking how to recognize dependent libraries... " >&6; } +if ${lt_cv_deplibs_check_method+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[4-9]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[45]*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]' + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[3-9]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +$as_echo "$lt_cv_deplibs_check_method" >&6; } + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + + + + + + + + + + + + + + + + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. +set dummy ${ac_tool_prefix}dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DLLTOOL"; then + ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DLLTOOL=$ac_cv_prog_DLLTOOL +if test -n "$DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +$as_echo "$DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DLLTOOL"; then + ac_ct_DLLTOOL=$DLLTOOL + # Extract the first word of "dlltool", so it can be a program name with args. +set dummy dlltool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DLLTOOL"; then + ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DLLTOOL="dlltool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL +if test -n "$ac_ct_DLLTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +$as_echo "$ac_ct_DLLTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DLLTOOL" = x; then + DLLTOOL="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DLLTOOL=$ac_ct_DLLTOOL + fi +else + DLLTOOL="$ac_cv_prog_DLLTOOL" +fi + +test -z "$DLLTOOL" && DLLTOOL=dlltool + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +$as_echo_n "checking how to associate runtime and link libraries... " >&6; } +if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; } +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + + + + + + + +if test -n "$ac_tool_prefix"; then + for ac_prog in ar + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$AR"; then + ac_cv_prog_AR="$AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_AR="$ac_tool_prefix$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +AR=$ac_cv_prog_AR +if test -n "$AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +$as_echo "$AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$AR" && break + done +fi +if test -z "$AR"; then + ac_ct_AR=$AR + for ac_prog in ar +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_AR"; then + ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_AR="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_AR=$ac_cv_prog_ac_ct_AR +if test -n "$ac_ct_AR"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +$as_echo "$ac_ct_AR" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$ac_ct_AR" && break +done + + if test "x$ac_ct_AR" = x; then + AR="false" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + AR=$ac_ct_AR + fi +fi + +: ${AR=ar} +: ${AR_FLAGS=cru} + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +$as_echo_n "checking for archiver @FILE support... " >&6; } +if ${lt_cv_ar_at_file+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ar_at_file=no + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 + (eval $lt_ar_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +$as_echo "$lt_cv_ar_at_file" >&6; } + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi + + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. +set dummy ${ac_tool_prefix}strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$STRIP"; then + ac_cv_prog_STRIP="$STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_STRIP="${ac_tool_prefix}strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +STRIP=$ac_cv_prog_STRIP +if test -n "$STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +$as_echo "$STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_STRIP"; then + ac_ct_STRIP=$STRIP + # Extract the first word of "strip", so it can be a program name with args. +set dummy strip; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_STRIP+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_STRIP"; then + ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_STRIP="strip" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP +if test -n "$ac_ct_STRIP"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +$as_echo "$ac_ct_STRIP" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_STRIP" = x; then + STRIP=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + STRIP=$ac_ct_STRIP + fi +else + STRIP="$ac_cv_prog_STRIP" +fi + +test -z "$STRIP" && STRIP=: + + + + + + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +$as_echo "$RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +$as_echo "$ac_ct_RANLIB" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +test -z "$RANLIB" && RANLIB=: + + + + + + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + + +# Check for command to grab the raw symbol name followed by C symbol from nm. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } +if ${lt_cv_sys_global_symbol_pipe+:} false; then : + $as_echo_n "(cached) " >&6 +else + +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[BCDEGRST]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([_A-Za-z][_A-Za-z0-9]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[BCDT]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[ABCDGISTW]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[ABCDEGRST]' + fi + ;; +irix* | nonstopux*) + symcode='[BCDEGRST]' + ;; +osf*) + symcode='[BCDEGQRST]' + ;; +solaris*) + symcode='[BDRT]' + ;; +sco3.2v5*) + symcode='[DT]' + ;; +sysv4.2uw2*) + symcode='[DT]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[ABDT]' + ;; +sysv4) + symcode='[DFNSTU]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[ABCDGIRSTW]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK '"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + # Now try to grab the symbols. + nlist=conftest.nm + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&5 + fi + else + echo "cannot find nm_test_var in $nlist" >&5 + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 + fi + else + echo "$progname: failed program was:" >&5 + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done + +fi + +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +$as_echo "failed" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +$as_echo "ok" >&6; } +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +$as_echo_n "checking for sysroot... " >&6; } + +# Check whether --with-sysroot was given. +if test "${with_sysroot+set}" = set; then : + withval=$with_sysroot; +else + with_sysroot=no +fi + + +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +$as_echo "$with_sysroot" >&6; } + as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 + ;; +esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +$as_echo "${lt_sysroot:-no}" >&6; } + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +$as_echo_n "checking for a working dd... " >&6; } +if ${ac_cv_path_lt_DD+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +if test -z "$lt_DD"; then + ac_path_lt_DD_found=false + # Loop through the user's path and test for each of PROGNAME-LIST + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in dd; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_lt_DD="$as_dir/$ac_prog$ac_exec_ext" + as_fn_executable_p "$ac_path_lt_DD" || continue +if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi + $ac_path_lt_DD_found && break 3 + done + done + done +IFS=$as_save_IFS + if test -z "$ac_cv_path_lt_DD"; then + : + fi +else + ac_cv_path_lt_DD=$lt_DD +fi + +rm -f conftest.i conftest2.i conftest.out +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +$as_echo "$ac_cv_path_lt_DD" >&6; } + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +$as_echo_n "checking how to truncate binary pipes... " >&6; } +if ${lt_cv_truncate_bin+:} false; then : + $as_echo_n "(cached) " >&6 +else + printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +$as_echo "$lt_cv_truncate_bin" >&6; } + + + + + + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in $*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + +# Check whether --enable-libtool-lock was given. +if test "${enable_libtool_lock+set}" = set; then : + enableval=$enable_libtool_lock; +fi + +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '#line '$LINENO' "configure"' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +$as_echo_n "checking whether the C compiler needs -belf... " >&6; } +if ${lt_cv_cc_needs_belf+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_cc_needs_belf=yes +else + lt_cv_cc_needs_belf=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +$as_echo "$lt_cv_cc_needs_belf" >&6; } + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. +set dummy ${ac_tool_prefix}mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$MANIFEST_TOOL"; then + ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL +if test -n "$MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +$as_echo "$MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_MANIFEST_TOOL"; then + ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL + # Extract the first word of "mt", so it can be a program name with args. +set dummy mt; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_MANIFEST_TOOL"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL +if test -n "$ac_ct_MANIFEST_TOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +$as_echo "$ac_ct_MANIFEST_TOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_MANIFEST_TOOL" = x; then + MANIFEST_TOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL + fi +else + MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL" +fi + +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if ${lt_cv_path_mainfest_tool+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&5 + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest* +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +$as_echo "$lt_cv_path_mainfest_tool" >&6; } +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi + + + + + + + case $host_os in + rhapsody* | darwin*) + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. +set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$DSYMUTIL"; then + ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +DSYMUTIL=$ac_cv_prog_DSYMUTIL +if test -n "$DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +$as_echo "$DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_DSYMUTIL"; then + ac_ct_DSYMUTIL=$DSYMUTIL + # Extract the first word of "dsymutil", so it can be a program name with args. +set dummy dsymutil; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_DSYMUTIL"; then + ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL +if test -n "$ac_ct_DSYMUTIL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +$as_echo "$ac_ct_DSYMUTIL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_DSYMUTIL" = x; then + DSYMUTIL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + DSYMUTIL=$ac_ct_DSYMUTIL + fi +else + DSYMUTIL="$ac_cv_prog_DSYMUTIL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. +set dummy ${ac_tool_prefix}nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$NMEDIT"; then + ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +NMEDIT=$ac_cv_prog_NMEDIT +if test -n "$NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +$as_echo "$NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_NMEDIT"; then + ac_ct_NMEDIT=$NMEDIT + # Extract the first word of "nmedit", so it can be a program name with args. +set dummy nmedit; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_NMEDIT"; then + ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_NMEDIT="nmedit" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT +if test -n "$ac_ct_NMEDIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +$as_echo "$ac_ct_NMEDIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_NMEDIT" = x; then + NMEDIT=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + NMEDIT=$ac_ct_NMEDIT + fi +else + NMEDIT="$ac_cv_prog_NMEDIT" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. +set dummy ${ac_tool_prefix}lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$LIPO"; then + ac_cv_prog_LIPO="$LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_LIPO="${ac_tool_prefix}lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +LIPO=$ac_cv_prog_LIPO +if test -n "$LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +$as_echo "$LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_LIPO"; then + ac_ct_LIPO=$LIPO + # Extract the first word of "lipo", so it can be a program name with args. +set dummy lipo; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_LIPO+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_LIPO"; then + ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_LIPO="lipo" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO +if test -n "$ac_ct_LIPO"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +$as_echo "$ac_ct_LIPO" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_LIPO" = x; then + LIPO=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + LIPO=$ac_ct_LIPO + fi +else + LIPO="$ac_cv_prog_LIPO" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL"; then + ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL="${ac_tool_prefix}otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL=$ac_cv_prog_OTOOL +if test -n "$OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +$as_echo "$OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL"; then + ac_ct_OTOOL=$OTOOL + # Extract the first word of "otool", so it can be a program name with args. +set dummy otool; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL"; then + ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL="otool" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL +if test -n "$ac_ct_OTOOL"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +$as_echo "$ac_ct_OTOOL" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL" = x; then + OTOOL=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL=$ac_ct_OTOOL + fi +else + OTOOL="$ac_cv_prog_OTOOL" +fi + + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. +set dummy ${ac_tool_prefix}otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OTOOL64"; then + ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OTOOL64=$ac_cv_prog_OTOOL64 +if test -n "$OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +$as_echo "$OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_OTOOL64"; then + ac_ct_OTOOL64=$OTOOL64 + # Extract the first word of "otool64", so it can be a program name with args. +set dummy otool64; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$ac_ct_OTOOL64"; then + ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_OTOOL64="otool64" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 +if test -n "$ac_ct_OTOOL64"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +$as_echo "$ac_ct_OTOOL64" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "x$ac_ct_OTOOL64" = x; then + OTOOL64=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + OTOOL64=$ac_ct_OTOOL64 + fi +else + OTOOL64="$ac_cv_prog_OTOOL64" +fi + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +$as_echo_n "checking for -single_module linker flag... " >&6; } +if ${lt_cv_apple_cc_single_mod+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&5 + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&5 + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +$as_echo "$lt_cv_apple_cc_single_mod" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } +if ${lt_cv_ld_exported_symbols_list+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_ld_exported_symbols_list=yes +else + lt_cv_ld_exported_symbols_list=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +$as_echo_n "checking for -force_load linker flag... " >&6; } +if ${lt_cv_ld_force_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 + echo "$AR cru libconftest.a conftest.o" >&5 + $AR cru libconftest.a conftest.o 2>&5 + echo "$RANLIB libconftest.a" >&5 + $RANLIB libconftest.a 2>&5 + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5 + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&5 + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&5 + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +$as_echo "$lt_cv_ld_force_load" >&6; } + case $host_os in + rhapsody* | darwin1.[012]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[91]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[012][,.]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x$2 in + x) + ;; + *:) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'` \$$1\" + ;; + x:*) + eval $1=\"\$$1 `$ECHO $2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval $1=\"\$$1\ `$ECHO $2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval $1=\"`$ECHO $2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \$$1\" + ;; + *) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'`\" + ;; + esac +} + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do : + as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` +ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +" +if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_header in dlfcn.h +do : + ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default +" +if test "x$ac_cv_header_dlfcn_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_DLFCN_H 1 +_ACEOF + +fi + +done + + + + + +# Set options + + + + enable_dlopen=no + + + enable_win32_dll=no + + + + + +# Check whether --with-pic was given. +if test "${with_pic+set}" = set; then : + withval=$with_pic; lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + pic_mode=default +fi + + + + + + + + + # Check whether --enable-fast-install was given. +if test "${enable_fast_install+set}" = set; then : + enableval=$enable_fast_install; p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else + enable_fast_install=yes +fi + + + + + + + + + shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[5-9]*,yes) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +$as_echo_n "checking which variant of shared library versioning to provide... " >&6; } + +# Check whether --with-aix-soname was given. +if test "${with_aix_soname+set}" = set; then : + withval=$with_aix_soname; case $withval in + aix|svr4|both) + ;; + *) + as_fn_error $? "Unknown argument to --with-aix-soname" "$LINENO" 5 + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname +else + if ${lt_cv_with_aix_soname+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_with_aix_soname=aix +fi + + with_aix_soname=$lt_cv_with_aix_soname +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +$as_echo "$with_aix_soname" >&6; } + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + + + + + + + + + + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +test -z "$LN_S" && LN_S="ln -s" + + + + + + + + + + + + + + +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +$as_echo_n "checking for objdir... " >&6; } +if ${lt_cv_objdir+:} false; then : + $as_echo_n "(cached) " >&6 +else + rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +$as_echo "$lt_cv_objdir" >&6; } +objdir=$lt_cv_objdir + + + + + +cat >>confdefs.h <<_ACEOF +#define LT_OBJDIR "$lt_cv_objdir/" +_ACEOF + + + + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +func_cc_basename $compiler +cc_basename=$func_cc_basename_result + + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/${ac_tool_prefix}file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"${ac_tool_prefix}file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + + + +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +$as_echo_n "checking for file... " >&6; } +if ${lt_cv_path_MAGIC_CMD+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $MAGIC_CMD in +[\\/*] | ?:[\\/]*) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/file"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"file" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac +fi + +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +$as_echo "$MAGIC_CMD" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + else + MAGIC_CMD=: + fi +fi + + fi + ;; +esac + +# Use C for the default configuration in the libtool script + +lt_save_CC=$CC +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +objext=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + + + + + + + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC + +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* + +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* + + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + +lt_prog_compiler_no_builtin_flag= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;; + *) + lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_rtti_exceptions=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="-fno-rtti -fno-exceptions" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_rtti_exceptions=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } + +if test yes = "$lt_cv_prog_compiler_rtti_exceptions"; then + lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" +else + : +fi + +fi + + + + + + + lt_prog_compiler_wl= +lt_prog_compiler_pic= +lt_prog_compiler_static= + + + if test yes = "$GCC"; then + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_static='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + fi + lt_prog_compiler_pic='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + lt_prog_compiler_pic='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + lt_prog_compiler_static= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + ;; + + interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + lt_prog_compiler_can_build_shared=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic=-Kconform_pic + fi + ;; + + *) + lt_prog_compiler_pic='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + lt_prog_compiler_wl='-Xlinker ' + if test -n "$lt_prog_compiler_pic"; then + lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + lt_prog_compiler_wl='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + lt_prog_compiler_static='-Bstatic' + else + lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + lt_prog_compiler_pic='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + lt_prog_compiler_pic='-DDLL_EXPORT' + case $host_os in + os2*) + lt_prog_compiler_static='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + lt_prog_compiler_wl='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + lt_prog_compiler_pic='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + lt_prog_compiler_static='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + lt_prog_compiler_wl='-Wl,' + # PIC (with -KPIC) is the default. + lt_prog_compiler_static='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='--shared' + lt_prog_compiler_static='--static' + ;; + nagfor*) + # NAG Fortran compiler + lt_prog_compiler_wl='-Wl,-Wl,,' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + ccc*) + lt_prog_compiler_wl='-Wl,' + # All Alpha code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-qpic' + lt_prog_compiler_static='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='' + ;; + *Sun\ F* | *Sun*Fortran*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + lt_prog_compiler_wl='-Wl,' + ;; + *Intel*\ [CF]*Compiler*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; + *Portland\ Group*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fpic' + lt_prog_compiler_static='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + lt_prog_compiler_pic='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + lt_prog_compiler_wl='-Wl,' + # All OSF/1 code is PIC. + lt_prog_compiler_static='-non_shared' + ;; + + rdos*) + lt_prog_compiler_static='-non_shared' + ;; + + solaris*) + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + lt_prog_compiler_wl='-Qoption ld ';; + *) + lt_prog_compiler_wl='-Wl,';; + esac + ;; + + sunos4*) + lt_prog_compiler_wl='-Qoption ld ' + lt_prog_compiler_pic='-PIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + lt_prog_compiler_pic='-Kconform_pic' + lt_prog_compiler_static='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-KPIC' + lt_prog_compiler_static='-Bstatic' + ;; + + unicos*) + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_can_build_shared=no + ;; + + uts4*) + lt_prog_compiler_pic='-pic' + lt_prog_compiler_static='-Bstatic' + ;; + + *) + lt_prog_compiler_can_build_shared=no + ;; + esac + fi + +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + lt_prog_compiler_pic= + ;; + *) + lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC" + ;; +esac + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +$as_echo_n "checking for $compiler option to produce PIC... " >&6; } +if ${lt_cv_prog_compiler_pic+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic=$lt_prog_compiler_pic +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +$as_echo "$lt_cv_prog_compiler_pic" >&6; } +lt_prog_compiler_pic=$lt_cv_prog_compiler_pic + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$lt_prog_compiler_pic"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if ${lt_cv_prog_compiler_pic_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_pic_works=no + ac_outfile=conftest.$ac_objext + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$lt_prog_compiler_pic -DPIC" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_pic_works=yes + fi + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_pic_works"; then + case $lt_prog_compiler_pic in + "" | " "*) ;; + *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; + esac +else + lt_prog_compiler_pic= + lt_prog_compiler_can_build_shared=no +fi + +fi + + + + + + + + + + + +# +# Check to make sure the static flag actually works. +# +wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if ${lt_cv_prog_compiler_static_works+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_static_works=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $lt_tmp_static_flag" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler_static_works=yes + fi + else + lt_cv_prog_compiler_static_works=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +$as_echo "$lt_cv_prog_compiler_static_works" >&6; } + +if test yes = "$lt_cv_prog_compiler_static_works"; then + : +else + lt_prog_compiler_static= +fi + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if ${lt_cv_prog_compiler_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler_c_o=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + lt_cv_prog_compiler_c_o=yes + fi + fi + chmod u+w . 2>&5 + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +$as_echo "$lt_cv_prog_compiler_c_o" >&6; } + + + + +hard_links=nottested +if test no = "$lt_cv_prog_compiler_c_o" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +$as_echo_n "checking if we can lock with hard links... " >&6; } + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +$as_echo "$hard_links" >&6; } + if test no = "$hard_links"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + need_locks=warn + fi +else + need_locks=no +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + + runpath_var= + allow_undefined_flag= + always_export_symbols=no + archive_cmds= + archive_expsym_cmds= + compiler_needs_object=no + enable_shared_with_static_runtimes=no + export_dynamic_flag_spec= + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + hardcode_automatic=no + hardcode_direct=no + hardcode_direct_absolute=no + hardcode_libdir_flag_spec= + hardcode_libdir_separator= + hardcode_minus_L=no + hardcode_shlibpath_var=unsupported + inherit_rpath=no + link_all_deplibs=unknown + module_cmds= + module_expsym_cmds= + old_archive_from_new_cmds= + old_archive_from_expsyms_cmds= + thread_safe_flag_spec= + whole_archive_flag_spec= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + include_expsyms= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + esac + + ld_shlibs=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;; + *\ \(GNU\ Binutils\)\ [3-9]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + export_dynamic_flag_spec='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + whole_archive_flag_spec=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + whole_archive_flag_spec= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/(^)\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[3-9]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + allow_undefined_flag=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + ld_shlibs=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, + # as there is no search path for DLLs. + hardcode_libdir_flag_spec='-L$libdir' + export_dynamic_flag_spec='$wl--export-all-symbols' + allow_undefined_flag=unsupported + always_export_symbols=no + enable_shared_with_static_runtimes=yes + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' + exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + ld_shlibs=no + fi + ;; + + haiku*) + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + link_all_deplibs=yes + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + interix[3-9]*) + hardcode_direct=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + whole_archive_flag_spec= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + whole_archive_flag_spec='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + whole_archive_flag_spec='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + compiler_needs_object=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + export_dynamic_flag_spec='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + ld_shlibs=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) + ld_shlibs=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + ;; + + sunos4*) + archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + ld_shlibs=no + fi + ;; + esac + + if test no = "$ld_shlibs"; then + runpath_var= + hardcode_libdir_flag_spec= + export_dynamic_flag_spec= + whole_archive_flag_spec= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + allow_undefined_flag=unsupported + always_export_symbols=yes + archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + hardcode_minus_L=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + hardcode_direct=unsupported + fi + ;; + + aix[4-9]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + archive_cmds='' + hardcode_direct=yes + hardcode_direct_absolute=yes + hardcode_libdir_separator=':' + link_all_deplibs=yes + file_list_spec='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + hardcode_direct=no + hardcode_direct_absolute=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[012]|aix4.[012].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + hardcode_direct=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + hardcode_minus_L=yes + hardcode_libdir_flag_spec='-L$libdir' + hardcode_libdir_separator= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + export_dynamic_flag_spec='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + always_export_symbols=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + allow_undefined_flag='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + hardcode_libdir_flag_spec='$wl-R $libdir:/usr/lib:/lib' + allow_undefined_flag="-z nodefs" + archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + if ${lt_cv_aix_libpath_+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + lt_aix_libpath_sed=' + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }' + lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + if test -z "$lt_cv_aix_libpath_"; then + lt_cv_aix_libpath_=/usr/lib:/lib + fi + +fi + + aix_libpath=$lt_cv_aix_libpath_ +fi + + hardcode_libdir_flag_spec='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + no_undefined_flag=' $wl-bernotok' + allow_undefined_flag=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + whole_archive_flag_spec='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + whole_archive_flag_spec='$convenience' + fi + archive_cmds_need_lc=yes + archive_expsym_cmds='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([, ]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + archive_expsym_cmds="$archive_expsym_cmds"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + archive_expsym_cmds="$archive_expsym_cmds"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + archive_expsym_cmds="$archive_expsym_cmds"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + archive_expsym_cmds='' + ;; + m68k) + archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + ;; + esac + ;; + + bsdi[45]*) + export_dynamic_flag_spec=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + always_export_symbols=yes + file_list_spec='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, )='true' + enable_shared_with_static_runtimes=yes + exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + old_postinstall_cmds='chmod 644 $oldlib' + postlink_cmds='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + hardcode_libdir_flag_spec=' ' + allow_undefined_flag=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + old_archive_from_new_cmds='true' + # FIXME: Should let the user specify the lib program. + old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' + enable_shared_with_static_runtimes=yes + ;; + esac + ;; + + darwin* | rhapsody*) + + + archive_cmds_need_lc=no + hardcode_direct=no + hardcode_automatic=yes + hardcode_shlibpath_var=unsupported + if test yes = "$lt_cv_ld_force_load"; then + whole_archive_flag_spec='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + + else + whole_archive_flag_spec='' + fi + link_all_deplibs=yes + allow_undefined_flag=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + archive_expsym_cmds="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + + else + ld_shlibs=no + fi + + ;; + + dgux*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + hpux9*) + if test yes = "$GCC"; then + archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + export_dynamic_flag_spec='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + archive_cmds='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + archive_cmds='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + archive_cmds='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + archive_cmds='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +$as_echo_n "checking if $CC understands -b... " >&6; } +if ${lt_cv_prog_compiler__b+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_prog_compiler__b=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -b" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&5 + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + lt_cv_prog_compiler__b=yes + fi + else + lt_cv_prog_compiler__b=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +$as_echo "$lt_cv_prog_compiler__b" >&6; } + +if test yes = "$lt_cv_prog_compiler__b"; then + archive_cmds='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' +else + archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' +fi + + ;; + esac + fi + if test no = "$with_gnu_ld"; then + hardcode_libdir_flag_spec='$wl+b $wl$libdir' + hardcode_libdir_separator=: + + case $host_cpu in + hppa*64*|ia64*) + hardcode_direct=no + hardcode_shlibpath_var=no + ;; + *) + hardcode_direct=yes + hardcode_direct_absolute=yes + export_dynamic_flag_spec='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + hardcode_minus_L=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if ${lt_cv_irix_exported_symbol+:} false; then : + $as_echo_n "(cached) " >&6 +else + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int foo (void) { return 0; } +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + lt_cv_irix_exported_symbol=yes +else + lt_cv_irix_exported_symbol=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +$as_echo "$lt_cv_irix_exported_symbol" >&6; } + if test yes = "$lt_cv_irix_exported_symbol"; then + archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + else + archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + inherit_rpath=yes + link_all_deplibs=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + ld_shlibs=yes + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_direct=yes + hardcode_shlibpath_var=no + ;; + + newsos6) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + hardcode_shlibpath_var=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + hardcode_direct=yes + hardcode_shlibpath_var=no + hardcode_direct_absolute=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + export_dynamic_flag_spec='$wl-E' + else + archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + hardcode_libdir_flag_spec='$wl-rpath,$libdir' + fi + else + ld_shlibs=no + fi + ;; + + os2*) + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + allow_undefined_flag=unsupported + shrext_cmds=.dll + archive_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + archive_expsym_cmds='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + enable_shared_with_static_runtimes=yes + ;; + + osf3*) + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + archive_cmds_need_lc='no' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + hardcode_libdir_separator=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + allow_undefined_flag=' $wl-expect_unresolved $wl\*' + archive_cmds='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' + else + allow_undefined_flag=' -expect_unresolved \*' + archive_cmds='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + hardcode_libdir_flag_spec='-rpath $libdir' + fi + archive_cmds_need_lc='no' + hardcode_libdir_separator=: + ;; + + solaris*) + no_undefined_flag=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + archive_cmds='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + archive_cmds='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + archive_cmds='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + hardcode_libdir_flag_spec='-R$libdir' + hardcode_shlibpath_var=no + case $host_os in + solaris2.[0-5] | solaris2.[0-5].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + whole_archive_flag_spec='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + whole_archive_flag_spec='-z allextract$convenience -z defaultextract' + fi + ;; + esac + link_all_deplibs=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + archive_cmds='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + hardcode_libdir_flag_spec='-L$libdir' + hardcode_direct=yes + hardcode_minus_L=yes + hardcode_shlibpath_var=no + ;; + + sysv4) + case $host_vendor in + sni) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' + reload_cmds='$CC -r -o $output$reload_objs' + hardcode_direct=no + ;; + motorola) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_direct=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + hardcode_shlibpath_var=no + ;; + + sysv4.3*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + export_dynamic_flag_spec='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_shlibpath_var=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ld_shlibs=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) + no_undefined_flag='$wl-z,text' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + no_undefined_flag='$wl-z,text' + allow_undefined_flag='$wl-z,nodefs' + archive_cmds_need_lc=no + hardcode_shlibpath_var=no + hardcode_libdir_flag_spec='$wl-R,$libdir' + hardcode_libdir_separator=':' + link_all_deplibs=yes + export_dynamic_flag_spec='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + archive_cmds='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + archive_cmds='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + archive_expsym_cmds='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; + + *) + ld_shlibs=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + export_dynamic_flag_spec='$wl-Blargedynsym' + ;; + esac + fi + fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +$as_echo "$ld_shlibs" >&6; } +test no = "$ld_shlibs" && can_build_shared=no + +with_gnu_ld=$with_gnu_ld + + + + + + + + + + + + + + + +# +# Do we need to explicitly link libc? +# +case "x$archive_cmds_need_lc" in +x|xyes) + # Assume -lc should be added + archive_cmds_need_lc=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $archive_cmds in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } +if ${lt_cv_archive_cmds_need_lc+:} false; then : + $as_echo_n "(cached) " >&6 +else + $RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$lt_prog_compiler_wl + pic_flag=$lt_prog_compiler_pic + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$allow_undefined_flag + allow_undefined_flag= + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 + (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + then + lt_cv_archive_cmds_need_lc=no + else + lt_cv_archive_cmds_need_lc=yes + fi + allow_undefined_flag=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +$as_echo "$lt_cv_archive_cmds_need_lc" >&6; } + archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc + ;; + esac + fi + ;; +esac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +$as_echo_n "checking dynamic linker characteristics... " >&6; } + +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[lt_foo]++; } + if (lt_freq[lt_foo] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([A-Za-z]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + + + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[4-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[01] | aix4.[01].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a(lib.so.V)' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V($shared_archive_member_spec.o), lib.a(lib.so.V)" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a(lib.so.V), lib.so.V($shared_archive_member_spec.o)" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[45]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' + + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[23].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[01]* | freebsdelf3.[01]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ + freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[3-9]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + hardcode_libdir_flag_spec='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + if ${lt_cv_shlibpath_overrides_runpath+:} false; then : + $as_echo_n "(cached) " >&6 +else + lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ + LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : + lt_cv_shlibpath_overrides_runpath=yes +fi +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + +fi + + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Add ABI-specific directories to the system library path. + sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +$as_echo "$dynamic_linker" >&6; } +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +$as_echo_n "checking how to hardcode library paths into programs... " >&6; } +hardcode_action= +if test -n "$hardcode_libdir_flag_spec" || + test -n "$runpath_var" || + test yes = "$hardcode_automatic"; then + + # We can hardcode non-existent directories. + if test no != "$hardcode_direct" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, )" && + test no != "$hardcode_minus_L"; then + # Linking always hardcodes the temporary library directory. + hardcode_action=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + hardcode_action=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + hardcode_action=unsupported +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +$as_echo "$hardcode_action" >&6; } + +if test relink = "$hardcode_action" || + test yes = "$inherit_rpath"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi + + + + + + + if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + +fi + + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" +if test "x$ac_cv_func_shl_load" = xyes; then : + lt_cv_dlopen=shl_load +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +$as_echo_n "checking for shl_load in -ldld... " >&6; } +if ${ac_cv_lib_dld_shl_load+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char shl_load (); +int +main () +{ +return shl_load (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_shl_load=yes +else + ac_cv_lib_dld_shl_load=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +$as_echo "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes; then : + lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld +else + ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" +if test "x$ac_cv_func_dlopen" = xyes; then : + lt_cv_dlopen=dlopen +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +$as_echo_n "checking for dlopen in -ldl... " >&6; } +if ${ac_cv_lib_dl_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldl $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dl_dlopen=yes +else + ac_cv_lib_dl_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +$as_echo "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +$as_echo_n "checking for dlopen in -lsvld... " >&6; } +if ${ac_cv_lib_svld_dlopen+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lsvld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dlopen (); +int +main () +{ +return dlopen (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_svld_dlopen=yes +else + ac_cv_lib_svld_dlopen=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +$as_echo "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes; then : + lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +$as_echo_n "checking for dld_link in -ldld... " >&6; } +if ${ac_cv_lib_dld_dld_link+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-ldld $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char dld_link (); +int +main () +{ +return dld_link (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_dld_dld_link=yes +else + ac_cv_lib_dld_dld_link=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +$as_echo "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes; then : + lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld +fi + + +fi + + +fi + + +fi + + +fi + + +fi + + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +$as_echo_n "checking whether a program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +$as_echo "$lt_cv_dlopen_self" >&6; } + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } +if ${lt_cv_dlopen_self_static+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test yes = "$cross_compiling"; then : + lt_cv_dlopen_self_static=cross +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +} +_LT_EOF + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 + (eval $ac_link) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&5 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; + x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; + esac + else : + # compilation failed + lt_cv_dlopen_self_static=no + fi +fi +rm -fr conftest* + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +$as_echo "$lt_cv_dlopen_self_static" >&6; } + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi + + + + + + + + + + + + + + + + + +striplib= +old_striplib= +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +$as_echo_n "checking whether stripping libraries is possible... " >&6; } +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + ;; + esac +fi + + + + + + + + + + + + + # Report what library types will actually be built + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +$as_echo_n "checking if libtool supports shared libraries... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +$as_echo "$can_build_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +$as_echo_n "checking whether to build shared libraries... " >&6; } + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[4-9]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +$as_echo "$enable_shared" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +$as_echo_n "checking whether to build static libraries... " >&6; } + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +$as_echo "$enable_static" >&6; } + + + + +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +CC=$lt_save_CC + + + + + + + + + + + + + + + + ac_config_commands="$ac_config_commands libtool" + + + + +# Only expand once: + + + + +# Checks for header files. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 +$as_echo_n "checking for ANSI C header files... " >&6; } +if ${ac_cv_header_stdc+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_header_stdc=yes +else + ac_cv_header_stdc=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then : + +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then : + : +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + +fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 +$as_echo "$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +$as_echo "#define STDC_HEADERS 1" >>confdefs.h + +fi + +for ac_header in string.h +do : + ac_fn_c_check_header_mongrel "$LINENO" "string.h" "ac_cv_header_string_h" "$ac_includes_default" +if test "x$ac_cv_header_string_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_STRING_H 1 +_ACEOF + +fi + +done + + +# Checks for typedefs, structures, and compiler characteristics. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +$as_echo_n "checking for an ANSI C-conforming const... " >&6; } +if ${ac_cv_c_const+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifndef __cplusplus + /* Ultrix mips cc rejects this sort of thing. */ + typedef int charset[2]; + const charset cs = { 0, 0 }; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *pcpcc; + char **ppc; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + pcpcc = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++pcpcc; + ppc = (char**) pcpcc; + pcpcc = (char const *const *) ppc; + { /* SCO 3.2v4 cc rejects this sort of thing. */ + char tx; + char *t = &tx; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; } bx; + struct s *b = &bx; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !cs[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_const=yes +else + ac_cv_c_const=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +$as_echo "$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +$as_echo "#define const /**/" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +$as_echo_n "checking for inline... " >&6; } +if ${ac_cv_c_inline+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#ifndef __cplusplus +typedef int foo_t; +static $ac_kw foo_t static_foo () {return 0; } +$ac_kw foo_t foo () {return 0; } +#endif + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_c_inline=$ac_kw +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test "$ac_cv_c_inline" != no && break +done + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +$as_echo "$ac_cv_c_inline" >&6; } + +case $ac_cv_c_inline in + inline | yes) ;; + *) + case $ac_cv_c_inline in + no) ac_val=;; + *) ac_val=$ac_cv_c_inline;; + esac + cat >>confdefs.h <<_ACEOF +#ifndef __cplusplus +#define inline $ac_val +#endif +_ACEOF + ;; +esac + + +# Checks for library functions. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqrt in -lm" >&5 +$as_echo_n "checking for sqrt in -lm... " >&6; } +if ${ac_cv_lib_m_sqrt+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char sqrt (); +int +main () +{ +return sqrt (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_m_sqrt=yes +else + ac_cv_lib_m_sqrt=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_sqrt" >&5 +$as_echo "$ac_cv_lib_m_sqrt" >&6; } +if test "x$ac_cv_lib_m_sqrt" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBM 1 +_ACEOF + + LIBS="-lm $LIBS" + +fi + +for ac_func in floor pow sqrt +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + + + + + + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + ac_fn_c_check_decl "$LINENO" "strdup" "ac_cv_have_decl_strdup" "#include +" +if test "x$ac_cv_have_decl_strdup" = xyes; then : + +fi + + + eso_save_CFLAGS="$CFLAGS" + + if test x"$GCC" = xyes; then + CFLAGS="$CFLAGS -pedantic-errors" + fi + + ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup" +if test "x$ac_cv_func_strdup" = xyes; then : + +fi + + + CFLAGS="$eso_save_CFLAGS" + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + if test x"$ac_cv_have_decl_strdup" = xyes && + test x"$ac_cv_func_strdup" = xyes; then + $as_echo "#define HAVE_STRDUP 1" >>confdefs.h + + fi + + + + + + +# Check for CPL presence and usability + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CPL" >&5 +$as_echo_n "checking for CPL... " >&6; } + + # assumes if one is there all are there as there is no way to do a partial + # install with cpl + cpl_check_cpl_lib="-lcplcore" + + cpl_includes="" + cpl_ldflags="" + + +# Check whether --with-cpl was given. +if test "${with_cpl+set}" = set; then : + withval=$with_cpl; + cpl_with_cpl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + cpl_with_cpl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + +fi + + + +# Check whether --with-cpl-includes was given. +if test "${with_cpl_includes+set}" = set; then : + withval=$with_cpl_includes; cpl_with_cpl_includes=$withval +fi + + + +# Check whether --with-cpl-libs was given. +if test "${with_cpl_libs+set}" = set; then : + withval=$with_cpl_libs; cpl_with_cpl_libs=-L$withval +fi + + + # Check whether --enable-cpl-test was given. +if test "${enable_cpl_test+set}" = set; then : + enableval=$enable_cpl_test; cpl_enable_cpl_test=$enableval +else + cpl_enable_cpl_test=yes +fi + + + + if test "x$cpl_enable_cpl_test" = xyes; then + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking checking for cpl" >&5 +$as_echo_n "checking checking for cpl... " >&6; } + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$cpl_with_cpl_libs"; then + LDFLAGS="$cpl_with_cpl_libs" + elif test -n "$CPLDIR"; then + LDFLAGS="-L$CPLDIR/lib -L$CPLDIR/lib64 -L$CPLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$cpl_with_cpl_includes"; then + CFLAGS="-I$cpl_with_cpl_includes" + elif test -n "$CPLDIR"; then + CFLAGS="-I$CPLDIR/include" + else + CFLAGS="" + fi + LIBS=$cpl_check_cpl_lib + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +cpl_init(0); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + cpl_includes=$CFLAGS + cpl_ldflags=$LDFLAGS + +else + + as_fn_error $? "CPL not found" "$LINENO" 5 + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + # Set up the symbols + + CPL_INCLUDES="$cpl_includes" + CPL_LDFLAGS="$cpl_ldflags" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + LIBCPLCORE='-lcplcore' + LIBCPLDRS='-lcpldrs' + LIBCPLUI='-lcplui' + LIBCPLDFS='-lcpldfs' + LIBCEXT='-lcext' + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 +$as_echo "disabled" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: CPL checks have been disabled! This package may not build!" >&5 +$as_echo "$as_me: WARNING: CPL checks have been disabled! This package may not build!" >&2;} + CPL_INCLUDES="" + CPL_LDFLAGS="" + LIBCPLCORE="" + LIBCPLDRS="" + LIBCPLUI="" + LIBCPLDFS="" + LIBCEXT="" + fi + + + + + + + + + + +# Check for GSL + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSL" >&5 +$as_echo_n "checking for GSL... " >&6; } + + gsl_check_gsl_lib="-lgsl -lgslcblas" + + gsl_includes="" + gsl_libraries="" + + +# Check whether --with-gsl was given. +if test "${with_gsl+set}" = set; then : + withval=$with_gsl; + gsl_with_gsl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + gsl_with_gsl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + +fi + + + +# Check whether --with-gsl-includes was given. +if test "${with_gsl_includes+set}" = set; then : + withval=$with_gsl_includes; gsl_with_gsl_includes=$withval +fi + + + +# Check whether --with-gsl-libs was given. +if test "${with_gsl_libs+set}" = set; then : + withval=$with_gsl_libs; gsl_with_gsl_libs=-L$withval +fi + + + # Check whether --enable-gsl-test was given. +if test "${enable_gsl_test+set}" = set; then : + enableval=$enable_gsl_test; gsl_enable_gsl_test=$enableval +else + gsl_enable_gsl_test=yes +fi + + + + if test "x$gsl_enable_gsl_test" = xyes; then + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$gsl_with_gsl_libs"; then + LDFLAGS="$gsl_with_gsl_libs" + elif test -n "$GSLDIR"; then + LDFLAGS="-L$GSLDIR/lib -L$GSLDIR/lib64 -L$GSLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$gsl_with_gsl_includes"; then + CFLAGS="-I$gsl_with_gsl_includes" + elif test -n "$GSLDIR"; then + CFLAGS="-I$GSLDIR/include" + else + CFLAGS="" + fi + LIBS=$gsl_check_gsl_lib + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +gsl_sf_bessel_J0(5.); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_GSL 1" >>confdefs.h + + +$as_echo "#define HAVE_LIBGSL 1" >>confdefs.h + + # Set up the symbols + GSL_INCLUDES="$CFLAGS" + GSL_LDFLAGS="$LDFLAGS" + GSL_LIBS="$gsl_check_gsl_lib" + +else + + if test "x" = xoptional; then + { $as_echo "$as_me:${as_lineno-$LINENO}: Optional GSL not found" >&5 +$as_echo "$as_me: Optional GSL not found" >&6;} + else + as_fn_error $? "GSL not found" "$LINENO" 5 + fi + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 +$as_echo "disabled" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: GSL checks have been disabled! This package may not build!" >&5 +$as_echo "$as_me: WARNING: GSL checks have been disabled! This package may not build!" >&2;} + GSL_INCLUDES="" + GSL_LDFLAGS="" + GSL_LIBS="" + fi + + + + + + + + + + + # Symbols for package include file and library search paths + + HDRL_INCLUDES='-I$(top_srcdir)' + HDRL_LDFLAGS='-L$(top_builddir)' + + # Library aliases + + LIBHDRL='$(top_builddir)/libhdrl.la' + + # Substitute the defined symbols + + + + + + + + # Check for CPL and user defined libraries + + + all_includes='$(HDRL_INCLUDES) $(CPL_INCLUDES)' + all_ldflags='$(HDRL_LDFLAGS) $(CPL_LDFLAGS)' + + + + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if malloc debugging is wanted" >&5 +$as_echo_n "checking if malloc debugging is wanted... " >&6; } + +# Check whether --with-dmalloc was given. +if test "${with_dmalloc+set}" = set; then : + withval=$with_dmalloc; if test "$withval" = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define WITH_DMALLOC 1" >>confdefs.h + + LIBS="$LIBS -ldmalloc" + LDFLAGS="$LDFLAGS -g" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + +#AC_CONFIG_SUBDIRS(external/fftw external/sextractor external/swarp) +#AC_CONFIG_SUBDIRS(external/sextractor external/swarp) + +ac_config_files="$ac_config_files Makefile tests/Makefile catalogue/Makefile catalogue/tests/Makefile" + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( + *) { eval $ac_var=; unset $ac_var;} ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes: double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \. + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + if test "x$cache_file" != "x/dev/null"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +$as_echo "$as_me: updating cache $cache_file" >&6;} + if test ! -f "$cache_file" || test -h "$cache_file"; then + cat confcache >"$cache_file" + else + case $cache_file in #( + */* | ?:*) + mv -f confcache "$cache_file"$$ && + mv -f "$cache_file"$$ "$cache_file" ;; #( + *) + mv -f confcache "$cache_file" ;; + esac + fi + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +U= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" + as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +$as_echo_n "checking that generated files are newer than configure... " >&6; } + if test -n "$am_sleep_pid"; then + # Hide warnings about reused PIDs. + wait $am_sleep_pid 2>/dev/null + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 +$as_echo "done" >&6; } + if test -n "$EXEEXT"; then + am__EXEEXT_TRUE= + am__EXEEXT_FALSE='#' +else + am__EXEEXT_TRUE='#' + am__EXEEXT_FALSE= +fi + +if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then + as_fn_error $? "conditional \"AMDEP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then + as_fn_error $? "conditional \"am__fastdepCC\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${VLTSW_TRUE}" && test -z "${VLTSW_FALSE}"; then + as_fn_error $? "conditional \"VLTSW\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi + +: "${CONFIG_STATUS=./config.status}" +ac_write_fail=0 +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +as_write_fail=0 +cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false + +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 +## -------------------- ## +## M4sh Initialization. ## +## -------------------- ## + +# Be more Bourne compatible +DUALCASE=1; export DUALCASE # for MKS sh +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : + emulate sh + NULLCMD=: + # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in #( + *posix*) : + set -o posix ;; #( + *) : + ;; +esac +fi + + +as_nl=' +' +export as_nl +# Printing a long string crashes Solaris 7 /usr/bin/printf. +as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo +as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo +# Prefer a ksh shell builtin over an external printf program on Solaris, +# but without wasting forks for bash or zsh. +if test -z "$BASH_VERSION$ZSH_VERSION" \ + && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='print -r --' + as_echo_n='print -rn --' +elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then + as_echo='printf %s\n' + as_echo_n='printf %s' +else + if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then + as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' + as_echo_n='/usr/ucb/echo -n' + else + as_echo_body='eval expr "X$1" : "X\\(.*\\)"' + as_echo_n_body='eval + arg=$1; + case $arg in #( + *"$as_nl"*) + expr "X$arg" : "X\\(.*\\)$as_nl"; + arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; + esac; + expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" + ' + export as_echo_n_body + as_echo_n='sh -c $as_echo_n_body as_echo' + fi + export as_echo_body + as_echo='sh -c $as_echo_body as_echo' +fi + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + PATH_SEPARATOR=: + (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { + (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || + PATH_SEPARATOR=';' + } +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +as_myself= +case $0 in #(( + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + exit 1 +fi + +# Unset variables that we do not need and which cause bugs (e.g. in +# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" +# suppresses any "Segmentation fault" message there. '((' could +# trigger a bug in pdksh 5.2.14. +for as_var in BASH_ENV ENV MAIL MAILPATH +do eval test x\${$as_var+set} = xset \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# CDPATH. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + + +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- +# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are +# provided, also output the error to LOG_FD, referencing LINENO. Then exit the +# script with STATUS, using 1 if that was 0. +as_fn_error () +{ + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + fi + $as_echo "$as_me: error: $2" >&2 + as_fn_exit $as_status +} # as_fn_error + + +# as_fn_set_status STATUS +# ----------------------- +# Set $? to STATUS, without forking. +as_fn_set_status () +{ + return $1 +} # as_fn_set_status + +# as_fn_exit STATUS +# ----------------- +# Exit the shell with STATUS, even in a "trap 0" or "set -e" context. +as_fn_exit () +{ + set +e + as_fn_set_status $1 + exit $1 +} # as_fn_exit + +# as_fn_unset VAR +# --------------- +# Portably unset VAR. +as_fn_unset () +{ + { eval $1=; unset $1;} +} +as_unset=as_fn_unset +# as_fn_append VAR VALUE +# ---------------------- +# Append the text in VALUE to the end of the definition contained in VAR. Take +# advantage of any shell optimizations that allow amortized linear growth over +# repeated appends, instead of the typical quadratic growth present in naive +# implementations. +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : + eval 'as_fn_append () + { + eval $1+=\$2 + }' +else + as_fn_append () + { + eval $1=\$$1\$2 + } +fi # as_fn_append + +# as_fn_arith ARG... +# ------------------ +# Perform arithmetic evaluation on the ARGs, and store the result in the +# global $as_val. Take advantage of shells that can avoid forks. The arguments +# must be portable across $(()) and expr. +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : + eval 'as_fn_arith () + { + as_val=$(( $* )) + }' +else + as_fn_arith () + { + as_val=`expr "$@" || test $? -eq 1` + } +fi # as_fn_arith + + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in #((((( +-n*) + case `echo 'xy\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + xy) ECHO_C='\c';; + *) echo `echo ksh88 bug on AIX 6.1` > /dev/null + ECHO_T=' ';; + esac;; +*) + ECHO_N='-n';; +esac + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir 2>/dev/null +fi +if (echo >conf$$.file) 2>/dev/null; then + if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -pR'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -pR' + elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln + else + as_ln_s='cp -pR' + fi +else + as_ln_s='cp -pR' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + + +# as_fn_mkdir_p +# ------------- +# Create "$as_dir" as a directory, including parents if necessary. +as_fn_mkdir_p () +{ + + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || eval $as_mkdir_p || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" + + +} # as_fn_mkdir_p +if mkdir -p . 2>/dev/null; then + as_mkdir_p='mkdir -p "$as_dir"' +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p +as_test_x='test -x' +as_executable_p=as_fn_executable_p + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 +## ----------------------------------- ## +## Main body of $CONFIG_STATUS script. ## +## ----------------------------------- ## +_ASEOF +test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# Save the log message, to keep $0 and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by HDRL Pipeline $as_me 1.1.0b3, which was +generated by GNU Autoconf 2.69. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +case $ac_config_files in *" +"*) set x $ac_config_files; shift; ac_config_files=$*;; +esac + +case $ac_config_headers in *" +"*) set x $ac_config_headers; shift; ac_config_headers=$*;; +esac + + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" +config_commands="$ac_config_commands" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +ac_cs_usage="\ +\`$as_me' instantiates files and other configuration actions +from templates according to the current configuration. Unless the files +and actions are specified as TAGs, all are instantiated by default. + +Usage: $0 [OPTION]... [TAG]... + + -h, --help print this help, then exit + -V, --version print version number and configuration settings, then exit + --config print configuration, then exit + -q, --quiet, --silent + do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Configuration commands: +$config_commands + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_version="\\ +HDRL Pipeline config.status 1.1.0b3 +configured by $0, generated by GNU Autoconf 2.69, + with options \\"\$ac_cs_config\\" + +Copyright (C) 2012 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +MKDIR_P='$MKDIR_P' +AWK='$AWK' +test -n "\$AWK" || AWK=awk +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# The default lists apply if the user does not specify any file. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=?*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + --*=) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg= + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + $as_echo "$ac_cs_version"; exit ;; + --config | --confi | --conf | --con | --co | --c ) + $as_echo "$ac_cs_config"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + '') as_fn_error $? "missing file argument" ;; + esac + as_fn_append CONFIG_FILES " '$ac_optarg'" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + case $ac_optarg in + *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append CONFIG_HEADERS " '$ac_optarg'" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + as_fn_error $? "ambiguous option: \`$1' +Try \`$0 --help' for more information.";; + --help | --hel | -h ) + $as_echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) as_fn_error $? "unrecognized option: \`$1' +Try \`$0 --help' for more information." ;; + + *) as_fn_append ac_config_targets " $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +if \$ac_cs_recheck; then + set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion + shift + \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + CONFIG_SHELL='$SHELL' + export CONFIG_SHELL + exec "\$@" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + $as_echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +# +# INIT-COMMANDS +# +AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" + + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`' +enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`' +macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`' +macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`' +pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`' +enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`' +shared_archive_member_spec='`$ECHO "$shared_archive_member_spec" | $SED "$delay_single_quote_subst"`' +SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`' +ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`' +PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`' +host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`' +host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`' +host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`' +build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`' +build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`' +build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`' +SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`' +Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`' +GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`' +EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`' +FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`' +LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`' +NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`' +LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`' +max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`' +ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`' +exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`' +lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`' +lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`' +lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`' +lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`' +lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`' +reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`' +reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`' +OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`' +deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`' +file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`' +file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' +want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' +DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`' +sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' +AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' +AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' +archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' +STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' +RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`' +old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`' +old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`' +lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`' +CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`' +CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`' +compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`' +GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_import='`$ECHO "$lt_cv_sys_global_symbol_to_import" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`' +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`' +lt_cv_nm_interface='`$ECHO "$lt_cv_nm_interface" | $SED "$delay_single_quote_subst"`' +nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`' +lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`' +lt_cv_truncate_bin='`$ECHO "$lt_cv_truncate_bin" | $SED "$delay_single_quote_subst"`' +objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`' +MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`' +lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`' +lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`' +need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`' +MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`' +DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`' +NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`' +LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`' +OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`' +OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`' +libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`' +shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`' +extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`' +enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`' +export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`' +whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`' +compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`' +old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`' +old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`' +archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`' +archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`' +module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`' +module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`' +with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`' +allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`' +no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`' +hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`' +hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`' +hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`' +hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`' +hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`' +hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`' +inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`' +link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`' +always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`' +export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`' +exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`' +include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`' +prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`' +postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`' +file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`' +variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`' +need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`' +need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`' +version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`' +runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`' +shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`' +libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`' +library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`' +soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`' +install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`' +postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`' +postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`' +finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`' +finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`' +hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`' +sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`' +configure_time_dlsearch_path='`$ECHO "$configure_time_dlsearch_path" | $SED "$delay_single_quote_subst"`' +configure_time_lt_sys_library_path='`$ECHO "$configure_time_lt_sys_library_path" | $SED "$delay_single_quote_subst"`' +hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`' +enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`' +enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`' +old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`' +striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`' + +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in SHELL \ +ECHO \ +PATH_SEPARATOR \ +SED \ +GREP \ +EGREP \ +FGREP \ +LD \ +NM \ +LN_S \ +lt_SP2NL \ +lt_NL2SP \ +reload_flag \ +OBJDUMP \ +deplibs_check_method \ +file_magic_cmd \ +file_magic_glob \ +want_nocaseglob \ +DLLTOOL \ +sharedlib_from_linklib_cmd \ +AR \ +AR_FLAGS \ +archiver_list_spec \ +STRIP \ +RANLIB \ +CC \ +CFLAGS \ +compiler \ +lt_cv_sys_global_symbol_pipe \ +lt_cv_sys_global_symbol_to_cdecl \ +lt_cv_sys_global_symbol_to_import \ +lt_cv_sys_global_symbol_to_c_name_address \ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ +lt_cv_nm_interface \ +nm_file_list_spec \ +lt_cv_truncate_bin \ +lt_prog_compiler_no_builtin_flag \ +lt_prog_compiler_pic \ +lt_prog_compiler_wl \ +lt_prog_compiler_static \ +lt_cv_prog_compiler_c_o \ +need_locks \ +MANIFEST_TOOL \ +DSYMUTIL \ +NMEDIT \ +LIPO \ +OTOOL \ +OTOOL64 \ +shrext_cmds \ +export_dynamic_flag_spec \ +whole_archive_flag_spec \ +compiler_needs_object \ +with_gnu_ld \ +allow_undefined_flag \ +no_undefined_flag \ +hardcode_libdir_flag_spec \ +hardcode_libdir_separator \ +exclude_expsyms \ +include_expsyms \ +file_list_spec \ +variables_saved_for_relink \ +libname_spec \ +library_names_spec \ +soname_spec \ +install_override_mode \ +finish_eval \ +old_striplib \ +striplib; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in reload_cmds \ +old_postinstall_cmds \ +old_postuninstall_cmds \ +old_archive_cmds \ +extract_expsyms_cmds \ +old_archive_from_new_cmds \ +old_archive_from_expsyms_cmds \ +archive_cmds \ +archive_expsym_cmds \ +module_cmds \ +module_expsym_cmds \ +export_symbols_cmds \ +prelink_cmds \ +postlink_cmds \ +postinstall_cmds \ +postuninstall_cmds \ +finish_cmds \ +sys_lib_search_path_spec \ +configure_time_dlsearch_path \ +configure_time_lt_sys_library_path; do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[\\\\\\\`\\"\\\$]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +ac_aux_dir='$ac_aux_dir' + +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + + + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile' + + + + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; + "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "tests/Makefile") CONFIG_FILES="$CONFIG_FILES tests/Makefile" ;; + "catalogue/Makefile") CONFIG_FILES="$CONFIG_FILES catalogue/Makefile" ;; + "catalogue/tests/Makefile") CONFIG_FILES="$CONFIG_FILES catalogue/tests/Makefile" ;; + + *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers + test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= ac_tmp= + trap 'exit_status=$? + : "${ac_tmp:=$tmp}" + { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status +' 0 + trap 'as_fn_exit 1' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 +ac_tmp=$tmp + +# Set up the scripts for CONFIG_FILES section. +# No need to generate them if there are no CONFIG_FILES. +# This happens for instance with `./config.status config.h'. +if test -n "$CONFIG_FILES"; then + + +ac_cr=`echo X | tr X '\015'` +# On cygwin, bash can eat \r inside `` if the user requested igncr. +# But we know of no other shell where ac_cr would be empty at this +# point, so we can use a bashism as a fallback. +if test "x$ac_cr" = x; then + eval ac_cr=\$\'\\r\' +fi +ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` +if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then + ac_cs_awk_cr='\\r' +else + ac_cs_awk_cr=$ac_cr +fi + +echo 'BEGIN {' >"$ac_tmp/subs1.awk" && +_ACEOF + + +{ + echo "cat >conf$$subs.awk <<_ACEOF" && + echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && + echo "_ACEOF" +} >conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + . ./conf$$subs.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + + ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` + if test $ac_delim_n = $ac_delim_num; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done +rm -f conf$$subs.sh + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && +_ACEOF +sed -n ' +h +s/^/S["/; s/!.*/"]=/ +p +g +s/^[^!]*!// +:repl +t repl +s/'"$ac_delim"'$// +t delim +:nl +h +s/\(.\{148\}\)..*/\1/ +t more1 +s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ +p +n +b repl +:more1 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t nl +:delim +h +s/\(.\{148\}\)..*/\1/ +t more2 +s/["\\]/\\&/g; s/^/"/; s/$/"/ +p +b +:more2 +s/["\\]/\\&/g; s/^/"/; s/$/"\\/ +p +g +s/.\{148\}// +t delim +' >$CONFIG_STATUS || ac_write_fail=1 +rm -f conf$$subs.awk +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +_ACAWK +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && + for (key in S) S_is_set[key] = 1 + FS = "" + +} +{ + line = $ 0 + nfields = split(line, field, "@") + substed = 0 + len = length(field[1]) + for (i = 2; i < nfields; i++) { + key = field[i] + keylen = length(key) + if (S_is_set[key]) { + value = S[key] + line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) + len += length(value) + length(field[++i]) + substed = 1 + } else + len += 1 + keylen + } + + print line +} + +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then + sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" +else + cat +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ + || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 +_ACEOF + +# VPATH may cause trouble with some makes, so we remove sole $(srcdir), +# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ +h +s/// +s/^/:/ +s/[ ]*$/:/ +s/:\$(srcdir):/:/g +s/:\${srcdir}:/:/g +s/:@srcdir@:/:/g +s/^:*// +s/:*$// +x +s/\(=[ ]*\).*/\1/ +G +s/\n// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +fi # test -n "$CONFIG_FILES" + +# Set up the scripts for CONFIG_HEADERS section. +# No need to generate them if there are no CONFIG_HEADERS. +# This happens for instance with `./config.status Makefile'. +if test -n "$CONFIG_HEADERS"; then +cat >"$ac_tmp/defines.awk" <<\_ACAWK || +BEGIN { +_ACEOF + +# Transform confdefs.h into an awk script `defines.awk', embedded as +# here-document in config.status, that substitutes the proper values into +# config.h.in to produce config.h. + +# Create a delimiter string that does not exist in confdefs.h, to ease +# handling of long lines. +ac_delim='%!_!# ' +for ac_last_try in false false :; do + ac_tt=`sed -n "/$ac_delim/p" confdefs.h` + if test -z "$ac_tt"; then + break + elif $ac_last_try; then + as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5 + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +# For the awk script, D is an array of macro values keyed by name, +# likewise P contains macro parameters if any. Preserve backslash +# newline sequences. + +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +sed -n ' +s/.\{148\}/&'"$ac_delim"'/g +t rset +:rset +s/^[ ]*#[ ]*define[ ][ ]*/ / +t def +d +:def +s/\\$// +t bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3"/p +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p +d +:bsnl +s/["\\]/\\&/g +s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ +D["\1"]=" \3\\\\\\n"\\/p +t cont +s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p +t cont +d +:cont +n +s/.\{148\}/&'"$ac_delim"'/g +t clear +:clear +s/\\$// +t bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/"/p +d +:bsnlc +s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p +b cont +' >$CONFIG_STATUS || ac_write_fail=1 + +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + for (key in D) D_is_set[key] = 1 + FS = "" +} +/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { + line = \$ 0 + split(line, arg, " ") + if (arg[1] == "#") { + defundef = arg[2] + mac1 = arg[3] + } else { + defundef = substr(arg[1], 2) + mac1 = arg[2] + } + split(mac1, mac2, "(") #) + macro = mac2[1] + prefix = substr(line, 1, index(line, defundef) - 1) + if (D_is_set[macro]) { + # Preserve the white space surrounding the "#". + print prefix "define", macro P[macro] D[macro] + next + } else { + # Replace #undef with comments. This is necessary, for example, + # in the case of _POSIX_SOURCE, which is predefined and required + # on some systems where configure will not decide to define it. + if (defundef == "undef") { + print "/*", prefix defundef, macro, "*/" + next + } + } +} +{ print } +_ACAWK +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 + as_fn_error $? "could not setup config headers machinery" "$LINENO" 5 +fi # test -n "$CONFIG_HEADERS" + + +eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" +shift +for ac_tag +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$ac_tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; + esac + case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + as_fn_append ac_file_inputs " '$ac_f'" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input='Generated from '` + $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + `' by configure.' + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +$as_echo "$as_me: creating $ac_file" >&6;} + fi + # Neutralize special characters interpreted by sed in replacement strings. + case $configure_input in #( + *\&* | *\|* | *\\* ) + ac_sed_conf_input=`$as_echo "$configure_input" | + sed 's/[\\\\&|]/\\\\&/g'`;; #( + *) ac_sed_conf_input=$configure_input;; + esac + + case $ac_tag in + *:-:* | *:-) cat >"$ac_tmp/stdin" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac + ac_MKDIR_P=$MKDIR_P + case $MKDIR_P in + [\\/$]* | ?:[\\/]* ) ;; + */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= +ac_sed_dataroot=' +/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p' +case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 +ac_sed_extra="$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s|@configure_input@|$ac_sed_conf_input|;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@top_build_prefix@&$ac_top_build_prefix&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +s&@MKDIR_P@&$ac_MKDIR_P&;t t +$ac_datarootdir_hack +" +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ + >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ + "$ac_tmp/out"`; test -z "$ac_out"; } && + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&5 +$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined" >&2;} + + rm -f "$ac_tmp/stdin" + case $ac_file in + -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; + *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; + esac \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + ;; + :H) + # + # CONFIG_HEADER + # + if test x"$ac_file" != x-; then + { + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" + } >"$ac_tmp/config.h" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then + { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +$as_echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f "$ac_file" + mv "$ac_tmp/config.h" "$ac_file" \ + || as_fn_error $? "could not create $ac_file" "$LINENO" 5 + fi + else + $as_echo "/* $configure_input */" \ + && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ + || as_fn_error $? "could not create -" "$LINENO" 5 + fi +# Compute "$ac_file"'s index in $config_headers. +_am_arg="$ac_file" +_am_stamp_count=1 +for _am_header in $config_headers :; do + case $_am_header in + $_am_arg | $_am_arg:* ) + break ;; + * ) + _am_stamp_count=`expr $_am_stamp_count + 1` ;; + esac +done +echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" || +$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$_am_arg" : 'X\(//\)[^/]' \| \ + X"$_am_arg" : 'X\(//\)$' \| \ + X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$_am_arg" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'`/stamp-h$_am_stamp_count + ;; + + :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +$as_echo "$as_me: executing $ac_file commands" >&6;} + ;; + esac + + + case $ac_file$ac_mode in + "depfiles":C) test x"$AMDEP_TRUE" != x"" || { + # Older Autoconf quotes --file arguments for eval, but not when files + # are listed without --file. Let's play safe and only enable the eval + # if we detect the quoting. + case $CONFIG_FILES in + *\'*) eval set x "$CONFIG_FILES" ;; + *) set x $CONFIG_FILES ;; + esac + shift + for mf + do + # Strip MF so we end up with the name of the file. + mf=`echo "$mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile or not. + # We used to match only the files named 'Makefile.in', but + # some people rename them; so instead we look at the file content. + # Grep'ing the first line is not enough: some people post-process + # each Makefile.in and add a new line on top of each file to say so. + # Grep'ing the whole file is not good either: AIX grep has a line + # limit of 2048, but all sed's we know have understand at least 4000. + if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then + dirpart=`$as_dirname -- "$mf" || +$as_expr X"$mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$mf" : 'X\(//\)[^/]' \| \ + X"$mf" : 'X\(//\)$' \| \ + X"$mf" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$mf" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + else + continue + fi + # Extract the definition of DEPDIR, am__include, and am__quote + # from the Makefile without running 'make'. + DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"` + test -z "$DEPDIR" && continue + am__include=`sed -n 's/^am__include = //p' < "$mf"` + test -z "$am__include" && continue + am__quote=`sed -n 's/^am__quote = //p' < "$mf"` + # Find all dependency output files, they are included files with + # $(DEPDIR) in their names. We invoke sed twice because it is the + # simplest approach to changing $(DEPDIR) to its actual value in the + # expansion. + for file in `sed -n " + s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \ + sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do + # Make sure the directory exists. + test -f "$dirpart/$file" && continue + fdir=`$as_dirname -- "$file" || +$as_expr X"$file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$file" : 'X\(//\)[^/]' \| \ + X"$file" : 'X\(//\)$' \| \ + X"$file" : 'X\(/\)' \| . 2>/dev/null || +$as_echo X"$file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + as_dir=$dirpart/$fdir; as_fn_mkdir_p + # echo "creating $dirpart/$file" + echo '# dummy' > "$dirpart/$file" + done + done +} + ;; + "libtool":C) + + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool 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 of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool 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, see . + + +# The names of the tagged configurations supported by this script. +available_tags='' + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Which release of libtool.m4 was used? +macro_version=$macro_version +macro_revision=$macro_revision + +# What type of objects to build. +pic_mode=$pic_mode + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# Shared archive member basename,for filename based shared library versioning on AIX. +shared_archive_member_spec=$shared_archive_member_spec + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# An echo program that protects backslashes. +ECHO=$lt_ECHO + +# The PATH separator for the build system. +PATH_SEPARATOR=$lt_PATH_SEPARATOR + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="\$SED -e 1s/^X//" + +# A grep program that handles long lines. +GREP=$lt_GREP + +# An ERE matcher. +EGREP=$lt_EGREP + +# A literal string matcher. +FGREP=$lt_FGREP + +# A BSD- or MS-compatible name lister. +NM=$lt_NM + +# Whether we need soft or hard links. +LN_S=$lt_LN_S + +# What is the maximum length of a command? +max_cmd_len=$max_cmd_len + +# Object file suffix (normally "o"). +objext=$ac_objext + +# Executable file suffix (normally ""). +exeext=$exeext + +# whether the shell understands "unset". +lt_unset=$lt_unset + +# turn spaces into newlines. +SP2NL=$lt_lt_SP2NL + +# turn newlines into spaces. +NL2SP=$lt_lt_NL2SP + +# convert \$build file names to \$host format. +to_host_file_cmd=$lt_cv_to_host_file_cmd + +# convert \$build files to toolchain format. +to_tool_file_cmd=$lt_cv_to_tool_file_cmd + +# An object symbol dumper. +OBJDUMP=$lt_OBJDUMP + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method = "file_magic". +file_magic_cmd=$lt_file_magic_cmd + +# How to find potential files when deplibs_check_method = "file_magic". +file_magic_glob=$lt_file_magic_glob + +# Find potential files using nocaseglob when deplibs_check_method = "file_magic". +want_nocaseglob=$lt_want_nocaseglob + +# DLL creation program. +DLLTOOL=$lt_DLLTOOL + +# Command to associate shared and link libraries. +sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd + +# The archiver. +AR=$lt_AR + +# Flags to create an archive. +AR_FLAGS=$lt_AR_FLAGS + +# How to feed a file listing to the archiver. +archiver_list_spec=$lt_archiver_list_spec + +# A symbol stripping program. +STRIP=$lt_STRIP + +# Commands used to install an old-style archive. +RANLIB=$lt_RANLIB +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Whether to use a lock for old archive extraction. +lock_old_archive_extraction=$lock_old_archive_extraction + +# A C compiler. +LTCC=$lt_CC + +# LTCC compiler flags. +LTCFLAGS=$lt_CFLAGS + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration. +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm into a list of symbols to manually relocate. +global_symbol_to_import=$lt_lt_cv_sys_global_symbol_to_import + +# Transform the output of nm in a C name address pair. +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# Transform the output of nm in a C name address pair when lib prefix is needed. +global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix + +# The name lister interface. +nm_interface=$lt_lt_cv_nm_interface + +# Specify filename containing input files for \$NM. +nm_file_list_spec=$lt_nm_file_list_spec + +# The root where to search for dependent libraries,and where our libraries should be installed. +lt_sysroot=$lt_sysroot + +# Command to truncate a binary pipe. +lt_truncate_bin=$lt_lt_cv_truncate_bin + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# Used to examine libraries when file_magic_cmd begins with "file". +MAGIC_CMD=$MAGIC_CMD + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Manifest tool. +MANIFEST_TOOL=$lt_MANIFEST_TOOL + +# Tool to manipulate archived DWARF debug symbol files on Mac OS X. +DSYMUTIL=$lt_DSYMUTIL + +# Tool to change global to local symbols on Mac OS X. +NMEDIT=$lt_NMEDIT + +# Tool to manipulate fat objects and archives on Mac OS X. +LIPO=$lt_LIPO + +# ldd/readelf like tool for Mach-O binaries on Mac OS X. +OTOOL=$lt_OTOOL + +# ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. +OTOOL64=$lt_OTOOL64 + +# Old archive suffix (normally "a"). +libext=$libext + +# Shared library suffix (normally ".so"). +shrext_cmds=$lt_shrext_cmds + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at link time. +variables_saved_for_relink=$lt_variables_saved_for_relink + +# Do we need the "lib" prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Library versioning type. +version_type=$version_type + +# Shared library runtime path variable. +runpath_var=$runpath_var + +# Shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Permission mode override for installation of shared libraries. +install_override_mode=$lt_install_override_mode + +# Command to use after installation of a shared archive. +postinstall_cmds=$lt_postinstall_cmds + +# Command to use after uninstallation of a shared archive. +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# As "finish_cmds", except a single script fragment to be evaled but +# not shown. +finish_eval=$lt_finish_eval + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Compile-time system search path for libraries. +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Detected run-time system search path for libraries. +sys_lib_dlsearch_path_spec=$lt_configure_time_dlsearch_path + +# Explicit LT_SYS_LIBRARY_PATH set during ./configure time. +configure_time_lt_sys_library_path=$lt_configure_time_lt_sys_library_path + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + + +# The linker used to build libraries. +LD=$lt_LD + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# Commands used to build an old-style archive. +old_archive_cmds=$lt_old_archive_cmds + +# A language specific compiler. +CC=$lt_compiler + +# Is the compiler the GNU compiler? +with_gcc=$GCC + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag + +# Additional compiler flags for building library objects. +pic_flag=$lt_lt_prog_compiler_pic + +# How to pass a linker flag through the compiler. +wl=$lt_lt_prog_compiler_wl + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_lt_prog_compiler_static + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_lt_cv_prog_compiler_c_o + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$archive_cmds_need_lc + +# Whether or not to disallow shared libs when runtime libs are static. +allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_export_dynamic_flag_spec + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_whole_archive_flag_spec + +# Whether the compiler copes with passing no objects directly. +compiler_needs_object=$lt_compiler_needs_object + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_old_archive_from_new_cmds + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds + +# Commands used to build a shared archive. +archive_cmds=$lt_archive_cmds +archive_expsym_cmds=$lt_archive_expsym_cmds + +# Commands used to build a loadable module if different from building +# a shared archive. +module_cmds=$lt_module_cmds +module_expsym_cmds=$lt_module_expsym_cmds + +# Whether we are building with GNU ld or not. +with_gnu_ld=$lt_with_gnu_ld + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_allow_undefined_flag + +# Flag that enforces no undefined symbols. +no_undefined_flag=$lt_no_undefined_flag + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist +hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec + +# Whether we need a single "-rpath" flag with a separated argument. +hardcode_libdir_separator=$lt_hardcode_libdir_separator + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary. +hardcode_direct=$hardcode_direct + +# Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes +# DIR into the resulting binary and the resulting library dependency is +# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# library is relocated. +hardcode_direct_absolute=$hardcode_direct_absolute + +# Set to "yes" if using the -LDIR flag during linking hardcodes DIR +# into the resulting binary. +hardcode_minus_L=$hardcode_minus_L + +# Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR +# into the resulting binary. +hardcode_shlibpath_var=$hardcode_shlibpath_var + +# Set to "yes" if building a shared library automatically hardcodes DIR +# into the library and all subsequent libraries and executables linked +# against it. +hardcode_automatic=$hardcode_automatic + +# Set to yes if linker adds runtime paths of dependent libraries +# to runtime path list. +inherit_rpath=$inherit_rpath + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$link_all_deplibs + +# Set to "yes" if exported symbols are required. +always_export_symbols=$always_export_symbols + +# The commands to list exported symbols. +export_symbols_cmds=$lt_export_symbols_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_exclude_expsyms + +# Symbols that must always be exported. +include_expsyms=$lt_include_expsyms + +# Commands necessary for linking programs (against libraries) with templates. +prelink_cmds=$lt_prelink_cmds + +# Commands necessary for finishing linking programs. +postlink_cmds=$lt_postlink_cmds + +# Specify filename containing input files. +file_list_spec=$lt_file_list_spec + +# How to hardcode a shared library path into an executable. +hardcode_action=$hardcode_action + +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x$2 in + x) + ;; + *:) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'` \$$1\" + ;; + x:*) + eval $1=\"\$$1 `$ECHO $2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval $1=\"\$$1\ `$ECHO $2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval $1=\"`$ECHO $2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \$$1\" + ;; + *) + eval $1=\"`$ECHO $2 | $SED 's/:/ /g'`\" + ;; + esac +} + + +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in $*""; do + case $cc_temp in + compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; + distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} + + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + +ltmain=$ac_aux_dir/ltmain.sh + + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" + + ;; + + esac +done # for ac_tag + + +as_fn_exit 0 +_ACEOF +ac_clean_files=$ac_clean_files_save + +test $ac_write_fail = 0 || + as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || as_fn_exit 1 +fi +if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} +fi + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/configure.ac cpl-plugin-sinfo-3.1.0+dfsg/hdrl/configure.ac --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/configure.ac 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/configure.ac 2018-02-20 13:00:18.000000000 +0000 @@ -0,0 +1,132 @@ +# Process this file with autoconf to produce a configure script. + +AC_INIT([HDRL Pipeline], [1.1.0b3], [usd-help@eso.org], [hdrl]) +AC_PREREQ([2.59]) + +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_AUX_DIR([admin]) +AC_CONFIG_MACRO_DIR([m4macros]) + +AC_CANONICAL_HOST +AC_CANONICAL_TARGET + +AM_INIT_AUTOMAKE +AC_CONFIG_HEADERS([config.h]) + +AM_MAINTAINER_MODE([enable]) + +# Immediately before every release do: +#------------------------------------- +# if (the interface is totally unchanged from previous release) +# REVISION++; +# else { +# /* interfaces have been added, removed or changed */ +# REVISION = 0; +# CURRENT++; +# if (any interfaces have been _added_ since last release) +# AGE++; +# if (any interfaces have been _removed_ or incompatibly changed) +# AGE = 0; +# } + +# Order of arguments: VERSION, CURRENT, REVISION, AGE +HDRL_SET_VERSION_INFO([$VERSION], [0], [0], [0]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AM_PROG_CC_C_O +AC_PROG_LN_S + +AC_SYS_LARGEFILE + +ESO_ENABLE_DEBUG(no) +ESO_ENABLE_STRICT(no) +ESO_PROG_CC_FLAG([pthread], [CFLAGS="$CFLAGS -pthread"]) +ESO_PROG_CC_FLAG([std=c99], [CFLAGS="$CFLAGS -std=c99"]) +ESO_PROG_CC_FLAG([Wall], [CFLAGS="-Wall $CFLAGS"]) +ESO_PROG_CC_FLAG([fvisibility=hidden], [CFLAGS="-fvisibility=hidden $CFLAGS"]) +ESO_PROG_CC_FLAG([Werror=implicit-function-declaration], + [CFLAGS="-Werror=implicit-function-declaration $CFLAGS"]) +ESO_PROG_CC_FLAG([Werror=incompatible-pointer-types], + [CFLAGS="$CFLAGS -Werror=incompatible-pointer-types"]) + +# simple openmp check, the one in eso.m4 is unnecessarily fragile +# ESO_ENABLE_OPENMP(openmp=no) +#----------------------------- +AC_DEFUN([ESO_ENABLE_OPENMP], +[ + AC_REQUIRE([AC_PROG_CC]) + + AC_ARG_ENABLE(openmp, + AS_HELP_STRING([--enable-openmp], + [compiles with openmp compiler options (may not work!) [[default=$1]]]), + eso_enable_openmp=$enableval, eso_enable_openmp=$1) + + AC_CACHE_CHECK([whether openmp compiler options should be used], + eso_cv_enable_openmp, + eso_cv_enable_openmp=$eso_enable_openmp) + + + if test x"$eso_cv_enable_openmp" = xyes; then + ESO_PROG_CC_FLAG([fopenmp], [CFLAGS="$CFLAGS -fopenmp" + LDFLAGS="$LDFLAGS -fopenmp"]) + ESO_PROG_CC_FLAG([xopenmp], [CFLAGS="$CFLAGS -xopenmp" + LDFLAGS="$LDFLAGS -xopenmp"]) + fi +]) +ESO_ENABLE_OPENMP([yes]) +ESO_ENABLE_TSAN([no]) + +AC_DEFUN([ESO_ENABLE_STANDALONE], +[ + AC_ARG_ENABLE(standalone, + AS_HELP_STRING([--enable-standalone], + [enable standalone installation for VLTSW [[default=$1]]]), + eso_enable_standalone=$enableval, eso_enable_standalone=$1) + + AM_CONDITIONAL([VLTSW], [test x"$eso_enable_standalone" = xyes]) +]) + +ESO_ENABLE_STANDALONE([no]) + +ESO_CHECK_DOCTOOLS + +AC_ENABLE_STATIC(no) +AC_ENABLE_SHARED(yes) + +AC_PROG_LIBTOOL +AC_SUBST(LIBTOOL_DEPS) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([string.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_C_INLINE + +# Checks for library functions. +AC_CHECK_LIB([m], [sqrt]) +AC_CHECK_FUNCS([floor pow sqrt]) +ESO_FUNC_STRDUP + +# Check for CPL presence and usability +ESO_CHECK_CPL + +# Check for GSL +GSL_CHECK_LIBS() + + +HDRL_CREATE_SYMBOLS + +AM_WITH_DMALLOC + +#AC_CONFIG_SUBDIRS(external/fftw external/sextractor external/swarp) +#AC_CONFIG_SUBDIRS(external/sextractor external/swarp) + +AC_CONFIG_FILES(Makefile + tests/Makefile + catalogue/Makefile + catalogue/tests/Makefile) +AC_OUTPUT diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_2d.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_2d.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_2d.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_2d.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,1335 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_utils.h" + +#include "hdrl_bpm_2d.h" +#include "hdrl_prototyping.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + + +/** + * @defgroup hdrl_bpm Bad Pixel Detection + * + * @brief + * This module contains functions to detect bad pixels on single images, on a + * stack of identical images and on a sequence of images. + * + */ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_2d Bad Pixel Mask 2D Computation + @ingroup hdrl_bpm + + @brief + Algorithms to detect bad pixels on a single image + + The routines in this module can be used to detect bad pixels on a single image. + The algorithm first smoothes the image by applying different methods. + Then it subtracts the smoothed image and derives bad + pixels by thresholding the residual image, i.e. all pixels exceeding + the threshold are considered as bad. + + The calculation is performed by calling the top-level function + hdrl_bpm_2d_compute() and the parameters passed to this function can be created + by calling hdrl_bpm_2d_parameter_create_filtersmooth() \b or + hdrl_bpm_2d_parameter_create_legendresmooth(), depending on the method one + would like to use. + + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + + +/** @cond PRIVATE */ + +static cpl_image * hdrl_get_residuals_filtersmooth(cpl_size, cpl_size, + cpl_filter_mode, cpl_border_mode, cpl_image *, cpl_mask *); +static cpl_image * hdrl_get_residuals_legendresmooth(const cpl_image *, int, + int, int, int, int, int) ; + +/*----------------------------------------------------------------------------- + BPM Parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + cpl_filter_mode filter ; + cpl_border_mode border ; + double kappa_low ; + double kappa_high ; + int maxiter ; + int steps_x ; + int steps_y ; + int filter_size_x ; + int filter_size_y ; + int order_x ; + int order_y ; + int smooth_x ; + int smooth_y ; + hdrl_bpm_2d_method method ; +} hdrl_bpm_2d_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_bpm_2d_parameter_type = { + HDRL_PARAMETER_BPM_2D, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_bpm_2d_parameter), /* obj_size */ +}; +/** @endcond */ + +/*----------------------------------------------------------------------------*/ +/** + @brief Creates BPM_2D Parameters object for HDRL_BPM_2D_FILTERSMOOTH + @param kappa_low Low kappa factor for thresholding algorithm + @param kappa_high High kappa factor for thresholding algorithm + @param maxiter Maximum number of iterations + @param filter filter mode + @param border border mode + @param smooth_x Smoothing kernel X size + @param smooth_y Smoothing kernel Y size + @return The BPM_2D parameters object. It needs to be deallocated with + hdrl_parameter_delete() + + The method creates a parameter for the method HDRL_BPM_2D_FILTERSMOOTH + + @see hdrl_parameter_delete() + @see hdrl_bpm_2d_compute() + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_2d_parameter_create_filtersmooth( + double kappa_low, + double kappa_high, + int maxiter, + cpl_filter_mode filter, + cpl_border_mode border, + int smooth_x, + int smooth_y) +{ + hdrl_bpm_2d_parameter * p = (hdrl_bpm_2d_parameter *) + hdrl_parameter_new(&hdrl_bpm_2d_parameter_type); + p->kappa_low = kappa_low ; + p->kappa_high = kappa_high ; + p->maxiter = maxiter ; + p->filter = filter ; + p->border = border ; + p->smooth_x = smooth_x ; + p->smooth_y = smooth_y ; + p->steps_x = 0 ; + p->steps_y = 0 ; + p->filter_size_x = 0 ; + p->filter_size_y = 0 ; + p->order_x = 0 ; + p->order_y = 0 ; + p->method = HDRL_BPM_2D_FILTERSMOOTH ; + + if (hdrl_bpm_2d_parameter_verify((hdrl_parameter*)p) != CPL_ERROR_NONE) { + cpl_free(p); + return NULL; + } + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Creates BPM_2D Parameters object for HDRL_BPM_2D_LEGENDRESMOOTH + @param kappa_low Low kappa factor for thresholding algorithm + @param kappa_high High kappa factor for thresholding algorithm + @param maxiter Maximum number of iterations + @param steps_x Number of sampling coordinates in x-dir + @param steps_y Number of sampling coordinates in y-dir + @param filter_size_x size of the median box in x-dir + @param filter_size_y size of the median box in y-dir + @param order_x order of polynomial in x-dir + @param order_y order of polynomial in y-dir + @return The BPM_2D parameters object. It needs to be deallocated with + hdrl_parameter_delete(). + + The method creates a hdrl parameter for the method HDRL_BPM_2D_LEGENDRESMOOTH + + @see hdrl_parameter_delete() + @see hdrl_bpm_2d_compute() + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_2d_parameter_create_legendresmooth( + double kappa_low, + double kappa_high, + int maxiter, + int steps_x, + int steps_y, + int filter_size_x, + int filter_size_y, + int order_x, + int order_y) +{ + hdrl_bpm_2d_parameter * p = (hdrl_bpm_2d_parameter *) + hdrl_parameter_new(&hdrl_bpm_2d_parameter_type); + p->kappa_low = kappa_low ; + p->kappa_high = kappa_high ; + p->maxiter = maxiter ; + p->filter = CPL_FILTER_MEDIAN ; + p->border = CPL_BORDER_FILTER ; + p->smooth_x = 0 ; + p->smooth_y = 0 ; + p->steps_x = steps_x ; + p->steps_y = steps_y ; + p->filter_size_x = filter_size_x ; + p->filter_size_y = filter_size_y ; + p->order_x = order_x ; + p->order_y = order_y ; + p->method = HDRL_BPM_2D_LEGENDRESMOOTH ; + if (hdrl_bpm_2d_parameter_verify((hdrl_parameter*)p) != CPL_ERROR_NONE) { + cpl_free(p); + return NULL; + } + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Verify basic correctness of the BPM_2D parameters + @param param BPM_2D parameters + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_bpm_2d_parameter_verify( + const hdrl_parameter * param) +{ + const hdrl_bpm_2d_parameter * param_loc = (const hdrl_bpm_2d_parameter *)param ; + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_bpm_2d_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected BPM_2d parameter") ; + + cpl_error_ensure(param_loc->method == HDRL_BPM_2D_LEGENDRESMOOTH || + param_loc->method == HDRL_BPM_2D_FILTERSMOOTH, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Unsupported method"); + + switch (param_loc->method) { + case HDRL_BPM_2D_FILTERSMOOTH: + cpl_error_ensure(param_loc->smooth_x >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "smooth-x must be >=0"); + cpl_error_ensure(param_loc->smooth_y >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "smooth-y must be >=0"); + /* Only odd-sized kernel are allowed */ + cpl_error_ensure(((param_loc->smooth_x)&1) == 1, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "smooth-x must be odd"); + cpl_error_ensure(((param_loc->smooth_y)&1) == 1, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "smooth-y must be odd"); + if (param_loc->filter != CPL_FILTER_AVERAGE && + param_loc->filter != CPL_FILTER_AVERAGE_FAST && + param_loc->filter != CPL_FILTER_MEDIAN) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Function only supports filters: " + "CPL_FILTER_AVERAGE, CPL_FILTER_AVERAGE_FAST " + "and CPL_FILTER_MEDIAN"); + return CPL_ERROR_ILLEGAL_INPUT; + } + break ; + case HDRL_BPM_2D_LEGENDRESMOOTH: + cpl_error_ensure(param_loc->order_x >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "order-x must be >= 0"); + cpl_error_ensure(param_loc->order_y >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "order-y must be >= 0"); + cpl_error_ensure(param_loc->steps_x > param_loc->order_x, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "stepx_x must be > order-x"); + cpl_error_ensure(param_loc->steps_y > param_loc->order_y, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "stepx_y must be > order-y"); + cpl_error_ensure(param_loc->filter_size_x > 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "filter-size-x must be > 0"); + cpl_error_ensure(param_loc->filter_size_y > 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "filter-size-y must be > 0"); + break ; + } + + cpl_error_ensure(param_loc->kappa_low >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "kappa-low must be >=0"); + cpl_error_ensure(param_loc->kappa_high >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "kappa-high must be >=0"); + cpl_error_ensure(param_loc->maxiter >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "maxiter must be >=0"); + return CPL_ERROR_NONE ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is a BPM_2D parameter + @param self The parameter to check + @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_bpm_2d_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_bpm_2d_parameter_type); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the filter in the BPM_2D parameter + @param p The BPM_2D parameter + @return The filter + */ +/*----------------------------------------------------------------------------*/ +cpl_filter_mode hdrl_bpm_2d_parameter_get_filter( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, CPL_FILTER_EROSION); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->filter : CPL_FILTER_EROSION; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the border in the BPM_2D parameter + @param p The BPM_2D parameter + @return The border + */ +/*----------------------------------------------------------------------------*/ +cpl_border_mode hdrl_bpm_2d_parameter_get_border( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, CPL_BORDER_FILTER); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->border : CPL_BORDER_FILTER; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the kappa_low in the BPM_2D parameter + @param p The BPM_2D parameter + @return The kappa_low + */ +/*----------------------------------------------------------------------------*/ +double hdrl_bpm_2d_parameter_get_kappa_low( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->kappa_low : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the kappa_high in the BPM_2D parameter + @param p The BPM_2D parameter + @return The kappa_high + */ +/*----------------------------------------------------------------------------*/ +double hdrl_bpm_2d_parameter_get_kappa_high( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->kappa_high : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the maxiter in the BPM_2D parameter + @param p The BPM_2D parameter + @return The maxiter + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_maxiter( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->maxiter : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the steps_x in the BPM_2D parameter + @param p The BPM_2D parameter + @return The steps_x + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_steps_x( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->steps_x : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the steps_y in the BPM_2D parameter + @param p The BPM_2D parameter + @return The steps_y + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_steps_y( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->steps_y : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the filter_size_x in the BPM_2D parameter + @param p The BPM_2D parameter + @return The filter_size_x + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_filter_size_x( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->filter_size_x : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the filter_size_y in the BPM_2D parameter + @param p The BPM_2D parameter + @return The filter_size_y + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_filter_size_y( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->filter_size_y : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the order_x in the BPM_2D parameter + @param p The BPM_2D parameter + @return The order_x + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_order_x( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->order_x : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the order_y in the BPM_2D parameter + @param p The BPM_2D parameter + @return The order_y + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_order_y( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->order_y : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the smooth_y in the BPM_2D parameter + @param p The BPM_2D parameter + @return The smooth_y + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_smooth_y( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->smooth_y : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the smooth_x in the BPM_2D parameter + @param p The BPM_2D parameter + @return The smooth_x + */ +/*----------------------------------------------------------------------------*/ +int hdrl_bpm_2d_parameter_get_smooth_x( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->smooth_x : 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the method in the BPM_2D parameter + @param p The BPM_2D parameter + @return The method + */ +/*----------------------------------------------------------------------------*/ +hdrl_bpm_2d_method hdrl_bpm_2d_parameter_get_method( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, HDRL_BPM_2D_LEGENDRESMOOTH); + return p != NULL ? ((const hdrl_bpm_2d_parameter *)p)->method : HDRL_BPM_2D_LEGENDRESMOOTH; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Create parameter list for the BPM_2D legendresmooth computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be an empty string + @param deflt defaults + Creates a parameter list with the BPM_2D parameters: + - base_context.prefix.method + - base_context.prefix.legendre.kappa_low + - base_context.prefix.legendre.kappa_high + - base_context.prefix.legendre.maxiter + - base_context.prefix.legendre.steps_x + - base_context.prefix.legendre.steps_y + - base_context.prefix.legendre.filter_size_x + - base_context.prefix.legendre.filter_size_y + - base_context.prefix.legendre.order_x + - base_context.prefix.legendre.order_y + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +static cpl_parameterlist * hdrl_bpm_2d_legendresmooth_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *deflt) +{ + cpl_ensure(prefix && base_context && deflt, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_bpm_2d_parameter_check(deflt), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist * parlist = cpl_parameterlist_new(); + char * context = + hdrl_join_string(".", 2, base_context, prefix); + + double kappa_low_def = hdrl_bpm_2d_parameter_get_kappa_low(deflt); + double kappa_high_def = hdrl_bpm_2d_parameter_get_kappa_high(deflt); + int maxiter_def = hdrl_bpm_2d_parameter_get_maxiter(deflt); + + /* --prefix.kappa_low */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "kappa-low", base_context, + "Low RMS scaling factor for image thresholding", CPL_TYPE_DOUBLE, + kappa_low_def) ; + + /* --prefix.kappa_high */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "kappa-high", base_context, + "High RMS scaling factor for image thresholding", CPL_TYPE_DOUBLE, + kappa_high_def) ; + + /* --prefix.maxiter */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "maxiter", base_context, + "Maximum number of algorithm iterations", CPL_TYPE_INT, maxiter_def); + + /* --prefix.steps_x */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "steps-x", + base_context, "Number of image sampling points in x-dir for fitting", + CPL_TYPE_INT, hdrl_bpm_2d_parameter_get_steps_x(deflt)); + + /* --prefix.steps_y */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "steps-y", + base_context, "Number of image sampling points in y-dir for fitting", + CPL_TYPE_INT, hdrl_bpm_2d_parameter_get_steps_y(deflt)) ; + + /* --prefix.filter_size_x */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "filter-size-x", + base_context, "X size of the median box around sampling points", CPL_TYPE_INT, + hdrl_bpm_2d_parameter_get_filter_size_x(deflt)) ; + + /* --prefix.filter_size_y */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "filter-size-y", + base_context, "Y size of the median box around sampling points", CPL_TYPE_INT, + hdrl_bpm_2d_parameter_get_filter_size_y(deflt)); + + /* --prefix.order_x */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "order-x", + base_context, "Order of x polynomial for the fit", CPL_TYPE_INT, + hdrl_bpm_2d_parameter_get_order_x(deflt)); + + /* --prefix.order_y */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "order-y", + base_context, "Order of y polynomial for the fit", CPL_TYPE_INT, + hdrl_bpm_2d_parameter_get_order_y(deflt)) ; + + + cpl_free(context); + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + return parlist; +} + + +static const char * filter_to_string(cpl_filter_mode filter) +{ + switch (filter) { + case CPL_FILTER_EROSION: + return "EROSION"; + break; + case CPL_FILTER_DILATION: + return "DILATION"; + break; + case CPL_FILTER_OPENING: + return "OPENING"; + break; + case CPL_FILTER_CLOSING: + return "CLOSING"; + break; + case CPL_FILTER_LINEAR: + return "LINEAR"; + break; + case CPL_FILTER_LINEAR_SCALE: + return "LINEAR_SCALE"; + break; + case CPL_FILTER_AVERAGE: + return "AVERAGE"; + break; + case CPL_FILTER_AVERAGE_FAST: + return "AVERAGE_FAST"; + break; + case CPL_FILTER_MEDIAN: + return "MEDIAN"; + break; + case CPL_FILTER_STDEV: + return "STDEV"; + break; + case CPL_FILTER_STDEV_FAST: + return "STDEV_FAST"; + break; + case CPL_FILTER_MORPHO: + return "MORPHO"; + break; + case CPL_FILTER_MORPHO_SCALE: + return "MORPHO_SCALE"; + break; + default : + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Filter unknown"); + return ""; + break; + } +} + +static const char * border_to_string(cpl_border_mode border) +{ + switch (border) { + case CPL_BORDER_FILTER: + return "FILTER"; + break; + case CPL_BORDER_ZERO: + return "ZERO"; + break; + case CPL_BORDER_CROP: + return "CROP"; + break; + case CPL_BORDER_NOP: + return "NOP"; + break; + case CPL_BORDER_COPY: + return "COPY"; + break; + default : + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "border unknown"); + return ""; + break; + } +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Create parameter list for the BPM_2D filtersmooth computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be an empty string + @param deflt defaults + Creates a parameter list with the BPM_2D parameters: + - base_context.prefix.method + - base_context.prefix.filter.kappa-low + - base_context.prefix.filter.kappa-high + - base_context.prefix.filter.maxiter + - base_context.prefix.filter.filter + - base_context.prefix.filter.border + - base_context.prefix.filter.smooth-x + - base_context.prefix.filter.smooth-y + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +static cpl_parameterlist * hdrl_bpm_2d_filtersmooth_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *deflt) +{ + cpl_ensure(prefix && base_context && deflt, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_bpm_2d_parameter_check(deflt), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + char * name ; + cpl_parameterlist * parlist = cpl_parameterlist_new(); + cpl_parameter * par ; + char * context = + hdrl_join_string(".", 2, base_context, prefix); + + double kappa_low_def = hdrl_bpm_2d_parameter_get_kappa_low(deflt); + double kappa_high_def = hdrl_bpm_2d_parameter_get_kappa_high(deflt); + int maxiter_def = hdrl_bpm_2d_parameter_get_maxiter(deflt); + + /* --prefix.kappa_low */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "kappa-low", base_context, + "Low RMS scaling factor for image thresholding", CPL_TYPE_DOUBLE, kappa_low_def) ; + + /* --prefix.kappa_high */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "kappa-high", base_context, + "High RMS scaling factor for image thresholding", CPL_TYPE_DOUBLE, kappa_high_def) ; + + /* --prefix.maxiter */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "maxiter", base_context, + "Maximum number of algorithm iterations", CPL_TYPE_INT, maxiter_def); + + /* --prefix.filter */ + cpl_filter_mode filter = hdrl_bpm_2d_parameter_get_filter(deflt); + const char * filter_def = filter_to_string(filter); + name = hdrl_join_string(".", 2, context, "filter"); + par = cpl_parameter_new_enum(name, CPL_TYPE_STRING, "Filter mode for image smooting", + context, filter_def, 3, "AVERAGE", "AVERAGE_FAST", "MEDIAN"); + cpl_free(name); + name = hdrl_join_string(".", 2, prefix, "filter"); + cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV); + cpl_free(name); + cpl_parameterlist_append(parlist, par); + + /* --prefix.border */ + cpl_border_mode border = hdrl_bpm_2d_parameter_get_border(deflt); + const char * border_def = border_to_string(border); + name = hdrl_join_string(".", 2, context, "border"); + par = cpl_parameter_new_enum(name, CPL_TYPE_STRING, + "Border mode to use for the image smooting filter " + "(only for MEDIAN filter)", + context, border_def, 4, "FILTER", "CROP", "NOP", "COPY"); + cpl_free(name); + name = hdrl_join_string(".", 2, prefix, "border"); + cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV); + cpl_free(name); + cpl_parameterlist_append(parlist, par); + + /* --prefix.smooth_x */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "smooth-x", + base_context, "Kernel y size of the smoothing filter", CPL_TYPE_INT, + hdrl_bpm_2d_parameter_get_smooth_x(deflt)); + + /* --prefix.smooth_y */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "smooth-y", + base_context, "Kernel y size of the image smoothing filter", CPL_TYPE_INT, + hdrl_bpm_2d_parameter_get_smooth_y(deflt)); + + cpl_free(context); + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create parameter list for the BPM_2D computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be an empty string + @param method_def default used method + @param filtersmooth_def defaults for filtersmooth method + @param legendresmooth_def defaults for legendresmooth method + Creates a parameter list with the BPM_2D parameters: + - base_context.prefix.method + - base_context.prefix.legendre.kappa-low + - base_context.prefix.legendre.kappa-high + - base_context.prefix.legendre.maxiter + - base_context.prefix.legendre.steps-x + - base_context.prefix.legendre.steps-y + - base_context.prefix.legendre.filter-size-x + - base_context.prefix.legendre.filter-size-y + - base_context.prefix.legendre.order-x + - base_context.prefix.legendre.order-y + - base_context.prefix.filter.kappa-low + - base_context.prefix.filter.kappa-high + - base_context.prefix.filter.maxiter + - base_context.prefix.filter.filter + - base_context.prefix.filter.border + - base_context.prefix.filter.smooth-x + - base_context.prefix.filter.smooth-y + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_bpm_2d_parameter_create_parlist( + const char *base_context, + const char *prefix, + const char *method_def, + const hdrl_parameter *filtersmooth_def, + const hdrl_parameter *legendresmooth_def) +{ + cpl_ensure(prefix && base_context && method_def, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(filtersmooth_def || legendresmooth_def, + CPL_ERROR_NULL_INPUT, NULL); + + if(filtersmooth_def){ + cpl_ensure(hdrl_bpm_2d_parameter_check(filtersmooth_def), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + } + + if(legendresmooth_def){ + cpl_ensure(hdrl_bpm_2d_parameter_check(legendresmooth_def), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + } + + char * name ; + cpl_parameterlist * parlist = cpl_parameterlist_new(); + cpl_parameter * par ; + char * context = + hdrl_join_string(".", 2, base_context, prefix); + + /* --prefix.method */ + name = hdrl_join_string(".", 2, context, "method"); + par = cpl_parameter_new_enum(name, CPL_TYPE_STRING, "Method used", context, + method_def, 2, "FILTER", "LEGENDRE"); + cpl_free(name); + name = hdrl_join_string(".", 2, prefix, "method"); + cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, name); + cpl_free(name); + cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV); + cpl_parameterlist_append(parlist, par); + + /* --prefix.legendre */ + name = hdrl_join_string(".", 2, prefix, "legendre"); + cpl_parameterlist * pleg = hdrl_bpm_2d_legendresmooth_parameter_create_parlist( + base_context, name, legendresmooth_def); + cpl_free(name); + for (cpl_parameter * p = cpl_parameterlist_get_first(pleg) ; + p != NULL; p = cpl_parameterlist_get_next(pleg)) + cpl_parameterlist_append(parlist, cpl_parameter_duplicate(p)); + cpl_parameterlist_delete(pleg); + + /* --prefix.filter */ + name = hdrl_join_string(".", 2, prefix, "filter"); + cpl_parameterlist * pfil = hdrl_bpm_2d_filtersmooth_parameter_create_parlist( + base_context, name, filtersmooth_def); + cpl_free(name); + for (cpl_parameter * p = cpl_parameterlist_get_first(pfil) ; + p != NULL; p = cpl_parameterlist_get_next(pfil)) + cpl_parameterlist_append(parlist, cpl_parameter_duplicate(p)); + cpl_parameterlist_delete(pfil); + + cpl_free(context); + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Parse parameter list to create input parameters for the BPM_2D + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return Input parameters for the BPM_2D computation + + Reads a parameter list in order to create BPM_2D parameters. + + Expects a parameter list containing: + - prefix.method + - prefix.legendre.kappa-low + - prefix.legendre.kappa-high + - prefix.legendre.maxiter + - prefix.legendre.steps-x + - prefix.legendre.steps-y + - prefix.legendre.filter-size-x + - prefix.legendre.filter-size-y + - prefix.legendre.order-x + - prefix.legendre.order-y + - prefix.filter.kappa-low + - prefix.filter.kappa-high + - prefix.filter.maxiter + - prefix.filter.filter + - prefix.filter.border + - prefix.filter.smooth-x + - prefix.filter.smooth-y + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_2d_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name ; + const cpl_parameter * par; + const char * tmp_str; + cpl_filter_mode filter = CPL_FILTER_EROSION ; + cpl_border_mode border = CPL_BORDER_FILTER ; + double kappa_low = -1.0 ; + double kappa_high = -1.0 ; + int maxiter = -1; + int steps_x = -1 ; + int steps_y = -1 ; + int filter_size_x = -1 ; + int filter_size_y = -1 ; + int order_x = -1 ; + int order_y = -1 ; + cpl_size smooth_x = -1 ; + cpl_size smooth_y = -1 ; + hdrl_bpm_2d_method method ; + + /* --method */ + name = hdrl_join_string(".", 2, prefix, "method"); + par = cpl_parameterlist_find_const(parlist, name) ; + tmp_str = cpl_parameter_get_string(par); + if (tmp_str == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + cpl_free(name) ; + if(!strcmp(tmp_str, "FILTER")) { + method = HDRL_BPM_2D_FILTERSMOOTH ; + } else if(!strcmp(tmp_str, "LEGENDRE")) { + method = HDRL_BPM_2D_LEGENDRESMOOTH ; + } else { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Invalid method: %s", tmp_str); + return NULL; + } + + char * kappa_prefix = hdrl_join_string(".", 2, prefix, + method == HDRL_BPM_2D_FILTERSMOOTH ? + "filter" : "legendre" ); + + /* --kappa_low */ + name = hdrl_join_string(".", 2, kappa_prefix, "kappa-low"); + par=cpl_parameterlist_find_const(parlist, name); + kappa_low = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --kappa_high */ + name = hdrl_join_string(".", 2, kappa_prefix, "kappa-high"); + par=cpl_parameterlist_find_const(parlist, name); + kappa_high = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --maxiter */ + name = hdrl_join_string(".", 2, kappa_prefix, "maxiter"); + par=cpl_parameterlist_find_const(parlist, name); + maxiter = cpl_parameter_get_int(par); + cpl_free(name) ; + + cpl_free(kappa_prefix); + + /* --steps_x */ + name = hdrl_join_string(".", 2, prefix, "legendre.steps-x"); + par=cpl_parameterlist_find_const(parlist, name); + steps_x = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --steps_y */ + name = hdrl_join_string(".", 2, prefix, "legendre.steps-y"); + par=cpl_parameterlist_find_const(parlist, name); + steps_y = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --filter_size_x */ + name = hdrl_join_string(".", 2, prefix, "legendre.filter-size-x"); + par=cpl_parameterlist_find_const(parlist, name); + filter_size_x = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --filter_size_y */ + name = hdrl_join_string(".", 2, prefix, "legendre.filter-size-y"); + par=cpl_parameterlist_find_const(parlist, name); + filter_size_y = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --order_x */ + name = hdrl_join_string(".", 2, prefix, "legendre.order-x"); + par=cpl_parameterlist_find_const(parlist, name); + order_x = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --order_y */ + name = hdrl_join_string(".", 2, prefix, "legendre.order-y"); + par=cpl_parameterlist_find_const(parlist, name); + order_y = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --filter */ + name = hdrl_join_string(".", 2, prefix, "filter.filter"); + par = cpl_parameterlist_find_const(parlist, name) ; + tmp_str = cpl_parameter_get_string(par); + if (tmp_str == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + if(!strcmp(tmp_str, "erosion")) { + filter = CPL_FILTER_EROSION ; + } else if(!strcmp(tmp_str, "DILATION")) { + filter = CPL_FILTER_DILATION ; + } else if(!strcmp(tmp_str, "OPENING")) { + filter = CPL_FILTER_OPENING ; + } else if(!strcmp(tmp_str, "CLOSING")) { + filter = CPL_FILTER_CLOSING ; + } else if(!strcmp(tmp_str, "LINEAR")) { + filter = CPL_FILTER_LINEAR ; + } else if(!strcmp(tmp_str, "LINEAR_SCALE")) { + filter = CPL_FILTER_LINEAR_SCALE ; + } else if(!strcmp(tmp_str, "AVERAGE")) { + filter = CPL_FILTER_AVERAGE ; + } else if(!strcmp(tmp_str, "AVERAGE_FAST")) { + filter = CPL_FILTER_AVERAGE_FAST ; + } else if(!strcmp(tmp_str, "MEDIAN")) { + filter = CPL_FILTER_MEDIAN ; + } else if(!strcmp(tmp_str, "STDEV")) { + filter = CPL_FILTER_STDEV ; + } else if(!strcmp(tmp_str, "STDEV_FAST")) { + filter = CPL_FILTER_STDEV_FAST ; + } else if(!strcmp(tmp_str, "MORPHO")) { + filter = CPL_FILTER_MORPHO ; + } else if(!strcmp(tmp_str, "MORPHO_SCALE")) { + filter = CPL_FILTER_MORPHO_SCALE ; + } + cpl_free(name) ; + + /* --border */ + name = hdrl_join_string(".", 2, prefix, "filter.border"); + par = cpl_parameterlist_find_const(parlist, name) ; + tmp_str = cpl_parameter_get_string(par); + if (tmp_str == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + if(!strcmp(tmp_str, "filter")) { + border = CPL_BORDER_FILTER ; + } else if(!strcmp(tmp_str, "ZERO")) { + border = CPL_BORDER_ZERO ; + } else if(!strcmp(tmp_str, "CROP")) { + border = CPL_BORDER_CROP ; + } else if(!strcmp(tmp_str, "NOP")) { + border = CPL_BORDER_NOP ; + } else if(!strcmp(tmp_str, "COPY")) { + border = CPL_BORDER_COPY ; + } + cpl_free(name) ; + + /* --smooth_x */ + name = hdrl_join_string(".", 2, prefix, "filter.smooth-x"); + par=cpl_parameterlist_find_const(parlist, name); + smooth_x = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --smooth_y */ + name = hdrl_join_string(".", 2, prefix, "filter.smooth-y"); + par=cpl_parameterlist_find_const(parlist, name); + smooth_y = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* Return */ + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist with prefix %s", prefix); + return NULL; + } else { + if (method == HDRL_BPM_2D_FILTERSMOOTH) { + return hdrl_bpm_2d_parameter_create_filtersmooth(kappa_low, + kappa_high, maxiter, filter, border, smooth_x, smooth_y) ; + } else if (method == HDRL_BPM_2D_LEGENDRESMOOTH) { + return hdrl_bpm_2d_parameter_create_legendresmooth(kappa_low, + kappa_high, maxiter, steps_x, steps_y, filter_size_x, + filter_size_y, order_x, order_y) ; + } else { + return NULL ; + } + } +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Detect bad pixels on a single image with an iterative process + @param img_in input hdrl image + @param params BPM_2D computation parameters - see below + @return Bad pixel mask with the newly found bad pixels + + + The algorithm first smoothes the image by applying the methods + described below. Then it subtracts the smoothed image and derives bad + pixels by thresholding the residual image, i.e. all pixels exceeding + the threshold are considered as bad. To compute the upper and lower + threshold, it measures a robust rms (a properly scaled Median Absolute + Deviation), which is then scaled by the parameter \e kappa_low and \e + kappa_high. Furthermore, the algorithm is applied iteratively + controlled by \e maxiter. During each iteration the newly found bad + pixels are ignored. Please note, that the thresholding values are + applied as median(residual-image) \f$\pm\f$ thresholds. This makes the + algorithm more robust in the case that the methods listed below are + not able to completely remove the background level, e.g due to an + exceeding number of bad pixels in the first iteration. + +Two methods are currently available to derive a smoothed version of +the image: + +\li \c Applying a filter like e.g. a median filter to the image. The + filtering can be done by all modes currently supported by cpl and is + controlled by the filter-type \e filter, the border-type \e border + and by the kernel size in x and y, i.e. \e smooth_x and \e + smooth_y. The corresponding BPM_2D parameter is created by + hdrl_bpm_2d_parameter_create_filtersmooth() + +\li \c Fitting a Legendre polynomial to the image of order \e order_x, + in x and \e order_y in y direction. This method allows you to + define \e steps_x \f$\times\f$ \e steps_y sampling points (the + latter are computed as the median within a box of \e filter_size_x + and \e filter_size_y) where the polynomial is fitted. This + substantially decreases the fitting time for the Legendre + polynomial. The corresponding BPM_2D parameter is created by + hdrl_bpm_2d_parameter_create_legendresmooth() + + */ +/*----------------------------------------------------------------------------*/ +cpl_mask * hdrl_bpm_2d_compute( + const hdrl_image * img_in, + const hdrl_parameter * params) +{ + cpl_image * img; + cpl_mask * mask_iter, * img_mask; + + /* Check Entries */ + cpl_error_ensure(img_in && params, CPL_ERROR_NULL_INPUT, + return NULL, "NULL input"); + if (hdrl_bpm_2d_parameter_verify(params) != CPL_ERROR_NONE) return NULL; + + /* Local Usage Parameters */ + const hdrl_bpm_2d_parameter * p_loc = (const hdrl_bpm_2d_parameter *)params ; + + img = cpl_image_duplicate(hdrl_image_get_image_const(img_in)); + img_mask = cpl_mask_duplicate(cpl_image_get_bpm(img)); + + /* The first iteration contains the passed mask */ + mask_iter = cpl_mask_duplicate(img_mask); + + + for (int var = 0; var < p_loc->maxiter; ++var) { + cpl_image * img_res = NULL; + cpl_mask * mask_iter_startloop = cpl_mask_duplicate(mask_iter); + double median, mad, std_mad, std_mad_low, std_mad_high ; + + /*Add original bad pixels to previous iteration*/ + cpl_mask_or(mask_iter, img_mask); + + /* Filter the image */ + if (p_loc->method == HDRL_BPM_2D_FILTERSMOOTH){ + img_res = hdrl_get_residuals_filtersmooth(p_loc->smooth_x, + p_loc->smooth_y, p_loc->filter, p_loc->border, img, + mask_iter); + } else if (p_loc->method == HDRL_BPM_2D_LEGENDRESMOOTH) { + img_res = hdrl_get_residuals_legendresmooth(img, p_loc->steps_x, + p_loc->steps_y, p_loc->filter_size_x, p_loc->filter_size_y, + p_loc->order_x, p_loc->order_y); + } + + /* + For a Gaussian distribution the Median Absolute Deviation (MAD) is a + robust and consistent estimate of the Standard Deviation (STD) in the + sense that the STD is approximately K * MAD, where K is a constant + equal to approximately 1.4826 == CPL_MATH_STD_MAD + */ + + /* Calculating the mad and assuming that after subtraction image has a + mean of Zero */ + + median = cpl_image_get_mad(img_res, &mad); + //mad = cpl_image_get_stdev(img_res); + if(mad <= 0){ + mad=nextafter(0,1.0); + } + std_mad = CPL_MATH_STD_MAD * mad; + std_mad_low = median -(std_mad * p_loc->kappa_low); + std_mad_high = median + (std_mad * p_loc->kappa_high); + + /*restore the original mask as we only want to add the new bad pixels + * to the originally passed mask - done by the threshold function*/ + + cpl_image_reject_from_mask(img_res, img_mask); + + /*Reset all pixels to good in the mask as we only want the new bad + * pixels */ + cpl_mask_xor(mask_iter, mask_iter); + + cpl_mask_threshold_image(mask_iter, img_res, std_mad_low, std_mad_high, + CPL_BINARY_0); + + /* Currently the cpl function assigns the "outside" value + * also to the bad pixels - thus if one only wants to have the new bad + * pixel, one has to do the bitwise or */ + cpl_mask_xor(mask_iter, img_mask); + cpl_image_delete(img_res); + + if (!hdrl_check_maskequality(mask_iter, mask_iter_startloop)) { + cpl_mask_delete(mask_iter_startloop); + cpl_msg_debug(cpl_func, "iter: %d", var); + break; + } + cpl_mask_delete(mask_iter_startloop); + cpl_msg_debug(cpl_func, "iter: %d", var); + } + cpl_mask_delete(img_mask); + cpl_image_delete(img); + + return mask_iter ; +} + +/**@}*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief calculates the residual of an image by fitting a Legendre polynomial + @param img Input image where the residuals are calculated + @param steps_x Number of sampling points in x for the polyfit + @param steps_y Number of sampling points in y for the polyfit + @param filter_size_x x-size of the median filter to calc the sampling points + @param filter_size_y y-size of the median filter to calc the sampling points + @param order_x x-degree of the fitted Legendre polynomial + @param order_y y-degree of the fitted Legendre polynomial + @return The residual image derived as (data - fit) + + The function interpolates the image onto a grid steps_x, steps_y using the + median. The size of the median box can by controlled by filter_size_x, + filter_size_y. On this image a Legendre polynomial of degree order_x, order_y + is fitted and subtracted from the original image + */ +/*----------------------------------------------------------------------------*/ +static cpl_image * hdrl_get_residuals_legendresmooth( + const cpl_image * img, + int steps_x, + int steps_y, + int filter_size_x, + int filter_size_y, + int order_x, + int order_y) +{ + cpl_image * img_res; + cpl_image * img_filtered; + cpl_size nx = cpl_image_get_size_x(img); + cpl_size ny = cpl_image_get_size_y(img); + cpl_size sx = CX_MAX(nx / steps_x, 1); + cpl_size sy = CX_MAX(ny / steps_y, 1); + + /* fit to stepped grid */ + cpl_matrix * x = hdrl_matrix_linspace(sx / 2, nx, sx); + cpl_matrix * y = hdrl_matrix_linspace(sy / 2, ny, sy); + cpl_image * imgtmp_mod = + hdrl_medianfilter_image_grid(img, x, y, + filter_size_x, + filter_size_y); + cpl_matrix * coeffs = hdrl_fit_legendre(imgtmp_mod, + order_x, order_y, + x, y, nx, ny); + /* TODO: naming conventions: hdrl_matrix_legendre_to_image() */ + img_filtered = hdrl_legendre_to_image(coeffs, order_x, order_y, nx, ny); + img_res = cpl_image_subtract_create(img, img_filtered); + if (cpl_msg_get_level() == CPL_MSG_DEBUG) + cpl_matrix_dump(coeffs, stdout); + cpl_matrix_delete(coeffs); + cpl_matrix_delete(x); + cpl_matrix_delete(y); + cpl_image_delete(imgtmp_mod); + cpl_image_delete(img_filtered); + return img_res; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief calculates the residual of an image by smoothing the image + @param kernel_size_x x-size of the smoothing kernel + @param kernel_size_y y-size of the smoothing kernel + @param filter, Filter type to be applied (all cpl filters) + @param border, Border-mode to be applied (all cpl border) + @param img, Input image where to apply the filtering + @param mask_iter, Input mask do determine the bad pixels + @return The residual image derived as (data - data_smoothed) + */ +/*----------------------------------------------------------------------------*/ +static cpl_image * hdrl_get_residuals_filtersmooth( + cpl_size kernel_size_x, + cpl_size kernel_size_y, + cpl_filter_mode filter, + cpl_border_mode border, + cpl_image * img, + cpl_mask * mask_iter) +{ + cpl_mask * kernel ; + cpl_image * img_res = NULL; + cpl_image * img_filtered = NULL; + + cpl_size nx = cpl_image_get_size_x(img); + cpl_size ny = cpl_image_get_size_y(img); + + + /* Create the kernel */ + kernel = cpl_mask_new(kernel_size_x, kernel_size_y) ; + cpl_mask_not(kernel); + if (kernel == NULL) return NULL ; + + /* Filter the image */ + cpl_image_reject_from_mask(img, mask_iter); + if (border == CPL_BORDER_FILTER) { + img_filtered = hdrl_parallel_filter_image(img, NULL, kernel, filter); + } + else { + img_filtered = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_filter_mask(img_filtered, img, kernel, filter, border); + } + cpl_mask_delete(kernel) ; + img_res = cpl_image_subtract_create(img, img_filtered); + cpl_image_delete(img_filtered); + + return img_res; +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_2d.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_2d.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_2d.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_2d.h 2014-09-10 16:43:44.000000000 +0000 @@ -0,0 +1,101 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_BPM_2D_H +#define HDRL_BPM_2D_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include +#include "hdrl_image.h" +#include "hdrl_imagelist.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ + +typedef enum { + HDRL_BPM_2D_LEGENDRESMOOTH, + HDRL_BPM_2D_FILTERSMOOTH +} hdrl_bpm_2d_method ; + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + BPM_2D Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_2d_parameter_create_legendresmooth(double, double, + int, int, int, int, int, int, int) ; +hdrl_parameter * hdrl_bpm_2d_parameter_create_filtersmooth(double, double, + int, cpl_filter_mode, cpl_border_mode, int, int) ; +cpl_error_code hdrl_bpm_2d_parameter_verify(const hdrl_parameter *) ; +cpl_boolean hdrl_bpm_2d_parameter_check(const hdrl_parameter *) ; + +/* Accessors */ +cpl_filter_mode hdrl_bpm_2d_parameter_get_filter(const hdrl_parameter *) ; +cpl_border_mode hdrl_bpm_2d_parameter_get_border(const hdrl_parameter *) ; +double hdrl_bpm_2d_parameter_get_kappa_low(const hdrl_parameter *) ; +double hdrl_bpm_2d_parameter_get_kappa_high(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_maxiter(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_steps_x(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_steps_y(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_filter_size_x(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_filter_size_y(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_order_x(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_order_y(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_smooth_x(const hdrl_parameter *) ; +int hdrl_bpm_2d_parameter_get_smooth_y(const hdrl_parameter *) ; +hdrl_bpm_2d_method hdrl_bpm_2d_parameter_get_method(const hdrl_parameter *) ; + +/* Parameter Lists */ +cpl_parameterlist * hdrl_bpm_2d_parameter_create_parlist( + const char * base_context, + const char * prefix, + const char * method_def, + const hdrl_parameter * filtersmooth_def, + const hdrl_parameter * legendresmooth_def); +hdrl_parameter * hdrl_bpm_2d_parameter_parse_parlist(const cpl_parameterlist *, + const char *) ; + +/*---------------------------------------------------------------------------- + BPM_2D Computation + ----------------------------------------------------------------------------*/ + +cpl_mask * hdrl_bpm_2d_compute( + const hdrl_image * img_in, + const hdrl_parameter * params) ; + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_3d.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_3d.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_3d.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_3d.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,524 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_utils.h" + +#include "hdrl_bpm_3d.h" +#include "hdrl_prototyping.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_3d Bad Pixel Mask 3D Computation + @ingroup hdrl_bpm + + @brief + Algorithms to detect bad pixels on a stack of identical images like e.g. + bias images + + The routines in this module can be used to detect bad pixels on a stack of + identical images like bias or dark images. The algorithm first collapses + the stack of images by using the median in order to generate a master-image. + Then it subtracts the master image from each individual image and derives the + bad pixels on the residual-images by thresholding, i.e. all pixels exceeding + the threshold are considered as bad. Please note, that the algorithm assumes + that the mean level of the different images is the same, if this is not the + case, the master-image as described above will be biased. + + The calculation is performed by calling the top-level function + hdrl_bpm_3d_compute() and the parameters passed to this function can be created + by calling hdrl_bpm_3d_parameter_create(). + + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/** @cond PRIVATE */ + + +/*----------------------------------------------------------------------------- + BPM Parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + double kappa_low ; + double kappa_high ; + hdrl_bpm_3d_method method ; +} hdrl_bpm_3d_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_bpm_3d_parameter_type = { + HDRL_PARAMETER_BPM_3D, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_bpm_3d_parameter), /* obj_size */ +}; +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + @brief Creates BPM Parameters object for the imagelist method + @param kappa_low Low kappa factor for thresholding algorithm + @param kappa_high High kappa factor for thresholding algorithm + @param method used method + @return The BPM_3D parameters object. + + It needs to be deallocated with hdrl_parameter_delete() + + @see hdrl_parameter_delete() + @see hdrl_bpm_3d_compute() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_3d_parameter_create( + double kappa_low, + double kappa_high, + hdrl_bpm_3d_method method) +{ + hdrl_bpm_3d_parameter * p = (hdrl_bpm_3d_parameter *) + hdrl_parameter_new(&hdrl_bpm_3d_parameter_type); + p->kappa_low = kappa_low ; + p->kappa_high = kappa_high ; + p->method = method ; + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Verify basic correctness of the BPM_3D parameters + @param param BPM image parameters + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_bpm_3d_parameter_verify( + const hdrl_parameter * param) +{ + const hdrl_bpm_3d_parameter * param_loc = (const hdrl_bpm_3d_parameter *)param ; + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_bpm_3d_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected BPM image parameter") ; + + cpl_error_ensure(param_loc->method == HDRL_BPM_3D_THRESHOLD_ABSOLUTE || + param_loc->method == HDRL_BPM_3D_THRESHOLD_RELATIVE || + param_loc->method == HDRL_BPM_3D_THRESHOLD_ERROR, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Unsupported method"); + switch (param_loc->method) { + case HDRL_BPM_3D_THRESHOLD_ABSOLUTE: + cpl_error_ensure(param_loc->kappa_high >= param_loc->kappa_low, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "kappa_high must be larger than kappa_low"); + break; + case HDRL_BPM_3D_THRESHOLD_RELATIVE: + case HDRL_BPM_3D_THRESHOLD_ERROR: + cpl_error_ensure(param_loc->kappa_low >= 0, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "kappa_low must be >=0"); + cpl_error_ensure(param_loc->kappa_high >= 0, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "kappa_high must be >=0"); + break; + } + return CPL_ERROR_NONE ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is a BPM_3D parameter + @param self The parameter to check + @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_bpm_3d_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_bpm_3d_parameter_type); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the kappa_low in the BPM_3D parameter + @param p The BPM_3D parameter + @return The kappa_low + */ +/*----------------------------------------------------------------------------*/ +double hdrl_bpm_3d_parameter_get_kappa_low( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return ((const hdrl_bpm_3d_parameter *)p)->kappa_low; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the kappa_high in the BPM_3D parameter + @param p The BPM_3D parameter + @return The kappa_high + */ +/*----------------------------------------------------------------------------*/ +double hdrl_bpm_3d_parameter_get_kappa_high( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return ((const hdrl_bpm_3d_parameter *)p)->kappa_high; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the method in the BPM_3D parameter + @param p The BPM_3D parameter + @return The method + */ +/*----------------------------------------------------------------------------*/ +hdrl_bpm_3d_method hdrl_bpm_3d_parameter_get_method( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return ((const hdrl_bpm_3d_parameter *)p)->method; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create a parameter list for the BPM_3D computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param defaults default values + + Creates a parameterlist with the BPM_3D parameters: + - base_context.prefix.kappa_low + - base_context.prefix.kappa_high + - base_context.prefix.method + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_bpm_3d_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *defaults) +{ + cpl_ensure(prefix && base_context && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_bpm_3d_parameter_check(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + char *name; + cpl_parameterlist *parlist = cpl_parameterlist_new(); + cpl_parameter *par; + char *context = + hdrl_join_string(".", 2, base_context, prefix); + + double kappa_low_def = hdrl_bpm_3d_parameter_get_kappa_low(defaults); + double kappa_high_def = hdrl_bpm_3d_parameter_get_kappa_high(defaults); + + hdrl_bpm_3d_method method_def = hdrl_bpm_3d_parameter_get_method(defaults); + cpl_ensure( method_def == HDRL_BPM_3D_THRESHOLD_ABSOLUTE + || method_def == HDRL_BPM_3D_THRESHOLD_RELATIVE + || method_def == HDRL_BPM_3D_THRESHOLD_ERROR, + CPL_ERROR_ILLEGAL_INPUT, NULL) ; + + const char *method_str; + if (method_def == HDRL_BPM_3D_THRESHOLD_ABSOLUTE) { + method_str = "absolute" ; + } else if (method_def == HDRL_BPM_3D_THRESHOLD_RELATIVE) { + method_str = "relative" ; + } else if (method_def == HDRL_BPM_3D_THRESHOLD_ERROR) { + method_str = "error" ; + } else { + method_str = ""; + } + + /* --prefix.kappa_low */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "kappa-low", base_context, + "Low RMS scaling factor for image thresholding.", CPL_TYPE_DOUBLE, + kappa_low_def) ; + + /* --prefix.kappa_high */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "kappa-high", base_context, + "High RMS scaling factor for image thresholding.", CPL_TYPE_DOUBLE, + kappa_high_def) ; + + /* --prefix.method */ + name = hdrl_join_string(".", 2, context, "method"); + par = cpl_parameter_new_enum(name, CPL_TYPE_STRING, + "Thresholdig method to use for bpm detection", context, method_str, + 3, "absolute", "relative", "error"); + cpl_free(name); + name = hdrl_join_string(".", 2, prefix, "method"); + cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV); + cpl_free(name); + cpl_parameterlist_append(parlist, par); + + cpl_free(context); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Parse a parameterlist to create input parameters for the BPM_3D + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return Input parameters for the BPM_3D computation + + Reads a parameterlist in order to create BPM image parameters. + Expects a parameterlist containing: + - prefix.kappa_low + - prefix.kappa_high + - prefix.method + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_3d_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name; + const cpl_parameter * par; + const char * tmp_str ; + double kappa_low; + double kappa_high; + hdrl_bpm_3d_method method; + + /* --kappa_low */ + name = hdrl_join_string(".", 2, prefix, "kappa-low"); + par=cpl_parameterlist_find_const(parlist, name); + kappa_low = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --kappa_high */ + name = hdrl_join_string(".", 2, prefix, "kappa-high"); + par=cpl_parameterlist_find_const(parlist, name); + kappa_high = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --method */ + name = hdrl_join_string(".", 2, prefix, "method"); + par = cpl_parameterlist_find_const(parlist, name) ; + tmp_str = cpl_parameter_get_string(par); + if (tmp_str == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + cpl_free(name) ; + if(!strcmp(tmp_str, "absolute")) { + method = HDRL_BPM_3D_THRESHOLD_ABSOLUTE ; + } else if(!strcmp(tmp_str, "relative")) { + method = HDRL_BPM_3D_THRESHOLD_RELATIVE ; + } else if(!strcmp(tmp_str, "error")) { + method = HDRL_BPM_3D_THRESHOLD_ERROR ; + } else { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Invalid method: %s", tmp_str); + return NULL; + } + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist with prefix %s", prefix); + return NULL; + } else { + return hdrl_bpm_3d_parameter_create(kappa_low, kappa_high, method) ; + } +} + +/*----------------------------------------------------------------------------*/ +/** + @brief detect bad pixels on a stack of identical images + @param imglist input hdrl imagelist + @param params BPM_3D computation parameters + @return cpl_imagelist where the newly rejected pixels are marked as unity. + +The algorithm first collapses the stack of images by using the median to +generate a master-image. Then it subtracts the master image from each individual +image and derives the bad pixels on the residual-images by thresholding, +i.e. all pixels strictly exceeding the threshold are considered as bad. + +Three methods are currently available to derive the bad pixels on the +residual images and can be set when creating the BPM_3D parameter via +hdrl_bpm_3d_parameter_create(): + +\li \c method = HDRL_BPM_3D_THRESHOLD_ABSOLUTE: It uses + \e kappa_low and \e kappa_high as absolute threshold + +\li \c method = HDRL_BPM_3D_THRESHOLD_RELATIVE: It scales the + measured rms on the residual-image with \e kappa_low and + \e kappa_high and uses it as threshold. For the rms a properly + scaled Median Absolute Deviation (MAD) is used. + +\li \c method = HDRL_BPM_3D_THRESHOLD_ERROR: It scales the + propagated error of each individual pixel with \e kappa_low and + \e kappa_high and uses it as threshold. + + + @note We assume that the images are already scaled outside this routine, i.e. + their absolute levels match. + + @details For a Gaussian distribution the Median Absolute Deviation (MAD) is a + robust and consistent estimate of the Standard Deviation (STD) in the sense + that the STD is approximately K * MAD, where K is a constant equal to + approximately 1.4826 + + */ +/*----------------------------------------------------------------------------*/ +cpl_imagelist * hdrl_bpm_3d_compute( + const hdrl_imagelist * imglist, + const hdrl_parameter * params) +{ + +/* This routine assumes that the images are already scaled outside ! */ + + cpl_imagelist * imglist_out = NULL; + hdrl_imagelist * masterlist = NULL; + hdrl_parameter * collapse_params = NULL; + + /* Check Entries */ + cpl_error_ensure(imglist && params, CPL_ERROR_NULL_INPUT, + return NULL, "NULL input"); + if (hdrl_bpm_3d_parameter_verify(params) != CPL_ERROR_NONE) return NULL; + + /* Local Usage Parameters */ + const hdrl_bpm_3d_parameter * p_loc = (const hdrl_bpm_3d_parameter *)params ; + + collapse_params = hdrl_collapse_median_parameter_create(); + + imglist_out = cpl_imagelist_new(); + masterlist = hdrl_imagelist_new(); + + + /* Here we have correlated errors */ + hdrl_image * master; + cpl_image * contrib_map; + + /* Get the proper collapse function and perform frames combination */ + hdrl_imagelist_collapse(imglist, collapse_params, &master,&contrib_map); + /* broadcasted same master over list */ + for (int var = 0; var < hdrl_imagelist_get_size(imglist); ++var) { + hdrl_imagelist_set(masterlist, master, + hdrl_imagelist_get_size(masterlist)); + } + cpl_image_delete(contrib_map); + + + for (int var = 0; var < hdrl_imagelist_get_size(imglist); ++var) { + /* subtract master */ + hdrl_image * tmp_hdrlimg = hdrl_image_sub_image_create( + hdrl_imagelist_get_const(imglist, var), + hdrl_imagelist_get(masterlist, var)); + cpl_mask * tmp_cplimg_mask = hdrl_image_get_mask(tmp_hdrlimg); + cpl_mask * mask_out = NULL; + + if (p_loc->method == HDRL_BPM_3D_THRESHOLD_ABSOLUTE) { + /* Absolute values */ + mask_out = cpl_mask_threshold_image_create( + hdrl_image_get_image(tmp_hdrlimg), p_loc->kappa_low, + p_loc->kappa_high); + cpl_mask_not(mask_out); + /*Here we use the bpm from the image after master frame subtraction + * - this is not 100 percent clean but a good approximation*/ + cpl_mask_xor(mask_out, tmp_cplimg_mask); + } else if (p_loc->method == HDRL_BPM_3D_THRESHOLD_RELATIVE) { + /* Scaled residual from image using scaled mad*/ + double mad, std_mad; + cpl_image_get_mad(hdrl_image_get_image(tmp_hdrlimg), &mad); + if (mad <= 0){ + mad = nextafter(0, 1.0); + } + std_mad = CPL_MATH_STD_MAD * mad; + mask_out = cpl_mask_threshold_image_create( + hdrl_image_get_image(tmp_hdrlimg), + -(p_loc->kappa_low * std_mad), + (p_loc->kappa_high * std_mad)); + cpl_mask_not(mask_out); + /*Here we use the bpm from the image after master frame subtraction + * - this is not 100 percent clean but a good approximation*/ + cpl_mask_xor(mask_out, tmp_cplimg_mask); + } else if (p_loc->method == HDRL_BPM_3D_THRESHOLD_ERROR) { + /* Using scaled pixel error bars to detect bp - + * we use the propagated error */ + cpl_size nx = hdrl_image_get_size_x(tmp_hdrlimg); + cpl_size ny = hdrl_image_get_size_y(tmp_hdrlimg); + mask_out = cpl_mask_new(nx, ny); /*All pixels are now good*/ + + for (cpl_size x = 1; x <= nx; ++x) { + for (cpl_size y = 1; y <= ny; ++y) { + int bad_data; + hdrl_value v = hdrl_image_get_pixel(tmp_hdrlimg, x, y, + &bad_data); + + if (v.data < -(v.error * p_loc->kappa_low) || + v.data > (v.error * p_loc->kappa_high) || bad_data) { + cpl_mask_set(mask_out, x, y, CPL_BINARY_1); + } + } + } + /*Here we use the bpm from the image after master frame subtraction + * - this is not 100 percent clean but a good approximation */ + cpl_mask_xor(mask_out, tmp_cplimg_mask); + } + cpl_imagelist_set(imglist_out, cpl_image_new_from_mask(mask_out), var); + cpl_mask_delete(mask_out); + hdrl_image_delete(tmp_hdrlimg); + } + + if (cpl_error_get_code() != CPL_ERROR_NONE) { + cpl_imagelist_delete(imglist_out); + imglist_out = NULL; + } + + hdrl_parameter_delete(collapse_params); + + /* single master broadcasted over list */ + hdrl_image_delete(hdrl_imagelist_unset(masterlist, 0)); + hdrl_imagelist_unwrap(masterlist); + + return imglist_out; +} + +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_3d.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_3d.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_3d.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_3d.h 2014-09-15 13:05:15.000000000 +0000 @@ -0,0 +1,84 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_BPM_3D_H +#define HDRL_BPM_3D_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include +#include "hdrl_image.h" +#include "hdrl_imagelist.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ + +typedef enum { + HDRL_BPM_3D_THRESHOLD_ABSOLUTE, + HDRL_BPM_3D_THRESHOLD_RELATIVE, + HDRL_BPM_3D_THRESHOLD_ERROR +} hdrl_bpm_3d_method ; + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + BPM Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_3d_parameter_create(double,double,hdrl_bpm_3d_method); +cpl_error_code hdrl_bpm_3d_parameter_verify(const hdrl_parameter *) ; +cpl_boolean hdrl_bpm_3d_parameter_check(const hdrl_parameter *) ; + +/* Accessors */ +double hdrl_bpm_3d_parameter_get_kappa_low(const hdrl_parameter *) ; +double hdrl_bpm_3d_parameter_get_kappa_high(const hdrl_parameter *) ; +hdrl_bpm_3d_method hdrl_bpm_3d_parameter_get_method(const hdrl_parameter *) ; + +/* Parameter Lists */ +cpl_parameterlist * hdrl_bpm_3d_parameter_create_parlist(const char *, + const char *, const hdrl_parameter *) ; +hdrl_parameter * hdrl_bpm_3d_parameter_parse_parlist(const cpl_parameterlist *, + const char *) ; + +/*---------------------------------------------------------------------------- + BPM_3D Computation + ----------------------------------------------------------------------------*/ + +cpl_imagelist * hdrl_bpm_3d_compute( + const hdrl_imagelist * imglist, + const hdrl_parameter * params) ; + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_fit.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_fit.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_fit.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_fit.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,671 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_utils.h" +#include "hdrl_fit.h" +#include "hdrl_bpm_fit.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_fit Bad Pixel Mask via fitting + @ingroup hdrl_bpm + + @brief + Algorithms to detect bad-pixels on a sequence of images like e.g. domeflats + + The routine in this module derives bad pixels on a sequence of images (e.g. + domeflats with differend exposure time). The algorithm fits a polynomial to each + pixel-sequence and determinates bad pixels based on this fit and various + thresholding methods. + + The calculation is performed by calling the top-level function + hdrl_bpm_fit_compute() and the parameters passed to this function can be created + by calling + hdrl_bpm_fit_parameter_create_rel_chi(), \b or + hdrl_bpm_fit_parameter_create_rel_coef(), \b or + hdrl_bpm_fit_parameter_create_pval(), depending on the method one would like + to use. + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/** @cond PRIVATE */ + +double igamc(double, double); + +/*----------------------------------------------------------------------------- + BPM Parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + int degree; + double pval; + double rel_chi_l; + double rel_chi_h; + double rel_coef_l; + double rel_coef_h; +} hdrl_bpm_fit_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_bpm_fit_parameter_type = { + HDRL_PARAMETER_BPM_FIT, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_bpm_fit_parameter), /* obj_size */ +}; + + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief create general bpm_fit parameter only one cut must be > 0 + * @param degree degree of fit + * @param pval p-value bpm cutoff + * @param rel_chi relative chi bpm cutoff + * @param rel_coef relative coefficient bpm cutoff + * + * @return valud hdrl_parameter or NULL on error + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_parameter * +hdrl_bpm_fit_parameter_create_all(int degree, double pval, + double rel_chi_l, double rel_chi_h, + double rel_coef_l, double rel_coef_h) +{ + hdrl_bpm_fit_parameter * p = (hdrl_bpm_fit_parameter *) + hdrl_parameter_new(&hdrl_bpm_fit_parameter_type); + p->degree = degree; + p->pval = pval; + p->rel_chi_l = rel_chi_l; + p->rel_chi_h = rel_chi_h; + p->rel_coef_l = rel_coef_l; + p->rel_coef_h = rel_coef_h; + if (hdrl_bpm_fit_parameter_verify((const hdrl_parameter *)p) == + CPL_ERROR_NONE) { + return (hdrl_parameter *)p; + } + else { + hdrl_parameter_delete((hdrl_parameter*)p); + return NULL; + } +} + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create bpm_fit parameter with p-value bpm treshold + * @param degree degree of fit + * @param pval p-value of bpm threshold + * @return hdrl_parameter or NULL on error + * @see hdrl_bpm_fit_compute() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_bpm_fit_parameter_create_pval(int degree, double pval) +{ + return hdrl_bpm_fit_parameter_create_all(degree, pval, -1, -1, -1, -1); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create bpm_fit parameter with relative chi bpm treshold + * @param degree degree of fit + * @param rel_chi_low relative chi distribution bpm lower threshold + * @param rel_chi_high relative chi distribution bpm upper threshold + * @return hdrl_parameter or NULL on error + * @see hdrl_bpm_fit_compute() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_bpm_fit_parameter_create_rel_chi(int degree, + double rel_chi_low, double rel_chi_high) +{ + return hdrl_bpm_fit_parameter_create_all(degree, -1, + rel_chi_low, rel_chi_high, -1, -1); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create bpm_fit parameter with relative coefficient bpm treshold + * @param degree degree of fit + * @param rel_coef_low relative fit coefficient distribution bpm lower threshold + * @param rel_coef_high relative fit coefficient distribution bpm upper threshold + * @return hdrl_parameter or NULL on error + * @see hdrl_bpm_fit_compute() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_bpm_fit_parameter_create_rel_coef(int degree, + double rel_coef_low, double rel_coef_high) +{ + return hdrl_bpm_fit_parameter_create_all(degree, -1, + -1, -1, rel_coef_low, rel_coef_high); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is a bpm_fit parameter + @param self The parameter to check + @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_bpm_fit_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_bpm_fit_parameter_type); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief verify that the parameter is a valid bpm_fit_parameter + * @param p parameter + * @return error code + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_bpm_fit_parameter_verify(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + const hdrl_bpm_fit_parameter * par = (const hdrl_bpm_fit_parameter *)p; + int have_par = 0; + if (par->degree < 0) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "degree must be positive"); + } + + if (par->pval >= 0) { + if (par->pval > 100.) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "pval must be between 0 and 100%%"); + } + have_par = 1; + } + + if (par->rel_chi_l >= 0 || par->rel_chi_h >= 0) { + if (have_par) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Only one rejection criteria is allowed, " + "set the others to negative values"); + } + if (!(par->rel_chi_l >= 0 && par->rel_chi_h >= 0)) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Upper and lower rejection criteria must be >= 0"); + } + have_par = 1; + } + + if (par->rel_coef_l >= 0 || par->rel_coef_h >= 0) { + if (have_par) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Only one rejection criteria is allowed, " + "set the others to negative values"); + } + if (!(par->rel_coef_l >= 0 && par->rel_coef_h >= 0)) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Upper and lower rejection criteria must be >= 0"); + } + have_par = 1; + } + + if (!have_par) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Only no bad pixel parameter given, the chosen threshold " + "must have a value larger than zero"); + } + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get degree of polynomial fit of parameter + * @param p parameter + * @return degree of polynomial fit + */ +/* ---------------------------------------------------------------------------*/ +int hdrl_bpm_fit_parameter_get_degree(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + return ((const hdrl_bpm_fit_parameter *)p)->degree; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get p-value bpm treshold + * @param p parameter + * @return p-value + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_bpm_fit_parameter_get_pval( const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1.); + return ((const hdrl_bpm_fit_parameter *)p)->pval; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get relative chi distribution lower threshold + * @param p parameter + * @return relative chi distribution lower threshold + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_bpm_fit_parameter_get_rel_chi_low(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1.); + return ((const hdrl_bpm_fit_parameter *)p)->rel_chi_l; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get relative chi distribution upper threshold + * @param p parameter + * @return relative chi distribution upper threshold + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_bpm_fit_parameter_get_rel_chi_high(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1.); + return ((const hdrl_bpm_fit_parameter *)p)->rel_chi_h; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get relative fit coefficient distribution lower threshold + * @param p parameter + * @return relative fit coefficient distribution lower threshold + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_bpm_fit_parameter_get_rel_coef_low(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1.); + return ((const hdrl_bpm_fit_parameter *)p)->rel_coef_l; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get relative fit coefficient distribution upper threshold + * @param p parameter + * @return relative fit coefficient distribution upper threshold + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_bpm_fit_parameter_get_rel_coef_high(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.); + cpl_ensure(hdrl_bpm_fit_parameter_check(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1.); + return ((const hdrl_bpm_fit_parameter *)p)->rel_coef_h; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create a parameter list for the BPM_FIT computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param defaults default values + + Creates a parameterlist with the BPM_FIT parameters: + - base_context.prefix.degree + - base_context.prefix.pval + - base_context.prefix.rel-chi-low + - base_context.prefix.rel-chi-high + - base_context.prefix.rel-coef-low + - base_context.prefix.rel-coef-high + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_bpm_fit_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *defaults) +{ + cpl_ensure(prefix && base_context && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_bpm_fit_parameter_check(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist *parlist = cpl_parameterlist_new(); + + int degree_default = hdrl_bpm_fit_parameter_get_degree(defaults); + double pval_default = hdrl_bpm_fit_parameter_get_pval(defaults) ; + double rel_chi_low_default = + hdrl_bpm_fit_parameter_get_rel_chi_low(defaults) ; + double rel_chi_high_default = + hdrl_bpm_fit_parameter_get_rel_chi_high(defaults) ; + double rel_coef_low_default = + hdrl_bpm_fit_parameter_get_rel_coef_low(defaults) ; + double rel_coef_high_default = + hdrl_bpm_fit_parameter_get_rel_coef_high(defaults); + + hdrl_setup_vparameter(parlist, prefix, ".", "", "degree", base_context, + "Degree of polynomial to fit.", CPL_TYPE_INT, degree_default); + + hdrl_setup_vparameter(parlist, prefix, ".", "", "pval", base_context, + "p-value threshold (in percent). Fits with a p-value below " + "this threshold are considered bad pixels.", + CPL_TYPE_DOUBLE, pval_default); + + hdrl_setup_vparameter(parlist, prefix, ".", "", "rel-chi-low", base_context, + "Relative chi threshold. Pixels with with a chi value " + "smaller than mean - rel-threshold * stdev-of-chi are " + "considered bad pixels.", CPL_TYPE_DOUBLE, rel_chi_low_default); + + hdrl_setup_vparameter(parlist, prefix, ".", "", "rel-chi-high", base_context, + "Relative chi threshold. Pixels with with a chi value larger " + "than mean + rel-threshold * stdev-of-chi are " + "considered bad pixels.", CPL_TYPE_DOUBLE, rel_chi_high_default); + + hdrl_setup_vparameter(parlist, prefix, ".", "", "rel-coef-low", base_context, + "Relative fit coefficient threshold. Pixels with with a " + "coefficient value smaller than " + "mean +- rel-threshold * stdev-of-coeff are " + "considered bad pixels.", CPL_TYPE_DOUBLE, rel_coef_low_default); + + hdrl_setup_vparameter(parlist, prefix, ".", "", "rel-coef-high", base_context, + "Relative fit coefficient threshold. Pixels with with a " + "coefficient value larger than " + "mean +- rel-threshold * stdev-of-coeff are " + "considered bad pixels.", CPL_TYPE_DOUBLE, rel_coef_high_default); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Parse a parameterlist to create input parameters for the BPM_FIT + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return Input parameter for the BPM_FIT computation + + Reads a parameterlist in order to create BPM image parameters. + Expects a parameterlist containing: + - prefix.degree + - prefix.pval + - prefix.rel-chi-low + - prefix.rel-chi-high + - prefix.rel-coef-low + - prefix.rel-coef-high + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_fit_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name; + const cpl_parameter * par; + double pval = -1; + double rel_chi_l = -1; + double rel_chi_h = -1; + double rel_coef_l = -1; + double rel_coef_h = -1; + int degree; + + name = hdrl_join_string(".", 2, prefix, "degree"); + par = cpl_parameterlist_find_const(parlist, name); + if (par == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + degree = cpl_parameter_get_int(par); + cpl_free(name); + + name = hdrl_join_string(".", 2, prefix, "pval"); + par = cpl_parameterlist_find_const(parlist, name); + if (par) { + pval = cpl_parameter_get_double(par); + } + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "rel-chi-low"); + par = cpl_parameterlist_find_const(parlist, name); + if (par) { + rel_chi_l = cpl_parameter_get_double(par); + } + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "rel-chi-high"); + par = cpl_parameterlist_find_const(parlist, name); + if (par) { + rel_chi_h = cpl_parameter_get_double(par); + } + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "rel-coef-low"); + par = cpl_parameterlist_find_const(parlist, name); + if (par) { + rel_coef_l = cpl_parameter_get_double(par); + } + cpl_free(name); + + name = hdrl_join_string(".", 2, prefix, "rel-coef-high"); + par = cpl_parameterlist_find_const(parlist, name); + if (par) { + rel_coef_h = cpl_parameter_get_double(par); + } + cpl_free(name); + + if (cpl_error_get_code()) { + return NULL; + } + /* does verification */ + return hdrl_bpm_fit_parameter_create_all(degree, pval, + rel_chi_l, rel_chi_h, rel_coef_l, rel_coef_h); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief Utility to get a integer mask from a (stdev) relative threshold + * @param img image to threshold + * @param kappa_low (stdev) relative threshold + * @param kappa_high (stdev) relative threshold + * @param mad if true estimate stdev via mad + * @return integer mask where threshold is exceeded + */ +/* ---------------------------------------------------------------------------*/ +static cpl_image * +bpm_from_rel(cpl_image * img, double kappa_low, double kappa_high, int mad) +{ + cpl_image * r; + double m, s; + if (mad) { + m = cpl_image_get_mad(img, &s); + s *= CPL_MATH_STD_MAD; + s = CX_MAX(DBL_EPSILON, s); + } + else { + m = cpl_image_get_mean(img); + s = cpl_image_get_stdev(img); + } + cpl_mask * bpm = cpl_mask_threshold_image_create(img, m - s * kappa_low, + m + s * kappa_high); + cpl_mask_not(bpm); + r = cpl_image_new_from_mask(bpm); + cpl_mask_delete(bpm); + return r; +} + + + +/* ---------------------------------------------------------------------------*/ +/** + @brief compute bad pixel map based on fitting a stack of images + @param par input bpm_fit_parameter + @param data hdrl_imagelist to fit + @param sample_pos cpl_vector of sampling position of the images in data, + e.g. exposure time + @param out_mask output bad pixel mask as integer image + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + +The function fits a polynomial of degree \e degree to +the imagelist at the sampling positions defined in \e sample_pos. + +Three methods are available to convert the information from the fit +into a bad pixel map: + + +\li \c Relative cutoff on the chi distribution of all fits. Pixels + with chi values strictly outside the interval \f$ mean(\chi) - + stdev(\chi) \times rel\_chi\_low \f$ and \f$ mean(\chi) + + stdev(\chi) \times rel\_chi\_high \f$ are considered bad. The + corresponding hdrl parameter is created by + hdrl_bpm_fit_parameter_create_rel_chi() + +\li \c Relative cutoff on the distribution of the fit + coefficients. Pixels with fit coefficients strictly outside the + interval \f$ mean(coef) - stdev(coef) \times rel\_coef\_low + \f$ and \f$ mean(coef) + stdev(coef) \times rel\_coef\_high + \f$ are considered bad. The coefficient numbers that caused + the pixel to be marked as bad are encoded as powers of two of + their degree (starting from 0). The corresponding hdrl + parameter is created by + hdrl_bpm_fit_parameter_create_rel_coef() + +\li \c Pixels with low \e p-value. When the errors of the pixels are + correct the \e p-value can be interpreted as the probability + with which the pixel response fits the chosen model. The + corresponding hdrl parameter is created by + hdrl_bpm_fit_parameter_create_pval() + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_bpm_fit_compute(const hdrl_parameter * par, + const hdrl_imagelist * data, + const cpl_vector * sample_pos, + cpl_image ** out_mask) +{ + cpl_image * out_chi2 = NULL, * out_dof = NULL; + hdrl_imagelist * out_coef = NULL; + if (hdrl_bpm_fit_parameter_verify(par) != CPL_ERROR_NONE) + return cpl_error_get_code(); + + int degree = hdrl_bpm_fit_parameter_get_degree(par); + + /* TODO check for 0 error, + * in that case set to 1 and do not allow pval */ + + cpl_error_code err = hdrl_fit_polynomial_imagelist(data, sample_pos, degree, + &out_coef, &out_chi2, &out_dof); + if (err) { + return cpl_error_set_message(cpl_func, CPL_ERROR_FILE_NOT_FOUND, + "Fit failed"); + } + + if (cpl_image_count_rejected(out_chi2) == + (cpl_image_get_size_x(out_chi2) * cpl_image_get_size_y(out_chi2))) { + cpl_msg_error(cpl_func, "Too few good pixels to fit polynomial of " + "degree %d in all pixels", degree); + goto end; + } + + { + cpl_image * bpm = NULL; + double pval = hdrl_bpm_fit_parameter_get_pval(par); + double rel_chi_l = hdrl_bpm_fit_parameter_get_rel_chi_low(par); + double rel_chi_h = hdrl_bpm_fit_parameter_get_rel_chi_high(par); + double rel_coef_l = hdrl_bpm_fit_parameter_get_rel_coef_low(par); + double rel_coef_h = hdrl_bpm_fit_parameter_get_rel_coef_high(par); + + if (rel_chi_l >= 0) { + /* chi is symmetric */ + cpl_image_power(out_chi2, 0.5); + bpm = bpm_from_rel(out_chi2, rel_chi_l, rel_chi_h, 1); + } + else if (rel_coef_l >= 0) { + for (cpl_size i = 0; i < hdrl_imagelist_get_size(out_coef); i++) { + hdrl_image * coef = hdrl_imagelist_get(out_coef, i); + cpl_image * b = bpm_from_rel(hdrl_image_get_image(coef), + rel_coef_l, rel_coef_h, 0); + + /* bits of bpm defines which coefficient "bad" */ + if (bpm) { + cpl_image_multiply_scalar(b, pow(2, i)); + cpl_image_add(bpm, b); + cpl_image_delete(b); + } + else { + bpm = b; + } + } + } + else if (pval >= 0) { + pval /= 100.; + bpm = cpl_image_new(cpl_image_get_size_x(out_chi2), + cpl_image_get_size_y(out_chi2), + CPL_TYPE_INT); + int * md = cpl_image_get_data_int(bpm); + hdrl_data_t * cd = cpl_image_get_data(out_chi2); + hdrl_data_t * dd = cpl_image_get_data(out_dof); + for (size_t i = 0; i < (size_t)cpl_image_get_size_x(out_chi2) * + cpl_image_get_size_y(out_chi2); i++) { + double pv = igamc(dd[i] / 2., cd[i] / 2.); + md[i] = (pv < pval); + } + } + *out_mask = bpm; + } + +end: + hdrl_imagelist_delete(out_coef); + cpl_image_delete(out_chi2); + cpl_image_delete(out_dof); + + return cpl_error_get_code(); +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_fit.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_fit.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_fit.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_fit.h 2015-04-27 09:40:36.000000000 +0000 @@ -0,0 +1,82 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifndef HDRL_BPM_FIT_H +#define HDRL_BPM_FIT_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_parameter.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + BPM Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_bpm_fit_parameter_create_pval(int, double); +hdrl_parameter * hdrl_bpm_fit_parameter_create_rel_chi(int, double, double); +hdrl_parameter * hdrl_bpm_fit_parameter_create_rel_coef(int, double, double); +cpl_boolean hdrl_bpm_fit_parameter_check(const hdrl_parameter * self); +cpl_error_code hdrl_bpm_fit_parameter_verify(const hdrl_parameter *) ; + +/* Accessors */ +int hdrl_bpm_fit_parameter_get_degree(const hdrl_parameter *); +double hdrl_bpm_fit_parameter_get_pval(const hdrl_parameter *); +double hdrl_bpm_fit_parameter_get_rel_chi_low(const hdrl_parameter *); +double hdrl_bpm_fit_parameter_get_rel_chi_high(const hdrl_parameter *); +double hdrl_bpm_fit_parameter_get_rel_coef_low(const hdrl_parameter *); +double hdrl_bpm_fit_parameter_get_rel_coef_high(const hdrl_parameter *); + +/* Parameter Lists */ +cpl_parameterlist * hdrl_bpm_fit_parameter_create_parlist(const char *, + const char *, const hdrl_parameter *); +hdrl_parameter * hdrl_bpm_fit_parameter_parse_parlist( + const cpl_parameterlist *, + const char *); + +/*---------------------------------------------------------------------------- + BPM_FIT Computation + ----------------------------------------------------------------------------*/ + +cpl_error_code +hdrl_bpm_fit_compute(const hdrl_parameter * par, + const hdrl_imagelist * data, + const cpl_vector * sample_pos, + cpl_image ** out_mask); + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_utils.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_utils.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_utils.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_utils.c 2017-08-28 07:23:35.000000000 +0000 @@ -0,0 +1,318 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_utils.h" + +#include "hdrl_bpm_utils.h" +#include "hdrl_prototyping.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_utils Bad Pixel Utilities + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Wrapper around hdrl_bpm_filter() to filter list of images + @param inlist input image list + @param kernel_nx size in x-direction of the filtering kernel + @param kernel_ny size in y-direction of the filtering kernel + @param filter filter modes as defined in cpl + @return The filtered image list + @see hdrl_bpm_filter() + */ +/*----------------------------------------------------------------------------*/ +cpl_imagelist * hdrl_bpm_filter_list( + const cpl_imagelist * inlist, + cpl_size kernel_nx, + cpl_size kernel_ny, + cpl_filter_mode filter) +{ + cpl_imagelist * out ; + cpl_size nima; + + /* Check Entries */ + cpl_ensure(inlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + nima = cpl_imagelist_get_size(inlist) ; + + /* Create Output list */ + out = cpl_imagelist_new() ; + + /* Loop over the imagelist */ + for (cpl_size i = 0 ; i < nima ; i++) { + cpl_mask * mask_in, * mask_out; + /* Convert input image to mask */ + mask_in = cpl_mask_threshold_image_create( + cpl_imagelist_get_const(inlist, i), -0.5, 0.5); + cpl_mask_not(mask_in); + + /* Filter mask */ + mask_out = hdrl_bpm_filter(mask_in, kernel_nx, kernel_ny, filter) ; + cpl_mask_delete(mask_in) ; + if (mask_out == NULL) { + cpl_imagelist_delete(out) ; + return NULL ; + } + + /* Convert mask to image and store it in the list */ + cpl_imagelist_set(out, cpl_image_new_from_mask(mask_out), i); + cpl_mask_delete(mask_out) ; + } + return out ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Allows the growing and shrinking of bad pixel masks. It can be used to + e.g. set pixels to bad if the pixel is surrounded by other bad pixels. + @param input_mask input mask + @param kernel_nx size in x-direction of the filtering kernel + @param kernel_ny size in y-direction of the filtering kernel + @param filter filter modes as defined in cpl - see below + Supported modes: + CPL_FILTER_EROSION, CPL_FILTER_DILATION, CPL_FILTER_OPENING, + CPL_FILTER_CLOSING + + The returned mask must be deallocated using cpl_mask_delete(). + The algorithm assumes, that all pixels outside the mask are good, i.e. it + enlarges the mask by the kernel size and marks this border as good. It + applies on the enlarged mask the operation and extract the original-size + mask at the very end. + */ +/*----------------------------------------------------------------------------*/ +cpl_mask * hdrl_bpm_filter( + const cpl_mask * input_mask, + cpl_size kernel_nx, + cpl_size kernel_ny, + cpl_filter_mode filter) +{ + cpl_mask * kernel; + cpl_mask * filtered_mask; + cpl_mask * expanded_mask; + cpl_mask * expanded_filtered_mask; + + /* Check Entries */ + cpl_ensure(input_mask != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(kernel_nx >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(kernel_ny >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(filter == CPL_FILTER_EROSION || filter == CPL_FILTER_DILATION || + filter == CPL_FILTER_OPENING || filter == CPL_FILTER_CLOSING, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + /* Only odd-sized masks allowed */ + cpl_ensure((kernel_nx&1) == 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure((kernel_ny&1) == 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + + kernel = cpl_mask_new(kernel_nx, kernel_ny); + cpl_mask_not(kernel); /* All values set to unity*/ + + /* Enlarge the original mask with the kernel size and assume that outside + * all pixels are good */ + expanded_mask = cpl_mask_new( + cpl_mask_get_size_x(input_mask) + 2 * kernel_nx, + cpl_mask_get_size_y(input_mask) + 2 * kernel_ny); + + cpl_mask_copy(expanded_mask, input_mask, kernel_nx + 1, kernel_ny +1 ); + + expanded_filtered_mask = cpl_mask_new(cpl_mask_get_size_x(expanded_mask), + cpl_mask_get_size_y(expanded_mask)); + + if(cpl_mask_filter(expanded_filtered_mask, expanded_mask, kernel, filter, + CPL_BORDER_ZERO) != CPL_ERROR_NONE) { + + cpl_mask_delete(kernel); + cpl_mask_delete(expanded_filtered_mask); + cpl_mask_delete(expanded_mask); + return NULL; + } + + /* Extract the original mask from the expanded mask */ + filtered_mask = cpl_mask_extract(expanded_filtered_mask, + kernel_nx+1, kernel_ny + 1, + cpl_mask_get_size_x(input_mask) + kernel_nx, + cpl_mask_get_size_y(input_mask) + kernel_ny); + + + /* Free memory */ + cpl_mask_delete(kernel); + cpl_mask_delete(expanded_filtered_mask); + cpl_mask_delete(expanded_mask); + + return filtered_mask; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief convert bad pixel information mask to a cpl_mask + @param bpm integer image containing the bad pixel information + @param selection bit-mask selecting which values to set to bad + @return cpl_mask + @note as cpl only supports 32 bit integer images the top 32 bit of the + selection mask must be zero + */ +/*----------------------------------------------------------------------------*/ +cpl_mask * hdrl_bpm_to_mask(const cpl_image * bpm, uint64_t selection) +{ + cpl_ensure(bpm, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_image_get_type(bpm) == CPL_TYPE_INT, + CPL_ERROR_ILLEGAL_INPUT, NULL); + /* cpl currently only has int images, but use 64 for forward compat */ + cpl_ensure(selection <= CX_MAXUINT, CPL_ERROR_UNSUPPORTED_MODE, NULL); + unsigned int iselection = (unsigned int)selection; + const unsigned int * data=(const unsigned int *)cpl_image_get_data_int_const(bpm); + const size_t nx = cpl_image_get_size_x(bpm); + const size_t ny = cpl_image_get_size_y(bpm); + cpl_mask * msk = cpl_mask_new(nx, ny); + cpl_binary * dmsk = cpl_mask_get_data(msk); + for (size_t i = 0; i < ny * nx; i++) { + dmsk[i] = (data[i] & iselection) ? 1 : 0; + } + return msk; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief convert cpl_mask to bad pixel information mask + @param mask cpl_mask to be converted + @param flag bit-mask selecting which values to set the bad pixels to + @return integer cpl_image + @note as cpl only supports 32 bit integer images the top 32 bit of the + selection mask must be zero + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_mask_to_bpm(const cpl_mask * mask, uint64_t flag) +{ + cpl_ensure(mask, CPL_ERROR_NULL_INPUT, NULL); + /* cpl currently only has int images, but use 64 for forward compatibility */ + cpl_ensure(flag <= CX_MAXUINT, CPL_ERROR_UNSUPPORTED_MODE, NULL); + unsigned int iflag = (unsigned int)flag; + const size_t nx = cpl_mask_get_size_x(mask); + const size_t ny = cpl_mask_get_size_y(mask); + cpl_image * bpm = cpl_image_new(nx, ny, CPL_TYPE_INT); + const cpl_binary * dmsk = cpl_mask_get_data_const(mask); + unsigned int * data = (unsigned int *)cpl_image_get_data_int(bpm); + for (size_t i = 0; i < ny * nx; i++) { + data[i] = dmsk[i] ? iflag : 0; + } + return bpm; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief apply array of masks to an image list + @param list image list where the masks should be applied + @param masks array of masks, must have same length as the image list + + already existing masks will be overwritten + can be used to re-apply the original mask array returned by + hdrl_join_mask_on_imagelist + + Example:\code{.c} + cpl_mask ** orig_masks; + // change mask to get partial statistics from the list + hdrl_join_mask_on_imagelist(list, echelle_mask, &orig_masks); + stats = get_stats_from_echelle_orders(); + // restore original mask + hdrl_set_masks_on_imagelist(list, orig_masks); + // free memory + for (i = 0; i < cpl_imagelist_get_size(list); i++) { + cpl_mask_free(orig_masks[i]); + } + cpl_free(orig_masks); + \endcode + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_set_masks_on_imagelist( + cpl_imagelist * list, + cpl_mask ** masks) +{ + cpl_ensure_code(list, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(masks, CPL_ERROR_NULL_INPUT); + + for (size_t i = 0; i < (size_t)cpl_imagelist_get_size(list); i++) { + cpl_image * img = cpl_imagelist_get(list, i); + cpl_mask * img_mask = cpl_image_get_bpm(img); + /* zero mask */ + cpl_mask_xor(img_mask, img_mask); + /* add new mask */ + cpl_mask_or(img_mask, masks[i]); + } + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief join mask with existing masks in an imagelist + @param list imagelist where the new mask should be joined on + @param new_mask new mask joined with the masks in the images + @param pold_mask pointer to array pointer to store a copy of the original + masks, array and masks contained in it must be deleted by + the user, may be NULL in which case no copy is stored + @see hdrl_set_masks_on_imagelist + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_join_mask_on_imagelist( + cpl_imagelist * list, + cpl_mask * new_mask, + cpl_mask *** pold_mask) +{ + cpl_ensure_code(list, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(new_mask, CPL_ERROR_NULL_INPUT); + + if (pold_mask) { + *pold_mask = cpl_malloc(sizeof(*pold_mask) * + cpl_imagelist_get_size(list)); + } + + for (size_t i = 0; i < (size_t)cpl_imagelist_get_size(list); i++) { + cpl_image * img = cpl_imagelist_get(list, i); + cpl_mask * img_mask = cpl_image_get_bpm(img); + if (pold_mask) { + (*pold_mask)[i] = cpl_mask_duplicate(img_mask); + } + + cpl_mask_or(img_mask, new_mask); + } + return cpl_error_get_code(); +} + +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_utils.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_utils.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_bpm_utils.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_bpm_utils.h 2014-08-20 11:43:41.000000000 +0000 @@ -0,0 +1,56 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_BPM_UTILS_H +#define HDRL_BPM_UTILS_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include +#include "hdrl_image.h" +#include "hdrl_imagelist.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +cpl_mask * hdrl_bpm_filter(const cpl_mask *, cpl_size, cpl_size, cpl_filter_mode) ; +cpl_imagelist * hdrl_bpm_filter_list(const cpl_imagelist *, cpl_size, cpl_size, + cpl_filter_mode) ; + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE +cpl_mask * hdrl_bpm_to_mask(const cpl_image *, uint64_t) ; +cpl_image * hdrl_mask_to_bpm(const cpl_mask *, uint64_t) ; +cpl_error_code hdrl_set_masks_on_imagelist(cpl_imagelist *, cpl_mask **) ; +cpl_error_code hdrl_join_mask_on_imagelist(cpl_imagelist *, cpl_mask *, + cpl_mask ***); +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_buffer.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_buffer.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_buffer.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_buffer.c 2017-09-20 13:52:02.000000000 +0000 @@ -0,0 +1,331 @@ +/* $Id: hdrl_buffer.c,v 1.1 2013-10-23 09:13:56 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013,2014,2015 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112L /* posix_fallocate, ftruncate */ +/* posix 2001 not enough for ftruncate on glibc 2.12 (SL6.3) */ +#define _XOPEN_SOURCE 600 +#endif +#include "hdrl_buffer.h" +#include "hdrl_types.h" +#include "hdrl_utils.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +static int hdrl_fallocate(int fd, off_t offset, off_t len) +{ +#ifdef __APPLE__ + /* could be improved via fcntl(fd, F_PREALLOCATE, ...); */ + return ftruncate(fd, offset + len); +#else + return posix_fallocate(fd, offset, len); +#endif +} + +static const size_t hdrl_pool_minsize = 2<<20; + +struct _hdrl_buffer_ { + cx_list * pools; + cx_list * freelist; + size_t pool_size; + size_t total_size; + size_t malloc_thresh; +}; + +typedef struct { + char * base; + char * free_offset; + size_t size; + hdrl_free * destructor; +} hdrl_pool_base; + +typedef struct { + hdrl_pool_base p; + int fd; +} hdrl_pool_mmap; + +typedef struct { + hdrl_pool_base p; +} hdrl_pool_malloc; + +typedef hdrl_pool_base hdrl_pool; + +static void hdrl_pool_mmap_delete(void * pool) +{ + if (!pool) + return; + hdrl_pool_mmap * p = pool; + /* truncate temp file to stop writeback of dirty pages */ + if (ftruncate(p->fd, 0)) {} + munmap(p->p.base, p->p.size); + close(p->fd); +} + +static hdrl_pool * hdrl_pool_mmap_new(size_t pool_size) +{ + hdrl_pool_mmap * pool = cpl_malloc(sizeof(*pool)); + pool_size = CX_MAX(pool_size, hdrl_pool_minsize); + pool->p.destructor = &hdrl_pool_mmap_delete; + + /* Current working directory */ + char *cwd = hdrl_get_cwd(); + int cwd_fd = hdrl_get_tempfile(cwd, CPL_TRUE); + cpl_free(cwd); + + /* Allocate TMPDIR first as it usually is a fast disk */ + int tmp_fd = hdrl_get_tempfile(NULL, CPL_TRUE); + if (hdrl_fallocate(tmp_fd, 0, pool_size) != 0) { + close(tmp_fd); + if (hdrl_fallocate(cwd_fd, 0, pool_size) != 0) { + close(cwd_fd); + cpl_free(pool); + cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, + "Allocation of %zu bytes failed", pool_size); + return NULL; + } else { + pool->fd = cwd_fd; + } + } else { + pool->fd = tmp_fd; + } + + pool->p.base = mmap(NULL, pool_size, PROT_READ | PROT_WRITE, MAP_SHARED, + pool->fd, 0); + + if (pool->p.base == MAP_FAILED) { + close(pool->fd); + cpl_free(pool); + cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, + "Allocation of %zu bytes failed", pool_size); + return NULL; + } + + pool->p.size = pool_size; + pool->p.free_offset = pool->p.base; + + cpl_msg_debug(cpl_func, "Creating mmap pool %p of size %zu", + (const void*)pool, pool_size); + + return (hdrl_pool*)pool; +} + +static void hdrl_pool_malloc_delete(void * pool) +{ + if (!pool) + return; + cpl_free(((hdrl_pool*)pool)->base); +} + +static hdrl_pool * hdrl_pool_malloc_new(size_t pool_size) +{ + hdrl_pool_mmap * pool = cpl_malloc(sizeof(*pool)); + pool->p.size = CX_MAX(pool_size, hdrl_pool_minsize); + pool->p.destructor = &hdrl_pool_malloc_delete; + + pool->p.base = cpl_malloc(pool_size); + pool->p.free_offset = pool->p.base; + cpl_msg_debug(cpl_func, "Creating malloc pool %p of size %zu", + (const void*)pool, pool_size); + return (hdrl_pool*)pool; +} + +static void hdrl_pool_delete(hdrl_pool * pool) +{ + if (!pool) { + return; + } + + cpl_msg_debug(cpl_func, "Deleting pool %p", (const void*)pool); + pool->destructor(pool); + cpl_free(pool); +} + +static size_t hdrl_pool_available(hdrl_pool * p) +{ + return (p->base + p->size - p->free_offset); +} + +static char * hdrl_pool_alloc(hdrl_pool * p, size_t n) +{ + if (hdrl_pool_available(p) < n) { + return NULL; + } + char * b = p->free_offset; + p->free_offset += n; + cpl_msg_debug(cpl_func, "Allocating %zu from pool of size %zu (%zu)", + n, p->size, hdrl_pool_available(p)); + return b; +} + +static hdrl_pool * hdrl_pool_get_from_ptr(char * HDRL_UNUSED(p)) +{ + return NULL; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Create buffer object + * @param pool_size size of each memory pool + * @return buffer object useable to obtain memory mapped memory + */ +/* ---------------------------------------------------------------------------*/ +hdrl_buffer * hdrl_buffer_new(void) +{ + /* TODO pool_size probably does not need to be in api */ + hdrl_buffer * buf = cpl_malloc(sizeof(*buf)); + buf->pools = cx_list_new(); + buf->freelist = cx_list_new(); + buf->pool_size = 128ul * (1ul << 20ul); + buf->total_size = 0; + buf->malloc_thresh = 0; + + return buf; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief set total amount of memory the buffer can malloc + * + * @param buf buffer object + * @param t amount of memory in MiB + * + * @return old amount in wMiB + * @note changing threshold will only affect future allocation + */ +/* ---------------------------------------------------------------------------*/ +size_t hdrl_buffer_set_malloc_threshold(hdrl_buffer * buf, size_t t) +{ + size_t o = buf->malloc_thresh; + buf->malloc_thresh = t * (1ul << 20ul); + return o; +} + +void hdrl_buffer_readonly(hdrl_buffer * buf, cpl_boolean ro) +{ + /* TODO page alignment for malloc pool */ + for (cx_list_iterator it = cx_list_begin(buf->pools); + it != cx_list_end(buf->pools); + it = cx_list_next(buf->pools, it)) { + hdrl_pool * pool = cx_list_get(buf->pools, it); + if (ro) { + mprotect(pool->base, pool->size, PROT_READ); + } + else { + mprotect(pool->base, pool->size, PROT_READ | PROT_WRITE); + } + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Allocate memory block from buffer + * + * @param buf buffer object + * @param size size of memory to allocate + * + * @return writable memory block, or NULL on failure + */ +/* ---------------------------------------------------------------------------*/ +char * hdrl_buffer_allocate(hdrl_buffer * buf, size_t size) +{ + hdrl_pool * p = NULL; + char * m; + for (cx_list_iterator it = cx_list_begin(buf->freelist); + it != cx_list_end(buf->freelist); + it = cx_list_next(buf->freelist, it)) { + hdrl_pool * _p = cx_list_get(buf->freelist, it); + if (hdrl_pool_available(_p) >= size) { + p = _p; + cpl_msg_debug(cpl_func, "Found free available in pool."); + break; + } + } + + if (p == NULL) { + /* no free pool, clear freelist (TODO clear full pools earlier) */ + cx_list_empty(buf->freelist); + if (buf->total_size + size < buf->malloc_thresh || + getenv("HDRL_BUFFER_MALLOC")) { + p = hdrl_pool_malloc_new(CX_MAX(size, buf->pool_size)); + } + else { + p = hdrl_pool_mmap_new(CX_MAX(size, buf->pool_size)); + } + cx_list_push_back(buf->pools, p); + /* add new pool to freelist if it has free available left */ + if (size < buf->pool_size / 2) { + cx_list_push_back(buf->freelist, p); + } + } + + m = hdrl_pool_alloc(p, size); + buf->total_size += size; + return m; +} + +void hdrl_buffer_free(hdrl_buffer * HDRL_UNUSED(buf), char * p) +{ + hdrl_pool * pool = hdrl_pool_get_from_ptr(p); + if (pool) {} + /* TODO add free, only from top of pool should be simple, + * MADV_DONTNEED may be enough */ +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete buffer + * @param buf buffer + * + * Invalidates memory of all objects contained in the buffer + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_buffer_delete(hdrl_buffer * buf) +{ + if (!buf) { + return; + } + + cpl_msg_debug(cpl_func, "Deleting buffer with %zu pools", + cx_list_size(buf->pools)); + cx_list_destroy(buf->pools, (hdrl_free*)&hdrl_pool_delete); + cx_list_delete(buf->freelist); + cpl_free(buf); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_buffer.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_buffer.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_buffer.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_buffer.h 2017-08-29 10:37:21.000000000 +0000 @@ -0,0 +1,52 @@ +/* $Id: hdrl_buffer.h,v 1.2 2013-10-23 09:42:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-23 09:42:14 $ + * $Revision: 1.2 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_BUFFER_H +#define HDRL_BUFFER_H + +#include +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +typedef struct _hdrl_buffer_ hdrl_buffer; + +hdrl_buffer * hdrl_buffer_new(void); +void hdrl_buffer_readonly(hdrl_buffer * buf, cpl_boolean ro); +size_t hdrl_buffer_set_malloc_threshold(hdrl_buffer * buf, size_t t); +char * hdrl_buffer_allocate(hdrl_buffer *, size_t); +void hdrl_buffer_free(hdrl_buffer *, char *); +void hdrl_buffer_delete(hdrl_buffer *); +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_catalogue.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_catalogue.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_catalogue.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_catalogue.c 2017-10-13 09:59:32.000000000 +0000 @@ -0,0 +1,648 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include +#include +#include + +#include "hdrl_catalogue.h" +#include "hdrl_image.h" +#include "hdrl_types.h" +#include "hdrl_utils.h" + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + + + + +/** + * + * @defgroup hdrl_catalogue Object catalogue + * + * @brief + * This module provides algorithms to build an objects catalogue. + * Depending on the value of the control parameter "resulttype", additional + * products may be generated: a full catalogue, the background map, the + * segmentation map. + * + * \par Brief algorithm description: + * + * A local sky background is estimated and removed + * + * Objects and blends are detected and the image pixels are assigned to each + * object (or blend) they belong to. + * + * On the objects it is performed astrometry, photometry and shape analysis. + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + Catalogue parameters Definition + -----------------------------------------------------------------------------*/ + +/** @cond PRIVATE */ + +typedef struct { + HDRL_PARAMETER_HEAD; + int obj_min_pixels; + double obj_threshold; + cpl_boolean obj_deblending; + double obj_core_radius; + cpl_boolean bkg_estimate; + int bkg_mesh_size; + hdrl_catalogue_options resulttype; + double bkg_smooth_fwhm; + double det_eff_gain; + double det_saturation; +} hdrl_catalogue_parameter; + +/* parameter type */ +static hdrl_parameter_typeobj hdrl_catalogue_parameter_type = { + HDRL_PARAMETER_CATALOGUE, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_catalogue_parameter), /* obj_size */ +}; + +static cpl_error_code hdrl_cleanup_qclist(cpl_propertylist * qclist); + +/*----------------------------------------------------------------------------*/ +/** + * @internal + * @brief Verify basic correctness of the catalogue parameters + * @param param catalogue parameters + * @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_catalogue_parameter_verify(const hdrl_parameter * param) +{ + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_catalogue_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected catalogue parameter") ; + + const hdrl_catalogue_parameter * param_loc = (const hdrl_catalogue_parameter *)param ; + + cpl_error_ensure(param_loc->obj_min_pixels > 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "obj.min-pixels > 0"); + + cpl_error_ensure(param_loc->obj_threshold > 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "obj_threshold > 0."); + + cpl_error_ensure(param_loc->obj_core_radius > 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "obj_core_radius > 0."); + + if (param_loc->bkg_estimate) { + cpl_error_ensure(param_loc->bkg_mesh_size > 2, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "bkg_mesh_size > 2"); + + cpl_error_ensure(param_loc->bkg_smooth_fwhm >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "bkg_mesh_size >= 0."); + } + + cpl_error_ensure(param_loc->det_eff_gain > 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "det_eff_gain > 0."); + + cpl_error_ensure(param_loc->det_saturation > 0. || + param_loc->det_saturation == HDRL_SATURATION_INIT, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "det_saturation > 0"); + + return CPL_ERROR_NONE ; + +} + +/** @endcond */ + +/*----------------------------------------------------------------------------*/ +/** + * @brief Creates catalogue Parameters object + * + * @param obj_min_pixels Minimum pixel area for each detected object. + * @param obj_threshold Detection threshold in sigma above sky. + * @param obj_deblending Use deblending? + * @param obj_core_radius Value of Rcore in pixels. + * @param bkg_estimate Estimate background from input, if false it is assumed + * input is already background corrected with median 0. + * @param bkg_mesh_size Background smoothing box size. + * @param bkg_smooth_fwhm The FWHM of the Gaussian kernel used in convolution + * for object detection. + * @param det_eff_gain Detector gain value to rescale convert intensity to + * electrons. + * @param det_saturation Detector saturation value. + * @param resulttype Requested output: CAT (table), BKG(image), + * SEGMAP(image), QCLIST(propertylist). + * @return The catalogue parameters object. + * It needs to be deallocated with hdrl_parameter_delete() + * @see hdrl_parameter_delete() + * @see hdrl_catalogue_compute() + * The method creates a parameter to compute the catalogue + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_catalogue_parameter_create(int obj_min_pixels, + double obj_threshold, cpl_boolean obj_deblending, + double obj_core_radius, + cpl_boolean bkg_estimate, int bkg_mesh_size, + double bkg_smooth_fwhm, double det_eff_gain, + double det_saturation, + hdrl_catalogue_options resulttype) +{ + hdrl_catalogue_parameter * p = (hdrl_catalogue_parameter *) + hdrl_parameter_new(&hdrl_catalogue_parameter_type); + + p->obj_min_pixels = obj_min_pixels; + p->obj_threshold = obj_threshold; + p->obj_deblending = obj_deblending; + p->obj_core_radius = obj_core_radius; + p->bkg_estimate = bkg_estimate; + p->bkg_mesh_size = bkg_mesh_size; + p->resulttype = resulttype; + p->bkg_smooth_fwhm = bkg_smooth_fwhm; + p->det_eff_gain = det_eff_gain; + p->det_saturation = det_saturation; + + if (!bkg_estimate) { + p->resulttype &= ~(HDRL_CATALOGUE_BKG); + } + + if (hdrl_catalogue_parameter_verify((hdrl_parameter *)p)) { + cpl_free(p); + return NULL; + } + return (hdrl_parameter *)p; + +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Check that the parameter is a catalogue parameter + * @param self The parameter to check + * @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_catalogue_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_catalogue_parameter_type); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief set result option of catalogue parameter + * + * @param par hdrl catalogue parameter + * @param opt the options to set + * + * @return cpl_error_code + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_catalogue_parameter_set_option(hdrl_parameter * par, + hdrl_catalogue_options opt) +{ + cpl_ensure_code(par, CPL_ERROR_NULL_INPUT); + cpl_error_code err = hdrl_catalogue_parameter_verify(par); + if (err != CPL_ERROR_NONE) { + return err; + } + hdrl_catalogue_parameter * par_ = (hdrl_catalogue_parameter*)par; + par_->resulttype = opt; + if (!par_->bkg_estimate) { + par_->resulttype &= ~(HDRL_CATALOGUE_BKG); + } + return hdrl_catalogue_parameter_verify(par); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Create parameter list for the catalogue computation + * @param base_context base context of parameter (e.g. recipe name) + * @param prefix prefix of parameter, may be an empty string + * @param par_ hdrl_parameter defining the defaults + * @see hdrl_catalogue_parameter_create() + * + * + * Creates a parameter list with the catalogue parameters: + * - base_context.prefix.obj.min-pixels + * - base_context.prefix.obj.threshold + * - base_context.prefix.obj.deblending + * - base_context.prefix.obj.core-radius + * - base_context.prefix.bkg.estimate + * - base_context.prefix.bkg.mesh-size + * - base_context.prefix.bkg.smooth-gauss-size + * - base_context.prefix.det.effective-gain + * - base_context.prefix.det.saturation + * + * The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_catalogue_parameter_create_parlist( + const char *base_context, + const char *prefix, + hdrl_parameter *defaults) +{ + + cpl_ensure(prefix && base_context && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_catalogue_parameter_check(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + hdrl_catalogue_parameter *par = (hdrl_catalogue_parameter*)defaults; + + cpl_parameterlist *parlist = cpl_parameterlist_new(); + + hdrl_setup_vparameter(parlist, prefix, ".", "obj.", "min-pixels", + base_context, "Minimum pixel area for each detected " + "object.", CPL_TYPE_INT, par->obj_min_pixels); + + hdrl_setup_vparameter(parlist, prefix, ".", "obj.", "threshold", + base_context, + "Detection threshold in sigma above sky.", + CPL_TYPE_DOUBLE, par->obj_threshold); + + hdrl_setup_vparameter(parlist, prefix, ".", "obj.", "deblending", + base_context, "Use deblending?.", + CPL_TYPE_BOOL, par->obj_deblending); + + hdrl_setup_vparameter(parlist, prefix, ".", "obj.", "core-radius", + base_context, "Value of Rcore in pixels.", + CPL_TYPE_DOUBLE, par->obj_core_radius); + + hdrl_setup_vparameter(parlist, prefix, ".", "bkg.", "estimate", + base_context, "Estimate background from input, if " + "false it is assumed input is already background " + "corrected with median 0", + CPL_TYPE_BOOL, par->bkg_estimate); + + hdrl_setup_vparameter(parlist, prefix, ".", "bkg.", "mesh-size", + base_context, "Background smoothing box size.", + CPL_TYPE_INT, par->bkg_mesh_size); + + /* --prefix.result-type not an cpl option*/ + + hdrl_setup_vparameter(parlist, prefix, ".", "bkg.", "smooth-gauss-fwhm", + base_context, "The FWHM of the Gaussian kernel used " + "in convolution for object detection.", + CPL_TYPE_DOUBLE, par->bkg_smooth_fwhm); + + hdrl_setup_vparameter(parlist, prefix, ".", "det.", "effective-gain", + base_context, "Detector gain value to rescale " + "convert intensity to electrons", + CPL_TYPE_DOUBLE, par->det_eff_gain); + + hdrl_setup_vparameter(parlist, prefix, ".", "det.", "saturation", + base_context, "Detector saturation value", + CPL_TYPE_DOUBLE, par->det_saturation); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Parse parameter list to create input parameters for the catalogue + * @param parlist parameter list to parse + * @param prefix prefix of parameter name + * @return Input parameters for the catalogue computation + * + * Reads a parameter list in order to create catalogue parameters. + * + * Expects a parameter list containing: + * - base_context.prefix.obj.min-pixels + * - base_context.prefix.obj.threshold + * - base_context.prefix.obj.deblending + * - base_context.prefix.obj.core-radius + * - base_context.prefix.bkg.estimate + * - base_context.prefix.bkg.mesh-size + * - base_context.prefix.bkg.smooth-gauss-fwhm + * - base_context.prefix.det.effective-gain + * - base_context.prefix.det.saturation + * + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_catalogue_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name ; + const cpl_parameter * par; + int obj_min_pixels, bkg_mesh_size; + cpl_boolean obj_deblending, bkg_estimate; + double obj_threshold, obj_core_radius, bkg_smooth_fwhm, det_eff_gain, + det_saturation; + + + name = hdrl_join_string(".", 2, prefix, "obj.min-pixels"); + par = cpl_parameterlist_find_const(parlist, name); + obj_min_pixels = cpl_parameter_get_int(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "obj.threshold"); + par = cpl_parameterlist_find_const(parlist, name); + obj_threshold = cpl_parameter_get_double(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "obj.deblending"); + par = cpl_parameterlist_find_const(parlist, name); + obj_deblending = cpl_parameter_get_bool(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "obj.core-radius"); + par=cpl_parameterlist_find_const(parlist, name); + obj_core_radius = cpl_parameter_get_double(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "bkg.estimate"); + par = cpl_parameterlist_find_const(parlist, name); + bkg_estimate = cpl_parameter_get_bool(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "bkg.mesh-size"); + par = cpl_parameterlist_find_const(parlist, name); + bkg_mesh_size = cpl_parameter_get_int(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "bkg.smooth-gauss-fwhm"); + par = cpl_parameterlist_find_const(parlist, name); + bkg_smooth_fwhm = cpl_parameter_get_double(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "det.effective-gain"); + par = cpl_parameterlist_find_const(parlist, name); + det_eff_gain = cpl_parameter_get_double(par); + cpl_free(name) ; + + name = hdrl_join_string(".", 2, prefix, "det.saturation"); + par = cpl_parameterlist_find_const(parlist, name); + det_saturation = cpl_parameter_get_double(par); + cpl_free(name) ; + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist with prefix %s", prefix); + return NULL; + } else { + return hdrl_catalogue_parameter_create(obj_min_pixels, obj_threshold, + obj_deblending, obj_core_radius, + bkg_estimate, + bkg_mesh_size, bkg_smooth_fwhm, + det_eff_gain, det_saturation, + HDRL_CATALOGUE_ALL); + } + +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief delete hdrl parameter result object + * @param result hdrl parameter result object + * + * @return void + */ +/*----------------------------------------------------------------------------*/ +void hdrl_catalogue_result_delete(hdrl_catalogue_result * result) +{ + if (result == NULL) { + return; + } + cpl_table_delete(result->catalogue); + cpl_image_delete(result->background); + cpl_image_delete(result->segmentation_map); + cpl_propertylist_delete(result->qclist); + cpl_free(result); +} +/*----------------------------------------------------------------------------*/ +/** + * @brief build object catalog + * @param image_ input image + * @param confidence_map confidence map (optional input) + * @param wcs wcs information (optional input) + * @param param_ parameter structure controlling catalog determination + * + * @return void + */ +/*----------------------------------------------------------------------------*/ +hdrl_catalogue_result * +hdrl_catalogue_compute(const cpl_image * image_, const cpl_image * confidence_map, + const cpl_wcs * wcs, hdrl_parameter * param_) +{ + hdrl_casu_fits *inf,*inconf = NULL; + hdrl_casu_result * intres = NULL; + cpl_ensure(image_, CPL_ERROR_NULL_INPUT, NULL); + if (hdrl_catalogue_parameter_verify((hdrl_parameter *)param_)) { + return NULL; + } + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + + hdrl_catalogue_result * res = NULL; + const hdrl_catalogue_parameter * param = (hdrl_catalogue_parameter *)param_; + cpl_image * image = (cpl_image *)image_; + if (cpl_image_get_type(image) != CPL_TYPE_DOUBLE) { + image = cpl_image_cast(image, CPL_TYPE_DOUBLE); + } + + inf = hdrl_casu_fits_wrap((cpl_image *)image); + + cpl_image * conf_ = (cpl_image*)confidence_map; + + CPL_DIAG_PRAGMA_POP; + + + if (confidence_map) { + if (cpl_image_get_min(confidence_map) < 0) { + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "confidence_map must only contain " + "positive numbers"); + goto cleanup; + } + } + + if (cpl_image_get_bpm_const(image) != NULL) { + if (confidence_map) { + conf_ = cpl_image_cast(confidence_map, CPL_TYPE_DOUBLE); + } + else { + conf_ = cpl_image_new(cpl_image_get_size_x(image), + cpl_image_get_size_y(image), CPL_TYPE_DOUBLE); + cpl_image_add_scalar(conf_, 100); + } + cpl_image_reject_from_mask(conf_, cpl_image_get_bpm_const(image)); + cpl_image_fill_rejected(conf_, 0); + cpl_image_accept_all(conf_); + } + else if (confidence_map && + cpl_image_get_type(confidence_map) != CPL_TYPE_DOUBLE) { + conf_ = cpl_image_cast(confidence_map, CPL_TYPE_DOUBLE); + } + inconf = hdrl_casu_fits_wrap((cpl_image *)conf_); + + /* Run catalogue */ + res = cpl_calloc(sizeof(hdrl_catalogue_result), 1); + intres = cpl_calloc(sizeof(hdrl_casu_result), 1); + hdrl_casu_catalogue(inf, inconf, wcs, + param->obj_min_pixels, param->obj_threshold, + param->obj_deblending, param->obj_core_radius, + param->bkg_estimate, + param->bkg_mesh_size, (int)param->resulttype, + param->bkg_smooth_fwhm, param->det_eff_gain, + param->det_saturation, intres); + + if (intres->catalogue) { + res->catalogue = cpl_table_duplicate( hdrl_casu_tfits_get_table(intres->catalogue)); + res->qclist = cpl_propertylist_duplicate(hdrl_casu_tfits_get_ehu( intres->catalogue)); + hdrl_cleanup_qclist(res->qclist); + } + res->segmentation_map = intres->segmentation_map; + res->background = intres->background; + +cleanup: + inf->image = NULL; + if (image_ != image) { + cpl_image_delete(image); + } + if (inconf && inconf->image == confidence_map) { + inconf->image = NULL; + } + hdrl_casu_fits_delete(inf); + if (intres) { + hdrl_casu_tfits_delete(intres->catalogue); + } + hdrl_casu_fits_delete(inconf); + cpl_free(intres); + + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Cleaning of the quality control propertylist + * @param qclist propertylist to be cleaned + * @return cpl_error_code + */ + +static cpl_error_code hdrl_cleanup_qclist(cpl_propertylist * qclist){ + + cpl_propertylist * qclocal = cpl_propertylist_duplicate(qclist); + cpl_propertylist_empty(qclist); + + if (cpl_propertylist_has(qclocal, "APCOR1")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR1"); + if (cpl_propertylist_has(qclocal, "APCOR2")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR2"); + if (cpl_propertylist_has(qclocal, "APCOR3")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR3"); + if (cpl_propertylist_has(qclocal, "APCOR4")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR4"); + if (cpl_propertylist_has(qclocal, "APCOR5")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR5"); + if (cpl_propertylist_has(qclocal, "APCOR6")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR6"); + if (cpl_propertylist_has(qclocal, "APCOR7")) + cpl_propertylist_copy_property(qclist, qclocal, "APCOR7"); + if (cpl_propertylist_has(qclocal, "APCORPK")) + cpl_propertylist_copy_property(qclist, qclocal, "APCORPK"); + if (cpl_propertylist_has(qclocal, "SYMBOL1")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL1"); + if (cpl_propertylist_has(qclocal, "SYMBOL2")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL2"); + if (cpl_propertylist_has(qclocal, "SYMBOL3")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL3"); + if (cpl_propertylist_has(qclocal, "SYMBOL4")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL4"); + if (cpl_propertylist_has(qclocal, "SYMBOL5")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL5"); + if (cpl_propertylist_has(qclocal, "SYMBOL6")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL6"); + if (cpl_propertylist_has(qclocal, "SYMBOL7")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL7"); + if (cpl_propertylist_has(qclocal, "SYMBOL8")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL8"); + if (cpl_propertylist_has(qclocal, "SYMBOL9")) + cpl_propertylist_copy_property(qclist, qclocal, "SYMBOL9"); + +/* + if (cpl_propertylist_has(qclocal, "ESO DRS CLASSIFD")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS CLASSIFD"); + if (cpl_propertylist_has(qclocal, "ESO DRS CROWDED")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS CROWDED"); + if (cpl_propertylist_has(qclocal, "ESO DRS FILTFWHM")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS FILTFWHM"); + if (cpl_propertylist_has(qclocal, "ESO DRS MINPIX")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS MINPIX"); + if (cpl_propertylist_has(qclocal, "ESO DRS NXOUT")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS NXOUT"); + if (cpl_propertylist_has(qclocal, "ESO DRS NYOUT")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS NYOUT"); + if (cpl_propertylist_has(qclocal, "ESO DRS RCORE")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS RCORE"); + if (cpl_propertylist_has(qclocal, "ESO DRS SEEING")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS SEEING"); + if (cpl_propertylist_has(qclocal, "ESO DRS THRESHOL")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS THRESHOL"); + if (cpl_propertylist_has(qclocal, "ESO DRS XCOL")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS XCOL"); + if (cpl_propertylist_has(qclocal, "ESO DRS YCOL")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO DRS YCOL"); + if (cpl_propertylist_has(qclocal, "ESO QC APERTURE_CORR")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC APERTURE_CORR"); + if (cpl_propertylist_has(qclocal, "ESO QC ELLIPTICITY")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC ELLIPTICITY"); + if (cpl_propertylist_has(qclocal, "ESO QC IMAGE_SIZE")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC IMAGE_SIZE"); + if (cpl_propertylist_has(qclocal, "ESO QC MEAN_SKY")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC MEAN_SKY"); + if (cpl_propertylist_has(qclocal, "ESO QC NOISE_OBJ")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC NOISE_OBJ"); + if (cpl_propertylist_has(qclocal, "ESO QC POSANG")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC POSANG"); + if (cpl_propertylist_has(qclocal, "ESO QC SATURATION")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC SATURATION"); + if (cpl_propertylist_has(qclocal, "ESO QC SKY_NOISE")) + cpl_propertylist_copy_property(qclist, qclocal, "ESO QC SKY_NOISE"); + if (cpl_propertylist_has(qclocal, "HISTORY")) + cpl_propertylist_copy_property(qclist, qclocal, "HISTORY"); + +*/ + + cpl_propertylist_delete(qclocal); + + return cpl_error_get_code(); +} +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_catalogue.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_catalogue.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_catalogue.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_catalogue.h 2017-10-17 13:49:42.000000000 +0000 @@ -0,0 +1,90 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifndef HDRL_CATALOGUE_H +#define HDRL_CATALOGUE_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include + +#include "catalogue/hdrl_cat_conf.h" + +#include "hdrl_types.h" +#include "hdrl_image.h" + + + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + + +typedef struct { + cpl_table * catalogue; + cpl_image * segmentation_map; + cpl_image * background; + cpl_propertylist * qclist; +} hdrl_catalogue_result; + + + +hdrl_catalogue_result * +hdrl_catalogue_compute(const cpl_image * image_, const cpl_image * confidence_map, + const cpl_wcs * wcs, hdrl_parameter * param_); +void hdrl_catalogue_result_delete(hdrl_catalogue_result * result); + +hdrl_parameter * hdrl_catalogue_parameter_create(int obj_min_pixels, + double obj_threshold, cpl_boolean obj_deblending, + double obj_core_radius, + cpl_boolean bkg_estimate, int bkg_mesh_size, + double bkg_smooth_fwhm, double det_eff_gain, + double det_saturation, + hdrl_catalogue_options resulttype); +cpl_error_code hdrl_catalogue_parameter_set_option(hdrl_parameter * par, + hdrl_catalogue_options opt); +cpl_boolean hdrl_catalogue_parameter_check(const hdrl_parameter * self); +hdrl_parameter * hdrl_catalogue_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix); +cpl_parameterlist * hdrl_catalogue_parameter_create_parlist( + const char * base_context, + const char * prefix, + hdrl_parameter * defaults); + + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_collapse.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_collapse.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_collapse.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_collapse.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,2126 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_collapse.h" +#include "hdrl_parameter.h" +#include "hdrl_parameter_defs.h" +#include "hdrl_sigclip.h" +#include "hdrl_utils.h" +#include "hdrl_types.h" +#include + +#include +#include +/*----------------------------------------------------------------------------- + Types +-----------------------------------------------------------------------------*/ + +/* function performing imglist -> image reduction */ +typedef cpl_error_code (hdrl_collapse_imagelist_to_image_f)( + const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, + cpl_image ** err, + cpl_image ** contrib, + void * parameters, + void * extra_out); + +struct hdrl_collapse_imagelist_to_image_s { + /* function performing imglist -> image reduction */ + hdrl_collapse_imagelist_to_image_f * func; + /* create extra out storage */ + void * (*create_eout)(const cpl_image *); + /* move extra out storage */ + cpl_error_code (*move_eout)(void *, void *, const cpl_size); + /* unwrap extra out storage */ + hdrl_free * unwrap_eout; + /* delete extra out storage */ + void (*delete_eout)(void *); + /* parameters the reduction function requires */ + hdrl_parameter * parameters; +}; + +/* function performing imglist -> image reduction */ +typedef cpl_error_code (hdrl_collapse_imagelist_to_vector_f)( + const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, + cpl_vector ** err, + cpl_array ** contrib, + void * parameters, + void * extra_out); + +struct hdrl_collapse_imagelist_to_vector_s { + /* function performing imglist -> vector reduction */ + hdrl_collapse_imagelist_to_vector_f * func; + /* create extra out storage */ + void * (*create_eout)(cpl_size); + /* move extra out storage */ + cpl_error_code (*move_eout)(void *, void *, const cpl_size); + /* unwrap extra out storage */ + hdrl_free * unwrap_eout; + /* delete extra out storage */ + void (*delete_eout)(void *); + /* parameters the reduction function requires */ + hdrl_parameter * parameters; +}; + +static cpl_error_code +hdrl_collapse_mean(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, void *, void *); +static cpl_error_code +hdrl_collapse_median(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, void *, void *); +static cpl_error_code +hdrl_collapse_sigclip(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * parameters, void * extra_out); + +static cpl_error_code +hdrl_collapse_minmax(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * parameters, void * extra_out); + +static cpl_error_code +hdrl_collapse_weighted_mean(const cpl_imagelist * data_, + const cpl_imagelist * errors_, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, void *, void *); + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_collapse Collapse Parameters + + This module provides collapse parameters to be used by hdrl_image and + hdrl_imagelist objects. + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/** @cond PRIVATE */ + + +/*----------------------------------------------------------------------------- + Collapse Parameters + -----------------------------------------------------------------------------*/ +static void hdrl_nop_free(void * HDRL_UNUSED(x)) +{ + return; +} + +static void * hdrl_mean_alloc(size_t n); +static void * hdrl_median_alloc(size_t n); +static void * hdrl_weighted_mean_alloc(size_t n); + +/* Mean COLLAPSE */ +typedef hdrl_parameter_empty hdrl_collapse_mean_parameter; +static hdrl_parameter_typeobj hdrl_collapse_mean_parameter_type = { + HDRL_PARAMETER_COLLAPSE_MEAN, /* type */ + (hdrl_alloc *)&hdrl_mean_alloc, /* fp_alloc */ + (hdrl_free *)&hdrl_nop_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_collapse_mean_parameter), /* obj_size */ +}; + +HDRL_PARAMETER_SINGLETON(HDRL_COLLAPSE_MEAN, + hdrl_collapse_mean_parameter_type, + hdrl_mean_alloc); + +/* Median COLLAPSE */ +typedef hdrl_parameter_empty hdrl_collapse_median_parameter; +static hdrl_parameter_typeobj hdrl_collapse_median_parameter_type = { + HDRL_PARAMETER_COLLAPSE_MEDIAN, /* type */ + (hdrl_alloc *)&hdrl_median_alloc, /* fp_alloc */ + (hdrl_free *)&hdrl_nop_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_collapse_median_parameter), /* obj_size */ +}; + +HDRL_PARAMETER_SINGLETON(HDRL_COLLAPSE_MEDIAN, + hdrl_collapse_median_parameter_type, + hdrl_median_alloc); + +/* Weighted Mean COLLAPSE */ +typedef hdrl_parameter_empty hdrl_collapse_weighted_mean_parameter; +static hdrl_parameter_typeobj hdrl_collapse_weighted_mean_parameter_type = { + HDRL_PARAMETER_COLLAPSE_WEIGHTED_MEAN, /* type */ + (hdrl_alloc *)&hdrl_weighted_mean_alloc, /* fp_alloc */ + (hdrl_free *)&hdrl_nop_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_collapse_weighted_mean_parameter), /* obj_size */ +}; + +HDRL_PARAMETER_SINGLETON(HDRL_COLLAPSE_WEIGHTED_MEAN, + hdrl_collapse_weighted_mean_parameter_type, + hdrl_weighted_mean_alloc); + +/* Sigma-Clipping COLLAPSE */ +typedef struct { + HDRL_PARAMETER_HEAD; + double kappa_low; + double kappa_high; + int niter; +} hdrl_collapse_sigclip_parameter; +static hdrl_parameter_typeobj hdrl_collapse_sigclip_parameter_type = { + HDRL_PARAMETER_COLLAPSE_SIGCLIP, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_collapse_sigclip_parameter), /* obj_size */ +}; + + +/* Minmax-Clipping COLLAPSE */ +typedef struct { + HDRL_PARAMETER_HEAD; + double nlow; + double nhigh; +} hdrl_collapse_minmax_parameter; +static hdrl_parameter_typeobj hdrl_collapse_minmax_parameter_type = { + HDRL_PARAMETER_COLLAPSE_MINMAX, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_collapse_minmax_parameter), /* obj_size */ +}; + + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a parameter object for mean + * @return hdrl_parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_collapse_mean_parameter_create(void) +{ + hdrl_parameter_empty * p = (hdrl_parameter_empty *) + hdrl_parameter_new(&hdrl_collapse_mean_parameter_type); + return (hdrl_parameter *)p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief check if parameter is a mean parameter + * @return boolean + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_collapse_parameter_is_mean(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_collapse_mean_parameter_type); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a parameter object for median + * @return hdrl_parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_collapse_median_parameter_create(void) +{ + hdrl_parameter_empty * p = (hdrl_parameter_empty *) + hdrl_parameter_new(&hdrl_collapse_median_parameter_type); + return (hdrl_parameter *)p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief check if parameter is a median parameter + * @return boolean + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_collapse_parameter_is_median(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_collapse_median_parameter_type); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a parameter object for weighted mean + * @return hdrl_parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_collapse_weighted_mean_parameter_create(void) +{ + hdrl_parameter_empty * p = (hdrl_parameter_empty *) + hdrl_parameter_new(&hdrl_collapse_weighted_mean_parameter_type); + return (hdrl_parameter *)p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief check if parameter is a weighted mean parameter + * @return boolean + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_collapse_parameter_is_weighted_mean( + const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, + &hdrl_collapse_weighted_mean_parameter_type); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a parameter object for sigclipped mean + * + * @param kappa_low low kappa multiplier + * @param kappa_high high kappa multiplier + * @param niter maximum number of clipping iterations + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_collapse_sigclip_parameter_create(double kappa_low, double kappa_high, int niter) +{ + hdrl_collapse_sigclip_parameter * p = (hdrl_collapse_sigclip_parameter *) + hdrl_parameter_new(&hdrl_collapse_sigclip_parameter_type); + p->kappa_low = kappa_low; + p->kappa_high = kappa_high; + p->niter = niter; + + if (hdrl_collapse_sigclip_parameter_verify((hdrl_parameter*)p) != + CPL_ERROR_NONE) { + hdrl_parameter_delete((hdrl_parameter*)p); + return NULL; + } + return (hdrl_parameter *)p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief check if parameter is a sigclip mean parameter + * @return boolean + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_collapse_parameter_is_sigclip(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, + &hdrl_collapse_sigclip_parameter_type); +} + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Verify basic correctness of the parameters + @param param Collapse siglip parameters + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_collapse_sigclip_parameter_verify( + const hdrl_parameter * param) +{ + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, + "NULL Collapse Sigclip Parameters"); + + cpl_error_ensure(hdrl_collapse_parameter_is_sigclip(param), + CPL_ERROR_INCOMPATIBLE_INPUT, return + CPL_ERROR_INCOMPATIBLE_INPUT, + "Not a Sigclip parameter"); + + const hdrl_collapse_sigclip_parameter * param_loc = + (const hdrl_collapse_sigclip_parameter *)param ; + + cpl_error_ensure(param_loc->niter > 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "sigma-clipping iter (%d) value must be > 0", + param_loc->niter); + + return CPL_ERROR_NONE ; +} + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get low kappa + * @param p parameter + * @return kappa_low if p is of sigclip type + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_collapse_sigclip_parameter_get_kappa_high(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(hdrl_collapse_parameter_is_sigclip(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1); + + return ((const hdrl_collapse_sigclip_parameter *)p)->kappa_high; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get high kappa + * @param p parameter + * @return kappa_high if p is of sigclip type + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_collapse_sigclip_parameter_get_kappa_low(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(hdrl_collapse_parameter_is_sigclip(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1); + + return ((const hdrl_collapse_sigclip_parameter *)p)->kappa_low; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get maximum number of clipping iterations + * @param p parameter + * @return n if p is of sigclip type + */ +/* ---------------------------------------------------------------------------*/ +int hdrl_collapse_sigclip_parameter_get_niter(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(hdrl_collapse_parameter_is_sigclip(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1); + + return ((const hdrl_collapse_sigclip_parameter *)p)->niter; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a parameter object for min-max rejected mean + * + * @param nlow number of low pixels to be rejected + * @param nhigh number of high pixels to be rejected + * @return minmax collapse parameter or NULL on error + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_collapse_minmax_parameter_create(double nlow, double nhigh) +{ + hdrl_collapse_minmax_parameter * p = (hdrl_collapse_minmax_parameter *) + hdrl_parameter_new(&hdrl_collapse_minmax_parameter_type); + p->nlow = nlow; + p->nhigh = nhigh; + + if (hdrl_collapse_minmax_parameter_verify((hdrl_parameter*)p) != + CPL_ERROR_NONE) { + hdrl_parameter_delete((hdrl_parameter*)p); + return NULL; + } + return (hdrl_parameter *)p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief check if parameter is a minmax mean parameter + * @return boolean + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_collapse_parameter_is_minmax(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, + &hdrl_collapse_minmax_parameter_type); +} + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Verify basic correctness of the parameters + @param param Collapse minmax parameters + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_collapse_minmax_parameter_verify( + const hdrl_parameter * param) +{ + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, + "NULL Collapse Minmax Parameters"); + + cpl_error_ensure(hdrl_collapse_parameter_is_minmax(param), + CPL_ERROR_INCOMPATIBLE_INPUT, return + CPL_ERROR_INCOMPATIBLE_INPUT, + "Not a minmax parameter"); + + const hdrl_collapse_minmax_parameter * param_loc = + (const hdrl_collapse_minmax_parameter *)param ; + + cpl_error_ensure(param_loc->nlow >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "nlow value (%g) must be >= 0", + param_loc->nlow); + + cpl_error_ensure(param_loc->nhigh >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "nhigh value (%g) must be >= 0", + param_loc->nlow); + + return CPL_ERROR_NONE ; +} + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get low value + * @param p parameter + * @return nlow if p is of minmax type + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_collapse_minmax_parameter_get_nhigh(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(hdrl_collapse_parameter_is_minmax(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1); + + return ((const hdrl_collapse_minmax_parameter *)p)->nhigh; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get high value + * @param p parameter + * @return nhigh if p is of minmax type + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_collapse_minmax_parameter_get_nlow(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(hdrl_collapse_parameter_is_minmax(p), + CPL_ERROR_INCOMPATIBLE_INPUT, -1); + + return ((const hdrl_collapse_minmax_parameter *)p)->nlow; +} + + +/* ---------------------------------------------------------------------------*/ +/** + @brief Create parameters for the collapse + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param method_def default collapse method + @param sigclip_def default sigclip parameters + @param minmax_def default minmax parameters + @return The created parameter list + Creates a parameterlist containing + base_context.prefix.method + base_context.prefix.sigclip.* + The CLI aliases omit the base_context. + */ +/* ---------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_collapse_parameter_create_parlist( + const char *base_context, + const char *prefix, + const char *method_def, + hdrl_parameter *sigclip_def, + hdrl_parameter *minmax_def) +{ + cpl_ensure(base_context && prefix, CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure( hdrl_collapse_parameter_is_sigclip(sigclip_def) + && hdrl_collapse_parameter_is_minmax( minmax_def ), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + char *name; + cpl_parameterlist *parlist = cpl_parameterlist_new(); + cpl_parameter *p; + char *context = hdrl_join_string(".", 2, base_context, prefix); + + /* --prefix.method */ + name = hdrl_join_string(".", 2, context, "method"); + p = cpl_parameter_new_enum(name, CPL_TYPE_STRING, + "Method used for collapsing the data", context, + method_def, 5, "MEAN", "WEIGHTED_MEAN", "MEDIAN", "SIGCLIP", + "MINMAX"); + cpl_free(name) ; + name = hdrl_join_string(".", 2, prefix, "method"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); + cpl_free(name) ; + cpl_parameterlist_append(parlist, p); + + /* --prefix.sigclip.xxx */ + name = hdrl_join_string(".", 2, prefix, "sigclip"); + cpl_parameterlist * psigclip = hdrl_sigclip_parameter_create_parlist( + base_context, name, sigclip_def); + cpl_free(name) ; + + for (cpl_parameter * par = cpl_parameterlist_get_first(psigclip); + par != NULL; + par = cpl_parameterlist_get_next(psigclip)) { + cpl_parameterlist_append(parlist, cpl_parameter_duplicate(par)); + } + cpl_parameterlist_delete(psigclip); + + /* --prefix.minmax.xxx */ + name = hdrl_join_string(".", 2, prefix, "minmax"); + cpl_parameterlist * pminmax = hdrl_minmax_parameter_create_parlist( + base_context, name, minmax_def); + cpl_free(name) ; + + + for (cpl_parameter * par = cpl_parameterlist_get_first(pminmax); + par != NULL; + par = cpl_parameterlist_get_next(pminmax)) { + cpl_parameterlist_append(parlist, cpl_parameter_duplicate(par)); + } + cpl_parameterlist_delete(pminmax); + + + cpl_free(context); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief parse parameterlist for imagelist reduction method + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return hdrl_parameter + Reads a Parameterlist in order to create collapse parameters. + Expects a parameterlist containing + prefix.method + prefix.sigclip.* + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_collapse_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + hdrl_parameter * p = NULL; + + /* Get the Method parameter */ + char * name = hdrl_join_string(".", 2, prefix, "method"); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + const char * value = cpl_parameter_get_string(par); + if (value == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + + /* Switch on the methods */ + if(!strcmp(value, "MEDIAN")) { + p = hdrl_collapse_median_parameter_create(); + } else if (!strcmp(value, "WEIGHTED_MEAN")) { + p = hdrl_collapse_weighted_mean_parameter_create(); + } else if (!strcmp(value, "MEAN")) { + p = hdrl_collapse_mean_parameter_create(); + } else if (!strcmp(value, "SIGCLIP")) { + double kappa_low, kappa_high; + int niter; + hdrl_sigclip_parameter_parse_parlist(parlist, prefix, &kappa_low, + &kappa_high, &niter); + p = hdrl_collapse_sigclip_parameter_create(kappa_low,kappa_high,niter); + } else if (!strcmp(value, "MINMAX")) { + double nlow, nhigh; + hdrl_minmax_parameter_parse_parlist(parlist, prefix, &nlow, + &nhigh); + p = hdrl_collapse_minmax_parameter_create(nlow,nhigh); + } else { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "%s not a valid method for %s", value, name); + cpl_free(name); + return NULL; + } + cpl_free(name); + return p; +} + +/** @cond PRIVATE */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a new imagelist wrapping errors with same bpm as data + * + * @param data data list + * @param errors error list + * @returns cpl_imagelist which needs deleted with unwrap_synced_errlist + * + * Creates a new imagelist containing the wrapped data from the error list but + * the bad pixel map from the data list. + * This avoids issues with desynchronized bad pixel maps and avoids modifiying + * the inputs for collapse operations. + */ +/* ---------------------------------------------------------------------------*/ +static cpl_imagelist * +wrap_synced_errlist(const cpl_imagelist * data, const cpl_imagelist * errors) +{ + cpl_imagelist * nerrors = cpl_imagelist_new(); + for (size_t i = 0; i < (size_t)cpl_imagelist_get_size(errors); i++) { + const cpl_image * img = cpl_imagelist_get_const(data, i); + const cpl_image * err = cpl_imagelist_get_const(errors, i); + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + + cpl_image * nerr = cpl_image_wrap(cpl_image_get_size_x(err), + cpl_image_get_size_y(err), + cpl_image_get_type(err), + (void*)cpl_image_get_data_const(err)); + cpl_mask_delete(hcpl_image_set_bpm(nerr, + (cpl_mask*)cpl_image_get_bpm_const(img))); + + CPL_DIAG_PRAGMA_POP; + + cpl_imagelist_set(nerrors, nerr, i); + } + return nerrors; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief unwrap imagelist created with wrap_synced_errlist + * + * @param nerrors imagelist from wrap_synced_errlist + */ +/* ---------------------------------------------------------------------------*/ +static void +unwrap_synced_errlist(cpl_imagelist * nerrors) +{ + for (size_t i = 0; i < (size_t)cpl_imagelist_get_size(nerrors); i++) { + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + + cpl_image * err = (cpl_image*)cpl_imagelist_get_const(nerrors, i); + + CPL_DIAG_PRAGMA_POP; + + cpl_image_unset_bpm(err); + cpl_image_unwrap(err); + } + cpl_imagelist_unwrap(nerrors); +} + +/* ---------------------------------------------------------------------------*/ +/** + @internal + @brief calculate sum of squares of an imagelist + @param data imagelist + @param contrib if not NULL contribution map of reduction is stored + @return image containing the sum of squares along the imagelist axis + equivalent to: + cpl_imagelist_power(data, 2.) + sqlist = cpl_imagelist_collapse_create(data) + cpl_image_multiply(sqlist, contrib); + */ +/* ---------------------------------------------------------------------------*/ +static cpl_image * imagelist_sqsum( + const cpl_imagelist * data, + cpl_image ** pcontrib) +{ + cpl_image * contrib = cpl_image_new_from_accepted(data); + cpl_image * res = NULL; + + for (cpl_size i = 0; i < cpl_imagelist_get_size(data); i++) { + const cpl_image * img = cpl_imagelist_get_const(data, i); + cpl_image * sqerr = cpl_image_multiply_create(img, img); + if (cpl_image_get_bpm_const(sqerr)) { + cpl_image_fill_rejected(sqerr, 0.0); + cpl_image_accept_all(sqerr); + } + + if (i == 0) { + res = sqerr; + } else { + cpl_image_add(res, sqerr); + cpl_image_delete(sqerr); + } + } + cpl_mask * allbad = cpl_mask_threshold_image_create(contrib, 0, 0); + cpl_image_reject_from_mask(res, allbad); + cpl_mask_delete(allbad); + + if (pcontrib) + *pcontrib = contrib; + else + cpl_image_delete(contrib); + + return res; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements mean combination on input image list + * + * @param data input data images + * @param errors input errors images + * @param out output combined images + * @param err output combined errors + * @param contrib output contribution mask + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * + * @return cpl_error_code + * + * @doc + * Mean and associated error are computed with standard formulae + * + * \f$ + * x_{mean}=\frac{(\sum_{i}^{n} x_{i})} { n } + * \f$ + * + * \f$ + * \sigma_{x}=\sqrt{ \frac{ \sum_{i}^{n} x_{i}^{2} }{ n } } + * \f$ + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_collapse_mean(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * HDRL_UNUSED(parameters), + void * HDRL_UNUSED(extra_out)) +{ + /* (\Sum_i^n x_i) / n */ + /* \sqrt(\Sum_i^n x_i^2) / n */ + cpl_errorstate prestate = cpl_errorstate_get(); + *out = cpl_imagelist_collapse_create(data); + /* ignore division by 0 on all pixels zero error */ + if (*out == NULL) { + cpl_errorstate_set(prestate); + *out = cpl_image_duplicate(cpl_imagelist_get_const(data, 0)); + cpl_image_accept_all(*out); + cpl_mask_not(cpl_image_get_bpm(*out)); + *err = cpl_image_duplicate(cpl_imagelist_get_const(errors, 0)); + cpl_image_accept_all(*err); + cpl_mask_not(cpl_image_get_bpm(*err)); + *contrib = cpl_image_new(cpl_image_get_size_x(*err), + cpl_image_get_size_y(*err), CPL_TYPE_INT); + cpl_image_fill_rejected(*out, NAN); + cpl_image_fill_rejected(*err, NAN); + } + else { + *err = imagelist_sqsum(errors, contrib); + cpl_image_power(*err, 0.5); + cpl_image_divide(*err, *contrib); + cpl_image_fill_rejected(*out, NAN); + cpl_image_fill_rejected(*err, NAN); + } + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements weighted mean combination on input image list + * + * @param data input data images + * @param errors_ input errors images + * @param out output combined images + * @param err output combined errors + * @param contrib output contribution mask + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * @return cpl_error_code + * + * @doc + * weighted mean and associated error are computed with standard formulae + * + * \f$ + * x_{mean}=\frac{(\sum_{i}^{n} w_{i} \cdot x_{i})} { \sum_{i}^{n} w_{i} } + * \f$ + * + * \f$ + * \sigma_{x}=\frac{ 1 } { \sqrt{ \sum_{i}^{n} w_{i}^{2} } } + * \f$ + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_collapse_weighted_mean(const cpl_imagelist * data_, + const cpl_imagelist * errors_, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * HDRL_UNUSED(parameters), + void * HDRL_UNUSED(extra_out)) +{ + /* (\Sum_i^n w_i * x_i) / (\Sum_i^n w_i) */ + /* 1 / \sqrt(\Sum_i^n w_i^2) */ + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_imagelist * data = cpl_imagelist_duplicate(data_); + cpl_imagelist * errors = cpl_imagelist_new(); + cpl_image * tmperr; + cpl_imagelist_cast(errors, errors_, + cpl_image_get_type(cpl_imagelist_get(data, 0))); + cpl_imagelist_power(errors, -2); + cpl_imagelist_multiply(data, errors); + *contrib = cpl_image_new_from_accepted(data); + *out = cpl_imagelist_collapse_create(data); + if (*out == NULL) { + cpl_errorstate_set(prestate); + *out = cpl_image_duplicate(cpl_imagelist_get_const(data, 0)); + cpl_image_accept_all(*out); + cpl_mask_not(cpl_image_get_bpm(*out)); + *err = cpl_image_duplicate(cpl_imagelist_get_const(errors, 0)); + cpl_image_accept_all(*err); + cpl_mask_not(cpl_image_get_bpm(*err)); + cpl_image_fill_rejected(*out, NAN); + cpl_image_fill_rejected(*err, NAN); + cpl_imagelist_delete(errors); + cpl_imagelist_delete(data); + return cpl_error_get_code(); + } + cpl_imagelist_delete(data); + tmperr = cpl_imagelist_collapse_create(errors); + cpl_imagelist_delete(errors); + cpl_image_multiply(*out, *contrib); + cpl_image_multiply(tmperr, *contrib); + cpl_image_divide(*out, tmperr); + cpl_image_power(tmperr, -0.5); + if (cpl_image_get_type(cpl_imagelist_get_const(errors_, 0)) == + cpl_image_get_type(cpl_imagelist_get_const(data_, 0))) { + *err = tmperr; + } + else { + *err = cpl_image_cast(tmperr, + cpl_image_get_type(cpl_imagelist_get_const(errors_, 0))); + cpl_image_delete(tmperr); + } + + cpl_image_fill_rejected(*out, NAN); + cpl_image_fill_rejected(*err, NAN); + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements median combination on input image list + * + * @param data input data images + * @param errors input errors images + * @param out output combined images + * @param err output combined errors + * @param contrib output contribution mask + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * @return cpl_error_code + * + * @doc + * Median and associated error are computed similarly as for mean but + * scaling by \f$ \sqrt{ \frac{ \pi } { 2 } } \f$ + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_collapse_median(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * HDRL_UNUSED(parameters), + void * HDRL_UNUSED(extra_out)) +{ + cpl_errorstate prestate = cpl_errorstate_get(); + /* same as mean with scaling by \sqrt(\pi / 2) */ + *out = cpl_imagelist_collapse_median_create(data); + *err = imagelist_sqsum(errors, contrib); + cpl_image_power(*err, 0.5); + cpl_image_divide(*err, *contrib); + if (cpl_error_get_code() == CPL_ERROR_DIVISION_BY_ZERO) { + cpl_errorstate_set(prestate); + cpl_image_accept_all(*out); + cpl_mask_not(cpl_image_get_bpm(*out)); + cpl_image_accept_all(*err); + cpl_mask_not(cpl_image_get_bpm(*err)); + cpl_image_fill_rejected(*out, NAN); + cpl_image_fill_rejected(*err, NAN); + return cpl_error_get_code(); + } + /* scale error so it estimates stdev of normal distribution */ + cpl_image_multiply_scalar(*err, sqrt(CPL_MATH_PI_2)); + /* revert scaling for contrib <= 2 as median == mean in this case */ + cpl_image * tmp = cpl_image_cast(*contrib, CPL_TYPE_DOUBLE); + cpl_image_threshold(tmp, 2.1, 2.1, 1. / sqrt(CPL_MATH_PI_2), 1.); + cpl_image_multiply(*err, tmp); + cpl_image_delete(tmp); + cpl_image_fill_rejected(*out, NAN); + cpl_image_fill_rejected(*err, NAN); + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements sigma-clipped combination on input image list + * + * @param data input data images + * @param errors input errors images + * @param out output combined images + * @param err output combined errors + * @param contrib output contribution mask + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * @return cpl_error_code + * + * @doc + * sigma-clipped mean and associated error, computed similarly as for mean but + * without taking the clipped values into account. + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_collapse_sigclip(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * parameters, void * extra_out) +{ + /* same as mean but working on the not-clipped values only */ + hdrl_collapse_sigclip_parameter * par = parameters; + hdrl_sigclip_image_output * eout = + (hdrl_sigclip_image_output *)extra_out; + cpl_ensure_code(par, CPL_ERROR_NULL_INPUT); + const cpl_image * img = cpl_imagelist_get_const(data, 0); + size_t nx = cpl_image_get_size_x(img); + size_t ny = cpl_image_get_size_y(img); + *out = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + *err = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + *contrib = cpl_image_new(nx, ny, CPL_TYPE_INT); + hdrl_vector_cache * cache = + hdrl_vector_cache_new(cpl_imagelist_get_size(data), nx * 2); + + /* sigmaclip along imagelist axis */ + for (size_t y = 1; y < ny + 1; y++) { + cpl_vector * vdv[nx]; + cpl_vector * vev[nx]; + hdrl_imagelist_to_vector_row(data, y, vdv, cache); + hdrl_imagelist_to_vector_row(errors, y, vev, cache); + for (size_t x = 1; x < nx + 1; x++) { + cpl_vector * vd = vdv[x - 1]; + cpl_vector * ve = vev[x - 1]; + if (vd && ve) { + double m, e, rej_low, rej_high; + cpl_size naccepted; + hdrl_kappa_sigma_clip(vd, ve, + par->kappa_low, par->kappa_high, + par->niter, CPL_TRUE, + &m, &e, &naccepted, + &rej_low, &rej_high); + cpl_image_set(*out, x, y, m); + cpl_image_set(*err, x, y, e); + cpl_image_set(*contrib, x, y, naccepted); + if (eout) { + cpl_image_set(eout->reject_low, x, y, rej_low); + cpl_image_set(eout->reject_high, x, y, rej_high); + } + } + else { + cpl_image_set(*out, x, y, NAN); + cpl_image_set(*err, x, y, NAN); + cpl_image_reject(*out, x, y); + cpl_image_reject(*err, x, y); + cpl_image_set(*contrib, x, y, 0); + if (eout) { + cpl_image_set(eout->reject_low, x, y, 0.); + cpl_image_set(eout->reject_high, x, y, 0.); + } + } + hdrl_cplvector_delete_to_cache(cache, vd); + hdrl_cplvector_delete_to_cache(cache, ve); + } + } + hdrl_vector_cache_delete(cache); + + return cpl_error_get_code(); +} + + + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements minmax-clipped combination on input image list + * + * @param data input data images + * @param errors input errors images + * @param out output combined images + * @param err output combined errors + * @param contrib output contribution mask + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * @return cpl_error_code + * + * @doc minmax-clipped mean and associated error, computed similarly + * as for mean but without taking the clipped values into account + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_collapse_minmax(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, cpl_image ** err, + cpl_image ** contrib, + void * parameters, void * extra_out) +{ + /* same as mean but working on the not-clipped values only */ + hdrl_collapse_minmax_parameter * par = parameters; + cpl_ensure_code(par, CPL_ERROR_NULL_INPUT); + hdrl_minmax_image_output * eout = + (hdrl_minmax_image_output *)extra_out; + const cpl_image * img = cpl_imagelist_get_const(data, 0); + size_t nx = cpl_image_get_size_x(img); + size_t ny = cpl_image_get_size_y(img); + *out = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + *err = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + *contrib = cpl_image_new(nx, ny, CPL_TYPE_INT); + hdrl_vector_cache * cache = + hdrl_vector_cache_new(cpl_imagelist_get_size(data), nx * 2); + + /* minmaxclip along imagelist axis */ + for (size_t y = 1; y < ny + 1; y++) { + cpl_vector * vdv[nx]; + cpl_vector * vev[nx]; + hdrl_imagelist_to_vector_row(data, y, vdv, cache); + hdrl_imagelist_to_vector_row(errors, y, vev, cache); + for (size_t x = 1; x < nx + 1; x++) { + cpl_vector * vd = vdv[x - 1]; + cpl_vector * ve = vev[x - 1]; + if (vd && ve) { + double m, e, rej_low, rej_high; + cpl_size naccepted; + hdrl_minmax_clip(vd, ve, + par->nlow, par->nhigh, CPL_TRUE, + &m, &e, &naccepted, + &rej_low, &rej_high); + cpl_image_set(*out, x, y, m); + cpl_image_set(*err, x, y, e); + cpl_image_set(*contrib, x, y, naccepted); + if (eout) { + cpl_image_set(eout->reject_low, x, y, rej_low); + cpl_image_set(eout->reject_high, x, y, rej_high); + } + } + else { + cpl_image_set(*out, x, y, NAN); + cpl_image_set(*err, x, y, NAN); + cpl_image_reject(*out, x, y); + cpl_image_reject(*err, x, y); + cpl_image_set(*contrib, x, y, 0); + if (eout) { + cpl_image_set(eout->reject_low, x, y, 0.); + cpl_image_set(eout->reject_high, x, y, 0.); + } + } + hdrl_cplvector_delete_to_cache(cache, vd); + hdrl_cplvector_delete_to_cache(cache, ve); + } + } + hdrl_vector_cache_delete(cache); + + return cpl_error_get_code(); +} + +static void * +hdrl_nop_create_eout_vec(cpl_size HDRL_UNUSED(size)) +{ + return NULL; +} + +static void * +hdrl_nop_create_eout_img(const cpl_image * HDRL_UNUSED(img)) +{ + return NULL; +} + +static cpl_error_code +hdrl_nop_move_eout(void * HDRL_UNUSED(dst_), + void * HDRL_UNUSED(src_), const cpl_size HDRL_UNUSED(y)) +{ + return CPL_ERROR_NONE; +} + +static void +hdrl_nop_unwrap_eout(void * HDRL_UNUSED(dst)) +{ + return; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via mean + * @return mean reduction object + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_mean(void) +{ + hdrl_collapse_imagelist_to_image_t * s = cpl_calloc(1, sizeof(*s)); + s->func = &hdrl_collapse_mean; + s->create_eout = &hdrl_nop_create_eout_img; + s->move_eout = &hdrl_nop_move_eout; + s->unwrap_eout = &hdrl_nop_unwrap_eout; + s->delete_eout = &hdrl_nop_unwrap_eout; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via weighted mean + * @return weighted mean reduction object + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_weighted_mean(void) +{ + hdrl_collapse_imagelist_to_image_t * s = cpl_calloc(1, sizeof(*s)); + s->func = &hdrl_collapse_weighted_mean; + s->create_eout = &hdrl_nop_create_eout_img; + s->move_eout = &hdrl_nop_move_eout; + s->unwrap_eout = &hdrl_nop_unwrap_eout; + s->delete_eout = &hdrl_nop_unwrap_eout; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via median + * @return median reduction object + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_median(void) +{ + hdrl_collapse_imagelist_to_image_t * s = cpl_calloc(1, sizeof(*s)); + s->func = &hdrl_collapse_median; + s->create_eout = &hdrl_nop_create_eout_img; + s->move_eout = &hdrl_nop_move_eout; + s->unwrap_eout = &hdrl_nop_unwrap_eout; + s->delete_eout = &hdrl_nop_unwrap_eout; + return s; +} + +static void * +hdrl_sigclip_create_eout_img(const cpl_image * img) +{ + cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); + hdrl_sigclip_image_output * eout = cpl_calloc(sizeof(*eout), 1); + eout->reject_low = cpl_image_new(cpl_image_get_size_x(img), + cpl_image_get_size_y(img), + cpl_image_get_type(img)); + eout->reject_high = cpl_image_new(cpl_image_get_size_x(img), + cpl_image_get_size_y(img), + cpl_image_get_type(img)); + /* add masks for thread safety on move */ + cpl_image_get_bpm(eout->reject_low); + cpl_image_get_bpm(eout->reject_high); + return eout; +} + +static void +hdrl_sigclip_delete_eout_img(void * eout_) +{ + if (eout_ == NULL) { + return; + } + hdrl_sigclip_image_output * eout = (hdrl_sigclip_image_output*)eout_; + cpl_image_delete(eout->reject_low); + cpl_image_delete(eout->reject_high); + cpl_free(eout); +} + +static cpl_error_code +hdrl_sigclip_move_eout_img(void * dst_, void * src_, const cpl_size y) +{ + hdrl_sigclip_image_output * dst = dst_; + hdrl_sigclip_image_output * src = src_; + cpl_ensure_code(dst, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(src, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(y > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(y <= cpl_image_get_size_y(dst->reject_low), + CPL_ERROR_ACCESS_OUT_OF_RANGE); + + cpl_image_copy(dst->reject_low, src->reject_low, 1, y); + cpl_image_copy(dst->reject_high, src->reject_high, 1, y); + cpl_image_delete(src->reject_low); + cpl_image_delete(src->reject_high); + cpl_free(src); + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via kappa sigma clipped mean + * + * @param kappa_low low sigma bound + * @param kappa_high high sigma bound + * @param niter number of clipping iterators + * + * @return sigma clip reduction object + * @see hdrl_kappa_sigma_clip() + * + * the high and low reject values are stored in extra_out if applicable + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_image_t * +hdrl_collapse_imagelist_to_image_sigclip(double kappa_low, + double kappa_high, + int niter) +{ + hdrl_collapse_imagelist_to_image_t * s = cpl_calloc(1, sizeof(*s)); + hdrl_parameter * sp = + hdrl_collapse_sigclip_parameter_create(kappa_low, kappa_high, niter); + s->func = &hdrl_collapse_sigclip; + s->create_eout = &hdrl_sigclip_create_eout_img; + s->move_eout = &hdrl_sigclip_move_eout_img; + s->unwrap_eout = &cpl_free; + s->delete_eout = &hdrl_sigclip_delete_eout_img; + s->parameters = sp; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via minmax clipped mean + * + * @param nlow number of low pixel to reject + * @param nhigh number of high pixel to reject + * + * @return minmax cliped reduction object + * @see hdrl_minmax_clip() + * + * + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_image_t * +hdrl_collapse_imagelist_to_image_minmax(double nlow, + double nhigh) +{ + hdrl_collapse_imagelist_to_image_t * s = cpl_calloc(1, sizeof(*s)); + hdrl_parameter * sp = + hdrl_collapse_minmax_parameter_create(nlow, nhigh); + s->func = &hdrl_collapse_minmax; + s->create_eout = &hdrl_sigclip_create_eout_img; + s->move_eout = &hdrl_sigclip_move_eout_img; + s->unwrap_eout = &cpl_free; + s->delete_eout = &hdrl_sigclip_delete_eout_img; + s->parameters = sp; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Call the associated reduction function + * + * @param f reduction function object + * @param data data to apply function on + * @param errors errors to use for propagation + * @param out pointer which will contain reduced data image, type double + * @param err pointer which will contain reduced error image, type double + * @param contrib pointer which will contain contribution map, type integer + * @param eout storage for extra output, may be NULL + * + * @return cpl_error_code + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_collapse_imagelist_to_image_call(hdrl_collapse_imagelist_to_image_t * f, + const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, + cpl_image ** err, + cpl_image ** contrib, + void ** eout) +{ + cpl_ensure_code(f, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(data, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(errors, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(out, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(err, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(contrib, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(data) == + cpl_imagelist_get_size(errors), + CPL_ERROR_INCOMPATIBLE_INPUT); + if (eout) { + *eout = f->create_eout(cpl_imagelist_get_const(data, 0)); + } + + cpl_imagelist * nerrors = wrap_synced_errlist(data, errors); + if (nerrors == NULL) { + return cpl_error_get_code(); + } + + cpl_error_code errcode = f->func(data, nerrors, out, err, contrib, + f->parameters, eout ? *eout : NULL); + + unwrap_synced_errlist(nerrors); + + return errcode; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call extra output creation function + * + * @param f reduction function object + * @param data an image of same size and type as the intended reductee + * + * @return reduction objects extra output function, its entries must be deleted + * by the caller and the structure unwraped with the unwrap_eout + * function + */ +/* ---------------------------------------------------------------------------*/ +void * +hdrl_collapse_imagelist_to_image_create_eout( + hdrl_collapse_imagelist_to_image_t * f, + const cpl_image * data) +{ + cpl_ensure(f, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(data, CPL_ERROR_NULL_INPUT, NULL); + + return f->create_eout(data); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call extra output unwrap function + * + * @param f reduction function object + * + * @note does not delete the members + * + */ +/* ---------------------------------------------------------------------------*/ +void +hdrl_collapse_imagelist_to_image_unwrap_eout( + hdrl_collapse_imagelist_to_image_t * f, + void * eout) +{ + if (f != NULL) { + f->unwrap_eout(eout); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call extra output delete function + * + * @param f reduction function object + * + * @note does delete the members + * + */ +/* ---------------------------------------------------------------------------*/ +void +hdrl_collapse_imagelist_to_image_delete_eout( + hdrl_collapse_imagelist_to_image_t * f, + void * eout) +{ + if (f != NULL) { + f->delete_eout(eout); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call function to move extra output do destination with offset + * + * @param f reduction function object + * @param dst destination output + * @param src source output + * @param y offset in y, see cpl_image_copy + * + * @return cpl_error_code + * + * @note deletes the source after the content is copied + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_collapse_imagelist_to_image_move_eout( + hdrl_collapse_imagelist_to_image_t * f, + void * dst, + void * src, + cpl_size y) +{ + cpl_ensure_code(f, CPL_ERROR_NULL_INPUT); + + return f->move_eout(dst, src, y); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete imagelist reduction object + * + * @param p imagelist reduction object or NULL + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_collapse_imagelist_to_image_delete(hdrl_collapse_imagelist_to_image_t * p) +{ + if (p) { + hdrl_parameter_delete(p->parameters); + } + cpl_free(p); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call extra output creation function + * + * @param f reduction function object + * @param size size of the imagelist which should be reduced + * + * @return reduction objects extra output function, its entries must be deleted + * by the caller and the structure unwraped with the unwrap_eout + * function + */ +/* ---------------------------------------------------------------------------*/ +void * hdrl_collapse_imagelist_to_vector_create_eout( + hdrl_collapse_imagelist_to_vector_t * f, + const cpl_size size) +{ + cpl_ensure(f, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(size > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + return f->create_eout(size); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call extra output unwrap function + * + * @param f reduction function object + * + * @note does not delete the members + * + */ +/* ---------------------------------------------------------------------------*/ +void +hdrl_collapse_imagelist_to_vector_unwrap_eout( + hdrl_collapse_imagelist_to_vector_t * f, + void * eout) +{ + if (f != NULL) { + f->unwrap_eout(eout); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call extra output delete function + * + * @param f reduction function object + * + * @note does delete the members + * + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_collapse_imagelist_to_vector_delete_eout( + hdrl_collapse_imagelist_to_vector_t * f, + void * eout) +{ + if (f != NULL) { + f->delete_eout(eout); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief call function to move extra output do destination with offset + * + * @param f reduction function object + * @param dst destination output + * @param src source output + * @param y offset in y, see cpl_image_copy + * + * @return cpl_error_code + * + * @note deletes the source after the content is copied + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_collapse_imagelist_to_vector_move_eout( + hdrl_collapse_imagelist_to_vector_t * f, + void * dst, + void * src, + cpl_size y) +{ + cpl_ensure_code(f, CPL_ERROR_NULL_INPUT); + + return f->move_eout(dst, src, y); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements mean reduction on each image of an imagelist + * + * @param data input data images + * @param errors input errors images + * @param out vector of median of each image + * @param err vector of errors of median of each image + * @param contrib array of contributions + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * @return cpl_error_code + * + * @doc + * The mean value on all good pixels of each image of an imagelist, the + * associated error and the number of good pixels are stored as elements + * of the corresponding output vectors. + * If all pixels of an image in the list are bad the contribution is 0 and the + * out and err are set to NAN. + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +reduce_imagelist_to_vector_mean(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, cpl_vector ** err, + cpl_array ** contrib, + void * HDRL_UNUSED(parameters), + void * HDRL_UNUSED(extra_out)) +{ + size_t nz = cpl_imagelist_get_size(data); + *out = cpl_vector_new(nz); + *err = cpl_vector_new(nz); + *contrib = cpl_array_new(nz, CPL_TYPE_INT); + + for (size_t i = 0; i < nz; i++) { + const cpl_image * img = cpl_imagelist_get_const(data, i); + const cpl_image * ierr = cpl_imagelist_get_const(errors, i); + size_t naccepted = hdrl_get_image_good_npix(img); + + if (naccepted != 0) { + double error = sqrt(cpl_image_get_sqflux(ierr)) / naccepted; + + cpl_vector_set(*out, i, cpl_image_get_mean(img)); + cpl_vector_set(*err, i, error); + } + else { + cpl_vector_set(*out, i, NAN); + cpl_vector_set(*err, i, NAN); + } + cpl_array_set_int(*contrib, i, naccepted); + } + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via mean + * @return mean reduction object + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_mean(void) +{ + hdrl_collapse_imagelist_to_vector_t * s = cpl_calloc(1, sizeof(*s)); + s->create_eout = &hdrl_nop_create_eout_vec; + s->move_eout = &hdrl_nop_move_eout; + s->unwrap_eout = &hdrl_nop_unwrap_eout; + s->delete_eout = &hdrl_nop_unwrap_eout; + s->func = &reduce_imagelist_to_vector_mean; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements weighted mean reduction on each image of an imagelist + * + * @param data input data images + * @param errors input errors images + * @param out vector of median of each image + * @param err vector of errors of median of each image + * @param contrib array of contributions + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * + * @return cpl_error_code + * + * @doc + * weighted mean and associated error are computed with standard formulae + * + * \f$ + * x_{mean}=\frac{(\sum_{i}^{n} w_{i} \cdot x_{i})} { \sum_{i}^{n} w_{i} } + * \f$ + * + * \f$ + * \sigma_{x}=\frac{ 1 } { \sqrt{ \sum_{i}^{n} w_{i}^{2} } } + * \f$ + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +reduce_imagelist_to_vector_weighted_mean(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, cpl_vector ** err, + cpl_array ** contrib, + void * HDRL_UNUSED(parameters), + void * HDRL_UNUSED(extra_out)) +{ + size_t nz = cpl_imagelist_get_size(data); + *out = cpl_vector_new(nz); + *err = cpl_vector_new(nz); + *contrib = cpl_array_new(nz, CPL_TYPE_INT); + + for (size_t i = 0; i < nz; i++) { + cpl_image * img = + cpl_image_duplicate(cpl_imagelist_get_const(data, i)); + cpl_image * ierr = + cpl_image_duplicate(cpl_imagelist_get_const(errors, i)); + size_t naccepted = hdrl_get_image_good_npix(img); + + if (naccepted != 0) { + /* (\Sum_i^n w_i * x_i) / (\Sum_i^n w_i) */ + /* 1 / \sqrt(\Sum_i^n w_i^2) */ + cpl_image_power(ierr, -2); + /* ierr = weights now */ + cpl_image_multiply(img, ierr); + double sum_v = cpl_image_get_mean(img) * naccepted; + double sum_w = cpl_image_get_mean(ierr) * naccepted; + double wmean = sum_v / sum_w; + double error = 1. / sqrt(sum_w); + + cpl_vector_set(*out, i, wmean); + cpl_vector_set(*err, i, error); + } + else { + cpl_vector_set(*out, i, NAN); + cpl_vector_set(*err, i, NAN); + } + cpl_array_set_int(*contrib, i, naccepted); + cpl_image_delete(img); + cpl_image_delete(ierr); + } + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via weighted mean + * @return weighted mean reduction object + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_weighted_mean(void) +{ + hdrl_collapse_imagelist_to_vector_t * s = cpl_calloc(1, sizeof(*s)); + s->create_eout = &hdrl_nop_create_eout_vec; + s->move_eout = &hdrl_nop_move_eout; + s->unwrap_eout = &hdrl_nop_unwrap_eout; + s->delete_eout = &hdrl_nop_unwrap_eout; + s->func = &reduce_imagelist_to_vector_weighted_mean; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief implements median reduction on each image of an imagelist + * + * @param data input data images + * @param errors input errors images + * @param out vector of median of each image + * @param err vector of errors of median of each image + * @param contrib array of contributions + * @param parameters parameters to control, not used + * @param extra_out optional extra output, not used + * @return cpl_error_code + * + * @doc + * The median value on all good pixels of each image of an imagelist, the + * associated error and the number of good pixels are stored as elements + * of the corresponding output vectors. + * If all pixels of an image in the list are bad the contribution is 0 and the + * out and err are set to NAN. + * The errors are scaled by the sqrt of the statistical efficiency of the + * median on normal distributed data which is \f$ \frac{ \pi }{ 2 } \f$ + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +reduce_imagelist_to_vector_median(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, cpl_vector ** err, + cpl_array ** contrib, + void * HDRL_UNUSED(parameters), + void * HDRL_UNUSED(extra_out)) +{ + size_t nz = cpl_imagelist_get_size(data); + *out = cpl_vector_new(nz); + *err = cpl_vector_new(nz); + *contrib = cpl_array_new(nz, CPL_TYPE_INT); + + for (size_t i = 0; i < nz; i++) { + const cpl_image * img = cpl_imagelist_get_const(data, i); + const cpl_image * ierr = cpl_imagelist_get_const(errors, i); + size_t naccepted = hdrl_get_image_good_npix(img); + + if (naccepted != 0) { + double error = sqrt(cpl_image_get_sqflux(ierr)) / naccepted; + /* sqrt(statistical efficiency on normal data)*/ + if (naccepted > 2) { + error *= sqrt(CPL_MATH_PI_2); + } + + cpl_vector_set(*out, i, cpl_image_get_median(img)); + cpl_vector_set(*err, i, error); + } + else { + cpl_vector_set(*out, i, NAN); + cpl_vector_set(*err, i, NAN); + } + cpl_array_set_int(*contrib, i, naccepted); + } + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist via median + * @return median reduction object + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_median(void) +{ + hdrl_collapse_imagelist_to_vector_t * s = cpl_calloc(1, sizeof(*s)); + s->create_eout = &hdrl_nop_create_eout_vec; + s->move_eout = &hdrl_nop_move_eout; + s->unwrap_eout = &hdrl_nop_unwrap_eout; + s->delete_eout = &hdrl_nop_unwrap_eout; + s->func = &reduce_imagelist_to_vector_median; + return s; +} + +static void * +hdrl_sigclip_create_eout_vec(cpl_size size) +{ + hdrl_sigclip_vector_output * eout = cpl_calloc(sizeof(*eout), 1); + eout->reject_low = cpl_vector_new(size); + eout->reject_high = cpl_vector_new(size); + return eout; +} + +static void +hdrl_sigclip_delete_eout_vec(void * eout_) +{ + if (eout_ == NULL) { + return; + } + hdrl_sigclip_vector_output * eout = (hdrl_sigclip_vector_output*)eout_; + cpl_vector_delete(eout->reject_low); + cpl_vector_delete(eout->reject_high); + cpl_free(eout); +} + +static cpl_error_code +hdrl_sigclip_move_eout_vec(void * dst_, void * src_, const cpl_size y) +{ + hdrl_sigclip_vector_output * dst = dst_; + hdrl_sigclip_vector_output * src = src_; + cpl_ensure_code(dst, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(src, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(y >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(y < cpl_vector_get_size(dst->reject_low), + CPL_ERROR_ACCESS_OUT_OF_RANGE); + + double * ddst = cpl_vector_get_data(dst->reject_low); + double * dsrc = cpl_vector_get_data(src->reject_low); + memcpy(ddst + y, dsrc, cpl_vector_get_size(src->reject_low)); + ddst = cpl_vector_get_data(dst->reject_high); + dsrc = cpl_vector_get_data(src->reject_high); + memcpy(ddst + y, dsrc, cpl_vector_get_size(src->reject_high)); + cpl_vector_delete(src->reject_low); + cpl_vector_delete(src->reject_high); + cpl_free(src); + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief implements sigma-clipped combination on input image list into a vector + * + * @param data input data imagelist + * @param errors input errors imagelist + * @param out output vector + * @param err output vector errors + * @param contrib output contribution vector + * + * @return cpl_error_code + * + * If all pixels of an image in the list are rejected the contribution is 0 and + * the out and err are set to NAN. + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +reduce_imagelist_to_vector_sigclip(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, cpl_vector ** err, + cpl_array ** contrib, void * parameters, + void * extra_out) +{ + hdrl_collapse_sigclip_parameter * par = parameters; + hdrl_minmax_vector_output * eout = + (hdrl_minmax_vector_output *)extra_out; + + cpl_size nz = cpl_imagelist_get_size(data); + *out = cpl_vector_new(nz); + *err = cpl_vector_new(nz); + *contrib = cpl_array_new(nz, CPL_TYPE_INT); + + /* sigmaclip on each image of the imagelist */ + for (cpl_size z = 0; z < nz ; z++) { + double corr, error, low, high; + cpl_size contribution; + if (hdrl_kappa_sigma_clip_image(cpl_imagelist_get_const(data, z), + cpl_imagelist_get_const(errors, z), + par->kappa_low, + par->kappa_high, + par->niter, + &corr, + &error, + &contribution, + &low, + &high) != CPL_ERROR_NONE) { + break; + } + cpl_vector_set(*out, z, corr); + cpl_vector_set(*err, z, error); + cpl_array_set_int(*contrib, z, contribution); + + if (eout) { + cpl_vector_set(eout->reject_low, z, low); + cpl_vector_set(eout->reject_high, z, high); + } + } + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist to a vector via kappa sigma + * clipped mean + * + * @param kappa_low low sigma bound + * @param kappa_high high sigma bound + * @param niter maximum number of clipping iterations + * + * @return sigma clip reduction object + * @see hdrl_kappa_sigma_clip() + * + * the high and low reject values are stored in extra_out if applicable + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_vector_t * +hdrl_collapse_imagelist_to_vector_sigclip(double kappa_low, double kappa_high, + int niter) +{ + hdrl_collapse_imagelist_to_vector_t * s = cpl_calloc(1, sizeof(*s)); + hdrl_parameter * sp = + hdrl_collapse_sigclip_parameter_create(kappa_low, kappa_high, niter); + s->func = &reduce_imagelist_to_vector_sigclip; + s->create_eout = &hdrl_sigclip_create_eout_vec; + s->move_eout = &hdrl_sigclip_move_eout_vec; + s->unwrap_eout = &cpl_free; + s->delete_eout = &hdrl_sigclip_delete_eout_vec; + s->parameters = sp; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief implements minmax-clipped combination on input image list into a vector + * + * @param data input data imagelist + * @param errors input errors imagelist + * @param out output vector + * @param err output vector errors + * + * @return cpl_error_code + * + * If all pixels of an image in the list are rejected the contribution is 0 and + * the out and err are set to NAN. + * + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +reduce_imagelist_to_vector_minmax(const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, cpl_vector ** err, + cpl_array ** contrib, void * parameters, + void * extra_out) +{ + hdrl_collapse_minmax_parameter * par = parameters; + hdrl_sigclip_vector_output * eout = + (hdrl_sigclip_vector_output *)extra_out; + cpl_size nz = cpl_imagelist_get_size(data); + *out = cpl_vector_new(nz); + *err = cpl_vector_new(nz); + *contrib = cpl_array_new(nz, CPL_TYPE_INT); + + /* minmax on each image of the imagelist */ + for (cpl_size z = 0; z < nz ; z++) { + double corr, error, low, high; + cpl_size contribution; + if (hdrl_minmax_clip_image(cpl_imagelist_get_const(data, z), + cpl_imagelist_get_const(errors, z), + par->nlow, + par->nhigh, + &corr, + &error, + &contribution, + &low, &high) != CPL_ERROR_NONE) { + break; + } + cpl_vector_set(*out, z, corr); + cpl_vector_set(*err, z, error); + cpl_array_set_int(*contrib, z, contribution); + + if (eout) { + cpl_vector_set(eout->reject_low, z, low); + cpl_vector_set(eout->reject_high, z, high); + } + } + + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reduction object to reduce imagelist to a vector via min-max rejection + * + * @param nlow low bound + * @param nhigh high bound + * + * @return minmax rejected reduction object + * @see hdrl_minmax() + * + */ +/* ---------------------------------------------------------------------------*/ +hdrl_collapse_imagelist_to_vector_t * +hdrl_collapse_imagelist_to_vector_minmax(double nlow, double nhigh) +{ + hdrl_collapse_imagelist_to_vector_t * s = cpl_calloc(1, sizeof(*s)); + hdrl_parameter * sp = + hdrl_collapse_minmax_parameter_create(nlow, nhigh); + s->func = &reduce_imagelist_to_vector_minmax; + s->create_eout = &hdrl_sigclip_create_eout_vec; + s->move_eout = &hdrl_sigclip_move_eout_vec; + s->unwrap_eout = &cpl_free; + s->delete_eout = &hdrl_sigclip_delete_eout_vec; + s->parameters = sp; + return s; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Call the associated reduction function + * + * @param f reduction function object + * @param data data to apply function on + * @param errors errors to use for propagation + * @param out pointer which will contain reduced data image, type double + * @param err pointer which will contain reduced error image, type double + * @param contrib pointer which will contain contribution map, type integer + * @param eout storage for extra output, may be NULL + * + * @return cpl_error_code + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_collapse_imagelist_to_vector_call(hdrl_collapse_imagelist_to_vector_t * f, + const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, + cpl_vector ** err, + cpl_array ** contrib, + void ** eout) +{ + cpl_ensure_code(f, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(data, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(errors, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(out, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(err, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(contrib, CPL_ERROR_NULL_INPUT); + if (eout) { + *eout = f->create_eout(cpl_imagelist_get_size(data)); + } + + cpl_imagelist * nerrors = wrap_synced_errlist(data, errors); + if (nerrors == NULL) { + return cpl_error_get_code(); + } + + cpl_error_code errcode = f->func(data, errors, out, err, contrib, + f->parameters, eout ? *eout : NULL); + + unwrap_synced_errlist(nerrors); + + return errcode; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete imagelist reduction object + * + * @param p imagelist reduction object or NULL + */ +/* ---------------------------------------------------------------------------*/ +void +hdrl_collapse_imagelist_to_vector_delete(hdrl_collapse_imagelist_to_vector_t * p) +{ + if (p) { + cpl_free(p->parameters); + } + cpl_free(p); +} + +/** @endcond */ + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_collapse.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_collapse.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_collapse.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_collapse.h 2017-08-25 12:45:15.000000000 +0000 @@ -0,0 +1,179 @@ +/* $Id: hdrl_collapse.h,v 1.11 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.11 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_COLLAPSE_H +#define HDRL_COLLAPSE_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_parameter.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +hdrl_parameter * hdrl_collapse_mean_parameter_create(void); +cpl_boolean hdrl_collapse_parameter_is_mean(const hdrl_parameter *); +extern hdrl_parameter * HDRL_COLLAPSE_MEAN; +hdrl_parameter * hdrl_collapse_median_parameter_create(void); +cpl_boolean hdrl_collapse_parameter_is_median(const hdrl_parameter *); +extern hdrl_parameter * HDRL_COLLAPSE_MEDIAN; +hdrl_parameter * hdrl_collapse_weighted_mean_parameter_create(void); +cpl_boolean hdrl_collapse_parameter_is_weighted_mean(const hdrl_parameter *); +extern hdrl_parameter * HDRL_COLLAPSE_WEIGHTED_MEAN; +hdrl_parameter * hdrl_collapse_sigclip_parameter_create(double, double, int); +cpl_boolean hdrl_collapse_parameter_is_sigclip(const hdrl_parameter *); +double hdrl_collapse_sigclip_parameter_get_kappa_high(const hdrl_parameter *); +double hdrl_collapse_sigclip_parameter_get_kappa_low(const hdrl_parameter *); +int hdrl_collapse_sigclip_parameter_get_niter(const hdrl_parameter *); + +hdrl_parameter * hdrl_collapse_minmax_parameter_create(double, double); +cpl_boolean hdrl_collapse_parameter_is_minmax(const hdrl_parameter *); +double hdrl_collapse_minmax_parameter_get_nhigh(const hdrl_parameter *); +double hdrl_collapse_minmax_parameter_get_nlow(const hdrl_parameter *); + + +hdrl_parameter * hdrl_collapse_parameter_parse_parlist( + const cpl_parameterlist *, const char *); +cpl_parameterlist * hdrl_collapse_parameter_create_parlist(const char *, + const char *, const char *, hdrl_parameter *, hdrl_parameter *) ; + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE +cpl_error_code hdrl_collapse_minmax_parameter_verify(const hdrl_parameter *); +cpl_error_code hdrl_collapse_sigclip_parameter_verify(const hdrl_parameter *); + +typedef struct hdrl_collapse_imagelist_to_image_s + hdrl_collapse_imagelist_to_image_t; +typedef struct hdrl_collapse_imagelist_to_vector_s + hdrl_collapse_imagelist_to_vector_t; + +typedef struct { + cpl_image * reject_low; + cpl_image * reject_high; +} hdrl_sigclip_image_output; +typedef hdrl_sigclip_image_output hdrl_minmax_image_output; + +typedef struct { + cpl_vector * reject_low; + cpl_vector * reject_high; +} hdrl_sigclip_vector_output; +typedef hdrl_sigclip_vector_output hdrl_minmax_vector_output; + +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_mean(void); +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_weighted_mean(void); +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_median(void); +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_sigclip(double, double, int); +hdrl_collapse_imagelist_to_image_t * + hdrl_collapse_imagelist_to_image_minmax(double, double); +cpl_error_code hdrl_collapse_imagelist_to_image_call( + hdrl_collapse_imagelist_to_image_t * f, + const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_image ** out, + cpl_image ** err, + cpl_image ** contrib, + void ** eout); +void * +hdrl_collapse_imagelist_to_image_create_eout( + hdrl_collapse_imagelist_to_image_t * f, + const cpl_image * data); +void +hdrl_collapse_imagelist_to_image_delete_eout( + hdrl_collapse_imagelist_to_image_t * f, + void * eout); +void +hdrl_collapse_imagelist_to_image_unwrap_eout( + hdrl_collapse_imagelist_to_image_t * f, + void * eout); +cpl_error_code +hdrl_collapse_imagelist_to_image_move_eout( + hdrl_collapse_imagelist_to_image_t * f, + void * dst, + void * src, + cpl_size y); +void hdrl_collapse_imagelist_to_image_delete(hdrl_collapse_imagelist_to_image_t *); + +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_mean(void); +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_weighted_mean(void); +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_median(void); +hdrl_collapse_imagelist_to_vector_t * + hdrl_collapse_imagelist_to_vector_sigclip(double, double, int); +hdrl_collapse_imagelist_to_vector_t * +hdrl_collapse_imagelist_to_vector_minmax(double, double); + +cpl_error_code hdrl_collapse_imagelist_to_vector_call( + hdrl_collapse_imagelist_to_vector_t * f, + const cpl_imagelist * data, + const cpl_imagelist * errors, + cpl_vector ** out, + cpl_vector ** err, + cpl_array ** contrib, + void ** eout); + +void * hdrl_collapse_imagelist_to_vector_create_eout( + hdrl_collapse_imagelist_to_vector_t * f, + cpl_size); +void hdrl_collapse_imagelist_to_vector_delete_eout( + hdrl_collapse_imagelist_to_vector_t * f, + void * eout); +void hdrl_collapse_imagelist_to_vector_unwrap_eout( + hdrl_collapse_imagelist_to_vector_t * f, + void * eout); +cpl_error_code hdrl_collapse_imagelist_to_vector_move_eout( + hdrl_collapse_imagelist_to_vector_t * f, + void * dst, + void * src, + cpl_size y); +void hdrl_collapse_imagelist_to_vector_delete( + hdrl_collapse_imagelist_to_vector_t *); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_combine.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_combine.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_combine.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_combine.c 2013-11-18 16:37:28.000000000 +0000 @@ -0,0 +1,100 @@ +/* $Id: hdrl_combine.c,v 1.15 2013-09-24 14:58:54 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-09-24 14:58:54 $ + * $Revision: 1.15 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_combine.h" +#include "hdrl_iter.h" +#include "hdrl_utils.h" +#include "hdrl_sigclip.h" +#include +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_combine COMBINE Module + + This module allows the combination of imagelists with error propagation. + If input images size is large the user should use hdrl_imagelist_combine_it() + for efficient RAM usage. Else can be used hdrl_imagelist_combine() + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief combine imagelist with error propagation + * + * @param data input data imagelist + * @param errors input imagelist containing errors of data + * @param method reduction method applied to the imagelists + * @param out pointer to storage for a pointer to the allocated + * combined data image + * @param out pointer to storage for a pointer to the allocated + * combined error image + * @param contrib pointer to storage for a pointer to the allocated + * contribution map + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_imagelist_combine(const cpl_imagelist * data, + const cpl_imagelist * errors, + hdrl_collapse_imagelist_to_image_t * method, + cpl_image ** out, + cpl_image ** err, + cpl_image ** contrib) +{ + cpl_ensure_code(data && errors, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(out && err && contrib, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(data) > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(data) == + cpl_imagelist_get_size(errors), CPL_ERROR_ILLEGAL_INPUT); + + hdrl_collapse_imagelist_to_image_call(method, data, errors, + out, err, contrib, NULL); + + return cpl_error_get_code(); +} + +/**@}*/ + +/** @endcond */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_combine.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_combine.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_combine.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_combine.h 2013-11-18 11:49:07.000000000 +0000 @@ -0,0 +1,64 @@ +/* $Id: hdrl_combine.h,v 1.6 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.6 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_COMBINE_H +#define HDRL_COMBINE_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_iter.h" +#include "hdrl_collapse.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +cpl_error_code +hdrl_imagelist_combine(const cpl_imagelist * data, const cpl_imagelist * errors, + hdrl_collapse_imagelist_to_image_t * method, + cpl_image ** out, cpl_image ** err, cpl_image ** contrib); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_correlation.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_correlation.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_correlation.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_correlation.c 2017-08-25 12:18:43.000000000 +0000 @@ -0,0 +1,483 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_correlation.h" + +#include + + +/*----------------------------------------------------------------------------- + Data structures used internally + -----------------------------------------------------------------------------*/ +typedef struct{ + double mean; + double stdev; +}mean_and_stdev; + +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ + +static inline +double calculate_xcorr_sample(const cpl_size shift, const cpl_array * arr1, + const cpl_array * arr2, const double mean1, const double mean2, + const double stdev1, const double stdev2); + +static inline +mean_and_stdev calculate_mean_and_stdev(const cpl_array * arr1); + +static inline cpl_error_code +hdrl_compute_xcorrelation_refine(hdrl_xcorrelation_result* xcorr_res, + const double bin, const double wrange); + +/** + * @addtogroup hdrl_correlation + * @{ + */ +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Constructor for hdrl_xcorrelation_result + * @param x_corr Cross correlation. x_corr becomes owned by the returned value, + * do not free x_corr after the wrapping. + * @param max_idx Index where the cross correlation reaches its maximum + * @param half_window Half window used for the cross-correlation calculation + * + * @return the constructed object. NULL in case of error. Errors are triggered if + * data are not self consistent, e.g. if max_idx is greated than the length of + * x_corr. + */ +/* ---------------------------------------------------------------------------*/ + +hdrl_xcorrelation_result * +hdrl_xcorrelation_result_wrap(cpl_array * x_corr, const cpl_size max_idx, + const cpl_size half_window){ + + cpl_ensure(x_corr != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(max_idx >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(max_idx < cpl_array_get_size(x_corr), + CPL_ERROR_ILLEGAL_INPUT, NULL); + + hdrl_xcorrelation_result * to_ret = cpl_calloc(1, sizeof(*to_ret)); + + to_ret->xcorr = x_corr; + to_ret->pix_peakpos = max_idx; + to_ret->half_window = half_window; + return to_ret; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Destructor for hdrl_xcorrelation_result + * @param self hdrl_xcorrelation_result to be deleted + * + * @return nothing + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_xcorrelation_result_delete(hdrl_xcorrelation_result * self){ + if(self == NULL) return; + + cpl_array_delete(self->xcorr); + cpl_free(self); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the index where the cross correlation reaches its maximum + * @param self hdrl_xcorrelation_result the getter will extract the + * data from + * + * @return the index where the cross correlation reaches its maximum + */ +/* ---------------------------------------------------------------------------*/ +cpl_size +hdrl_xcorrelation_result_get_peak_pixel(const hdrl_xcorrelation_result * self){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); + + return self->pix_peakpos; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the index where the cross correlation reaches its maximum, with + * sub-pixel precision + * @param self hdrl_xcorrelation_result the getter will extract the + * data from + * + * @return the index where the cross correlation reaches its maximum, with + * sub-pixel precision + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_xcorrelation_result_get_peak_subpixel + (const hdrl_xcorrelation_result * self){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); + + return self->peakpos; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the half_window used to calculate the cross-correlation. + * @param self hdrl_xcorrelation_result the getter will extract the + * data from + * + * @return the half_window used to calculate the cross-correlation. + */ +/* ---------------------------------------------------------------------------*/ +cpl_size hdrl_xcorrelation_result_get_half_window + (const hdrl_xcorrelation_result * self){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); + + return self->half_window; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Get the estimated standard deviation of the correlation + * @param self hdrl_xcorrelation_result the getter will extract the + * data from + * + * @return the estimated standard deviation of the correlation + */ +/* ---------------------------------------------------------------------------*/ +double +hdrl_xcorrelation_result_get_sigma(const hdrl_xcorrelation_result * self){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); + + return self->sigma; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter for the cross correlation + * @param self hdrl_xcorrelation_result the getter will extract the + * data from + * + * @return the cross correlation + */ +/* ---------------------------------------------------------------------------*/ +const cpl_array * +hdrl_xcorrelation_result_get_correlation(const hdrl_xcorrelation_result * self){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + + return self->xcorr; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Calculate cross-correlation + * @param arr1 First array + * @param arr2 Second array + * @param half_window half search window where the correlation is calculated + * @param normalize CPL_TRUE normalize correlation in mean and rms + * + * @return cross correlation and index where the peak is. NULL in case of error. + * + * @note: elements marked as invalid in arr1 or arr2 will be treated as they were + * out-of-boudary pixels. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_xcorrelation_result * hdrl_compute_xcorrelation( + const cpl_array * arr1, const cpl_array * arr2, + const cpl_size half_window, const cpl_boolean normalize){ + + cpl_ensure(half_window > 1, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + const mean_and_stdev not_normalized = {0.0, 1.0}; + + cpl_ensure(arr1 != NULL && arr2 != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_size xcorr_length = 2 * half_window + 1; + cpl_array * corr = cpl_array_new(xcorr_length, HDRL_TYPE_DATA); + + const mean_and_stdev d1 = normalize ? + calculate_mean_and_stdev(arr1) : not_normalized; + const mean_and_stdev d2 = normalize ? + calculate_mean_and_stdev(arr2) : not_normalized; + + cpl_size max_idx = -1; + double max_corr = 0.0; + + for(cpl_size i = -half_window; i <= half_window; ++i){ + const double cr = calculate_xcorr_sample(i, arr1, arr2, d1.mean, d2.mean, + d1.stdev, d2.stdev); + + const cpl_size idx = i + half_window; + cpl_array_set(corr, idx, cr); + + if(isnan(cr)) continue; + + if(cr >= max_corr || max_idx < 0){ + max_corr = cr; + max_idx = idx; + } + } + + return hdrl_xcorrelation_result_wrap(corr, max_idx, half_window); +} + +static inline +cpl_error_code check_if_bad(const hdrl_xcorrelation_result * gfit, + const cpl_boolean check_refine){ + + cpl_ensure_code(gfit != NULL, CPL_ERROR_ILLEGAL_OUTPUT); + cpl_ensure_code(hdrl_xcorrelation_result_get_peak_pixel(gfit) >=0, + CPL_ERROR_ILLEGAL_OUTPUT); + + if(check_refine){ + + const double px = hdrl_xcorrelation_result_get_peak_subpixel(gfit); + cpl_ensure_code(px >= 0.0 && !isnan(px), CPL_ERROR_ILLEGAL_OUTPUT); + + const double sigma = hdrl_xcorrelation_result_get_sigma(gfit); + cpl_ensure_code( sigma > 0.0 && !isnan(sigma),CPL_ERROR_ILLEGAL_OUTPUT); + } + + return CPL_ERROR_NONE; +} + +static inline +cpl_boolean check_and_delete_if_bad(hdrl_xcorrelation_result ** gfit_arg, + const cpl_boolean check_refine){ + + cpl_error_code fail = check_if_bad(*gfit_arg, check_refine); + + if(fail){ + hdrl_xcorrelation_result_delete(*gfit_arg); + *gfit_arg = NULL; + } + + return fail ? CPL_FALSE : CPL_TRUE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Calculate gaussian fit on cross-correlation, does a second fitting for + * refinement. + * @param arr1 First array + * @param arr2 Second array + * @param half_win half search window where the correlation is calculated + * @param normalize CPL_TRUE normalize correlation in mean and rms + * @param bin wavelength bin + * @param wrange half window wavelength range where the fit is going to be + * done + * + * @return gaussian fit for cross correlation. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_xcorrelation_result * hdrl_compute_offset_gaussian( + const cpl_array * arr1, + const cpl_array * arr2, + const cpl_size half_win, const cpl_boolean normalize, + const double bin, const double wrange){ + + cpl_ensure(half_win > 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(arr1 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(arr2 != NULL, CPL_ERROR_NULL_INPUT, NULL); + + hdrl_xcorrelation_result * gfit = + hdrl_compute_offset_gaussian_internal(arr1, arr2, half_win, + normalize, bin, wrange); + + cpl_ensure(gfit != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + const cpl_size half_win2 = + (cpl_size)(3. * CPL_MATH_FWHM_SIG * gfit->sigma / bin); + + hdrl_xcorrelation_result_delete(gfit); + + gfit = hdrl_compute_offset_gaussian_internal(arr1, arr2, half_win2, + normalize, bin, wrange); + + return gfit; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Calculate gaussian fit on cross-correlation + * @param arr1 First array + * @param arr2 Second array + * @param half_win half search window where the correlation is calculated + * @param normalize CPL_TRUE normalize correlation in mean and rms + * @param bin wavelength bin + * @param wrange half window wavelength range where the fit is going to be + * done + * + * @return gaussian fit for cross correlation. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_xcorrelation_result * hdrl_compute_offset_gaussian_internal( + const cpl_array * arr1, const cpl_array * arr2, + const cpl_size half_win, const cpl_boolean normalize, + const double bin, const double wrange){ + + hdrl_xcorrelation_result * res = + hdrl_compute_xcorrelation(arr1, arr2, half_win, normalize); + + if(!check_and_delete_if_bad(&res, CPL_FALSE)) return NULL; + + cpl_error_code fail = + hdrl_compute_xcorrelation_refine(res, bin, wrange); + + if(fail){ + hdrl_xcorrelation_result_delete(res); + return NULL; + } + + if(!check_and_delete_if_bad(&res, CPL_TRUE)) return NULL; + + return res; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Refine a hdrl_xcorrelation_result using gaussian fit + * @param xcorr_res hdrl_xcorrelation_result calculated with pixel precision + * @param bin wavelength bin + * @param wrange half window wavelength range where the fit is going to be + * done + * + * @return gaussian fit for cross correlation. + */ +/* ---------------------------------------------------------------------------*/ +static inline cpl_error_code +hdrl_compute_xcorrelation_refine(hdrl_xcorrelation_result* xcorr_res, + const double bin, const double wrange){ + + const cpl_array * xcorr = hdrl_xcorrelation_result_get_correlation(xcorr_res); + const cpl_size maxpos = hdrl_xcorrelation_result_get_peak_pixel(xcorr_res); + + const cpl_size xcorr_size = cpl_array_get_size(xcorr); + const cpl_size pre_idx = CPL_MAX(0, maxpos - 1); + const cpl_size post_idx = CPL_MIN(maxpos + 1, xcorr_size - 1); + + const double a = cpl_array_get(xcorr, pre_idx, NULL); + const double b = cpl_array_get(xcorr, post_idx, NULL); + const double c = cpl_array_get(xcorr, maxpos, NULL); + /* Find sub-pixel peak initial estimation. Use parabolic assumption */ + const double fraction = (b - a) / ( 4. * c - 2. * a - 2. * b ); + const double subpix_offset = maxpos - fraction; + + xcorr_res->peakpos = subpix_offset * bin; + xcorr_res->sigma = bin * 10; + xcorr_res->area = 1.0; + + cpl_size num_elems = 0; + + cpl_vector * wavs_windowed = cpl_vector_new(xcorr_size); + cpl_vector * corr_windowed = cpl_vector_new(xcorr_size); + + for(cpl_size i = 0; i < xcorr_size; ++i){ + const double w = i * bin; + int rej = 0; + const double xcorr_data = cpl_array_get(xcorr, i, &rej); + + if(rej || isnan(xcorr_data)) continue; + if(w < xcorr_res->peakpos - wrange + || w > xcorr_res->peakpos + wrange) continue; + + cpl_vector_set(corr_windowed, num_elems, xcorr_data); + cpl_vector_set(wavs_windowed, num_elems, w); + + num_elems++; + } + + if(num_elems <= 0){ + cpl_vector_delete(wavs_windowed); + cpl_vector_delete(corr_windowed); + cpl_ensure_code(CPL_FALSE, CPL_ERROR_ILLEGAL_OUTPUT); + } + + cpl_vector_set_size(corr_windowed, num_elems); + cpl_vector_set_size(wavs_windowed, num_elems); + + cpl_error_code code = cpl_vector_fit_gaussian(wavs_windowed, NULL, + corr_windowed, NULL, CPL_FIT_ALL, &xcorr_res->peakpos, &xcorr_res->sigma, + &xcorr_res->area, &xcorr_res->offset, &xcorr_res->mse, NULL, NULL); + + /* if the fitting does not converge, CPL_ERROR_CONTINUE is set, the + * output parameters are calculated using a best-effort approach. + * See the documentation of cpl_vector_fit_gaussian .*/ + if(code == CPL_ERROR_CONTINUE){ + cpl_error_reset(); + } + + cpl_vector_delete(wavs_windowed); + cpl_vector_delete(corr_windowed); + + return cpl_error_get_code(); +} + +static inline +double calculate_xcorr_sample(const cpl_size shift, + const cpl_array * arr1, const cpl_array * arr2, + const double mean1, const double mean2, + const double stdev1, const double stdev2){ + + double d = 0.0; + cpl_size num_el = 0; + + const double norm = 1.00 / sqrt(stdev1 * stdev2); + + const cpl_size l1 = cpl_array_get_size(arr1); + const cpl_size l2 = cpl_array_get_size(arr2); + + for(cpl_size i = 0; i < l2; i++){ + const cpl_size j = i + shift; + int rej1 = 0, rej2 = 0; + if(j < 0) continue; + if(j >= l1) continue; + + const double v1 = cpl_array_get(arr1, j, &rej1); + const double v2 = cpl_array_get(arr2, i, &rej2); + + if(rej1 || rej2) continue; + + const double val = norm * (v1 - mean1) * (v2 - mean2); + + d += val; + num_el++; + } + return d / (double)num_el; +} + +static inline +mean_and_stdev calculate_mean_and_stdev(const cpl_array * arr1){ + + const double mean = cpl_array_get_mean(arr1); + const double stdev = cpl_array_get_stdev(arr1); + + return (mean_and_stdev){mean, stdev}; +} +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_correlation.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_correlation.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_correlation.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_correlation.h 2017-08-25 12:18:43.000000000 +0000 @@ -0,0 +1,97 @@ +/* $Id: hdrl_correlation.h,v 0.1 2017-04-12 16:49:47 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-04-12 16:49:47 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_CORRELATION_H +#define HDRL_CORRELATION_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include "hdrl_types.h" + +CPL_BEGIN_DECLS + + +typedef struct{ + double peakpos; /* Position of the peak of the gaussian fitted to the cross correlation */ + double sigma; /* Width of the gaussian fitted to the cross correlation */ + double area; /* Area of the gaussian fitted to the cross correlation */ + double offset; /* Fitted background level */ + double mse; /* Mean squared error of the best fit */ + cpl_array * xcorr; /* Cross-correlation */ + cpl_size pix_peakpos; /* Pixel position of the peak */ + cpl_size half_window; +}hdrl_xcorrelation_result; + +hdrl_xcorrelation_result * +hdrl_xcorrelation_result_wrap(cpl_array * x_corr, const cpl_size max_idx, + const cpl_size half_window); + +void hdrl_xcorrelation_result_delete(hdrl_xcorrelation_result * self); + +cpl_size +hdrl_xcorrelation_result_get_peak_pixel(const hdrl_xcorrelation_result * self); + +double +hdrl_xcorrelation_result_get_peak_subpixel(const hdrl_xcorrelation_result * self); + +cpl_size +hdrl_xcorrelation_result_get_half_window (const hdrl_xcorrelation_result * self); + +double +hdrl_xcorrelation_result_get_sigma(const hdrl_xcorrelation_result * self); + +const cpl_array * +hdrl_xcorrelation_result_get_correlation(const hdrl_xcorrelation_result * self); + + +hdrl_xcorrelation_result * hdrl_compute_xcorrelation( + const cpl_array * arr1, + const cpl_array * arr2, + const cpl_size half_window, const cpl_boolean normalize); + +hdrl_xcorrelation_result * hdrl_compute_offset_gaussian( + const cpl_array * arr1, + const cpl_array * arr2, + const cpl_size half_win, const cpl_boolean normalize, + const double bin, const double wrange); + +#if defined HDRL_USE_PRIVATE + +hdrl_xcorrelation_result * +hdrl_compute_offset_gaussian_internal( + const cpl_array * arr1, const cpl_array * arr2, + const cpl_size half_win, const cpl_boolean normalize, + const double bin, const double wrange); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_dar.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_dar.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_dar.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_dar.c 2017-10-04 06:06:09.000000000 +0000 @@ -0,0 +1,531 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200112L +#endif + + +/*---------------------------------------------------------------------------* + * Includes * + *---------------------------------------------------------------------------*/ +#include "hdrl_dar.h" + +#include + +/*---------------------------------------------------------------------------* + * Debugging/feature Macros * + *---------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------* + * Static * + *---------------------------------------------------------------------------*/ + + +/*---------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_dar DAR (Differential Atmospheric Refraction) + * + * @brief + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------- + DAR Parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + hdrl_value airmass; /* Air mass */ + hdrl_value parang; /* Parallactic angle during exposure */ + hdrl_value posang; /* Position angle on the sky from the angles we have */ + hdrl_value temp; /* Temperature [Celsius] */ + hdrl_value rhum; /* Relative humidity [%] */ + hdrl_value pres; /* Pressure [mbar] */ + cpl_wcs *wcs; /* World Coordinate system (WCS) in degrees(CDi_j) */ +} hdrl_dar_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_dar_parameter_type = { + HDRL_PARAMETER_DAR, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_dar_parameter), /* obj_size */ +}; + +/*----------------------------------------------------------------------------*/ + /** + * @brief Verify basic correctness of the DAR parameters + * + * @param param Contains all of DAR parameters + * + * @return CPL_ERROR_NONE if everything is ok, an error code otherwise + * + **/ + /*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_dar_parameter_verify(const hdrl_parameter *param) +{ + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + + cpl_error_ensure(hdrl_parameter_check_type(param, &hdrl_dar_parameter_type), CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Expected DAR parameter"); + + const hdrl_dar_parameter *p_loc = (const hdrl_dar_parameter *)param; + hdrl_value airmass = p_loc->airmass; + hdrl_value parang = p_loc->parang; /* Degrees */ + hdrl_value posang = p_loc->posang; /* Degrees */ + hdrl_value temp = p_loc->temp; /* T [Celsius] */ + hdrl_value rhum = p_loc->rhum; /* Relative humidity [%] */ + hdrl_value pres = p_loc->pres; /* Pressure [mbar] */ + + cpl_error_ensure(airmass.data >= 0. && airmass.error >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Airmass parameter not valid"); + + cpl_error_ensure(parang.data >= -180. && parang.data <= 180. && parang.error >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Paralactic angle not valid"); + + cpl_error_ensure(posang.data >= -360. && posang.data <= 360. && posang.error >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Position angle not valid"); + + cpl_error_ensure(temp.data >= -273.15 && temp.error >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Temperature not valid"); + + cpl_error_ensure(rhum.data >= 0. && rhum.data <=100 && rhum.error >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Humidity percent value not valid"); + + cpl_error_ensure( pres.data >= 0. && pres.error >= 0., CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Pressure not valid"); + + cpl_wcs* wcs = p_loc->wcs; /* Degrees */ + + cpl_error_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL WCS Input"); + + return CPL_ERROR_NONE; +} + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Creates DAR parameters object with the values in the header + * + * @param airmass Air mass + * @param parang Parallactic angle during exposure + * @param posang Position angle on the sky from the angles we have + * @param temp Temperature [Celsius] + * @param rhum Relative humidity [%] + * @param pres Pressure [mbar] + * @param wcs World Coordinate system (WCS) in degrees(CDi_j) + * + * @return The dar parameters object. It needs to be deallocated + * with hdrl_parameter_delete() or _destroy() + * + * @note References: + * - based on public domain code of the IDL astro-lib procedure getrot.pro + * - See getrot + * for more info. + * + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_dar_parameter_create(hdrl_value airmass, hdrl_value parang, + hdrl_value posang, hdrl_value temp, hdrl_value rhum, hdrl_value pres, cpl_wcs *wcs) +{ + hdrl_dar_parameter *p = (hdrl_dar_parameter *)hdrl_parameter_new(&hdrl_dar_parameter_type); + + p->airmass = airmass; + p->parang = parang; + p->posang = posang; + p->temp = temp; + p->rhum = rhum; + p->pres = pres; + + p->wcs = wcs; + + /* After add the parameters, verify if they are correct */ + if (hdrl_dar_parameter_verify((hdrl_parameter *)p) != CPL_ERROR_NONE) { + hdrl_parameter_delete((hdrl_parameter*)p); + return NULL; + } + + return (hdrl_parameter *)p; +} + + +/*----------------------------------------------------------------------------*/ +/** + * @brief Correct the pixel coordinates of all pixels of a given pixel table + * for differential atmospheric refraction (DAR). + * + * @param params In: h_parameter with all of params. in the observation + * @param lambdaRef In: Reference wavelength (in Angstroms) + * @param lambdaIn In: One lambda for each plane (in Angstroms) + * @param xShift Out: Correction for each plane in x-axis (pixels) + * @param yShift Out: Correction for each plane in y-axis (pixels) + * @param xShiftErr Out: Error in correction for each plane in x-axis (pix) + * @param yShiftErr Out: Error in correction for each plane in x-axis (pix) + * + * @return CPL_ERROR_NONE on success another CPL error code on failure + * + * @remark The resulting correction can be directly applied to the pixel table. + * + * Loop that compute the DAR offset for the wavelength difference with respect + * to the reference wavelength, and storage the shift in the coordinates, + * taking into account the instrument rotation angle on the sky and the + * parallactic angle at the time of the observations. + * + * The algorithm from Filippenko (1982, PASP, 94, 715). This only uses the formula + * from Owens which converts relative humidity to water vapor pressure. + * + * @note The calculation is performed by calling the top-level function + * hdrl_dar_compute() and the parameters passed to this function can be created + * by calling hdrl_dar_parameter_create(). + * + * @note This module contains routines to calculate the refractive index of air. + * See + * here for the formulae used. + * + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_dar_compute(const hdrl_parameter *params, + const hdrl_value lambdaRef, const cpl_vector *lambdaIn, + cpl_vector *xShift, cpl_vector *yShift, cpl_vector *xShiftErr, cpl_vector *yShiftErr) +{ + + cpl_error_ensure(params && lambdaIn && xShift && yShift != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + + /* Check entry values in hdrl_parameter */ + if (hdrl_dar_parameter_verify(params) != CPL_ERROR_NONE) { + return CPL_ERROR_UNSPECIFIED; + } + + cpl_error_ensure(lambdaRef.data >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "Reference wavelength must be >=0"); + + /* Local Usage Parameters */ + const hdrl_dar_parameter *p_loc = (const hdrl_dar_parameter *)params; + hdrl_value airmass = p_loc->airmass; + hdrl_value parang = p_loc->parang; /* Degrees */ + hdrl_value posang = p_loc->posang; /* Degrees */ + hdrl_value temp = p_loc->temp; /* T [Celsius] */ + hdrl_value rhum = p_loc->rhum; /* Relative humidity [%] */ + hdrl_value pres = p_loc->pres; /* Pressure [mbar] */ + cpl_wcs *wcs = p_loc->wcs; /* Degrees */ + + /* Check if the airmass is at less 1. */ + cpl_ensure_code(airmass.data >= 1., cpl_error_get_code()); + + /* simple zenith distance in radians */ + hdrl_value z = {acos(1. / airmass.data), + airmass.error * fabs( (-1. / pow(airmass.data, 2)) / sqrt(1. - pow(1. / airmass.data, 2)) )}; + + /* ----------------------------------------------------------------- * + * Compute the refractive index at lambdaRef with FILIPPENKO method * + * in um and output properties in "natural" (for the formulae) units * + * ----------------------------------------------------------------- */ + + /* Use the Owens formula to derive saturation pressure. Needs T[K] */ + hdrl_value temp_kel = {temp.data + 273.15, temp.error}; + hdrl_value sp = hdrl_dar_owens_saturation_pressure(temp_kel); + + /* Conversion from hPa (or mbar) to mmHg, needed for Filippenko * + * using that, derive the water vapor pressure in mmHg */ + double HDRL_PHYS_hPa_TO_mmHg = 0.75006158; + + /* Convert relative humidity [%] to fraction */ + rhum.data /= 100.; + rhum.error /= 100.; + + /* water vapor pressure in mmHg */ + hdrl_value fp = {rhum.data *sp.data *HDRL_PHYS_hPa_TO_mmHg, + fabs(HDRL_PHYS_hPa_TO_mmHg * sp.data ) * rhum.error + + fabs(HDRL_PHYS_hPa_TO_mmHg * rhum.data) * sp.error}; + + /* need the pressure in mmHg */ + pres.data *= HDRL_PHYS_hPa_TO_mmHg; + pres.error *= HDRL_PHYS_hPa_TO_mmHg; + + /* refractive index of air at reference wavelength. Needs lambda[um] */ + hdrl_value lambdaRef_um = {lambdaRef.data * 1e-4,lambdaRef.error * 1e-4}; + hdrl_value nr0 = hdrl_dar_filippenko_refractive_index(lambdaRef_um, pres, temp, fp); + + /* Obtain shift with scale: Absolute Shift for a lambdaRef, xshift is in * + * E-W direction for posang = 0, yshift is N-S Shift units --> Degrees */ + hdrl_value x_shift = {-sin( (parang.data + posang.data) * CPL_MATH_RAD_DEG), + parang.error * fabs(-CPL_MATH_RAD_DEG * cos(parang.data + posang.data)) + + posang.error * fabs(-CPL_MATH_RAD_DEG * cos(parang.data + posang.data))}; + + hdrl_value y_shift = { cos( (parang.data + posang.data) * CPL_MATH_RAD_DEG), + parang.error * fabs(-CPL_MATH_RAD_DEG * sin(parang.data + posang.data)) + + posang.error * fabs(-CPL_MATH_RAD_DEG * sin(parang.data + posang.data))}; + + /* Get scale in the world cordinate system (wcs) and apply them */ + double xscale, yscale; + hdrl_dar_wcs_get_scales(wcs, &xscale, &yscale); + + x_shift.data /= xscale; + x_shift.error /= xscale; + + y_shift.data /= yscale; + y_shift.error /= yscale; + + /* Diff. refr. base in arcsec converted from radians (Filippenko does * + * the conversion using x206265 which converts radians to arcsec) */ + hdrl_value dr0 = {tan(z.data) * CPL_MATH_DEG_RAD, + z.error * fabs( (1. + pow(tan(z.data), 2)) * CPL_MATH_DEG_RAD)}; + + /* ------------------------------------------------------------------ * + * Calculate the relative lambda of in array (in) * + * apply the absolute shift (x_shift, y_shift) for lamdaRef * + * for obtain the out arrays (xShift, yShift ) * + * ------------------------------------------------------------------ */ + cpl_size i; + cpl_size nmax = cpl_vector_get_size(lambdaIn); + + HDRL_OMP(omp parallel for \ + default(none) \ + shared( nmax, lambdaIn, \ + xShift, yShift, xShiftErr, yShiftErr, \ + lambdaRef_um, pres, temp, fp, dr0, nr0, \ + x_shift, y_shift )) + for (i = 0; i < nmax; i++) { + + double lambda = cpl_vector_get(lambdaIn, i); + if (isfinite(lambda) != 0) { + + hdrl_value lambda_um = {lambda * 1e-4, lambdaRef_um.error}; + hdrl_value nr = hdrl_dar_filippenko_refractive_index(lambda_um, pres, temp, fp); + + hdrl_value dr = {dr0.data * (nr0.data - nr.data), + dr0.error * fabs(nr0.data - nr.data) + + nr0.error * fabs( dr0.data) + + nr.error * fabs(-dr0.data)}; + + hdrl_value shiftPlaneX = {x_shift.data * dr.data, + x_shift.error * fabs(dr.data) + + dr.error * fabs(x_shift.data)}; + cpl_vector_set(xShift, i, shiftPlaneX.data ); + cpl_vector_set(xShiftErr, i, shiftPlaneX.error); + + hdrl_value shiftPlaneY = {y_shift.data * dr.data, + y_shift.error * fabs(dr.data) + + dr.error * fabs(y_shift.data)}; + cpl_vector_set(yShift, i, shiftPlaneY.data ); + cpl_vector_set(yShiftErr, i, shiftPlaneY.error); + + } else { + + cpl_vector_set(xShift, i, NAN); + cpl_vector_set(xShiftErr, i, NAN); + + cpl_vector_set(yShift, i, NAN); + cpl_vector_set(yShiftErr, i, NAN); + } + } + + return CPL_ERROR_NONE; +} + + +/*----------------------------------------------------------------------------*/ +/** + * @brief Compute the saturation pressure using the Owens calibration. + * + * @param hvT temperature (in Kelvin) wit it error associated + * + * @return the saturation pressure for the given temperature with it error propagation + * + * \f[ + * s_p = -10474 +116.43\ T -0.43284\ T^2 +0.00053840\ T^3 + * \f] + * where T is the temperature. + * + * @note This function is used for the Filippenko formulae. + * + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_dar_owens_saturation_pressure(hdrl_value hvT) +{ + double T = hvT.data; + double errorT = hvT.error; + + return (hdrl_value){-10474.0 + 116.43 * T - 0.43284 * T * T + 0.00053840 * pow(T, 3), + errorT * fabs(0.0016152 * T * T - 0.86568 * T + 116.43)}; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Compute the refractive index for the given wavelength following + * Filippenko formulae. This function is called by hdrl_dar_compute(). + * + * @param hvL the wavelength (in um) with it error associated + * @param hvP atmospheric pressure (in mmHg) with it error associated + * @param hvT temperature (in degrees Celsius) with it error associated + * @param hvF water vapor pressure (in mmHg) with it error associated + * + * @return The refractive index with it error propagation + * + * At sea level (P=760 mm Hg, T = 15 \f$^oC\f$) the refractive index of dry air is given + * by (Edlén 1953; Coleman, Bozman, and Meggers 1960): + * \f[ + * (n( \lambda )_{15,760}-1)10^6 = 64.328 + \frac{29498.1}{146-(1/ \lambda )^2} +\frac{255.4}{41-(1/ \lambda )^2} + * \f] + * where \lambda is the wavelength of light in vacue (microns). Since observatories + * are usually located at high altitudes, the index of refraction must be corrected + * for the lower ambient temperature and pressure (Barrell 1951): + * \f[ + * (n(\lambda)_{T,P} -1) = (n(\lambda)_{15,760} - 1) \cdot + * \frac{P[1+(1.049-0.0157\ T) 10^{-6}\ P]}{720.883 (1+0.003661\ T)} + * \f] + * In addition, the presence of water vapor in the atmosphere reduces \f$(n-1)10^6\f$ by: + * \f[ + * \frac{0.0624-0.000680/\lambda^2}{1 + 0.003661\ T} f + * \f] + * here \f$f\f$ is the water vapor pressure in mm of Hg and T is the air temperature + * in \f$^oC\f$ (Barrell 1951). + * \f[ + * f = 0.75006158 \cdot s_p \cdot h + * \f] + * where \f$s_p\f$ is the saturation pressure with Owens calibration and h is the fraction + * of humidity in [%]. + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_dar_filippenko_refractive_index( + hdrl_value hvL, hdrl_value hvP, hdrl_value hvT, hdrl_value hvF) +{ + double l = hvL.data, + P = hvP.data, + T = hvT.data, + f = hvF.data; + + double errorL = hvL.error, + errorP = hvP.error, + errorT = hvT.error, + errorF = hvF.error; + + /* inverse square of the wavelength */ + double lisq = 1. / (l * l); + double errorLisq = errorL * fabs(-2. / pow(l, 3) ); + + /* 10^6 [n(lambda) - 1] at standard environmental conditions, Eq. (1) */ + double nl1 = 64.328 + 29498.1 / (146. - lisq) + 255.4 / (41. - lisq); + double errorNl1 = errorLisq * fabs( 29498.1 / pow(146. - lisq, 2) + 255.4 / pow(41. - lisq, 2) ); + + /* correction for non-standard conditions, Eq. (2) */ + double nl2A = nl1 * ( P / 720.883 * (1. + (1.049 -0.0157 * T) * 1e-6 * P) / (1. + 0.003661 * T) ); + double errorNl2A1 = errorNl1 * fabs( P / 720.883 * (1. + (1.049 - 0.0157 * T) * 1e-6 * P) / (1. + 0.003661 * T) ); + double errorNl2A2 = errorP * fabs( nl1 / (720.883 * (1. + 0.003661 * T)) *( (1. + (1.049 - 0.0157 * T) * 1e-6 * P) + P * (1.049 - 0.0157 * T) * 1e-6) ); + double errorNl2A3 = errorT * fabs( nl1 * P / 720.883 * ( ( -0.0157 * 1e-6 * P * (1. + 0.003661 * T) - 0.003661 * (1. + (1.049 - 0.0157 * T) * 1e-6 * P) )/pow(1. + 0.003661 * T, 2) ) ); + double errorNl2A = errorNl2A1 + errorNl2A2 + errorNl2A3; + + /* Calcule correction for water vapor, Eq. (3) */ + double nl2B = (0.0624 - 0.000680 * lisq) / (1. + 0.003661 * T) * f; + double errorNl2B1 = errorLisq * fabs( -0.000680 * f / (1. + 0.003661 * T) ); + double errorNl2B2 = errorT * fabs( -0.003661 * (0.0624 - 0.000680 * lisq) * f / pow(1. + 0.003661 * T, 2) ); + double errorNl2B3 = errorF * fabs( (0.0624 - 0.000680 * lisq) / (1. + 0.003661 * T) ); + double errorNl2B = errorNl2B1 + errorNl2B2 + errorNl2B3; + + /* Apply correction for water vapor, Eq. (3) */ + double nl2 = nl2A - nl2B; + double errorNl2 = errorNl2A + errorNl2B; + + /* convert to refractive index n(lambda) */ + double nl3 = nl2 * 1e-6 + 1.; + double errorNl3 = fabs(errorNl2 * 1e-6); + + return (hdrl_value){nl3,errorNl3}; +} + + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + * @brief Compute the spatial scales (in degrees) from the FITS header WCS. + * + * @param header the input header containing the WCS of the exposure + * @param aXScale the output scale in x-direction + * @param aYScale the output scale in y-direction + * + * @return CPL_ERROR_NONE for success, any other value for failure + * + * The world coordinate system from header, i.e. the CDi_j matrix, is used to + * compute the scales. + * + * @note References: + * - based on public domain code of the IDL astro-lib procedure getrot.pro + * - http://idlastro.gsfc.nasa.gov/ftp/pro/astrom/getrot.pro + * + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_dar_wcs_get_scales( + cpl_wcs *wcs, + double *aXScale, + double *aYScale) +{ + cpl_ensure_code(aXScale && aYScale, CPL_ERROR_NULL_INPUT); + + cpl_errorstate prestate = cpl_errorstate_get(); + + const cpl_matrix *cd = cpl_wcs_get_cd(wcs); + + /* take the absolute and scale by 3600 to get positive arcseconds */ + double cd11 = cpl_matrix_get(cd, 0, 0), + cd12 = cpl_matrix_get(cd, 0, 1), + cd21 = cpl_matrix_get(cd, 1, 0), + cd22 = cpl_matrix_get(cd, 1, 1); + + double det = cd11 * cd22 - cd12 * cd21; + cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code()); + + if (det < 0.) { + cd12 *= -1.; + cd11 *= -1.; + } + + /* matrix without rotation */ + if (cd12 == 0. && cd21 == 0.) { + *aXScale = cd11; + *aYScale = cd22; + return CPL_ERROR_NONE; + } + + /* Only the absolute value */ + *aXScale = sqrt(cd11 * cd11 + cd12 * cd12); + *aYScale = sqrt(cd22 * cd22 + cd21 * cd21); + + return CPL_ERROR_NONE; +} + +/** @endcond */ + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_dar.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_dar.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_dar.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_dar.h 2017-08-24 12:07:21.000000000 +0000 @@ -0,0 +1,88 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_DAR_H_ +#define HDRL_DAR_H_ + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_parameter.h" + +#include + + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + DAR Parameters Definition + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------* + * Special variable types * + *----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------* + * Struct variable types * + *----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + Parameters + ----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + Computation + ----------------------------------------------------------------------------*/ + +hdrl_parameter * hdrl_dar_parameter_create(hdrl_value airmass, hdrl_value parang, + hdrl_value posang, hdrl_value temp, hdrl_value rhum, hdrl_value pres, cpl_wcs *wcs); + +cpl_error_code hdrl_dar_compute(const hdrl_parameter *params, + const hdrl_value lambdaRef, const cpl_vector *lambdaIn, + cpl_vector *xShift, cpl_vector *yShift, cpl_vector *xShiftErr, cpl_vector *yShiftErr); + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + + cpl_error_code hdrl_dar_parameter_verify(const hdrl_parameter *param); + + hdrl_value hdrl_dar_owens_saturation_pressure(hdrl_value hvT); + + hdrl_value hdrl_dar_filippenko_refractive_index( + hdrl_value hvL, hdrl_value hvP, hdrl_value hvT, hdrl_value hvF); + + cpl_error_code hdrl_dar_wcs_get_scales( + cpl_wcs *wcs, double *aXScale, double *aYScale); + +#endif + +CPL_END_DECLS + +#endif /* HDRL_DAR_H_ */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_DER_SNR.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_DER_SNR.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_DER_SNR.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_DER_SNR.c 2017-08-22 09:42:21.000000000 +0000 @@ -0,0 +1,315 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_DER_SNR.h" +#include "hdrl_image.h" +#include "hdrl_utils.h" + +#include +#include + +/* returns TRUE iff lambdas(i) < lambdas(i + 1) for every i */ +static inline cpl_boolean is_strictly_monotonic(const cpl_array * lambdas); + +static inline cpl_boolean +should_skip(const cpl_binary * msk, cpl_size i1, cpl_size i2, cpl_size i3); + +/* DER_SNR estimation if the wavelengths are strictly monotonically increasing*/ +static inline cpl_image * +estimate_noise_DER_SNR_on_sorted(const hdrl_data_t * flux, + const cpl_binary * msk_in, const cpl_size length, + const cpl_size half_window); + +/* insert the arrays in the table and sorty according to wavelength. The + * table is returned*/ +static inline +cpl_table * conv_to_sorted_table(const hdrl_data_t * flux_in, + const cpl_binary * msk_in, const cpl_array * wavelengths, + const cpl_size length); + +/* DER_SNR estimation if the wavelengths are NOT strictly monotonically + * increasing*/ +static inline cpl_image * +estimate_noise_DER_SNR_on_unsorted(const hdrl_data_t * flux_in, + const cpl_binary * msk_in, const cpl_array * wavelengths, + const cpl_size length, const cpl_size half_window); + +/** + * @addtogroup hdrl_spectrum1D + * @{ + */ +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Estimate the noise in the pixels between [start, stop]. The noise + * calculation is done using the formula from: Stoehr, F. et al. + * DER SNR: A Simple & General Spectroscopic Signal-to-Noise Measurement Algorithm + * @param flux Input Flux + * @param msk Bad Pixel Mask + * @param start First Pixel + * @param stop Last Pixel + * @param sz Length of the flux (must be the same for msk) + * @return estimated noise for the given window, NAN is returned in case of + * error or if there are not enough non bad pixels to execute the calculation. + * + * Possible cpl-error-code set in this function (which also implies + * that NAN is returned): + * - CPL_ERROR_NULL_INPUT: if flux or msk are NULL + * - CPL_ERROR_INCOMPATIBLE_INPUT: if start, stop and size are either not + * compatible with each other or if the resulting window is too small to + * calculate the noise (there must be at least 4 pixels between start and stop). + */ +/* ---------------------------------------------------------------------------*/ +hdrl_error_t estimate_noise_window(const hdrl_data_t * flux, + const cpl_binary * msk, cpl_size start, cpl_size stop, + const cpl_size sz){ + + const hdrl_data_t factor = CPL_MATH_STD_MAD / sqrt(6.0); + + cpl_ensure(flux != NULL, CPL_ERROR_NULL_INPUT, NAN); + + cpl_ensure(start >= 0, CPL_ERROR_INCOMPATIBLE_INPUT, NAN); + cpl_ensure(stop > start, CPL_ERROR_INCOMPATIBLE_INPUT, NAN); + + + cpl_ensure(stop < sz, CPL_ERROR_INCOMPATIBLE_INPUT, NAN); + + start += 2; + stop -= 2; + + const cpl_size max_elems = stop - start + 1; + + cpl_ensure(max_elems > 0 , CPL_ERROR_INCOMPATIBLE_INPUT, NAN); + + cpl_array * data = cpl_array_new(max_elems, HDRL_TYPE_ERROR); + cpl_array_fill_window_invalid(data, 0, max_elems - 1); + + for(cpl_size i = start; i <= stop; ++i){ + + const cpl_size i_pre = i - 2; + const cpl_size i_post = i + 2; + + if(should_skip(msk, i, i_pre, i_post)) continue; + + const hdrl_data_t curr = flux[i]; + const hdrl_data_t pre = flux[i_pre]; + const hdrl_data_t next = flux[i_post]; + + const hdrl_error_t noise = + (hdrl_error_t)fabs(factor * (2.0 * curr - pre - next)); + cpl_array_set(data, i - start, noise); + } + + hdrl_error_t median = NAN; + + /* If no pixels were available for DER_SNR calculation, return NAN */ + if(cpl_array_count_invalid(data) < max_elems) + median = cpl_array_get_median(data); + + cpl_array_delete(data); + + return median; + +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief For every pixel in position i in img_arg, the function estimates the + * noise using the pixels in the window [i - half_window, i + half_window]. + * For details on the calculation inside the window, see estimate_noise_window() + * @param flux_in input flux + * @param msk_in bad pixels mask + * @param wavelengths wavelengths of the spectrum + * @param length length of the flux and msl + * @param half_window half window used to calculate the noise for each pixel. + * @return the estimate standard deviation for each pixel or NULL in case of error. + * + * Possible cpl-error-code set in this function (which also implies + * that NULL is returned): + * - CPL_ERROR_NULL_INPUT: if any among flux_in, msk_in or wavelengths are NULL + * - CPL_ERROR_INCOMPATIBLE_INPUT: if half_window < 2 or length > 4 + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * +estimate_noise_DER_SNR(const hdrl_data_t * flux_in, const cpl_binary * msk_in, + const cpl_array * wavelengths, const cpl_size length, + const cpl_size half_window){ + + cpl_ensure(half_window >= 2, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(flux_in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(wavelengths != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(length > 4, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + /* simple case */ + if(is_strictly_monotonic(wavelengths)) + return estimate_noise_DER_SNR_on_sorted + (flux_in, msk_in, length, half_window); + + /* complex case, we need to sort copies of the data calculate DER_SNR and + * put the correct noise sample in the correct spot, following the positioning + * provided as input*/ + return estimate_noise_DER_SNR_on_unsorted(flux_in, msk_in, wavelengths, + length, half_window); +} + +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ + +static inline cpl_image * +estimate_noise_DER_SNR_on_sorted(const hdrl_data_t * flux, + const cpl_binary * msk_in, const cpl_size length, + const cpl_size half_window){ + + cpl_image * to_ret = cpl_image_new(length, 1, HDRL_TYPE_ERROR); + cpl_mask * msk = cpl_mask_new(length, 1); + + for(cpl_size i = 0; i < length; ++i){ + + cpl_boolean rej = msk_in != NULL && msk_in[i]; + + double d = NAN; + /* skip if bad pixel */ + if(!rej) + { + const cpl_size start = CPL_MAX(0, i - half_window); + const cpl_size stop = CPL_MIN(length - 1, i + half_window); + d = estimate_noise_window(flux, msk_in, start, stop, length); + } + + cpl_image_set(to_ret, i + 1, 1, d); + + if(isnan(d)){ + cpl_mask_set(msk, i + 1, 1, CPL_BINARY_1); + } + } + + cpl_mask_delete(cpl_image_set_bpm(to_ret, msk)); + return to_ret; +} + +static inline +cpl_table * conv_to_sorted_table(const hdrl_data_t * flux_in, + const cpl_binary * msk_in, const cpl_array * wavelengths, + const cpl_size length){ + + cpl_table * tb = cpl_table_new(length); + int * map = cpl_calloc(length, sizeof(int)); + int * pmask = cpl_calloc(length, sizeof(int)); + hdrl_data_t * flux = cpl_calloc(length, sizeof(hdrl_data_t)); + double * pwlen = cpl_calloc(length, sizeof(double)); + + for(cpl_size i = 0; i < length; ++i){ + map[i] = i; + pwlen[i] = cpl_array_get(wavelengths, i, NULL); + pmask[i] = msk_in == NULL ? 0 : (int)msk_in[i]; + flux[i] = flux_in[i]; + } + + cpl_table_wrap_int(tb, map, "map"); + cpl_table_wrap_int(tb, pmask, "bad_pixel_mask"); + cpl_table_wrap_double(tb, pwlen, "lambda"); + hdrl_wrap_table(tb, flux, "flux"); + + cpl_propertylist * ls = cpl_propertylist_new(); + cpl_propertylist_append_bool(ls, "lambda", CPL_FALSE); + cpl_table_sort(tb, ls); + cpl_propertylist_delete(ls); + return tb; +} + +static inline cpl_image * +estimate_noise_DER_SNR_on_unsorted(const hdrl_data_t * flux_in, + const cpl_binary * msk_in, const cpl_array * wavelengths, + const cpl_size length, const cpl_size half_window){ + + cpl_binary * msk_sorted = cpl_calloc(length, sizeof(cpl_binary)); + + cpl_table * tb = conv_to_sorted_table(flux_in, msk_in, wavelengths, length); + + /* extract columns */ + int * map = (int*)cpl_table_unwrap(tb, "map"); + hdrl_data_t * flux = (hdrl_data_t*)cpl_table_unwrap(tb, "flux"); + int * pmask = (int*)cpl_table_unwrap(tb, "bad_pixel_mask"); + + cpl_table_delete(tb); + + /* convert to a cpl_binary array the sorted masks */ + for(cpl_size i = 0; i < length; ++i){ + msk_sorted[i] = pmask[i]; + } + cpl_free(pmask); + + cpl_image * img_sorted = estimate_noise_DER_SNR_on_sorted + (flux, msk_sorted, length, half_window); + + cpl_free(flux); + cpl_free(msk_sorted); + + cpl_image * to_ret = cpl_image_new(length, 1, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < length; i++){ + const cpl_size dest_idx = map[i] + 1; + const cpl_size source_idx = i + 1; + + int rej; + double data = cpl_image_get(img_sorted, source_idx, 1, &rej); + if(rej){ + cpl_image_reject(to_ret, dest_idx, 1); + } + else{ + cpl_image_set(to_ret, dest_idx, 1, data); + } + } + + cpl_free(map); + cpl_image_delete(img_sorted); + return to_ret; +} + +static inline cpl_boolean is_strictly_monotonic(const cpl_array * lambdas){ + for(cpl_size i = 0; i < cpl_array_get_size(lambdas) - 1; ++i){ + if(cpl_array_get(lambdas, i, NULL) >= cpl_array_get(lambdas, i + 1, NULL)){ + return CPL_FALSE; + } + } + return CPL_TRUE; +} + +static inline cpl_boolean +should_skip(const cpl_binary * msk, cpl_size i1, cpl_size i2, cpl_size i3){ + + /*no mask means all the pixel are good*/ + if(!msk) return CPL_FALSE; + + return msk[i1] || msk[i2] || msk[i3]; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_DER_SNR.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_DER_SNR.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_DER_SNR.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_DER_SNR.h 2017-08-25 12:05:37.000000000 +0000 @@ -0,0 +1,50 @@ +/* $Id: hdrl_DER_SNR.h,v 0.1 2017-03-02 15:38:44 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-03-02 15:38:44 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_DER_SNR_H +#define HDRL_DER_SNR_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include "hdrl_types.h" + +CPL_BEGIN_DECLS + +hdrl_error_t estimate_noise_window(const hdrl_data_t * flux, const cpl_binary * msk, + cpl_size start, cpl_size stop, const cpl_size sz); + +cpl_image * +estimate_noise_DER_SNR(const hdrl_data_t * flux_in, const cpl_binary * msk_in, + const cpl_array * wavelengths, const cpl_size length, + const cpl_size half_window); + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_efficiency.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_efficiency.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_efficiency.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_efficiency.c 2017-08-28 09:37:00.000000000 +0000 @@ -0,0 +1,497 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include + +#include "hdrl_spectrum.h" +#include "hdrl_spectrum_resample.h" +#include "hdrl_parameter.h" +#include + +/*----------------------------------------------------------------------------- + Private Functions and Data Structures + -----------------------------------------------------------------------------*/ + +/*Parameter used for the efficiency calculation*/ +typedef struct { + HDRL_PARAMETER_HEAD; + hdrl_value Ap; + hdrl_value Am; + hdrl_value G; + hdrl_value Tex; + hdrl_value Atel; +} hdrl_efficiency_parameters; + +static hdrl_parameter_typeobj +hdrl_efficiency_parameters_type = { + HDRL_PARAMETER_EFFICIENCY, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_efficiency_parameters), /* obj_size */ +}; + +static inline cpl_error_code +hdrl_efficiency_parameter_check(const hdrl_parameter * pars); + +static inline hdrl_value +hdrl_efficiency_parameter_get_Am(const hdrl_parameter * pars); +static inline hdrl_value +hdrl_efficiency_parameter_get_Ap(const hdrl_parameter * pars); +static inline hdrl_value +hdrl_efficiency_parameter_get_G(const hdrl_parameter * pars); +static inline hdrl_value +hdrl_efficiency_parameter_get_Tex(const hdrl_parameter * pars); +static inline hdrl_value +hdrl_efficiency_parameter_get_Atel(const hdrl_parameter * pars); + +static inline hdrl_spectrum1D * +select_obs_spectrum(const hdrl_spectrum1D * I_std, + const hdrl_spectrum1D * I_std_ref, + const hdrl_spectrum1D * E_x); + +static inline hdrl_data_t +lowest_w_max(const cpl_array * a1, const cpl_array * a2); + +static inline hdrl_data_t +highest_w_min(const cpl_array * a1, const cpl_array * a2); + +/** + * @addtogroup hdrl_efficiency + * @{ + */ +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief ctor for the hdrl_parameter for response + * @param Ap Parameter to indicate if the efficiency is computed at + * airmass = 0, or at a given non zero value + * @param Am Airmass at which the std star was observed + * @param G Gain [e/ADU] + * @param Tex Exposure time [s] + * + * @return hdrl_parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter* hdrl_response_parameter_create( + const hdrl_value Ap, const hdrl_value Am, const hdrl_value G, + const hdrl_value Tex){ + + hdrl_efficiency_parameters * p + = (hdrl_efficiency_parameters *) + hdrl_parameter_new(&hdrl_efficiency_parameters_type); + + p->Am = Am; + p->Ap = Ap; + p->G = G; + p->Tex = Tex; + p->Atel = (hdrl_value){0.0, 0.0}; + return (hdrl_parameter*) p; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief ctor for the hdrl_parameter for efficiency + * @param Ap Parameter to indicate if the efficiency is computed at + * airmass = 0, or at a given non zero value + * @param Am Airmass at which the std star was observed + * @param G Gain [e/ADU] + * @param Tex Exposure time [s] + * @param Atel Collecting area of the telescope [cm2] + * + * @return hdrl_parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter* hdrl_efficiency_parameter_create( + const hdrl_value Ap, const hdrl_value Am, const hdrl_value G, + const hdrl_value Tex, const hdrl_value Atel){ + + hdrl_efficiency_parameters * p + = (hdrl_efficiency_parameters *) + hdrl_parameter_new(&hdrl_efficiency_parameters_type); + + p->Am = Am; + p->Ap = Ap; + p->G = G; + p->Tex = Tex; + p->Atel = Atel; + return (hdrl_parameter*) p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief core response calculation + * @param I_std_arg std star observed spectrum, wavelength in [nm] + * @param I_std_ref std start model spectrum, wavelength in [nm] + * @param E_x atm. extinction model spectrum, wavelength in [nm] + * @param pars parameters, see the constructor for + * hdrl_efficiency_parameter_create + * @return response, NULL in case of error + * + * This function implements the efficiency calculation. The formula used is: + * + * I_std_ref(l)* G * Tex * 10^(0.4 * (Ap-Am) * E_x(l)) + * Res(l)= ----------------------------------------------------------- + * I_std(l) + * + * Where I_std_ref and E_x spectra are resampled by this function to match + * the wavelengths where I_std is defined on. If E_x and I_std_ref already match + * the wavelengths of I_std resampling is not executed. If E_x or I_std_ref do not + * completely cover the wavelength interval where I_std is defined, I_std is + * truncated to avoid extrapolation of the models. + * For the other parameters see hdrl_response_parameter_create(). + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the spectra or parameter are NULL + * - For other errors see hdrl_spectrum1D_resample(), and arithmetic functions + * for spectrum processing (e.g. hdrl_spectrum1D_div_spectrum_create()) + */ +/* ---------------------------------------------------------------------------*/ + + +hdrl_spectrum1D * +hdrl_response_core_compute( +const hdrl_spectrum1D * I_std_arg, +const hdrl_spectrum1D * I_std_ref, +const hdrl_spectrum1D * E_x, +const hdrl_parameter * pars){ + + cpl_ensure(I_std_arg != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(I_std_ref != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(E_x != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pars != NULL, CPL_ERROR_NULL_INPUT, NULL); + + const hdrl_value Ap = hdrl_efficiency_parameter_get_Ap(pars); + const hdrl_value Am = hdrl_efficiency_parameter_get_Am(pars); + const hdrl_value G = hdrl_efficiency_parameter_get_G(pars); + const hdrl_value Tex = hdrl_efficiency_parameter_get_Tex(pars); + + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * I_std = select_obs_spectrum(I_std_arg, I_std_ref, E_x); + + cpl_ensure(I_std != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + const hdrl_spectrum1D_wavelength spec_wav = + hdrl_spectrum1D_get_wavelength(I_std); + + hdrl_parameter *params = hdrl_spectrum1D_resample_interpolate_parameter_create( + hdrl_spectrum1D_interp_akima); + hdrl_spectrum1D *exponential = hdrl_spectrum1D_resample(E_x, &spec_wav, params); + hdrl_parameter_delete(params); + cpl_ensure(exponential != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + params = hdrl_spectrum1D_resample_interpolate_parameter_create( + hdrl_spectrum1D_interp_akima); + hdrl_spectrum1D * I_std_ref_resampled = hdrl_spectrum1D_resample(I_std_ref, + &spec_wav, params); + hdrl_parameter_delete(params); + cpl_ensure(I_std_ref_resampled != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + + /* exponent of 10.0*/ + { + hdrl_spectrum1D * exponential2 = hdrl_spectrum1D_duplicate(exponential); + + /*0.4A_pE_x(f) */ + hdrl_spectrum1D_mul_scalar(exponential, (hdrl_value){0.4, 0.0}); + hdrl_spectrum1D_mul_scalar(exponential, Ap); + + /*0.4A_mE_x(f) */ + hdrl_spectrum1D_mul_scalar(exponential2, (hdrl_value){0.4, 0.0}); + hdrl_spectrum1D_mul_scalar(exponential2, Am); + + /*0.4A_pE_x(f) - 0.4A_mE_x(f) */ + hdrl_spectrum1D_sub_spectrum(exponential, exponential2); + + hdrl_spectrum1D_delete(&exponential2); + } + + hdrl_spectrum1D_exp_scalar(exponential, (hdrl_value){10.0, 0.0}); + hdrl_spectrum1D_mul_scalar(exponential, G); + hdrl_spectrum1D_mul_spectrum(exponential, I_std_ref_resampled); + hdrl_spectrum1D_mul_scalar(exponential, Tex); + hdrl_spectrum1D_div_spectrum(exponential, I_std); + + hdrl_spectrum1D_delete(&I_std_ref_resampled); + hdrl_spectrum1D_delete(&I_std); + + return exponential; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief efficiency calculation + * @param I_std_arg std star observed spectrum, wavelength in [nm] + * @param I_std_ref std start model spectrum, wavelength in [nm] + * @param E_x atm. extinction model spectrum, wavelength in [nm] + * @param pars parameters, see the constructor for + * hdrl_spectrum1D_efficiency_parameter_create + * @return efficiency, NULL in case of error + * + * This function implements the efficiency calculation. The formula used is: + * + * I_std(l) * 10^(0.4 * E_x(l) * (Ap-Am)) * G * E_phot(l) + * Eff(l)= ----------------------------------------------------------- + * Tex * Atel * I_std_ref(l) + * + * Where I_std_ref and E_x spectra are resampled by this function to match + * the wavelengths where I_std is defined on. If E_x and I_std_ref already match + * the wavelengths of I_std resampling is not executed. + * E_phot is the energy of one photon. For the other parameters see + * hdrl_spectrum1D_efficiency_parameter_create(). If E_x or I_std_ref do not + * completely cover the wavelength interval where I_std is defined, I_std is + * truncated to avoid extrapolation of the models. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the spectra or parameter are NULL + * - For other errors see hdrl_spectrum1D_resample(), and arithmetic functions + * for spectrum processing (e.g. hdrl_spectrum1D_div_spectrum_create()) + */ +/* ---------------------------------------------------------------------------*/ + +hdrl_spectrum1D * hdrl_efficiency_compute( + const hdrl_spectrum1D * I_std_arg, + const hdrl_spectrum1D * I_std_ref, + const hdrl_spectrum1D * E_x, + const hdrl_parameter * pars) +{ + + cpl_ensure(I_std_arg != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(I_std_ref != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(E_x != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pars != NULL, CPL_ERROR_NULL_INPUT, NULL); + + const hdrl_value Ap = hdrl_efficiency_parameter_get_Ap(pars); + const hdrl_value Am = hdrl_efficiency_parameter_get_Am(pars); + const hdrl_value G = hdrl_efficiency_parameter_get_G(pars); + const hdrl_value Tex = hdrl_efficiency_parameter_get_Tex(pars); + const hdrl_value Atel = hdrl_efficiency_parameter_get_Atel(pars); + + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * I_std = select_obs_spectrum(I_std_arg, I_std_ref, E_x); + cpl_ensure(I_std != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + const hdrl_spectrum1D_wavelength spec_wav = hdrl_spectrum1D_get_wavelength(I_std); + + hdrl_parameter * params = hdrl_spectrum1D_resample_interpolate_parameter_create( + hdrl_spectrum1D_interp_akima); + hdrl_spectrum1D * exponential = hdrl_spectrum1D_resample(E_x, + &spec_wav, params); + hdrl_parameter_delete(params); + cpl_ensure(exponential != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + params = hdrl_spectrum1D_resample_interpolate_parameter_create( + hdrl_spectrum1D_interp_akima); + hdrl_spectrum1D * I_std_ref_resampled = hdrl_spectrum1D_resample(I_std_ref, + &spec_wav, params); + hdrl_parameter_delete(params); + cpl_ensure(I_std_ref_resampled != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + /* exponent of 10.0*/ + { + hdrl_spectrum1D * exponential2 = hdrl_spectrum1D_duplicate(exponential); + + /*0.4A_pE_x(f) */ + hdrl_spectrum1D_mul_scalar(exponential, (hdrl_value){0.4, 0.0}); + hdrl_spectrum1D_mul_scalar(exponential, Ap); + + /*0.4A_mE_x(f) */ + hdrl_spectrum1D_mul_scalar(exponential2, (hdrl_value){0.4, 0.0}); + hdrl_spectrum1D_mul_scalar(exponential2, Am); + + /*0.4A_pE_x(f) - 0.4A_mE_x(f) */ + hdrl_spectrum1D_sub_spectrum(exponential, exponential2); + + hdrl_spectrum1D_delete(&exponential2); + } + + hdrl_spectrum1D * eph_spec = hdrl_spectrum1D_create_analytic( + E_ph, spec_wav.wavelength, spec_wav.scale); + + hdrl_spectrum1D_exp_scalar(exponential, (hdrl_value){10.0, 0.0}); + hdrl_spectrum1D_mul_scalar(exponential, G); + hdrl_spectrum1D_mul_spectrum(exponential, I_std); + hdrl_spectrum1D_mul_spectrum(exponential, eph_spec); + hdrl_spectrum1D_div_scalar(exponential, Tex); + hdrl_spectrum1D_div_scalar(exponential, Atel); + hdrl_spectrum1D_div_spectrum(exponential, I_std_ref_resampled); + + hdrl_spectrum1D_delete(&eph_spec); + hdrl_spectrum1D_delete(&I_std_ref_resampled); + hdrl_spectrum1D_delete(&I_std); + return exponential; + +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief energy of the photon calculation + * @param lambda wavelength, in nm + * @return energy of the photon for the given wavelength + */ +/* ---------------------------------------------------------------------------*/ +hdrl_value E_ph(hdrl_data_t lambda){ + const double nm2um = 0.001; + const double hc = 1.e7*1.986e-19 / nm2um; + + return (hdrl_value){ hc / lambda, 0.0}; +} + +/*----------------------------------------------------------------------------- + Private Functions Implementation + -----------------------------------------------------------------------------*/ +/* check that hdrl_parameter is an compatible with the efficiency computation + * routine.*/ +static inline cpl_error_code +hdrl_efficiency_parameter_check(const hdrl_parameter * pars){ + + + cpl_ensure_code(pars != NULL, CPL_ERROR_NULL_INPUT); + + cpl_boolean is_compatible = hdrl_parameter_get_parameter_enum(pars) == + HDRL_PARAMETER_EFFICIENCY; + cpl_ensure_code(is_compatible , CPL_ERROR_INCOMPATIBLE_INPUT); + + return CPL_ERROR_NONE; +} + +static inline hdrl_value +hdrl_efficiency_parameter_get_Am(const hdrl_parameter * pars){ + + if(hdrl_efficiency_parameter_check(pars)) + return (hdrl_value){0.0,0.0}; + + const hdrl_efficiency_parameters * p + = (const hdrl_efficiency_parameters*)pars; + + return p->Am; +} + +static inline hdrl_value +hdrl_efficiency_parameter_get_Ap(const hdrl_parameter * pars){ + + if(hdrl_efficiency_parameter_check(pars)) + return (hdrl_value){0.0,0.0}; + + const hdrl_efficiency_parameters * p + = (const hdrl_efficiency_parameters*)pars; + + return p->Ap; +} + +static inline hdrl_value +hdrl_efficiency_parameter_get_G(const hdrl_parameter * pars){ + + if(hdrl_efficiency_parameter_check(pars)) + return (hdrl_value){0.0,0.0}; + + const hdrl_efficiency_parameters * p + = (const hdrl_efficiency_parameters*)pars; + + return p->G; +} + +static inline hdrl_value +hdrl_efficiency_parameter_get_Tex(const hdrl_parameter * pars){ + + if(hdrl_efficiency_parameter_check(pars)) + return (hdrl_value){0.0,0.0}; + + const hdrl_efficiency_parameters * p + = (const hdrl_efficiency_parameters*)pars; + + return p->Tex; +} + +static inline hdrl_value +hdrl_efficiency_parameter_get_Atel(const hdrl_parameter * pars){ + + if(hdrl_efficiency_parameter_check(pars)) + return (hdrl_value){0.0,0.0}; + + const hdrl_efficiency_parameters * p + = (const hdrl_efficiency_parameters*)pars; + + return p->Atel; +} +/*get the maximum between the two minimum values of a1 and a2*/ +static inline hdrl_data_t +highest_w_min(const cpl_array * a1, const cpl_array * a2){ + const hdrl_data_t w1 = cpl_array_get_min(a1); + const hdrl_data_t w2 = cpl_array_get_min(a2); + + return CPL_MAX(w2, w1); +} + +/*get the minimum between the two maximum values of a1 and a2*/ +static inline hdrl_data_t +lowest_w_max(const cpl_array * a1, const cpl_array * a2){ + const hdrl_data_t w1 = cpl_array_get_max(a1); + const hdrl_data_t w2 = cpl_array_get_max(a2); + + return CPL_MIN(w2, w1); +} + +/*Removes lines inside I_std whose wavelengths are not contained inside I_std_ref + * or E_x*/ +static inline hdrl_spectrum1D * +select_obs_spectrum(const hdrl_spectrum1D * I_std, + const hdrl_spectrum1D * I_std_ref, + const hdrl_spectrum1D * E_x){ + + const cpl_array * w_std_ref = + hdrl_spectrum1D_get_wavelength(I_std_ref).wavelength; + + const cpl_array * E_x_ref = + hdrl_spectrum1D_get_wavelength(E_x).wavelength; + + const hdrl_data_t w_min = highest_w_min(w_std_ref, E_x_ref); + const hdrl_data_t w_max = lowest_w_max(w_std_ref, E_x_ref); + + cpl_ensure(w_min < w_max, CPL_ERROR_ILLEGAL_INPUT, NULL); + + cpl_bivector * wavs = cpl_bivector_new(1); + cpl_vector_set(cpl_bivector_get_x(wavs), 0, w_min); + cpl_vector_set(cpl_bivector_get_y(wavs), 0, w_max); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_select_wavelengths(I_std, + wavs, CPL_TRUE); + + cpl_bivector_delete(wavs); + + return to_ret; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_efficiency.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_efficiency.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_efficiency.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_efficiency.h 2017-08-28 09:37:00.000000000 +0000 @@ -0,0 +1,77 @@ +/* $Id: hdrl_efficiency.h,v 0.1 2017-03-15 11:55:00 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-03-15 11:55:00 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_EFFICIENCY_H +#define HDRL_EFFICIENCY_H + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum.h" + +#include + +CPL_BEGIN_DECLS + + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +hdrl_parameter* hdrl_efficiency_parameter_create( + const hdrl_value Ap, const hdrl_value Am, const hdrl_value G, + const hdrl_value Tex, const hdrl_value Atel); + +hdrl_spectrum1D * hdrl_efficiency_compute( + const hdrl_spectrum1D * I_std_arg, const hdrl_spectrum1D * I_std_ref, + const hdrl_spectrum1D * E_x, const hdrl_parameter * pars); + + +hdrl_parameter* hdrl_response_parameter_create( + const hdrl_value Ap, const hdrl_value Am, const hdrl_value G, + const hdrl_value Tex); + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE + + hdrl_value E_ph(hdrl_data_t lambda); + + hdrl_spectrum1D * + hdrl_response_core_compute( + const hdrl_spectrum1D * I_std_arg, const hdrl_spectrum1D * I_std_ref, + const hdrl_spectrum1D * E_x, const hdrl_parameter * pars); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_elemop.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_elemop.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_elemop.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_elemop.c 2017-08-25 10:54:40.000000000 +0000 @@ -0,0 +1,883 @@ +/* $Id: hdrl_elemop.c,v 1.4 2013-10-04 08:03:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-04 08:03:14 $ + * $Revision: 1.4 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_utils.h" +#include "hdrl_types.h" +#include "hdrl_elemop.h" + +#include +#include + +#ifndef SQR +#define SQR(a) ((a) * (a)) +#endif + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief add two arrays of with error propagation in place + * + * @param a array of values of size na + * @param ea array of errors of a + * @param na size of a arrays + * @param b array of values of size nb + * @param eb array of errors of b + * @param nb size of b array, must be equal to na or 1 + * @param mask bad pixel mask, positions where it is true are not modified + * + * a = a + b + * e = hypot(ea, eb) + * error propagation of first order, correlations not considered + * except for the a === b case (correlation = 1) + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_elemop_add(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask) +{ + if (a == b && ea == eb) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + a[i] += a[i]; + ea[i] *= 2; + } + } + } + else { + cpl_ensure_code(na == nb || nb == 1, CPL_ERROR_ILLEGAL_INPUT); + + if (nb == 1) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + a[i] += b[0]; + ea[i] = hypot(ea[i], eb[0]); + } + } + } + else { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + a[i] += b[i]; + ea[i] = hypot(ea[i], eb[i]); + } + } + } + } + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief subtract two arrays of with error propagation in place + * + * @param a array of values of size na + * @param ea array of errors of a + * @param na size of a arrays + * @param b array of values of size nb + * @param eb array of errors of b + * @param nb size of b array, must be equal to na or 1 + * @param mask bad pixel mask, positions where it is true are not modified + * + * a = a - b + * e = hypot(ea, eb) + * error propagation of first order, correlations not considered + * except for the a === b case (correlation = 1) + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_elemop_sub(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask) +{ + if (a == b && ea == eb) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + a[i] = 0.; + ea[i] = 0.; + } + } + } + else { + cpl_ensure_code(na == nb || nb == 1, CPL_ERROR_ILLEGAL_INPUT); + + if (nb == 1) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + a[i] -= b[0]; + ea[i] = hypot(ea[i], eb[0]); + } + } + } + else { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + a[i] -= b[i]; + ea[i] = hypot(ea[i], eb[i]); + } + } + } + } + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief multiply two arrays of with error propagation in place + * + * @param a array of values of size na + * @param ea array of errors of a + * @param na size of a arrays + * @param b array of values of size nb + * @param eb array of errors of b + * @param nb size of b array, must be equal to na or 1 + * @param mask bad pixel mask, positions where it is true are not modified + * + * a = a * b + * e = hypot(a * eb, b * ea) + * error propagation of first order, correlations not considered + * except for the a === b case (correlation = 1) + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_elemop_mul(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask) +{ + if (a == b && ea == eb) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + const hdrl_data_t a_ = a[i] * a[i]; + ea[i] = 2 * fabs(a[i]) * ea[i]; + a[i] = a_; + } + } + } + else { + cpl_ensure_code(na == nb || nb == 1, CPL_ERROR_ILLEGAL_INPUT); + + if (nb == 1) { + const hdrl_data_t b0 = b[0]; + const hdrl_error_t eb0 = eb[0]; + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + const hdrl_data_t a_ = a[i] * b0; + ea[i] = hypot(eb0 * a[i], ea[i] * b0); + a[i] = a_; + } + } + } + else { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + const hdrl_data_t a_ = a[i] * b[i]; + ea[i] = hypot(eb[i] * a[i], ea[i] * b[i]); + a[i] = a_; + } + } + } + } + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief divide two arrays of with error propagation in place + * + * @param a array of values of size na + * @param ea array of errors of a + * @param na size of a arrays + * @param b array of values of size nb + * @param eb array of errors of b + * @param nb size of b array, must be equal to na or 1 + * @param mask bad pixel mask, positions where it is true are not modified + * + * a = a / b + * e = hypot(ea / b, eb * a / (b * b)) + * error propagation of first order, correlations not considered + * except for the a === b case (correlation = 1) + * + * unlike cpl_image_divide pixels which are divided by zero are set to NAN and + * not marked as bad. + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_elemop_div(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask) +{ + if (a == b && ea == eb) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + ea[i] = 0.; + a[i] = 1.; + } + } + } + else { + cpl_ensure_code(na == nb || nb == 1, CPL_ERROR_ILLEGAL_INPUT); + + if (nb == 1) { + const hdrl_data_t rb0 = 1. / b[0]; + const hdrl_error_t eb0 = eb[0]; + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + const hdrl_data_t a_ = a[i] * rb0; + if (b[0] == 0.) { + a[i] = NAN; + ea[i] = NAN; + } + else { + /* sqrt((ea / b)^2 + (eb * a / b^2)^2) */ + ea[i] = sqrt(SQR(ea[i] * rb0) + + SQR(eb0 * a_ * rb0)); + a[i] = a_; + } + } + } + } + else { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + const hdrl_data_t rb = 1. / b[i]; + const hdrl_data_t a_ = a[i] * rb; + if (b[i] == 0.) { + a[i] = NAN; + ea[i] = NAN; + } + else { + /* sqrt((ea / b)^2 + (eb * a / b^2)^2) */ + ea[i] = sqrt(SQR(ea[i] * rb) + + SQR(eb[i] * a_ * rb)); + a[i] = a_; + } + } + } + } + } + + return CPL_ERROR_NONE; +} + +/* Utility function with error propagation logic for pow */ +static inline void pow_scalar(hdrl_data_t base, hdrl_error_t base_e, + hdrl_data_t exp, hdrl_error_t exp_e, + hdrl_data_t* out, hdrl_error_t* out_e){ + + *out_e = 0.0; + + if(base == 0. && exp < 0.){ + *out = NAN; + *out_e = NAN; + return; + } + + if(exp_e == .0 && exp == 2.0){ + *out = base * base; + *out_e = fabs(2.0 * base_e * base); + return; + } + + *out = pow(base, exp); + + /*No exponent error*/ + if(exp_e == 0.){ + *out_e = fabs(*out * (exp / base * base_e)); + return; + } + + const hdrl_data_t log_base = log(fabs(base)); + *out_e = fabs(*out) * sqrt(SQR( exp / base * base_e) + + SQR(log_base * exp_e)); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief power of two arrays of with error propagation in place + * + * @param a array of values of size na + * @param ea array of errors of a + * @param na size of a arrays + * @param b array of values of size nb + * @param eb array of errors of b + * @param nb size of b array, must be equal to na or 1 + * @param mask bad pixel mask, positions where it is true are not modified + * + * a = pow(a, b) + * e = pow(a, b) * sqrt((a / b * ea)^2 + (ln(a) * eb)^2) + * error propagation of first order, correlations not considered + * except for the a === b case (correlation = 1) + * + * if b < 0 and a == 0 the result is NAN + * for a < 0 and eb != 0 the error is not well defined + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_elemop_pow(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask) +{ + if (a == b && ea == eb) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + hdrl_data_t loga = log(fabs(a[i])); + a[i] = pow(a[i], a[i]); + ea[i] = fabs(a[i]) * + sqrt(SQR(ea[i]) * (1. + SQR(loga) + 2 * loga)); + } + } + } + else { + cpl_ensure_code(na == nb || nb == 1, CPL_ERROR_ILLEGAL_INPUT); + + if (nb == 1) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + pow_scalar(a[i], ea[i], b[0], eb[0], &a[i], &ea[i]); + } + } + } + else { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + pow_scalar(a[i], ea[i], b[i], eb[i], &a[i], &ea[i]); + } + } + } + } + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief power of two arrays of with error propagation in place + * + * @param a array of values of size na + * @param ea array of errors of a + * @param na size of a arrays + * @param b array of values of size nb + * @param eb array of errors of b + * @param nb size of b array, must be equal to na or 1 + * @param mask bad pixel mask, positions where it is true are not modified + * + * a = pow(b, a) + * e = pow(b, a) * sqrt((b / a * eb)^2 + (ln(b) * ea)^2) + * error propagation of first order, correlations not considered + * except for the a === b case (correlation = 1) + * + * if a < 0 and b == 0 the result is NAN + * for b < 0 and ea != 0 the error is not well defined + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_elemop_pow_inverted(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask) +{ + if (a == b && ea == eb) { + /* a and b are the same image, order is irrelevant*/ + return hdrl_elemop_pow(a, ea, na, b, eb, nb, mask); + } + else { + cpl_ensure_code(na == nb || nb == 1, CPL_ERROR_ILLEGAL_INPUT); + + if (nb == 1) { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + pow_scalar(b[0], eb[0], a[i], ea[i], &a[i], &ea[i]); + } + } + } + else { + for (size_t i = 0; i < na; i++) { + if (mask == NULL || mask[i] == CPL_BINARY_0) { + pow_scalar(b[i], eb[i], a[i], ea[i], &a[i], &ea[i]); + } + } + } + } + + return CPL_ERROR_NONE; +} + + +typedef cpl_error_code (hdrl_math_op_f)( + hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); + +typedef cpl_error_code (hdrl_math_op_image_f)( + cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be); + +typedef cpl_error_code (hdrl_math_op_image_scalar_f)( + cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); + +static cpl_error_code +check_input(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be) +{ + cpl_ensure_code(a, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(ae, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(b, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(be, CPL_ERROR_NULL_INPUT); + + cpl_ensure_code(cpl_image_get_size_x(a) == cpl_image_get_size_x(ae), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_size_y(a) == cpl_image_get_size_y(ae), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_size_x(b) == cpl_image_get_size_x(be), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_size_y(b) == cpl_image_get_size_y(be), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_size_x(a) == cpl_image_get_size_x(b), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_size_y(a) == cpl_image_get_size_y(b), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_type(a) == HDRL_TYPE_DATA, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_type(ae) == HDRL_TYPE_ERROR, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_type(b) == HDRL_TYPE_DATA, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_type(be) == HDRL_TYPE_ERROR, + CPL_ERROR_INCOMPATIBLE_INPUT); + + return CPL_ERROR_NONE; +} + + +static cpl_error_code +hdrl_elemop_image_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be, + hdrl_math_op_f * f) +{ + const cpl_binary * dmask = NULL; + cpl_ensure_code(a, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(ae, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_image_get_type(a) == HDRL_TYPE_DATA, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_image_get_type(ae) == HDRL_TYPE_ERROR, + CPL_ERROR_INCOMPATIBLE_INPUT); + const cpl_mask * bpm = cpl_image_get_bpm_const(a); + + if (bpm != NULL) { + dmask = cpl_mask_get_data_const(bpm); + } + + if (f == hdrl_elemop_div && b == 0.) { + cpl_msg_warning(cpl_func, "dividing image by scalar zero"); + cpl_image_add_scalar(a, NAN); + cpl_image_add_scalar(ae, NAN); + cpl_image_reject_value(a, CPL_VALUE_NAN); + cpl_image_reject_value(ae, CPL_VALUE_NAN); + return cpl_error_get_code(); + } + else { + cpl_error_code err = f(hdrl_get_image_data(a), + hdrl_get_image_error(ae), + hdrl_get_image_npix(a), + &b, &be, 1, + dmask); + if (f == hdrl_elemop_pow || f == hdrl_elemop_pow_inverted) { + cpl_image_reject_value(a, CPL_VALUE_NAN); + cpl_image_reject_from_mask(ae, cpl_image_get_bpm(a)); + } + return err; + } +} + +/* doxygen in header */ +cpl_error_code +hdrl_elemop_image_add_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be) +{ + return hdrl_elemop_image_scalar(a, ae, b, be, hdrl_elemop_add); +} + +cpl_error_code +hdrl_elemop_image_sub_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be) +{ + return hdrl_elemop_image_scalar(a, ae, b, be, hdrl_elemop_sub); +} + +cpl_error_code +hdrl_elemop_image_mul_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be) +{ + return hdrl_elemop_image_scalar(a, ae, b, be, hdrl_elemop_mul); +} + +cpl_error_code +hdrl_elemop_image_div_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be) +{ + return hdrl_elemop_image_scalar(a, ae, b, be, hdrl_elemop_div); +} + +cpl_error_code +hdrl_elemop_image_pow_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be) +{ + return hdrl_elemop_image_scalar(a, ae, b, be, hdrl_elemop_pow); +} + +cpl_error_code +hdrl_elemop_image_exp_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be) +{ + return hdrl_elemop_image_scalar(a, ae, b, be, hdrl_elemop_pow_inverted); +} + +static cpl_error_code +hdrl_elemop_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be, + hdrl_math_op_f * f) +{ + cpl_error_code r = check_input(a, ae, b, be); + const cpl_binary * dmask = NULL; + cpl_ensure_code(r == CPL_ERROR_NONE, r); + const cpl_mask * bbpm = cpl_image_get_bpm_const(b); + + if (bbpm != NULL) { + if (cpl_image_get_bpm_const(a)) { + /* a and b have bpm, merge them */ + cpl_mask * abpm = cpl_image_get_bpm(a); + cpl_mask_or(abpm, bbpm); + dmask = cpl_mask_get_data_const(abpm); + } + else { + /* a has no bpm, copy from b */ + cpl_image_reject_from_mask(a, bbpm); + dmask = cpl_mask_get_data_const(bbpm); + } + } + else { + const cpl_mask * abpm = cpl_image_get_bpm_const(a); + if (abpm) { + dmask = cpl_mask_get_data_const(abpm); + } + } + + r = f(hdrl_get_image_data(a), + hdrl_get_image_error(ae), + hdrl_get_image_npix(a), + hdrl_get_image_data_const(b), + hdrl_get_image_error_const(be), + hdrl_get_image_npix(a), + dmask); + + if (f == hdrl_elemop_div || f == hdrl_elemop_pow) { + cpl_image_reject_value(a, CPL_VALUE_NAN); + cpl_image_reject_from_mask(ae, cpl_image_get_bpm(a)); + } + + return r; +} + +cpl_error_code +hdrl_elemop_image_add_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be) +{ + return hdrl_elemop_image(a, ae, b, be, hdrl_elemop_add); +} + +cpl_error_code +hdrl_elemop_image_sub_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be) +{ + return hdrl_elemop_image(a, ae, b, be, hdrl_elemop_sub); +} + +cpl_error_code +hdrl_elemop_image_mul_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be) +{ + return hdrl_elemop_image(a, ae, b, be, hdrl_elemop_mul); +} + +cpl_error_code +hdrl_elemop_image_div_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be) +{ + return hdrl_elemop_image(a, ae, b, be, hdrl_elemop_div); +} + +cpl_error_code +hdrl_elemop_image_pow_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be) +{ + return hdrl_elemop_image(a, ae, b, be, hdrl_elemop_pow); +} + +static cpl_error_code +hdrl_elemop_imagelist_vector(cpl_imagelist * self_d, + cpl_imagelist * self_e, + const cpl_vector * other_d, + const cpl_vector * other_e, + hdrl_math_op_image_scalar_f * f) +{ + cpl_ensure_code(self_d, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self_e, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other_d, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other_e, CPL_ERROR_NULL_INPUT); + const size_t nz = cpl_imagelist_get_size(self_d); + cpl_ensure_code(nz == (size_t)cpl_imagelist_get_size(self_e), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(nz == (size_t)cpl_vector_get_size(other_d), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(nz == (size_t)cpl_vector_get_size(other_e), + CPL_ERROR_INCOMPATIBLE_INPUT); + + for (size_t i = 0; i < nz; i++) { + cpl_image * ad = cpl_imagelist_get(self_d, i); + cpl_image * ae = cpl_imagelist_get(self_e, i); + const double bd = cpl_vector_get(other_d, i); + const double be = cpl_vector_get(other_e, i); + f(ad, ae, bd, be); + } + + return cpl_error_get_code(); +} + +cpl_error_code +hdrl_elemop_imagelist_add_vector(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_vector * b, + const cpl_vector * be) +{ + return hdrl_elemop_imagelist_vector(a, ae, b, be, + hdrl_elemop_image_add_scalar); +} + +cpl_error_code +hdrl_elemop_imagelist_sub_vector(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_vector * b, + const cpl_vector * be) +{ + return hdrl_elemop_imagelist_vector(a, ae, b, be, + hdrl_elemop_image_sub_scalar); +} + +cpl_error_code +hdrl_elemop_imagelist_mul_vector(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_vector * b, + const cpl_vector * be) +{ + return hdrl_elemop_imagelist_vector(a, ae, b, be, + hdrl_elemop_image_mul_scalar); +} + +cpl_error_code +hdrl_elemop_imagelist_div_vector(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_vector * b, + const cpl_vector * be) +{ + return hdrl_elemop_imagelist_vector(a, ae, b, be, + hdrl_elemop_image_div_scalar); +} + +cpl_error_code +hdrl_elemop_imagelist_pow_vector(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_vector * b, + const cpl_vector * be) +{ + return hdrl_elemop_imagelist_vector(a, ae, b, be, + hdrl_elemop_image_pow_scalar); +} + +static cpl_error_code +hdrl_elemop_imagelist_image(cpl_imagelist * self_d, + cpl_imagelist * self_e, + const cpl_image * other_d, + const cpl_image * other_e, + hdrl_math_op_image_f * f) +{ + cpl_ensure_code(self_d, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self_e, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other_d, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other_e, CPL_ERROR_NULL_INPUT); + const size_t nz = cpl_imagelist_get_size(self_d); + cpl_ensure_code(nz == (size_t)cpl_imagelist_get_size(self_e), + CPL_ERROR_INCOMPATIBLE_INPUT); + + for (size_t i = 0; i < nz; i++) { + cpl_image * ad = cpl_imagelist_get(self_d, i); + cpl_image * ae = cpl_imagelist_get(self_e, i); + f(ad, ae, other_d, other_e); + } + + return cpl_error_get_code(); +} + +cpl_error_code +hdrl_elemop_imagelist_add_image(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_image * b, + const cpl_image * be) +{ + return hdrl_elemop_imagelist_image(a, ae, b, be, + hdrl_elemop_image_add_image); +} + +cpl_error_code +hdrl_elemop_imagelist_sub_image(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_image * b, + const cpl_image * be) +{ + return hdrl_elemop_imagelist_image(a, ae, b, be, + hdrl_elemop_image_sub_image); +} + +cpl_error_code +hdrl_elemop_imagelist_mul_image(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_image * b, + const cpl_image * be) +{ + return hdrl_elemop_imagelist_image(a, ae, b, be, + hdrl_elemop_image_mul_image); +} + +cpl_error_code +hdrl_elemop_imagelist_div_image(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_image * b, + const cpl_image * be) +{ + return hdrl_elemop_imagelist_image(a, ae, b, be, + hdrl_elemop_image_div_image); +} + +cpl_error_code +hdrl_elemop_imagelist_pow_image(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_image * b, + const cpl_image * be) +{ + return hdrl_elemop_imagelist_image(a, ae, b, be, + hdrl_elemop_image_pow_image); +} + +static cpl_error_code +hdrl_elemop_imagelist(cpl_imagelist * self_d, + cpl_imagelist * self_e, + const cpl_imagelist * other_d, + const cpl_imagelist * other_e, + hdrl_math_op_image_f * f) +{ + cpl_ensure_code(self_d, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other_d, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self_e, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other_e, CPL_ERROR_NULL_INPUT); + const size_t nz = cpl_imagelist_get_size(self_d); + cpl_ensure_code(nz == (size_t)cpl_imagelist_get_size(self_e), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(nz == (size_t)cpl_imagelist_get_size(other_d), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(nz == (size_t)cpl_imagelist_get_size(other_e), + CPL_ERROR_INCOMPATIBLE_INPUT); + + for (size_t i = 0; i < nz; i++) { + cpl_image * ad = cpl_imagelist_get(self_d, i); + cpl_image * ae = cpl_imagelist_get(self_e, i); + const cpl_image * bd = cpl_imagelist_get_const(other_d, i); + const cpl_image * be = cpl_imagelist_get_const(other_e, i); + f(ad, ae, bd, be); + } + + return cpl_error_get_code(); +} + +cpl_error_code +hdrl_elemop_imagelist_add_imagelist(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_imagelist * b, + const cpl_imagelist * be) +{ + return hdrl_elemop_imagelist(a, ae, b, be, + hdrl_elemop_image_add_image); +} + +cpl_error_code +hdrl_elemop_imagelist_sub_imagelist(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_imagelist * b, + const cpl_imagelist * be) +{ + return hdrl_elemop_imagelist(a, ae, b, be, + hdrl_elemop_image_sub_image); +} + +cpl_error_code +hdrl_elemop_imagelist_mul_imagelist(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_imagelist * b, + const cpl_imagelist * be) +{ + return hdrl_elemop_imagelist(a, ae, b, be, + hdrl_elemop_image_mul_image); +} + +cpl_error_code +hdrl_elemop_imagelist_div_imagelist(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_imagelist * b, + const cpl_imagelist * be) +{ + return hdrl_elemop_imagelist(a, ae, b, be, + hdrl_elemop_image_div_image); +} + +cpl_error_code +hdrl_elemop_imagelist_pow_imagelist(cpl_imagelist * a, + cpl_imagelist * ae, + const cpl_imagelist * b, + const cpl_imagelist * be) +{ + return hdrl_elemop_imagelist(a, ae, b, be, + hdrl_elemop_image_pow_image); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_elemop.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_elemop.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_elemop.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_elemop.h 2017-04-07 13:23:18.000000000 +0000 @@ -0,0 +1,238 @@ +/* $Id: hdrl_elemop.h,v 1.4 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.4 $ + */ + +#ifndef HDRL_ELEMOP_H +#define HDRL_ELEMOP_H + +#ifndef HDRL_USE_PRIVATE +#error This file is not allowed to be included outside of hdrl +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief add/subtract/multiply/divide two images with error propagation + * + * @param a image, modified in place + * @param ae errors of image a, modified in place + * @param b image + * @param be errors of image b + * + * Gaussian error propagation of first order, no accounting correlation + * besides a == b. + * Divisions by zero will be marked as bad pixels and set to NAN + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_elemop_image_add_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_image_sub_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_image_mul_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_image_div_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_image_pow_image(cpl_image * a, cpl_image * ae, + const cpl_image * b, const cpl_image * be); + +/* ---------------------------------------------------------------------------*/ +/** + * @brief add/subtract/multiply/divide image and scalar with error propagation + * + * @param a image, modified in place + * @param ae errors of image a, modified in place + * @param b scalar + * @param be error of scalar b + * + * Gaussian error propagation of first order, no accounting correlation + * besides a == b. + * Divisions by zero will be marked as bad pixels and set to NAN + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_elemop_image_add_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); +cpl_error_code +hdrl_elemop_image_sub_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); +cpl_error_code +hdrl_elemop_image_mul_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); +cpl_error_code +hdrl_elemop_image_div_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); +cpl_error_code +hdrl_elemop_image_pow_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); +cpl_error_code +hdrl_elemop_image_exp_scalar(cpl_image * a, cpl_image * ae, + const hdrl_data_t b, const hdrl_error_t be); +/* ---------------------------------------------------------------------------*/ +/** + * @brief add/subtract/multiply/divide two imagelists and scalar with error + * propagation + * + * @param a imagelist, modified in place + * @param ae errors of imagelist a, modified in place + * @param b imagelist + * @param be error of imagelist b + * + * Gaussian error propagation of first order, no accounting correlation + * besides a == b. + * Divisions by zero will be marked as bad pixels and set to NAN + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_elemop_imagelist_add_imagelist(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_imagelist * b, const cpl_imagelist * be); +cpl_error_code +hdrl_elemop_imagelist_sub_imagelist(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_imagelist * b, const cpl_imagelist * be); +cpl_error_code +hdrl_elemop_imagelist_mul_imagelist(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_imagelist * b, const cpl_imagelist * be); +cpl_error_code +hdrl_elemop_imagelist_div_imagelist(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_imagelist * b, const cpl_imagelist * be); +cpl_error_code +hdrl_elemop_imagelist_pow_imagelist(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_imagelist * b, const cpl_imagelist * be); + +/* ---------------------------------------------------------------------------*/ +/** + * @brief add/subtract/multiply/divide each image of an imagelist and a + * scalar from a vector with error propagation + * + * @param a imagelist, modified in place + * @param ae errors of imagelist a, modified in place + * @param b vector + * @param be error of vector b + * + * Gaussian error propagation of first order, no accounting correlation + * besides a == b. + * Divisions by zero will be marked as bad pixels and set to NAN + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_elemop_imagelist_add_vector(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_vector * b, const cpl_vector * be); +cpl_error_code +hdrl_elemop_imagelist_sub_vector(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_vector * b, const cpl_vector * be); +cpl_error_code +hdrl_elemop_imagelist_mul_vector(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_vector * b, const cpl_vector * be); +cpl_error_code +hdrl_elemop_imagelist_div_vector(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_vector * b, const cpl_vector * be); +cpl_error_code +hdrl_elemop_imagelist_pow_vector(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_vector * b, const cpl_vector * be); + +/* ---------------------------------------------------------------------------*/ +/** + * @brief add/subtract/multiply/divide each image of an imagelist and an image + * with error propagation + * + * @param a imagelist, modified in place + * @param ae errors of imagelist a, modified in place + * @param b image + * @param be error of image b + * + * Gaussian error propagation of first order, no accounting correlation + * besides a == b. + * Divisions by zero will be marked as bad pixels and set to NAN + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_elemop_imagelist_add_image(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_imagelist_sub_image(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_imagelist_mul_image(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_imagelist_div_image(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_image * b, const cpl_image * be); +cpl_error_code +hdrl_elemop_imagelist_pow_image(cpl_imagelist * a, cpl_imagelist * ae, + const cpl_image * b, const cpl_image * be); + +/* see hdrl_elemop.c for doc strings */ +cpl_error_code hdrl_elemop_add(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); +cpl_error_code hdrl_elemop_sub(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); +cpl_error_code hdrl_elemop_mul(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); +cpl_error_code hdrl_elemop_div(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); +cpl_error_code hdrl_elemop_pow(hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); +cpl_error_code hdrl_elemop_pow_inverted( + hdrl_data_t * a, hdrl_error_t * ea, size_t na, + const hdrl_data_t * b, const hdrl_error_t * eb, size_t nb, + const cpl_binary * mask); + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fit.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fit.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fit.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fit.c 2017-09-04 08:42:44.000000000 +0000 @@ -0,0 +1,698 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_utils.h" +#include "hdrl_fit.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_fit Fitting + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/** @cond PRIVATE */ + +#if CPL_VERSION_CODE > CPL_VERSION(6, 6, 255) +static cpl_matrix * matrix_product_normal_create(const cpl_matrix * self) +{ + const size_t m = cpl_matrix_get_nrow(self); + cpl_matrix * product = cpl_matrix_wrap((cpl_size)m, (cpl_size)m, + cpl_malloc(m * m * sizeof(double))); + + if (cpl_matrix_product_normal(product, self)) { + cpl_matrix_delete(product); + product = NULL; + } + + return product; +} +#else +cpl_matrix * cpl_matrix_product_normal_create(const cpl_matrix * self); +cpl_error_code cpl_matrix_product_transpose(cpl_matrix * self, + const cpl_matrix * ma, + const cpl_matrix * mb); +static cpl_matrix * matrix_product_normal_create(const cpl_matrix * self) +{ + + return cpl_matrix_product_normal_create(self); +} +#endif + + +typedef struct { + /* input design matrix of fit */ + cpl_matrix * design; + /* coefficient row matrix */ + cpl_matrix * coef; + /* covariance matrix of coefficients */ + cpl_matrix * cov; +} hdrl_ls_fit_result; + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create least squares fit result structure + * @return fit result structure + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_ls_fit_result * hdrl_ls_fit_result_create(void) +{ + return cpl_calloc(1, sizeof(hdrl_ls_fit_result)); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete least squares fit result structure + * @param fit result structure, may be NULL + */ +/* ---------------------------------------------------------------------------*/ +static void hdrl_ls_fit_result_delete(hdrl_ls_fit_result * r) +{ + if (r == NULL) + return; + cpl_matrix_delete(r->design); + cpl_matrix_delete(r->coef); + cpl_matrix_delete(r->cov); + cpl_free(r); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get fitted values from a least squares fit result + * @param r fit result structure + * @return vector containing the fitted values + */ +/* ---------------------------------------------------------------------------*/ +static cpl_vector * hdrl_ls_fit_result_get_fitted_values( + const hdrl_ls_fit_result * r) +{ + cpl_matrix * fvalues = cpl_matrix_product_create(r->design, r->coef); + cpl_vector * res = cpl_vector_wrap(cpl_matrix_get_nrow(fvalues), + cpl_matrix_get_data(fvalues)); + cpl_matrix_unwrap(fvalues); + return res; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get fit residuals from a least squares fit result + * @param r fit result structure + * @param data data which from which the fitted values are subtracted + * @return vector of residuals + */ +/* ---------------------------------------------------------------------------*/ +static cpl_vector * hdrl_ls_fit_result_get_residuals( + const hdrl_ls_fit_result * r, + const cpl_vector * data) +{ + cpl_vector * fval = hdrl_ls_fit_result_get_fitted_values(r); + cpl_vector * res = cpl_vector_duplicate(data); + cpl_vector_subtract(res, fval); + cpl_vector_delete(fval); + return res; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get squared chi of a least squares fit result + * @param r fit result structure + * @param data data of the fit + * @param errors errors of the fit + * @return squared chi statistic of the fit + * + * the chi square is computed as: + * sum_i(1/sigma_i^2 * residual_i ^ 2) + */ +/* ---------------------------------------------------------------------------*/ +static double hdrl_ls_fit_result_get_chi2( + const hdrl_ls_fit_result * r, + const cpl_vector * data, + cpl_vector * errors) +{ + cpl_vector * fval = hdrl_ls_fit_result_get_residuals(r, data); + /* mse = sum(sqrt(weights) * residuals ** 2) / df */ + cpl_vector_divide(fval, errors); + cpl_vector_multiply(fval, fval); + double mswd = cpl_vector_get_sum(fval); + + cpl_vector_delete(fval); + return mswd; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get degrees of freedom of a least squares fit + * @param r fit result structure + * @return degrees of freedom + */ +/* ---------------------------------------------------------------------------*/ +static cpl_size hdrl_ls_fit_result_get_residual_dof(const hdrl_ls_fit_result * r) +{ + return cpl_matrix_get_nrow(r->design) - cpl_matrix_get_ncol(r->design); +} + +/* ---------------------------------------------------------------------------*/ +/** +* @brief generic 1d vandermonde matrix +* +* @param sample sampling positions +* @param degree degree of polynomial +* @param func function evaluating polynomials from [0, degree] at +* sampling point +* @return matrix containing the vandermonde matrix +*/ +/* ---------------------------------------------------------------------------*/ +static cpl_matrix * vander1d( + const cpl_vector * sample, + cpl_size degree, + void (*func)(double, double *, size_t)) +{ + const size_t nr = cpl_vector_get_size(sample); + const size_t nc = degree + 1; + cpl_matrix * V = cpl_matrix_new(nr, nc); + double * v = cpl_matrix_get_data(V); + const double * d = cpl_vector_get_data_const(sample); + for (size_t i = 0; i < nr; i++) { + func(d[i], &v[i*nc], nc); + } + + return V; +} + +static void polynomial(double x, double * p, size_t ncoefs) +{ + p[0] = 1.; + for (size_t i = 1; i < ncoefs; i++) { + p[i] = pow(x, i); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get vandermonde matrix for a 1d polynomial + * @param sample sampling positions + * @param degree degree of polynomial + * @return matrix containing the vandermonde matrix + */ +/* ---------------------------------------------------------------------------*/ +static cpl_matrix * polyvander1d( + const cpl_vector * sample, + cpl_size degree) +{ + return vander1d(sample, degree, &polynomial); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief perform a least squares fit + * @param design design matrix + * @param values data to fit + * @param errors errors of data + * @return fit result structure + * must be deleted with hdrl_ls_fit_result_delete() + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_ls_fit_result * fit( + const cpl_matrix * design, + const cpl_vector * values, + const cpl_vector * errors) +{ + hdrl_ls_fit_result * r = hdrl_ls_fit_result_create(); + r->design = cpl_matrix_duplicate(design); + if (errors) { + assert(cpl_matrix_get_nrow(design) == cpl_vector_get_size(errors)); + /* weight response and design */ + cpl_vector * vrhs = cpl_vector_duplicate(errors); + cpl_vector_power(vrhs, -1); + cpl_matrix * wdesign = cpl_matrix_duplicate(design); + for (size_t i = 0; i < (size_t)cpl_vector_get_size(errors); i++) { + double w = cpl_vector_get(vrhs, i); + for (size_t j = 0; j < (size_t)cpl_matrix_get_ncol(wdesign); j++) { + cpl_matrix_set(wdesign, i, j, + cpl_matrix_get(wdesign, i, j) * w); + } + } + + cpl_vector_multiply(vrhs, values); + cpl_matrix * rhs = cpl_matrix_wrap(cpl_vector_get_size(vrhs), 1, + cpl_vector_get_data(vrhs)); + + /* solve Ax = b */ + /* cpl_matrix_solve_normal(design, rhs) + covariance */ + { + cpl_matrix * At = cpl_matrix_transpose_create(wdesign); + cpl_matrix * AtA = matrix_product_normal_create(At); + + /* RRt = AtA */ + cpl_matrix_decomp_chol(AtA); + /* solve for pseudo inverse: (RRt)P=At*/ + cpl_matrix_solve_chol(AtA, At); + /* compute solution to system Ax=b -> x=Pb */ + r->coef = cpl_matrix_product_create(At, rhs); + /* compute covariance matrix cov(b) = PPt */ + r->cov = cpl_matrix_new(cpl_matrix_get_ncol(At), + cpl_matrix_get_ncol(At)); + cpl_matrix_product_transpose(r->cov, At, At); + + cpl_matrix_delete(At); + cpl_matrix_delete(AtA); + } + + cpl_matrix_unwrap(rhs); + cpl_vector_delete(vrhs); + cpl_matrix_delete(wdesign); + } + else { + cpl_vector * vrhs = cpl_vector_duplicate(values); + cpl_matrix * rhs = cpl_matrix_wrap(cpl_vector_get_size(vrhs), 1, + cpl_vector_get_data(vrhs)); + r->coef = cpl_matrix_solve_normal(design, rhs); + cpl_matrix_unwrap(rhs); + cpl_vector_delete(vrhs); + } + return r; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief perform 1d polynomial least squares fit + * + * @param sample sampling points + * @param values values to fit + * @param errors errors to fit + * @param degree degree of polynomial to fit + * @return fit result structure + * must be deleted with hdrl_ls_fit_result_delete() + * @see fit, polyvander1d + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_ls_fit_result * polyfit1d( + const cpl_vector * sample, + const cpl_vector * values, + const cpl_vector * errors, + int degree) +{ + cpl_matrix * design = polyvander1d(sample, degree); + hdrl_ls_fit_result * r = fit(design, values, errors); + cpl_matrix_delete(design); + return r; +} +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief weighted least squares polynomial fit of each pixel of a imagelist + * + * @param list imagelist to fit, the 1/errors^2 are used as the weights of + * the fit + * @param samplepos vector of sample position of each image in the list + * @param degree degree of the fit starting from 0 + * @param coef output coefficient hdrl_imagelist, the data contains the + * coefficient the error contains the diagonal element of the + * covariance matrix + * @param chi2 output double cpl_image, contains the chi2 of the fit + * @param dof output double cpl_image, contains the degrees of freedom of + * the residuals + * + * @note the errors only need to be relative correct, if the are wrong by a + * constant the real errors of the data points can be estimated by + * multiplying the squared errors with chi2/dof + * The fitting method uses normal equation so the function should not be + * used for badly conditioned data. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_fit_polynomial_imagelist(const hdrl_imagelist * list, + const cpl_vector * samplepos, + const int degree, + hdrl_imagelist ** coef, + cpl_image ** chi2, + cpl_image ** dof) +{ + cpl_ensure_code(degree >= 0, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(list && samplepos && coef, CPL_ERROR_NULL_INPUT); + // TODO test + cpl_ensure_code(cpl_vector_get_size(samplepos) == + hdrl_imagelist_get_size(list), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_vector_get_size(samplepos) == + hdrl_imagelist_get_size(list), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_imagelist_get_size(list) > 0, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_imagelist_get_size(list) >= degree + 1, + CPL_ERROR_INCOMPATIBLE_INPUT); + intptr_t nx = hdrl_imagelist_get_size_x(list); + intptr_t ny = hdrl_imagelist_get_size_y(list); + size_t noz = degree + 1; + + /* make sure image has a mask to avoid creation race later */ + if (coef) { + *coef = hdrl_imagelist_new(); + } + if (chi2) { + *chi2 = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_get_bpm(*chi2); + } + if (dof) { + *dof = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_get_bpm(*dof); + } + for (size_t z = 0; z < noz; z++) { + hdrl_image * img = hdrl_image_new(nx, ny); + hdrl_image_get_mask(img); + hdrl_imagelist_set(*coef, img, z); + } + cpl_imagelist * datal, *errorl; + if (hdrl_imagelist_to_cplwrap(list, &datal, &errorl)) { + goto fail; + } + HDRL_OMP(omp parallel shared(coef, chi2, dof)) + { + hdrl_vector_cache * cache = + hdrl_vector_cache_new(cpl_imagelist_get_size(datal), nx * 2); + /* copy to store bad pixel cleaned positions in */ + cpl_vector * nsamppos = cpl_vector_duplicate(samplepos); + HDRL_OMP(omp for) + for (intptr_t y = 0; y < ny; y++) { + cpl_vector * datav[nx]; + cpl_vector * errsv[nx]; + hdrl_imagelist_to_vector_row(datal, y + 1, datav, cache); + hdrl_imagelist_to_vector_row(errorl, y + 1, errsv, cache); + for (intptr_t x = 0; x < nx; x++) { + /* all bad or less good than fit degrees */ + cpl_vector * data = datav[x]; + cpl_vector * errs = errsv[x]; + if (data == NULL || (size_t)cpl_vector_get_size(data) < noz) { + for (size_t z = 0; z < noz; z++) { + hdrl_image * oimg = hdrl_imagelist_get(*coef, z); + hdrl_image_set_pixel(oimg, x + 1, y + 1, + (hdrl_value){NAN, NAN}); + hdrl_image_reject(oimg, x + 1, y + 1); + } + if (chi2) { + cpl_image_set(*chi2, x + 1, y + 1, NAN); + cpl_image_reject(*chi2, x + 1, y + 1); + } + if (dof) { + int n = data ? cpl_vector_get_size(data) - noz : -noz; + cpl_image_set(*dof, x + 1, y + 1, n); + cpl_image_reject(*dof, x + 1, y + 1); + } + hdrl_cplvector_delete_to_cache(cache, data); + hdrl_cplvector_delete_to_cache(cache, errs); + continue; + } + + hdrl_ls_fit_result * r; + + /* remove bad pixels from sample positions and fit */ + if (cpl_vector_get_size(data) != cpl_vector_get_size(samplepos)) { + size_t j = 0; + cpl_vector_set_size(nsamppos, cpl_vector_get_size(data)); + for (size_t i = 0; i < (size_t)hdrl_imagelist_get_size(list); i++) { + hdrl_image * img = hdrl_imagelist_get(list, i); + if (hdrl_image_is_rejected(img, x + 1, y + 1)) + continue; + cpl_vector_set(nsamppos, j++, cpl_vector_get(samplepos, i)); + } + + r = polyfit1d(nsamppos, data, errs, degree); + } + else { + r = polyfit1d(samplepos, data, errs, degree); + } + + // TODO handle failure + for (size_t z = 0; z < noz; z++) { + hdrl_image * oimg = hdrl_imagelist_get(*coef, z); + hdrl_image_set_pixel(oimg, x + 1, y + 1, + (hdrl_value){cpl_matrix_get(r->coef, z, 0), + sqrt(cpl_matrix_get(r->cov, z, z))}); + } + if (chi2) { + cpl_image_set(*chi2, x + 1, y + 1, + hdrl_ls_fit_result_get_chi2(r, data, errs)); + } + if (dof) { + cpl_image_set(*dof, x + 1, y + 1, + hdrl_ls_fit_result_get_residual_dof(r)); + } + hdrl_ls_fit_result_delete(r); + hdrl_cplvector_delete_to_cache(cache, data); + hdrl_cplvector_delete_to_cache(cache, errs); + } + } + hdrl_vector_cache_delete(cache); + cpl_vector_delete(nsamppos); + } + + cpl_imagelist_unwrap(datal); + cpl_imagelist_unwrap(errorl); + + return cpl_error_get_code(); +fail: + hdrl_imagelist_delete(*coef); + *coef = NULL; + if (chi2) { + cpl_image_delete(*chi2); + *chi2 = NULL; + } + if (dof) { + cpl_image_delete(*dof); + *dof = NULL; + } + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief weighted least squares polynomial fit of each pixel of a imagelist + * + * @param list imagelist to fit, the 1/errors^2 are used as the weights of + * the fit + * @param samplepos each slice of pixels of this imagelist form the sample + * position vector + * @param degree degree of the fit starting from 0 + * @param coef output coefficient hdrl_imagelist, the data contains the + * coefficient the error contains the diagonal element of the + * covariance matrix + * @param chi2 output double cpl_image, contains the chi2 of the fit + * @param dof output double cpl_image, contains the degrees of freedom of + * the residuals + * @see hdrl_fit_polynomial_imagelist + * + * Similar to hdrl_fit_polynomial_imagelist except the sample positions for + * each line of pixels per image is taken from the slice of pixels of the + * samplepos imagelist + * + * @note the errors only need to be relative correct, if the are wrong by a + * constant the real errors of the data points can be estimated by + * multiplying the squared errors with chi2/dof + * The fitting method uses normal equation so the function should not be + * used for badly conditioned data. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_fit_polynomial_imagelist2(const hdrl_imagelist * list, + const cpl_imagelist * samplepos, + const int degree, + hdrl_imagelist ** coef, + cpl_image ** chi2, + cpl_image ** dof) +{ + cpl_ensure_code(degree >= 0, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(list && samplepos && coef, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(samplepos) == + hdrl_imagelist_get_size(list), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(samplepos) == + hdrl_imagelist_get_size(list), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_imagelist_get_size(list) > 0, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_imagelist_get_size(list) >= degree + 1, + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_image_get_size_x(hdrl_imagelist_get_const(list, 0)) == + cpl_image_get_size_x(cpl_imagelist_get_const(samplepos, 0)), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_image_get_size_y(hdrl_imagelist_get_const(list, 0)) == + cpl_image_get_size_y(cpl_imagelist_get_const(samplepos, 0)), + CPL_ERROR_INCOMPATIBLE_INPUT); + intptr_t nx = hdrl_imagelist_get_size_x(list); + intptr_t ny = hdrl_imagelist_get_size_y(list); + size_t noz = degree + 1; + + /* make sure image has a mask to avoid creation race later */ + if(coef) { + *coef = hdrl_imagelist_new(); + } + if (chi2) { + *chi2 = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_get_bpm(*chi2); + } + if (dof) { + *dof = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_get_bpm(*dof); + } + for (size_t z = 0; z < noz; z++) { + hdrl_image * img = hdrl_image_new(nx, ny); + hdrl_image_get_mask(img); + hdrl_imagelist_set(*coef, img, z); + } + cpl_imagelist * datal, *errorl; + if (hdrl_imagelist_to_cplwrap(list, &datal, &errorl)) { + goto fail; + } + HDRL_OMP(omp parallel shared(coef, chi2, dof)) + { + hdrl_vector_cache * cache = + hdrl_vector_cache_new(cpl_imagelist_get_size(datal), nx * 3); + HDRL_OMP(omp for) + for (intptr_t y = 0; y < ny; y++) { + cpl_vector * datav[nx]; + cpl_vector * errsv[nx]; + cpl_vector * samplev[nx]; + hdrl_imagelist_to_vector_row(datal, y + 1, datav, cache); + hdrl_imagelist_to_vector_row(errorl, y + 1, errsv, cache); + hdrl_imagelist_to_vector_row(samplepos, y + 1, samplev, cache); + for (intptr_t x = 0; x < nx; x++) { + cpl_vector * data = datav[x]; + cpl_vector * errs = errsv[x]; + cpl_vector * samp = samplev[x]; + /* all bad or less good than fit degrees */ + if (data == NULL || samp == NULL || + (size_t)cpl_vector_get_size(data) < noz || + (size_t)cpl_vector_get_size(samp) < noz) { + for (size_t z = 0; z < noz; z++) { + hdrl_image * oimg = hdrl_imagelist_get(*coef, z); + hdrl_image_set_pixel(oimg, x + 1, y + 1, + (hdrl_value){NAN, NAN}); + hdrl_image_reject(oimg, x + 1, y + 1); + } + if (chi2) { + cpl_image_set(*chi2, x + 1, y + 1, NAN); + cpl_image_reject(*chi2, x + 1, y + 1); + } + if (dof) { + int n = data ? cpl_vector_get_size(data) - noz : -noz; + cpl_image_set(*dof, x + 1, y + 1, n); + cpl_image_reject(*dof, x + 1, y + 1); + } + hdrl_cplvector_delete_to_cache(cache, data); + hdrl_cplvector_delete_to_cache(cache, errs); + hdrl_cplvector_delete_to_cache(cache, samp); + continue; + } + + /* remove bad pixels from vectors */ + if (cpl_vector_get_size(data) != hdrl_imagelist_get_size(list) || + cpl_vector_get_size(samp) != hdrl_imagelist_get_size(list)) { + size_t j = 0; + for (size_t i = 0; i < (size_t)hdrl_imagelist_get_size(list); i++) { + int dump; + hdrl_image * himg = hdrl_imagelist_get(list, i); + const cpl_image * img = cpl_imagelist_get_const(samplepos, i); + /* if any entry is bad skip */ + if (hdrl_image_is_rejected(himg, x + 1, y + 1) || + cpl_image_is_rejected(img, x + 1, y + 1)) + continue; + /* refill vector with non bad pixels in order */ + hdrl_value val = hdrl_image_get_pixel(himg, x + 1, y + 1, NULL); + cpl_vector_set(data, j, val.data); + cpl_vector_set(errs, j, val.error); + cpl_vector_set(samp, j, cpl_image_get(img, x + 1, y + 1, &dump)); + j++; + } + cpl_vector_set_size(data, j); + cpl_vector_set_size(errs, j); + cpl_vector_set_size(samp, j); + } + + hdrl_ls_fit_result * r = polyfit1d(samp, data, errs, degree); + // TODO handle failure + for (size_t z = 0; z < noz; z++) { + hdrl_image * oimg = hdrl_imagelist_get(*coef, z); + hdrl_image_set_pixel(oimg, x + 1, y + 1, + (hdrl_value){cpl_matrix_get(r->coef, z, 0), + sqrt(cpl_matrix_get(r->cov, z, z))}); + } + if (chi2) { + cpl_image_set(*chi2, x + 1, y + 1, + hdrl_ls_fit_result_get_chi2(r, data, errs)); + } + if (dof) { + cpl_image_set(*dof, x + 1, y + 1, + hdrl_ls_fit_result_get_residual_dof(r)); + } + hdrl_ls_fit_result_delete(r); + hdrl_cplvector_delete_to_cache(cache, data); + hdrl_cplvector_delete_to_cache(cache, errs); + hdrl_cplvector_delete_to_cache(cache, samp); + } + } + hdrl_vector_cache_delete(cache); + } + + cpl_imagelist_unwrap(datal); + cpl_imagelist_unwrap(errorl); + + return cpl_error_get_code(); +fail: + hdrl_imagelist_delete(*coef); + *coef = NULL; + if (chi2) { + cpl_image_delete(*chi2); + *chi2 = NULL; + } + if (dof) { + cpl_image_delete(*dof); + *dof = NULL; + } + return cpl_error_get_code(); +} +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fit.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fit.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fit.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fit.h 2015-07-08 10:13:20.000000000 +0000 @@ -0,0 +1,71 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifndef HDRL_FIT_H +#define HDRL_FIT_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_imagelist.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +cpl_error_code +hdrl_fit_polynomial_imagelist(const hdrl_imagelist * list, + const cpl_vector * samplepos, + const int degree, + hdrl_imagelist ** coef, + cpl_image ** chi2, + cpl_image ** dof); + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +/** @cond EXPERIMENTAL */ + +cpl_error_code +hdrl_fit_polynomial_imagelist2(const hdrl_imagelist * list, + const cpl_imagelist * samplepos, + const int degree, + hdrl_imagelist ** coef, + cpl_image ** chi2, + cpl_image ** dof); + +/** @endcond */ +#endif + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_flat.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_flat.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_flat.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_flat.c 2017-09-14 14:52:05.000000000 +0000 @@ -0,0 +1,599 @@ +/* $Id: hdrl_flat.c,v 1.29 2013-09-25 11:04:29 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-09-25 11:04:29 $ + * $Revision: 1.29 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_flat.h" +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + + @defgroup hdrl_flat Master Flatfield + + @brief + This module provides algorithms to compute a master flatfield. + Several methods are available to deal with different flatfield + characteristics. + + The routines in this module can be used to derive a high frequency or a low + frequency master flatfield. + + \par HIGH frequency algorithm: + The algorithm first smoothes the input images by a median filter and divides + each input image through the smoothed image. The smoothed images is considered + to be noiseless i.e. the relative error of the resulting images is the same as + the one of the input image. Then all residual images are collapsed into a + single master flatfield. The collapsing can be done with all methods + currently implemented in hdrl. Moreover, it is also possible to give a static + mask to the algorithm which e.g. allows the user to distinguish illuminated + and not illuminated regions. In this case the smoothing procedure is done + twice, once for the illuminated region and once for the blanked region. This + ensures that the information of one region does not influence the other + regions during the smoothing process. + + \par LOW frequency algorithm: + The algorithm multiplicatively normalizes the input images by the median of + the image to unity. A static mask can be provided to the algorithm in order + to define the pixels that should be taken into account when computing the + normalisation factor. This allows the user to normalize the flatfield e.g. + only by the illuminated section. Then all normalized images are collapsed + into a single master flatfield. The collapsing can be done with all methods + currently implemented in hdrl. Finally, the master flatfield is smoothed by a + median filter. The associated error of the final masterframe is the error + derived via error propagation of the previous steps, i.e. the smoothing itself + is considered noiseless. + + + The calculation is performed by calling the top-level function + hdrl_flat_compute() and the parameters passed to this function + can be created by calling hdrl_flat_parameter_create(). Additional one has + to pass also the collapse parameter created e.g. via + hdrl_collapse_mean_parameter_create(), ... + Note that the function will overwrite the input imagelist in order to + conserve memory. Its contents after the call are undefined and it must be + deleted by the caller. + + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/** @cond PRIVATE */ + + +/*----------------------------------------------------------------------------- + FLAT Parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + cpl_size filter_size_x ; + cpl_size filter_size_y ; + hdrl_flat_method method ; +} hdrl_flat_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_flat_parameter_type = { + HDRL_PARAMETER_FLAT, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_flat_parameter), /* obj_size */ +}; + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Verify basic correctness of the FLAT parameters + @param param FLAT image parameters + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_flat_parameter_verify( + const hdrl_parameter * param) +{ + const hdrl_flat_parameter * param_loc = (const hdrl_flat_parameter *)param ; + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_flat_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected FLAT image parameter") ; + + cpl_error_ensure(param_loc->method == HDRL_FLAT_FREQ_LOW || + param_loc->method == HDRL_FLAT_FREQ_HIGH, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Unsupported method"); + cpl_error_ensure(param_loc->filter_size_x > 0, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "filter_size_x must be > 0"); + cpl_error_ensure(param_loc->filter_size_y > 0, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "filter_size_y must be > 0"); + cpl_error_ensure((param_loc->filter_size_x % 2) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "filter_size_x must an odd number"); + cpl_error_ensure((param_loc->filter_size_y % 2) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "filter_size_y must an odd number"); + return CPL_ERROR_NONE ; +} + +/** @endcond PRIVATE */ + +/* ---------------------------------------------------------------------------*/ +/** + @brief Creates FLAT Parameters object + @param filter_size_x Smoothing filter size in x-direction + @param filter_size_y Smoothing filter size in y-direction + @param method used method + @return The FLAT parameters object. + + It needs to be deallocated with hdrl_parameter_delete() + + @see hdrl_parameter_delete() + @see hdrl_flat_compute() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_flat_parameter_create( + cpl_size filter_size_x, + cpl_size filter_size_y, + hdrl_flat_method method) +{ + hdrl_flat_parameter * p = (hdrl_flat_parameter *) + hdrl_parameter_new(&hdrl_flat_parameter_type); + p->filter_size_x = filter_size_x ; + p->filter_size_y = filter_size_y ; + p->method = method ; + if (hdrl_flat_parameter_verify((hdrl_parameter *)p) != CPL_ERROR_NONE) { + hdrl_parameter_delete((hdrl_parameter *)p); + return NULL; + } + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is a FLAT parameter + @param self The parameter to check + @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_flat_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_flat_parameter_type); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the filter_size_x in the FLAT parameter + @param p The FLAT parameter + @return The filter_size_x + */ +/*----------------------------------------------------------------------------*/ +cpl_size hdrl_flat_parameter_get_filter_size_x( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return ((const hdrl_flat_parameter *)p)->filter_size_x; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the filter_size_y in the FLAT parameter + @param p The FLAT parameter + @return The filter_size_y + */ +/*----------------------------------------------------------------------------*/ +cpl_size hdrl_flat_parameter_get_filter_size_y( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return ((const hdrl_flat_parameter *)p)->filter_size_y; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the method in the FLAT parameter + @param p The FLAT parameter + @return The method + */ +/*----------------------------------------------------------------------------*/ +hdrl_flat_method hdrl_flat_parameter_get_method( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return ((const hdrl_flat_parameter *)p)->method; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create a parameter list for the FLAT computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param defaults default values + + Creates a parameterlist with the FLAT parameters: + - base_context.prefix.filter_size_x + - base_context.prefix.filter_size_y + - base_context.prefix.method + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_flat_parameter_create_parlist( + const char * base_context, + const char * prefix, + const hdrl_parameter * defaults) +{ + cpl_ensure(prefix && base_context && defaults, CPL_ERROR_NULL_INPUT, NULL); + char * name ; + cpl_parameterlist * parlist = cpl_parameterlist_new(); + cpl_parameter * par ; + char * context = + hdrl_join_string(".", 2, base_context, prefix); + + cpl_size filter_size_x_def = hdrl_flat_parameter_get_filter_size_x(defaults) ; + cpl_size filter_size_y_def = hdrl_flat_parameter_get_filter_size_y(defaults) ; + + hdrl_flat_method method_def =hdrl_flat_parameter_get_method(defaults); + cpl_ensure( method_def == HDRL_FLAT_FREQ_LOW || method_def == HDRL_FLAT_FREQ_HIGH, + CPL_ERROR_ILLEGAL_INPUT, NULL) ; + + const char *method_str; + if (method_def == HDRL_FLAT_FREQ_LOW) { + method_str = "low"; + } else if (method_def == HDRL_FLAT_FREQ_HIGH) { + method_str = "high"; + } else { + method_str = ""; + } + + /* --prefix.filter_size_x */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "filter-size-x", base_context, + "Smoothing filter size in x-direction.", CPL_TYPE_INT, + (int)filter_size_x_def) ; + + /* --prefix.filter_size_y */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "filter-size-y", base_context, + "Smoothing filter size in y-direction.", CPL_TYPE_INT, + (int)filter_size_y_def) ; + + /* --prefix.method */ + name = hdrl_join_string(".", 2, context, "method"); + par = cpl_parameter_new_enum(name, CPL_TYPE_STRING, + "Method to use for the master flatfield calculation", context, method_str, + 2, "low", "high"); + cpl_free(name); + name = hdrl_join_string(".", 2, prefix, "method"); + cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV); + cpl_free(name); + cpl_parameterlist_append(parlist, par); + + cpl_free(context); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Parse a parameterlist to create input parameters for the FLAT + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return Input parameters for the FLAT computation + + Reads a parameterlist in order to create FLAT image parameters. + Expects a parameterlist containing: + - prefix.filter_size_x + - prefix.filter_size_y + - prefix.method + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_flat_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name; + const cpl_parameter * par; + const char * tmp_str ; + cpl_size filter_size_x; + cpl_size filter_size_y; + hdrl_flat_method method; + + /* --filter_size_x */ + name = hdrl_join_string(".", 2, prefix, "filter-size-x"); + par=cpl_parameterlist_find_const(parlist, name); + filter_size_x = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --filter_size_y */ + name = hdrl_join_string(".", 2, prefix, "filter-size-y"); + par=cpl_parameterlist_find_const(parlist, name); + filter_size_y = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --method */ + name = hdrl_join_string(".", 2, prefix, "method"); + par = cpl_parameterlist_find_const(parlist, name) ; + tmp_str = cpl_parameter_get_string(par); + if (tmp_str == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + cpl_free(name) ; + if(!strcmp(tmp_str, "low")) { + method = HDRL_FLAT_FREQ_LOW ; + } else if(!strcmp(tmp_str, "high")) { + method = HDRL_FLAT_FREQ_HIGH ; + } else { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Invalid method: %s", tmp_str); + return NULL; + } + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist with prefix %s", prefix); + return NULL; + } else { + return hdrl_flat_parameter_create(filter_size_x, filter_size_y, method) ; + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief compute high or low frequency master flat with median filtering + * + * @param hdrl_data input flats, will be overwritten! + * @param stat_mask input mask to select the regions for + * statistics or smoothing + * @param collapse_params parameter controlling the collapse algorithm + * @param flat_params parameter controlling the flatfield algorithm + * @param master returned masterflat + * @param contrib_map returned contribution map + * + * \par The algorithms are described in the master flatfield module documentation + * + * @note the function will overwrite the input imagelist in order to + * conserve memory. Its contents after the call are undefined and it must be + * deleted by the caller. + */ +/* ---------------------------------------------------------------------------*/ + +cpl_error_code hdrl_flat_compute( + hdrl_imagelist * hdrl_data, + const cpl_mask * stat_mask, + const hdrl_parameter * collapse_params, + hdrl_parameter * flat_params, + hdrl_image ** master, + cpl_image ** contrib_map) +{ + hdrl_image * comb_img = NULL; + cpl_image * comb_ctr = NULL; + int lowf = 0; + + /* Check Entries */ + cpl_error_ensure(hdrl_data != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "No flatfields found"); + cpl_error_ensure(collapse_params != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "No collapsing parameter"); + cpl_error_ensure(flat_params != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "No flatfield parameter"); + + if (hdrl_flat_parameter_verify(flat_params) != CPL_ERROR_NONE) + return cpl_error_get_code(); + + /* Local Usage Parameters */ + const hdrl_flat_parameter * p_loc = (hdrl_flat_parameter *)flat_params ; + cpl_size filter_size_x = p_loc->filter_size_x; + cpl_size filter_size_y = p_loc->filter_size_y; + + if (p_loc->method == HDRL_FLAT_FREQ_LOW) { + lowf = 1; + } else if (p_loc->method == HDRL_FLAT_FREQ_HIGH) { + lowf = 0; + } + + cpl_mask * kernel = cpl_mask_new(filter_size_x, filter_size_y) ; + cpl_mask_not(kernel); + + /* NOTE: The filtered image is supposed to be noiseless */ + + for (cpl_size i = 0; i < hdrl_imagelist_get_size(hdrl_data); i++) { + + /* TODO Only extract the mask if there is a mask and only combine + * the masks if there are both masks */ + + cpl_image *img = hdrl_image_get_image(hdrl_imagelist_get(hdrl_data, i)); + cpl_image *img_err = hdrl_image_get_error(hdrl_imagelist_get(hdrl_data, i)); + + cpl_mask *img_mask = cpl_mask_duplicate(cpl_image_get_bpm(img)); + cpl_mask *img_mask_orig = cpl_mask_duplicate(cpl_image_get_bpm(img)); + + if (lowf == 1) { + double median; + /* no error propagation as the median error is small and also + * consistency with the high freq variant which can't propagate + * error */ + if (stat_mask != NULL) { + cpl_mask_or(img_mask, stat_mask); + /* Apply combined mask */ + cpl_image_reject_from_mask(img, img_mask); + median = cpl_image_get_median(img); + cpl_msg_debug(cpl_func, "Median of the flat: %g", median); + /* restore the original mask */ + cpl_image_reject_from_mask(img, img_mask_orig); + } + else { + median = cpl_image_get_median(img); + cpl_msg_debug(cpl_func, "Median of the flat: %g", median); + } + cpl_image_divide_scalar(img, median); + cpl_image_divide_scalar(img_err, median); + } + else { + cpl_image * img_filtered; + if (stat_mask != NULL) { + cpl_image * img_filtered2; + + /* Algorithm takes into account border effects introduced by the + * static mask, i.e it smoothes the good and bad region + * seperately in order to make sure that they are not + * correlated: + * 1) Smooth the part of the image declared to belong together + * by the static mask, e.g. the iluminated part of the image + * 2) Smooth the remaining part of the image, e.g. the not + * iluminated part of the image + * 3) combine 1) and 2) in a single image + * */ + + /*A) Filter the image declared as good by the static mask */ + + cpl_mask_or(img_mask, stat_mask); + cpl_image_reject_from_mask(img, img_mask); + img_filtered = hdrl_parallel_filter_image(img, NULL, kernel, + CPL_FILTER_MEDIAN); + + /*The filtering extents the image into the bad pixel part, thus + * we must reapply the static mask to preserve the sharp + * cutoff */ + cpl_mask_or(cpl_image_get_bpm(img_filtered), stat_mask); + + /*B) Filter the image declared as bad by the static mask */ + + /* Create an inverted mask */ + cpl_mask * stat_mask_inverted=cpl_mask_duplicate(stat_mask); + cpl_mask_not(stat_mask_inverted); + /* Restore the original bad pixel mask into img_mask */ + cpl_mask_delete(img_mask); + img_mask = cpl_mask_duplicate(img_mask_orig); + /* Filter the image */ + cpl_mask_or(img_mask, stat_mask_inverted); + cpl_image_reject_from_mask(img, img_mask); + img_filtered2 = hdrl_parallel_filter_image(img, NULL, kernel, + CPL_FILTER_MEDIAN); + + /*The filtering extents the image into the bad pixel part, thus + * we must reapply the static mask to preserve the sharp + * cutoff */ + cpl_mask_or(cpl_image_get_bpm(img_filtered2), + stat_mask_inverted); + cpl_mask_delete(stat_mask_inverted); + + /*C) Combine the two images into one image */ + + cpl_image_fill_rejected(img_filtered, 0.); + cpl_image_fill_rejected(img_filtered2, 0.); + /* remove the static masks to join images */ + cpl_mask * img_filtered1_mask = + cpl_image_unset_bpm(img_filtered); + cpl_mask * img_filtered2_mask = + cpl_image_unset_bpm(img_filtered2); + + cpl_image_add(img_filtered, img_filtered2); + cpl_image_delete(img_filtered2); + + /* & of static make should be input bpm */ + cpl_mask_and(img_filtered1_mask, img_filtered2_mask); + assert(memcmp(cpl_mask_get_data(img_filtered1_mask), + cpl_mask_get_data(img_mask_orig), + hdrl_get_image_npix(img)) == 0); + + /* apply original bpm back onto filtered image */ + cpl_image_reject_from_mask(img_filtered, img_filtered1_mask); + cpl_mask_delete(img_filtered1_mask); + cpl_mask_delete(img_filtered2_mask); + } + else { + /* Filter the image */ + cpl_image_reject_from_mask(img, img_mask); + /* currently only tested for CPL_BORDER_FILTER */ + img_filtered = hdrl_parallel_filter_image(img, NULL, kernel, + CPL_FILTER_MEDIAN); + } + + /* restore the original mask */ + cpl_image_reject_from_mask(img, img_mask_orig); + cpl_image_reject_from_mask(img_err, img_mask_orig); + + cpl_image_divide(img, img_filtered); + cpl_image_divide(img_err, img_filtered); + cpl_image_delete(img_filtered); + } + + /* make sure that the error is positive */ + /* TODO Check if this is following the error propagation law */ + cpl_image_abs(img_err); + + cpl_mask_delete(img_mask); + cpl_mask_delete(img_mask_orig); + } + + cpl_msg_info(cpl_func, "Combining the normalized flatfields generating" + " the master-flatfield"); + + hdrl_imagelist_collapse(hdrl_data, collapse_params, &comb_img, &comb_ctr); + + if (lowf == 1){ + cpl_image *img_filtered = hdrl_parallel_filter_image( + hdrl_image_get_image_const(comb_img), NULL, kernel, CPL_FILTER_MEDIAN); + *master = hdrl_image_create(img_filtered, hdrl_image_get_error(comb_img)); + *contrib_map = comb_ctr; + hdrl_image_delete(comb_img); + cpl_image_delete(img_filtered); + } + else { + *master = comb_img; + *contrib_map = comb_ctr; + } + + cpl_mask_delete(kernel); + cpl_msg_indent_less(); + return cpl_error_get_code(); +} + + +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_flat.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_flat.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_flat.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_flat.h 2017-09-14 14:52:05.000000000 +0000 @@ -0,0 +1,94 @@ +/* $Id: hdrl_flat.h,v 1.7 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.7 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_FLAT_H +#define HDRL_FLAT_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +typedef enum { + HDRL_FLAT_FREQ_LOW, + HDRL_FLAT_FREQ_HIGH +} hdrl_flat_method ; + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + FLAT Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_flat_parameter_create(cpl_size, cpl_size, hdrl_flat_method); +cpl_boolean hdrl_flat_parameter_check(const hdrl_parameter *) ; + +/* Accessors */ +cpl_size hdrl_flat_parameter_get_filter_size_x(const hdrl_parameter *) ; +cpl_size hdrl_flat_parameter_get_filter_size_y(const hdrl_parameter *) ; +hdrl_flat_method hdrl_flat_parameter_get_method(const hdrl_parameter *) ; + +/* Parameter Lists */ +cpl_parameterlist * hdrl_flat_parameter_create_parlist(const char *, + const char *, const hdrl_parameter *) ; +hdrl_parameter * hdrl_flat_parameter_parse_parlist(const cpl_parameterlist *, + const char *) ; + +/*---------------------------------------------------------------------------- + FLAT Computation + ----------------------------------------------------------------------------*/ + +cpl_error_code hdrl_flat_compute( + hdrl_imagelist * hdrl_data, + const cpl_mask * stat_mask, + const hdrl_parameter * collapse_params, + hdrl_parameter * flat_params, + hdrl_image ** master, + cpl_image ** contrib_map); + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_frameiter.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_frameiter.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_frameiter.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_frameiter.c 2017-09-20 13:52:02.000000000 +0000 @@ -0,0 +1,307 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_frameiter.h" +#include "hdrl_iter.h" + +#include + +/*----------------------------------------------------------------------------- + Static Prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + * @addtogroup hdrl_frameiter + * @{ + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ +#define MAX_DIM 32 + +typedef struct { + /* frameset being iterated */ + const cpl_frameset * frames; + /* number of axes being iterated */ + intptr_t naxes; + /* global index/counter */ + intptr_t index; + /* dimensions of iteration space */ + intptr_t dim[MAX_DIM]; + /* current position */ + intptr_t pos[MAX_DIM]; + /* current count in dimension */ + intptr_t cnt[MAX_DIM]; + /* offsets in data */ + intptr_t offsets[MAX_DIM]; + /* iteration strides */ + intptr_t strides[MAX_DIM]; + /* iteration axes */ + intptr_t axes[MAX_DIM]; + /* last iteration axis */ + intptr_t naxes_max; + hdrl_frameiter_data data; +} hdrl_frameiter_state; + +static cpl_size hdrl_frameiter_length(hdrl_iter * it); +static void hdrl_frameiter_delete(void * it); +static void * hdrl_frameiter_next(hdrl_iter * it); + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create iterator over cpl_frameset + * + * @param frames frames to iterate + * @param flags flags of iterator + * @param naxes number axis to iterate + * @param axes axes iteration order + * @param offsets offsets in axes (NULL for no offset) + * @param strides strides in axes (NULL for stride 1) + * @param dims dimensions of axes (NULL for dimensions of data) + * + * Create iterator over uniform frameset and extensions. + * Treats data as [nframes,next,nx,ny,nz] dimensional array and iterates over + * some axis of this data. + * Currently only supports iterating over frame and extension axis and + * returning 2d images. + * E.g. create iterator iterating first over the frames beginning at offset 0 + * and stride 1, then over the extensions beginning at offset 2 (primary is + * offset 0) with stride 2. It returns a cpl_image in each iteration which is + * owned by the caller. The dimensions are defined by the data in the frames: + * + * it = hdrl_frameiter_new(frames, 2, + * (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, + * HDRL_FRAMEITER_AXIS_EXT}, + * (intptr_t[]){0, 2}, (intptr_t[]){1, 2}, NULL), + * for (cpl_image * h = hdrl_iter_next(it); h != NULL; + * h = hdrl_iter_next(it)) { + * cpl_image_delete(h); + * } + * hdrl_iter_delete(it); + */ +/* ---------------------------------------------------------------------------*/ +hdrl_iter * +hdrl_frameiter_new(const cpl_frameset * frames, hdrl_iter_flags flags, + intptr_t naxes, + intptr_t * axes, intptr_t * offsets, intptr_t * strides, + intptr_t * dims) +{ + hdrl_frameiter_state * state = cpl_calloc(sizeof(*state), 1); + state->frames = frames; + state->naxes = naxes; + /* negative to indicate no iteration has happened yet */ + state->index = -1; + /* setup dimensions from data, adapted for user parameters later */ + state->dim[HDRL_FRAMEITER_AXIS_FRAME] = cpl_frameset_get_size(frames); + for (cpl_size i = 0; i < cpl_frameset_get_size(frames); i++) { + const cpl_frame * frm = cpl_frameset_get_position_const(frames, i); + const char * fn = cpl_frame_get_filename(frm); + cpl_size next = cpl_frame_get_nextensions(frm); + // todo check shape equality over all frames/ext + state->dim[HDRL_FRAMEITER_AXIS_EXT] = next + 1; + for (cpl_size j = 0; j < next + 1; j++) { + cpl_propertylist * plist = + cpl_propertylist_load_regexp(fn, j, "NAXIS.*", 0); + if (!cpl_propertylist_has(plist, "NAXIS")) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "NO DATA"); + } + state->naxes_max = HDRL_FRAMEITER_AXIS_EXT + cpl_propertylist_get_int(plist, "NAXIS"); + for (int k = 0; k < cpl_propertylist_get_int(plist, "NAXIS"); k++) { + char * buf = cpl_sprintf("NAXIS%d", k + 1); + state->dim[HDRL_FRAMEITER_AXIS_NAXIS1 + k] = cpl_propertylist_get_int(plist, buf); + cpl_free(buf); + } + cpl_propertylist_delete(plist); + } + } + if (state->naxes_max > HDRL_FRAMEITER_AXIS_NAXIS2 || + naxes > HDRL_FRAMEITER_AXIS_NAXIS2) { + cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, + "UNSUPPORTED MODE"); + } + if (cpl_error_get_code()) { + cpl_free(state); + return NULL; + } + + /* setup iteration space in data */ + for (intptr_t i = 0; i < naxes; i++) { + intptr_t offset = offsets == NULL ? 0 : offsets[i]; + intptr_t stride = strides == NULL ? 1 : strides[i]; + state->pos[axes[i]] = offset; + state->offsets[axes[i]] = offset; + state->strides[axes[i]] = stride; + if (dims && dims[i] > 0) { + /* TODO error checking? */ + state->dim[axes[i]] = dims[i]; + } + else { + state->dim[axes[i]] -= offset; + if (stride != 0) { + if (state->dim[axes[i]] % stride) { + state->dim[axes[i]] /= stride; + state->dim[axes[i]] += 1; + } + else { + state->dim[axes[i]] /= stride; + } + } + } + state->axes[i] = axes[i]; + } + return hdrl_iter_init(&hdrl_frameiter_next, NULL, + &hdrl_frameiter_length, + &hdrl_frameiter_delete, + HDRL_ITER_INPUT | HDRL_ITER_IMAGE | flags, state); +} + +static cpl_size hdrl_frameiter_length(hdrl_iter * it) +{ + hdrl_frameiter_state * state = hdrl_iter_state(it); + intptr_t sz = 1; + for (intptr_t i = 0; i < state->naxes; i++) { + sz *= state->dim[state->axes[i]]; + } + return sz; +} + +static void hdrl_frameiter_delete(void * it) +{ + if (!it) + return; + hdrl_frameiter_state * state = hdrl_iter_state(it); + if (hdrl_iter_check(it, HDRL_ITER_OWNS_DATA)) { + cpl_image_delete(state->data.image); + cpl_propertylist_delete(state->data.plist); + } + cpl_free(state); +} + +static cpl_boolean hdrl_frameiter_done(hdrl_iter * it) +{ + hdrl_frameiter_state * state = hdrl_iter_state(it); + return state->index >= hdrl_frameiter_length(it); +} + +static void get_data(hdrl_frameiter_state * state) +{ + if (state->naxes == 2 && state->naxes_max == HDRL_FRAMEITER_AXIS_NAXIS2) { + + if (state->axes[0] <= HDRL_FRAMEITER_AXIS_EXT && + state->axes[1] <= HDRL_FRAMEITER_AXIS_EXT ){ + + cpl_msg_debug(cpl_func, "Getting frame %zd, ext %zd", + state->pos[HDRL_FRAMEITER_AXIS_FRAME], + state->pos[HDRL_FRAMEITER_AXIS_EXT]); + + const cpl_frame *frm = cpl_frameset_get_position_const( + state->frames, state->pos[HDRL_FRAMEITER_AXIS_FRAME]); + + state->data.image = cpl_image_load(cpl_frame_get_filename(frm), + CPL_TYPE_UNSPECIFIED, 0, state->pos[HDRL_FRAMEITER_AXIS_EXT]); + + state->data.plist = cpl_propertylist_load( + cpl_frame_get_filename(frm), state->pos[HDRL_FRAMEITER_AXIS_EXT]); + + } else { + cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, "UNSUPPORTED MODE"); + } + + } else if (state->naxes == 1 && + state->axes[0] == HDRL_FRAMEITER_AXIS_FRAME ){ + /* + cpl_msg_debug(cpl_func, "Getting frame %zd, ext 0", + state->pos[HDRL_FRAMEITER_AXIS_FRAME]); + */ + const cpl_frame * frm = cpl_frameset_get_position_const( + state->frames, state->pos[HDRL_FRAMEITER_AXIS_FRAME]); + + state->data.image = cpl_image_load( + cpl_frame_get_filename(frm), CPL_TYPE_UNSPECIFIED, 0, 0); + + state->data.plist = cpl_propertylist_load( + cpl_frame_get_filename(frm), 0); + + } else if (state->naxes == 1 && + state->axes[0] == HDRL_FRAMEITER_AXIS_EXT ){ + + cpl_msg_debug(cpl_func, "Getting frame 0, ext %zd", + state->pos[HDRL_FRAMEITER_AXIS_EXT]); + + const cpl_frame * frm = cpl_frameset_get_position_const( + state->frames, 0); + + state->data.image = cpl_image_load(cpl_frame_get_filename(frm), + CPL_TYPE_UNSPECIFIED, 0, state->pos[HDRL_FRAMEITER_AXIS_EXT]); + + state->data.plist = cpl_propertylist_load(cpl_frame_get_filename(frm), + state->pos[HDRL_FRAMEITER_AXIS_EXT]); + + } else { + cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, "UNSUPPORTED MODE"); + } +} + +static void * hdrl_frameiter_next(hdrl_iter * it) +{ + hdrl_frameiter_state * state = hdrl_iter_state(it); + /* iterate to next position and return data, iterator starts at first + * position */ + state->index++; + for (intptr_t i = state->naxes - 1; state->index > 0 && i >= 0; i--) { + intptr_t idx = state->axes[i]; + if (state->cnt[idx] + 1 < state->dim[idx]) { + state->cnt[idx]++; + state->pos[idx] += state->strides[idx]; + break; + } + else { + state->cnt[idx] = 0; + state->pos[idx] = state->offsets[idx]; + } + } + + if (hdrl_iter_check(it, HDRL_ITER_OWNS_DATA)) { + cpl_image_delete(state->data.image); + cpl_propertylist_delete(state->data.plist); + state->data.image = NULL; + state->data.plist = NULL; + } + + if (hdrl_frameiter_done(it)) { + return NULL; + } + + get_data(state); + return &state->data; + +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_frameiter.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_frameiter.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_frameiter.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_frameiter.h 2016-08-12 10:04:13.000000000 +0000 @@ -0,0 +1,80 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifndef HDRL_FRAMEITER_H +#define HDRL_FRAMEITER_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_iter.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +/** @cond EXPERIMENTAL */ + +typedef enum { + HDRL_FRAMEITER_AXIS_FRAME = 0, + HDRL_FRAMEITER_AXIS_EXT = 1, + HDRL_FRAMEITER_AXIS_NAXIS1 = 2, + HDRL_FRAMEITER_AXIS_NAXIS2 = 3, + HDRL_FRAMEITER_AXIS_NAXIS3 = 4 +} hdrl_frameiter_axis; + +typedef struct { + cpl_image * image; + cpl_propertylist * plist; +} hdrl_frameiter_data; + +hdrl_iter * +hdrl_frameiter_new(const cpl_frameset * frames, hdrl_iter_flags flags, + intptr_t naxes, intptr_t * axes, intptr_t * offsets, + intptr_t *strides, intptr_t * dims); + +/** @endcond */ +#endif + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl +------------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE +/** @cond PRIVATE */ + +/** @endcond */ +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fringe.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fringe.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fringe.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fringe.c 2017-09-04 12:22:36.000000000 +0000 @@ -0,0 +1,938 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2015 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 + * + * hdrl_fringe.c + * + * Created on: May 11, 2015 + * Author: agabasch + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include +#include + + + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_fringe Fringing + * + * @brief + * This module contains functions to derive and subtract a master-fringe image + * + * \section Computation Master-fringe computation + * + * For the master-fringe estimation, the algorithm model the pixel intensity + * distribution in a given image as a mixture of two Gaussian distributions, + * whose means are the background and the fringe amplitudes, respectively: + * + * \image html gaussians.png + * + * Thus the density function \f$f(x)\f$ of the + * intensity of an individual pixel is modeled as follows + * \f[ + * f(x) = c_1\,e^{ -\frac{(x-\mu_1)^2}{2\sigma_1^2} } + * + c_2\,e^{ -\frac{(x-\mu_2)^2}{2\sigma_2^2} }. + * \f] + * + * The means \f$\mu_1\f$ and \f$\mu_2\f$ ( \f$\mu_1 < \mu_2 = \mu_{1}+a\f$) are + * proportional to the background amplitude and the fringe pattern + * amplitude, respectively. These values are used for normalization of + * the background and fringe amplitudes before stacking. + * + * The parameters of the two Gaussian components are estimated from the + * density function of the pixel intensities by a nonlinear least squares + * fit algorithm. The algorithm requires as its input an estimated + * density function. Such an estimate is calculated in a preprocessing + * step as a truncated Hermite series: + * \f[ + * f(x) \approx \sum_{n=0}^p \; c_n h_n\left(\frac{x - \mu}{\sigma}\right), + * \f] + * where \f$h_n\f$ is the normalized Hermite function + * \f[ + * h_n(x) = {\pi}^{-\frac14} \, + * 2^{-\frac{n}{2}} (n!)^{-\frac12} \, (\-1)^n \, e^{\frac{x^2\!\!}{2}} \, + * \frac{d^n}{dx^n}\left( e^{-x^2} \right), + * \f] + * \f$\mu\f$ and \f$\sigma\f$ are, respectively, the sample mean and the + * sample standard deviation of pixel intensities in the given image. + * The truncation parameter \f$p\f$ is found experimentally, \f$p = 20\f$ has + * been sufficient so far. The Hermite coefficients \f$c_n\f$ are computed + * as follows + * \f[ + * c_n = \frac1{\sigma N}\; \sum_{i=1}^N h_n\left(\frac{I_i - \mu}{\sigma}\right), + * \f] + * where the summation extends over all pixel intensities \f$I_1, \ldots, + * I_{N}\f$, \f$N\f$ is the total number of pixels, and \f$n = 0, \ldots, p\f$. + * + * The following image shows a truncated Hermite series and its + * approximation by a Gaussian mixture. + * + * \image html hermite.png + * + * \section Subtractoin Master-fringe subtraction + * + * For the master-fringe subtraction the algorithm computes fringe + * amplitudes for each individual image by a least squares fit of a + * linear combination of the estimated master-fringe and a constant background. + * Specifically, the \f$i\f$th fringe \f$F_i\f$ is estimated as + * + * \f[ + * F_{i} = a_{i}F + b_{i}, + * \f] + * + * where \f$F\f$ is the estimated stacked master-fringe, and \f$b_i\f$ is a + * constant representing the background. The unknown constants \f$a_i\f$ + * and \f$b_i\f$ are computed by a standard least squares fit preformed + * over the unmasked pixels. + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*---------------------------------------------------------------------------*/ +/** + * @brief Calculates the master fringe and contribution map based on the + * @brief Gaussian mixture model. + * + * @param ilist_fringe Image list from where to extract the fringes + * @param ilist_obj Masks with the objects of the single images (or NULL) + * @param stat_mask Static mask (or NULL) + * @param collapse_params parameter controlling the collapse algorithm + * @param master returned master fringe map + * @param contrib_map returned contribution map of the master fringe map + * @param qctable returned table containing quality control information (or NULL) + * + * @return the cpl error code in case of error or CPL_ERROR_NONE + * + * The function calculates the master fringe and contribution maps of a list of + * (dithered) images. The background and fringe level are estimated as the mean + * values of a Gaussian mixture model to the image histogram. The histogram is + * approximated by a Hermite series before fitting the mixture model, + * in order to avoid possible problems with bin sizes. + * + * The masks exclude the regions where the fringe is weak, and are essential + * for an accurate estimation of noisy images. + * The masks can be used to remove objects and bad regions from the + * fit as well: + * The algorithm combines the bad pixel map (from ilist_fringe), + * the object mask (from ilist_obj), and static mask (stat_mask) + * for the fringe computation itself, but uses only + * the combined bad pixel map and object mask for the final collapsing. This + * ensures that the master fringe is also calculated in regions excluded by the + * static mask. + * + * @note Please note, that the function directly works on the passed hdrl + * imagelist (ilist_fringe) in order to save memory thus modifying the imagelist + * + * @note Error propagation: Please note, that the scaling factor derived and + * used in this function is considered to be noiseless, i.e. the associated + * error is supposed to be zero + * + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_fringe_compute(hdrl_imagelist* ilist_fringe, const cpl_imagelist * ilist_obj, + const cpl_mask* stat_mask, const hdrl_parameter* collapse_params, + hdrl_image** master, cpl_image** contrib_map, + cpl_table ** qctable) +{ + if (qctable) { + *qctable = NULL; + } + /*Check that ilist_fringe and collapse_params are not pointer to NULL + * and that there is at least one image in the hdrl imagelist */ + cpl_error_ensure(ilist_fringe && collapse_params , CPL_ERROR_NULL_INPUT, + goto cleanup, "NULL input imagelist or parameter"); + cpl_error_ensure(hdrl_imagelist_get_size(ilist_fringe) > 0 , + CPL_ERROR_NULL_INPUT, goto cleanup, + "input imagelist is empty"); + + cpl_size nx, ny, nx1, ny1; + nx = hdrl_image_get_size_x(hdrl_imagelist_get_const(ilist_fringe, 0)); + ny = hdrl_image_get_size_y(hdrl_imagelist_get_const(ilist_fringe, 0)); + + /* If there is a ilist_obj check the size and the dimensions: */ + if (ilist_obj != NULL) { + cpl_error_ensure(hdrl_imagelist_get_size(ilist_fringe) == + cpl_imagelist_get_size(ilist_obj), + CPL_ERROR_INCOMPATIBLE_INPUT, goto cleanup, + "size of fringe and object image list does " + "not match"); + + nx1 = cpl_image_get_size_x(cpl_imagelist_get_const(ilist_obj, 0)); + ny1 = cpl_image_get_size_y(cpl_imagelist_get_const(ilist_obj, 0)); + cpl_error_ensure(nx == nx1, CPL_ERROR_INCOMPATIBLE_INPUT, goto cleanup, + "size of fringe image and object mask does not match"); + cpl_error_ensure(ny == ny1, CPL_ERROR_INCOMPATIBLE_INPUT, goto cleanup, + "size of fringe image and object mask does not match"); + } + + /* If there is a static mask check the dimensions: */ + if (stat_mask != NULL) { + /* If there is a stat_mask check the dimensions: */ + cpl_error_ensure(nx == cpl_mask_get_size_x(stat_mask), + CPL_ERROR_INCOMPATIBLE_INPUT, goto cleanup, + "size of fringe image and fringe mask does not match"); + cpl_error_ensure(ny == cpl_mask_get_size_y(stat_mask), + CPL_ERROR_INCOMPATIBLE_INPUT, goto cleanup, + "size of fringe image and fringe mask does not match"); + } + +/* This algorithm combines bpm (ilist_fringe), object list (from ilist_obj) + * and static mask (stat_mask) for the fringe computation but uses only + * the combined bpm and object list for the collapsing */ + +/* !! This algorithm directly works on the ilist_fringe object thus it + * modifies ilist_fringe !! */ + + double bkg_level = 0.; + double fringe_level = 0.; + + cpl_size isize = hdrl_imagelist_get_size(ilist_fringe); + cpl_msg_debug(cpl_func, "Measure fringe amplitudes"); + if (qctable != NULL) { + *qctable = cpl_table_new(isize); + cpl_table_new_column(*qctable, "Background_level", CPL_TYPE_DOUBLE); + cpl_table_new_column(*qctable, "Fringe_amplitude", CPL_TYPE_DOUBLE); + } + for (cpl_size i = 0; i < isize; i++) { + + hdrl_image * this_himg = hdrl_imagelist_get(ilist_fringe, i); + + cpl_mask *this_fmsk = cpl_mask_duplicate(hdrl_image_get_mask(this_himg)); + if (ilist_obj != NULL) { + const cpl_image * obj = cpl_imagelist_get_const(ilist_obj, i); + cpl_mask * obj_mask = cpl_mask_threshold_image_create(obj, + -0.5, 0.5) ; + cpl_mask_not(obj_mask) ; + cpl_mask_or(this_fmsk, obj_mask); + cpl_mask_delete(obj_mask) ; + } + + /* Add the object mask to the bad pixel mask for the collapsing */ + hdrl_image_reject_from_mask(this_himg, this_fmsk); + + /* Add the static mask to the bad pixel mask and object mask for the + * amplitude calculation */ + + if (stat_mask != NULL) { + cpl_mask_or(this_fmsk, stat_mask); + } + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_matrix *cur_amplitudes = hdrl_mime_fringe_amplitudes( + hdrl_image_get_image_const(this_himg), this_fmsk); + + /* Handle situation where fit is not converging */ + if (!cpl_errorstate_is_equal(prestate)) { + cpl_msg_warning(cpl_func, "Background level and fringe amplitude " + "could not be determined! Assuming a background" + " level of 0 and a fringe amplitude of 1"); + bkg_level = 0.; + fringe_level = 1.; + /* Reset error code */ + cpl_errorstate_set(prestate); + } + else { + bkg_level = cpl_matrix_get(cur_amplitudes, 0, 0); + fringe_level = cpl_matrix_get(cur_amplitudes, 1, 0); + } + + + double fringe_amplitude = fringe_level - bkg_level; + if (qctable != NULL) { + cpl_table_set_double(*qctable,"Background_level", i, bkg_level); + cpl_table_set_double(*qctable,"Fringe_amplitude", i, fringe_amplitude); + } + cpl_msg_info(cpl_func, "img: %04d Bkg: %12.6g Amplitude: %12.6g", + (int)i+1, bkg_level, fringe_amplitude); + + cpl_msg_debug(cpl_func, "Rescaling image"); + + hdrl_image_sub_scalar(this_himg, (hdrl_value){bkg_level, 0.}); + + hdrl_image_div_scalar(this_himg, (hdrl_value){fringe_amplitude, 0.}); + + cpl_matrix_delete(cur_amplitudes); + cpl_mask_delete(this_fmsk); + } + + cpl_msg_debug(cpl_func, "Combining the normalized fringes generating" + " the master-fringe"); + hdrl_imagelist_collapse(ilist_fringe, collapse_params, master, + contrib_map); + +cleanup: + if (cpl_error_get_code() != CPL_ERROR_NONE) { + if (qctable) { + cpl_table_delete(*qctable); + *qctable = NULL; + } + if (master) { + *master = NULL; + } + if (contrib_map) { + *contrib_map = NULL; + } + } + + return cpl_error_get_code(); + +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Scales and subtracts the master fringe from the images. + * + * @param ilist_fringe Image list from where to subtract the master fringe + * @param ilist_obj Masks with the objects of the single images (or NULL) + * @param stat_mask Static mask (or NULL) + * @param masterfringe master fringe to scale and subtract + * @param qctable table containing quality control information (or NULL) + * + * @return the cpl error code in case of error or CPL_ERROR_NONE + * + * The function subtracts a fringe correction image (master) from a set of + * input images (ilist_fringe). The amplitude of the fringes is computed + * for each input image and used to properly rescale the correction image + * before subtraction. + * + * The masks exclude the regions where the fringe is weak, and are essential + * for an accurate scaling estimation of noisy images. + * The algorithm combines the bad pixel map (from ilist_fringe), + * the object mask (from ilist_obj), and static mask (stat_mask) + * for the scaling computation of the master fringe, but only uses the bad pixel + * map when subtracting the master-fringe. The object mask and static mask + * are ignored in this step. This ensures that the master fringe is properly + * subtracted (with error propagation) in all regions not affected by the bad + * pixel mask. + * + * @note Please note, that the function directly works on the passed hdrl + * imagelist (ilist_fringe) in order to save memory thus modifying the imagelist + * i.e. removing the fringes directly from the original imagelist (ilist_fringe) + * + * @note Error propagation: Please note, that the scaling factor derived and + * used in this function is considered to be noiseless, i.e. the associated + * error is supposed to be zero + * + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_fringe_correct(hdrl_imagelist * ilist_fringe, const cpl_imagelist * ilist_obj, + const cpl_mask * stat_mask, const hdrl_image * masterfringe, + cpl_table ** qctable) +{ + if (qctable) { + *qctable = NULL; + } + /*Check that ilist_fringe and masterfringe are not NULL pointers + * and that there is at least one image in the hdrl imagelist */ + cpl_ensure_code(ilist_fringe && masterfringe, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(hdrl_imagelist_get_size(ilist_fringe) > 0 , + CPL_ERROR_NULL_INPUT); + + cpl_size nx, ny, nx1, ny1; + nx = hdrl_image_get_size_x(hdrl_imagelist_get_const(ilist_fringe, 0)); + ny = hdrl_image_get_size_y(hdrl_imagelist_get_const(ilist_fringe, 0)); + + /*Check the dimension of the masterfringe image*/ + nx1 = hdrl_image_get_size_x(masterfringe); + ny1 = hdrl_image_get_size_y(masterfringe); + cpl_ensure_code(nx == nx1, CPL_ERROR_INCOMPATIBLE_INPUT ); + cpl_ensure_code(ny == ny1, CPL_ERROR_INCOMPATIBLE_INPUT ); + + + /* If there is a ilist_obj check the size and the dimensions: */ + if (ilist_obj != NULL) { + cpl_ensure_code(hdrl_imagelist_get_size(ilist_fringe) == + cpl_imagelist_get_size(ilist_obj), + CPL_ERROR_INCOMPATIBLE_INPUT); + + nx1 = cpl_image_get_size_x(cpl_imagelist_get_const(ilist_obj, 0)); + ny1 = cpl_image_get_size_y(cpl_imagelist_get_const(ilist_obj, 0)); + cpl_ensure_code(nx == nx1, CPL_ERROR_INCOMPATIBLE_INPUT ); + cpl_ensure_code(ny == ny1, CPL_ERROR_INCOMPATIBLE_INPUT ); + } + + /* If there is a static mask check the dimensions: */ + if (stat_mask != NULL) { + /* If there is a stat_mask check the dimensions: */ + cpl_ensure_code(nx == cpl_mask_get_size_x(stat_mask), + CPL_ERROR_INCOMPATIBLE_INPUT ); + cpl_ensure_code(ny == cpl_mask_get_size_y(stat_mask), + CPL_ERROR_INCOMPATIBLE_INPUT ); + } + /* !! This algorithm directly works on the ilist_fringe object thus it + * modifies ilist_fringe !! */ + + /* Do the actual fringemap correction */ + double bkg_level = 0.; + double fringe_level = 0.; + + cpl_size isize = hdrl_imagelist_get_size(ilist_fringe); + cpl_msg_debug(cpl_func, "Measure fringe amplitudes"); + + if (qctable != NULL) { + *qctable = cpl_table_new(isize); + cpl_table_new_column(*qctable, "Background_level", CPL_TYPE_DOUBLE); + cpl_table_new_column(*qctable, "Fringe_amplitude", CPL_TYPE_DOUBLE); + } + for (cpl_size i = 0; i < isize; i++) { + + hdrl_image * this_himg = hdrl_imagelist_get(ilist_fringe, i); + hdrl_image * this_masterfringe = hdrl_image_duplicate(masterfringe); + + cpl_mask *this_fmsk = cpl_mask_duplicate(hdrl_image_get_mask(this_himg)); + if (stat_mask != NULL) { + cpl_mask_or(this_fmsk, stat_mask); + } + + if (ilist_obj != NULL) { + const cpl_image * obj = cpl_imagelist_get_const(ilist_obj, i); + cpl_mask * obj_mask = cpl_mask_threshold_image_create(obj, + -0.5, 0.5) ; + cpl_mask_not(obj_mask) ; + cpl_mask_or(this_fmsk, obj_mask); + cpl_mask_delete(obj_mask) ; + } + + cpl_errorstate prestate = cpl_errorstate_get(); + + cpl_matrix * cur_amplitudes = hdrl_mime_fringe_amplitudes_ls( + hdrl_image_get_image_const(this_himg), this_fmsk, + hdrl_image_get_image_const(this_masterfringe)); + + /* Handle situation where fit is not converging */ + if (!cpl_errorstate_is_equal(prestate)) { + cpl_msg_warning(cpl_func, "Background level and fringe amplitude " + "could not be determined! Assuming a background" + " level of 0 and a fringe amplitude of 0, i.e. " + "no correction will be applied to this image"); + bkg_level = 0.; + fringe_level = 0.; + /* Reset error code */ + cpl_errorstate_set(prestate); + } + else { + bkg_level = cpl_matrix_get(cur_amplitudes, 0, 0); + fringe_level = cpl_matrix_get(cur_amplitudes, 1, 0); + } + + double fringe_amplitude = fringe_level - bkg_level; + + if (qctable != NULL) { + cpl_table_set_double(*qctable,"Background_level", i, bkg_level); + cpl_table_set_double(*qctable,"Fringe_amplitude", i, fringe_amplitude); + } + cpl_msg_info(cpl_func, "img: %04d Bkg: %12.6g Amplitude: %12.6g", + (int)i+1, bkg_level, fringe_amplitude); + + cpl_msg_debug(cpl_func, "Rescaling masterfringe"); + hdrl_image_mul_scalar(this_masterfringe, (hdrl_value){fringe_amplitude, 0.}); + + cpl_msg_debug(cpl_func, "Subtract rescaled masterfringe"); + hdrl_image_sub_image(this_himg, this_masterfringe); + + hdrl_image_delete(this_masterfringe); + cpl_matrix_delete(cur_amplitudes); + cpl_mask_delete(this_fmsk); + } + + if (cpl_error_get_code() != CPL_ERROR_NONE && qctable != NULL) { + cpl_table_delete(*qctable); + *qctable = NULL; + } + + return cpl_error_get_code(); + +} + +/** @cond PRIVATE */ +/*---------------------------------------------------------------------------*/ +/** + * @brief Estimate background and fringe levels in an image from a + * @brief Gaussian mixture model. + * + * @param img0 Image, + * @param mask0 Mask, + * + * @return A 2-by-1 matrix with the bkg and fringe amplitudes. + * + * Background and fringe level are estimated as the mean values of a + * Gaussian mixture model to the image histogram. The histogram is + * approximated by a Hermite series before fitting the mixture model, + * in order to avoid possible problems with bin sizes. + * + * The mask exclude the regions where the fringe is weak, and is essential + * for an accurate estimation of noisy images. + * The mask can be used to remove objects and bad regions from the + * fit. + * + * The returned matrix must be deallocated using cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_fringe_amplitudes(const cpl_image * img0, + const cpl_mask * mask0) +{ + cpl_matrix *mdata; + cpl_matrix *coeffs; + cpl_matrix *x; + cpl_matrix *hseries; + cpl_matrix *amplitudes; + cpl_vector *vals; + cpl_vector *params; + const double *img_data; + const cpl_binary *mask_data; + double *md; + double *par; + double mean, stdev, bkg_amp, fringe_amp; + int nx, ny, n, size, ns; + int msize, i; + + cpl_ensure(img0 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(mask0 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_image_get_type(img0) == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE, NULL); + +/* setting parameters + n number of the Hermite functions + */ + n = 20; + +/* getting image parameters and stats + nx, ny dimensions of images + */ + nx = cpl_image_get_size_x(img0); + ny = cpl_image_get_size_y(img0); + size = nx * ny; + msize = size - cpl_mask_count(mask0); + /* check that at least some region have been flagged */ + cpl_ensure(msize > 0 , CPL_ERROR_ILLEGAL_INPUT,NULL); + +/* creating masked image */ + mdata = cpl_matrix_new(msize, 1); + md = cpl_matrix_get_data(mdata); + + img_data = cpl_image_get_data_double_const(img0); + mask_data = cpl_mask_get_data_const(mask0); + for (i = 0; i < size; i++, mask_data++, img_data++) + { + if (*mask_data == CPL_BINARY_0) + { + *md = (double) *img_data; + md++; + } + } + mean = cpl_matrix_get_mean(mdata); + stdev = cpl_matrix_get_stdev(mdata); + +/* computing the Hermite coefficients */ + coeffs = hdrl_mime_hermite_functions_sums_create(n, mean, stdev, mdata); + cpl_matrix_multiply_scalar(coeffs, 1.0 / msize); + +/* reconstructing the density function as the Hermite series */ + ns = 1000; + x = hdrl_mime_matrix_linspace_create(ns, mean - 4.0 * stdev, + mean + 4.0 * stdev); + hseries = hdrl_mime_hermite_series_create(n, mean, stdev, coeffs, x); + +/* computing the parameters of the Gaussian mixture */ + + params = cpl_vector_new(6); + par = cpl_vector_get_data(params); + + par[0] = 0.62 / (sqrt(CPL_MATH_PI) * stdev); + par[1] = mean - 0.4 * stdev; + par[2] = 0.58 * stdev; + + par[3] = 0.57 / (sqrt(CPL_MATH_PI) * stdev); + par[4] = mean + 0.3 * stdev; + par[5] = 0.61 * stdev; + + vals = cpl_vector_wrap(ns, cpl_matrix_get_data(hseries)); + cpl_fit_lvmq(x, NULL, vals, NULL, params, NULL, hdrl_mime_gmix1, + hdrl_mime_gmix_derivs1, CPL_FIT_LVMQ_TOLERANCE, CPL_FIT_LVMQ_COUNT, + CPL_FIT_LVMQ_MAXITER, NULL, NULL, NULL); + + bkg_amp = (par[1] > par[4] ? par[4] : par[1]); + fringe_amp = (par[1] > par[4] ? par[1] : par[4]); + amplitudes = cpl_matrix_new(2, 1); + cpl_matrix_set(amplitudes, 0, 0, bkg_amp); + cpl_matrix_set(amplitudes, 1, 0, fringe_amp); + +/* cleaning up */ + cpl_matrix_delete(mdata); + cpl_matrix_delete(coeffs); + cpl_matrix_delete(x); + cpl_matrix_delete(hseries); + cpl_vector_unwrap(vals); + cpl_vector_delete(params); + + return amplitudes; +} + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Estimate background and fringe levels in an image from a + * @brief least-squares fit. + * + * @param img0 Image, + * @param mask0 Mask, + * @param fringe0 Fringe image + * + * @return A 2-by-1 matrix with the bkg and fringe amplitudes. + * + * The function determines the background and fringe levels in the + * image @a img0 by fitting the image with the fringe image @a fringe0 + * and a constant background in the least-squares sense. The fit + * ignores the masked parts of the image and the fringe, where the + * fringe is weak. + * + * The returned matrix must be deallocated using cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_fringe_amplitudes_ls(const cpl_image * img0, + const cpl_mask * mask0, const cpl_image * fringe0) +{ + cpl_matrix *mdata; + cpl_matrix *fdata; + cpl_matrix *cols12; + cpl_matrix *coeffs; + cpl_matrix *amplitudes; + const double *img_data; + const cpl_binary *mask_data; + const double *fringe_data; + double *md; + double *fd; + int nx, ny, size; + int msize, i; + + cpl_ensure(img0 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(mask0 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(fringe0 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_image_get_type(img0) == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE, NULL); + cpl_ensure(cpl_image_get_type(fringe0) == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE, NULL); + +/* getting image parameters and stats + nx, ny dimensions of images + */ + nx = cpl_image_get_size_x(img0); + ny = cpl_image_get_size_y(img0); + size = nx * ny; + msize = size - cpl_mask_count(mask0); + /* check that at least some region have been flagged */ + cpl_ensure(msize > 0 , CPL_ERROR_ILLEGAL_INPUT,NULL); + +/* creating masked image and masked fringe */ + mdata = cpl_matrix_new(msize, 1); + md = cpl_matrix_get_data(mdata); + + fdata = cpl_matrix_new(msize, 1); + fd = cpl_matrix_get_data(fdata); + + img_data = cpl_image_get_data_double_const(img0); + mask_data = cpl_mask_get_data_const(mask0); + fringe_data = cpl_image_get_data_double_const(fringe0); + for (i = 0; i < size; i++, img_data++, mask_data++, fringe_data++) + { + if (*mask_data == CPL_BINARY_0) + { + *md = (double) *img_data; + *fd = (double) *fringe_data; + md++; + fd++; + } + } + +/* computing the least squares coefficients */ + cols12 = cpl_matrix_new(msize, 2); + cpl_matrix_fill(cols12, 1.0); + cpl_matrix_copy(cols12, fdata, 0, 0); + coeffs = hdrl_mime_linalg_solve_tikhonov(cols12, mdata, 1.0e-10); + +/* computing the amplitudes */ + amplitudes = cpl_matrix_new(2, 1); + cpl_matrix_set(amplitudes, 0, 0, cpl_matrix_get(coeffs, 1, 0)); + cpl_matrix_set(amplitudes, 1, 0, cpl_matrix_get(coeffs, 0, 0) + + cpl_matrix_get(coeffs, 1, 0)); + +/* cleaning up */ + cpl_matrix_delete(mdata); + cpl_matrix_delete(fdata); + cpl_matrix_delete(cols12); + cpl_matrix_delete(coeffs); + + return amplitudes; +} + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Evaluate the partial derivatives of the Gaussian mixture + * + * @param x[] Argument + * @param params[] Array of length 6 with the means, sigmas, and factors, + * @param result[] Derivatives of the GM at x[0] + * + * @return zero on success + * + */ +/*---------------------------------------------------------------------------*/ +int hdrl_mime_gmix_derivs1(const double x[], const double params[], + double result[]) +{ + double a1, m1, sigma1; + double a2, m2, sigma2; + double tmp; + +/* initializing */ + a1 = params[0]; + m1 = params[1]; + sigma1 = params[2]; + + a2 = params[3]; + m2 = params[4]; + sigma2 = params[5]; + +/* evaluating */ + tmp = (x[0] - m1) / sigma1; + result[0] = exp(-0.5 * tmp * tmp); + result[1] = a1 * exp(-0.5 * tmp * tmp); + result[1] *= tmp / sigma1; + result[2] = a1 * exp(-0.5 * tmp * tmp); + result[2] *= tmp * tmp / sigma1; + + tmp = (x[0] - m2) / sigma2; + result[3] = exp(-0.5 * tmp * tmp); + result[4] = a2 * exp(-0.5 * tmp * tmp); + result[4] *= tmp / sigma2; + result[5] = a2 * exp(-0.5 * tmp * tmp); + result[5] *= tmp * tmp / sigma2; + + return 0; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Evaluate Gaussian mixture + * + * @param x[] Argument + * @param params[] Array of length 6 with the means, sigmas, and factors, + * @param result Value of the GM at x[0] + * + * @return zero on success + * + */ +/*---------------------------------------------------------------------------*/ +int hdrl_mime_gmix1(const double x[], const double params[], double *result) +{ + double a1, m1, sigma1; + double a2, m2, sigma2; + double tmp; + +/* initializing */ + a1 = params[0]; + m1 = params[1]; + sigma1 = params[2]; + + a2 = params[3]; + m2 = params[4]; + sigma2 = params[5]; + +/* evaluating */ + tmp = (x[0] - m1) / sigma1; + result[0] = a1 * exp(-0.5 * tmp * tmp); + tmp = (x[0] - m2) / sigma2; + result[0] += a2 * exp(-0.5 * tmp * tmp); + + return 0; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Evaluate the Hermite series at given arguments. + * + * @param n Number of the Hermite functions, + * @param center Center, + * @param scale Scale factor, + * @param coeffs Hermite coefficients, + * @param x Nodes, at which the functions are evaluated. + * + * @return The Hermite series evaluated at given arguments. + * + * The Hermite functions are normalized in the L2-sense. + * + * The returned matrix must be deallocated using cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_hermite_series_create(int n, double center, + double scale, const cpl_matrix * coeffs, const cpl_matrix * x) +{ + cpl_matrix *series; + double *ms; + const double *mc; + const double *mx; + double rt; + int i, k, size; + +/* testing input */ + if (x == NULL || coeffs == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (n < 1 || scale <= 0.0) + { + cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return NULL; + } + +/* The specific dimensions of the matrix x are not used, only its size. */ + size = cpl_matrix_get_nrow(x) * cpl_matrix_get_ncol(x); + mx = cpl_matrix_get_data_const(x); + mc = cpl_matrix_get_data_const(coeffs); + +/* allocating memory */ + series = cpl_matrix_new(size, 1); + ms = cpl_matrix_get_data(series); + +/* computing the normalization constant */ + rt = 1.0 / sqrt(sqrt(CPL_MATH_PI)); + +/* evaluating the Hermite functions at the samples */ + for (k = 0; k < size; k++) + { + double xk = (mx[k] - center) / scale; + double tmp1 = rt * exp(-0.5 * xk * xk); + double tmp2 = rt * sqrt(2.0) * xk * exp(-0.5 * xk * xk); + for (i = 2; i < n + 2; i++) + { + double tmp3 = sqrt(2) * xk * tmp2 - sqrt(i - 1) * tmp1; + tmp3 = tmp3 / sqrt(i); + + ms[k] += tmp1 * mc[i - 2]; + tmp1 = tmp2; + tmp2 = tmp3; + } + } + +/* normalizing */ + cpl_matrix_multiply_scalar(series, 1 / sqrt(scale)); + + return series; +} + + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Create the sum of values of the k-th Hermite function at + * @brief given arguments, for k = 0, ..., n-1. + * + * @param n Number of the Hermite functions. + * @param center Center. + * @param scale Scale factor. + * @param x Nodes, at which the functions are evaluated. + * + * @return The sums of the Hermite functions at given arguments. + * + * The Hermite functions are normalized in the L2-sense. + * + * The returned matrix must be deallocated using cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_hermite_functions_sums_create(int n, double center, + double scale, const cpl_matrix * x) +{ + cpl_matrix *sums; + double *ms; + const double *mx; + double rt; + int i, k, size; + double tmp3; + double sqrt_i[n + 2]; + double rsqrt_i[n + 2]; + +/* testing input */ + if (x == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (n < 1 || scale <= 0.0) + { + cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return NULL; + } + +/* The specific dimensions of the matrix x are not used, only its size. */ + size = cpl_matrix_get_nrow(x) * cpl_matrix_get_ncol(x); + mx = cpl_matrix_get_data_const(x); + +/* allocating memory */ + sums = cpl_matrix_new(n, 1); + ms = cpl_matrix_get_data(sums); + +/* computing the normalization constant */ + rt = 1.0 / sqrt(sqrt(CPL_MATH_PI)); + for (i = 1; i < n + 2; i++) { + sqrt_i[i] = sqrt(i); + rsqrt_i[i] = 1. / sqrt_i[i]; + } + +/* evaluating the Hermite functions at the samples */ + for (k = 0; k < size; k++) + { + double xk = (mx[k] - center) / scale; + double tmp1 = rt * exp(-0.5 * xk * xk); + double tmp2 = rt * sqrt(2.0) * xk * exp(-0.5 * xk * xk); + for (i = 2; i < n + 2; i++) + { + tmp3 = sqrt(2) * xk * tmp2 - sqrt_i[i - 1] * tmp1; + tmp3 = tmp3 * rsqrt_i[i]; + + ms[i - 2] += tmp1; + tmp1 = tmp2; + tmp2 = tmp3; + } + } + +/* normalizing */ + cpl_matrix_multiply_scalar(sums, 1 / sqrt(scale)); + + return sums; +} +/** @endcond */ + + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fringe.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fringe.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_fringe.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_fringe.h 2016-10-11 10:54:28.000000000 +0000 @@ -0,0 +1,70 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2015 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 + * + * hdrl_fringe.h + * + * Created on: May 11, 2015 + * Author: agabasch + */ + +#ifndef HDRL_FRINGE_H +#define HDRL_FRINGE_H +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +cpl_error_code +hdrl_fringe_compute(hdrl_imagelist* ilist_fringe, const cpl_imagelist * ilist_obj, + const cpl_mask* stat_mask, const hdrl_parameter* collapse_params, + hdrl_image** master, cpl_image** contrib_map, + cpl_table ** qctable); +cpl_error_code +hdrl_fringe_correct(hdrl_imagelist * ilist_fringe, const cpl_imagelist * ilist_obj, + const cpl_mask * stat_mask, const hdrl_image * masterfringe, + cpl_table ** qctable); + +#if defined HDRL_USE_PRIVATE +cpl_matrix * hdrl_mime_fringe_amplitudes(const cpl_image * img0, + const cpl_mask * mask0); + +cpl_matrix * hdrl_mime_fringe_amplitudes_ls(const cpl_image * img0, + const cpl_mask * mask0, const cpl_image * fringe0); + +int hdrl_mime_gmix_derivs1(const double x[], const double params[], + double result[]); +int hdrl_mime_gmix1(const double x[], const double params[], double *result); +cpl_matrix *hdrl_mime_hermite_series_create(int n, double center, + double scale, const cpl_matrix * coeffs, const cpl_matrix * x); +cpl_matrix *hdrl_mime_hermite_functions_sums_create(int n, double center, + double scale, const cpl_matrix * x); +#endif + + +#endif /* HDRL_FRINGE_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl.h 2017-08-11 08:17:58.000000000 +0000 @@ -0,0 +1,77 @@ +/* $Id: hdrl.h,v 1.4 2013-10-23 09:42:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +/*----------------------------------------------------------------------------*/ +/* Documentation here is used in the reference manual Main Page */ +/** @mainpage HDRL Introduction + + TEXT + + \section releases Releases + + List of release notes for diff releases + + \section usage Usage + + Externals Defintions description + + \section hdrldemop + + Offered recipes + + \section links Links + CPL page + Pipelines page + +*/ +/*----------------------------------------------------------------------------*/ + + +#ifndef HDRL_H +#define HDRL_H + +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_parameter.h" +#include "hdrl_imagelist_view.h" +#include "hdrl_overscan.h" +#include "hdrl_buffer.h" +#include "hdrl_collapse.h" +#include "hdrl_lacosmics.h" +#include "hdrl_bpm_2d.h" +#include "hdrl_bpm_3d.h" +#include "hdrl_bpm_fit.h" +#include "hdrl_bpm_utils.h" +#include "hdrl_fit.h" +#include "hdrl_strehl.h" +#include "hdrl_flat.h" +#include "hdrl_catalogue.h" +#include "hdrl_random.h" +#include "hdrl_iter.h" +#include "hdrl_frameiter.h" +#include "hdrl_multiiter.h" +#include "hdrl_fringe.h" +#include "hdrl_spectrum.h" +#include "hdrl_spectrumlist.h" +#include "hdrl_response.h" +#include "hdrl_efficiency.h" +#include "hdrl_spectrum_resample.h" +#include "hdrl_dar.h" +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image.c 2017-08-25 11:27:19.000000000 +0000 @@ -0,0 +1,801 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_elemop.h" +#include "hdrl_image.h" +#include "hdrl_image_defs.h" +#include "hdrl_utils.h" +#include "hdrl_buffer.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_image Image object + * + * hdrl_image is a two dimensional array object containing data and its + * associated errors. It provides a similar api to cpl_image and performs + * linear error propagation where it makes sense. + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +static void _hdrl_image_delete(hdrl_image * himg); +static void _hdrl_image_delete_buffer(hdrl_image * himg); +static void _hdrl_image_sync_mask(hdrl_image * himg); + +/* ---------------------------------------------------------------------------*/ +/** + * @brief check data and its errors for consistency + * + * will warn if error has a different bpm than image + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_image_check_consistent(const cpl_image * image, + const cpl_image * error) +{ + cpl_ensure_code(image, CPL_ERROR_NULL_INPUT); + if (error) { + cpl_size inx = cpl_image_get_size_x(image); + cpl_size iny = cpl_image_get_size_y(image); + cpl_size enx = cpl_image_get_size_x(error); + cpl_size eny = cpl_image_get_size_y(error); + const cpl_mask * ibpm = cpl_image_get_bpm_const(image); + const cpl_mask * ebpm = cpl_image_get_bpm_const(error); + cpl_ensure_code(inx == enx, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(iny == eny, CPL_ERROR_INCOMPATIBLE_INPUT); + + if (ibpm && ebpm) { + const cpl_binary * dibpm = cpl_mask_get_data_const(ibpm); + const cpl_binary * debpm = cpl_mask_get_data_const(ebpm); + if (memcmp(dibpm, debpm, inx * iny) != 0) { + cpl_msg_warning(cpl_func, "Image and error bad pixel mask " + "not equal, ignoring mask of error image"); + } + } + else if (ibpm == NULL && ebpm) { + cpl_msg_warning(cpl_func, "Image and error bad pixel mask " + "not equal, ignoring mask of error image"); + } + } + + return CPL_ERROR_NONE; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get data as cpl image + * @param himg hdrl image + * @return cpl_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * hdrl_image_get_image(hdrl_image * himg) +{ + cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL); + return himg->image; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get data as cpl image + * @param himg hdrl image + * @return const cpl_image + */ +/* ---------------------------------------------------------------------------*/ +const cpl_image * hdrl_image_get_image_const(const hdrl_image * himg) +{ + cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL); + return himg->image; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get error as cpl image + * @param himg hdrl image + * @return cpl_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * hdrl_image_get_error(hdrl_image * himg) +{ + cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL); + return himg->error; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get error as cpl image + * @param himg hdrl image + * @return cpl_image + */ +/* ---------------------------------------------------------------------------*/ +const cpl_image * hdrl_image_get_error_const(const hdrl_image * himg) +{ + cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL); + return himg->error; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get cpl bad pixel mask from image + * @param himg hdrl image + * @return cpl_mask, created when it does not exist + */ +/* ---------------------------------------------------------------------------*/ +cpl_mask * hdrl_image_get_mask(hdrl_image * himg) +{ + cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL); + if (cpl_image_get_bpm_const(hdrl_image_get_image(himg)) == NULL) { + /* call adds mask, also add a mask to the errors */ + cpl_image_get_bpm(hdrl_image_get_error(himg)); + } + + return cpl_image_get_bpm(hdrl_image_get_image(himg)); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get cpl bad pixel mask from image + * @param himg hdrl image + * @return cpl_mask or NULL if no mask exists + */ +/* ---------------------------------------------------------------------------*/ +const cpl_mask * hdrl_image_get_mask_const(const hdrl_image * himg) +{ + cpl_ensure(himg, CPL_ERROR_NULL_INPUT, NULL); + return cpl_image_get_bpm_const(hdrl_image_get_image_const(himg)); +} + + + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief create hdrl image by wrapping two cpl images + * @note beside typecheck no consistency checks on the two images + * @see hdrl_image_check_consistent + */ +/* ---------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_wrap(cpl_image * img, cpl_image * err, hdrl_free * destructor, + cpl_boolean sync_mask) +{ + hdrl_image * himg; + cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(err, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_image_get_type(img) == HDRL_TYPE_DATA, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(cpl_image_get_type(err) == HDRL_TYPE_ERROR, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + himg = cpl_malloc(sizeof(*himg)); + himg->image = img; + himg->error = err; + + if (destructor) { + himg->fp_free = destructor; + } + else { + himg->fp_free = (hdrl_free*)_hdrl_image_delete; + } + + if (sync_mask) { + _hdrl_image_sync_mask(himg); + } + + return himg; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief unwrap hdrl image, will not delete wrapped cpl images + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_image_unwrap(hdrl_image * himg) +{ + cpl_free(himg); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief create a new hdrl_image from to existing images by copying them + * + * @param image data to copy + * @param error errors to copy + * @param check_consistent check consistency + * + * @return hdrl_image + * @see hdrl_image_create + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_image * _hdrl_image_create(const cpl_image * image, + const cpl_image * error, + cpl_boolean check_consistent) +{ + cpl_image * himage = NULL, * herror = NULL; + + if (check_consistent && hdrl_image_check_consistent(image, error)) { + return NULL; + } + + himage = cpl_image_cast(image, HDRL_TYPE_DATA); + if (error) { + herror = cpl_image_cast(error, HDRL_TYPE_ERROR); + } + else { + /* set error to zero */ + herror = cpl_image_new(cpl_image_get_size_x(image), + cpl_image_get_size_y(image), + HDRL_TYPE_ERROR); + } + + /* sync image and error bpm ignoring what is in error before */ + if (cpl_image_get_bpm_const(image)) { + cpl_image_reject_from_mask(herror, + cpl_image_get_bpm_const(image)); + } + else { + cpl_image_accept_all(herror); + } + + return hdrl_image_wrap(himage, herror, NULL, CPL_FALSE); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a new hdrl_image from to existing images by copying them + * + * @param image data to copy + * @param error errors to copy + * + * @return hdrl_image + */ +/* ---------------------------------------------------------------------------*/ +hdrl_image * hdrl_image_create(const cpl_image * image, + const cpl_image * error) +{ + return _hdrl_image_create(image, error, CPL_TRUE); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create new zero filled hdrl image + * + * @param nx size in x + * @param ny size in y + * + * @return hdrl_image or NULL on error + */ +/* ---------------------------------------------------------------------------*/ +hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny) +{ + cpl_image * himage = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image * herror = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + + if (cpl_error_get_code()) { + cpl_image_delete(himage); + cpl_image_delete(herror); + return NULL; + } + + return hdrl_image_wrap(himage, herror, NULL, CPL_FALSE); +} + +hdrl_image * +hdrl_image_new_from_buffer(cpl_size nx, cpl_size ny, hdrl_buffer * buf) +{ + char * p = hdrl_buffer_allocate(buf, nx * ny * (sizeof(hdrl_data_t) + + sizeof(hdrl_error_t))); + cpl_image * himage = cpl_image_wrap(nx, ny, HDRL_TYPE_DATA, p); + cpl_image * herror = cpl_image_wrap(nx, ny, HDRL_TYPE_ERROR, + p + nx * ny * sizeof(hdrl_data_t)); + + if (cpl_error_get_code()) { + cpl_image_delete(himage); + cpl_image_delete(herror); + return NULL; + } + + return hdrl_image_wrap(himage, herror, + (hdrl_free*)&_hdrl_image_delete_buffer, + CPL_FALSE); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete hdrl_image + */ +/* ---------------------------------------------------------------------------*/ +static void _hdrl_image_delete(hdrl_image * himg) +{ + if (himg) { + cpl_image_delete(himg->image); + cpl_image_delete(himg->error); + cpl_free(himg); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete buffered hdrl_image + */ +/* ---------------------------------------------------------------------------*/ +static void _hdrl_image_delete_buffer(hdrl_image * himg) +{ + if (himg) { + cpl_image_unwrap(himg->image); + cpl_image_unwrap(himg->error); + cpl_free(himg); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete hdrl_image + * @note may be used on views in which case the original memory is kept + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_image_delete(hdrl_image * himg) +{ + if (himg) { + himg->fp_free(himg); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief copy hdrl_image + */ +/* ---------------------------------------------------------------------------*/ +hdrl_image * hdrl_image_duplicate(const hdrl_image * himg) +{ + return _hdrl_image_create(hdrl_image_get_image_const(himg), + hdrl_image_get_error_const(himg), CPL_FALSE); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief set bpm of hdrl_image + * + * @param self image on which to set bpm + * @param map bpm to set + * @see cpl_image_reject_from_mask + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_reject_from_mask(hdrl_image * self, + const cpl_mask * map) +{ + if (hdrl_image_get_mask_const(self) != map) { + cpl_image_reject_from_mask(hdrl_image_get_image(self), map); + } + return cpl_image_reject_from_mask(hdrl_image_get_error(self), map); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief mark pixel as bad + * + * @param self image + * @param xpos x coordinate (FITS CONVENTION) + * @param ypos y coordinate (FITS CONVENTION) + * @see cpl_image_reject + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_reject(hdrl_image * self, + cpl_size xpos, cpl_size ypos) +{ + cpl_image_reject(hdrl_image_get_image(self), xpos, ypos); + return cpl_image_reject(hdrl_image_get_error(self), xpos, ypos); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return if pixel is marked bad + * + * @param self image + * @param xpos x coordinate (FITS CONVENTION) + * @param ypos y coordinate (FITS CONVENTION) + * @see cpl_image_is_rejected + */ +/* ---------------------------------------------------------------------------*/ +int hdrl_image_is_rejected(hdrl_image * self, cpl_size xpos, cpl_size ypos) +{ + cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1); + return cpl_image_is_rejected(hdrl_image_get_image(self), xpos, ypos); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return number of rejected pixels + * + * @param self image + * @return number of rejected pixels + * @see cpl_image_count_rejected + */ +/* ---------------------------------------------------------------------------*/ +cpl_size hdrl_image_count_rejected(const hdrl_image * self) +{ + cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1); + return cpl_image_count_rejected(hdrl_image_get_image_const(self)); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Reject pixels with the specified special value(s) + * + * @param self Input image to modify + * @param mode Bit field specifying which special value(s) to reject + * @see cpl_image_reject_value + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_reject_value(hdrl_image * self, cpl_value mode) +{ + return cpl_image_reject_value(hdrl_image_get_image(self), mode); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief mark pixel as good + * + * @param self image + * @param xpos x coordinate (FITS CONVENTION) + * @param ypos y coordinate (FITS CONVENTION) + * @see cpl_image_accept + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_accept(hdrl_image * self, + cpl_size xpos, cpl_size ypos) +{ + cpl_image_accept(hdrl_image_get_image(self), xpos, ypos); + return cpl_image_accept(hdrl_image_get_error(self), xpos, ypos); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Accept all pixels in an image + * + * @param self input image + * @see cpl_image_accept_all + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_accept_all(hdrl_image * self) +{ + cpl_image_accept_all(hdrl_image_get_image(self)); + cpl_image_accept_all(hdrl_image_get_error(self)); + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return size of X dimension of image + * + * @param self image + * @return size of X dimension of image + * @see cpl_image_get_size_x + */ +/* ---------------------------------------------------------------------------*/ +cpl_size hdrl_image_get_size_x(const hdrl_image * self) +{ + return cpl_image_get_size_x(hdrl_image_get_image_const(self)); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return size of Y dimension of image + * + * @param self image + * @return size of Y dimension of image + * @see cpl_image_get_size_y + */ +/* ---------------------------------------------------------------------------*/ +cpl_size hdrl_image_get_size_y(const hdrl_image * self) +{ + return cpl_image_get_size_y(hdrl_image_get_image_const(self)); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get pixel values of hdrl_image + * + * @param self image + * @param xpos x coordinate (FITS CONVENTION) + * @param ypos y coordinate (FITS CONVENTION) + * @param pis_rejected int pointer to store if pixel is bad, may be NULL + * + * @return data value of the pixel + * @see cpl_image_get + */ +/* ---------------------------------------------------------------------------*/ +hdrl_value hdrl_image_get_pixel(const hdrl_image * self, + cpl_size xpos, cpl_size ypos, + int * pis_rejected) +{ + int d; + hdrl_value v; + v.data = cpl_image_get(hdrl_image_get_image_const(self), xpos, ypos, &d); + + /* NULL allowed, different than CPL */ + if (pis_rejected) { + *pis_rejected = d; + } + if (d) { + v.data = NAN; + v.error = NAN; + } + else { + v.error = cpl_image_get(hdrl_image_get_error_const(self), + xpos, ypos, &d); + } + + return v; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief set pixel values of hdrl_image + * + * @param self image + * @param xpos x coordinate (FITS CONVENTION) + * @param ypos y coordinate (FITS CONVENTION) + * @param value data value to set + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_set_pixel(hdrl_image * self, + cpl_size xpos, cpl_size ypos, + hdrl_value value) +{ + /* nan may be used as a bad pixel value */ + cpl_ensure_code(value.error >= 0 || isnan(value.error), CPL_ERROR_ILLEGAL_INPUT); + + if (cpl_image_set(hdrl_image_get_image(self), xpos, ypos, value.data)) { + return cpl_error_get_code(); + } + + return cpl_image_set(hdrl_image_get_error(self), xpos, ypos, value.error); +} + + +/* ---------------------------------------------------------------------------*/ +/** + @brief extract copy of window from image + @param self image to extract from + @param llx lower left x coordinate of window (FITS convention) + @param lly lower left y coordinate of window (FITS convention) + @param urx upper right x coordinate of window (FITS convention) + @param ury upper right y coordinate of window (FITS convention) + + @return newly allocated hdrl_image containing the window + @see cpl_image_extract + + If the coordinates are < 1 the dimension of the image is added to them. + So llx = 0 wraps to hdrl_image_get_size_x(self). + */ +/* ---------------------------------------------------------------------------*/ +hdrl_image * hdrl_image_extract( + const hdrl_image * self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) +{ + const cpl_size nx = hdrl_image_get_size_x(self); + const cpl_size ny = hdrl_image_get_size_y(self); + if (llx < 1) llx += nx; + if (lly < 1) lly += ny; + if (urx < 1) urx += nx; + if (ury < 1) ury += ny; + + cpl_image * img = cpl_image_extract(hdrl_image_get_image_const(self), + llx, lly, urx, ury); + cpl_image * err = cpl_image_extract(hdrl_image_get_error_const(self), + llx, lly, urx, ury); + + if (cpl_error_get_code()) { + cpl_image_delete(img); + cpl_image_delete(err); + return NULL; + } + + return hdrl_image_wrap(img, err, NULL, CPL_FALSE); +} + + +/* ---------------------------------------------------------------------------*/ +/** + @brief Rotate an image by a multiple of 90 degrees clockwise. + @param self The image to rotate in place. + @param rot The multiple: -1 is a rotation of 90 deg counterclockwise. + @return CPL_ERROR_NONE on success, otherwise the relevant cpl_error_code + @see cpl_image_turn + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_turn(hdrl_image * self, int rot) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_image_turn(hdrl_image_get_image(self), rot); + cpl_image_turn(hdrl_image_get_error(self), rot); + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + @brief Copy one image into another + @param dst the image in which im2 is inserted + @param src the inserted image + @param xpos the x pixel position in im1 where the lower left pixel of + im2 should go (from 1 to the x size of im1) + @param ypos the y pixel position in im1 where the lower left pixel of + im2 should go (from 1 to the y size of im1) + @return CPL_ERROR_NONE or the relevant cpl_error_code on error. + @see cpl_image_copy + @note The two pixel buffers may not overlap + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_copy(hdrl_image * dst, const hdrl_image * src, + cpl_size xpos, cpl_size ypos) +{ + cpl_ensure_code(dst, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(src, CPL_ERROR_NULL_INPUT); + cpl_image_copy(hdrl_image_get_image(dst), hdrl_image_get_image_const(src), + xpos, ypos); + cpl_image_copy(hdrl_image_get_error(dst), hdrl_image_get_error_const(src), + xpos, ypos); + + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + @brief Copy cpl images into an hdrl image + @param self the image in which the cpl images are inserted + @param image the inserted image + @param error the inserted error, may be NULL + @param xpos the x pixel position in im1 where the lower left pixel of + im2 should go (from 1 to the x size of im1) + @param ypos the y pixel position in im1 where the lower left pixel of + im2 should go (from 1 to the y size of im1) + @return CPL_ERROR_NONE or the relevant cpl_error_code on error. + @see hdrl_image_copy + @note The pixel buffers may not overlap + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_insert(hdrl_image * self, + const cpl_image * image, + const cpl_image * error, + cpl_size xpos, cpl_size ypos) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(image, CPL_ERROR_NULL_INPUT); + cpl_image_copy(hdrl_image_get_image(self), image, xpos, ypos); + if (error) { + cpl_image_copy(hdrl_image_get_error(self), error, xpos, ypos); + } + /* sync error mask */ + if (cpl_image_get_bpm_const(image)) { + const cpl_mask * msrc = cpl_image_get_bpm_const(image); + cpl_mask * mdst = cpl_image_get_bpm(hdrl_image_get_error(self)); + cpl_mask_copy(mdst, msrc, xpos, ypos); + } + + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief synchronize mask + */ +/* ---------------------------------------------------------------------------*/ + +static void _hdrl_image_sync_mask(hdrl_image * himg) +{ + const cpl_mask * m = hdrl_image_get_mask_const(himg); + if (m) { + hdrl_image_reject_from_mask(himg, m); + } + else { + cpl_image_accept_all(hdrl_image_get_error(himg)); + } +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Dump structural information of a HDRL image + @param himg Image to dump + @param stream Output stream, accepts @c stdout or @c stderr + @return CPL_ERROR_NONE or the relevant cpl-error-code on error + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_FILE_IO if a write operation fails + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_dump_structure( + const hdrl_image * himg, + FILE * stream) +{ + return cpl_image_dump_structure(hdrl_image_get_image_const(himg), stream); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Dump pixel values in a HDRL image + @param himg Image to dump + @param llx Lower left x position (FITS convention, 1 for leftmost) + @param lly Lower left y position (FITS convention, 1 for lowest) + @param urx Specifies the window position + @param ury Specifies the window position + @param stream Output stream, accepts @c stdout or @c stderr + @return CPL_ERROR_NONE or the relevant cpl-error-code on error + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_FILE_IO if a write operation fails + - CPL_ERROR_ACCESS_OUT_OF_RANGE if the defined window is not in the image + - CPL_ERROR_ILLEGAL_INPUT if the window definition is wrong (e.g llx > urx) + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_image_dump_window( + const hdrl_image * himg, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + FILE * stream) +{ + return cpl_image_dump_window(hdrl_image_get_image_const(himg), + llx, lly, urx, ury, stream); + +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image_defs.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image_defs.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image_defs.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image_defs.h 2013-10-17 15:44:26.000000000 +0000 @@ -0,0 +1,48 @@ +/* $Id: hdrl_image_defs.h,v 1.4 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.4 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_IMAGE_DEFS_H +#define HDRL_IMAGE_DEFS_H + +#ifndef HDRL_USE_PRIVATE +#error This file is not allowed to be included outside of hdrl +#endif + +#include "hdrl_types.h" +#include + +CPL_BEGIN_DECLS + +struct _hdrl_image_ { + cpl_image * image; + cpl_image * error; + hdrl_free * fp_free; +}; + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image.h 2017-08-25 11:27:19.000000000 +0000 @@ -0,0 +1,131 @@ +/* $Id: hdrl_image.h,v 1.18 2013-10-23 09:42:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-23 09:42:14 $ + * $Revision: 1.18 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_IMAGE_H +#define HDRL_IMAGE_H + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + +typedef struct _hdrl_image_ hdrl_image; + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_image_math.h" +#include "hdrl_utils.h" +#include "hdrl_buffer.h" +#include "hdrl_types.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny); + +hdrl_image * hdrl_image_create(const cpl_image * image, + const cpl_image * error); + +hdrl_image * hdrl_image_duplicate(const hdrl_image * himg); + +void hdrl_image_delete(hdrl_image * himg); + +cpl_image * hdrl_image_get_image(hdrl_image * himg); +const cpl_image * hdrl_image_get_image_const(const hdrl_image * himg); + +cpl_image * hdrl_image_get_error(hdrl_image * himg); +const cpl_image * hdrl_image_get_error_const(const hdrl_image * himg); + +cpl_mask * hdrl_image_get_mask(hdrl_image * himg); +const cpl_mask * hdrl_image_get_mask_const(const hdrl_image * himg); + +hdrl_value hdrl_image_get_pixel(const hdrl_image * self, + cpl_size xpos, cpl_size ypos, + int * pis_rejected); + +cpl_error_code hdrl_image_set_pixel(hdrl_image * self, + cpl_size xpos, cpl_size ypos, + hdrl_value value); + +cpl_size hdrl_image_get_size_x(const hdrl_image * self) ; +cpl_size hdrl_image_get_size_y(const hdrl_image * self) ; + +hdrl_image * hdrl_image_extract(const hdrl_image *, + cpl_size, cpl_size, cpl_size, cpl_size) ; + +cpl_error_code hdrl_image_reject(hdrl_image * self, + cpl_size xpos, cpl_size ypos); +cpl_error_code hdrl_image_reject_value(hdrl_image * self, cpl_value mode); +cpl_error_code hdrl_image_reject_from_mask(hdrl_image * self, + const cpl_mask * map); +int hdrl_image_is_rejected(hdrl_image * self, cpl_size xpos, cpl_size ypos); +cpl_size hdrl_image_count_rejected(const hdrl_image * self); +cpl_error_code hdrl_image_accept(hdrl_image * self, + cpl_size xpos, cpl_size ypos); +cpl_error_code hdrl_image_accept_all(hdrl_image * self); + +cpl_error_code hdrl_image_turn(hdrl_image * self, int rot); + +cpl_error_code hdrl_image_copy(hdrl_image * dst, const hdrl_image * src, + cpl_size xpos, cpl_size ypos); + +cpl_error_code hdrl_image_insert(hdrl_image * self, + const cpl_image * image, + const cpl_image * error, + cpl_size xpos, cpl_size ypos); + +cpl_error_code hdrl_image_dump_structure(const hdrl_image *, FILE *) ; + +cpl_error_code hdrl_image_dump_window(const hdrl_image *, + cpl_size, cpl_size, cpl_size, cpl_size, FILE *) ; + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +hdrl_image * +hdrl_image_new_from_buffer(cpl_size nx, cpl_size ny, hdrl_buffer * buf); +#endif + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ +#ifdef HDRL_USE_PRIVATE +hdrl_image * hdrl_image_wrap(cpl_image *, cpl_image *, hdrl_free *, + cpl_boolean); +void hdrl_image_unwrap(hdrl_image * himg); +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_basic.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_basic.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_basic.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_basic.c 2018-01-12 09:59:51.000000000 +0000 @@ -0,0 +1,863 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include "hdrl_imagelist_view.h" +#include "hdrl_imagelist_defs.h" +#include "hdrl_image.h" +#include "hdrl_collapse.h" + +#include +#include + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_imagelist Imagelist object + * + * hdrl_imagelist is similiar to cpl_imagelist but for hdrl_image. + * Its reduction methods (mean, median, ...) provide linear error propagation. + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @enum hdrl_imagelist_basic_type + @brief Define the kind of operation to apply + */ +/*----------------------------------------------------------------------------*/ +typedef enum { + HDRL_IMLIST_BASIC_IMLIST = 0, + HDRL_IMLIST_BASIC_IMAGE, + HDRL_IMLIST_BASIC_SCALAR +} hdrl_imagelist_basic_type; + +typedef cpl_error_code (*hdrl_f_image)(hdrl_image *, const hdrl_image *); +typedef cpl_error_code (*hdrl_f_scalar)(hdrl_image *, hdrl_value); + +/*----------------------------------------------------------------------------- + Static Prototypes + -----------------------------------------------------------------------------*/ + +static cpl_error_code hdrl_imagelist_basic_operation( + hdrl_imagelist_basic_type type, + hdrl_f_image func, + hdrl_imagelist *himlist1, + const hdrl_imagelist *himlist2, + const hdrl_image *himg, + hdrl_value *value); + +static cpl_error_code hdrl_imagelist_collapse_interface( + const hdrl_imagelist *himlist, + hdrl_collapse_imagelist_to_image_t *collapse_method, + hdrl_image **out, + cpl_image **contrib, + void **eout); + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Add two image lists, the first one is replaced by the result. + @param himlist1 first input image list (modified) + @param himlist2 image list to add + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_add_image() + + The two input lists must have the same size, the image number n in the + list himlist2 is added to the image number n in the list himlist1. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ILLEGAL_INPUT if the input images have different sizes + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_add_imagelist( + hdrl_imagelist * himlist1, + const hdrl_imagelist * himlist2) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST, + &hdrl_image_add_image, himlist1, himlist2, NULL, NULL); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Subtract two image lists, the first one is replaced by the result. + @param himlist1 first input image list (modified) + @param himlist2 image list to subtract + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_sub_image() + @see hdrl_imagelist_add_imagelist + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_sub_imagelist( + hdrl_imagelist * himlist1, + const hdrl_imagelist * himlist2) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST, + &hdrl_image_sub_image, himlist1, himlist2, NULL, NULL); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Multiply two image lists, the first one is replaced by the result. + @param himlist1 first input image list (modified) + @param himlist2 image list to multiply + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_mul_image() + @see hdrl_imagelist_add_imagelist + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_mul_imagelist( + hdrl_imagelist * himlist1, + const hdrl_imagelist * himlist2) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST, + &hdrl_image_mul_image, himlist1, himlist2, NULL, NULL); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Divide two image lists, the first one is replaced by the result. + @param himlist1 first input image list (modified) + @param himlist2 image list to divide + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_div_image() + @see hdrl_imagelist_add_imagelist + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_div_imagelist( + hdrl_imagelist * himlist1, + const hdrl_imagelist * himlist2) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST, + &hdrl_image_div_image, himlist1, himlist2, NULL, NULL); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Add an image to an image list. + @param himlist input image list (modified) + @param himg image to add + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_add_image() + + The passed image is added to each image of the passed image list. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_add_image( + hdrl_imagelist * himlist, + const hdrl_image * himg) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE, + &hdrl_image_add_image, himlist, NULL, himg, NULL); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Subtract an image from an image list. + @param himlist input image list (modified) + @param himg image to subtract + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_sub_image() + @see hdrl_imagelist_add_image() + + The passed image is subtracted from each image of the passed image list. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_sub_image( + hdrl_imagelist * himlist, + const hdrl_image * himg) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE, + &hdrl_image_sub_image, himlist, NULL, himg, NULL); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Multiply an image by an image list. + @param himlist input image list (modified) + @param himg image to multiply + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_mul_image() + @see hdrl_imagelist_add_image() + + The passed image is multiplied by each image of the passed image list. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_mul_image( + hdrl_imagelist * himlist, + const hdrl_image * himg) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE, + &hdrl_image_mul_image, himlist, NULL, himg, NULL); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Divide an image from an image list. + @param himlist input image list (modified) + @param himg image to divide + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_div_image() + @see hdrl_imagelist_add_image() + + The passed image is used to divide each image of the passed image list. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_div_image( + hdrl_imagelist * himlist, + const hdrl_image * himg) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE, + &hdrl_image_div_image, himlist, NULL, himg, NULL); +} + + + +/*----------------------------------------------------------------------------*/ +/** + @brief Elementwise addition of a scalar to each image in the himlist + @param himlist Imagelist to be modified in place. + @param value Value to add to the images + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_add_scalar() + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_add_scalar( + hdrl_imagelist * himlist, + hdrl_value value) +{ + const cpl_error_code code = + hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR, + (hdrl_f_image)&hdrl_image_add_scalar, + himlist, NULL, NULL, &value); + return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Elementwise subtraction of a scalar to each image in the himlist + @param himlist Imagelist to be modified in place. + @param value Value to subtract to the images + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_sub_scalar() + @see hdrl_imagelist_add_scalar() + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_sub_scalar( + hdrl_imagelist * himlist, + hdrl_value value) +{ + const cpl_error_code code = + hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR, + (hdrl_f_image)&hdrl_image_sub_scalar, + himlist, NULL, NULL, &value); + return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Elementwise multiplication of a scalar to each image in the himlist + @param himlist Imagelist to be modified in place. + @param value Value to multiply to the images + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_mul_scalar() + @see hdrl_imagelist_add_scalar() + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_mul_scalar( + hdrl_imagelist * himlist, + hdrl_value value) +{ + const cpl_error_code code = + hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR, + (hdrl_f_image)&hdrl_image_mul_scalar, + himlist, NULL, NULL, &value); + return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Elementwise division by a scalar to each image in the himlist + @param himlist Imagelist to be modified in place. + @param value Value to divide to the images + @return the cpl_error_code or CPL_ERROR_NONE + @see hdrl_image_div_scalar() + @see hdrl_imagelist_add_scalar() + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_div_scalar( + hdrl_imagelist * himlist, + hdrl_value value) +{ + return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR, + (hdrl_f_image)&hdrl_image_div_scalar, himlist, + NULL, NULL, &value); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Compute the elementwise power of each image in the himlist + @param himlist Imagelist to be modified in place. + @param exponent Scalar exponent + @return CPL_ERROR_NONE or the relevant the cpl_error_code on error + @see hdrl_image_power() + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_pow_scalar( + hdrl_imagelist * himlist, + hdrl_value exponent) +{ + cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT); + + cpl_size nima = hdrl_imagelist_get_size(himlist) ; + for (cpl_size i = 0 ; ireject_low; + } else { + cpl_image_delete(sigclipout->reject_low); + } + + if (reject_high) { + *reject_high = sigclipout->reject_high; + } else { + cpl_image_delete(sigclipout->reject_high); + } + + hdrl_collapse_imagelist_to_image_unwrap_eout(method, sigclipout); + hdrl_collapse_imagelist_to_image_delete(method); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Minmax-clipped collapsing of image list + @param himlist input image list + @param nlow low number of pixels to reject + @param nhigh high number of pixels to reject + @param out output combined image + @param contrib output contribution mask + @param reject_low output low rejection thresholds, may be NULL + @param reject_high output high rejection thresholds, may be NULL + @return CPL_ERROR_NONE or the relevant the cpl_error_code on error + @see hdrl_imagelist_collapse() + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_collapse_minmax( + const hdrl_imagelist * himlist, + double nlow, + double nhigh, + hdrl_image ** out, + cpl_image ** contrib, + cpl_image ** reject_low, + cpl_image ** reject_high) +{ + hdrl_minmax_image_output * minmaxout; + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_minmax(nlow, nhigh); + hdrl_imagelist_collapse_interface(himlist, method, out, contrib, (void**)&minmaxout); + + if (cpl_error_get_code() != CPL_ERROR_NONE) { + + hdrl_collapse_imagelist_to_image_delete(method); + + if (reject_low) { + *reject_low = NULL; + } + + if (reject_high) { + *reject_high = NULL; + } + + return cpl_error_get_code(); + } + + if (reject_low) { + *reject_low = minmaxout->reject_low; + } else { + cpl_image_delete(minmaxout->reject_low); + } + + if (reject_high) { + *reject_high = minmaxout->reject_high; + } else { + cpl_image_delete(minmaxout->reject_high); + } + + hdrl_collapse_imagelist_to_image_unwrap_eout(method, minmaxout); + hdrl_collapse_imagelist_to_image_delete(method); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Generic hdrl_imagelist_collapse interface to hdrl_collapse + @param himlist input image list + @param niter number of clipping iterators + @param out output combined image + @param contrib output contribution mask + @param eout storage for extra output, may be NULL + @return CPL_ERROR_NONE or the relevant the cpl_error_code on error + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code hdrl_imagelist_collapse_interface( + const hdrl_imagelist * himlist, + hdrl_collapse_imagelist_to_image_t * collapse_method, + hdrl_image ** out, + cpl_image ** contrib, + void ** eout) +{ + cpl_error_code fail = CPL_ERROR_NONE; + + /* Check inputs */ + cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(out != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(contrib != NULL, CPL_ERROR_NULL_INPUT); + + cpl_size nz = hdrl_imagelist_get_size(himlist); + cpl_size nx = hdrl_imagelist_get_size_x(himlist); + cpl_size ny = hdrl_imagelist_get_size_y(himlist); + if (cpl_error_get_code() != CPL_ERROR_NONE) { + return cpl_error_get_code(); + } + + *out = hdrl_image_new(nx, ny); + *contrib = cpl_image_new( nx, ny, CPL_TYPE_INT); + + /* make sure we have masks else the copy into these is not threadsafe */ + cpl_image_get_bpm(*contrib); + hdrl_image_get_mask(*out); + + /* create full extra output */ + if (eout) { + *eout = hdrl_collapse_imagelist_to_image_create_eout( + collapse_method, hdrl_image_get_image(hdrl_imagelist_get(himlist, 0))); + } + + /* get blocks that can be processed in parallel + * small blocksize better for cache but currently excessive malloc/free + * prevents making it smaller */ + cpl_size blocksize = 16ul * (1ul<<20ul) / (nz * nx * sizeof(double)); + hdrl_iter *it = hdrl_imagelist_get_iter_row_slices(himlist, blocksize, 0, HDRL_ITER_CONST); + + cpl_size nit = hdrl_iter_length(it); + hdrl_imagelist *vl[nit]; + cpl_size yl[nit]; + + { + cpl_size i = 0; + cpl_size y = 1; + for (hdrl_imagelist * v = hdrl_iter_next(it); + v != NULL; + v = hdrl_iter_next(it)) { + vl[i] = v; + yl[i++] = y; + y += hdrl_imagelist_get_size_y(v); + } + } + + hdrl_iter_delete(it); + + if (cpl_error_get_code() != CPL_ERROR_NONE) { + for (cpl_size i = 0; i < nit; i++) { + hdrl_imagelist_delete(vl[i]); + } + return cpl_error_get_code(); + } + + HDRL_OMP(omp parallel for) + for (cpl_size i = 0; i < nit; i++) { + + cpl_image *out_data; + cpl_image *out_errors; + cpl_image *out_contrib; + + cpl_imagelist *data; + cpl_imagelist *errors; + + void *out_eout; + + hdrl_imagelist *v = vl[i]; + cpl_size y = yl[i]; + + /* Build the Inputs Interface */ + hdrl_imagelist_to_cplwrap(v, &data, &errors); + + /* Call the actual collapsing */ + hdrl_collapse_imagelist_to_image_call(collapse_method, data, errors, + &out_data, &out_errors, + &out_contrib, &out_eout); + + if (cpl_error_get_code() != CPL_ERROR_NONE) { + + fail = cpl_error_get_code(); + cpl_imagelist_unwrap(data) ; + cpl_imagelist_unwrap(errors) ; + hdrl_imagelist_delete(v); + + } else { + + cpl_msg_debug(cpl_func, "Collapsed block %lld to %lld", y, + y + cpl_image_get_size_y(out_data) - 1); + + /* TODO make use of output image views to avoid copying */ + assert(hdrl_image_get_mask_const(*out)); + assert(cpl_image_get_bpm_const(*contrib)); + hdrl_image_insert(*out, out_data, out_errors, 1, y); + cpl_image_copy(*contrib, out_contrib, 1, y); + + /* copy and delete slice extra out */ + if (out_eout) { + hdrl_collapse_imagelist_to_image_move_eout(collapse_method, + *eout, out_eout, y); + } + + /* Destroy the Inputs Interface */ + cpl_image_delete(out_data); + cpl_image_delete(out_errors); + cpl_image_delete(out_contrib); + cpl_imagelist_unwrap(data) ; + cpl_imagelist_unwrap(errors) ; + hdrl_imagelist_delete(v); + } + } + + if (fail != CPL_ERROR_NONE) { + + if (eout) { + hdrl_collapse_imagelist_to_image_delete_eout(collapse_method, *eout); + } + + hdrl_image_delete(*out); + cpl_image_delete(*contrib); + + return cpl_error_set_message(cpl_func, fail, "hdrl_imagelist_collapse failed"); + } + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Compute the elementwise power of each image in the himlist + * + * @param type type of operation + * @param func ptr to operation what it need to apply + * @param himlist1 ptr to imagelist to be modified (not NULL). + * @param himlist2 ptr to imagelist to be apply over himlist1 or NULL + * @param himg ptr to image to be apply over himlist1 or NULL + * @param value ptr to hvalue to be apply over himlist1 or NULL + * + * @return CPL_ERROR_NONE or the relevant the cpl_error_code on error + * + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_imagelist_basic_operation( + hdrl_imagelist_basic_type type, + hdrl_f_image func, + hdrl_imagelist *himlist1, + const hdrl_imagelist *himlist2, + const hdrl_image *himg, + hdrl_value *value){ + + /* Check input */ + cpl_ensure_code(func, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(himlist1, CPL_ERROR_NULL_INPUT); + + switch (type) { + case HDRL_IMLIST_BASIC_IMLIST: + cpl_ensure_code(himlist2, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(himlist1->ni == himlist2->ni, + CPL_ERROR_INCOMPATIBLE_INPUT); + break; + case HDRL_IMLIST_BASIC_IMAGE: + cpl_ensure_code(himg, CPL_ERROR_NULL_INPUT); + break; + case HDRL_IMLIST_BASIC_SCALAR: + cpl_ensure_code(value, CPL_ERROR_NULL_INPUT); + break; + } + + /* Loop and apply the operation */ + for (cpl_size i = 0; i < himlist1->ni; i++) { + cpl_error_code err; + switch (type) { + case HDRL_IMLIST_BASIC_IMLIST: + err = func(himlist1->images[i], himlist2->images[i]); + break; + case HDRL_IMLIST_BASIC_IMAGE: + err = func(himlist1->images[i], himg); + break; + case HDRL_IMLIST_BASIC_SCALAR: + err = ((hdrl_f_scalar)func)(himlist1->images[i], *value); + break; + } + cpl_ensure_code(err == CPL_ERROR_NONE, err); + } + + return CPL_ERROR_NONE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_basic.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_basic.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_basic.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_basic.h 2014-08-19 11:33:24.000000000 +0000 @@ -0,0 +1,79 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_IMAGELIST_BASIC_H +#define HDRL_IMAGELIST_BASIC_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_collapse.h" +#include "hdrl_parameter.h" +#include "hdrl_imagelist.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + +/* Imagelist Basic Operations */ +cpl_error_code hdrl_imagelist_add_imagelist(hdrl_imagelist *, + const hdrl_imagelist *); +cpl_error_code hdrl_imagelist_sub_imagelist(hdrl_imagelist *, + const hdrl_imagelist *); +cpl_error_code hdrl_imagelist_mul_imagelist(hdrl_imagelist *, + const hdrl_imagelist *); +cpl_error_code hdrl_imagelist_div_imagelist(hdrl_imagelist *, + const hdrl_imagelist *); + +cpl_error_code hdrl_imagelist_add_image(hdrl_imagelist *, const hdrl_image *); +cpl_error_code hdrl_imagelist_sub_image(hdrl_imagelist *, const hdrl_image *); +cpl_error_code hdrl_imagelist_mul_image(hdrl_imagelist *, const hdrl_image *); +cpl_error_code hdrl_imagelist_div_image(hdrl_imagelist *, const hdrl_image *); + +cpl_error_code hdrl_imagelist_add_scalar(hdrl_imagelist *, hdrl_value); +cpl_error_code hdrl_imagelist_sub_scalar(hdrl_imagelist *, hdrl_value); +cpl_error_code hdrl_imagelist_mul_scalar(hdrl_imagelist *, hdrl_value); +cpl_error_code hdrl_imagelist_div_scalar(hdrl_imagelist *, hdrl_value); +cpl_error_code hdrl_imagelist_pow_scalar(hdrl_imagelist *, hdrl_value); + +/* Collapsing functions */ +cpl_error_code hdrl_imagelist_collapse( + const hdrl_imagelist * himlist, + const hdrl_parameter * param, + hdrl_image ** out, + cpl_image ** contrib); +cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *, + hdrl_image **, cpl_image **) ; +cpl_error_code hdrl_imagelist_collapse_weighted_mean(const hdrl_imagelist *, + hdrl_image **, cpl_image **) ; +cpl_error_code hdrl_imagelist_collapse_median(const hdrl_imagelist *, + hdrl_image **, cpl_image **) ; +cpl_error_code hdrl_imagelist_collapse_sigclip(const hdrl_imagelist *, + double, double, int, hdrl_image **, cpl_image **, + cpl_image **, cpl_image **) ; +cpl_error_code hdrl_imagelist_collapse_minmax(const hdrl_imagelist *, + double, double, hdrl_image **, cpl_image **, + cpl_image **, cpl_image **) ; + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_defs.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_defs.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_defs.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_defs.h 2014-08-07 13:35:13.000000000 +0000 @@ -0,0 +1,51 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifndef HDRL_IMAGELIST_DEFS_H +#define HDRL_IMAGELIST_DEFS_H + +#ifndef HDRL_USE_PRIVATE +#error This file is not allowed to be included outside of hdrl +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include "hdrl_image.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + +struct _hdrl_imagelist_ { + cpl_size ni; + cpl_size capacity; + hdrl_image ** images; +}; + + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist.h 2013-11-19 16:52:00.000000000 +0000 @@ -0,0 +1,37 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_IMAGELIST_H +#define HDRL_IMAGELIST_H + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + +typedef struct _hdrl_imagelist_ hdrl_imagelist; + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist_io.h" +#include "hdrl_imagelist_basic.h" +#include "hdrl_imagelist_view.h" + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_io.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_io.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_io.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_io.c 2017-09-01 12:37:08.000000000 +0000 @@ -0,0 +1,688 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_imagelist_defs.h" +#include "hdrl_imagelist_view.h" +#include "hdrl_iter.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ + +#define HDRL_MSG "Imagelist with %d image(s)\n" +#define HDRL_IMSG "Image nb %d of %d in imagelist\n" + +/*----------------------------------------------------------------------------- + Static Prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + * @addtogroup hdrl_imagelist + * @{ + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief resize buffer to set size + * @param h imagelist to update + * @param size capacity the buffer should have, minimum 128 + * + * only changes the buffer size, not the number of contained images + */ +/* ---------------------------------------------------------------------------*/ +static void hdrl_imagelist_set_capacity(hdrl_imagelist * h, cpl_size size) +{ + h->capacity = CX_MAX(h->ni, CX_MAX(128, size)); + h->images = cpl_realloc(h->images, h->capacity * sizeof(h->images[0])); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create an empty imagelist + @return 1 newly allocated hdrl_imagelist + @see hdrl_imagelist_set() + The returned hdrl_imagelist must be deallocated using hdrl_imagelist_delete() + */ +/*----------------------------------------------------------------------------*/ +hdrl_imagelist * hdrl_imagelist_new(void) +{ + hdrl_imagelist * h = cpl_calloc(1, sizeof(hdrl_imagelist)); + hdrl_imagelist_set_capacity(h, 128); + return h; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create an hdrl_imagelist out of 2 cpl_imagelist + @param imlist the list of image + @param errlist the list of errors + @return The new hdrl_imagelist + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +hdrl_imagelist * hdrl_imagelist_create( + cpl_imagelist * imlist, + cpl_imagelist * errlist) +{ + hdrl_imagelist * himlist ; + cpl_image * error ; + + /* Check Entries */ + cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + if (errlist) { + cpl_ensure(cpl_imagelist_get_size(imlist) == + cpl_imagelist_get_size(errlist), CPL_ERROR_ILLEGAL_INPUT, NULL); + } + + /* Create the new HDRL image list */ + himlist = hdrl_imagelist_new() ; + + /* Loop on the input image list */ + for (cpl_size i = 0; i < cpl_imagelist_get_size(imlist); i++) { + /* Get the error image */ + hdrl_image * tmp ; + if (errlist) { + error = cpl_imagelist_get(errlist, i) ; + } else { + error = NULL ; + } + /* Create the HDRL image */ + tmp = hdrl_image_create(cpl_imagelist_get_const(imlist, i), error) ; + + /* Fill the HDRL image list */ + hdrl_imagelist_set(himlist, tmp, i); + + } + return himlist ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Get the number of images in the imagelist + @param himlist the list of images + @return The number of images or -1 on error + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_size hdrl_imagelist_get_size(const hdrl_imagelist * himlist) +{ + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1); + assert( himlist->ni >= 0 ); + return himlist->ni; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Get number of colums of images in the imagelist + @param himlist the list of images + @return The number of columns of images or -1 on error + + assumes the imagelist is uniform (cpl_imagelist_is_uniform) + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ILLEGAL_INPUT if the list is empty + */ +/*----------------------------------------------------------------------------*/ +cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist * himlist) +{ + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(himlist->ni > 0, CPL_ERROR_ILLEGAL_INPUT, -1); + return hdrl_image_get_size_x(hdrl_imagelist_get_const(himlist, 0)); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Get number of rows of images in the imagelist + @param himlist the list of images + @return The number of rows of images or -1 on error + + assumes the imagelist is uniform (cpl_imagelist_is_uniform) + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ILLEGAL_INPUT if the list is empty + */ +/*----------------------------------------------------------------------------*/ +cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist * himlist) +{ + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(himlist->ni > 0, CPL_ERROR_ILLEGAL_INPUT, -1); + return hdrl_image_get_size_y(hdrl_imagelist_get_const(himlist, 0)); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Get an image from a list of images + @param himlist the image list + @param inum the image id (from 0 to number of images-1) + @return A pointer to the image or NULL in error case. + + The returned pointer refers to already allocated data. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ACCESS_OUT_OF_RANGE if inum is bigger thant the list size + - CPL_ERROR_ILLEGAL_INPUT if inum is negative + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * hdrl_imagelist_get( + const hdrl_imagelist * himlist, + cpl_size inum) +{ + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(inum < himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + return himlist->images[inum]; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Get an image from a list of images + @param himlist the image list + @param inum the image id (from 0 to number of images-1) + @return A pointer to the image or NULL in error case. + @see hdrl_imagelist_get + */ +/*----------------------------------------------------------------------------*/ +const hdrl_image * hdrl_imagelist_get_const( + const hdrl_imagelist * himlist, + cpl_size inum) +{ + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(inum < himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + return himlist->images[inum]; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Insert an image into an imagelist + @param himlist The imagelist + @param himg The image to insert + @param pos The list position (from 0 to number of images) + @return CPL_ERROR_NONE or the relevant cpl_error_code on error + + It is allowed to specify the position equal to the number of images in the + list. This will increment the size of the imagelist. + + No action occurs if an image is inserted more than once into the same + position. It is allowed to insert the same image into two different + positions in a list. + + The image is inserted at the position pos in the image list. If the image + already there is only present in that one location in the list, then the + image is deallocated. + + It is not allowed to insert images of different size into a list. + + The added image is owned by the imagelist object, which deallocates it + hdrl_imagelist_delete is called. Other option is to use + hdrl_imagelist_unset to recover ownership of the image, in which case + the hdrl_imagelist object is not longer responsible for deallocating it. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ILLEGAL_INPUT if pos is negative + - CPL_ERROR_TYPE_MISMATCH if himg and himlist are of different types + - CPL_ERROR_INCOMPATIBLE_INPUT if himg and himlist have different sizes + - CPL_ERROR_ACCESS_OUT_OF_RANGE if pos is bigger than the number of + images in himlist + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_set( + hdrl_imagelist * himlist, + hdrl_image * himg, + cpl_size pos) +{ + cpl_ensure_code(himlist, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(himg, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(pos <= himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE); + + /* Do nothing if the image is already there */ + if (pos < himlist->ni && himg == himlist->images[pos]) + return CPL_ERROR_NONE; + + if (pos > 0 || himlist->ni > 1) { + /* Require images to have the same size and type */ + cpl_ensure_code(hdrl_image_get_size_x(himg) == + hdrl_image_get_size_x(himlist->images[0]), + CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(hdrl_image_get_size_y(himg) == + hdrl_image_get_size_y(himlist->images[0]), + CPL_ERROR_INCOMPATIBLE_INPUT); + // TODO : type of hdrl_image ?? + //cpl_ensure_code(hdrl_image_get_type(himg) == + // hdrl_image_get_type(himlist->images[0]), + // CPL_ERROR_TYPE_MISMATCH); + } + + if (pos == himlist->ni) { + /* double buffer if required */ + if (pos >= himlist->capacity) { + hdrl_imagelist_set_capacity(himlist, 2 * pos); + } + himlist->ni++; + } else { + /* Check if the image at the position to be overwritten + is present in only one position */ + int i; + + for (i = 0; i < himlist->ni; i++) { + if (i != pos && himlist->images[i] == himlist->images[pos]) break; + } + if (i == himlist->ni) { + /* The image at the position to be overwritten + is present in only one position, so delete it */ + hdrl_image_delete(himlist->images[pos]); + } + } + + himlist->images[pos] = himg; + + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Remove an image from an imagelist + @param himlist The imagelist + @param pos The list position (from 0 to number of images-1) + @return The pointer to the removed image or NULL in error case + + The specified image is not deallocated, it is simply removed from the + list. The pointer to the image is returned to let the user decide to + deallocate it or not. + Eventually, the image will have to be deallocated with hdrl_image_delete(). + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ILLEGAL_INPUT if pos is negative + - CPL_ERROR_ACCESS_OUT_OF_RANGE if pos is bigger than the number of + images in himlist + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * hdrl_imagelist_unset( + hdrl_imagelist * himlist, + cpl_size pos) +{ + hdrl_image * out; + cpl_size i; + + cpl_ensure(himlist, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(pos < himlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + + /* Get pointer to image to be removed */ + out = himlist->images[pos]; + + /* Move the following images one position towards zero */ + for (i=pos + 1; i < himlist->ni; i++) { + himlist->images[i-1] = himlist->images[i]; + } + + /* Decrement of the size */ + himlist->ni--; + + /* shrink the buffer if its significantly too large */ + if (himlist->ni < himlist->capacity / 2) { + hdrl_imagelist_set_capacity(himlist, himlist->ni / 2); + } + + return out; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Free all memory used by a hdrl_imagelist object including the images + @param himlist The image list or NULL + @return Nothing + @see hdrl_imagelist_empty(), hdrl_imagelist_unwrap() + */ +/*----------------------------------------------------------------------------*/ +void hdrl_imagelist_delete(hdrl_imagelist * himlist) +{ + if (himlist != NULL) { + hdrl_imagelist_empty(himlist); + hdrl_imagelist_unwrap(himlist); + } +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Empty an imagelist and deallocate all its images + @param himlist The image list or NULL + @return Nothing + @see hdrl_imagelist_empty(), hdrl_imagelist_delete() + @note If @em himlist is @c NULL nothing is done and no error is set. + + After the call the image list can be populated again. It must eventually + be deallocated with a call to hdrl_imagelist_delete(). + */ +/*----------------------------------------------------------------------------*/ +void hdrl_imagelist_empty(hdrl_imagelist * himlist) +{ + if (himlist != NULL) { + while (himlist->ni > 0) { /* An iteration may unset more than 1 image */ + + cpl_size i = himlist->ni - 1; + hdrl_image *del = hdrl_imagelist_unset(himlist, i); + + /* If this image was inserted more than once into the list, + the other insertions must be unset without a delete. */ + while (--i >= 0) { + if (himlist->images[i] == del) { + /* This image was inserted more than once in the list */ + del = hdrl_imagelist_unset(himlist, i); + } + } + + hdrl_image_delete(del); + } + } +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Duplicate an image list + @param himlist Source image list. + @return 1 newly allocated image list, or NULL on error. + + Copy an image list into a new image list object. + The returned image list must be deallocated using hdrl_imagelist_delete(). + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +hdrl_imagelist * hdrl_imagelist_duplicate(const hdrl_imagelist * himlist) +{ + hdrl_imagelist * out; + cpl_size i; + + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + + /* Create the new imagelist */ + out = hdrl_imagelist_new(); + + /* Duplicate the images */ + for (i=0; ini; i++) { + hdrl_imagelist_set(out, hdrl_image_duplicate(himlist->images[i]), i); + } + + return out; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Determine if an imagelist contains images of equal size and type + @param himlist The imagelist to check + @return Zero if ok, positive if not consistent and negative on error. + + The function returns 1 if the list is empty. + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +int hdrl_imagelist_is_consistent(const hdrl_imagelist * himlist) +{ + cpl_ensure(himlist != NULL, CPL_ERROR_NULL_INPUT, -1); + if (himlist->ni == 0) return 1; + + /* Check the images */ + // TODO + return 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Dump structural information of images in an imagelist + @param himlist Imagelist to dump + @param stream Output stream, accepts @c stdout or @c stderr + @return CPL_ERROR_NONE or the relevant cpl_error_code on error + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_FILE_IO if a write operation fails + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_dump_structure( + const hdrl_imagelist * himlist, + FILE * stream) +{ + const int msgmin = (int)strlen(HDRL_MSG) - 5; + + int i; + + cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); + + cpl_ensure_code( fprintf(stream, HDRL_MSG, (int)himlist->ni) >= msgmin, + CPL_ERROR_FILE_IO ); + + for (i = 0; i < himlist -> ni; i++) { + const hdrl_image * image = hdrl_imagelist_get_const(himlist, i); + const int imsgmin = (int)strlen(HDRL_IMSG) - 5; + + cpl_ensure_code( fprintf(stream, HDRL_IMSG, i, (int)himlist->ni) >= imsgmin, + CPL_ERROR_FILE_IO ); + + cpl_ensure_code( !hdrl_image_dump_structure(image, stream), + cpl_error_get_code() ); + } + + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Dump pixel values of images in a imagelist + @param himlist Imagelist to dump + @param llx Specifies the window position + @param lly Specifies the window position + @param urx Specifies the window position + @param ury Specifies the window position + @param stream Output stream, accepts @c stdout or @c stderr + @return CPL_ERROR_NONE or the relevant cpl_error_code on error + + Possible cpl_error_code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_FILE_IO if a write operation fails + - CPL_ERROR_ACCESS_OUT_OF_RANGE if the defined window is not in the image + - CPL_ERROR_ILLEGAL_INPUT if the window definition is wrong (e.g llx > urx) + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_dump_window( + const hdrl_imagelist * himlist, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + FILE * stream) +{ + cpl_size i; + + cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); + + for (i = 0; i < himlist -> ni; i++) { + const hdrl_image * image = hdrl_imagelist_get_const(himlist, i); + const int imsgmin = (int)strlen(HDRL_IMSG) - 5; + + cpl_ensure_code( fprintf(stream, HDRL_IMSG, (int)i, + (int)himlist->ni) >= imsgmin, CPL_ERROR_FILE_IO ); + + cpl_ensure_code( !hdrl_image_dump_window(image, llx, lly, urx, ury, + stream), + cpl_error_get_code() ); + } + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Free memory used by a hdrl_imagelist object, except the images + @param himlist The image list or NULL + @return Nothing + @see hdrl_imagelist_empty() + @note The caller must have pointers to all images in the list and is + reponsible for their deallocation. If @em himlist is @c NULL nothing is + done and no error is set. + */ +/*----------------------------------------------------------------------------*/ +void hdrl_imagelist_unwrap(hdrl_imagelist * himlist) +{ + if (himlist != NULL) { + cpl_free(himlist->images); + cpl_free(himlist); + } + return; +} + +typedef struct { + const hdrl_imagelist * hlist; + cpl_size ny; + cpl_size prev_pos; + cpl_size pos; + cpl_size nrows; + cpl_size overlap; + hdrl_imagelist * last_view; +} hdrl_imagelist_row_slices_iter; + +static void * hdrl_imagelist_row_slices_next(hdrl_iter * it) +{ + hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it); + if (s->pos > s->ny) { + return NULL; + } + cpl_size lower = CX_MAX(s->pos - s->overlap, 1); + cpl_size upper = CX_MIN(s->pos + s->nrows + s->overlap - 1, s->ny); + /* const iterator means you cannot modify the data but the created views + * can have a NULL bpm which can be faster e.g. when calling + * cpl_image_new_from_accepted on the view */ + /* TODO could set memory readonly? */ + hdrl_imagelist * view; + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + if (hdrl_iter_check(it, HDRL_ITER_CONST)) { + view = (hdrl_imagelist*) + hdrl_imagelist_const_row_view((hdrl_imagelist*)s->hlist, + lower, upper); + } + else { + view = hdrl_imagelist_row_view((hdrl_imagelist*)s->hlist, + lower, upper); + } + CPL_DIAG_PRAGMA_POP; + + s->prev_pos = s->pos; + s->pos = CX_MIN(s->pos + s->nrows - 1, s->ny) + 1; + if (hdrl_iter_check(it, HDRL_ITER_OWNS_DATA)) { + hdrl_imagelist_delete(s->last_view); + s->last_view = view; + } + return view; +} + +hdrl_il_rowsliceiter_data +hdrl_imagelist_iter_row_slices_get_data(const hdrl_iter * it) +{ + hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it); + + if (s->prev_pos == 1) { + return (hdrl_il_rowsliceiter_data){1., CX_MIN(s->nrows, s->ny)}; + } + else { + return (hdrl_il_rowsliceiter_data){s->overlap + 1, s->overlap + s->pos - s->prev_pos}; + } +} + +static cpl_size hdrl_imagelist_row_slices_length(hdrl_iter * it) +{ + hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it); + return s->ny / s->nrows + ((s->ny % s->nrows) != 0); +} + +static void hdrl_imagelist_iter_delete(void * it) +{ + if (!it) + return; + hdrl_imagelist_row_slices_iter * s = hdrl_iter_state(it); + hdrl_imagelist_delete(s->last_view); + cpl_free(s); +} + +/* TODO, add offset and stride for parallel processing? or imagelist_split? */ +hdrl_iter * hdrl_imagelist_get_iter_row_slices(const hdrl_imagelist * hlist, + cpl_size nrows, + cpl_size overlap, + hdrl_iter_flags flags) +{ + cpl_ensure(hlist, CPL_ERROR_NULL_INPUT, NULL); + /* 0 accepted for now, could mean choosen by function */ + cpl_ensure(nrows >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(hdrl_imagelist_get_size(hlist) > 0, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + hdrl_imagelist_row_slices_iter * state = cpl_malloc(sizeof(*state)); + state->hlist = hlist; + state->ny = hdrl_imagelist_get_size_y(hlist); + state->prev_pos = 1; + state->pos = 1; + state->overlap = CX_MAX(overlap, 0); + state->nrows = CX_MAX(nrows, 1); + state->last_view = NULL; + + return hdrl_iter_init(hdrl_imagelist_row_slices_next, NULL, + hdrl_imagelist_row_slices_length, + hdrl_imagelist_iter_delete, + HDRL_ITER_INPUT | HDRL_ITER_IMAGELIST | flags, + state); +} + + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_io.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_io.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_io.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_io.h 2016-08-11 10:58:18.000000000 +0000 @@ -0,0 +1,96 @@ +/* $Id: hdrl_imagelist_io.h,v 1.8 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.8 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_IMAGELIST_IO_H +#define HDRL_IMAGELIST_IO_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include "hdrl_iter.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + +/* Imagelist constructors */ +hdrl_imagelist * hdrl_imagelist_new(void) CPL_ATTR_ALLOC; +hdrl_imagelist * hdrl_imagelist_create(cpl_imagelist *, + cpl_imagelist *) CPL_ATTR_ALLOC; + +cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *); +cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist * himlist); +cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist * himlist); +hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *, cpl_size); +const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *, cpl_size); +cpl_error_code hdrl_imagelist_set(hdrl_imagelist *, hdrl_image *, cpl_size); +hdrl_image * hdrl_imagelist_unset(hdrl_imagelist *, cpl_size); + +/* Imagelist destructor */ +void hdrl_imagelist_delete(hdrl_imagelist *); +void hdrl_imagelist_empty(hdrl_imagelist *); + +/* Others */ +hdrl_imagelist * hdrl_imagelist_duplicate( + const hdrl_imagelist *) CPL_ATTR_ALLOC; +int hdrl_imagelist_is_consistent(const hdrl_imagelist *) ; + +cpl_error_code hdrl_imagelist_dump_structure(const hdrl_imagelist *, FILE *); +cpl_error_code hdrl_imagelist_dump_window(const hdrl_imagelist *, + cpl_size, cpl_size, cpl_size, cpl_size, FILE *); + + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +typedef struct { + cpl_size ly; + cpl_size uy; +} hdrl_il_rowsliceiter_data; +hdrl_il_rowsliceiter_data hdrl_imagelist_iter_row_slices_get_data(const hdrl_iter *); +hdrl_iter * hdrl_imagelist_get_iter_row_slices(const hdrl_imagelist * hlist, + cpl_size nrows, + cpl_size overlap, + hdrl_iter_flags flags); +#endif + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ +#ifdef HDRL_USE_PRIVATE +void hdrl_imagelist_unwrap(hdrl_imagelist * himlist); +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_view.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_view.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_view.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_view.c 2017-08-23 11:09:43.000000000 +0000 @@ -0,0 +1,472 @@ +/* $Id: hdrl_imagelist_view.c,v 1.8 2013-10-23 09:13:56 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-23 09:13:56 $ + * $Revision: 1.8 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include "hdrl_imagelist_defs.h" +#include "hdrl_imagelist_view.h" +#include "hdrl_image_defs.h" +#include "hdrl_image.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Static Prototypes + -----------------------------------------------------------------------------*/ + +/* destructor unwrapping data and error */ +static void hdrl_image_view_delete(hdrl_image * view) +{ + if (view) { + hdrl_image * himg = (hdrl_image*)view; + cpl_mask_unwrap(cpl_image_unset_bpm(hdrl_image_get_image(himg))); + cpl_mask_unwrap(cpl_image_unset_bpm(hdrl_image_get_error(himg))); + cpl_image_unwrap(hdrl_image_get_image(himg)); + cpl_image_unwrap(hdrl_image_get_error(himg)); + hdrl_image_unwrap(himg); + } +} + +/* destructor unwrapping data and deleting error */ +static void hdrl_image_imgview_delete(hdrl_image * view) +{ + if (view) { + hdrl_image * himg = (hdrl_image*)view; + cpl_mask_unwrap(cpl_image_unset_bpm(hdrl_image_get_image(himg))); + cpl_image_unwrap(hdrl_image_get_image(himg)); + cpl_image_delete(hdrl_image_get_error(himg)); + hdrl_image_unwrap(himg); + } +} + + +/**@{*/ + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a row view of an image + * + * @param himg input image + * @param ly lower row (FITS) + * @param uy upper row (FITS) + * + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_image * +hdrl_image_row_view_create(hdrl_image * himg, + cpl_size ly, + cpl_size uy) +{ + cpl_image * oimg = hdrl_image_get_image(himg); + cpl_image * oerr = hdrl_image_get_error(himg); + const size_t dsz = cpl_type_get_sizeof(cpl_image_get_type(oimg)); + const size_t esz = cpl_type_get_sizeof(cpl_image_get_type(oerr)); + const cpl_size nx = hdrl_image_get_size_x(himg); + char * d = cpl_image_get_data(oimg); + char * e = cpl_image_get_data(oerr); + size_t offset = (ly - 1) * nx; + cpl_size nny = uy - ly + 1; + cpl_image * img = cpl_image_wrap(nx, nny, cpl_image_get_type(oimg), + d + offset * dsz); + cpl_image * err = cpl_image_wrap(nx, nny, cpl_image_get_type(oerr), + e + offset * esz); + + /* we must create a mask in the original in order for views to work */ + cpl_mask * omask = hdrl_image_get_mask(himg); + cpl_mask * mask = cpl_mask_wrap(nx, nny, cpl_mask_get_data(omask) + offset); + cpl_mask_delete(hcpl_image_set_bpm(img, mask)); + omask = cpl_image_get_bpm(himg->error); + mask = cpl_mask_wrap(nx, nny, cpl_mask_get_data(omask) + offset); + cpl_mask_delete(hcpl_image_set_bpm(err, mask)); + + return hdrl_image_wrap(img, err, (hdrl_free*)&hdrl_image_view_delete, + CPL_FALSE); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief create a constant row view of an image + * + * @param himg input image + * @param ly lower row (FITS) + * @param uy upper row (FITS) + * @param uy upper row (FITS) + * @param destructor destructor function pointer + * + * compared to the non-const row version this does not force a bad pixel map + * onto the image which can improve performance a lot when the data is only + * read. + * As bad pixel information cannot be propagated in this case the view must not + * be modified. + */ +/* ---------------------------------------------------------------------------*/ +static const hdrl_image * +hdrl_image_const_row_view_create(const hdrl_image * himg, + cpl_size ly, + cpl_size uy, + hdrl_free * destructor) +{ + const cpl_image * oimg = hdrl_image_get_image_const(himg); + const cpl_image * oerr = hdrl_image_get_error_const(himg); + const size_t dsz = cpl_type_get_sizeof(cpl_image_get_type(oimg)); + const size_t esz = cpl_type_get_sizeof(cpl_image_get_type(oerr)); + const cpl_size nx = hdrl_image_get_size_x(himg); + const char * d = cpl_image_get_data_const(oimg); + const char * e = cpl_image_get_data_const(oerr); + size_t offset = (ly - 1) * nx; + cpl_size nny = uy - ly + 1; + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + + cpl_image * img = cpl_image_wrap(nx, nny, cpl_image_get_type(oimg), + (char*)d + offset * dsz); + cpl_image * err = cpl_image_wrap(nx, nny, cpl_image_get_type(oerr), + (char *)e + offset * esz); + + /* we must create a mask in the original in order for views to work */ + const cpl_mask * omask = hdrl_image_get_mask_const(himg); + if (omask) { + cpl_mask * mask = cpl_mask_wrap(nx, nny, + (cpl_binary*)cpl_mask_get_data_const(omask) + offset); + cpl_mask_delete(hcpl_image_set_bpm(img, mask)); + } + else { + if (cpl_image_get_bpm_const(himg->error) != NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Inconsistent HDRL image, data image has no" + " BPM but error image does"); + cpl_image_unwrap(img); + cpl_image_unwrap(err); + return NULL; + } + } + omask = cpl_image_get_bpm_const(himg->error); + if (omask) { + cpl_mask * mask = cpl_mask_wrap(nx, nny, + (cpl_binary*)cpl_mask_get_data_const(omask) + offset); + cpl_mask_delete(hcpl_image_set_bpm(err, mask)); + } + + CPL_DIAG_PRAGMA_POP; + + return hdrl_image_wrap(img, err, destructor, CPL_FALSE); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create view of subset of image rows in an imagelist + * + * @param hl source imagelist to create view of + * @param ly lower y row to view (FITS convention) + * @param uy upper y row to view (FITS convention) + * + * @return imagelist view + * + * The imagelist will contain the same number of images but they will have + * uy - ly + 1 rows. Modifiying the view will modify the selected rows of the + * original imagelist. + * The view can be deleted with hdrl_imagelist_delete. + * Deleting the original imagelist will invalidate all views, they must not be + * used anymore besides being deleted. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_imagelist * hdrl_imagelist_row_view( + hdrl_imagelist * hl, + cpl_size ly, + cpl_size uy) +{ + cpl_ensure(hl, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(uy >= ly, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + size_t n = hdrl_imagelist_get_size(hl); + cpl_ensure(n > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(uy <= hdrl_imagelist_get_size_y(hl), + CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + + hdrl_imagelist * viewlist = hdrl_imagelist_new(); + for (size_t i = 0; i < n; i++) { + hdrl_image * img = hdrl_imagelist_get(hl, i); + hdrl_image * view = hdrl_image_row_view_create(img, ly, uy); + if (view == NULL) { + hdrl_imagelist_delete(viewlist); + return NULL; + } + hdrl_imagelist_set(viewlist, view, i); + } + + return viewlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create const view of subset of image rows in an imagelist + * + * @param hl source imagelist to create view of + * @param ly lower y row to view (FITS convention) + * @param uy upper y row to view (FITS convention) + * + * @return constant imagelist view + * + * The imagelist will contain the same number of images but they will have + * uy - ly + 1 rows. Modifiying the view will modify the selected rows of the + * original imagelist. + * The view can be deleted with hdrl_imagelist_delete. + * Deleting the original imagelist will invalidate all views, they must not be + * used anymore besides being deleted. + * The view must not be modified as bad pixel information cannot be propagated + * to the original image if it did not have a bad pixel map to begin with. + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_imagelist * hdrl_imagelist_const_row_view( + const hdrl_imagelist * hl, + cpl_size ly, + cpl_size uy) +{ + cpl_ensure(hl, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(uy >= ly, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + size_t n = hdrl_imagelist_get_size(hl); + cpl_ensure(n > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(uy <= hdrl_imagelist_get_size_y(hl), + CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + + hdrl_imagelist * viewlist = hdrl_imagelist_new(); + for (size_t i = 0; i < n; i++) { + hdrl_image * img = hdrl_imagelist_get(hl, i); + const hdrl_image * view = hdrl_image_const_row_view_create(img, ly, uy, + (hdrl_free*)&hdrl_image_view_delete); + if (view == NULL) { + hdrl_imagelist_delete(viewlist); + return NULL; + } + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + hdrl_imagelist_set(viewlist, (hdrl_image*)view, i); + CPL_DIAG_PRAGMA_POP; + } + + return viewlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create view of subset of images in an imagelist + * + * @param hl source imagelist to create view of + * @param lz lower image index to view, starting from 0 + * @param uz upper bound exclusive + * + * @return imagelist view + * + * The imagelist will contain uz - lz images of the same size as the original + * imagelist. Modifiying the view is not allowed + * The view must be deleted with hdrl_imagelist_delete. + * Deleting the original imagelist will invalidate all views, they must not be + * used anymore besides being deleted. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_imagelist * hdrl_imagelist_image_view( + hdrl_imagelist * hl, + cpl_size lz, + cpl_size uz) +{ + cpl_ensure(hl, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(uz > lz, CPL_ERROR_ILLEGAL_INPUT, NULL); + size_t n = hdrl_imagelist_get_size(hl); + cpl_ensure(lz >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(uz <= (cpl_size)n, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + + hdrl_imagelist * viewlist = hdrl_imagelist_new(); + for (size_t i = lz; i < (size_t)uz; i++) { + hdrl_image * img = hdrl_imagelist_get(hl, i); + size_t ny = hdrl_image_get_size_y(img); + hdrl_image * view = hdrl_image_row_view_create(img, 1, ny); + if (view == NULL) { + hdrl_imagelist_delete(viewlist); + return NULL; + } + hdrl_imagelist_set(viewlist, view, i - lz); + } + + return viewlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create const view of subset of image rows in cpl imagelists + * + * @param imglist source imagelist to create view of + * @param errlist source error imagelist to create view of, may be NULL + * @param ly lower y row to view (FITS convention) + * @param uy upper y row to view (FITS convention) + * + * @return constant imagelist view + * + * The imagelist will contain the same number of images but they will have + * uy - ly + 1 rows. Modifiying the view is not allowed + * The view can be deleted with hdrl_imagelist_delete. + * Deleting the original imagelist will invalidate all views, they must not be + * used anymore besides being deleted. + * The images and errors in the lists must contain equal bad pixel maps. + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_imagelist * hdrl_imagelist_const_cpl_row_view( + const cpl_imagelist * imglist, + const cpl_imagelist * errlist, + cpl_size ly, + cpl_size uy) +{ + cpl_ensure(imglist, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(uy >= ly, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + size_t n = cpl_imagelist_get_size(imglist); + cpl_ensure(n > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(uy <= cpl_image_get_size_y(cpl_imagelist_get_const(imglist, 0)), + CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(errlist == NULL || n <= (size_t)cpl_imagelist_get_size(errlist), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + hdrl_imagelist * viewlist = hdrl_imagelist_new(); + if (errlist) { + const cpl_image * img = cpl_imagelist_get_const(imglist, 0); + const cpl_image * err = cpl_imagelist_get_const(errlist, 0); + + if (cpl_image_get_type(img) != HDRL_TYPE_DATA || + cpl_image_get_type(err) != HDRL_TYPE_ERROR) { + hdrl_imagelist_delete(viewlist); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Can only view image pairs with type " + "HDRL_TYPE_DATA and HDRL_TYPE_ERROR"); + return NULL; + } + if (cpl_image_get_size_x(img) != cpl_image_get_size_x(err) || + cpl_image_get_size_y(img) != cpl_image_get_size_y(err)) { + hdrl_imagelist_delete(viewlist); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Image and Error not consistent"); + return NULL; + } + for (size_t i = 0; i < n; i++) { + img = cpl_imagelist_get_const(imglist, i); + err = cpl_imagelist_get_const(errlist, i); + if ((cpl_image_get_bpm_const(img) && !cpl_image_get_bpm_const(err)) || + (!cpl_image_get_bpm_const(img) && cpl_image_get_bpm_const(err))) { + hdrl_imagelist_delete(viewlist); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Image and error bad pixel mask " + "not equal"); + return NULL; + } + if (cpl_image_get_bpm_const(img) && cpl_image_get_bpm_const(err)) { + const cpl_binary * dibpm = + cpl_mask_get_data_const(cpl_image_get_bpm_const(img)); + const cpl_binary * debpm = + cpl_mask_get_data_const(cpl_image_get_bpm_const(err)); + if (memcmp(dibpm, debpm, hdrl_get_image_npix(img)) != 0) { + hdrl_imagelist_delete(viewlist); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Image and error bad pixel mask " + "not equal"); + return NULL; + } + } + /* TODO could wrap directly */ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + hdrl_image * himg = hdrl_image_wrap((cpl_image*)img, (cpl_image*)err, + (hdrl_free*)&hdrl_image_view_delete, + CPL_FALSE); + const hdrl_image * view = + hdrl_image_const_row_view_create(himg, ly, uy, + (hdrl_free*)&hdrl_image_view_delete); + if (view == NULL) { + hdrl_imagelist_delete(viewlist); + return NULL; + } + hdrl_image_unwrap(himg); + hdrl_imagelist_set(viewlist, (hdrl_image*)view, i); + CPL_DIAG_PRAGMA_POP; + } + } + else { + const cpl_image * img = cpl_imagelist_get_const(imglist, 0); + if (cpl_image_get_type(img) != HDRL_TYPE_DATA) { + hdrl_imagelist_delete(viewlist); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Can only view images with type " + "HDRL_TYPE_DATA"); + return NULL; + } + for (size_t i = 0; i < n; i++) { + img = cpl_imagelist_get_const(imglist, i); + /* can't share a single image as it needs the same bpm as img + * TODO the bpm of img could probably be shared */ + cpl_image * err = cpl_image_new(cpl_image_get_size_x(img), + cpl_image_get_size_y(img), + HDRL_TYPE_ERROR); + if (cpl_image_get_bpm_const(img)) { + cpl_image_reject_from_mask(err, cpl_image_get_bpm_const(img)); + } + /* TODO could wrap directly */ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + hdrl_image * himg = hdrl_image_wrap((cpl_image*)img, err, + (hdrl_free*)&hdrl_image_imgview_delete, + CPL_FALSE); + const hdrl_image * view = hdrl_image_const_row_view_create(himg, ly, uy, + (hdrl_free*)&hdrl_image_imgview_delete); + if (view == NULL) { + hdrl_imagelist_delete(viewlist); + return NULL; + } + hdrl_image_unwrap(himg); + cpl_mask_unwrap(cpl_image_unset_bpm(err)); + cpl_image_unwrap(err); + hdrl_imagelist_set(viewlist, (hdrl_image*)view, i); + CPL_DIAG_PRAGMA_POP; + } + } + + return viewlist; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_view.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_view.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_imagelist_view.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_imagelist_view.h 2017-08-25 12:52:36.000000000 +0000 @@ -0,0 +1,61 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifndef HDRL_IMAGELIST_VIEW_H +#define HDRL_IMAGELIST_VIEW_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE + +hdrl_imagelist * hdrl_imagelist_row_view( + hdrl_imagelist * hl, + cpl_size ly, + cpl_size uy); + +const hdrl_imagelist * hdrl_imagelist_const_row_view( + const hdrl_imagelist * hl, + cpl_size ly, + cpl_size uy); + +hdrl_imagelist * hdrl_imagelist_image_view( + hdrl_imagelist * hl, + cpl_size lz, + cpl_size uz); + +const hdrl_imagelist * hdrl_imagelist_const_cpl_row_view( + const cpl_imagelist * imglist, + const cpl_imagelist * errlist, + cpl_size ly, + cpl_size uy); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image_math.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image_math.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image_math.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image_math.c 2017-08-23 11:09:43.000000000 +0000 @@ -0,0 +1,651 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_elemop.h" +#include "hdrl_image.h" +#include "hdrl_collapse.h" + +#include +#include + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Add two images, store the result in the first image. + @param self first operand. + @param other second operand. + @return the cpl-error-code or CPL_ERROR_NONE + + The first input image is modified to contain the result of the operation. + + The bad pixel map of the first image becomes the union of the bad pixel + maps of the input images. + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_INCOMPATIBLE_INPUT if the input images have different sizes + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_add_image(hdrl_image * self, const hdrl_image * other) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_add_image(hdrl_image_get_image(self), hdrl_image_get_error(self), + hdrl_image_get_image_const(other), + hdrl_image_get_error_const(other)); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Add two images. + @param self first operand + @param other second operand + @return 1 newly allocated image or NULL on error + + Creates a new image, being the result of the operation, and returns it to + the caller. The returned image must be deallocated using hdrl_image_delete(). + + The bad pixels map of the result is the union of the bad pixels maps of + the input images. + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_INCOMPATIBLE_INPUT if the input images have different sizes + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_add_image_create(const hdrl_image * self, const hdrl_image * other) +{ + hdrl_image * n = hdrl_image_duplicate(self); + + if (hdrl_image_add_image(n, other)) { + hdrl_image_delete(n); + return NULL; + } + + return n; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Elementwise addition of a scalar to an image + @param self Image to be modified in place. + @param value Number to add + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + + Modifies the image by adding a number to each of its pixels with error + propagation. + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_add_scalar(hdrl_image * self, hdrl_value value) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_add_scalar(hdrl_image_get_image(self), + hdrl_image_get_error(self), + value.data, value.error); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Subtract two images, store the result in the first image. + @param self first operand. + @param other second operand. + @return the cpl-error-code or CPL_ERROR_NONE + @see hdrl_image_add_image() + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_sub_image(hdrl_image * self, const hdrl_image * other) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_sub_image(hdrl_image_get_image(self), hdrl_image_get_error(self), + hdrl_image_get_image_const(other), + hdrl_image_get_error_const(other)); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Subtract two images. + @param self first operand + @param other second operand + @return 1 newly allocated image or NULL on error + @see hdrl_image_add_image_create() + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_sub_image_create(const hdrl_image * self, const hdrl_image * other) +{ + hdrl_image * n = hdrl_image_duplicate(self); + + if (hdrl_image_sub_image(n, other)) { + hdrl_image_delete(n); + return NULL; + } + + return n; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Elementwise subtraction of a scalar from an image + @param self Image to be modified in place. + @param value Number to subtract + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + @see hdrl_image_add_scalar() + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_sub_scalar(hdrl_image * self, hdrl_value value) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_sub_scalar(hdrl_image_get_image(self), + hdrl_image_get_error(self), + value.data, value.error); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Multiply two images, store the result in the first image. + @param self first operand. + @param other second operand. + @return the cpl-error-code or CPL_ERROR_NONE + @see hdrl_image_add_image() + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_mul_image(hdrl_image * self, const hdrl_image * other) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_mul_image(hdrl_image_get_image(self), hdrl_image_get_error(self), + hdrl_image_get_image_const(other), + hdrl_image_get_error_const(other)); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Multiply two images. + @param self first operand + @param other second operand + @return 1 newly allocated image or NULL on error + @see hdrl_image_add_image_create() + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_mul_image_create(const hdrl_image * self, const hdrl_image * other) +{ + hdrl_image * n = hdrl_image_duplicate(self); + + if (hdrl_image_mul_image(n, other)) { + hdrl_image_delete(n); + return NULL; + } + + return n; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Elementwise multiplication of an image with a scalar + @param self Image to be modified in place. + @param value Number to multiply with + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + @see hdrl_image_add_scalar() + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_mul_scalar(hdrl_image * self, hdrl_value value) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_mul_scalar(hdrl_image_get_image(self), + hdrl_image_get_error(self), + value.data, value.error); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Divide two images, store the result in the first image. + @param self first operand + @param other second operand + @return the cpl-error-code or CPL_ERROR_NONE + @see hdrl_image_add_image() + + @note The result of division with a zero-valued pixel is marked as a bad + pixel. Additionally, the value and the error are set to NAN + + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_INCOMPATIBLE_INPUT if the input images have different sizes + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_div_image(hdrl_image * self, const hdrl_image * other) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_div_image(hdrl_image_get_image(self), hdrl_image_get_error(self), + hdrl_image_get_image_const(other), + hdrl_image_get_error_const(other)); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Divide two images and return the resulting image + @param self first operand + @param other second operand + @return 1 newly allocated image or NULL on error + @see hdrl_image_add_image_create() + + @note The result of division with a zero-valued pixel is marked as a bad + pixel. Additionally, the value and the error are set to NAN + + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_INCOMPATIBLE_INPUT if the input images have different sizes + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_div_image_create(const hdrl_image * self, const hdrl_image * other) +{ + hdrl_image * n = hdrl_image_duplicate(self); + + if (hdrl_image_div_image(n, other)) { + hdrl_image_delete(n); + return NULL; + } + + return n; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Elementwise division of an image with a scalar + @param self Image to be modified in place. + @param value Non-zero number to divide with + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + @see cpl_image_add_image_scalar() + + Possible cpl-error-code set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_div_scalar(hdrl_image * self, hdrl_value value) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_div_scalar(hdrl_image_get_image(self), + hdrl_image_get_error(self), + value.data, value.error); +} +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief Collapse the image +\todo copy from overscan + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_image_collapse(hdrl_collapse_imagelist_to_vector_t * red, + const hdrl_image * self, + hdrl_data_t * result, hdrl_error_t * error, + int * contrib, void * eout) +{ + cpl_imagelist * ld = cpl_imagelist_new(); + cpl_imagelist * le = cpl_imagelist_new(); + cpl_vector * od = NULL, * oe = NULL; + cpl_array * oc = NULL; + cpl_error_code fail; + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + cpl_imagelist_set(ld, hdrl_image_get_image((hdrl_image * )self), 0); + cpl_imagelist_set(le, hdrl_image_get_error((hdrl_image * )self), 0); + CPL_DIAG_PRAGMA_POP; + + fail = hdrl_collapse_imagelist_to_vector_call(red, ld, le, &od, &oe, &oc, + eout); + cpl_imagelist_unwrap(ld); + cpl_imagelist_unwrap(le); + + if (fail == CPL_ERROR_NONE) { + if (result) { + *result = cpl_vector_get(od, 0); + } + if (error) { + *error = cpl_vector_get(oe, 0); + } + if (contrib) { + *contrib = cpl_array_get_int(oc, 0, NULL); + } + } + else { + if (result) { + *result = NAN; + } + if (error) { + *error = NAN; + } + } + + cpl_vector_delete(od); + cpl_vector_delete(oe); + cpl_array_delete(oc); + + return fail; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes mean pixel value and associated error of an image. + @param self input image + @return mean and its error in a hdrl_value structure + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_mean(const hdrl_image * self) +{ + hdrl_collapse_imagelist_to_vector_t * red = + hdrl_collapse_imagelist_to_vector_mean(); + hdrl_value res; + hdrl_image_collapse(red, self, &res.data, &res.error, NULL, NULL); + hdrl_collapse_imagelist_to_vector_delete(red); + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the sigma-clipped mean and associated error of an image. + @param self input image + @param kappa_low low sigma bound + @param kappa_high high sigma bound + @param niter maximum number of clipping iterators + @return clipped mean and its error in a hdrl_value structure + @see hdrl_kappa_sigma_clip() for the algorithm + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_sigclip_mean(const hdrl_image * self, double kappa_low, + double kappa_high, int niter) +{ + hdrl_collapse_imagelist_to_vector_t * red = + hdrl_collapse_imagelist_to_vector_sigclip(kappa_low, kappa_high, niter); + hdrl_value res; + hdrl_image_collapse(red, self, &res.data, &res.error, NULL, NULL); + hdrl_collapse_imagelist_to_vector_delete(red); + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the minmax rejected mean and the associated error of an image. + @param self input image + @param nlow number of low pixels to reject + @param nhigh number of high pixels to reject + @return minmax rejected mean and its error in a hdrl_value structure + @see hdrl_minmax_clip() for the algorithm + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_minmax_mean(const hdrl_image * self, double nlow, + double nhigh) +{ + hdrl_collapse_imagelist_to_vector_t * red = + hdrl_collapse_imagelist_to_vector_minmax(nlow, nhigh); + hdrl_value res; + hdrl_image_collapse(red, self, &res.data, &res.error, NULL, NULL); + hdrl_collapse_imagelist_to_vector_delete(red); + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the median and associated error of an image. + @param self input image + @return median and its error in a hdrl_value structure + + This function computes the median and the associated error of the image. For + the error propagation the error is scaled by the sqrt of the statistical + efficiency of the median on normal distributed data which is + \f$ \frac{\pi}{ 2 } \f$ + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_median(const hdrl_image * self) +{ + hdrl_collapse_imagelist_to_vector_t * red = + hdrl_collapse_imagelist_to_vector_median(); + hdrl_value res; + hdrl_image_collapse(red, self, &res.data, &res.error, NULL, NULL); + hdrl_collapse_imagelist_to_vector_delete(red); + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the weighted mean and associated error of an image. + @param self input image + @return weighted mean and its error in a hdrl_value structure + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_weighted_mean(const hdrl_image * self) +{ + hdrl_collapse_imagelist_to_vector_t * red = + hdrl_collapse_imagelist_to_vector_weighted_mean(); + hdrl_value res; + hdrl_image_collapse(red, self, &res.data, &res.error, NULL, NULL); + hdrl_collapse_imagelist_to_vector_delete(red); + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the standard deviation of the data of an image + @param self input image + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + @see cpl_image_get_stdev + */ +/*----------------------------------------------------------------------------*/ +double +hdrl_image_get_stdev(const hdrl_image * self) +{ + return cpl_image_get_stdev(hdrl_image_get_image_const(self)); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the sum of all pixel values and the associated error of an + image. + @param self input image + @return sum and its error in a hdrl_value structure + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_sum(const hdrl_image * self) +{ + int contrib; + hdrl_value res; + hdrl_collapse_imagelist_to_vector_t * red = + hdrl_collapse_imagelist_to_vector_mean(); + cpl_error_code err = hdrl_image_collapse(red, self, &res.data, &res.error, + &contrib, NULL); + if (err == CPL_ERROR_NONE) { + res.data *= contrib; + res.error *= contrib; + } + else { + res.data = NAN; + res.error = NAN; + } + hdrl_collapse_imagelist_to_vector_delete(red); + return res; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the sum of all pixel values and the error of a squared + image. + @param self input image + @return squared sum and its error in a hdrl_value structure + */ +/*----------------------------------------------------------------------------*/ +hdrl_value +hdrl_image_get_sqsum(const hdrl_image * self) +{ + /* TODO could be a specialized collapse method for better performance */ + hdrl_image * tmp = hdrl_image_pow_scalar_create(self, (hdrl_value){2, 0.}); + hdrl_value res = hdrl_image_get_sum(tmp); + hdrl_image_delete(tmp); + return res; +} + + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the power of an image by a scalar + @param self input image + @param exponent exponent of the power + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_pow_scalar(hdrl_image * self, const hdrl_value exponent) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_pow_scalar(hdrl_image_get_image(self), + hdrl_image_get_error(self), + exponent.data, exponent.error); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the power of an image by a scalar creating a new image + @param self input image + @param exponent exponent of the power + @return new image containing the powered data or NULL on error + @see hdrl_image_pow_scalar + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_pow_scalar_create(const hdrl_image * self, const hdrl_value exponent) +{ + hdrl_image * n = hdrl_image_duplicate(self); + + if (hdrl_image_pow_scalar(n, exponent)) { + hdrl_image_delete(n); + return NULL; + } + + return n; +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the exponential of an image by a scalar + @param self input image + @param base base of the power + @return CPL_ERROR_NONE or the relevant the cpl-error-code on error + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +hdrl_image_exp_scalar(hdrl_image * self, const hdrl_value base) +{ + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + /* size check included in elemop */ + return hdrl_elemop_image_exp_scalar(hdrl_image_get_image(self), + hdrl_image_get_error(self), + base.data, base.error); +} + +/*----------------------------------------------------------------------------*/ +/** + @ingroup hdrl_image + @brief computes the exponential of an image by a scalar creating a new image + @param self input image + @param base base of the power + @return new image containing the powered data or NULL on error + @see hdrl_image_pow_scalar + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * +hdrl_image_exp_scalar_create(const hdrl_image * self, const hdrl_value base) +{ + hdrl_image * n = hdrl_image_duplicate(self); + + if (hdrl_image_exp_scalar(n, base)) { + hdrl_image_delete(n); + return NULL; + } + + return n; +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image_math.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image_math.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_image_math.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_image_math.h 2017-08-28 13:24:21.000000000 +0000 @@ -0,0 +1,72 @@ +/* $Id: hdrl_image_math.h,v 1.6 2013-10-17 15:44:14 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-17 15:44:14 $ + * $Revision: 1.6 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_IMAGE_MATH_H +#define HDRL_IMAGE_MATH_H +#include "hdrl_image.h" +#include "hdrl_types.h" +#include + +CPL_BEGIN_DECLS + +hdrl_value hdrl_image_get_sqsum(const hdrl_image *self); +hdrl_value hdrl_image_get_sum(const hdrl_image *self); +double hdrl_image_get_stdev(const hdrl_image *self); +hdrl_value hdrl_image_get_median(const hdrl_image *self); +hdrl_value hdrl_image_get_mean(const hdrl_image *self); +hdrl_value hdrl_image_get_weighted_mean(const hdrl_image *self); +hdrl_value hdrl_image_get_sigclip_mean(const hdrl_image * self, + double kappa_low, double kappa_high, + int niter); +hdrl_value hdrl_image_get_minmax_mean(const hdrl_image * self, double nlow, + double nhigh); + +hdrl_image * hdrl_image_div_image_create(const hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_div_image( hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_div_scalar( hdrl_image *self, hdrl_value value); + +hdrl_image * hdrl_image_mul_image_create(const hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_mul_image( hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_mul_scalar( hdrl_image *self, hdrl_value value); + +hdrl_image * hdrl_image_sub_image_create(const hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_sub_image( hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_sub_scalar( hdrl_image *self, hdrl_value value); + +hdrl_image * hdrl_image_add_image_create(const hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_add_image( hdrl_image *self, const hdrl_image *other); +cpl_error_code hdrl_image_add_scalar( hdrl_image *self, hdrl_value value); + +hdrl_image * hdrl_image_pow_scalar_create(const hdrl_image *self, const hdrl_value exponent); +cpl_error_code hdrl_image_pow_scalar( hdrl_image *self, const hdrl_value exponent); + +hdrl_image * hdrl_image_exp_scalar_create(const hdrl_image *self, const hdrl_value base); +cpl_error_code hdrl_image_exp_scalar( hdrl_image *self, const hdrl_value base); + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_iter.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_iter.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_iter.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_iter.c 2017-09-20 10:02:45.000000000 +0000 @@ -0,0 +1,219 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_iter.h" +#include "hdrl_types.h" +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_iter Iterator + + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/** @cond EXPERIMENTAL */ + +/** @cond PRIVATE */ + +struct _hdrl_iter_ { + /* returns next value in sequence iterated on (e.g. image, imagelist) */ + hdrl_iter_next_f * next; + /* optional, resets the iteration to the first element */ + hdrl_iter_reset_f * reset; + /* optional, returns length of the iterator */ + hdrl_iter_length_f * length; + /* state destructor */ + hdrl_free * destructor; + /* iterator flags */ + hdrl_iter_flags flags; + /* state structure of iterator */ + void * state; +}; + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief initialize an iterator + * + * @param next function pointer returning next value in sequence iterated on + * @param reset function pointer or NULL, reseting iteration to first element + * @param length function pointer or NULL, returning length of sequence + * @param flags flags of iterator + * @param state state structure of iterator + * + * An iterator iterates on a sequence of data (e.g. imagelist, files on + * disk, ...) and returns an element of that sequence on each call to the + * next function. When the sequence is exhausted it returns NULL. + * + * Each member function is called with the iterator as first argument, from + * this the state can be received with hdrl_iter_state(it), the state is a + * user defined structure typically containing the current position in the + * sequence. + * + * The iterator type defines what kind of data is returned by each next call. + * The options are: + * HDRL_ITER_INPUT: data provided is input data to be processed, it will be + freed by the caller of next. (FIXME: add flag to not free?) + * HDRL_ITER_OUTPUT: data is an empty output buffer for the caller of next + * to place its results into. Its memory is managed by the + * iterator. + * HDRL_ITER_IMAGE: the return of next is a cpl_image + * HDRL_ITER_IMAGELIST: the return of next is a cpl_imagelist + */ +/* ---------------------------------------------------------------------------*/ +hdrl_iter * +hdrl_iter_init(hdrl_iter_next_f * next, + hdrl_iter_reset_f * reset, + hdrl_iter_length_f * length, + hdrl_free * destructor, + hdrl_iter_flags flags, + void * state) +{ + /* exactly one each set */ + hdrl_iter_flags inout = (HDRL_ITER_INPUT | HDRL_ITER_OUTPUT); + hdrl_iter_flags retflags = (HDRL_ITER_IMAGE | HDRL_ITER_IMAGELIST); + cpl_ensure(((flags & inout) == HDRL_ITER_INPUT) || + ((flags & inout) == HDRL_ITER_OUTPUT), + CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(((flags & retflags) == HDRL_ITER_IMAGE) || + ((flags & retflags) == HDRL_ITER_IMAGELIST), + CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(state, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(next, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(flags != 0, CPL_ERROR_NULL_INPUT, NULL); + hdrl_iter * it = cpl_malloc(sizeof(*it)); + it->next = next; + it->length = length; + it->reset = reset; + it->destructor = destructor ? destructor : &cpl_free; + it->flags = flags; + it->state = state; + return it; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief return the state structure of the iterator + * @param it iterator + * @return state structure + */ +/* ---------------------------------------------------------------------------*/ +void * hdrl_iter_state(const hdrl_iter * it) +{ + return it->state; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief check if iterator has a certain flag + * @param it iterator + * @param flags flag to check + * @return true or false depending wheter iterator has flags set + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_iter_check(hdrl_iter * it, hdrl_iter_flags flags) +{ + return (it->flags & flags) == flags; +} + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete iterator structure + * @param it iterator + * @note will not delete the state structure, typically this is called in the + * user iterator destructor + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_iter_delete(hdrl_iter * it) +{ + if (it) { + if (it->destructor) { + it->destructor(it); + } + cpl_free(it); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return next element in sequence or NULL if done + * @param it iterator + * @return object or NULL, type of object depends on iterator type + */ +/* ---------------------------------------------------------------------------*/ +void * hdrl_iter_next(hdrl_iter * it) +{ + return it->next(it); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief reset iterator to beginning of sequence + * @param it iterator + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_iter_reset(hdrl_iter * it) +{ + if (it->reset == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, + "Iterator has no reset method"); + } else { + it->reset(it); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return length of sequence + * @param it iterator + * @return length of sequence + */ +/* ---------------------------------------------------------------------------*/ +cpl_size hdrl_iter_length(hdrl_iter * it) +{ + if (it->length == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, + "Iterator has no length method"); + return -1; + } + return it->length(it); +} + +/**@}*/ + +/** @endcond */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_iter.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_iter.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_iter.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_iter.h 2017-08-25 12:33:59.000000000 +0000 @@ -0,0 +1,100 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_ITER_H +#define HDRL_ITER_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +/** @cond EXPERIMENTAL */ + +typedef struct _hdrl_iter_ hdrl_iter; +typedef enum { + /* next returns a imagelist */ + HDRL_ITER_IMAGELIST = 1<<0, + /* next returns a image */ + HDRL_ITER_IMAGE = 1<<1, + /* next returns an initialized input buffer */ + HDRL_ITER_INPUT = 1<<2, + /* next returns an uninitialized output buffer */ + HDRL_ITER_OUTPUT = 1<<3, + /* iterator owns its next output and will deallocate it */ + HDRL_ITER_OWNS_DATA = 1<<4, + /* iterating over const data, views make have NULL bpms */ + HDRL_ITER_CONST = 1<<5, + /* multi-iterator may return empty results */ + HDRL_ITER_ALLOW_EMPTY = 1<<6, +} hdrl_iter_flags; + +void * hdrl_iter_next(hdrl_iter * it); +cpl_size hdrl_iter_length(hdrl_iter * it); +void hdrl_iter_reset(hdrl_iter * it); +void hdrl_iter_delete(hdrl_iter * it); + +/** @endcond */ +#endif + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl +------------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE +/** @cond PRIVATE */ + +typedef void * (hdrl_iter_next_f)(hdrl_iter * it); +typedef void (hdrl_iter_reset_f)(hdrl_iter * it); +typedef cpl_size (hdrl_iter_length_f)(hdrl_iter * it); + +hdrl_iter * +hdrl_iter_init(hdrl_iter_next_f * next, + hdrl_iter_reset_f * reset, + hdrl_iter_length_f * length, + hdrl_free * destructor, + hdrl_iter_flags flags, + void * state); + +void * hdrl_iter_state(const hdrl_iter * it); + +cpl_boolean hdrl_iter_check(hdrl_iter * it, hdrl_iter_flags flags); + +/** @endcond */ +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_lacosmics.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_lacosmics.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_lacosmics.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_lacosmics.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,730 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +/* + * Originated from xshoop/xsh/xsh_remove_crh_single.c r154351 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/* This should be defined in a more clever way, a parameter for example */ +#define REGDEBUG_FULL 0 + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_lacosmics.h" +#include "hdrl_utils.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_lacosmic Bad Pixel Mask via edge detection + @ingroup hdrl_bpm + + @brief + Algorithm to detect bad-pixels and cosmic-rays hits on a single image like + e.g. science frames + +This routine determines bad-pixels on a single image via edge detection +following the algorithm (LA-Cosmic) describe in van Dokkum, +PASP,113,2001,p1420-27. The HDRL implementation does not use use error model +as described in the paper but the error image passed to the function. Moreover +we do several iterations and replace the detected bad pixels in each iteration +by the information of the surrounding pixels. + +The calculation is performed by calling the top-level function +hdrl_lacosmic_edgedetect() and the parameters passed to this function can be +created by calling hdrl_lacosmic_parameter_create(). + + + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + LaCosmic parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + double sigma_lim ; + double f_lim ; + int max_iter ; +} hdrl_lacosmic_parameter; + +/* parameter type */ +static hdrl_parameter_typeobj hdrl_lacosmic_parameter_type = { + HDRL_PARAMETER_LACOSMIC, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_lacosmic_parameter), /* obj_size */ +}; + +/*----------------------------------------------------------------------------*/ +/** + @brief Creates LaCosmic parameters object + @param sigma_lim Limiting sigma for detection on the sampling image + @param f_lim Limiting f factor for detection on the modified Laplacian + image. + @param max_iter Maximum number of iterations + @return The LaCosmic parameters object. It needs to be deallocated with + hdrl_parameter_delete() + @see hdrl_lacosmic_edgedetect() + + @note For the algorithm see the paper of + van Dokkum, + PASP,113,2001,p1420-27. + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_lacosmic_parameter_create( + double sigma_lim, + double f_lim, + int max_iter) +{ + hdrl_lacosmic_parameter * p = (hdrl_lacosmic_parameter *) + hdrl_parameter_new(&hdrl_lacosmic_parameter_type); + p->sigma_lim = sigma_lim ; + p->f_lim = f_lim ; + p->max_iter = max_iter ; + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Verify basic correctness of the LaCosmic parameters + @param param LaCosmic parameters + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_lacosmic_parameter_verify( + const hdrl_parameter * param) +{ + const hdrl_lacosmic_parameter * param_loc = (const hdrl_lacosmic_parameter *)param; + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_lacosmic_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected LaCosmic parameter") ; + + cpl_error_ensure(param_loc->max_iter > 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "max_iter must be >0"); + cpl_error_ensure(param_loc->f_lim >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "f_lim must be >=0"); + cpl_error_ensure(param_loc->sigma_lim >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "sigma_lim must be >=0"); + + return CPL_ERROR_NONE ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is an LaCosmic parameter + @param self The parameter to check + @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_lacosmic_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_lacosmic_parameter_type); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the sigma_lim in the LaCosmic parameter + @param p The LaCosmic parameter + @return The sigma_lim value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_lacosmic_parameter_get_sigma_lim( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return ((const hdrl_lacosmic_parameter *)p)->sigma_lim; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the f_lim in the LaCosmic parameter + @param p The LaCosmic parameter + @return The f_lim value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_lacosmic_parameter_get_f_lim( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return ((const hdrl_lacosmic_parameter *)p)->f_lim; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the max_iter in the LaCosmic parameter + @param p The LaCosmic parameter + @return The max_iter value + */ +/*----------------------------------------------------------------------------*/ +int hdrl_lacosmic_parameter_get_max_iter( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1); + return ((const hdrl_lacosmic_parameter *)p)->max_iter; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Create parameter list for the LaCosmic computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param defaults default values + + @return parameterlist controlling the LaCosmic algorithm + + base_context.prefix.sigma_lim + base_context.prefix.f_lim + base_context.prefix.max_iter + The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_lacosmic_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *defaults) +{ + cpl_ensure(prefix && base_context && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_lacosmic_parameter_check(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist *parlist = cpl_parameterlist_new(); + + double sigma_lim_def = hdrl_lacosmic_parameter_get_sigma_lim(defaults) ; + double f_lim_def = hdrl_lacosmic_parameter_get_f_lim(defaults) ; + int max_iter_def = hdrl_lacosmic_parameter_get_max_iter(defaults) ; + + /* --prefix.sigma_lim */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "sigma_lim", base_context, + "Poisson fluctuation threshold to flag cosmics" + "(see van Dokkum, PASP,113,2001,p1420-27).", + CPL_TYPE_DOUBLE, sigma_lim_def) ; + + /* --prefix.f_lim */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "f_lim", base_context, + "Minimum contrast between the Laplacian image and the fine " + "structure image that a point must have to be flagged as cosmics" + , CPL_TYPE_DOUBLE, f_lim_def) ; + + /* --prefix.max_iter */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "max_iter", base_context, + "Maximum number of alghoritm iterations", CPL_TYPE_INT, max_iter_def) ; + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Parse parameterlist to create input parameters for the LaCosmic + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return Input parameters for the LaCosmic Computation + + Reads a parameterlist in order to create LaCosmic parameters. + Expects a parameterlist containing: + - prefix.sigma_lim + - prefix.f_lim + - prefix.max_iter + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_lacosmic_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name ; + const cpl_parameter * par; + double sigma_lim, f_lim; + int max_iter; + + /* --sigma_lim */ + name = hdrl_join_string(".", 2, prefix, "sigma_lim"); + par=cpl_parameterlist_find_const(parlist, name); + sigma_lim = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --f_lim */ + name = hdrl_join_string(".", 2, prefix, "f_lim"); + par=cpl_parameterlist_find_const(parlist, name); + f_lim = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --max_iter */ + name = hdrl_join_string(".", 2, prefix, "max_iter"); + par=cpl_parameterlist_find_const(parlist, name); + max_iter = cpl_parameter_get_int(par); + cpl_free(name) ; + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist with prefix %s", prefix); + return NULL; + } else { + return hdrl_lacosmic_parameter_create(sigma_lim, f_lim, max_iter) ; + } +} + + + +/*----------------------------------------------------------------------------*/ +/** + @brief Detect bad-pixels / cosmic-rays on a single image. + @param ima_in The input image + @param params LaCosmic computation parameters + + @return Mask where all detected bad-pixels/cosmics-rays are marked + as bad or NULL on error + +This routine determines bad-pixels on a single image via edge +detection following the algorithm (LA-Cosmic) describe in van Dokkum, +PASP,113,2001,p1420-27. It was originally developed to detect cosmic +ray hits but can also be used in the more general context of detecting +bad pixels. The HDRL implementation does not use use error model as +described in the paper but the error image passed to the +function. Moreover we do several iterations with \e max_iter defining +an upper limit for the number of iterations, i.e. the iteration stops +if no new bad pixels are found or \e max_iter is reached. In each +iteration we replace the detected cosmic ray hits by the median of the +surroundings 5x5 pixels taking into account the pixel quality +information. The input parameter \e sigma_lim and \e f_lim refer to +\f$\sigma_{lim}\f$ and \f$f_{lim}\f$ as described in the paper +mentioned above. The hdrl parameter passed to this routine is created +by hdrl_lacosmic_parameter_create(). + +@note Be aware that the implementation only detects positive bad +pixels / cosmic ray hits, i.e. no "holes" in the image are detected, +but in such a case the pixels surrounding the whole are marked as +bad. Holes in the image can be introduced, if e.g. one subtracts a not +cosmic-ray-cleaned image from another image. + +*/ +/*----------------------------------------------------------------------------*/ +cpl_mask * hdrl_lacosmic_edgedetect( + const hdrl_image * ima_in, + const hdrl_parameter * params) +{ + cpl_image * sci_data; + cpl_image * sci_error = NULL; + cpl_mask * sci_mask = NULL; + cpl_image * laplacian_redu_data = NULL; /* re-binned Laplacian */ + cpl_image * subs2_data = NULL; /* Sub-sampled image by a factor of 2 */ + cpl_image * s_data = NULL; + cpl_image * f_data = NULL; + cpl_image * r_data = NULL; + + + intptr_t subs2_nx = 0; + intptr_t subs2_ny = 0; + + cpl_binary * psci_mask = NULL; + cpl_binary * pout_mask = NULL; + + cpl_matrix * laplacian_kernel = NULL; + + cpl_mask * median3_kernel = NULL; + cpl_mask * median5_kernel = NULL; + cpl_mask * median7_kernel = NULL; + cpl_mask * lastiter_mask = NULL; + cpl_mask * out_mask = NULL; + + double * psci_data = NULL; + double * psci_error = NULL; + double * psubs2_data = NULL; + double * plaplacian_data = NULL; + double * plaplacian_redu_data = NULL; + double * psci_median3_data = NULL; + double * ps_data = NULL; + double * pf_data = NULL; + double * pr_data = NULL; + + int nbiter = 1; + + intptr_t nx = 0; + intptr_t ny = 0; + + /* Check Entries */ + cpl_ensure(ima_in, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_lacosmic_parameter_verify(params) == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_INPUT, NULL) ; + + cpl_ensure(hdrl_image_get_size_x(ima_in) >= 7, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(hdrl_image_get_size_y(ima_in) >= 7, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + /* Local Usage parameters */ + const hdrl_lacosmic_parameter * p_loc = (const hdrl_lacosmic_parameter *)params ; + + sci_data = cpl_image_cast(hdrl_image_get_image_const(ima_in), + CPL_TYPE_DOUBLE); + if (hdrl_image_get_mask_const(ima_in)) { + sci_mask = cpl_mask_duplicate(hdrl_image_get_mask_const(ima_in)); + } else { + sci_mask = cpl_mask_new(cpl_image_get_size_x(sci_data), + cpl_image_get_size_y(sci_data)); + } + sci_error = cpl_image_cast(hdrl_image_get_error_const(ima_in), + CPL_TYPE_DOUBLE); + + /* Laplacian */ + laplacian_kernel = cpl_matrix_new(3, 3); + cpl_matrix_set(laplacian_kernel, 0, 0, 0.0); + cpl_matrix_set(laplacian_kernel, 0, 1, -1.0); + cpl_matrix_set(laplacian_kernel, 0, 2, 0.0); + cpl_matrix_set(laplacian_kernel, 1, 0, -1.0); + cpl_matrix_set(laplacian_kernel, 1, 1, 4.0); + cpl_matrix_set(laplacian_kernel, 1, 2, -1.0); + cpl_matrix_set(laplacian_kernel, 2, 0, 0.0); + cpl_matrix_set(laplacian_kernel, 2, 1, -1.0); + cpl_matrix_set(laplacian_kernel, 2, 2, 0.0); + + /* Median 3x3*/ + median3_kernel = cpl_mask_new(3, 3); + cpl_mask_not(median3_kernel); /* All values set to unity */ + + /* Median 5x5 */ + median5_kernel = cpl_mask_new(5, 5); + cpl_mask_not(median5_kernel); /* All values set to unity */ + + /* Median 7x7 */ + median7_kernel = cpl_mask_new(7, 7); + cpl_mask_not(median7_kernel); /* All values set to unity */ + + out_mask = cpl_mask_new(cpl_mask_get_size_x(sci_mask), + cpl_mask_get_size_y(sci_mask)); + + nx = cpl_image_get_size_x(sci_data); + ny = cpl_image_get_size_y(sci_data); + + /* Preparing different kernels */ + psci_data = cpl_image_get_data_double(sci_data); + psci_error = cpl_image_get_data_double(sci_error); + + psci_mask = cpl_mask_get_data(sci_mask); + pout_mask = cpl_mask_get_data(out_mask); + + subs2_nx = nx * 2; + subs2_ny = ny * 2; + + subs2_data = cpl_image_new(subs2_nx, subs2_ny, CPL_TYPE_DOUBLE); + psubs2_data = cpl_image_get_data_double( subs2_data); + + laplacian_redu_data = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + plaplacian_redu_data = cpl_image_get_data_double( laplacian_redu_data); + + s_data = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + ps_data = cpl_image_get_data_double( s_data); + + f_data = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + pf_data = cpl_image_get_data_double( f_data); + + r_data = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + pr_data = cpl_image_get_data_double( r_data); + + /* mask needed to stop the loop if the pixel-replacements is not propperly + * working */ + lastiter_mask = cpl_mask_duplicate(out_mask); + + /* The actual cosmic ray search is done here. + * stop if no new cosmic are found or max iter is reached */ + while (nbiter <= p_loc->max_iter) { + cpl_vector * median; + double * psci_median3_7_data; + double * ps_median_data; + + /* Stopping if the detections of the previus run are identical to + * the last run */ + if (nbiter > 1 && !hdrl_check_maskequality(lastiter_mask, out_mask)) { + cpl_msg_debug(cpl_func, "Detections of iteration %d and %d are " + "identical - stopping here", nbiter-1, nbiter ); + break; + } + cpl_mask_delete(lastiter_mask); + lastiter_mask = cpl_mask_duplicate(out_mask); + + /* Super sample data: + Create a 2n x 2n images like this + | 1 | 2 | => | 1 | 1 | 2 | 2 | + | 3 | 4 | | 1 | 1 | 2 | 2 | + | 3 | 3 | 4 | 4 | + | 3 | 3 | 4 | 4 | */ + + for (intptr_t j = 0; j < ny; j++) { + intptr_t j_2_subs2_nx = j * 2 * subs2_nx; + intptr_t j_nx = j * nx; + for (intptr_t i = 0; i < nx; i++) { + double val = psci_data[i + j_nx]; + intptr_t pix = i * 2 + j_2_subs2_nx; + psubs2_data[pix] = val; + psubs2_data[pix + subs2_nx] = val; + pix++; + psubs2_data[pix] = val; + psubs2_data[pix + subs2_nx] = val; + } + } + + /* Doing the Laplacian convolution and set negative pixels to + 0 in the Laplacian image + 0 -1 0 + -1 4 -1 + 0 -1 0 */ + + cpl_image * laplacian_data = hdrl_parallel_filter_image(subs2_data, + laplacian_kernel, NULL, + CPL_FILTER_LINEAR); + + plaplacian_data = cpl_image_get_data_double(laplacian_data); + for (intptr_t i = 0; i < subs2_nx * subs2_ny; i++) { + if (plaplacian_data[i] < 0.0) { + plaplacian_data[i] = 0.0; + } else { + /*TODO Where does this factor of 8 come from???*/ + plaplacian_data[i] *= 8.0; + } + } + + /* fix discontinuity at edges due to incomplete laplace kernel by + * mirroring the neighbouring pixel */ + for (intptr_t i = 0; i < subs2_ny; i++) { + plaplacian_data[i * subs2_nx + 0] = plaplacian_data[i * subs2_nx + 1]; + plaplacian_data[i * subs2_nx + subs2_nx - 1] = + plaplacian_data[i * subs2_nx + + subs2_nx - 2]; + } + for (intptr_t j = 0; j < subs2_nx; j++) { + plaplacian_data[0 * subs2_nx + j] = plaplacian_data[1 * subs2_nx + j]; + plaplacian_data[(subs2_ny - 1) * subs2_nx + j] = + plaplacian_data[(subs2_ny - 2) * subs2_nx + j]; + } + +#if REGDEBUG_FULL + cpl_image_save(laplacian_data, "Lpositive.fits", CPL_BPP_IEEE_DOUBLE, + NULL, CPL_IO_DEFAULT); +#endif + + /* resample to the original size + | 1 | 1 | 2 | 2 | | 1 | 2 | + | 1 | 1 | 2 | 2 | | 3 | 4 | + | 3 | 3 | 4 | 4 | => + | 3 | 3 | 4 | 4 | */ + +HDRL_OMP(omp parallel for) + for (intptr_t j = 0; j < ny; j++) { + intptr_t j_2_subs2_nx = j * 2 * subs2_nx; + intptr_t j_nx = j * nx; + for (intptr_t i = 0; i < nx; i++) { + intptr_t pix = i * 2 + j_2_subs2_nx; + plaplacian_redu_data[i + j_nx] = + (plaplacian_data[pix] + + plaplacian_data[pix + 1] + + plaplacian_data[pix + subs2_nx] + + plaplacian_data[pix + subs2_nx + 1]) * 0.25; + /* A) Compute S image */ + ps_data[i + j_nx] = + 0.5 * plaplacian_redu_data[i + j_nx] / psci_error[i + j_nx]; + } + } + +#if REGDEBUG_FULL + cpl_image_save(laplacian_redu_data, "Lplus.fits", CPL_BPP_IEEE_DOUBLE, + NULL, CPL_IO_DEFAULT); +#endif + + /* A) compute S median image */ + cpl_image * s_median_data = hdrl_parallel_filter_image(s_data, NULL, + median5_kernel, + CPL_FILTER_MEDIAN); + ps_median_data = cpl_image_get_data_double( s_median_data); + + + /* B) Compute s2 -> denoted S' in the original paper */ + for (intptr_t i = 0; i < nx * ny; i++) { + ps_data[i] -= ps_median_data[i]; + } + +#if REGDEBUG_FULL + cpl_image_save( s_data, "S2.fits", CPL_BPP_IEEE_DOUBLE, NULL, + CPL_IO_DEFAULT); +#endif + + /* Apply 3x3 median filter on data */ + cpl_image * sci_median3_data = + hdrl_parallel_filter_image(sci_data, NULL, + median3_kernel, + CPL_FILTER_MEDIAN); + psci_median3_data = cpl_image_get_data_double(sci_median3_data); + + /* Apply 7x7 median filter */ + + cpl_image * sci_median3_7_data = + hdrl_parallel_filter_image(sci_median3_data, NULL, + median7_kernel, + CPL_FILTER_MEDIAN); + psci_median3_7_data = cpl_image_get_data_double(sci_median3_7_data); + + /* C) Compute F, i.e. the fine structure image */ + for (intptr_t i = 0; i < nx * ny; i++) { + pf_data[i] = psci_median3_data[i] - psci_median3_7_data[i]; + /* TODO: why this setting? + * why one use an absolute number? + * pf_data may span on different ranges as it depends on the value + * of the difference psci_median3_data[i] - psci_median3_7_data[i] + */ + if (pf_data[i] < 0.01) { + pf_data[i] = 0.01; + } + } + +#if REGDEBUG_FULL + cpl_image_save( f_data, "F.fits", CPL_BPP_IEEE_DOUBLE, NULL, + CPL_IO_DEFAULT); +#endif + + /* D) Compute R, i.e. the ratio of Laplacian and fine structure image */ + for (intptr_t i = 0; i < nx * ny; i++) { + pr_data[i] = plaplacian_redu_data[i] / pf_data[i]; + } + +#if REGDEBUG_FULL + cpl_image_save( r_data, "R.fits", CPL_BPP_IEEE_DOUBLE, NULL, + CPL_IO_DEFAULT); +#endif + + /* E) Search for cosmics */ + median = cpl_vector_new(24); + for (intptr_t j = 0; j < ny - 1; j++) { + intptr_t j_nx = j * nx; + for (intptr_t i = 0; i < nx - 1; i++) { + intptr_t i_plus_j_nx = i + j_nx; + if (ps_data[i_plus_j_nx] > p_loc->sigma_lim && + pr_data[i_plus_j_nx] > p_loc->f_lim && + /* check for bad pixels added here */ + psci_mask[i_plus_j_nx] == CPL_BINARY_0) { + double *data = NULL; + cpl_vector* med_vect = NULL; + intptr_t li, lj, ui, uj, m; + /* we flag the CRH in the science frame */ + pout_mask[i_plus_j_nx] = CPL_BINARY_1; + cpl_msg_debug(cpl_func, "Detection found at x=%zd y=%zd with " + "value=%g", i+1, j+1, psci_data[i_plus_j_nx]); + + /* we replace the CRH with median of the surroundings + pixels in a box 5x5 pixels */ + m = 0; + li = CX_MAX(i - 2, 0); + lj = CX_MAX(j - 2, 0); + ui = CX_MIN(nx, i + 3); + uj = CX_MIN(ny, j + 3); + + for (intptr_t k = lj; k < uj; k++) { + intptr_t k_nx = k * nx; + for (intptr_t l = li; l < ui; l++) { + intptr_t l_plus_k_nx = l + k_nx; + if (ps_data[l_plus_k_nx] <= p_loc->sigma_lim && + /* check for bad pixels added here */ + psci_mask[l_plus_k_nx] == CPL_BINARY_0) { + cpl_vector_set(median,m,psci_data[l_plus_k_nx]); + m++; + continue; + } + if (pr_data[l_plus_k_nx] <= p_loc->f_lim && + /* check for bad pixels added here */ + psci_mask[l_plus_k_nx] == CPL_BINARY_0) { + cpl_vector_set(median,m,psci_data[l_plus_k_nx]); + m++; + } + } + } + /* if no good pixel has been found skip pixel value + replacement */ + if(m == 0) continue; + /* Replace CRH value with median of computed values on + good pixels */ + data = cpl_vector_get_data( median); + med_vect = cpl_vector_wrap( m, data); + psci_data[i_plus_j_nx] = cpl_vector_get_median(med_vect); + cpl_msg_debug(cpl_func, "Detection replaced with value=%g", + psci_data[i_plus_j_nx]); + cpl_vector_unwrap(med_vect); + } /* end check on thresholds */ + } /* end loop over image columns */ + } /* end loop over image rows */ + + cpl_vector_delete(median); median = NULL; + + nbiter++; + cpl_image_delete(laplacian_data); + cpl_image_delete(sci_median3_7_data); + cpl_image_delete(sci_median3_data); + cpl_image_delete(s_median_data); + } + +#if REGDEBUG_FULL + cpl_mask_save( *out_mask, "CRH_SINGLE.fits", NULL, CPL_IO_DEFAULT); +#endif + + /* Free memory */ + cpl_matrix_delete(laplacian_kernel); + cpl_mask_delete(median3_kernel); + cpl_mask_delete(median5_kernel); + cpl_mask_delete(median7_kernel); + cpl_mask_delete(lastiter_mask); + cpl_image_delete(laplacian_redu_data); + cpl_image_delete(subs2_data); + cpl_image_delete(s_data); + cpl_image_delete(f_data); + cpl_image_delete(r_data); + cpl_image_delete(sci_data); + cpl_image_delete(sci_error); + cpl_mask_delete(sci_mask); + + return out_mask; +} + +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_lacosmics.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_lacosmics.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_lacosmics.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_lacosmics.h 2014-09-15 13:05:15.000000000 +0000 @@ -0,0 +1,73 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_LACOSMICS_H_ +#define HDRL_LACOSMICS_H_ + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + LaCosmic Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_lacosmic_parameter_create(double, double, int); +cpl_error_code hdrl_lacosmic_parameter_verify(const hdrl_parameter *) ; +cpl_boolean hdrl_lacosmic_parameter_check(const hdrl_parameter *) ; + +/* Accessors */ +double hdrl_lacosmic_parameter_get_sigma_lim(const hdrl_parameter *) ; +double hdrl_lacosmic_parameter_get_f_lim(const hdrl_parameter *) ; +int hdrl_lacosmic_parameter_get_max_iter(const hdrl_parameter *) ; + +/* Parameter Lists */ +cpl_parameterlist * hdrl_lacosmic_parameter_create_parlist(const char *, + const char *, const hdrl_parameter *); +hdrl_parameter * hdrl_lacosmic_parameter_parse_parlist( + const cpl_parameterlist *, const char *) ; + +/*---------------------------------------------------------------------------- + LaCosmic Computation + ----------------------------------------------------------------------------*/ + +cpl_mask * hdrl_lacosmic_edgedetect( + const hdrl_image * ima_in, + const hdrl_parameter * params) ; + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE + +#endif + +CPL_END_DECLS + +#endif /* HDRL_LACOSMICS_H_ */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_multiiter.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_multiiter.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_multiiter.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_multiiter.c 2017-08-25 12:52:36.000000000 +0000 @@ -0,0 +1,143 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_multiiter.h" +#include "hdrl_iter.h" + +#include +#include + +/*----------------------------------------------------------------------------- + Static Prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + * @addtogroup hdrl_multiiter + * @{ + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ +#define MAX_ITERS 32 + +typedef struct { + const cpl_frameset * frames; + hdrl_iter * iters[MAX_ITERS]; + intptr_t niters; + void * data[MAX_ITERS]; +} hdrl_multiiter_state; + +static cpl_size hdrl_multiiter_length(hdrl_iter * it); +static void hdrl_multiiter_delete(void * it); +static void * hdrl_multiiter_next(hdrl_iter * it); + +/* ---------------------------------------------------------------------------*/ +/** + * @brief iterate over multiple iterators + * + * @param niters number of iterators + * @param iters array of iterators + * @param flags flags of iterator + * + * Iterates over multiple iterators returning their results as an array of + * pointers of the same length as number of iterators. + * The length of all iterators must currently be equal unless + * the HDRL_ITER_ALLOW_EMPTY flag is set iterators. Then the iterator will + * return NULL for the exhausted iterator entries. + * The multiiter may have HDRL_ITER_OWNS_DATA set in which case it will delete + * the result values itself. To take ownership set the pointer in the multiiter + * result to NULL. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_iter * +hdrl_multiiter_new(intptr_t niters, hdrl_iter * iters[], hdrl_iter_flags flags) +{ + cpl_ensure(niters > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(iters, CPL_ERROR_NULL_INPUT, NULL); + hdrl_multiiter_state * state = cpl_calloc(sizeof(*state), 1); + state->niters = niters; + cpl_size nlen = hdrl_iter_length(iters[0]); + for (intptr_t i = 0; i < niters; i++) { + state->iters[i] = iters[i]; + /* TODO add broadcasting */ + if (!(flags & HDRL_ITER_ALLOW_EMPTY) && + hdrl_iter_length(iters[i]) != nlen) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Iterator length must match"); + } + } + + return hdrl_iter_init(&hdrl_multiiter_next, NULL, + &hdrl_multiiter_length, + &hdrl_multiiter_delete, + HDRL_ITER_INPUT | HDRL_ITER_IMAGE | flags, + state); +} + +static cpl_size hdrl_multiiter_length(hdrl_iter * it) +{ + hdrl_multiiter_state * state = hdrl_iter_state(it); + return hdrl_iter_length(state->iters[0]); +} + +static void hdrl_multiiter_delete(void * it) +{ + if (!it) + return; + hdrl_multiiter_state * state = hdrl_iter_state(it); + for (intptr_t i = 0; i < state->niters; i++) { + hdrl_iter_delete(state->iters[i]); + } + cpl_free(state); +} + + +static void * hdrl_multiiter_next(hdrl_iter * it) +{ + hdrl_multiiter_state * state = hdrl_iter_state(it); + int done = 0; + for (intptr_t i = 0; i < state->niters; i++) { + state->data[i] = hdrl_iter_next(state->iters[i]); + if (state->data[i] == NULL) { + done++; + } + assert(hdrl_iter_check(it, HDRL_ITER_ALLOW_EMPTY) || + (done && !state->data[i]) || (!done && state->data[i])); + } + /* if empties are allowed we are done when all iterators are done */ + if (hdrl_iter_check(it, HDRL_ITER_ALLOW_EMPTY)) { + return done == state->niters ? NULL : state->data; + } + else { + return done ? NULL : state->data; + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_multiiter.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_multiiter.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_multiiter.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_multiiter.h 2016-08-11 11:20:37.000000000 +0000 @@ -0,0 +1,65 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifndef HDRL_MULTIITER_H +#define HDRL_MULTIITER_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_iter.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +/** @cond EXPERIMENTAL */ + +hdrl_iter * +hdrl_multiiter_new(intptr_t niters, hdrl_iter * iters[], hdrl_iter_flags flags); + +/** @endcond */ +#endif + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl +------------------------------------------------------------------------------*/ + +#ifdef HDRL_USE_PRIVATE +/** @cond PRIVATE */ + +/** @endcond */ +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_overscan.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_overscan.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_overscan.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_overscan.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,1738 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_overscan.h" +#include "hdrl_overscan_defs.h" +#include "hdrl_sigclip.h" +#include "hdrl_utils.h" +#include "hdrl_collapse.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +static hdrl_overscan_compute_result * hdrl_overscan_compute_result_create( + void); +static cpl_error_code hdrl_overscan_compute_result_verify( + const hdrl_overscan_compute_result *); +static hdrl_overscan_correct_result * hdrl_overscan_correct_result_create( + void); +static cpl_error_code hdrl_overscan_compute_chi_square(const cpl_image *, + const cpl_image *, const double, double *, double *); +static cpl_error_code hdrl_overscan_reduce_image_to_scalar( + hdrl_collapse_imagelist_to_vector_t *, cpl_image *, cpl_image *, + double *, double *, cpl_size *, void **) ; +static void hdrl_overscan_parameter_destroy(void * param); + +/*----------------------------------------------------------------------------*/ +/* INCLUDED FROM doc/Func_Overscan.tex */ +/** + @defgroup hdrl_overscan Overscan Computation and Correction + +The overscan (or prescan) region on a CCD can consist of physical +pixels on the detector that are not illuminated, or it can consist of a set +of virtual pixels created by reading out the serial register either before or +after transferring the charge from the CCD for each column/row. +A detector may have multiple regions (amplifiers) and each one usually has +an associated overscan region. + +This module is intended to be applied to a single overscan region. + +The key parameter is box_hsize. When box_hsize is zero, then the +overscan correction is calculated without smoothing over adjacent rows/columns. +However, this may lead to a noisy overscan correction vector. +Increasing box_hsize will increase the S/N of the values in the overscan +correction vector, but will decrease the ability of the overscan correction +to correct for rapid spatial changes in the bias level. +A balance must be reached which will likely depend on the detector under +consideration. + +A typical overscan correction may be essentially independent of row/column, +or it may vary smoothly or with abrupt gradient changes. Hence the +implementation of a smoothing method as opposed to the fitting of an +analytical function. + +When choosing the overscan region, note that the first few rows/columns +that are read out after the image area will have an artificially high bias +level due to the charge transfer efficiency not being 100%. It is +recommended therefore to not include the 2-3 rows/columns right next +to the image region in the overscan region. + +An interesting phenomenon is that a very bright star/object may increase the +bias level for the few rows/columns that it covers. Hence it is not advisable +to set box_hsize to a value that is much larger than the image +point-spread-function FWHM. + +An overscan correction is the correct way to correct for the detector bias +level. It is preferable to do an overscan correction instead of using +bias frames to determine a bias level. + +This module allows the computation of the overscan correction for an image +from a predefined overscan region. It also provides a function that applies +the overscan correction to the image, using the result of the overscan +computation. + + \image html overscan_example.png + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + Overscan Parameters Definition + -----------------------------------------------------------------------------*/ +typedef struct { + HDRL_PARAMETER_HEAD; + hdrl_direction correction_direction; + double ccd_ron; + int box_hsize; + hdrl_parameter * collapse; + hdrl_parameter * rect_region; +} hdrl_overscan_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_overscan_parameter_type = { + HDRL_PARAMETER_OVERSCAN, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + (hdrl_free *)&hdrl_overscan_parameter_destroy, /* fp_destroy */ + sizeof(hdrl_overscan_parameter), /* obj_size */ +}; + +/* ---------------------------------------------------------------------------*/ +/** + @brief Creates Overscan Parameters object + @param correction_direction HDRL_X_AXIS or HDRL_Y_AXIS + @param ccd_ron The CCD read out noise + @param box_hsize The running box half size + @param collapse The collpase method parameters + @param rect_region The overscan computation region + @return The overscan parameters object. It needs to be deallocated + with hdrl_parameter_delete() or _destroy() + @see hdrl_parameter_delete() + @see hdrl_parameter_destroy() + @see hdrl_overscan_compute() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_overscan_parameter_create( + hdrl_direction correction_direction, + double ccd_ron, + int box_hsize, + hdrl_parameter * collapse, + hdrl_parameter * rect_region) +{ + hdrl_overscan_parameter * p = (hdrl_overscan_parameter *) + hdrl_parameter_new(&hdrl_overscan_parameter_type); + p->correction_direction = correction_direction ; + p->ccd_ron = ccd_ron ; + p->box_hsize = box_hsize ; + p->collapse = collapse ; + p->rect_region = rect_region ; + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Verify basic correctness of the Overscan parameters + @param param Overscan parameters + @param nx required X region size, set to < 0 to skip check + @param ny required Y region size, set to < 0 to skip check + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_overscan_parameter_verify( + const hdrl_parameter * param, + cpl_size nx, + cpl_size ny) +{ + const hdrl_overscan_parameter * param_loc = + (const hdrl_overscan_parameter *)param ; + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_overscan_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected Overscan parameter") ; + + cpl_error_ensure(param_loc->ccd_ron >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "CCD read out noise (%g) must be >= 0", param_loc->ccd_ron); + cpl_error_ensure(param_loc->box_hsize >= 0 || + param_loc->box_hsize == HDRL_OVERSCAN_FULL_BOX, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "half box size (%d) must be >= 0 or -1", + param_loc->box_hsize); + cpl_error_ensure(param_loc->correction_direction == HDRL_X_AXIS || + param_loc->correction_direction == HDRL_Y_AXIS, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "correction_direction must be HDRL_X_AXIS or HDRL_Y_AXIS"); + + if (hdrl_collapse_parameter_is_sigclip(param_loc->collapse)) { + cpl_error_ensure( + hdrl_collapse_sigclip_parameter_verify(param_loc->collapse) + == CPL_ERROR_NONE, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "Illegal Collapse Sigclip parameters"); + } + if (hdrl_collapse_parameter_is_minmax(param_loc->collapse)) { + cpl_error_ensure( + hdrl_collapse_minmax_parameter_verify(param_loc->collapse) + == CPL_ERROR_NONE, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "Illegal Collapse Minmax parameters"); + } + cpl_error_ensure( + hdrl_rect_region_parameter_verify(param_loc->rect_region, -1, -1) + == CPL_ERROR_NONE, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "Illegal Rect Region parameters"); + + cpl_error_ensure(hdrl_collapse_parameter_is_mean(param_loc->collapse) || + hdrl_collapse_parameter_is_weighted_mean(param_loc->collapse) || + hdrl_collapse_parameter_is_median(param_loc->collapse) || + hdrl_collapse_parameter_is_sigclip(param_loc->collapse) || + hdrl_collapse_parameter_is_minmax(param_loc->collapse), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Only supported methods are MEAN, WEIGHTED_MEAN, MEDIAN, SIGCLIP," + " and MINMAX"); + + /* The region must be contained in the image */ + if (nx > 0) { + cpl_size region_llx = hdrl_rect_region_get_llx(param_loc->rect_region); + cpl_size region_urx = hdrl_rect_region_get_urx(param_loc->rect_region); + cpl_error_ensure( + region_llx>=1 && region_urx <= nx, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Region (%d) exceeds source (%d) size in the X dir.", + (int)region_urx, (int)nx); + } + if (ny > 0) { + cpl_size region_lly = hdrl_rect_region_get_lly(param_loc->rect_region); + cpl_size region_ury = hdrl_rect_region_get_ury(param_loc->rect_region); + cpl_error_ensure( + region_lly>=1 && region_ury <= ny, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Region (%d) exceeds source (%d) size in the Y dir.", + (int)region_ury, (int)ny); + } + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is an Overscan parameter + @param self The parameter to check + @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_overscan_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_overscan_parameter_type); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the Correction Direction in the Overscan Parameter + @param p The Overscan parameter + @return The correction direction + */ +/*----------------------------------------------------------------------------*/ +hdrl_direction hdrl_overscan_parameter_get_correction_direction( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, HDRL_UNDEFINED_AXIS); + return ((const hdrl_overscan_parameter *)p)->correction_direction; +} +/*----------------------------------------------------------------------------*/ +/** + @brief Access the CCD read out noise in the Overscan Parameter + @param p The Overscan parameter + @return The CCD read out noise + */ +/*----------------------------------------------------------------------------*/ +double hdrl_overscan_parameter_get_ccd_ron( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0) ; + return ((const hdrl_overscan_parameter *)p)->ccd_ron ; +} +/*----------------------------------------------------------------------------*/ +/** + @brief Access the Box Half Size in the Overscan Parameter + @param p The Overscan parameter + @return The box half size + */ +/*----------------------------------------------------------------------------*/ +int hdrl_overscan_parameter_get_box_hsize( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0) ; + return ((const hdrl_overscan_parameter *)p)->box_hsize ; +} +/*----------------------------------------------------------------------------*/ +/** + @brief Access the collapse method parameters in the Overscan Parameter + @param p The Overscan parameter + @return The collapse method parameters + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_overscan_parameter_get_collapse( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, NULL) ; + return ((const hdrl_overscan_parameter *)p)->collapse; +} +/*----------------------------------------------------------------------------*/ +/** + @brief Access the Overscan Region parameters in the Overscan Parameter + @param p The Overscan parameter + @return The Overscan region parameters + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_overscan_parameter_get_rect_region( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, NULL) ; + return ((const hdrl_overscan_parameter *)p)->rect_region; +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief Create parameter list for the Overscan computation + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param corr_dir_def default correction direction value + @param box_hsize_def default box hsize value + @param ccd_ron_def default ccd ron value + @param rect_region_def default overscan region parameters + @param method_def default collapse method value + @param sigclip_def default sigma-clipping parameters + @param minmax_def default minmax-clipping parameters + + @see hdrl_rect_region_parameter_create_parlist() + @see hdrl_collapse_parameter_create_parlist() + Creates a parameterlist with the overscan computation parameters: + + - base_context.prefix.correction-direction + - base_context.prefix.box-hsize + - base_context.prefix.ccd-ron + - base_context.prefix.calc-* + - base_context.prefix.collapse.* + + The CLI aliases omit the base_context. + */ +/* ---------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_overscan_parameter_create_parlist( + const char *base_context, + const char *prefix, + const char *corr_dir_def, + int box_hsize_def, + double ccd_ron_def, + hdrl_parameter *rect_region_def, + const char *method_def, + hdrl_parameter *sigclip_def, + hdrl_parameter *minmax_def) +{ + cpl_ensure(prefix && base_context && rect_region_def && sigclip_def && minmax_def, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure( hdrl_rect_region_parameter_check( rect_region_def) + && hdrl_collapse_parameter_is_sigclip(sigclip_def ) + && hdrl_collapse_parameter_is_minmax( minmax_def ), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + char * name ; + cpl_parameterlist * parlist = cpl_parameterlist_new(); + cpl_parameter * par ; + char * context = + hdrl_join_string(".", 2, base_context, prefix); + + /* --prefix.correction_direction */ + name = hdrl_join_string(".", 2, context, "correction-direction"); + par = cpl_parameter_new_enum(name, CPL_TYPE_STRING, "Correction Direction", + context, corr_dir_def, 2, "alongX", "alongY"); + cpl_free(name); + name = hdrl_join_string(".", 2, prefix, "correction-direction"); + cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV); + cpl_free(name); + cpl_parameterlist_append(parlist, par); + + /* --prefix.box-hsize */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "box-hsize", base_context, + "Half size of running box in pixel, -1 for full overscan region", + CPL_TYPE_INT, box_hsize_def) ; + + /* --prefix.ccd-ron */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "ccd-ron", base_context, + "Readout noise in ADU", CPL_TYPE_DOUBLE, ccd_ron_def) ; + + /* Create Overscan Computation Region parameters */ + /* --prefix.overscan.calc-xxx */ + cpl_parameterlist * os_comp_reg = hdrl_rect_region_parameter_create_parlist( + base_context, prefix, "calc-", rect_region_def); + for (cpl_parameter * p = cpl_parameterlist_get_first(os_comp_reg) ; + p != NULL; p = cpl_parameterlist_get_next(os_comp_reg)) + cpl_parameterlist_append(parlist,cpl_parameter_duplicate(p)); + cpl_parameterlist_delete(os_comp_reg); + + /* Overscan Collapsing related parameters */ + /* --prefix.collapse.xxx */ + name = hdrl_join_string(".", 2, prefix, "collapse"); + cpl_parameterlist * pcollapse = hdrl_collapse_parameter_create_parlist( + base_context, name, method_def, sigclip_def, minmax_def) ; + cpl_free(name); + for (cpl_parameter * p = cpl_parameterlist_get_first(pcollapse) ; + p != NULL; p = cpl_parameterlist_get_next(pcollapse)) + cpl_parameterlist_append(parlist,cpl_parameter_duplicate(p)); + cpl_parameterlist_delete(pcollapse); + + cpl_free(context); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief Parse parameterlist to create input parameters for the Overscan method + @param parlist parameter list to parse + @param prefix prefix of parameter name + @return Input parameters for the Overscan Computation + Reads a Parameterlist in order to create overscan parameters. + Expects a parameterlist containing: + - prefix.correction-direction + - prefix.box-hsize + - prefix.ccd-ron + - prefix.calc-llx + - prefix.calc-lly + - prefix.calc-urx + - prefix.calc-ury + - prefix.collapse.method + - prefix.collapse.sigclip.kappa-low + - prefix.collapse.sigclip.kappa-high + - prefix.collapse.sigclip.niter + - prefix.collapse.minmax.nlow + - prefix.collapse.sigclip.nhigh + + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_overscan_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + hdrl_direction corr_dir_param = HDRL_UNDEFINED_AXIS ; + int box_hsize = 0 ; + double ccd_ron = 0. ; + hdrl_parameter * os_collapse_params = NULL; + hdrl_parameter * os_region_params = NULL; + char * name ; + + /* --correction-direction */ + name = hdrl_join_string(".", 2, prefix, "correction-direction"); + const cpl_parameter *par = cpl_parameterlist_find_const(parlist, name); + const char *correction_direction = cpl_parameter_get_string(par); + if (correction_direction == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + if(!strcmp(correction_direction, "alongX")) { + corr_dir_param = HDRL_X_AXIS; + } else if(!strcmp(correction_direction, "alongY")) { + corr_dir_param = HDRL_Y_AXIS; + } + cpl_free(name) ; + + /* --box-hsize */ + name = hdrl_join_string(".", 2, prefix, "box-hsize"); + par=cpl_parameterlist_find_const(parlist, name); + box_hsize = cpl_parameter_get_int(par); + cpl_free(name) ; + + /* --ccd-ron */ + name = hdrl_join_string(".", 2, prefix, "ccd-ron"); + par=cpl_parameterlist_find_const(parlist, name); + ccd_ron = cpl_parameter_get_double(par); + cpl_free(name) ; + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist " + "with prefix %s", prefix); + return NULL; + } + + /* --calc-* */ + os_region_params = hdrl_rect_region_parameter_parse_parlist(parlist, + prefix, "calc-"); + + /* --collapse.* */ + name = hdrl_join_string(".", 2, prefix, "collapse"); + os_collapse_params = hdrl_collapse_parameter_parse_parlist(parlist, name) ; + cpl_free(name) ; + + if (cpl_error_get_code()) { + hdrl_parameter_destroy(os_region_params); + hdrl_parameter_destroy(os_collapse_params); + return NULL; + } + else { + return hdrl_overscan_parameter_create(corr_dir_param, ccd_ron, + box_hsize, os_collapse_params, + os_region_params); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief get imagelist to vector reduction object + * + * @param cpse parameter that determines the reduction type + * @param overscan_sub_ima overscan image for default parameters + * @param reduce pointer to reduction object storage + * @return cpl_error_code + * + * pointer stored in reduce must be deleted with + * hdrl_collapse_imagelist_to_vector_delete() + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code +get_reduction(const hdrl_parameter * cpse, + const cpl_image * overscan_sub_ima, + hdrl_collapse_imagelist_to_vector_t ** reduce) +{ + if (hdrl_collapse_parameter_is_mean(cpse)) { + *reduce = hdrl_collapse_imagelist_to_vector_mean(); + } else if (hdrl_collapse_parameter_is_weighted_mean(cpse)) { + *reduce = hdrl_collapse_imagelist_to_vector_weighted_mean(); + } else if (hdrl_collapse_parameter_is_median(cpse)) { + *reduce = hdrl_collapse_imagelist_to_vector_median(); + } else if (hdrl_collapse_parameter_is_sigclip(cpse)) { + double kappa = + sqrt(log(CX_MAX(hdrl_get_image_good_npix(overscan_sub_ima), 1))); + double kappa_low = hdrl_collapse_sigclip_parameter_get_kappa_low(cpse); + double kappa_high = + hdrl_collapse_sigclip_parameter_get_kappa_high(cpse); + int niter = hdrl_collapse_sigclip_parameter_get_niter(cpse); + if (kappa_low <= 0) kappa_low = kappa; + if (kappa_high <= 0) kappa_high = kappa; + *reduce = hdrl_collapse_imagelist_to_vector_sigclip(kappa_low, + kappa_high, niter); + } else if (hdrl_collapse_parameter_is_minmax(cpse)) { + double nlow = hdrl_collapse_minmax_parameter_get_nlow(cpse); + double nhigh = hdrl_collapse_minmax_parameter_get_nhigh(cpse); + if (nlow <= 0) nlow = 0; + if (nhigh <= 0) nhigh = 0; + *reduce = hdrl_collapse_imagelist_to_vector_minmax(nlow, nhigh); + } + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Overscan correction computation + @param source input image containing the Overscan region + @param params Overscan computation parameters + @return hdrl_overscan_compute_result structure containing the results + of the computation. It must be de-allocated by the caller using + hdrl_overscan_compute_result_delete(). + In case of error, NULL is returned and an error code is set. + @see hdrl_overscan_compute_result_delete() + + The source image may contain more than the overscan region that is + actually needed by the computation. + + params->rect_region defines the overscan region in the source image. The + bad pixels that might be present in the image are taken into account (i.e. + excluded from the computations). + + params->correction_direction is HDRL_X_AXIS (resp. HDRL_Y_AXIS) if the + overscan region has to be collapsed along the X (resp. Y) axis in + order to create the 1D resulting images (correction, error, contribution, the + \f$\chi^{2}\f$ (chi2) and + the reduced \f$\chi^{2}\f$ (red_chi2), additionally sigclip_reject_low and + _high if the sigma-clipping collapsing is used). + + Each pixel of the resulting 1D images are computed from a running + sub-window of the overscan region. params->box_hsize defines the half size + of the sub-window used for the computation (in the direction orthogonal to + params->correction_direction). If params->box_hsize value is + HDRL_OVERSCAN_FULL_BOX, the calculation is done on the whole overscan + region instead of a running sub-window. In this case, all pixels of the + resulting 1D images will be identical. + + params->collapse methods can be mean, weighted mean, median or sigclip, + i.e. the + collapse parameter can be created with + hdrl_collapse_mean_parameter_create(), + hdrl_collapse_weighted_mean_parameter_create(), + hdrl_collapse_median_parameter_create() or + hdrl_collapse_sigclip_parameter_create(). + + params->ccd_ron is the CCD read-out noise. The parameter is mandatory, + must be strictly non-negative. It is used for the error, the chi2 and the + red_chi2 computation. + + In case the sigma-clipping collapsing method is used, a sigma clipping + iterative rejection is applied in the overscan sub-window before the + computation of the results. + + The output hdrl_overscan_compute_result structure (in the following + named 'out') contains the following members: + + out.correction is a 1D HDRL image of type double. + Its image contains the overscan correction values computed from the good + pixels of the running sub-window (mean, median or mean after rejection, + depending on the used collapsing method) + + Its error contains \f$\frac{ccd\_ron}{\sqrt{contribution}}\f$ for the + mean, weighted mean and sigma-cliping methods. + In case the method is the median one, it would contain + \f$\sqrt{\frac{\pi}{2}}\times\frac{ccd\_ron}{\sqrt{contribution}}\f$ + if contribution is strictly greater than 2 pixels and + \f$\frac{ccd\_ron}{\sqrt{contribution}}\f$ when the contribution is 1 or + 2 pixels. + + out.contribution is a 1D CPL image of type integer. + It contains the number of good pixels of the input running sub-window + for the mean and median methods, and the remaining good pixels after the + rejection for the sigma-clipping method. + + out.chi2 and out.red_chi2 are 1D CPL images of type double. + + out.chi2 contains the sum over the good pixels of the region to correct, i.e. + of \f$\frac{source - out.correction}{ccd\_ron}^2\f$ + + out.red_chi2 contains the reduced chi2, i.e. the chi2 divided by the number + of contributing pixels. + + out.sigclip_reject_low and _high are 1D CPL images of type double. + They are only returned for the sigma-clipping method. They + indicate the final thresholds of the sigma-clipping rejection. + + \image html overscan_computation_algorithm.png + + @see hdrl_kappa_sigma_clip + @see hdrl_overscan_correct + */ +/*----------------------------------------------------------------------------*/ +hdrl_overscan_compute_result * hdrl_overscan_compute( + const cpl_image * source, + const hdrl_parameter * params) +{ + cpl_image * correction_img = NULL; + cpl_image * correction_err_img = NULL; + cpl_image * contribution_img = NULL; + cpl_image * chi2_img = NULL; + cpl_image * red_chi2_img = NULL; + cpl_image * reject_low = NULL; + cpl_image * reject_high = NULL; + cpl_size llx = 0; + cpl_size lly = 0; + cpl_size urx = 0; + cpl_size ury = 0; + cpl_image * overscan_ima = NULL; + + /*TODO add minmax description to the doxygen */ + + /* Check Entries */ + cpl_error_ensure(source != NULL, CPL_ERROR_NULL_INPUT, + return NULL, "NULL input image"); + cpl_error_ensure(params != NULL, CPL_ERROR_NULL_INPUT, + return NULL, "NULL input parameters"); + + int d1 = sizeof(hdrl_sigclip_vector_output); + int d2 = sizeof(hdrl_minmax_vector_output ); + cpl_error_ensure(d1 == d2, CPL_ERROR_INVALID_TYPE, return NULL, + "Invalid check type between hdrl_sigclip_vector_output and hdrl_minmax_vector_output"); + + if (hdrl_overscan_parameter_verify( + params, + cpl_image_get_size_x(source), + cpl_image_get_size_y(source)) != CPL_ERROR_NONE) + return NULL; + + /* Local Usage Parameters */ + const hdrl_overscan_parameter * p_loc = + (const hdrl_overscan_parameter *)params ; + const hdrl_parameter * cpse = p_loc->collapse ; + const hdrl_parameter * rr = p_loc->rect_region ; + + /* Extract Overscan region */ + overscan_ima = cpl_image_extract(source, + hdrl_rect_region_get_llx(rr), + hdrl_rect_region_get_lly(rr), + hdrl_rect_region_get_urx(rr), + hdrl_rect_region_get_ury(rr)) ; + + /* Handle Orientation */ + if(p_loc->correction_direction == HDRL_Y_AXIS) { + /* rotate the image 90 degree counter-clockwise */ + cpl_image_turn(overscan_ima, -1); + } + + /* Redefine the boundaries to extracted image */ + llx = 1; + lly = 1; + urx = cpl_image_get_size_x(overscan_ima); + ury = cpl_image_get_size_y(overscan_ima); + + /* Create output images */ + correction_img = cpl_image_new(1, ury, HDRL_TYPE_DATA); + correction_err_img = cpl_image_new(1, ury, HDRL_TYPE_ERROR); + contribution_img = cpl_image_new(1, ury, CPL_TYPE_INT); + chi2_img = cpl_image_new(1, ury, CPL_TYPE_DOUBLE); + red_chi2_img = cpl_image_new(1, ury, CPL_TYPE_DOUBLE); + + if (hdrl_collapse_parameter_is_sigclip(cpse) || + hdrl_collapse_parameter_is_minmax(cpse)) { + reject_low = cpl_image_new(1, ury, CPL_TYPE_DOUBLE); + reject_high = cpl_image_new(1, ury, CPL_TYPE_DOUBLE); + } + + /* Loop along Y direction */ + /* only 1 iteration if hbox == HDRL_OVERSCAN_FULL_BOX */ +HDRL_OMP(omp parallel for) + for (long ipixel = 1; + ipixel <= (p_loc->box_hsize == HDRL_OVERSCAN_FULL_BOX ? 1 : ury); + ipixel++) { + cpl_size contribution; + double corr, error, chi2, red_chi2; + const int box_hsize = p_loc->box_hsize; + const double ccd_ron = p_loc->ccd_ron; + cpl_size upperlimit; + cpl_size lowerlimit; + cpl_image * overscan_sub_ima, * ccd_ron_ima; + /* Switch on the different methods */ + hdrl_collapse_imagelist_to_vector_t * reduce = NULL; + void * collapse_eout = NULL; + + /* define proper extraction limits */ + if (box_hsize == HDRL_OVERSCAN_FULL_BOX) { + /* take full region as box */ + lowerlimit = lly; + upperlimit = ury; + } + else if (ipixel + box_hsize > ury) { + /* Shrink the window if you are approaching the image boundaries */ + upperlimit = CX_MIN(ipixel + box_hsize, ury); + lowerlimit = 2 * ipixel - upperlimit; + } + else { + /* Shrink the window if you are approaching the image boundaries */ + lowerlimit = CX_MAX(ipixel - box_hsize, 1); + upperlimit = 2 * ipixel - lowerlimit; + } + + /* Extract the current running sub-window */ + overscan_sub_ima = cpl_image_extract(overscan_ima, llx, lowerlimit, + urx, upperlimit); + + /* Fill an image with the ccd_ron constant */ + ccd_ron_ima = cpl_image_duplicate(overscan_sub_ima); + cpl_image_multiply_scalar(ccd_ron_ima, 0.0); + cpl_image_add_scalar(ccd_ron_ima, ccd_ron); + + get_reduction(cpse, overscan_sub_ima, &reduce); + + /* Compute the over-scan correction, error, and contribution */ + hdrl_overscan_reduce_image_to_scalar(reduce, overscan_sub_ima, + ccd_ron_ima, &corr, &error, &contribution, &collapse_eout); + + /* handle additional sigclip and minmax output */ + if (collapse_eout && (hdrl_collapse_parameter_is_sigclip(cpse) || + hdrl_collapse_parameter_is_minmax(cpse))) { + + hdrl_sigclip_vector_output * eout = collapse_eout; + + double low = cpl_vector_get(eout->reject_low, 0); + double high = cpl_vector_get(eout->reject_high, 0); + + cpl_image_set(reject_low, 1, ipixel, low); + cpl_image_set(reject_high, 1, ipixel, high); + + cpl_vector_delete(eout->reject_low); + cpl_vector_delete(eout->reject_high); + } + + hdrl_collapse_imagelist_to_vector_unwrap_eout(reduce, collapse_eout); + + /* Compute the chi2 - Independent of the method */ + if (contribution == 0) { + chi2 = NAN; + red_chi2 = NAN; + } else if (p_loc->box_hsize == HDRL_OVERSCAN_FULL_BOX) { + hdrl_overscan_compute_chi_square(overscan_sub_ima, + ccd_ron_ima, corr, &chi2, &red_chi2); + } else { + /*Calculate the chi2 only in the central slice of the image + * TODO very inefficient - restructure */ + cpl_size nx = cpl_image_get_size_x(overscan_sub_ima); + cpl_size ny = cpl_image_get_size_y(overscan_sub_ima); + + cpl_image * overscan_sub_ima_slice = + cpl_image_extract(overscan_sub_ima, 1, (cpl_size)((ny+1)/2), + nx, (cpl_size)((ny+1)/2)); + cpl_image * ccd_ron_ima_slice = + cpl_image_extract(ccd_ron_ima, 1, (cpl_size)((ny+1)/2), nx, + (cpl_size)((ny+1)/2)); + + hdrl_overscan_compute_chi_square(overscan_sub_ima_slice, + ccd_ron_ima_slice, corr, &chi2, &red_chi2); + + cpl_image_delete(overscan_sub_ima_slice); + cpl_image_delete(ccd_ron_ima_slice); + } + + /* Fill the result images with the current result */ + cpl_image_set(correction_img, 1, ipixel, corr); + cpl_image_set(correction_err_img, 1, ipixel, error); + cpl_image_set(contribution_img, 1, ipixel, contribution); + cpl_image_set(chi2_img, 1, ipixel, chi2); + cpl_image_set(red_chi2_img, 1, ipixel, red_chi2); + + cpl_image_delete(overscan_sub_ima); + cpl_image_delete(ccd_ron_ima); + + hdrl_collapse_imagelist_to_vector_delete(reduce); + } + + /* broadcast the full box result to the full result row/col */ + if (p_loc->box_hsize == HDRL_OVERSCAN_FULL_BOX) { + int rej; + const double ccd_ron = p_loc->ccd_ron; + const double correction_value = + cpl_image_get(correction_img, 1, 1, &rej); + const double correction_err_value = + cpl_image_get(correction_err_img, 1, 1, &rej); + const cpl_size contribution_value = + cpl_image_get(contribution_img, 1, 1, &rej); + cpl_size loopmax = cpl_image_get_size_y(correction_img); +HDRL_OMP(omp parallel for private(rej)) + for (cpl_size i = 1; i <= loopmax; i++) { + double chi2, red_chi2; + cpl_image * overscan_sub_ima, * ccd_ron_ima; + + if (i < loopmax) { + /*Here we broadcast*/ + cpl_image_set(correction_img, 1, i + 1, correction_value); + cpl_image_set(correction_err_img, 1, i + 1, + correction_err_value); + cpl_image_set(contribution_img, 1, i + 1,contribution_value); + if (hdrl_collapse_parameter_is_sigclip(cpse) || + hdrl_collapse_parameter_is_minmax(cpse)) { + cpl_image_set(reject_low, 1, i + 1, + cpl_image_get(reject_low, 1, 1, &rej)); + cpl_image_set(reject_high, 1, i + 1, + cpl_image_get(reject_high, 1, 1, &rej)); + } + } + /* Here we do additional chi2 calculation */ + + /* Extract the current running sub-window */ + overscan_sub_ima = cpl_image_extract(overscan_ima, llx, i, urx, i); + + /* Fill an image with the ccd_ron constant */ + ccd_ron_ima = cpl_image_duplicate(overscan_sub_ima); + cpl_image_multiply_scalar(ccd_ron_ima, 0.0); + cpl_image_add_scalar(ccd_ron_ima, ccd_ron); + + hdrl_overscan_compute_chi_square(overscan_sub_ima, + ccd_ron_ima, correction_value, + &chi2, &red_chi2); + + cpl_image_set(chi2_img, 1, i, chi2); + cpl_image_set(red_chi2_img, 1, i, red_chi2); + cpl_image_delete(overscan_sub_ima); + cpl_image_delete(ccd_ron_ima); + } + } + + cpl_image_delete(overscan_ima); + /* flag bad pixels */ + cpl_image_reject_value(correction_img, CPL_VALUE_NAN); + cpl_image_reject_value(correction_err_img, CPL_VALUE_NAN); + cpl_image_reject_value(chi2_img, CPL_VALUE_NAN); + cpl_image_reject_value(red_chi2_img, CPL_VALUE_NAN); + if (hdrl_collapse_parameter_is_sigclip(cpse) || + hdrl_collapse_parameter_is_minmax(cpse)) { + cpl_image_reject_value(reject_low, CPL_VALUE_NAN); + cpl_image_reject_value(reject_high, CPL_VALUE_NAN); + } + + /* Handle Orientation */ + if(p_loc->correction_direction == HDRL_Y_AXIS) { + cpl_image_turn(correction_img, +1); + cpl_image_turn(correction_err_img, +1); + cpl_image_turn(contribution_img, +1); + cpl_image_turn(chi2_img, +1); + cpl_image_turn(red_chi2_img, +1); + if (hdrl_collapse_parameter_is_sigclip(cpse) || + hdrl_collapse_parameter_is_minmax(cpse)) { + cpl_image_turn(reject_low, +1); + cpl_image_turn(reject_high, +1); + } + } + + /* Create the Overscan resulting structure */ + { + hdrl_overscan_compute_result * result = + hdrl_overscan_compute_result_create(); + hdrl_image * res = hdrl_image_create(correction_img, + correction_err_img); + cpl_image_delete(correction_img); + cpl_image_delete(correction_err_img); + result->correction_direction = p_loc->correction_direction; + result->correction = res; + result->contribution = contribution_img; + result->chi2 = chi2_img; + result->red_chi2 = red_chi2_img; + result->sigclip_reject_low = reject_low; + result->sigclip_reject_high = reject_high; + return result; + } +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the correction in the Overscan Computation result object + @param res The Overscan Computation result object + @return The correction HDRL image + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * hdrl_overscan_compute_result_get_correction( + const hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + return res->correction; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the correction in the Overscan Computation result object + @param res The Overscan Computation result object + @return The correction HDRL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * hdrl_overscan_compute_result_unset_correction( + hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + hdrl_image * r = res->correction; + res->correction = NULL; + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the contribution in the Overscan Computation result object + @param res The Overscan Computation result object + @return The contribution CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_contribution( + const hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + return res->contribution; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the contribution in the Overscan Computation result object + @param res The Overscan Computation result object + @return The contribution CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_contribution( + hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + cpl_image * r = res->contribution; + res->contribution = NULL; + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the CHI2 in the Overscan Computation result object + @param res The Overscan Computation result object + @return The CHI2 CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_chi2( + const hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + return res->chi2; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the CHI2 in the Overscan Computation result object + @param res The Overscan Computation result object + @return The CHI2 CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_chi2( + hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + cpl_image * r = res->chi2; + res->chi2 = NULL; + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the reduced CHI2 in the Overscan Computation result object + @param res The Overscan Computation result object + @return The reduced CHI2 CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_red_chi2( + const hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + return res->red_chi2; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the reduced CHI2 in the Overscan Computation result object + @param res The Overscan Computation result object + @return The reduced CHI2 CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_red_chi2( + hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + cpl_image * r = res->red_chi2; + res->red_chi2 = NULL; + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the low threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The low threshold CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_sigclip_reject_low( + const hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + if (!res->sigclip_reject_low) { + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "rejection parameters are only " + "available if collapse mode of overscan is set " + "to sigclip or minmax"); + } + return res->sigclip_reject_low; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the low threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The low threshold CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_sigclip_reject_low( + hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + cpl_image * r = res->sigclip_reject_low; + if (!res->sigclip_reject_low) { + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "rejection parameters are only " + "available if collapse mode of overscan is set " + "to sigclip or minmax"); + } + res->sigclip_reject_low = NULL; + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the high threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The high threshold CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_sigclip_reject_high( + const hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + if (!res->sigclip_reject_high) { + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "rejection parameters are only " + "available if collapse mode of overscan is set " + "to sigclip or minmax"); + } + return res->sigclip_reject_high; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the high threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The high threshold CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_sigclip_reject_high( + hdrl_overscan_compute_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + cpl_image * r = res->sigclip_reject_high; + res->sigclip_reject_high = NULL; + return r; +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the low threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The low threshold CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_minmax_reject_low( + const hdrl_overscan_compute_result * res) +{ + return hdrl_overscan_compute_result_get_sigclip_reject_low(res); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the low threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The low threshold CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_minmax_reject_low( + hdrl_overscan_compute_result * res) +{ + return hdrl_overscan_compute_result_unset_sigclip_reject_low(res); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the high threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The high threshold CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_get_minmax_reject_high( + const hdrl_overscan_compute_result * res) +{ + return hdrl_overscan_compute_result_get_sigclip_reject_high(res); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the high threshold in the Overscan Computation result object + @param res The Overscan Computation result object + @return The high threshold CPL image that has been unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_compute_result_unset_minmax_reject_high( + hdrl_overscan_compute_result * res) +{ + return hdrl_overscan_compute_result_unset_sigclip_reject_high(res); +} + + + +/*----------------------------------------------------------------------------*/ +/** + @brief Deletes the Overscan Computation Result Structure + @param result The computation result structure to delete + */ +/*----------------------------------------------------------------------------*/ +void hdrl_overscan_compute_result_delete( + hdrl_overscan_compute_result * result) +{ + if (result == NULL) return; + hdrl_image_delete(result->correction); + cpl_image_delete(result->contribution); + cpl_image_delete(result->chi2); + cpl_image_delete(result->red_chi2); + cpl_image_delete(result->sigclip_reject_low); + cpl_image_delete(result->sigclip_reject_high); + cpl_free(result); + return; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Overscan correction + @param source Input HDRL image that needs to be corrected + @param region Region from source that needs correction + @param os_computation Results of the Overscan computation + @return hdrl_overscan_correct_result structure containing the + results of the correction. It must be freed with + hdrl_overscan_correct_result_delete() + On error, NULL is returned and an error code is set. + + source is the input CPL image that needs to be corrected. It is a required + input. + Usually the same image is passed to hdrl_overscan_compute() to compute + the overscan correction parameters. + + source_error is the error used for error propagation. It is a required input. + + region specifies which region of the source image must be corrected. + If NULL or invalid, the whole image is corrected. + The region size must fit the sixe of the os_computation. + + os_computation contains all the parameters for the overscan + correction. It has been produced by hdrl_overscan_compute(). + + Following results are available from the return value: + + hdrl_overscan_correct_result_get_corrected(result): + returns the HDRL image of type double of the same size as source. + + Its image part contains the corrected values where all the pixels + within the specified region were subtracted using the proper correction + obtained in os_computation.correction. + The pixels outside the specified region remain unchanged. + Pixels for which a overscan value could not be determined (e.g. because all + pixels in the overscan region are bad) are set to zero. + + Its error part contains the error where all the pixels within the specified + region are set to: \f$\sqrt{(os\_computation.error^2 + source\_error^2)}\f$, which is + the standard Gaussian error propagation. + The pixels outside the specified region remain unchanged. + Pixels for which a overscan value could not be determined (e.g. because all + pixels in the overscan region are bad) are set to zero. + + hdrl_overscan_correct_result_get_badmask(result): + returns an integer cpl_image of the same size as the input that contains a + value of 1 for pixels that have not been corrected due to the overscan data + being bad in that row/column. + */ +/*----------------------------------------------------------------------------*/ +hdrl_overscan_correct_result * hdrl_overscan_correct( + const hdrl_image * source, + const hdrl_parameter * region, + const hdrl_overscan_compute_result * os_computation) +{ + cpl_size llx = 0, lly = 0, urx = 0, ury = 0; + /* local pointers to source image and its error */ + cpl_image * source_loc = NULL; + cpl_image * source_error_loc = NULL; + long xsize_overscan = 0; + long ysize_overscan = 0; + size_t nx; + cpl_mask * orig_mask = NULL; + hdrl_image * hoverscan; + /* value to use in mask for pixels rejected by algorithm */ + hdrl_bitmask_t reject_code = 1; + + /* Check Entries */ + cpl_error_ensure(source != NULL, CPL_ERROR_NULL_INPUT, + return NULL, "NULL input source image"); + cpl_error_ensure(os_computation != NULL, CPL_ERROR_NULL_INPUT, + return NULL, "NULL overscan computation result"); + + cpl_error_ensure(hdrl_int_is_power_of_two(reject_code), + CPL_ERROR_ILLEGAL_INPUT, return NULL, + "reject_code must be a power of two"); + + if (hdrl_overscan_compute_result_verify(os_computation) != CPL_ERROR_NONE) + return NULL; + + hoverscan = os_computation->correction; + + /* Initialise Region parameters */ + if (region != NULL) { + if (hdrl_rect_region_parameter_verify(region, + hdrl_image_get_size_x(source), + hdrl_image_get_size_y(source)) != CPL_ERROR_NONE) + return NULL; + llx = hdrl_rect_region_get_llx(region); + lly = hdrl_rect_region_get_lly(region); + urx = hdrl_rect_region_get_urx(region); + ury = hdrl_rect_region_get_ury(region); + } else { + llx = lly = 1; + urx = hdrl_image_get_size_x(source); + ury = hdrl_image_get_size_y(source); + } + + source_loc = + cpl_image_cast(hdrl_image_get_image_const(source), HDRL_TYPE_DATA); + source_error_loc = + cpl_image_cast(hdrl_image_get_error_const(source), HDRL_TYPE_ERROR); + nx = cpl_image_get_size_x(source_loc); + + xsize_overscan = hdrl_image_get_size_x(hoverscan); + ysize_overscan = hdrl_image_get_size_y(hoverscan); + + /* Check if the overscan image has an appropriate size */ + if (os_computation->correction_direction == HDRL_X_AXIS && + ury-lly+1 != ysize_overscan) { + cpl_image_delete(source_loc); + cpl_image_delete(source_error_loc); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Correction region Y size does not match overscan Y size"); + return NULL; + } + if (os_computation->correction_direction == HDRL_Y_AXIS && + urx-llx+1 != xsize_overscan) { + cpl_image_delete(source_loc); + cpl_image_delete(source_error_loc); + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "Correction region X size does not match overscan X size"); + return NULL; + } + + if (xsize_overscan != 1 && ysize_overscan != 1) { + cpl_image_delete(source_loc); + cpl_image_delete(source_error_loc); + cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + return NULL; + } + + /* store original mask to later separate it from newly created bpms */ + orig_mask = hdrl_copy_image_mask(source_loc); + + { + hdrl_data_t * psource_loc = cpl_image_get_data(source_loc); + hdrl_error_t * psource_err_loc = cpl_image_get_data(source_error_loc); + const cpl_mask * bpm = hdrl_image_get_mask_const(hoverscan); + /* os image is one dimensional, so just get the data */ + const cpl_binary * rej = bpm ? cpl_mask_get_data_const(bpm) : NULL; + const hdrl_data_t * pos_val = hdrl_get_image_data_const( + hdrl_image_get_image_const(hoverscan)); + const hdrl_error_t * pos_e = hdrl_get_image_error_const( + hdrl_image_get_error_const(hoverscan)); + /* make sure we have a bpm before the parallel loop */ + cpl_image_get_bpm(source_loc); + + /* corrects extracted image for over-scan value, compute associated + * error, flag bad pixels */ +HDRL_OMP(omp parallel for) + for (long j = lly - 1; j < ury; j++) { + for (long i = llx - 1; i < urx; i++) { + const size_t idx = + os_computation->correction_direction == HDRL_X_AXIS ? + j-lly+1 : i-llx+1; + double ima_e = psource_err_loc[j * nx + i]; + + if (rej && rej[idx]) { + /* set to zero as per requirements */ + cpl_image_reject(source_loc, i + 1, j + 1); + psource_loc[j * nx + i] = 0; + psource_err_loc[j * nx + i] = 0; + } else { + psource_loc[j * nx + i] -= pos_val[idx]; + psource_err_loc[j * nx + i] = + sqrt(pos_e[idx] * pos_e[idx] + ima_e * ima_e); + } + } + } + } + + { + hdrl_overscan_correct_result * res; + cpl_mask * new_mask = hdrl_copy_image_mask(source_loc); + cpl_image * badmask = cpl_image_new(cpl_image_get_size_x(source_loc), + cpl_image_get_size_y(source_loc), + CPL_TYPE_INT); + /* get the new bad pixels */ + cpl_mask_xor(new_mask, orig_mask); + /* fill them with the code */ + cpl_image_reject_from_mask(badmask, new_mask); + cpl_image_fill_rejected(badmask, reject_code); + + cpl_mask_delete(new_mask); + cpl_mask_delete(orig_mask); + + /* Create, fill and return the returned structure */ + res = hdrl_overscan_correct_result_create(); + res->corrected = hdrl_image_wrap(source_loc, source_error_loc, NULL, + CPL_TRUE); + res->badmask = badmask; + return res; + } +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Delete the Overscan Correction Result Structure + @param result The correction result structure to delete + */ +/*----------------------------------------------------------------------------*/ +void hdrl_overscan_correct_result_delete( + hdrl_overscan_correct_result * result) +{ + if (result == NULL) return; + hdrl_image_delete(result->corrected); + cpl_image_delete(result->badmask); + cpl_free(result); + return; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the corrected image in the Overscan Correction result object + @param res The Overscan Correction result object + @return The HDLR corrected image + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * hdrl_overscan_correct_result_get_corrected( + const hdrl_overscan_correct_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + return res->corrected; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the corrected image in the Overscan Correction result object + @param res The Overscan Correction result object + @return The HDLR corrected image that was unset + */ +/*----------------------------------------------------------------------------*/ +hdrl_image * hdrl_overscan_correct_result_unset_corrected( + hdrl_overscan_correct_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + hdrl_image * r = res->corrected; + res->corrected = NULL; + return r; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Access the bad pixels mask in the Overscan Correction result object + @param res The Overscan Correction result object + @return The bad pixels mask as a CPL image + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_correct_result_get_badmask( + const hdrl_overscan_correct_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + return res->badmask; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unset the bad pixels mask in the Overscan Correction result object + @param res The Overscan Correction result object + @return The bad pixels mask as a CPL image that was unset + */ +/*----------------------------------------------------------------------------*/ +cpl_image * hdrl_overscan_correct_result_unset_badmask( + hdrl_overscan_correct_result * res) +{ + cpl_ensure(res, CPL_ERROR_NULL_INPUT, NULL); + cpl_image * r = res->badmask; + res->badmask = NULL; + return r; +} + +/**@}*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Destroys Overscan Parameters objects + @param param The parameter to destroy + */ +/*----------------------------------------------------------------------------*/ +static void hdrl_overscan_parameter_destroy(void * param) +{ + hdrl_overscan_parameter * p = (hdrl_overscan_parameter *)param ; + hdrl_parameter_destroy(p->collapse) ; + hdrl_parameter_destroy(p->rect_region) ; + hdrl_parameter_delete((hdrl_parameter*)param) ; + return ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Creates Overscan Computation Result Structure + @return A structure that needs to be de-allocated with + hdrl_overscan_compute_result_delete() + @see hdrl_overscan_compute_result_delete() + */ +/*----------------------------------------------------------------------------*/ +static hdrl_overscan_compute_result * hdrl_overscan_compute_result_create( + void) +{ + hdrl_overscan_compute_result * self = + cpl_malloc(sizeof(hdrl_overscan_compute_result)); + + self->correction_direction = HDRL_UNDEFINED_AXIS; + self->correction = NULL; + self->contribution = NULL; + self->chi2 = NULL; + self->red_chi2 = NULL; + self->sigclip_reject_low = NULL; + self->sigclip_reject_high = NULL; + return self; +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Verify basic correctness of the result structure + @param result Overscan result structure + @return CPL_ERROR_NONE if eveything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_compute_result_verify( + const hdrl_overscan_compute_result * result) +{ + cpl_error_ensure(result != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, + "NULL input overscan result structure"); + cpl_error_ensure(result->correction_direction == HDRL_X_AXIS || + result->correction_direction == HDRL_Y_AXIS, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The specified collapse direction is unknown"); + + if (result->correction_direction == HDRL_X_AXIS) { + cpl_error_ensure(hdrl_image_get_size_x(result->correction) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The Correction image X size should be 1"); + cpl_error_ensure(cpl_image_get_size_x(result->contribution) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The Contribution image X size should be 1"); + cpl_error_ensure(cpl_image_get_size_x(result->chi2) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The Chi Square image X size should be 1"); + cpl_error_ensure(cpl_image_get_size_x(result->red_chi2) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The reduced Chi Square image X size should be 1"); + if (result->sigclip_reject_low != NULL) { + cpl_error_ensure(cpl_image_get_size_x(result->sigclip_reject_low) + == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The SIGCLIP low rejection image X size should be 1"); + + } + if (result->sigclip_reject_high != NULL) { + cpl_error_ensure(cpl_image_get_size_x(result->sigclip_reject_high) + == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The SIGCLIP high rejection image X size should be 1"); + } + } + else if (result->correction_direction == HDRL_Y_AXIS) { + cpl_error_ensure(hdrl_image_get_size_y(result->correction) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The Correction image Y size should be 1"); + cpl_error_ensure(cpl_image_get_size_y(result->contribution) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The Contribution image Y size should be 1"); + cpl_error_ensure(cpl_image_get_size_y(result->chi2) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The Chi Square image Y size should be 1"); + cpl_error_ensure(cpl_image_get_size_y(result->red_chi2) == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The reduced Chi Square image Y size should be 1"); + if (result->sigclip_reject_low != NULL) { + cpl_error_ensure(cpl_image_get_size_y(result->sigclip_reject_low) + == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The SIGCLIP low rejection image Y size should be 1"); + + } + if (result->sigclip_reject_high != NULL) { + cpl_error_ensure(cpl_image_get_size_y(result->sigclip_reject_high) + == 1, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "The SIGCLIP high rejection image Y size should be 1"); + } + } + else return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "correction_direction must be HDRL_X_AXIS or HDRL_Y_AXIS"); + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Creates Overscan Correction result structure + @return A structure holding the Overscan Correction Results, that + needs to be de-allocated with hdrl_overscan_correct_result_delete() + @see hdrl_overscan_correct_result_delete() + */ +/*----------------------------------------------------------------------------*/ +static hdrl_overscan_correct_result * hdrl_overscan_correct_result_create( + void) +{ + hdrl_overscan_correct_result * self = cpl_malloc(sizeof(*self)); + self->corrected = NULL; + self->badmask = NULL; + return self; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Calculate chi square as well as the reduced chi square + @param data Measured data image + @param error Error of measured data image + @param expect Expected value of data + @param[out] chi2 Weighted sum of squared deviations + @param[out] red_chi2 Reduced weighted sum of squared deviations + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_compute_chi_square( + const cpl_image * data, + const cpl_image * error, + const double expect, + double * chi2, + double * red_chi2) +{ + cpl_image * s; + cpl_size nrej, nerej; + cpl_image * e = NULL; + cpl_size nepix = 0; + cpl_size npix = 0; + + nrej = cpl_image_count_rejected(data); + npix = cpl_image_get_size_x(data) * cpl_image_get_size_y(data); + + if (nrej == npix) { + *chi2 = NAN; + *red_chi2 = NAN; + return CPL_ERROR_NONE; + } + + e = cpl_image_duplicate(error); + nepix = cpl_image_get_size_x(e) * cpl_image_get_size_y(e); + + /*TODO handle pre-existing Zero's marked as bad */ + /* check if error image contains zeros */ + cpl_image_accept_all(e); + cpl_image_reject_value(e, CPL_VALUE_ZERO); + nerej = cpl_image_count_rejected(e); + /* all errors zero allowed */ + if (nerej == nepix) { + cpl_image_delete(e); + *chi2 = NAN; + *red_chi2 = NAN; + return CPL_ERROR_NONE; + } + /* partial zero errors make no sense */ + else if (nerej != 0) { + cpl_image_delete(e); + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Error image can't contain zeros"); + *chi2 = NAN; + *red_chi2 = NAN; + return CPL_ERROR_ILLEGAL_INPUT; + } + + s = cpl_image_duplicate(data); + /* computes chi squared defined as: + * \Sum_i[ (x_i - expect)^2 / sigma_i^2 ] */ + cpl_image_subtract_scalar(s, expect); + cpl_image_divide(s, e); + *chi2 = cpl_image_get_sqflux(s); /* = squared sum */ + *red_chi2 = *chi2 / npix; /* reduced chi2 */ + cpl_image_delete(s); + cpl_image_delete(e); + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief reduce image to scalar + @param red imagelist to vector reduction method + @param data image to reduce + @param data_error error of image + @param result data reduction result + @param error propagated error + @param contribution number of pixels that contributed + @param eout extra output for sigclip + @return A CPL error code + + this is just a single image wrapper over hdrl_collapse_imagelist_to_vector + */ +/* ---------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_reduce_image_to_scalar( + hdrl_collapse_imagelist_to_vector_t * red, + cpl_image * data, + cpl_image * data_error, + double * result, + double * error, + cpl_size * contribution, + void ** eout) +{ + cpl_imagelist * ld = cpl_imagelist_new(); + cpl_imagelist * le = cpl_imagelist_new(); + cpl_vector * od = NULL, * oe = NULL; + cpl_array * oc = NULL; + cpl_error_code fail; + cpl_imagelist_set(ld, data, 0); + cpl_imagelist_set(le, data_error, 0); + + + fail = hdrl_collapse_imagelist_to_vector_call(red, ld, le, &od, &oe, &oc, + eout); + cpl_imagelist_unwrap(ld); + cpl_imagelist_unwrap(le); + + if (fail == CPL_ERROR_NONE) { + *result = cpl_vector_get(od, 0); + *error = cpl_vector_get(oe, 0); + *contribution = cpl_array_get_int(oc, 0, NULL); + } + else { + *result = NAN; + *error = NAN; + *contribution = 0; + } + + cpl_vector_delete(od); + cpl_vector_delete(oe); + cpl_array_delete(oc); + + return fail; +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_overscan_defs.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_overscan_defs.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_overscan_defs.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_overscan_defs.h 2013-11-20 10:03:29.000000000 +0000 @@ -0,0 +1,79 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_OVERSCAN_DEFS_H +#define HDRL_OVERSCAN_DEFS_H + +#ifndef HDRL_USE_PRIVATE +#error This file is not allowed to be included outside of hdrl +#endif + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include + +CPL_BEGIN_DECLS + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + @struct _hdrl_overscan_compute_result_ + @brief Contains the Overscan Computation results + */ +/*----------------------------------------------------------------------------*/ +struct _hdrl_overscan_compute_result_ +{ + /** The direction in which the image were collapsed in the computation */ + hdrl_direction correction_direction; + /** The overscan correction as a 1D double image */ + hdrl_image * correction; + /** The number of good pixels that contributed as a 1D double image */ + cpl_image * contribution; + /** The \f$\chi^{2}\f$ as a 1D double image */ + cpl_image * chi2; + /** The reduced \f$\chi^{2}\f$ as a 1D double image */ + cpl_image * red_chi2; + /** The low threshold below which the pixels are rejected + as a 1D double image. Only for sigma-clipping collapsing method */ + cpl_image * sigclip_reject_low; + /** The high threshold above which the pixels are rejected + as a 1D double image. Only for sigma-clipping collapsing method */ + cpl_image * sigclip_reject_high; +}; + +/*----------------------------------------------------------------------------*/ +/** + @struct _hdrl_overscan_correct_result_ + @brief Contains the Overscan Correction results + */ +/*----------------------------------------------------------------------------*/ +struct _hdrl_overscan_correct_result_ +{ + /** The Overscan corrected image */ + hdrl_image * corrected; + /** Pixels marked as bad by algorithm, encoded by user choice */ + cpl_image * badmask; +}; + +/** @endcond */ + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_overscan.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_overscan.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_overscan.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_overscan.h 2014-09-04 14:48:18.000000000 +0000 @@ -0,0 +1,146 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifndef HDRL_OVERSCAN_H +#define HDRL_OVERSCAN_H + +/*----------------------------------------------------------------------------- + Include + -----------------------------------------------------------------------------*/ + +#include "hdrl_utils.h" +#include "hdrl_image.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +#define HDRL_OVERSCAN_FULL_BOX -1 +typedef struct _hdrl_overscan_compute_result_ hdrl_overscan_compute_result; +typedef struct _hdrl_overscan_correct_result_ hdrl_overscan_correct_result; + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + Overscan Computation Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_overscan_parameter_create(hdrl_direction, double, int, + hdrl_parameter *, hdrl_parameter *) ; +cpl_error_code hdrl_overscan_parameter_verify(const hdrl_parameter *, + cpl_size, cpl_size) ; +cpl_boolean hdrl_overscan_parameter_check(const hdrl_parameter *) ; + +/* Accessors */ +hdrl_direction hdrl_overscan_parameter_get_correction_direction( + const hdrl_parameter *) ; +double hdrl_overscan_parameter_get_ccd_ron(const hdrl_parameter *) ; +int hdrl_overscan_parameter_get_box_hsize(const hdrl_parameter *) ; +hdrl_parameter * hdrl_overscan_parameter_get_collapse(const hdrl_parameter *) ; +hdrl_parameter * hdrl_overscan_parameter_get_rect_region(const hdrl_parameter*); + +/* Parameter Lists */ +cpl_parameterlist * hdrl_overscan_parameter_create_parlist(const char *, + const char *, const char *, int, double, + hdrl_parameter *, const char *, hdrl_parameter *, hdrl_parameter *) ; +hdrl_parameter * hdrl_overscan_parameter_parse_parlist( + const cpl_parameterlist *, const char *) ; + +/*---------------------------------------------------------------------------- + Overscan Computation + ----------------------------------------------------------------------------*/ +hdrl_overscan_compute_result * hdrl_overscan_compute( + const cpl_image * source, + const hdrl_parameter * params) ; + +/*---------------------------------------------------------------------------- + Overscan Computation Result + ----------------------------------------------------------------------------*/ +hdrl_image * hdrl_overscan_compute_result_get_correction( + const hdrl_overscan_compute_result *); +hdrl_image * hdrl_overscan_compute_result_unset_correction( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_contribution( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_contribution( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_chi2( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_chi2( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_red_chi2( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_red_chi2( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_sigclip_reject_low( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_sigclip_reject_low( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_sigclip_reject_high( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_sigclip_reject_high( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_minmax_reject_low( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_minmax_reject_low( + hdrl_overscan_compute_result *); + +cpl_image * hdrl_overscan_compute_result_get_minmax_reject_high( + const hdrl_overscan_compute_result *); +cpl_image * hdrl_overscan_compute_result_unset_minmax_reject_high( + hdrl_overscan_compute_result *); + +void hdrl_overscan_compute_result_delete(hdrl_overscan_compute_result *); + +/*---------------------------------------------------------------------------- + Overscan Correction + ----------------------------------------------------------------------------*/ +hdrl_overscan_correct_result * hdrl_overscan_correct( + const hdrl_image * source, + const hdrl_parameter * region, + const hdrl_overscan_compute_result * os_computation) ; + +/*---------------------------------------------------------------------------- + Overscan Correction Result + ----------------------------------------------------------------------------*/ +hdrl_image * hdrl_overscan_correct_result_get_corrected( + const hdrl_overscan_correct_result *); +hdrl_image * hdrl_overscan_correct_result_unset_corrected( + hdrl_overscan_correct_result *); + +cpl_image * hdrl_overscan_correct_result_get_badmask( + const hdrl_overscan_correct_result *); +cpl_image * hdrl_overscan_correct_result_unset_badmask( + hdrl_overscan_correct_result *); +void hdrl_overscan_correct_result_delete(hdrl_overscan_correct_result *); + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_parameter.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_parameter.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_parameter.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_parameter.c 2017-08-23 11:09:43.000000000 +0000 @@ -0,0 +1,178 @@ +/* $Id: hdrl_parameter.c,v 1.3 2013-10-10 13:47:35 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-10 13:47:35 $ + * $Revision: 1.3 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_parameter.h" +#include "hdrl_parameter_defs.h" +#include + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_parameter Parameter object + * + * The hdrl_parameter is the base object to store various hierarchical + * parameters. It only provides the deletion functions, the parameters + * themselves are implemented in their respective modules. + * + * @internal + * see hdrl_parameter-test.c for an example usage + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/**@{*/ + +/** @cond PRIVATE */ + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief create new parameter of certain type + * + * @param type type object which defines the type of the parameter + * + * @return hdrl_parameter of type 'typeobj' + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_parameter_new(const hdrl_parameter_typeobj * typeobj) +{ + hdrl_parameter * p = typeobj->fp_alloc(typeobj->obj_size); + p->base = typeobj; + return p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief check if a parameter is of a certain type + * + * @param self parameter to check + * @param type type required + * + * @return true iff parameter is of type "type" + */ +/* ---------------------------------------------------------------------------*/ +int hdrl_parameter_check_type(const hdrl_parameter * self, + const hdrl_parameter_typeobj * type) +{ + /* we can't compare the base pointers as they may be different in recipes + * and libraries when static linking */ + if (self) { + return ((const hdrl_parameter_typeobj *)self->base)->type == type->type; + } + else { + return 0; + } +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get typeobject of parameter + * + * @param self parameter to check + * @return pointer to type object + * + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_parameter_typeobj * hdrl_parameter_get_type(const hdrl_parameter * self) +{ + return self->base; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get enum of parameter + * + * @param self parameter to check + * @return pointer to type object + * + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter_enum +hdrl_parameter_get_parameter_enum(const hdrl_parameter * self){ + return hdrl_parameter_get_type(self)->type; +} + +/** @endcond */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief shallow delete of a parameter + * + * @param obj parameter to delete, may be NULL + * + * will not delete sub parameters + * @see hdrl_parameter_destroy + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_parameter_delete(hdrl_parameter * obj) +{ + if (obj) { + obj->base->fp_free(obj); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief deep delete of a parameter + * + * @param obj parameter to delete, may be NULL + * + * deletes all sub parameters via the registered deep destructor + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_parameter_destroy(hdrl_parameter * obj) +{ + if (obj == NULL) { + return; + } + + if (obj->base->fp_destroy) { + obj->base->fp_destroy(obj); + } + else { + obj->base->fp_free(obj); + } +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_parameter_defs.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_parameter_defs.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_parameter_defs.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_parameter_defs.h 2013-11-26 14:24:14.000000000 +0000 @@ -0,0 +1,51 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_PARAMETER_DEFS_H +#define HDRL_PARAMETER_DEFS_H + +#ifndef HDRL_USE_PRIVATE +#error This file is not allowed to be included outside of hdrl +#endif + +#include "hdrl_parameter.h" + +#include + +/** @cond PRIVATE */ + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief base class of hdrl_parameter + * + * needs to be the first element of each child class structure, e.g: + * struct { + * HDRL_PARAMETER_HEAD; + * int val; + * } child_class; + */ +/* ---------------------------------------------------------------------------*/ +struct _hdrl_parameter_ { + const hdrl_parameter_typeobj * base; +}; + +/** @endcond */ + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_parameter.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_parameter.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_parameter.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_parameter.h 2017-08-17 09:12:33.000000000 +0000 @@ -0,0 +1,152 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifndef HDRL_PARAMETER_H +#define HDRL_PARAMETER_H + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + +typedef struct _hdrl_parameter_ hdrl_parameter; + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_types.h" +#include "hdrl_utils.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +void hdrl_parameter_delete(hdrl_parameter * obj); +void hdrl_parameter_destroy(hdrl_parameter * obj); + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ +#ifdef HDRL_USE_PRIVATE + +/** + * @brief parameter registry + * required as typeobject pointer is not unique when doing static linking + */ +typedef enum { + HDRL_PARAMETER_COLLAPSE_MEAN, + HDRL_PARAMETER_COLLAPSE_MEDIAN, + HDRL_PARAMETER_COLLAPSE_WEIGHTED_MEAN, + HDRL_PARAMETER_COLLAPSE_SIGCLIP, + HDRL_PARAMETER_COLLAPSE_MINMAX, + HDRL_PARAMETER_RECT_REGION, + HDRL_PARAMETER_OVERSCAN, + HDRL_PARAMETER_BPM_2D, + HDRL_PARAMETER_BPM_3D, + HDRL_PARAMETER_BPM_FIT, + HDRL_PARAMETER_LACOSMIC, + HDRL_PARAMETER_STREHL, + HDRL_PARAMETER_FLAT, + HDRL_PARAMETER_CATALOGUE, + HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTERPOLATE, + HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT, + HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTEGRATE, + HDRL_PARAMETER_SPECTRUM1D_SHIFT, + HDRL_PARAMETER_EFFICIENCY, + HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + HDRL_PARAMETER_RESPONSE_FIT, + HDRL_PARAMETER_DAR +} hdrl_parameter_enum; + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief required first member of each parameter object + * + * struct { + * HDRL_PARAMETER_HEAD; + * int val; + * } my_parameter; + */ +/* ---------------------------------------------------------------------------*/ +#define HDRL_PARAMETER_HEAD void * base + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief Base type object / object metadata + * + * Defines required object meta data of the parameter. + * Each object contains a reference to one of these so it can determine which + * functions to call on certain operations. + * Usually a single statically allocated type object shared between multiple + * hdrl_parameter objects of the same type. + * @see hdrl_parameter_new + */ +/* ---------------------------------------------------------------------------*/ +typedef struct { + /* enum defining type */ + hdrl_parameter_enum type; + /* base parameter structure allocation, e.g. cpl_malloc */ + hdrl_alloc * fp_alloc; + /* shallow destructor of the parameter */ + hdrl_free * fp_free; + /* deep destructor of the parameter, deletes all childs + * may be NULL in which case fp_free is used */ + hdrl_free * fp_destroy; + /* size of the base parameter structure, argument to fp_alloc */ + size_t obj_size; +} hdrl_parameter_typeobj; + + +/* empty parameter, e.g. for collapse_mean */ +typedef struct { + HDRL_PARAMETER_HEAD; +} hdrl_parameter_empty; + +hdrl_parameter * +hdrl_parameter_new(const hdrl_parameter_typeobj * typeobj); + +const hdrl_parameter_typeobj * +hdrl_parameter_get_type(const hdrl_parameter * self); + +hdrl_parameter_enum +hdrl_parameter_get_parameter_enum(const hdrl_parameter * self); + +int +hdrl_parameter_check_type(const hdrl_parameter * self, + const hdrl_parameter_typeobj * type); + +/* create a singleton parameter which does not need allocating or deleting a + * comon use case are enum like parameters */ +#define HDRL_PARAMETER_SINGLETON(name, type, alloc) \ +hdrl_parameter * name = &(hdrl_parameter){ &type }; \ +static void * alloc(size_t HDRL_UNUSED(n)) \ +{ \ + return name; \ +} + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_prototyping.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_prototyping.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_prototyping.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_prototyping.c 2017-10-04 06:06:09.000000000 +0000 @@ -0,0 +1,1277 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_prototyping.h" + +#include +#include +#include +#include +#include + +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + + +static cpl_image *hdrl_mirror_edges(cpl_image *image, int dx, int dy); +static cpl_image *hdrl_gen_lowpass(int xs, int ys, double sigma_x, + double sigma_y); + + + +/** Function to calculate the low spatial frequency +* +* @brief Get low spatial frequency componenets from an image using the FFTW +* @param ima image +* @param gausfilt Gaussian Fourier filter size +* @param mirrorx for mirroring edges (ocfft continuity) +* @param mirrory for mirroring edges (ocfft continuity) +* +* @return 1 newly allocated image. +*/ +cpl_image * hdrl_get_spatial_freq(cpl_image *ima, double gausfilt, int mirrorx, + int mirrory){ + + int xsize=0, ysize=0; + + double sigma_x = 0.; + double sigma_y = 0.; + + cpl_image *clean_flat; + cpl_image *eflat; + cpl_image *eflat_complex=NULL; + cpl_image *eflat_real=NULL; + + cpl_image *filter_image=NULL; + cpl_image *filter_image_complex=NULL; + cpl_image *flat_real; + + + /*Clean flat from bad pixels if bpm exists*/ + //clean_flat = cpl_image_duplicate(flat); + + /*The algorithm uses float, so we have to cast here or change the algo...*/ + cpl_type ima_type = cpl_image_get_type(ima); + + clean_flat = cpl_image_cast(ima, CPL_TYPE_FLOAT); + cpl_detector_interpolate_rejected(clean_flat); + + + /* Expand the flat image using the mirror edges function */ + eflat = hdrl_mirror_edges(clean_flat, mirrorx, mirrory); + + if (clean_flat != NULL) { + cpl_image_delete(clean_flat); + clean_flat = NULL; + } + + if(eflat == NULL){ + cpl_msg_error(cpl_func,"Filter image is NULL"); + return NULL; + } + + xsize = cpl_image_get_size_x(eflat); + ysize = cpl_image_get_size_y(eflat); + + sigma_x = gausfilt; + sigma_y = (double)(sigma_x * ysize) / xsize; + + + /* Generate a lowpass filter to be used in the FFT convolution */ + filter_image = hdrl_gen_lowpass(xsize, ysize, sigma_x, sigma_y); + if(filter_image == NULL){ + cpl_msg_error(cpl_func,"Filter image is NULL"); + cpl_image_delete(eflat); + return NULL; + } + + eflat_complex = cpl_image_new(xsize,ysize, CPL_TYPE_FLOAT_COMPLEX); + eflat_real = cpl_image_new(xsize,ysize, CPL_TYPE_FLOAT); + filter_image_complex =cpl_image_cast(filter_image,CPL_TYPE_FLOAT_COMPLEX); + + /*Free memory*/ + cpl_image_delete(filter_image); + + + /* Apply a forward FFT on the images */ + cpl_fft_image(eflat_complex, eflat, CPL_FFT_FORWARD); + /*Free memory*/ + cpl_image_delete(eflat); + + /*Multiply the filter with the the FFT image */ + cpl_image_multiply(eflat_complex,filter_image_complex); + + + /* Apply a backward FFT on the images */ + cpl_fft_image(eflat_real, eflat_complex,CPL_FFT_BACKWARD); + /*Free memory*/ + cpl_image_delete(eflat_complex); + cpl_image_delete(filter_image_complex); + + /* Extract original image from the expanded image. */ + flat_real = cpl_image_extract(eflat_real, mirrorx+1, mirrory+1, + xsize-mirrorx, ysize-mirrory); + + if (flat_real == NULL) { + cpl_msg_error (cpl_func,"Real extracted image is NULL. <%s>", cpl_error_get_message()); + return NULL; + } + cpl_image_delete(eflat_real); + + cpl_image * out_double = cpl_image_cast(flat_real, ima_type); + cpl_image_delete(flat_real); + return out_double; +} + +/*-------------------------------------------------------------------------*/ +/** +@brief Generate a low pass filter for FFT convolution . +@param xs x size of the generated image. +@param ys y size of the generated image. +@param sigma_x Sigma for the gaussian distribution. +@param sigma_y Sigma for the gaussian distribution. +@return 1 newly allocated image. + +This function generates an image of a 2d gaussian, modified in such +a way that the different quadrants have a quadrants of the gaussian +in the corner. This image is suitable for FFT convolution. +Copied from eclipse, src/iproc/generate.c + +The returned image must be deallocated. +*/ +/*--------------------------------------------------------------------------*/ +static cpl_image * hdrl_gen_lowpass(int xs, int ys, double sigma_x, + double sigma_y) +{ + + int i= 0.0; + int j= 0.0; + int hlx= 0.0; + int hly = 0.0; + double x= 0.0; + double gaussval= 0.0; + float *data; + + cpl_image *lowpass_image; + + + lowpass_image = cpl_image_new (xs, ys, CPL_TYPE_FLOAT); + if (lowpass_image == NULL) { + cpl_msg_error (cpl_func, "Cannot generate lowpass filter <%s>",cpl_error_get_message()); + return NULL; + } + + hlx = xs/2; + hly = ys/2; + + data = cpl_image_get_data_float(lowpass_image); + + /* Given an image with pixels 0<=i= 2) + for (i = 0; i < nr; i++, m += npoly) + m[1] = scale * (mx[i] - midpoint); + +/* filling the remaining columns by recursion + * j P'_j(x) = (2j-1)xP'_{j-1}(x) - (j-1)P'_{j-2}(x) + * with P'(x) = P((2x - b - a)/(b - a)) for orthogonality in [-1, 1]->[a, b] */ + m = cpl_matrix_get_data(polys); + for (i = 0; i < nr; i++, m += npoly) + { + double xi = scale * (mx[i] - midpoint); + for (j = 2; j < npoly; j++) + { + double alpha = (2.0 * j - 1.0) / j; + double beta = (j - 1.0) / j; + m[j] = alpha * xi * m[j - 1] - beta * m[j - 2]; + } + } + + return polys; +} +/*---------------------------------------------------------------------------*/ + /** + * @brief Create selected pairwise tensor products of the columns of two + * matrices. + * + * @param mat1 A matrix, + * @param mat2 A matrix. + * + * @return The tensor product of pairs the columns of the two matrices. + * + * The tensor product of the j1-th and j2-th columns is created iff + * j1*(nc2-1) + j2*(nc1-1) <= (nc1-1)*(nc2-1). The two matrices may + * have different dimensions. + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_linalg_pairwise_column_tensor_products_create(const + cpl_matrix * mat1, const cpl_matrix * mat2) +{ + cpl_matrix *tensor; + cpl_matrix *repl1; + cpl_matrix *repl2; + + int nc1, nc2; + int j1, j2, nc, col_count; + +/* testing input */ + if (mat1 == NULL || mat2 == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + +/* initializing */ + nc1 = cpl_matrix_get_ncol(mat1); + nc2 = cpl_matrix_get_ncol(mat2); + +/* counting the admissible pairs */ + nc = 0; + for (j1 = 0; j1 < nc1; j1++) + { + for (j2 = 0; j2 < nc2; j2++) + nc += (j1 * (nc2 - 1) + j2 * (nc1 - 1) <= + (nc1 - 1) * (nc2 - 1) ? 1 : 0); + } + +/* replicating the columns */ + repl1 = cpl_matrix_new(cpl_matrix_get_nrow(mat1), nc); + repl2 = cpl_matrix_new(cpl_matrix_get_nrow(mat2), nc); + col_count = 0; + + for (j1 = 0; j1 < nc1; j1++) + { + for (j2 = 0; j2 < nc2; j2++) + { + if (j1 * (nc2 - 1) + j2 * (nc1 - 1) <= (nc1 - 1) * (nc2 - 1)) + { + hdrl_mime_matrix_copy_column(mat1, j1, repl1, col_count); + hdrl_mime_matrix_copy_column(mat2, j2, repl2, col_count); + col_count++; + } + } + } + +/* filling the matrix with the tensor products */ + tensor = hdrl_mime_linalg_tensor_products_columns_create(repl1, repl2); + cpl_matrix_delete(repl1); + cpl_matrix_delete(repl2); + + return tensor; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Copy a column from one matrix to another matrix. + * + * @param mat1 The matrix whose column is copied, + * @param j_1 The index of the column to be copied, + * @param[in,out] mat2 The matrix whose column is overwritten, + * @param[in,out] j_2 The index of the column to be overwritten. + * + * @return @c CPL_ERROR_NONE or the appropriate error code. + * + * Both matrices must have the same number of rows. + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code hdrl_mime_matrix_copy_column(const cpl_matrix * mat1, int j_1, + cpl_matrix * mat2, int j_2) +{ + const double *m1; + double *m2; + int i, nr, nc1, nc2; + +/* testing input */ + if (mat1 == NULL || mat2 == NULL) + return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + + if (cpl_matrix_get_nrow(mat1) != cpl_matrix_get_nrow(mat2)) + return cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + + if (j_1 < 0 || j_1 >= cpl_matrix_get_ncol(mat1) || j_2 < 0 || + j_2 >= cpl_matrix_get_ncol(mat2)) + return cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + +/* initializing */ + nr = cpl_matrix_get_nrow(mat1); + nc1 = cpl_matrix_get_ncol(mat1); + nc2 = cpl_matrix_get_ncol(mat2); + m1 = cpl_matrix_get_data_const(mat1) + j_1; + m2 = cpl_matrix_get_data(mat2) + j_2; + +/* filling the column */ + for (i = 0; i < nr; i++, m1 += nc1, m2 += nc2) + *m2 = *m1; + + return CPL_ERROR_NONE; +} +/*---------------------------------------------------------------------------*/ + /** + * @brief Create the tensor products of the columns of two matrices. + * + * @param mat1 A matrix, + * @param mat2 A matrix. + * + * @return The tensor product of the columns of the two matrices. + * + * The two matrices must have the same number of columns. The result + * has dimensions (nr1*nr2) x nc. + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_linalg_tensor_products_columns_create(const cpl_matrix * + mat1, const cpl_matrix * mat2) +{ + cpl_matrix *tensor; + + const double *m1; + double *t; + int nr1, nr2, nc; + int i1; + +/* testing input */ + if (mat1 == NULL || mat2 == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (cpl_matrix_get_ncol(mat1) != cpl_matrix_get_ncol(mat2)) + { + cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + return NULL; + } + +/* initializing */ + nr1 = cpl_matrix_get_nrow(mat1); + nr2 = cpl_matrix_get_nrow(mat2); + nc = cpl_matrix_get_ncol(mat1); /* nc = cpl_matrix_get_ncol(mat2); */ + +/* allocating memory */ + tensor = cpl_matrix_new(nr1 * nr2, nc); + +/* filling the matrix with the tensor products */ + m1 = cpl_matrix_get_data_const(mat1); + t = cpl_matrix_get_data(tensor); + for (i1 = 0; i1 < nr1; i1++, m1 += nc) + { + int i2; + const double *m2; + m2 = cpl_matrix_get_data_const(mat2); + for (i2 = 0; i2 < nr2; i2++, m2 += nc, t += nc) + { + int j; + for (j = 0; j < nc; j++) + t[j] = m1[j] * m2[j]; + } + } + + return tensor; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Create tensor product weights. + * + * @param nx Number of nodes in the x-direction, + * @param ny Number of x nodes in the y-direction, + * + * @return The tensor weights + * + * The returned matrix must be deallocated using cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_tensor_weights_create(int nx, int ny) +{ + cpl_matrix *x; + cpl_matrix *y; + cpl_matrix *weights; + + double *m; + double ax, ay, bx, by, v; + int i; + +/* testing input */ + if (nx < 2 || ny < 2) + { + cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return NULL; + } + +/* setting parameters: + nx, ny numbers of the nodes in the x- and y-direction + */ + bx = 1.0 - 1.0 / nx; + ax = -bx; + + by = 1.0 - 1.0 / ny; + ay = -by; + +/* creating equally spaced nodes */ + x = hdrl_mime_matrix_linspace_create(nx, ax, bx); + y = hdrl_mime_matrix_linspace_create(ny, ay, by); + +/* creating the weights as the tensor product */ + m = cpl_matrix_get_data(x); + for (i = 0; i < nx; i++) + { + v = m[i]; + v = 1.0 / sqrt(1.0 - v * v); + m[i] = sqrt(v); + } + + m = cpl_matrix_get_data(y); + for (i = 0; i < ny; i++) + { + v = m[i]; + v = 1.0 / sqrt(1.0 - v * v); + m[i] = sqrt(v); + } + +/* switch + no weights: 1 + with weights: 0 */ + if (1) + { + cpl_matrix_fill(x, 1.0); + cpl_matrix_fill(y, 1.0); + } + + weights = hdrl_mime_linalg_pairwise_column_tensor_products_create(y, x); + +/* cleaning up */ + cpl_matrix_delete(x); + cpl_matrix_delete(y); + + return weights; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Fill matrix rows with zeros as indicated by a mask. + * + * @param mat A matrix, + * @param mask A mask flagging rows to be filled with 0.0s, + * + * @return @c CPL_ERROR_NONE or the appropriate error code. + * + * The size of @a mask must be equal to the number of rows of @a + * mat. The rows corresponding to @c CPL_BINARY_1 are set to 0.0. + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code hdrl_mime_matrix_mask_rows(cpl_matrix * mat, const cpl_mask * mask) +{ + double *m; + const cpl_binary *mk; + int i, j, nr, nc; + +/* testing input */ + if (mat == NULL || mask == NULL) + return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + + if (cpl_matrix_get_nrow(mat) != + cpl_mask_get_size_x(mask) * cpl_mask_get_size_y(mask)) + return cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + +/* initializing */ + nr = cpl_matrix_get_nrow(mat); + nc = cpl_matrix_get_ncol(mat); + m = cpl_matrix_get_data(mat); + mk = cpl_mask_get_data_const(mask); + +/* updating the rows */ + for (i = 0; i < nr; i++, mk++, m += nc) + { + if (*mk == CPL_BINARY_1) + { + for (j = 0; j < nc; j++) + m[j] = 0.0; + } + } + + return CPL_ERROR_NONE; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Multiply the rows of a matrix by given factors. + * + * @param mat A matrix, + * @param d The factors. + * @param[out] dmat The matrix with rescaled rows. + * + * @return @c CPL_ERROR_NONE or the appropriate error code. + * + * The number of rows must be equal to the size of @a d. The matrix + * @a dmat must be allocated before calling this function. + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code hdrl_mime_matrix_rescale_rows(const cpl_matrix * mat, + const cpl_matrix * d, cpl_matrix * dmat) +{ + const double *m; + const double *di; + double *dm; + int i, j, nr, nc; + +/* testing input */ + if (mat == NULL || d == NULL || dmat == NULL) + { + return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + } + + if (cpl_matrix_get_nrow(mat) != + cpl_matrix_get_nrow(d) * cpl_matrix_get_ncol(d)) + { + return cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + } + + if (cpl_matrix_get_ncol(mat) != cpl_matrix_get_ncol(dmat) || + cpl_matrix_get_nrow(mat) != cpl_matrix_get_nrow(dmat)) + { + return cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + } + +/* initializing */ + nr = cpl_matrix_get_nrow(mat); + nc = cpl_matrix_get_ncol(mat); + + m = cpl_matrix_get_data_const(mat); + di = cpl_matrix_get_data_const(d); + dm = cpl_matrix_get_data(dmat); + +/* multiplying the rows by the d[i]'s */ + for (i = 0; i < nr; i++, m += nc, dm += nc) + { + for (j = 0; j < nc; j++) + dm[j] = di[i] * m[j]; + } + + return CPL_ERROR_NONE; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Solve an overdetermined linear system in the least-squares sense. + * + * @param mat A matrix. + * @param rhs A matrix containing right-hand-side vectors. + * @param alpha The regularization parameter of the Tikhonov method. + * + * @return A matrix with solutions of the least-squares problem. + * + * Typically, this method is used for overdetermined systems, where + * the matrix has more rows than columns, but it can also be used for + * square and underdetermined systems. Several right-hand-sides can + * be provided. The regularization parameter increases with the noise + * level. + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_linalg_solve_tikhonov(const cpl_matrix * mat, + const cpl_matrix * rhs, double alpha) +{ + cpl_matrix *normal; + cpl_matrix *solution; + cpl_error_code error; + +/* testing input */ + if (mat == NULL || rhs == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (cpl_matrix_get_nrow(mat) != cpl_matrix_get_nrow(rhs)) + { + cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + return NULL; + } + +/* creating the normal equations and computing the Cholesky decomposition */ + normal = hdrl_mime_linalg_normal_equations_create(mat, alpha); + error = cpl_matrix_decomp_chol(normal); + + if (error != CPL_ERROR_NONE) + { + cpl_matrix_delete(normal); + return NULL; + } + +/* solving the normal equations and cleaning up */ + solution = hdrl_mime_matrix_product_left_transpose_create(mat, rhs); + error = cpl_matrix_solve_chol(normal, solution); + cpl_matrix_delete(normal); + + if (error != CPL_ERROR_NONE) + { + cpl_matrix_delete(solution); + return NULL; + } + + return solution; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Create the matrix transpose(A) * A + alpha for given A and alpha. + * + * @param mat Matrix, + * @param alpha The regularization parameter. + * + * @return The matrix transpose(@a mat) * @a mat + @a alpha. + * + * @note Only the upper triangle is computed, since cpl_matrix_decomp_chol() + * only requires the upper triangle. + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_linalg_normal_equations_create(const cpl_matrix * mat, + double alpha) +{ + cpl_matrix *normal; + const double *m; + double *p; + double sum; + int nr, nc; + int i, j, k; + +/* testing input */ + if (mat == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (alpha < 0.0) + { + cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return NULL; + } + +/* initializing */ + nr = cpl_matrix_get_nrow(mat); + nc = cpl_matrix_get_ncol(mat); + +/* allocating memory */ + normal = cpl_matrix_new(nc, nc); + +/* filling the normal matrix */ + p = cpl_matrix_get_data(normal); + for (i = 0; i < nc; i++, p += nc) + { + for (j = i; j < nc; j++) + { + m = cpl_matrix_get_data_const(mat); + sum = 0.0; + for (k = 0; k < nr; k++, m += nc) + sum += m[i] * m[j]; + p[j] = sum; + } + } + +/* updating the diagonal */ + p = cpl_matrix_get_data(normal); + for (i = 0; i < nc; i++) + p[nc * i + i] += alpha; + + return normal; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Create the product of the transpose of a matrix with + * another matrix. + * + * @param mat1 A matrix, + * @param mat2 A matrix. + * + * @return The product of the transpose of the first matrix with the second + * matrix. + * + * The two matrices must have the same number of rows. The product + * matrix must be deallocated with cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +cpl_matrix *hdrl_mime_matrix_product_left_transpose_create(const cpl_matrix * + mat1, const cpl_matrix * mat2) +{ + cpl_matrix *product; + + const double *m1; + const double *m2; + double *p; + double sum; + + int nr, nc, common; + int i, j, k; + +/* testing input */ + if (mat1 == NULL || mat2 == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (cpl_matrix_get_nrow(mat1) != cpl_matrix_get_nrow(mat2)) + { + cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + return NULL; + } + +/* initializing */ + nr = cpl_matrix_get_ncol(mat1); + nc = cpl_matrix_get_ncol(mat2); + common = cpl_matrix_get_nrow(mat1); + /* common = cpl_matrix_get_nrow(mat2); */ + +/* allocating memory */ + product = cpl_matrix_new(nr, nc); + p = cpl_matrix_get_data(product); + +/* filling the product matrix */ + for (i = 0; i < nr; i++, p += nc) + { + for (j = 0; j < nc; j++) + { + m1 = cpl_matrix_get_data_const(mat1); + m2 = cpl_matrix_get_data_const(mat2); + sum = 0.0; + for (k = 0; k < common; k++, m1 += nr, m2 += nc) + sum += m1[i] * m2[j]; + p[j] = sum; + } + } + + return product; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Fill a matrix with the product of two given matrices. + * + * @param mat1 A matrix, + * @param mat2 A matrix, + * @param[out] product The product of the matrices. + * + * @return @c CPL_ERROR_NONE or the appropriate error code. + * + * The number of rows of @a mat1 must be equal to the number of rows + * of @a product. The number of columns of @a mat2 must be equal to + * the number of columns of @a product. The number of columns of @a + * mat1 must be equal to the number of rows of @a mat2. + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code hdrl_mime_matrix_product(const cpl_matrix * mat1, + const cpl_matrix * mat2, cpl_matrix * product) +{ + const double *m1; + const double *m2; + double *p; + double sum; + + int nr, nc, common; + int i, j, k; + +/* testing input */ + if (mat1 == NULL || mat2 == NULL || product == NULL) + { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return CPL_ERROR_NONE; + } + + if (cpl_matrix_get_ncol(mat1) != cpl_matrix_get_nrow(mat2) || + cpl_matrix_get_nrow(mat1) != cpl_matrix_get_nrow(product) || + cpl_matrix_get_ncol(mat2) != cpl_matrix_get_ncol(product)) + { + cpl_error_set(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT); + return CPL_ERROR_NONE; + } + +/* initializing */ + nr = cpl_matrix_get_nrow(mat1); + nc = cpl_matrix_get_ncol(mat2); + common = cpl_matrix_get_ncol(mat1); /* common = cpl_matrix_get_nrow(mat2); */ + +/* filling the product matrix */ + m1 = cpl_matrix_get_data_const(mat1); + p = cpl_matrix_get_data(product); + for (i = 0; i < nr; i++, m1 += cpl_matrix_get_ncol(mat1), p += nc) + { + for (j = 0; j < nc; j++) + { + m2 = cpl_matrix_get_data_const(mat2); + sum = 0.0; + for (k = 0; k < common; k++, m2 += cpl_matrix_get_ncol(mat2)) + sum += m1[k] * m2[j]; + p[j] = sum; + } + } + + return CPL_ERROR_NONE; +} + + + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_prototyping.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_prototyping.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_prototyping.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_prototyping.h 2015-12-03 16:58:22.000000000 +0000 @@ -0,0 +1,74 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifndef HDRL_PROTOTYPING_H +#define HDRL_PROTOTYPING_H + +#include + +cpl_image * hdrl_get_spatial_freq(cpl_image *ima, double gausfilt, int mirrorx, + int mirrory); + +cpl_image * hdrl_mime_image_polynomial_bkg(cpl_image * image, + int dim_X, int dim_Y, + cpl_matrix ** coeffs); + + +cpl_error_code hdrl_mime_compute_polynomial_bkg( + const cpl_imagelist * images, + cpl_imagelist * bkg_images, + int dim_X, + int dim_Y, + cpl_matrix ** coeffs + ); +cpl_matrix *hdrl_mime_legendre_tensors_create(int nx, int ny, int npx, int npy); + +cpl_matrix *hdrl_mime_matrix_linspace_create(int n, double a, double b); + +cpl_matrix *hdrl_mime_legendre_polynomials_create(int npoly, double a, double b, + const cpl_matrix * x); + +cpl_matrix *hdrl_mime_linalg_pairwise_column_tensor_products_create(const + cpl_matrix * mat1, const cpl_matrix * mat2); + +cpl_error_code hdrl_mime_matrix_copy_column(const cpl_matrix * mat1, int j_1, + cpl_matrix * mat2, int j_2); + +cpl_matrix *hdrl_mime_linalg_tensor_products_columns_create(const cpl_matrix * + mat1, const cpl_matrix * mat2); +cpl_matrix *hdrl_mime_tensor_weights_create(int nx, int ny); + +cpl_error_code hdrl_mime_matrix_rescale_rows(const cpl_matrix * mat, + const cpl_matrix * d, cpl_matrix * dmat); + +cpl_error_code hdrl_mime_matrix_mask_rows(cpl_matrix * mat, const cpl_mask * mask); + +cpl_matrix *hdrl_mime_linalg_solve_tikhonov(const cpl_matrix * mat, + const cpl_matrix * rhs, double alpha); + +cpl_matrix *hdrl_mime_linalg_normal_equations_create(const cpl_matrix * mat, + double alpha); +cpl_matrix *hdrl_mime_matrix_product_left_transpose_create(const cpl_matrix * + mat1, const cpl_matrix * mat2); + +cpl_error_code hdrl_mime_matrix_product(const cpl_matrix * mat1, + const cpl_matrix * mat2, cpl_matrix * product); + + +#endif /* HDRL_PROTOTYPING_H */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_random.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_random.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_random.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_random.c 2017-09-07 13:33:12.000000000 +0000 @@ -0,0 +1,336 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + * + * + * + * uniform_double, poisson, normal partially based on numpy/random/mtrand + * Copyright 2005 Robert Kern (robert.kern@gmail.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * + * PCG generator implementation is licensed under Apache License 2.0 + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include +#include + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +struct hdrl_random_state_{ + uint64_t state; + uint64_t inc; + uint64_t has_normal; + double normal; +}; + +/* ---------------------------------------------------------------------------*/ +/** + * @brief generate uniform 64 bit random numbers + * + * @param rng random number generator state structure + * + * @return uniformly distributed 32 bit unsigned integer + */ +/* ---------------------------------------------------------------------------*/ +static uint32_t hdrl_random_uniform_uint32(hdrl_random_state * rng) +{ + /* from: + * PCG: A Family of Simple Fast Space-Efficient Statistically Good + * Algorithms for Random Number Generation */ + uint64_t oldstate = rng->state; + // Advance internal state + rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1); + // Calculate output function (XSH RR), uses old state for max ILP + uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; + uint32_t rot = oldstate >> 59u; + return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create random number generator state + * + * @param type type, currently needs to be 1 for pcg generator + * @param seed seed array, length depends on used generator, if NULL uses + * rand() to seed + * for pcg: two integers state and streamid + * + * @return random number generator state structure, must be deleted with + * hdrl_random_state_delete + */ +/* ---------------------------------------------------------------------------*/ +hdrl_random_state * hdrl_random_state_new(int type, uint64_t * seed) +{ + cpl_error_ensure(type == 1, CPL_ERROR_UNSUPPORTED_MODE, + return NULL, "type needs to be 1"); + hdrl_random_state * state = cpl_calloc(sizeof(*state), 1); + uint64_t s1 = seed ? seed[0] : (uint64_t)rand(); + uint64_t s2 = seed ? seed[1] : (uint64_t)rand(); + state->state = 0; + state->inc = s2; + hdrl_random_uniform_uint32(state); + state->state += s1; + hdrl_random_uniform_uint32(state); + return state; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief delete random number generator state structure + * + * @param state + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_random_state_delete(hdrl_random_state * state) +{ + cpl_free(state); +} + +static uint64_t hdrl_random_uniform_uint64_full(hdrl_random_state * state) +{ + return ((uint64_t)hdrl_random_uniform_uint32(state) << 32) | + (uint64_t)hdrl_random_uniform_uint32(state); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief generatore uniformly distributed 64 bit integers within range + * + * @param state rng state + * @param minval minimum value, inclusive + * @param maxval maximum value, inclusive + * + * @return uniformly distributed 64 bit integer within range + */ +/* ---------------------------------------------------------------------------*/ +int64_t +hdrl_random_uniform_int64(hdrl_random_state * state, + int64_t minval, int64_t maxval) +{ + uint64_t res, mask; + if (maxval < minval) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "maximum value smaller than minimum value"); + return 0; + } + uint64_t umaxval = (uint64_t)maxval - (uint64_t)minval; + if (umaxval == 0) { + return 0; + } + + /* create all 1 bitmask larger than maxval */ + mask = umaxval; + mask |= mask >> 1; + mask |= mask >> 2; + mask |= mask >> 4; + mask |= mask >> 8; + mask |= mask >> 16; + mask |= mask >> 32; + + /* draw numbers until the value is smaller than maxval */ + while (1) { + res = hdrl_random_uniform_uint64_full(state) & mask; + if (res <= umaxval) { + break; + } + } + return (int64_t)((uint64_t)minval + res); +} + +static double hdrl_random_uniform_double_one(hdrl_random_state * state) +{ + /* shifts : 67108864 = 0x4000000, 9007199254740992 = 0x20000000000000 */ + uint64_t a = hdrl_random_uniform_uint32(state) >> 5; + uint64_t b = hdrl_random_uniform_uint32(state) >> 6; + return (a * 67108864.0 + b) / 9007199254740992.0; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief generatore uniformly distributed double within range + * + * @param state rng state + * @param minval minimum value, inclusive + * @param maxval maximum value, inclusive + * + * @return uniformly distributed double within range + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_random_uniform_double(hdrl_random_state * state, + double minval, double maxval) +{ + double scale = fabs(maxval - minval); + return minval + scale * hdrl_random_uniform_double_one(state); +} + +static uint64_t hdrl_random_poisson_low(hdrl_random_state * state, double lam) +{ + const double explam = exp(-lam); + double prod = hdrl_random_uniform_double_one(state); + uint64_t r = 0; + + while (prod > explam) { + r++; + prod *= hdrl_random_uniform_double_one(state); + } + + return r; +} + +/* + * The transformed rejection method for generating Poisson random variables + * W. Hoermann + * Insurance: Mathematics and Economics 12, 39-45 (1993) + */ +static uint64_t hdrl_random_poisson_ptrs(hdrl_random_state * state, double lam) +{ + const double slam = sqrt(lam); + const double loglam = log(lam); + const double b = 0.931 + 2.53 * slam; + const double a = -0.059 + 0.02483 * b; + const double invalpha = 1.1239 + 1.1328 / (b - 3.4); + const double vr = 0.9277 - 3.6224 / (b - 2. ); + + while (1) { + + double U = hdrl_random_uniform_double_one(state) - 0.5; + double V = hdrl_random_uniform_double_one(state); + + double us = 0.5 - fabs(U); + cpl_boolean eval = (us >= 0.07); + + double aux = 2 * a / us; + int64_t k = (long)floor((aux + b) * U + lam + 0.43); + + if(eval && V <= vr) { + return k; + } + + if (k < 0 || (us < 0.013 && V > us) ) { + continue; + } + + double lgamk = lgamma(k + 1); + + if ((log(V) + log(invalpha) - log(a/(us*us)+b)) <= + (-lam + k * loglam - lgamk)) { + return k; + } + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief generatore poisson distributed values + * + * @param state rng state + * @param lam lambda/mean parameter of poisson distribution + * + * @return poisson distributed value + */ +/* ---------------------------------------------------------------------------*/ +uint64_t hdrl_random_poisson(hdrl_random_state * state, double lam) +{ + if (lam >= 10.) { + return hdrl_random_poisson_ptrs(state, lam); + } + else if (lam == 0.) { + return 0; + } + else if (lam < 0.) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "lam must not be negative"); + return 0; + } + else { + return hdrl_random_poisson_low(state, lam); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief generatore normal distributed values + * + * @param state rng state + * @param mean mean/location parameter of normal distribution + * @param sigma sigma/scale parameter of normal distribution + * + * @return normal distributed value + */ +/* ---------------------------------------------------------------------------*/ +double hdrl_random_normal(hdrl_random_state * state, double mean, double sigma) +{ + if (sigma < 0.) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "sigma must not be negative"); + return 0; + } + if (state->has_normal) { + state->has_normal = 0; + return mean + sigma * state->normal; + } + else { + double f, x1, x2, r; + + do { + x1 = 2.0 * hdrl_random_uniform_double_one(state) - 1.0; + x2 = 2.0 * hdrl_random_uniform_double_one(state) - 1.0; + r = x1 * x1 + x2 * x2; + } + while (r >= 1.0 || r == 0.0); + + /* Box-Muller transform */ + f = sqrt(-2.0*log(r)/r); + /* Keep second value for next call */ + state->normal = f * x1; + state->has_normal = 1; + return mean + sigma * f * x2; + } +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_random.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_random.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_random.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_random.h 2016-06-17 12:39:03.000000000 +0000 @@ -0,0 +1,49 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifndef HDRL_RANDOM_H +#define HDRL_RANDOM_H + +#include +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +/* currently intended for unit/regression testing purposes only */ +typedef struct hdrl_random_state_ hdrl_random_state; + +hdrl_random_state * hdrl_random_state_new(int type, uint64_t * seed); +void hdrl_random_state_delete(hdrl_random_state * state); + +int64_t hdrl_random_uniform_int64(hdrl_random_state * state, + int64_t minval, int64_t maxval); +double hdrl_random_uniform_double(hdrl_random_state * state, + double minval, double maxval); +uint64_t hdrl_random_poisson(hdrl_random_state * state, double lam); +double hdrl_random_normal(hdrl_random_state * state, double mean, double sigma); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_response.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_response.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_response.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_response.c 2018-01-22 10:21:47.000000000 +0000 @@ -0,0 +1,1881 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_response.h" +#include "hdrl_spectrum_resample.h" +#include "hdrl_efficiency.h" +#include "hdrl_utils.h" +#include +#include + + +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ +static inline cpl_array * +get_uniform_wavs(const hdrl_spectrum1D * s, const hdrl_data_t w_step, + const hdrl_data_t lmin, const hdrl_data_t lmax); + +static inline hdrl_xcorrelation_result * +correlate_obs_with_telluric(const hdrl_spectrum1D * obs_s, + const hdrl_spectrum1D * telluric_s, + const hdrl_data_t w_step, + cpl_size half_win, + const cpl_boolean normalize, + const hdrl_data_t lmin, + const hdrl_data_t lmax); + +static inline hdrl_spectrum1D * +shift_and_convolve_telluric_model(const hdrl_spectrum1D * obs, + const hdrl_spectrum1D * telluric, + const hdrl_data_t w_step, + const cpl_size half_win, + const cpl_boolean normalize, + const hdrl_data_t lmin, + const hdrl_data_t lmax, + double * telluric_shift); + +static inline cpl_size get_lower_odd(const cpl_size sz); + +static inline hdrl_spectrum1D * +convolve_with_kernel_symmetrically(const hdrl_spectrum1D * s, + const double sigma, + const hdrl_data_t w_step); + +static inline cpl_matrix * +create_symmetrical_gaussian_kernel(const double slitw, const double fwhm, + const cpl_size max_sz); + +static inline hdrl_spectrum1D * +convolve_spectrum_with_kernel(const hdrl_spectrum1D * s, + const cpl_matrix * kernel); + +static inline double +erf_antideriv(const double x, const double sigma); + + +/*calculate ratio between obs spectrum and convolved and shifted telluric model*/ +static inline hdrl_spectrum1D * +compute_corrected_obs_spectrum( + const hdrl_spectrum1D * obs_s_arg, + const hdrl_spectrum1D * telluric_s_arg, + const hdrl_data_t w_step, + const cpl_size half_win, + const cpl_boolean normalize, + const cpl_boolean shift_in_log_scale, + const hdrl_data_t lmin, const hdrl_data_t lmax, + double * telluric_shift); + +static inline hdrl_spectrum1D * +compute_interpolated_spectrum(const hdrl_spectrum1D * wlength_source, + const hdrl_spectrum1D * sampled_points, + const hdrl_spectrum1D_interpolation_method method); + +static inline void +compute_quality(const hdrl_spectrum1D * s, + const cpl_bivector * quality_areas, double * mean_abs_difference_from_1, + double * stddev); + +static inline void +free_spectrum_array(hdrl_spectrum1D ** s, const cpl_size sz); + +static inline cpl_error_code +get_first_error_code(const cpl_error_code * codes, const cpl_size sz); + +static inline hdrl_spectrum1D * +select_win(const hdrl_spectrum1D * s, const hdrl_data_t wmin, + const hdrl_data_t wmax); + +static inline hdrl_spectrum1D * +select_obs_wlen( const hdrl_spectrum1D * s, + const hdrl_spectrum1D * wlens_source); + +static inline hdrl_spectrum1D * +correct_spectrum_for_doppler_shift(const hdrl_spectrum1D * s, + const hdrl_data_t offset); + +static inline hdrl_spectrum1D * +filter_spectrum_median(const hdrl_spectrum1D * resp, const cpl_size radius); + +static inline hdrl_image * +compute_median_on_hdrl_image(const hdrl_image * img, const cpl_size radius); + +static inline hdrl_spectrum1D * +resample_on_medians_skip_abs_regions(const hdrl_spectrum1D * s, + const cpl_array * fit_points, const cpl_bivector * high_abs_regions, + const hdrl_data_t wrange); + +static inline cpl_array * +remove_regions_and_outliers_from_array(const cpl_array * fit_points, + const cpl_bivector * high_abs_regions, + const hdrl_data_t wmin, const hdrl_data_t wmax); + +static inline cpl_boolean +contained_in_any_region(const hdrl_data_t w, const cpl_bivector * high_abs_regions); + +static inline hdrl_spectrum1D * +get_median_on_fit_points(const hdrl_spectrum1D * s_input, + const cpl_array * fit_points, const hdrl_data_t wrange, + const cpl_array * dest_wlengths); + +static inline hdrl_spectrum1D * +remove_bad_data(const hdrl_spectrum1D * s); + +static inline const hdrl_spectrum1Dlist * +hdrl_response_telluric_evaluation_parameter_get_telluric_models( + const hdrl_parameter * par); + +static inline hdrl_data_t +hdrl_response_telluric_evaluation_parameter_get_w_step( + const hdrl_parameter * par); + +static inline cpl_size +hdrl_response_telluric_evaluation_parameter_get_half_win( + const hdrl_parameter * par); + +static inline cpl_boolean +hdrl_response_telluric_evaluation_parameter_get_normalize( + const hdrl_parameter * par); + +static inline cpl_boolean +hdrl_response_telluric_evaluation_parameter_get_shift_in_log_scale( + const hdrl_parameter * par); + +static inline const cpl_bivector * +hdrl_response_telluric_evaluation_parameter_get_quality_areas( + const hdrl_parameter * par); + +static inline const cpl_bivector * +hdrl_response_telluric_evaluation_parameter_get_fit_areas( + const hdrl_parameter * par); + +static inline hdrl_data_t +hdrl_response_telluric_evaluation_parameter_get_lmin( + const hdrl_parameter * par); + +static inline hdrl_data_t +hdrl_response_telluric_evaluation_parameter_get_lmax( + const hdrl_parameter * par); + +static inline const cpl_array * +hdrl_response_parameter_get_fit_points( + const hdrl_parameter * par); + +static inline const cpl_bivector * +hdrl_response_parameter_get_high_abs_regions( + const hdrl_parameter * par); + +static inline cpl_size +hdrl_response_parameter_get_radius( + const hdrl_parameter * par); + +static inline hdrl_data_t +hdrl_response_parameter_get_wrange( + const hdrl_parameter * par); + +static inline hdrl_spectrum1D * + hdrl_spectrum1D_extract_fit_regions(const hdrl_spectrum1D * s, + const cpl_bivector * areas); + +/*Private data structures*/ + +/*Parameter used for the telluric evaluation*/ +typedef struct { + HDRL_PARAMETER_HEAD; + hdrl_spectrum1Dlist * telluric_models; + hdrl_data_t w_step; + cpl_size half_win; + cpl_boolean normalize; + cpl_boolean shift_in_log_scale; + cpl_bivector * quality_areas; + cpl_bivector * fit_areas; + hdrl_data_t lmin; + hdrl_data_t lmax; +}hdrl_response_telluric_evaluation_parameter; + +static inline void +hdrl_response_telluric_evaluation_parameter_delete( + hdrl_parameter * ev){ + + if(ev == NULL) return; + + if(hdrl_parameter_get_parameter_enum(ev) + != HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION) + return; + + hdrl_response_telluric_evaluation_parameter * par = + (hdrl_response_telluric_evaluation_parameter *)ev; + + hdrl_spectrum1Dlist_delete(par->telluric_models); + cpl_bivector_delete(par->quality_areas); + cpl_bivector_delete(par->fit_areas); + cpl_free(par); +} + +static hdrl_parameter_typeobj +hdrl_telluric_eval_parameters_type = { + HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&hdrl_response_telluric_evaluation_parameter_delete, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_response_telluric_evaluation_parameter), /* obj_size */ +}; + +/*Parameter used for the response*/ +typedef struct { + HDRL_PARAMETER_HEAD; + cpl_size radius; + cpl_array * fit_points; + cpl_bivector * high_abs_regions; + hdrl_data_t wrange; +}response_fit_parameter; + +static inline void +hdrl_response_fit_parameter_delete( + hdrl_parameter * ev){ + + if(ev == NULL) return; + + if(hdrl_parameter_get_parameter_enum(ev) + != HDRL_PARAMETER_RESPONSE_FIT) + return; + + response_fit_parameter * par = + (response_fit_parameter *)ev; + + cpl_bivector_delete(par->high_abs_regions); + cpl_array_delete(par->fit_points); + cpl_free(par); +} + +static hdrl_parameter_typeobj +hdrl_response_parameters_type = { + HDRL_PARAMETER_RESPONSE_FIT, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&hdrl_response_fit_parameter_delete, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(response_fit_parameter), /* obj_size */ +}; + + +static inline hdrl_spectrum1D * +hdrl_spectrum1D_create_from_buffers(double * flux, double * wlens, cpl_size sz, + hdrl_spectrum1D_wave_scale scale); + +static inline hdrl_response_result * +hdrl_response_result_wrap(hdrl_spectrum1D * final_response, + hdrl_spectrum1D * selected_response, + hdrl_spectrum1D * raw_response, + + hdrl_spectrum1D * corrected_observed_spectrum, + cpl_size best_telluric_model_idx, + hdrl_data_t telluric_shift, + hdrl_data_t avg_diff_from_1, + hdrl_data_t stddev, + + hdrl_data_t doppler_shift); + +/** + * + * @addtogroup hdrl_response + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief ctor for the hdrl_parameter for the telluric evaluation + * @param telluric_models The available telluric models + * @param w_step Sampling step to use when upsampling model and + * observed spectrum to calculate the cross + * correlations + * @param half_win Half the search window to be used to find the + * peak of the cross correlation + * @param normalize CPL_TRUE if the cross correlation should be + * normalized, CPL_FALSE otherwise + * @param shift_in_log_scale CPL_TRUE if the cross correlation has to be + * calculated in logarithmic scale. + * CPL_FALSE otherwise. + * @param quality_areas Areas where the quality of the fit of the + * telluric model has to be evaluated. + * @param fit_areas Areas where the median points are extracted from, + * in order to generate the final quality parameters + * of the telluric model + * @param lmin Minimum wavelength used to calculate the + * cross-correlation (in log scale if + * shift_in_log_scale = TRUE) + * @param lmax Maximum wavelength used to calculate the + * cross-correlation (in log scale if + * shift_in_log_scale = TRUE) + * @return hdrl_parameter or NULL in case of error, see below. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the pointers are NULL + * - CPL_ERROR_ILLEGAL_INPUT: if w_step <= 0 or half_win <= 0 or lmin >= lmax + */ +/* ---------------------------------------------------------------------------*/ + +hdrl_parameter * +hdrl_response_telluric_evaluation_parameter_create( + const hdrl_spectrum1Dlist * telluric_models, + hdrl_data_t w_step, + cpl_size half_win, + cpl_boolean normalize, + cpl_boolean shift_in_log_scale, + const cpl_bivector * quality_areas, + const cpl_bivector * fit_areas, + hdrl_data_t lmin, + hdrl_data_t lmax){ + + cpl_ensure(quality_areas != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(telluric_models != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(fit_areas != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(w_step > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(half_win > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(lmin < lmax, CPL_ERROR_ILLEGAL_INPUT, NULL); + + hdrl_response_telluric_evaluation_parameter * ev + = (hdrl_response_telluric_evaluation_parameter *) + hdrl_parameter_new(&hdrl_telluric_eval_parameters_type); + + ev->telluric_models = hdrl_spectrum1Dlist_duplicate(telluric_models); + ev->w_step = w_step; + ev->half_win = half_win; + ev->normalize = normalize; + ev->shift_in_log_scale = shift_in_log_scale; + ev->quality_areas = cpl_bivector_duplicate(quality_areas); + ev->fit_areas = cpl_bivector_duplicate(fit_areas); + ev->lmin = lmin; + ev->lmax = lmax; + + return (hdrl_parameter *)ev; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief ctor for the hdrl_parameter for the final interpolation of the response + * @param radius Radius of the median filter used to smooth the + * response + * before the final interpolation + * @param fit_points Median points where the fit will be calculated + * @param wrange Range around the median point where the median + * is calculated + * @param high_abs_regions High absorption regions that should be skipped + * when calculating the fit. If NULL no skipping is done. + * + * @return hdrl_parameter or NULL in case of error, see below. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the required pointers are NULL + * - CPL_ERROR_ILLEGAL_INPUT: radius or wrange is less or equal 0 + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_response_fit_parameter_create( + const cpl_size radius, const cpl_array * fit_points, + const hdrl_data_t wrange, const cpl_bivector * high_abs_regions){ + + cpl_ensure(radius > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(wrange > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(fit_points != NULL, CPL_ERROR_NULL_INPUT, NULL); + + response_fit_parameter * p + = (response_fit_parameter *) + hdrl_parameter_new(&hdrl_response_parameters_type); + + p->fit_points = cpl_array_duplicate(fit_points); + p->high_abs_regions = NULL; + + if(high_abs_regions) + p->high_abs_regions = cpl_bivector_duplicate(high_abs_regions); + + p->radius = radius; + p->wrange = wrange; + + return (hdrl_parameter *) p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Computation of the response + * @param obs_s Observed spectrum + * @param ref_s Reference std star spectrum + * @param E_x Atmospheric Extinction + * @param telluric_par Telluric correction parameter, + * NULL if telluric correction is skipped. + * See hdrl_response_telluric_evaluation_parameter_create + * for details. + * @param velocity_par Doppler shift estimation and compensation. NULL if + * compensation has to be skipped. + * See hdrl_spectrum1D_shift_fit_parameter_create for + * more details. + * @param calc_par Parameter for the core computation of the response, + * e.g. exposure time. + * See hdrl_response_parameter_create for more details. + * @param fit_par Parameter for the final interpolation of the response, + * see hdrl_response_fit_parameter_create for more details. + * + * @return hdrl_response_result or NULL in case of error, see below. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any among calc_par, fit_par or the spectra + * are NULL + * - CPL_ERROR_ILLEGAL_OUTPUT: Any of the algorithmical steps can fail. + * This usually means that the output of that step + * can be NULL, if that is the case we abort triggering + * a CPL_ERROR_ILLEGAL_OUTPUT + */ +/* ---------------------------------------------------------------------------*/ +hdrl_response_result * +hdrl_response_compute( + const hdrl_spectrum1D * obs_s, + const hdrl_spectrum1D * ref_s, + const hdrl_spectrum1D * E_x, + const hdrl_parameter * telluric_par, + const hdrl_parameter * velocity_par, + const hdrl_parameter * calc_par, + const hdrl_parameter * fit_par){ + + cpl_ensure(calc_par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(calc_par) == + HDRL_PARAMETER_EFFICIENCY, CPL_ERROR_ILLEGAL_INPUT, NULL); + + if(telluric_par) + cpl_ensure(hdrl_parameter_get_parameter_enum(telluric_par) == + HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + if(velocity_par) + cpl_ensure(hdrl_parameter_get_parameter_enum(velocity_par) == + HDRL_PARAMETER_SPECTRUM1D_SHIFT, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + cpl_ensure(fit_par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(fit_par) == + HDRL_PARAMETER_RESPONSE_FIT, CPL_ERROR_ILLEGAL_INPUT, NULL); + + cpl_ensure(obs_s != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(ref_s != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(E_x != NULL, CPL_ERROR_NULL_INPUT, NULL); + + hdrl_data_t best_mean_minus1 = 0, best_stddev = 0; + hdrl_data_t best_telluric_shift = 0; + cpl_size best_idx = -1; + + hdrl_spectrum1D * corrected_obs = + hdrl_response_evaluate_telluric_models(obs_s, telluric_par, + &best_telluric_shift, &best_mean_minus1, &best_stddev, &best_idx); + + cpl_ensure(best_idx >= 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + cpl_ensure(corrected_obs != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_data_t velocity_shift = 0.0; + if(velocity_par != NULL){ + velocity_shift = + hdrl_spectrum1D_compute_shift_fit(corrected_obs, velocity_par); + } + + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * ref_shifted = + correct_spectrum_for_doppler_shift(ref_s, + velocity_shift); + + cpl_ensure(ref_shifted != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * resp_raw = + hdrl_response_core_compute(corrected_obs, ref_shifted, E_x, calc_par); + + cpl_ensure(resp_raw != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + const cpl_size radius = hdrl_response_parameter_get_radius(fit_par); + const cpl_bivector * high_abs_regions = + hdrl_response_parameter_get_high_abs_regions(fit_par); + const cpl_array * fit_points = + hdrl_response_parameter_get_fit_points(fit_par); + const hdrl_data_t wrange = + hdrl_response_parameter_get_wrange(fit_par); + + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * resp_smoothed = + filter_spectrum_median(resp_raw, radius); + + cpl_ensure(resp_smoothed != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * resp_on_fit_points = + resample_on_medians_skip_abs_regions(resp_smoothed, fit_points, + high_abs_regions, wrange); + + cpl_ensure(resp_on_fit_points != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, + CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + + hdrl_parameter * par = + hdrl_spectrum1D_resample_interpolate_parameter_create(hdrl_spectrum1D_interp_akima); + + hdrl_spectrum1D * resp_final = + hdrl_spectrum1D_resample_on_array(resp_on_fit_points, + hdrl_spectrum1D_get_wavelength(resp_smoothed).wavelength, + par); + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&resp_smoothed); + hdrl_spectrum1D_delete(&ref_shifted); + + + return hdrl_response_result_wrap(resp_final, resp_on_fit_points, + resp_raw, corrected_obs, best_idx, best_telluric_shift, + best_mean_minus1, best_stddev, velocity_shift); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter for the final response contained inside the hdrl_response_result + * @param res hdrl_response_result + * + * @return response or NULL in case of error. The final response is the final + * product of the algorithm. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ + +const hdrl_spectrum1D * +hdrl_response_result_get_final_response(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NULL); + return res->final_response; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter for the selected response contained inside the hdrl_response_result + * @param res hdrl_response_result + * + * @return selected response or NULL in case of error. The selected response is + * the raw response sampled in the fit points. This response is going then to be + * interpolated, creating the final response. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ + +const hdrl_spectrum1D * +hdrl_response_result_get_selected_response(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NULL); + return res->selected_response; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter for the raw response contained inside the hdrl_response_result + * @param res hdrl_response_result + * + * @return the raw response or NULL in case of error. The raw response is + * the ratio between the observed spectrum and the reference one, corrected for + * e.g. gain, atmospheric extinction, etc. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_spectrum1D * +hdrl_response_result_get_raw_response(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NULL); + return res->raw_response; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter for the corrected observed spectrum contained in hdrl_response_result + * @param res hdrl_response_result + * + * @return the observed spectrum corrected by the telluric model. If telluric + * correction was disabled the output of this function is not defined. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_spectrum1D * +hdrl_response_result_get_corrected_obs_spectrum(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NULL); + return res->corrected_observed_spectrum; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter of the index of the telluric model used for telluric correction + * contained in hdrl_response_result + * @param res hdrl_response_result + * + * @return the index (0-based) of the telluric model used for telluric correction. + * If telluric correction was disabled the output of this function is not defined. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +cpl_size +hdrl_response_result_get_best_telluric_model_idx(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, -1); + return res->best_telluric_model_idx; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter of the value |mean - 1|, where mean is the average of the ratio + * between the corrected observed spectrum and its smoothed fit. + * @param res hdrl_response_result + * + * @return the value |mean - 1|, where mean is the average of the ratio + * between the corrected observed spectrum and its smoothed fit. + * This value can be used to assess the quality of the match of the telluric model + * with the provided observed spectrum. + * If telluric correction was disabled the output of this function is not defined. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +hdrl_data_t +hdrl_response_result_get_avg_diff_from_1(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NAN); + return res->avg_diff_from_1; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter of the standard deviation of the ratio between the corrected + * observed spectrum and its smoothed fit. + * @param res hdrl_response_result + * + * @return the standard deviation of the ratio between the corrected observed + * spectrum and its smoothed fit. + * This value can be used to assess the quality of the match of the telluric model + * with the provided observed spectrum. + * If telluric correction was disabled the output of this function is not defined. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +hdrl_data_t +hdrl_response_result_get_stddev(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NAN); + return res->stddev; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter of the shift applied to the telluric model. + * @param res hdrl_response_result + * + * @return shift applied to the selected telluric model. + * This value can be used to assess the quality of the match of the telluric model + * with the provided observed spectrum. + * If telluric correction was disabled the output of this function is not defined. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +hdrl_data_t +hdrl_response_result_get_telluric_shift(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NAN); + return res->telluric_shift; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Getter of the doppler shift used to correct the model. + * @param res hdrl_response_result + * + * @return the doppler shift used to correct the model. + * If doppler corection was disabled the output of this function is not defined. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: res is NULL + */ +/* ---------------------------------------------------------------------------*/ +hdrl_data_t +hdrl_response_result_get_doppler_shift(const hdrl_response_result * res){ + cpl_ensure(res != NULL, CPL_ERROR_NULL_INPUT, NAN); + return res->doppler_shift; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Destructor for hdrl_response_result + * @param res hdrl_response_result to be destroyed + */ +/* ---------------------------------------------------------------------------*/ +void +hdrl_response_result_delete(hdrl_response_result * res){ + + if(!res) return; + + hdrl_spectrum1D_delete(&(res->final_response)); + hdrl_spectrum1D_delete(&(res->selected_response)); + hdrl_spectrum1D_delete(&(res->raw_response)); + + hdrl_spectrum1D_delete(&(res->corrected_observed_spectrum)); + + cpl_free(res); +} + +/* This function evaluates all the telluric models inside the hdrl_parameter ev, + * picks the best model, returns its index (best_model_index), some quality parameter + * (mean_minus_1 and stddev) and obs_s corrected with the best model. + * If ev == NULL the function returns a copy of obs_s. + * ev is created using hdrl_response_telluric_evaluation_parameter_create. */ +hdrl_spectrum1D * +hdrl_response_evaluate_telluric_models( + const hdrl_spectrum1D * obs_s, + const hdrl_parameter * ev, + hdrl_data_t * telluric_shift, + hdrl_data_t * mean_minus_1, hdrl_data_t * stddev, + cpl_size * best_model_index){ + + cpl_ensure(mean_minus_1 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(stddev != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(best_model_index != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(obs_s != NULL, CPL_ERROR_NULL_INPUT, NULL); + + *mean_minus_1 = (hdrl_data_t)0.0; + *stddev = (hdrl_data_t)0.0; + *best_model_index = -1; + + if(ev == NULL){ + *best_model_index = 0; + *mean_minus_1 = NAN; + *stddev = NAN; + *telluric_shift = NAN; + return hdrl_spectrum1D_duplicate(obs_s); + } + + cpl_ensure(hdrl_parameter_get_parameter_enum(ev) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + const hdrl_spectrum1Dlist * telluric_models = + hdrl_response_telluric_evaluation_parameter_get_telluric_models(ev); + const hdrl_data_t w_step = + hdrl_response_telluric_evaluation_parameter_get_w_step(ev); + const cpl_size half_win = + hdrl_response_telluric_evaluation_parameter_get_half_win(ev); + const cpl_boolean normalize = + hdrl_response_telluric_evaluation_parameter_get_normalize(ev); + const cpl_boolean shift_in_log_scale = + hdrl_response_telluric_evaluation_parameter_get_shift_in_log_scale(ev); + const cpl_bivector * quality_areas = + hdrl_response_telluric_evaluation_parameter_get_quality_areas(ev); + const cpl_bivector * fit_areas = + hdrl_response_telluric_evaluation_parameter_get_fit_areas(ev); + const hdrl_data_t lmin = + hdrl_response_telluric_evaluation_parameter_get_lmin(ev); + const hdrl_data_t lmax = + hdrl_response_telluric_evaluation_parameter_get_lmax(ev); + + hdrl_spectrum1D * to_ret = NULL; + + const cpl_size sz = hdrl_spectrum1Dlist_get_size(telluric_models); + cpl_ensure(sz > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + cpl_array * calc_std_devs = cpl_array_new(sz, CPL_TYPE_DOUBLE); + cpl_array * calc_means_minus_1 = cpl_array_new(sz, CPL_TYPE_DOUBLE); + cpl_array * calc_telluric_shift = cpl_array_new(sz, CPL_TYPE_DOUBLE); + + cpl_array_fill_window(calc_std_devs, 0, sz, 0); + cpl_array_fill_window(calc_means_minus_1, 0, sz, 0); + cpl_array_fill_window(calc_telluric_shift, 0, sz, 0); + + double * p_stddevs = cpl_array_get_data_double(calc_std_devs); + double * p_means = cpl_array_get_data_double(calc_means_minus_1); + double * p_telluric_shift = cpl_array_get_data_double(calc_telluric_shift); + + hdrl_spectrum1D ** l = cpl_calloc(sz, sizeof(hdrl_spectrum1D*)); + cpl_error_code * codes = cpl_calloc(sz, sizeof(cpl_error_code)); + + HDRL_OMP(omp parallel for) + for(cpl_size i = 0; i < sz; ++i){ + const hdrl_spectrum1D * this_model = + hdrl_spectrum1Dlist_get_const(telluric_models, i); + + l[i] = hdrl_response_evaluate_telluric_model(obs_s, this_model, w_step, + half_win, normalize, shift_in_log_scale, quality_areas, fit_areas, + lmin, lmax, p_means + i, p_stddevs + i,p_telluric_shift + i); + codes[i] = cpl_error_get_code(); + + if(l[i] == NULL && codes[i] == CPL_ERROR_NONE) + codes[i] = CPL_ERROR_ILLEGAL_OUTPUT; + } + + cpl_error_code err = get_first_error_code(codes, sz); + + if(!err){ + cpl_size best_idx = 0; + err = cpl_array_get_minpos(calc_means_minus_1, &best_idx); + if(!err){ + *stddev = cpl_array_get(calc_std_devs, best_idx, NULL); + *mean_minus_1 = cpl_array_get(calc_means_minus_1, best_idx, NULL); + *telluric_shift = cpl_array_get(calc_telluric_shift, best_idx, NULL); + to_ret = l[best_idx]; + l[best_idx] = NULL; + *best_model_index = best_idx; + } + } + + cpl_array_delete(calc_std_devs); + cpl_array_delete(calc_means_minus_1); + cpl_array_delete(calc_telluric_shift); + cpl_free(codes); + free_spectrum_array(l, sz); + + cpl_ensure(err == CPL_ERROR_NONE, err, NULL); + + return to_ret; +} + + + +/*This function evaluates how well a telluric model corrects an observed spectrum. + * For the parameters see hdrl_response_telluric_evaluation_parameter_create.*/ +hdrl_spectrum1D * +hdrl_response_evaluate_telluric_model(const hdrl_spectrum1D * obs_s_arg, + const hdrl_spectrum1D * telluric_s_arg, + const hdrl_data_t w_step, + const cpl_size half_win, + const cpl_boolean normalize, + const cpl_boolean shift_in_log_scale, + const cpl_bivector * quality_areas, + const cpl_bivector * fit_areas, + const hdrl_data_t lmin, const hdrl_data_t lmax, + double * mean_minus_1, double * stddev, + double * telluric_shift){ + + cpl_ensure(obs_s_arg != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(telluric_s_arg != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(quality_areas != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(fit_areas != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(mean_minus_1 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(stddev != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(w_step > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(half_win > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + *mean_minus_1 = 0.0; + *stddev = 0.0; + *telluric_shift = 0.0; + + hdrl_spectrum1D * corrected_spectrum = + compute_corrected_obs_spectrum(obs_s_arg, + telluric_s_arg, w_step, half_win, normalize, + shift_in_log_scale, lmin, lmax, telluric_shift); + + cpl_ensure(corrected_spectrum != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * corr_spectrum_extracted = + hdrl_spectrum1D_extract_fit_regions(corrected_spectrum, fit_areas); + + if(corr_spectrum_extracted == NULL) { + hdrl_spectrum1D_delete(&corrected_spectrum); + cpl_ensure(CPL_FALSE, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + } + + hdrl_spectrum1D * smoothed_fit = + compute_interpolated_spectrum(corrected_spectrum, + corr_spectrum_extracted, hdrl_spectrum1D_interp_akima); + + hdrl_spectrum1D * quality_ratio = + hdrl_spectrum1D_div_spectrum_create(corrected_spectrum, smoothed_fit); + + compute_quality(quality_ratio, quality_areas, mean_minus_1, stddev); + + hdrl_spectrum1D_delete(&corr_spectrum_extracted); + hdrl_spectrum1D_delete(&smoothed_fit); + hdrl_spectrum1D_delete(&quality_ratio); + + return corrected_spectrum; +} + +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ + +/* Given a spectrum the function calculates: + * mean_abs_difference_from_1 = |mean - 1| and standard deviation. + * The flux defined on wavelengths outside the quality_areas are ignored.*/ +static inline void +compute_quality(const hdrl_spectrum1D * s, + const cpl_bivector * quality_areas, double * mean_abs_difference_from_1, + double * stddev){ + + hdrl_spectrum1D * s_new = + hdrl_spectrum1D_select_wavelengths(s, quality_areas, CPL_TRUE); + + const hdrl_image * flux = hdrl_spectrum1D_get_flux(s_new); + + *mean_abs_difference_from_1 = fabs(hdrl_image_get_mean(flux).data - 1.0); + *stddev = hdrl_image_get_stdev(flux); + + hdrl_spectrum1D_delete(&s_new); +} + +/* Interpolates using a cspline the points in sampled_points to obtain a spectrum + * defined on the wavelengths of wlength_source*/ +static inline hdrl_spectrum1D * +compute_interpolated_spectrum(const hdrl_spectrum1D * wlength_source, + const hdrl_spectrum1D * sampled_points, + const hdrl_spectrum1D_interpolation_method method){ + + hdrl_parameter * par = + hdrl_spectrum1D_resample_interpolate_parameter_create(method); + + hdrl_spectrum1D_wavelength waves = hdrl_spectrum1D_get_wavelength(wlength_source); + + hdrl_spectrum1D * continuum_fit = + hdrl_spectrum1D_resample(sampled_points, &waves, par); + + hdrl_parameter_delete(par); + return continuum_fit; +} + +/* This function correct the observed spectrum by the telluric spectrum. In order + * to do so, the function aligns the two spectra, convolves the telluric model by + * a gaussian kernel. The observed spectrum is then divided by the shifted and + * convolved telluric model. + * NOTE: the output spectrum is defined on the wavelengths of obs_s_arg.*/ +static inline hdrl_spectrum1D * +compute_corrected_obs_spectrum( + const hdrl_spectrum1D * obs_s_arg, + const hdrl_spectrum1D * telluric_s_arg, + const hdrl_data_t w_step, const cpl_size half_win, + const cpl_boolean normalize, + const cpl_boolean shift_in_log_scale, + const hdrl_data_t lmin, const hdrl_data_t lmax, + double * telluric_shift){ + + cpl_ensure(obs_s_arg != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(telluric_s_arg != NULL, CPL_ERROR_NULL_INPUT, NULL); + + hdrl_spectrum1D_wavelength obs_wavs = hdrl_spectrum1D_get_wavelength(obs_s_arg); + + hdrl_spectrum1D * obs_s = hdrl_spectrum1D_duplicate(obs_s_arg); + hdrl_spectrum1D * telluric_s_cp = hdrl_spectrum1D_duplicate(telluric_s_arg); + + if(shift_in_log_scale){ + hdrl_spectrum1D_wavelength_convert_to_log(obs_s); + hdrl_spectrum1D_wavelength_convert_to_log(telluric_s_cp); + } + + hdrl_spectrum1D * telluric_s_shifted_convolved= + shift_and_convolve_telluric_model(obs_s, telluric_s_cp, w_step, + half_win, normalize, lmin, lmax, telluric_shift); + + + if(telluric_s_shifted_convolved != NULL){ + hdrl_spectrum1D_wavelength_convert_to_linear(telluric_s_shifted_convolved); + } + + hdrl_parameter * pars = hdrl_spectrum1D_resample_integrate_parameter_create(); + hdrl_spectrum1D * telluric_s_shifted_convolved_downsampled = + hdrl_spectrum1D_resample(telluric_s_shifted_convolved, &obs_wavs, pars); + hdrl_spectrum1D * corrected = + hdrl_spectrum1D_div_spectrum_create(obs_s_arg , telluric_s_shifted_convolved_downsampled); + + hdrl_spectrum1D_delete(&obs_s); + hdrl_spectrum1D_delete(&telluric_s_cp); + hdrl_spectrum1D_delete(&telluric_s_shifted_convolved); + hdrl_spectrum1D_delete(&telluric_s_shifted_convolved_downsampled); + hdrl_parameter_delete(pars); + + return corrected; +} + +/*Trims s so that its minimum and maximum wavelenghts do not exceed wlens_source*/ +static inline hdrl_spectrum1D * +select_obs_wlen( const hdrl_spectrum1D * s, + const hdrl_spectrum1D * wlens_source){ + + const cpl_array * wlens = hdrl_spectrum1D_get_wavelength(wlens_source).wavelength; + + const hdrl_data_t wmin = cpl_array_get_min(wlens); + const hdrl_data_t wmax = cpl_array_get_max(wlens); + + return select_win(s, wmin, wmax); +} + +/*The telluric model is correlated with the observed spectrum to compute the + * relative shift between the two. Then the telluric model is shifted to match the + * observed spectrum. Then the shifted model is convolved with a gaussian kernel. */ +static inline hdrl_spectrum1D * +shift_and_convolve_telluric_model(const hdrl_spectrum1D * obs, + const hdrl_spectrum1D * telluric, + const hdrl_data_t w_step, + const cpl_size half_win, + const cpl_boolean normalize, + const hdrl_data_t lmin, + const hdrl_data_t lmax, + double * telluric_shift){ + + hdrl_spectrum1D * telluric_s = select_win(telluric, lmin, lmax); + + cpl_ensure(telluric_s != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_xcorrelation_result * res = + correlate_obs_with_telluric(obs, telluric_s, + w_step, half_win, normalize, lmin, lmax); + hdrl_spectrum1D_delete(&telluric_s); + + cpl_ensure(res != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_data_t shift = (hdrl_data_t) + (hdrl_xcorrelation_result_get_peak_subpixel(res) - + hdrl_xcorrelation_result_get_half_window(res) * w_step); + + *telluric_shift = shift; + + hdrl_spectrum1D * telluric_selected_obs = + select_obs_wlen(telluric, obs); + + hdrl_spectrum1D * telluric_s_shifted = + hdrl_spectrum1D_wavelength_shift_create(telluric_selected_obs, shift); + const double sigma = hdrl_xcorrelation_result_get_sigma(res); + + hdrl_xcorrelation_result_delete(res); + + cpl_ensure(telluric_s_shifted != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * telluric_s_shifted_convolved = + convolve_with_kernel_symmetrically(telluric_s_shifted, sigma, w_step); + + hdrl_spectrum1D_delete(&telluric_s_shifted); + hdrl_spectrum1D_delete(&telluric_selected_obs); + + return telluric_s_shifted_convolved; +} + +/*The function: 1. resamples uniformly obs_s and telluric_s, so they're defined + * on the same wavelengths. 2. correlates the two spectra to find out the relative + * shift of one wrt the other. + * + * w_step, lmin and lmax are used for the resampling, all the other inputs + * are used for the cross correlation.*/ +static inline hdrl_xcorrelation_result * +correlate_obs_with_telluric(const hdrl_spectrum1D * obs_s, + const hdrl_spectrum1D * telluric_s, + const hdrl_data_t w_step, + const cpl_size half_win, + const cpl_boolean normalize, + const hdrl_data_t lmin, + const hdrl_data_t lmax){ + + cpl_ensure(obs_s != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(telluric_s != NULL, CPL_ERROR_NULL_INPUT, NULL); + + hdrl_data_t wmin = cpl_array_get_min(hdrl_spectrum1D_get_wavelength(obs_s).wavelength); + hdrl_data_t wmax = cpl_array_get_max(hdrl_spectrum1D_get_wavelength(obs_s).wavelength); + + hdrl_spectrum1D * tell_for_sel = select_win(telluric_s, wmin, wmax); + + hdrl_spectrum1D * telluric_s_res = NULL; + hdrl_spectrum1D * obs_s_res = NULL; + { + cpl_array * new_lambdas = get_uniform_wavs(tell_for_sel, w_step, lmin, lmax); + + /* + * We need to make sure that telluric_s and obs_s are + * sampled uniformly. + */ + hdrl_parameter * par = + hdrl_spectrum1D_resample_interpolate_parameter_create + (hdrl_spectrum1D_interp_akima); + + telluric_s_res = + hdrl_spectrum1D_resample_on_array(telluric_s, new_lambdas, par); + + obs_s_res = + hdrl_spectrum1D_resample_on_array(obs_s, new_lambdas, par); + + hdrl_parameter_delete(par); + cpl_array_delete(new_lambdas); + } + + cpl_ensure(obs_s_res != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + cpl_ensure(telluric_s_res != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_xcorrelation_result * gshift = + hdrl_spectrum1D_compute_shift_xcorrelation(telluric_s_res, obs_s_res, + half_win, normalize); + + hdrl_spectrum1D_delete(&telluric_s_res); + hdrl_spectrum1D_delete(&obs_s_res); + hdrl_spectrum1D_delete(&tell_for_sel); + return gshift; +} + + +/*This function returns a uniformly sampled sequence of wavelengths. The distance + * between 2 elements is w_step, the starting point is max(lmin, min_wavelengths_s) + * the end point is min(lmax, max_wavelegths_s)*/ +static inline cpl_array * +get_uniform_wavs(const hdrl_spectrum1D * s, const hdrl_data_t w_step, + const hdrl_data_t lmin, const hdrl_data_t lmax){ + + const hdrl_data_t w_min = CPL_MAX(lmin, + cpl_array_get_min(hdrl_spectrum1D_get_wavelength(s).wavelength)); + const hdrl_data_t w_max = CPL_MIN(lmax, + cpl_array_get_max(hdrl_spectrum1D_get_wavelength(s).wavelength)); + + const cpl_size sz_new_spectrum = (w_max - w_min)/w_step; + cpl_array * new_w_lengths = cpl_array_new(sz_new_spectrum, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < sz_new_spectrum; ++i){ + cpl_array_set(new_w_lengths, i, i * w_step + w_min); + } + + return new_w_lengths; +} + +/*This function convolves a kernel with the flux of a spectrum. The output + * spectrum is without error and it is defined on the same wavelengths of the input + * spectrum. The convolution one the borders is done using a reduced number of samples.*/ +static inline hdrl_spectrum1D * +convolve_spectrum_with_kernel(const hdrl_spectrum1D * s, + const cpl_matrix * kernel){ + + const cpl_size sz = hdrl_spectrum1D_get_size(s); + const hdrl_image * h_img = hdrl_spectrum1D_get_flux(s); + const cpl_image * img = hdrl_image_get_image_const(h_img); + cpl_image * dest = cpl_image_new(sz, 1, HDRL_TYPE_DATA); + + const cpl_error_code cd = + cpl_image_filter(dest, img, kernel, CPL_FILTER_LINEAR, CPL_BORDER_FILTER); + + + hdrl_spectrum1D * to_ret = NULL; + if(cd == CPL_ERROR_NONE){ + hdrl_spectrum1D_wavelength s_wav = hdrl_spectrum1D_get_wavelength(s); + + to_ret = + hdrl_spectrum1D_create_error_free(dest, s_wav.wavelength, s_wav.scale); + } + + cpl_image_delete(dest); + + cpl_ensure(cd == CPL_ERROR_NONE, cd, NULL); + + return to_ret; +} + +static inline cpl_size get_lower_odd(const cpl_size sz){ + + if(sz == 0) return 0; + + if(sz % 2 == 1) return sz; + return sz - 1; +} + +/*This function convolves the spectrum s with a symmetrical gaussian kernel having + * std deviation sigma. The wavelength step of the kernel is w_step.*/ +static inline hdrl_spectrum1D * +convolve_with_kernel_symmetrically(const hdrl_spectrum1D * s, + const double sigma, + const hdrl_data_t w_step){ + + const double fwhm = CPL_MATH_FWHM_SIG * sigma; + int fwhm_pix = (int) (fwhm / w_step + 0.5); + + cpl_matrix * kernel = + create_symmetrical_gaussian_kernel(fwhm_pix / CPL_MATH_FWHM_SIG, + fwhm_pix / CPL_MATH_FWHM_SIG, + get_lower_odd(hdrl_spectrum1D_get_size(s))); + + hdrl_spectrum1D * convolved = + convolve_spectrum_with_kernel(s, kernel); + cpl_matrix_delete(kernel); + + cpl_ensure(convolved != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + return convolved; +} + +/* Creates a gaussian symmetrical kernel for a given slit width (slitw) and a given + * fwhm. The function ALWAYS returns a kernel with a odd number of elements.*/ +static inline cpl_matrix * +create_symmetrical_gaussian_kernel(const double slitw, const double fwhm, + const cpl_size max_sz){ + + cpl_ensure(slitw > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(fwhm > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + const double sigma = fwhm * CPL_MATH_SIG_FWHM; + cpl_size size = 1 + (cpl_size)(5.0 * sigma + 0.5*slitw); + + size *= 2; + /* filter need an odd number of elements */ + size ++; + + size = CPL_MIN(size, max_sz); + + cpl_matrix * kernel = cpl_matrix_new(1, size); + + /* Special case for i = 0 */ + cpl_matrix_set(kernel, 0, size/2, + (erf_antideriv(0.5*slitw + 0.5, sigma) - + erf_antideriv(0.5*slitw - 0.5, sigma)) / slitw); + + for (cpl_size i = 1; i < size / 2; i++) { + + const double x1p = (double)i + 0.5 * slitw + 0.5; + const double x1n = (double)i - 0.5 * slitw + 0.5; + const double x0p = (double)i + 0.5 * slitw - 0.5; + const double x0n = (double)i - 0.5 * slitw - 0.5; + const double val = 0.5 / slitw * + (erf_antideriv(x1p, sigma) - erf_antideriv(x1n, sigma) - + erf_antideriv(x0p, sigma) + erf_antideriv(x0n, sigma)); + + cpl_matrix_set(kernel, 0, size/2 + i, val); + cpl_matrix_set(kernel, 0, size/2 - i, val); + } + + return kernel; +} + +/* The antiderivative of erx(x/sigma/sqrt(2)) with respect to x */ +static inline double +erf_antideriv(const double x, const double sigma) +{ + return x * erf( x / (sigma * CPL_MATH_SQRT2)) + + 2.0 * sigma/CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma)); +} + +/* Given an array of spectra the function takes care of freeing each spectra + * and the buffer containing the pointers.*/ +static inline void +free_spectrum_array(hdrl_spectrum1D ** s, const cpl_size sz){ + hdrl_spectrum1Dlist * l = hdrl_spectrum1Dlist_wrap(s, sz); + hdrl_spectrum1Dlist_delete(l); +} + +/*Get the first element of the array that is not CPL_ERROR_NONE. If all the + * elements are CPL_ERROR_NONE the function returns CPL_ERROR_NONE.*/ +static inline cpl_error_code +get_first_error_code(const cpl_error_code * codes, const cpl_size sz){ + for(cpl_size i = 0; i < sz; ++i){ + if(codes[i]) return codes[i]; + } + return CPL_ERROR_NONE; +} + +/*Selects all the wavelengths between wmin and wmax*/ +static inline hdrl_spectrum1D * +select_win(const hdrl_spectrum1D * s, const hdrl_data_t wmin, + const hdrl_data_t wmax){ + + cpl_bivector * bv = cpl_bivector_new(1); + + cpl_vector_set(cpl_bivector_get_x(bv), 0, wmin); + cpl_vector_set(cpl_bivector_get_y(bv), 0, wmax); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_select_wavelengths(s, bv, CPL_TRUE); + + cpl_bivector_delete(bv); + + return to_ret; +} +/*Corrects the spectrum s by the doppler offset offset.*/ +static inline hdrl_spectrum1D * +correct_spectrum_for_doppler_shift(const hdrl_spectrum1D * s, + const hdrl_data_t offset){ + + if(offset == 0.0) + return hdrl_spectrum1D_duplicate(s); + + const hdrl_image * flux = hdrl_spectrum1D_get_flux(s); + cpl_array * wavs = + cpl_array_duplicate(hdrl_spectrum1D_get_wavelength(s).wavelength); + + for(cpl_size i = 0; i < cpl_array_get_size(wavs); ++i){ + const double d = cpl_array_get(wavs, i, NULL) * (1. + offset); + cpl_array_set(wavs, i, d); + } + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create( + hdrl_image_get_image_const(flux), + hdrl_image_get_error_const(flux), + wavs, + hdrl_spectrum1D_get_scale(s)); + cpl_array_delete(wavs); + return to_ret; +} +/*Median filters the flux, with error propagation*/ +static inline hdrl_spectrum1D * +filter_spectrum_median(const hdrl_spectrum1D * resp, const cpl_size radius){ + const hdrl_image * flx_total = hdrl_spectrum1D_get_flux(resp); + hdrl_image * flx_smoothed = compute_median_on_hdrl_image(flx_total, radius); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create( + hdrl_image_get_image(flx_smoothed), + hdrl_image_get_error(flx_smoothed), + hdrl_spectrum1D_get_wavelength(resp).wavelength, + hdrl_spectrum1D_get_scale(resp)); + + hdrl_image_delete(flx_smoothed); + + return to_ret; +} + +/*Median filters an HDRL image, with error propagation*/ +static inline hdrl_image * +compute_median_on_hdrl_image(const hdrl_image * img, const cpl_size radius){ + + hdrl_image * to_ret = hdrl_image_duplicate(img); + cpl_size sz = hdrl_image_get_size_x(img); + for(cpl_size i = 1; i <= sz; ++i){ + cpl_size start = CPL_MAX(i - radius, 1); + cpl_size stop = CPL_MIN(i + radius, sz); + hdrl_image * ex_img = hdrl_image_extract(img, start, 1, stop, 1); + hdrl_value m = hdrl_image_get_median(ex_img); + hdrl_image_delete(ex_img); + hdrl_image_set_pixel(to_ret, i, 1, m); + } + return to_ret; +} + +/*Remove rejected values or values being NAN or INF*/ +static inline hdrl_spectrum1D * +remove_bad_data(const hdrl_spectrum1D * s){ + + const cpl_size sz = hdrl_spectrum1D_get_size(s); + double * flx = cpl_calloc(sz, sizeof(double)); + double * flx_e = cpl_calloc(sz, sizeof(double)); + double * wlen = cpl_calloc(sz, sizeof(double)); + + cpl_size true_size = 0; + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + hdrl_value v = hdrl_spectrum1D_get_flux_value(s, i, &rej); + if(rej || isnan(v.data) || isinf(v.data)) continue; + + flx[true_size] = v.data; + flx_e[true_size] = v.error; + wlen[true_size] = hdrl_spectrum1D_get_wavelength_value(s, i, &rej); + true_size++; + } + + if(true_size == 0){ + cpl_free(flx); + cpl_free(flx_e); + cpl_free(wlen); + return NULL; + } + + hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_get_scale(s); + cpl_image * img_flx = cpl_image_wrap_double(true_size, 1, flx); + cpl_image * img_flx_e = cpl_image_wrap_double(true_size, 1, flx_e); + cpl_array * arr_wlens= cpl_array_wrap_double(wlen, true_size); + hdrl_spectrum1D * good_spectrum = hdrl_spectrum1D_create(img_flx, img_flx_e, + arr_wlens, scale); + + cpl_image_delete(img_flx); + cpl_image_delete(img_flx_e); + cpl_array_delete(arr_wlens); + return good_spectrum; +} + +/* For each point p in fit_points generates a new spectrum whose wavelengths are + * fit_points and whose flux are the medians taken in the range + * [p - wrange, p + wrange]. */ +static inline hdrl_spectrum1D * +get_median_on_fit_points(const hdrl_spectrum1D * s_input, + const cpl_array * fit_points, const hdrl_data_t wrange, + const cpl_array * dest_wlengths){ + + cpl_size final_fit_points_size = cpl_array_get_size(fit_points); + + cpl_array * wlens_fit = cpl_array_new(final_fit_points_size, + HDRL_TYPE_DATA); + hdrl_image * flux_fit = hdrl_image_new(final_fit_points_size, 1); + + for(cpl_size i = 0; i < final_fit_points_size; ++i){ + const double w_fit = cpl_array_get(fit_points, i, NULL); + cpl_array_set(wlens_fit, i, w_fit); + hdrl_spectrum1D * f_s = + select_win(s_input, w_fit - wrange, w_fit + wrange); + + if(f_s == NULL){ + cpl_error_reset(); + hdrl_image_reject(flux_fit, i + 1, 1); + continue; + } + + const hdrl_value v = hdrl_image_get_median(hdrl_spectrum1D_get_flux(f_s)); + hdrl_image_set_pixel(flux_fit, i + 1, 1, v); + hdrl_spectrum1D_delete(&f_s); + } + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_get_scale(s_input); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create( + hdrl_image_get_image(flux_fit), + hdrl_image_get_error(flux_fit), + wlens_fit, + scale + ); + cpl_array_delete(wlens_fit); + hdrl_image_delete(flux_fit); + return to_ret; +} +/*removes high abs regions and values that are NAN or INF or rejected*/ +static inline hdrl_spectrum1D * +select_regions_and_good_value(const hdrl_spectrum1D * s, const cpl_bivector * areas){ + + hdrl_spectrum1D * filted = NULL; + if(areas != NULL) + filted = hdrl_spectrum1D_select_wavelengths(s, areas, CPL_FALSE); + else + filted = hdrl_spectrum1D_duplicate(s); + + hdrl_spectrum1D * to_ret = remove_bad_data(filted); + hdrl_spectrum1D_delete(&filted); + return to_ret; +} + +/*This function: + * 1. Removes all the wavelengths contained inside high_abs_regions, from both s + * and fit_points + * 2. For each surviving point in fit_points take the median flux on the filtered s +*/ +static inline hdrl_spectrum1D * +resample_on_medians_skip_abs_regions(const hdrl_spectrum1D * s, + const cpl_array * fit_points, const cpl_bivector * high_abs_regions, + const hdrl_data_t wrange){ + + cpl_ensure(s != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(fit_points != NULL, CPL_ERROR_NULL_INPUT, NULL); + + hdrl_spectrum1D * filter_s = + select_regions_and_good_value(s, high_abs_regions); + + cpl_ensure(filter_s != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + const hdrl_data_t wmin= + cpl_array_get_min(hdrl_spectrum1D_get_wavelength(filter_s).wavelength); + const hdrl_data_t wmax= + cpl_array_get_max(hdrl_spectrum1D_get_wavelength(filter_s).wavelength); + + cpl_array * filter_fit_points = + remove_regions_and_outliers_from_array(fit_points, high_abs_regions, wmin, wmax); + + if(filter_fit_points == NULL || cpl_array_get_size(filter_fit_points) == 0){ + hdrl_spectrum1D_delete(&filter_s); + cpl_array_delete(filter_fit_points); + cpl_ensure(CPL_FALSE, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + } + + hdrl_spectrum1D * selected_s_median_points = + get_median_on_fit_points(filter_s, filter_fit_points, wrange, + hdrl_spectrum1D_get_wavelength(s).wavelength); + + cpl_array_delete(filter_fit_points); + hdrl_spectrum1D_delete(&filter_s); + + return selected_s_median_points; +} + +/*Checks if w is contained in any of the windows in high_abs_regions.*/ +static inline cpl_boolean +contained_in_any_region(const hdrl_data_t w, const cpl_bivector * high_abs_regions){ + + if(!high_abs_regions) return CPL_FALSE; + + const cpl_size sz = cpl_bivector_get_size(high_abs_regions); + + for(cpl_size i = 0; i < sz; ++i){ + const double wmin = + cpl_vector_get(cpl_bivector_get_x_const(high_abs_regions), i); + const double wmax = + cpl_vector_get(cpl_bivector_get_y_const(high_abs_regions), i); + if(w >= wmin && w <= wmax) return CPL_TRUE; + } + return CPL_FALSE; +} + +/*Removes each element in the array that is outside the range [wmin, wmax] or that + * is contained inside the high_abs_regions*/ +static inline cpl_array * +remove_regions_and_outliers_from_array(const cpl_array * fit_points, + const cpl_bivector * high_abs_regions, + const hdrl_data_t wmin, const hdrl_data_t wmax){ + + const cpl_size sz = cpl_array_get_size(fit_points); + double * filter = cpl_calloc(sz, sizeof(*filter)); + cpl_size k = 0; + for(cpl_size i = 0; i < sz; ++i){ + const double w = cpl_array_get(fit_points, i, NULL); + if(w > wmax) continue; + if(w < wmin) continue; + if(contained_in_any_region(w, high_abs_regions)) continue; + + filter[k] = w; + k++; + } + + if(k == 0){ + cpl_free(filter); + return NULL; + } + + return cpl_array_wrap_double(filter, k); +} + +static inline const hdrl_spectrum1Dlist * +hdrl_response_telluric_evaluation_parameter_get_telluric_models( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->telluric_models; +} + +static inline hdrl_data_t +hdrl_response_telluric_evaluation_parameter_get_w_step( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->w_step; +} + +static inline cpl_size +hdrl_response_telluric_evaluation_parameter_get_half_win( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, 0); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->half_win; +} + +static inline cpl_boolean +hdrl_response_telluric_evaluation_parameter_get_normalize( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->normalize; +} + +static inline cpl_boolean +hdrl_response_telluric_evaluation_parameter_get_shift_in_log_scale( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, CPL_FALSE); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->shift_in_log_scale; +} + +static inline const cpl_bivector * +hdrl_response_telluric_evaluation_parameter_get_quality_areas( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->quality_areas; +} + +static inline const cpl_bivector * +hdrl_response_telluric_evaluation_parameter_get_fit_areas( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->fit_areas; +} + +static inline hdrl_data_t +hdrl_response_telluric_evaluation_parameter_get_lmin( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->lmin; +} + +static inline hdrl_data_t +hdrl_response_telluric_evaluation_parameter_get_lmax( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_TELLURIC_EVALUATION, + CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_response_telluric_evaluation_parameter * p = + (const hdrl_response_telluric_evaluation_parameter *)par; + return p->lmax; +} + +static inline const cpl_array * +hdrl_response_parameter_get_fit_points( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_FIT, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + const response_fit_parameter * p = + (const response_fit_parameter *)par; + return p->fit_points; +} + +static inline const cpl_bivector * +hdrl_response_parameter_get_high_abs_regions( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_FIT, + CPL_ERROR_ILLEGAL_INPUT, NULL); + + const response_fit_parameter * p = + (const response_fit_parameter *)par; + return p->high_abs_regions; +} + +static inline cpl_size +hdrl_response_parameter_get_radius( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_FIT, + CPL_ERROR_ILLEGAL_INPUT, 0); + + const response_fit_parameter * p = + (const response_fit_parameter *)par; + return p->radius; +} + +static inline hdrl_data_t +hdrl_response_parameter_get_wrange( + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_RESPONSE_FIT, + CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const response_fit_parameter * p = + (const response_fit_parameter *)par; + return p->wrange; +} + +/*wrapper around the hdrl_spectrum1D constructor that accepts double arrays*/ +static inline hdrl_spectrum1D * +hdrl_spectrum1D_create_from_buffers(double * flux, double * wlens, cpl_size sz, + hdrl_spectrum1D_wave_scale scale){ + + cpl_array * w = cpl_array_wrap_double(wlens, sz); + cpl_image * fl = cpl_image_wrap_double(sz, 1, flux); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create_error_free(fl, w, scale); + + cpl_array_unwrap(w); + cpl_image_unwrap(fl); + return to_ret; +} +/* For every window in "areas", extract a flux point having as wavelength the + * middle point of the window and as flux the median of the flux value defined + * on the window.*/ +static inline hdrl_spectrum1D * + hdrl_spectrum1D_extract_fit_regions(const hdrl_spectrum1D * s, + const cpl_bivector * areas){ + + const double step = 1.0; + + cpl_size sz = cpl_bivector_get_size(areas); + const cpl_vector * l_min = cpl_bivector_get_x_const(areas); + const cpl_vector * l_max = cpl_bivector_get_y_const(areas); + + double * flux = cpl_calloc(sz + 2, sizeof(double)); + double * wlens = cpl_calloc(sz + 2, sizeof(double)); + + const hdrl_data_t wmin = + cpl_array_get_min(hdrl_spectrum1D_get_wavelength(s).wavelength); + const hdrl_data_t wmax = + cpl_array_get_max(hdrl_spectrum1D_get_wavelength(s).wavelength); + { + hdrl_spectrum1D * s_sel = + select_win(s, wmin - step, wmin + step); + + const hdrl_image * sel_flux = hdrl_spectrum1D_get_flux(s_sel); + flux[0] = hdrl_image_get_median(sel_flux).data; + wlens[0] = wmin; + + hdrl_spectrum1D_delete(&s_sel); + } + + cpl_size size_sel = 1; + for(cpl_size i = 0; i < sz; ++i){ + const double lambda_min = cpl_vector_get(l_min, i); + const double lambda_max = cpl_vector_get(l_max, i); + + hdrl_spectrum1D * s_sel = + select_win(s, lambda_min, lambda_max); + + if(s_sel == NULL){ + cpl_error_reset(); + continue; + } + wlens[size_sel] = .5 * (lambda_max + lambda_min); + const hdrl_image * sel_flux = hdrl_spectrum1D_get_flux(s_sel); + flux[size_sel] = hdrl_image_get_median(sel_flux).data; + + hdrl_spectrum1D_delete(&s_sel); + size_sel++; + } + + { + hdrl_spectrum1D * s_sel = + select_win(s, wmax - step, wmax + step); + const hdrl_image * sel_flux = hdrl_spectrum1D_get_flux(s_sel); + flux[size_sel] = hdrl_image_get_median(sel_flux).data; + wlens[size_sel] = wmax; + hdrl_spectrum1D_delete(&s_sel); + size_sel++; + } + + hdrl_spectrum1D * sel_s = NULL; + if(size_sel > 0) + { + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_get_scale(s); + sel_s = hdrl_spectrum1D_create_from_buffers(flux, wlens, size_sel, scale); + } + + cpl_free(flux); + cpl_free(wlens); + + return sel_s; +} +/*ctor for hdrl_response_result. + * NOTE: hdrl_response_result gets ownership of all the pointers provided. + * DO NOT deallocate them, they will be de-allocated by hdrl_response_result dtor. + * */ +static inline hdrl_response_result * +hdrl_response_result_wrap(hdrl_spectrum1D * final_response, + hdrl_spectrum1D * selected_response, + hdrl_spectrum1D * raw_response, + + hdrl_spectrum1D * corrected_observed_spectrum, + cpl_size best_telluric_model_idx, + hdrl_data_t telluric_shift, + hdrl_data_t avg_diff_from_1, + hdrl_data_t stddev, + + hdrl_data_t doppler_shift){ + + hdrl_response_result * to_ret = cpl_calloc(1, sizeof(*to_ret)); + + to_ret->final_response = final_response; + to_ret->raw_response = raw_response; + to_ret->selected_response = selected_response; + + to_ret->corrected_observed_spectrum = corrected_observed_spectrum; + to_ret->best_telluric_model_idx = best_telluric_model_idx; + to_ret->telluric_shift = telluric_shift; + to_ret->avg_diff_from_1 = avg_diff_from_1; + to_ret->stddev = stddev; + + to_ret->doppler_shift = doppler_shift; + + return to_ret; +} + + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_response.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_response.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_response.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_response.h 2017-09-05 11:00:11.000000000 +0000 @@ -0,0 +1,137 @@ +/* $Id: hdrl_spectrum_response.h,v 0.1 2017-04-25 09:02:08 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-04-25 09:02:08 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_RESPONSE_H_ +#define HDRL_RESPONSE_H_ + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include +#include "hdrl_spectrum.h" +#include "hdrl_spectrumlist.h" +#include "hdrl_spectrum_shift.h" + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_response_telluric_evaluation_parameter_create( + const hdrl_spectrum1Dlist * telluric_models, + hdrl_data_t w_step, + cpl_size half_win, + cpl_boolean normalize, + cpl_boolean shift_in_log_scale, + const cpl_bivector * quality_areas, + const cpl_bivector * fit_areas, + hdrl_data_t lmin, + hdrl_data_t lmax); + +hdrl_parameter * +hdrl_response_fit_parameter_create( + const cpl_size radius, const cpl_array * fit_points, + const hdrl_data_t wrange, const cpl_bivector * high_abs_regions); + +typedef struct{ + + hdrl_spectrum1D * final_response; + hdrl_spectrum1D * selected_response; + hdrl_spectrum1D * raw_response; + + hdrl_spectrum1D * corrected_observed_spectrum; + cpl_size best_telluric_model_idx; + hdrl_data_t telluric_shift; + hdrl_data_t avg_diff_from_1; + hdrl_data_t stddev; + + hdrl_data_t doppler_shift; + +}hdrl_response_result; + +const hdrl_spectrum1D * +hdrl_response_result_get_final_response(const hdrl_response_result * res); +const hdrl_spectrum1D * +hdrl_response_result_get_selected_response(const hdrl_response_result * res); +const hdrl_spectrum1D * +hdrl_response_result_get_raw_response(const hdrl_response_result * res); +const hdrl_spectrum1D * +hdrl_response_result_get_corrected_obs_spectrum(const hdrl_response_result * res); +cpl_size +hdrl_response_result_get_best_telluric_model_idx(const hdrl_response_result * res); +hdrl_data_t +hdrl_response_result_get_avg_diff_from_1(const hdrl_response_result * res); +hdrl_data_t +hdrl_response_result_get_stddev(const hdrl_response_result * res); +hdrl_data_t +hdrl_response_result_get_telluric_shift(const hdrl_response_result * res); +hdrl_data_t +hdrl_response_result_get_doppler_shift(const hdrl_response_result * res); + +void +hdrl_response_result_delete(hdrl_response_result *); + +hdrl_response_result * +hdrl_response_compute( + const hdrl_spectrum1D * obs_s, + const hdrl_spectrum1D * ref_s, + const hdrl_spectrum1D * E_x, + const hdrl_parameter * telluric_par, + const hdrl_parameter * velocity_par, + const hdrl_parameter * calc_par, + const hdrl_parameter * fit_par); + + +#if defined HDRL_USE_PRIVATE + +hdrl_spectrum1D * +hdrl_response_evaluate_telluric_models( + const hdrl_spectrum1D * obs_s, + const hdrl_parameter * ev, + hdrl_data_t * telluric_shift, + hdrl_data_t * mean_minus_1, hdrl_data_t * stddev, + cpl_size * best_model_index); + +hdrl_spectrum1D * +hdrl_response_evaluate_telluric_model(const hdrl_spectrum1D * obs_s_arg, + const hdrl_spectrum1D * telluric_s_arg, + const hdrl_data_t w_step, + const cpl_size half_win, + const cpl_boolean normalize, + const cpl_boolean shift_in_log_scale, + const cpl_bivector * quality_areas, + const cpl_bivector * fit_areas, + const hdrl_data_t lmin, const hdrl_data_t lmax, + double * mean_minus_1, double * stddev, + double * telluric_shift); +#endif + +CPL_END_DECLS + +#endif /* HDRL_RESPONSE_H_ */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_sigclip.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_sigclip.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_sigclip.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_sigclip.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,892 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#include "hdrl_sigclip.h" +#include "hdrl_utils.h" +#include "hdrl_collapse.h" + +#include +#include +#include + + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +static cpl_error_code hdrl_sort_double_pairs(cpl_vector *, cpl_vector *) ; +static long get_lower_bound_d(double * vec, long count, double val); +static long get_upper_bound_d(double * vec, long count, double val); +static long get_lower_bound(cpl_vector * vec, double val); +static long get_upper_bound(cpl_vector * vec, double val); + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_sigclip Clipping module + + This module provides parameters for iterative \f$\kappa-\sigma\f$ clipping and + minmax rejection. + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/* ---------------------------------------------------------------------------*/ +/** + @brief Create parameters for the sigma-clip collapse + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param defaults default sigclip parameters + @return The created parameter list + Creates a parameterlist containing + base_context.prefix.kappa-low + base_context.prefix.kappa-high + base_context.prefix.niter + */ +/* ---------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_sigclip_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *defaults) +{ + cpl_ensure(base_context && prefix && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_collapse_parameter_is_sigclip(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist *parlist = cpl_parameterlist_new(); + + /* --prefix.kappa-low */ + hdrl_setup_vparameter(parlist, prefix, ".", "", + "kappa-low", base_context, + "Low kappa factor for kappa-sigma clipping algorithm", + CPL_TYPE_DOUBLE, + hdrl_collapse_sigclip_parameter_get_kappa_low(defaults)); + + /* --prefix.kappa-high */ + hdrl_setup_vparameter(parlist, prefix, ".", "", + "kappa-high", base_context, + "High kappa factor for kappa-sigma clipping algorithm", + CPL_TYPE_DOUBLE, + hdrl_collapse_sigclip_parameter_get_kappa_high(defaults)); + + /* --prefix.niter */ + hdrl_setup_vparameter(parlist, prefix, ".", "", + "niter", base_context, + "Maximum number of clipping iterations for kappa-sigma clipping", + CPL_TYPE_INT, + hdrl_collapse_sigclip_parameter_get_niter(defaults)); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} +/* ---------------------------------------------------------------------------*/ +/** + @brief Create parameters for the minmax-clip collapse + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param defaults default minmax parameters + @return The created parameter list + Creates a parameterlist containing + base_context.prefix.nlow + base_context.prefix.nhigh + */ +/* ---------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_minmax_parameter_create_parlist( + const char *base_context, + const char *prefix, + const hdrl_parameter *defaults) +{ + cpl_ensure(base_context && prefix && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_collapse_parameter_is_minmax(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist * parlist = cpl_parameterlist_new(); + + /* --prefix.nlow */ + hdrl_setup_vparameter(parlist, prefix, ".", "", + "nlow", base_context, + "Low number of pixels to reject for the minmax clipping algorithm", + CPL_TYPE_DOUBLE, + hdrl_collapse_minmax_parameter_get_nlow(defaults)); + + /* --prefix.nhigh */ + hdrl_setup_vparameter(parlist, prefix, ".", "", + "nhigh", base_context, + "High number of pixels to reject for the minmax clipping algorithm", + CPL_TYPE_DOUBLE, + hdrl_collapse_minmax_parameter_get_nhigh(defaults)); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief parse parameterlist for sigclip parameters to init corresponding hdrl + * structure parameters + * + * @param parlist parameter list to parse + * @param prefix prefix of parameter name + * @param kappa_low pointer to storage to save kappa_low or NULL + * @param kappa_high pointer to storage to save kappa_high or NULL + * @param niter pointer to storage to save niter or NULL + * @see hdrl_kappa_sigma_clip_get_parlist() + * @return cpl_error_code + * + * parameterlist should have been created with + * hdrl_kappa_sigma_clip_get_parlist or have the same name hierachy + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_sigclip_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix, + double * kappa_low, + double * kappa_high, + int * niter) +{ + cpl_ensure_code(prefix && parlist, CPL_ERROR_NULL_INPUT); + char * name; + + if (kappa_low) { + name = hdrl_join_string(".", 2, prefix, "sigclip.kappa-low"); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + *kappa_low = cpl_parameter_get_double(par); + cpl_free(name); + } + + if (kappa_high) { + name = hdrl_join_string(".", 2, prefix, "sigclip.kappa-high"); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + *kappa_high = cpl_parameter_get_double(par); + cpl_free(name); + } + + if (niter) { + name = hdrl_join_string(".", 2, prefix, "sigclip.niter"); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + *niter = cpl_parameter_get_int(par); + cpl_free(name); + } + + if (cpl_error_get_code()) { + return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist " + "with prefix %s", prefix); + } + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief parse parameterlist for minmax parameters to init corresponding hdrl + * structure parameters + * + * @param parlist parameter list to parse + * @param prefix prefix of parameter name + * @param nlow pointer to storage to save nlow or NULL + * @param nhigh pointer to storage to save nhigh or NULL + * @see hdrl_minmax_clip_get_parlist() + * @return cpl_error_code + * + * parameterlist should have been created with + * hdrl_minmax_clip_get_parlist or have the same name hierachy + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_minmax_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix, + double * nlow, + double * nhigh) +{ + cpl_ensure_code(prefix && parlist, CPL_ERROR_NULL_INPUT); + char * name; + + if (nlow) { + name = hdrl_join_string(".", 2, prefix, "minmax.nlow"); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + *nlow = cpl_parameter_get_double(par); + cpl_free(name); + } + + if (nhigh) { + name = hdrl_join_string(".", 2, prefix, "minmax.nhigh"); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + *nhigh = cpl_parameter_get_double(par); + cpl_free(name); + } + + if (cpl_error_get_code()) { + return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist " + "with prefix %s", prefix); + } + + return CPL_ERROR_NONE; +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Compute mean image value using min-max rejection method + @param source Input image + @param error Input error image + @param nlow Absolute number of low pixels to reject + @param nhigh Absolute number of high pixels to reject + @param mean_mm The min-max clipped mean + @param mean_mm_err The propagated error of the min-max clipped mean + @param naccepted Number of accepted values + @return @c CPL_ERROR_NONE or the appropriate error code. + @see hdrl_minmax_clip() + + This function converts the image inputs into the proper data types in + order to call the hdrl_minmax_clip() function. + If the error values at the rejection boundaries are ambigous, e.g. when you + have multiple pixels with the same value but different error and the + rejection boundary would only select a subset of these, the algorithm assigns + the smallest error values of the equal value range to the selected pixels. + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_minmax_clip_image( + const cpl_image * source, + const cpl_image * error, + const double nlow, + const double nhigh, + double * mean_mm, + double * mean_mm_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high) +{ + cpl_vector * vec_source = NULL; + cpl_vector * vec_error = NULL; + + /* Check Entries */ + cpl_error_ensure(source != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input source image!"); + cpl_error_ensure(error != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input error image!"); + cpl_error_ensure(cpl_image_get_size_x(source)==cpl_image_get_size_x(error), + CPL_ERROR_INCOMPATIBLE_INPUT, return CPL_ERROR_INCOMPATIBLE_INPUT, + "source and error image musty have same X size"); + cpl_error_ensure(cpl_image_get_size_y(source)==cpl_image_get_size_y(error), + CPL_ERROR_INCOMPATIBLE_INPUT, return CPL_ERROR_INCOMPATIBLE_INPUT, + "source and error image musty have same Y size"); + + /* compress images to vectors excluding the bad pixels */ + vec_source = hdrl_image_to_vector(source, NULL); + vec_error = hdrl_image_to_vector(error, cpl_image_get_bpm_const(source)); + + if (vec_source != NULL && vec_error != NULL) { + /* Call here the real clipping function */ + hdrl_minmax_clip(vec_source, vec_error, nlow, nhigh, CPL_TRUE, mean_mm, + mean_mm_err, naccepted, reject_low, reject_high); + } + /* no good pixels */ + else { + *mean_mm = NAN; + *mean_mm_err = NAN; + *naccepted = 0; + *reject_low = NAN; + *reject_high = NAN; + } + + cpl_msg_debug(cpl_func, "mean_mm, mean_mm_err, naccepted: %g, %g, %ld", + *mean_mm, *mean_mm_err, (long)*naccepted); + + cpl_vector_delete(vec_source); + cpl_vector_delete(vec_error); + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Compute mean using min-max clipping. + @param vec The vector for which the clipped mean is computed. + @param vec_err The error of vec. + @param nlow The number of low pixels to be rejected by the algorithm + @param nhigh The number of high pixels to be rejected by the algorithm + @param inplace If true the input vectors are modified + @param mean_mm The min-max clipped mean. + @param mean_mm_err The propagated error of the min-max clipped mean. + @param naccepted Number of accepted values. + @param reject_low The lowest value that is rejected + @param reject_high The highest value that is rejected + @return @c CPL_ERROR_NONE or the appropriate error code. + + This function computes the mean after sorting the elements and rejecting nlow + and nhigh values. The remaining pixels are then used to compute the mean and + the associated error. Please note that, if multiple equal elements are + present, the error propagation uses the value with the smallest error. + + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_minmax_clip( + cpl_vector * vec, + cpl_vector * vec_err, + const double nlow, + const double nhigh, + cpl_boolean inplace, + double * mean_mm, + double * mean_mm_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high) +{ + /* VARIABLES ON THE FUNCTION SCOPE: + + vec_image a deep copy of the input vector vec. + mean_mm min-max clip mean (return variable). + */ + + cpl_vector * vec_image = NULL; + cpl_vector * vec_image_err = NULL; + + cpl_size vec_size; + cpl_size nlow_int, nhigh_int; + cpl_vector * vec_trunc; + + cpl_size trunc_size; + double * d, * e; + + /*In the future minmax rejection could also use relative values therefore + * we pass a double to the function - nevertheless the code as it is now + * expects an integer - thus we need to do the rounding */ + + nlow_int = (cpl_size)round(nlow); + nhigh_int = (cpl_size)round(nhigh); + + cpl_error_ensure(vec != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input vector data"); + cpl_error_ensure(vec_err != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input vector errors"); + cpl_error_ensure(cpl_vector_get_size(vec) == cpl_vector_get_size(vec_err), + CPL_ERROR_INCOMPATIBLE_INPUT, + return CPL_ERROR_INCOMPATIBLE_INPUT, + "input data and error vectors must have same sizes"); + cpl_error_ensure(mean_mm != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input mean storage"); + + cpl_error_ensure(nlow_int >=0 && nhigh_int>=0, CPL_ERROR_INCOMPATIBLE_INPUT, + return CPL_ERROR_INCOMPATIBLE_INPUT, "nlow and nhigh must " + "be strictly positive"); + + vec_size = cpl_vector_get_size(vec); + + /* Nothing to do if only one data point */ + if(vec_size <= (nlow_int+nhigh_int)) { + *mean_mm=NAN; + *mean_mm_err=NAN; + *naccepted=0; + return cpl_error_get_code(); + } + + if (inplace) { + vec_image = vec; + vec_image_err = vec_err; + } + else { + vec_image = cpl_vector_duplicate(vec); + vec_image_err = cpl_vector_duplicate(vec_err); + } + + hdrl_sort_double_pairs(vec_image, vec_image_err); + + trunc_size = (vec_size - nhigh_int) - nlow_int; + d = cpl_vector_get_data(vec_image); + e = cpl_vector_get_data(vec_image_err); + vec_trunc = cpl_vector_wrap(trunc_size, d + nlow_int); + + /* COMPUTE THE MIN-MAX CLIP MEAN */ + *mean_mm = cpl_vector_get_mean(vec_trunc); + + if (naccepted) { + *naccepted = trunc_size; + } + + if (reject_low) { + *reject_low = d[nlow_int]; + } + if (reject_high) { + *reject_high = d[vec_size - nhigh_int - 1]; + } + + if (mean_mm_err) { + cpl_vector * vec_trunc_err; + /* if multiple equal elements use the one with the smallest error + * get the equal range, sort the errors and write the smallest into the + * valid array ends */ + intptr_t l = get_lower_bound(vec_image, d[nlow_int]); + intptr_t h = get_upper_bound(vec_image, d[nlow_int]); + if (h - l > 1 && h - l != vec_size) { + cpl_vector * e_vec = cpl_vector_extract(vec_image_err, l, h - 1, 1); + cpl_vector_sort(e_vec, CPL_SORT_ASCENDING); + for (intptr_t i = nlow_int; i < h; i++) { + cpl_vector_set(vec_image_err, i, + cpl_vector_get(e_vec, i - nlow_int)); + } + cpl_vector_delete(e_vec); + } + + l = get_lower_bound(vec_image, d[vec_size - nhigh_int - 1]); + h = get_upper_bound(vec_image, d[vec_size - nhigh_int - 1]); + if (h - l > 1 && h - l != vec_size) { + cpl_vector * e_vec = cpl_vector_extract(vec_image_err, l, h - 1, 1); + cpl_vector_sort(e_vec, CPL_SORT_ASCENDING); + for (intptr_t i = l; i < vec_size - nhigh; i++) { + cpl_vector_set(vec_image_err, i, + cpl_vector_get(e_vec, i - l)); + } + cpl_vector_delete(e_vec); + } + + vec_trunc_err = cpl_vector_wrap(trunc_size, e + nlow_int); + /*Propagate the errors (cpl_vector_power is very slow PIPE-4330) */ + cpl_vector_multiply(vec_trunc_err, vec_trunc_err); + *mean_mm_err = sqrt(cpl_vector_get_mean(vec_trunc_err) / + cpl_vector_get_size(vec_trunc_err)); + cpl_vector_unwrap(vec_trunc_err); + } + /* CLEAN, AND RETURN */ + cpl_vector_unwrap(vec_trunc); + if (!inplace) { + cpl_vector_delete(vec_image); + cpl_vector_delete(vec_image_err); + } + return cpl_error_get_code(); +} + + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Compute mean image value using kappa-sigma clipping method + @param source Input image + @param error Input error image + @param kappa_low Number of sigmas for lower threshold + @param kappa_high Number of sigmas for upper threshold + @param iter Number of iterations + @param mean_ks The kappa-sigma clipped mean + @param mean_ks_err The propagated error of the kappa-sigma clipped mean + @param naccepted Number of accepted values + @param reject_low Values lower than this have been rejected + @param reject_high Values higher than this have been rejected + @return @c CPL_ERROR_NONE or the appropriate error code. + @see hdrl_kappa_sigma_clip() + + This function converts the image inputs into the proper data types in + order to call the hdrl_kappa_sigma_clip() function. + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_kappa_sigma_clip_image( + const cpl_image * source, + const cpl_image * error, + const double kappa_low, + const double kappa_high, + const int iter, + double * mean_ks, + double * mean_ks_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high) +{ + cpl_vector * vec_source = NULL; + cpl_vector * vec_error = NULL; + + /* Check Entries */ + cpl_error_ensure(source != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input source image!"); + cpl_error_ensure(error != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input error image!"); + cpl_error_ensure(cpl_image_get_size_x(source)==cpl_image_get_size_x(error), + CPL_ERROR_INCOMPATIBLE_INPUT, return CPL_ERROR_INCOMPATIBLE_INPUT, + "source and error image musty have same X size"); + cpl_error_ensure(cpl_image_get_size_y(source)==cpl_image_get_size_y(error), + CPL_ERROR_INCOMPATIBLE_INPUT, return CPL_ERROR_INCOMPATIBLE_INPUT, + "source and error image musty have same Y size"); + + /* compress images to vectors excluding the bad pixels */ + vec_source = hdrl_image_to_vector(source, NULL); + vec_error = hdrl_image_to_vector(error, cpl_image_get_bpm_const(source)); + + if (vec_source != NULL && vec_error != NULL) { + /* Call here the real sigma-clipping function */ + hdrl_kappa_sigma_clip(vec_source, vec_error, kappa_low, kappa_high, + iter, CPL_TRUE, mean_ks, mean_ks_err, naccepted, + reject_low, reject_high); + } + /* no good pixels */ + else { + *mean_ks = NAN; + *mean_ks_err = NAN; + *naccepted = 0; + *reject_low = NAN; + *reject_high = NAN; + } + + cpl_msg_debug(cpl_func, "mean_ks, mean_ks_err, naccepted: %g, %g, %ld", + *mean_ks, *mean_ks_err, (long)*naccepted); + + cpl_vector_delete(vec_source); + cpl_vector_delete(vec_error); + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get first index that compares greater than value + * @param vec vector to check + * @param count size of vector + * @param val upper bound to check + */ +/* ---------------------------------------------------------------------------*/ +static long get_upper_bound_d(double * vec, long count, double val) +{ + long first = 0; + while (count > 0) + { + long step = count / 2; + long it = first + step; + if (!(val < vec[it])) { + first = it + 1; + count -= step + 1; + } + else + count = step; + } + return first; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get first index that compares greater than value + * @param vec vector to check + * @param val upper bound to check + */ +/* ---------------------------------------------------------------------------*/ +static long get_upper_bound(cpl_vector * vec, double val) +{ + double * d = cpl_vector_get_data(vec); + long count = cpl_vector_get_size(vec); + return get_upper_bound_d(d, count, val); +} +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get index that compares does not compare less than value + * @param vec vector to check + * @param count size of vector + * @param val upper bound to check + */ +/* ---------------------------------------------------------------------------*/ +static long get_lower_bound_d(double * vec, long count, double val) +{ + long first = 0; + while (count > 0) + { + long step = count / 2; + long it = first + step; + if (vec[it] < val) { + first = it + 1; + count -= step + 1; + } + else + count = step; + } + return first; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief get index that compares does not compare less than value + * @param vec vector to check + * @param val upper bound to check + */ +/* ---------------------------------------------------------------------------*/ +static long get_lower_bound(cpl_vector * vec, double val) +{ + double * d = cpl_vector_get_data(vec); + long count = cpl_vector_get_size(vec); + return get_lower_bound_d(d, count, val); +} + +/* compute mean and error without needing to wrap a vector, the allocation can + * be very expensive for small stacks of images */ +static void get_mean_err(const double * d, const double * e, long count, + double * rm, double * re) +{ + double m = 0.; + for (long i = 0; i < count; i++) { + m += (d[i] - m) / (double)(i + 1); + } + *rm = m; + + if (re) { + double se = 0; + for (long i = 0; i < count; i++) { + se += e[i] * e[i]; + } + *re = sqrt(se) / count; + } +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Compute mean using kappa-sigma clipping. + @param vec The vector for which mean is to be computed. + @param vec_err The error of vec. + @param kappa_low Number of sigmas for lower threshold. + @param kappa_high Number of sigmas for upper threshold. + @param iter Number of iterations. + @param inplace if true the vectors input are modified + @param mean_ks The kappa-sigma clipped mean. + @param mean_ks_err The propagated error of the kappa-sigma clipped mean. + @param naccepted Number of accepted values. + @param reject_low Values lower than this have been rejected. + @param reject_high Values higher than this have been rejected + @return @c CPL_ERROR_NONE or the appropriate error code. + + The function computes the arithmetic mean of a vector after rejecting + outliers using kappa-sigma clipping. Robust estimates of the mean and + standard deviation are used to derive the interval within which values in + the vector are considered good. + + The sigma-clipping is applied on the vec vector data. The vec_err vector + is used for the error computation. + + An iterative process of rejection of the outlier elements of vec is + applied. iter specifies the maximum number of iterations. + + At each iteration, the median and sigma values of the vector are computed and + used to derive low and high thresholds (\f$median-kappa\_low \times sigma\f$ + and \f$median+kappa\_low \times sigma\f$). The values of vec outside those + bounds are rejected and the remaining values are passed to the next + iteration. + + The mean value of the remaining elements is stored into mean_ks. + mean_ks_err contains \f$\frac{\sum_i{val_i^{2}}}{N}\f$ where \f$val_i\f$ + are the remaining elements of vec_err and N the number of those elements. + The N value is stored in naccepted. + + reject_low and reject_high are the final thresholds differenciating the + rejected pixels from the others. + + The iterative process is illustrated here: + \image html sigclip_algorithm.png + + Note that the \f$\sigma\f$ used for the thresholding in the different + iterations is not the standard deviation but the scaled + Median Absolute Deviation (MAD). The scaling is + \f$\sigma = MAD \times CPL_MATH_STD_MAD\f$. + + The MAD is a more robust estimate of the scale of the distribution than the + standard deviation but only has ??% of the asymptotic statistical efficiency + for normal distributed data. This higher error in scale parameter only has + limited influence on the result as it is only used determination of clipping + thresholds. + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_kappa_sigma_clip( + cpl_vector * vec, + cpl_vector * vec_err, + const double kappa_low, + const double kappa_high, + const int iter, + cpl_boolean inplace, + double * mean_ks, + double * mean_ks_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high) +{ + /* VARIABLES ON THE FUNCTION SCOPE: + + vec_image a deep copy of the input vector vec. + mean_ks kappa-sigma clip mean (return variable). + mean_ks kappa-sigma clip mean (return variable). + */ + + cpl_vector * vec_image = NULL; + cpl_vector * vec_image_err = NULL; + + cpl_size vec_size; + double lower_bound = 0.; + double upper_bound = 0.; + + cpl_error_ensure(vec != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input vector data"); + cpl_error_ensure(vec_err != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input vector errors"); + cpl_error_ensure(cpl_vector_get_size(vec) == cpl_vector_get_size(vec_err), + CPL_ERROR_INCOMPATIBLE_INPUT, + return CPL_ERROR_INCOMPATIBLE_INPUT, + "input data and error vectors must have same sizes"); + cpl_error_ensure(mean_ks != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "Null input mean storage"); + cpl_error_ensure(iter > 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "iter must be larger than 0"); + + if (inplace) { + vec_image = vec; + vec_image_err = vec_err; + } + else { + vec_image = cpl_vector_duplicate(vec); + vec_image_err = cpl_vector_duplicate(vec_err); + } + double * vec_data = cpl_vector_get_data(vec_image); + double * vec_data_orig = vec_data; + double * vec_data_err = cpl_vector_get_data(vec_image_err); + vec_size = cpl_vector_get_size(vec_image); + + /* sort the two vectors by the data */ + hdrl_sort_double_pairs(vec_image, vec_image_err); + + for(int it = 0; it < iter; it++) { + double median, sigma; + cpl_size lower_index, upper_index; + + /* Nothing to do if only one data point */ + if(vec_size == 1) { + lower_bound = vec_data[0]; + upper_bound = lower_bound; + break; + } + + /* STEPS OF KAPPA SIGMA CLIP + 1. Sort the vector. + 2. Find mean, and standard deviation (sigma). + 3. Find lower, and upper bound after kappa-sigma clip. + 4. Find index which corresponds to lower and upper bound + 5. Extract the vector within the index bound. + */ + + /* Use median as a robust estimator of the mean */ + + /* standard deviation from Median Absolute Deviation (MAD) as appropriate + for a Gaussian distribution */ + + /* offset index into original uncut vec_image */ + cpl_size orig_offset = (cpl_size)(vec_data - vec_data_orig) + 1; + median = hcpl_vector_get_mad_window(vec_image, orig_offset, + orig_offset + vec_size - 1, &sigma); + + if(sigma <= 0){ + sigma=nextafter(0,1.0); + } + sigma *= CPL_MATH_STD_MAD; + + lower_bound = median - kappa_low * sigma; + upper_bound = median + kappa_high * sigma; + + lower_index = get_lower_bound_d(vec_data, vec_size, lower_bound); + upper_index = get_upper_bound_d(vec_data, vec_size, upper_bound); + upper_index = CX_MAX(upper_index - 1, 0); + + /* Stop if no outliers were found */ + if ((lower_index == 0) && (upper_index == vec_size - 1)) + break; + + /* truncate vector */ + vec_data = vec_data + lower_index; + vec_data_err = vec_data_err + lower_index; + vec_size = upper_index - lower_index + 1; + } + + /* COMPUTE THE KAPPA-SIGMA CLIP MEAN */ + get_mean_err(vec_data, vec_data_err, vec_size, mean_ks, mean_ks_err); + + if (naccepted) *naccepted = vec_size; + + if (reject_low) *reject_low = lower_bound; + if (reject_high) *reject_high = upper_bound; + + /* CLEAN, AND RETURN */ + if (!inplace) { + cpl_vector_delete(vec_image); + cpl_vector_delete(vec_image_err); + } + return cpl_error_get_code(); +} + + +/*---------------------------------------------------------------------------*/ +/** + @internal + @brief Sort an array @a u1 of doubles, and permute an array @a u2 + in the same way as @a u1 is permuted. + @param u1 Pointer to the first array. + @param u2 Pointer to the second array. + @return @c CPL_ERROR_NONE or the appropriate error code. + */ +/*---------------------------------------------------------------------------*/ +static cpl_error_code hdrl_sort_double_pairs(cpl_vector *u1, cpl_vector *u2) +{ + cpl_bivector * bi_all = NULL; + + cpl_error_ensure(u1 != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL pointer to 1st array"); + cpl_error_ensure(u2 != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL pointer to 2nd array"); + + bi_all = cpl_bivector_wrap_vectors(u1, u2); + cpl_bivector_sort(bi_all, bi_all, CPL_SORT_ASCENDING, CPL_SORT_BY_X); + + /* cleaning up */ + cpl_bivector_unwrap_vectors(bi_all); + + return CPL_ERROR_NONE; +} + + +/**@}*/ +/** @endcond */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_sigclip.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_sigclip.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_sigclip.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_sigclip.h 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,110 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifndef HDRL_SIGCLIP_H_ +#define HDRL_SIGCLIP_H_ + +/*----------------------------------------------------------------------------- + Include + -----------------------------------------------------------------------------*/ + +#include "hdrl_parameter.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +cpl_parameterlist * hdrl_sigclip_parameter_create_parlist( + const char * base_context, + const char * prefix, + const hdrl_parameter * defaults); + +cpl_error_code hdrl_sigclip_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix, + double * kappa_low, + double * kappa_high, + int * niter); + +cpl_parameterlist * hdrl_minmax_parameter_create_parlist( + const char * base_context, + const char * prefix, + const hdrl_parameter * defaults); + +cpl_error_code hdrl_minmax_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix, + double * nlow, + double * nhigh); + +cpl_error_code hdrl_kappa_sigma_clip_image( + const cpl_image * source, + const cpl_image * error, + const double kappa_low, + const double kappa_high, + const int iter, + double * mean_ks, + double * mean_ks_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high); + +cpl_error_code hdrl_minmax_clip_image( + const cpl_image * source, + const cpl_image * error, + const double nlow, + const double nhigh, + double * mean_mm, + double * mean_mm_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high); + +cpl_error_code hdrl_kappa_sigma_clip( + cpl_vector * vec, + cpl_vector * vec_err, + const double kappa_low, + const double kappa_high, + const int iter, + cpl_boolean inplace, + double * mean_ks, + double * mean_ks_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high); + +cpl_error_code hdrl_minmax_clip( + cpl_vector * vec, + cpl_vector * vec_err, + const double nlow, + const double nhigh, + cpl_boolean inplace, + double * mean_mm, + double * mean_mm_err, + cpl_size * naccepted, + double * reject_low, + double * reject_high); + + +CPL_END_DECLS + +#endif /* HDRL_SIGCLIP_H_ */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum.c 2018-01-10 10:09:38.000000000 +0000 @@ -0,0 +1,1522 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_spectrum.h" + +#include "hdrl_DER_SNR.h" +#include "hdrl_utils.h" + +#include + +/** + * + * @defgroup hdrl_spectrum1D Spectrum 1D + * + * @brief + * This module defines the hdrl_spectrum1D data structure, + * provides basic functionalities for it (constructors, destructor, operators). + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ +typedef cpl_error_code (* operate_image_mutable) (hdrl_image * self, + const hdrl_image * other); + +typedef cpl_error_code (* operate_image_scalar_mutable) (hdrl_image * self, + hdrl_value scalar); + +static inline cpl_error_code +operate_spectra_flux_mutate(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other, + operate_image_mutable func); + +static inline hdrl_spectrum1D * +operate_spectra_flux_create(const hdrl_spectrum1D * self, + const hdrl_spectrum1D * other, + operate_image_mutable func); + +static inline cpl_error_code +operate_spectra_scalar_flux_mutate(hdrl_spectrum1D * self, + hdrl_value scalar, + operate_image_scalar_mutable func); + +static inline hdrl_spectrum1D * +operate_spectra_scalar_flux_create(const hdrl_spectrum1D * self, + hdrl_value scalar, + operate_image_scalar_mutable func); + +static inline +hdrl_spectrum1D * hdrl_spectrum1D_wrap(hdrl_image * arg_flux, + cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale); + +static inline int compare_double(const void * a, const void * b); + +static inline cpl_boolean is_uniformly_sampled(const double * v, cpl_size sz, + double * bin); + + +static inline cpl_boolean +is_wlen_selected(const cpl_bivector * windows, const cpl_boolean is_internal, + const hdrl_data_t w); + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1D default constructor + * @param arg_flux flux with bpm + * @param arg_flux_e error for the flux + * @param wavelength wavelengths + * @param wave_scale the scale of the wavelengths of the spectrum (logarithmic + * or linear) + * @return hdrl_spectrum1D or NULL on error + * + * The constructor allocates memory of a hdrl_spectrum1D structure. The + * cpl_image(s) and the cpl_array are copied inside the newly allocated data + * structure. The bpm of arg_flux becomes the bpm of the spectrum. + * + * @note providing a sorted, strictly monotonic increasing wavelength array will + * improve performance of DER_SNR calculation and resampling since no sorting will + * be required. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the images or array are NULL + * - CPL_ERROR_INCOMPATIBLE_INPUT: if the sizes of images and array do not match, + * or if the height of the image is not 1. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_create(const cpl_image * arg_flux, + const cpl_image * arg_flux_e, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale wave_scale){ + + cpl_ensure(arg_flux != NULL && wavelength != NULL && arg_flux_e != NULL, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(cpl_image_get_size_y(arg_flux) == 1 + && cpl_image_get_size_y(arg_flux_e) == 1, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_ensure(cpl_image_get_size_x(arg_flux) == cpl_array_get_size(wavelength) + && cpl_image_get_size_x(arg_flux_e) == cpl_array_get_size(wavelength), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_image * flux_error = cpl_image_cast(arg_flux_e, HDRL_TYPE_ERROR); + cpl_image * flux = cpl_image_cast(arg_flux, HDRL_TYPE_DATA); + + hdrl_image * flux_img = hdrl_image_wrap(flux, flux_error, NULL, CPL_TRUE); + cpl_array * lambda = cpl_array_cast(wavelength, HDRL_TYPE_DATA); + + return hdrl_spectrum1D_wrap(flux_img, lambda, wave_scale); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1D constructor in the case of a spectrum defined by an + * analytical function + * @param func analytical function defining the spectrum + * @param wavelength frequencies the flux is calculated on + * @param scale the scale of the spectrum (logarithmic or linear) + * @return hdrl_spectrum1D or NULL on error + * + * The constructor allocates memory of a hdrl_spectrum1D structure. + * The cpl_array is copied inside the newly allocated data structure. + * For every wavelength inside the CPL array flux and error are calculated using + * func. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any among the func or the array are NULL. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_create_analytic( + calculate_analytic_spectrum_point func, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale){ + + cpl_ensure(wavelength != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(func != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_size sx = cpl_array_get_size(wavelength); + cpl_image * flux = cpl_image_new(sx, 1, HDRL_TYPE_DATA); + cpl_image * flux_e = cpl_image_new(sx, 1, HDRL_TYPE_ERROR); + + for(cpl_size i = 0; i < sx; ++i){ + hdrl_data_t lambda = cpl_array_get(wavelength, i, NULL); + hdrl_value v = func(lambda); + cpl_image_set(flux, i + 1, 1, v.data); + cpl_image_set(flux_e, i + 1, 1, v.error); + } + + hdrl_spectrum1D * to_ret = + hdrl_spectrum1D_create(flux, flux_e, wavelength, scale); + + cpl_image_delete(flux); + cpl_image_delete(flux_e); + + return to_ret; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1D constructor in the case of error-free spectrum + * (i.e. the error on the flux is zero for every wavelengths). + * @param arg_flux flux with bpm + * @param wavelength frequencies + * @param scale the scale of the spectrum (logarithmic or linear) + * @return hdrl_spectrum1D or NULL on error + * + * The constructor allocates memory of a hdrl_spectrum1D structure. + * The cpl_array and the cpl_image are copied inside the newly allocated data + * structure. The flux error is considered to be zero. + * + * Possible cpl-error-code set in this function: see hdrl_spectrum1D_create() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_create_error_free + (const cpl_image * arg_flux, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale){ + + cpl_ensure(arg_flux != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_size sx = cpl_image_get_size_x(arg_flux); + cpl_size sy = cpl_image_get_size_y(arg_flux); + + cpl_ensure(sy == 1 && sx > 0, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_image * zero_errors = cpl_image_new(sx, sy, HDRL_TYPE_ERROR); + cpl_image_fill_window(zero_errors, 1, 1, sx, sy, 0.0); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create + (arg_flux, zero_errors, wavelength, scale); + + cpl_image_delete(zero_errors); + + return to_ret; + +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1D constructor when no error information is available, in + * this case we use DER_SNR to esimate the error. Please refer to the + * documentation of the function estimate_noise_DER_SNR(). + * @param arg_flux flux with bpm + * @param half_window half window the DER_SNR is calculated on + * @param wavelength frequencies + * @param scale the scale of the spectrum (logarithmic or linear) + * @return hdrl_spectrum1D or NULL on error + * + * The constructor allocates memory of a hdrl_spectrum1D structure. + * The cpl_array and the cpl_image are copied inside the newly allocated data + * structure. The flux error is calculated creating a window of + * 2 * half_window + 1 pixels around each flux pixel and then using the noise + * estimation used for DER_SNR calculation. The use of DER_SNR can increase the + * number of bad pixels, in the case of a good pixel surrounded by bad pixels. + * See estimate_noise_DER_SNR() for more details. + * + * Possible cpl-error-code set in this function: see hdrl_spectrum1D_create() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_create_error_DER_SNR + (const cpl_image * arg_flux, + cpl_size half_window, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale){ + cpl_ensure(arg_flux != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(wavelength != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_size sx = cpl_image_get_size_x(arg_flux); + cpl_size sy = cpl_image_get_size_y(arg_flux); + + cpl_ensure(sy == 1 && sx > 0, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_image * flux = cpl_image_cast(arg_flux, HDRL_TYPE_DATA); + + const hdrl_data_t * flux_data = + (const hdrl_data_t*)cpl_image_get_data_const(flux); + const cpl_mask * mask_in = cpl_image_get_bpm_const(flux); + const cpl_binary * msk_in = + mask_in == NULL ? NULL : cpl_mask_get_data_const(mask_in); + + cpl_image * DER_SNR_errors = estimate_noise_DER_SNR + (flux_data, msk_in, wavelength, sx, half_window); + + if(!DER_SNR_errors || cpl_error_get_code() != CPL_ERROR_NONE){ + cpl_image_delete(flux); + cpl_image_delete(DER_SNR_errors); + return NULL; + } + + /* DER_SNR_errors might contain more bad pixels than flux, e.g. 1 good pixel + * in position i that is surrounded by bad pixels + */ + cpl_mask * msk = cpl_image_unset_bpm(DER_SNR_errors); + cpl_mask_delete(cpl_image_set_bpm(flux, msk)); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create + (flux , DER_SNR_errors, wavelength, scale); + + cpl_image_delete(DER_SNR_errors); + cpl_image_delete(flux); + + return to_ret; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1D copy constructor + * @param self spectrum that has to be duplicated + * @return a copy of self, return NULL if self was NULL + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_duplicate(const hdrl_spectrum1D* self) +{ + if(!self) return NULL; + + hdrl_image * flux = hdrl_image_duplicate(self->flux); + cpl_array * lambdas = cpl_array_duplicate(self->wavelength); + + + return hdrl_spectrum1D_wrap(flux, lambdas, self->wave_scale); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1D destructor + * @param p_self spectrum to delete. + * @return nothing + * + * If p_self is NULL or *p_self is NULL nothing is done. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_spectrum1D_delete(hdrl_spectrum1D ** p_self){ + + if(!p_self) return; + + hdrl_spectrum1D * spectrum = *p_self; + + if(!spectrum) return; + + cpl_array_delete(spectrum->wavelength); + hdrl_image_delete(spectrum->flux); + cpl_free(spectrum); + + *p_self = NULL; +} + +/** + * @brief hdrl_spectrum1D getter for size + * @param self the spectrum + * @return the number of samples the 1D spectrum is made of + */ +/* ---------------------------------------------------------------------------*/ +cpl_size hdrl_spectrum1D_get_size(const hdrl_spectrum1D * self){ + + if(!self) return 0; + + return cpl_array_get_size(self->wavelength); +} + +/** + * @brief hdrl_spectrum1D getter flux + * @param self the spectrum + * @return hdrl image containing flux information (bpm, flux and error) + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_image* +hdrl_spectrum1D_get_flux(const hdrl_spectrum1D * self){ + + if(!self) return NULL; + + return self->flux; +} + +/** + * @brief hdrl_spectrum1D getter for wavelengths + * @param self the spectrum + * @return the wavelengths the spectrum is defined on. + * It returns also its scale and its bpm. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D_wavelength +hdrl_spectrum1D_get_wavelength(const hdrl_spectrum1D * self){ + + hdrl_spectrum1D_wavelength to_ret = {NULL, NULL, + hdrl_spectrum1D_wave_scale_linear}; + + cpl_ensure(self != NULL, + CPL_ERROR_NULL_INPUT, to_ret); + + const hdrl_image * flux = hdrl_spectrum1D_get_flux(self); + + const cpl_array * lambdas = self->wavelength; + + const cpl_mask * + mask = cpl_image_get_bpm_const(hdrl_image_get_image_const(flux)); + + to_ret.bpm = mask; + to_ret.wavelength = lambdas; + to_ret.scale = hdrl_spectrum1D_get_scale(self); + return to_ret; +} + +/** + * @brief hdrl_spectrum1D getter for scale + * @param self the spectrum + * @return the scale. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D_wave_scale +hdrl_spectrum1D_get_scale(const hdrl_spectrum1D * self){ + cpl_ensure(self != NULL, + CPL_ERROR_NULL_INPUT, hdrl_spectrum1D_wave_scale_linear); + + return self->wave_scale; +} + +/** + * @brief hdrl_spectrum1D getter for a flux value + * @param self the spectrum + * @param idx position of the sample. The samples are a 0-indexed sequence. + * @param rej output, set to 0 if the value is not a valid pixel. + * @return the i-th pixel value. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_value +hdrl_spectrum1D_get_flux_value(const hdrl_spectrum1D * self, int idx, int * rej){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, ((hdrl_value){0.0, 0.0})); + + const hdrl_image * flx = hdrl_spectrum1D_get_flux(self); + + return hdrl_image_get_pixel(flx, idx + 1, 1, rej); +} + +/** + * @brief hdrl_spectrum1D getter for a wavelength value + * @param self the spectrum + * @param idx position of the sample. The samples are a 0-indexed sequence. + * @param rej output, set to 0 if the value is not a valid pixel. + * @return the i-th wavelength value. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_data_t +hdrl_spectrum1D_get_wavelength_value(const hdrl_spectrum1D * self, int idx, int * rej){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); + + const hdrl_spectrum1D_wavelength lambdas = + hdrl_spectrum1D_get_wavelength(self); + + const cpl_array * wlengs = lambdas.wavelength; + const hdrl_data_t to_ret = (hdrl_data_t) cpl_array_get(wlengs, idx, NULL); + + if(rej){ + const cpl_mask * msk = lambdas.bpm; + if(msk) + *rej = cpl_mask_get(msk, idx + 1, 1); + else + *rej = CPL_BINARY_0; + } + + return to_ret; +} + +/** + * @brief divide one spectrum by another spectrum + * @param num numerator + * @param den denumerator + * @return a newly allocated spectrum whose flux values are num/den, + * with error propagation. + * + * Possible cpl-error-code set in this function: hdrl_image_div_image + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_div_spectrum_create(const hdrl_spectrum1D * num, + const hdrl_spectrum1D * den){ + return operate_spectra_flux_create(num, den, hdrl_image_div_image); +} + +/** + * @brief multiply one spectrum by another spectrum + * @param f1 factor 1 + * @param f2 factor 2 + * @return a newly allocated spectrum whose flux values are f1*f2, + * with error propagation. + * + * Possible cpl-error-code set in this function: hdrl_image_mul_image + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_mul_spectrum_create(const hdrl_spectrum1D * f1, + const hdrl_spectrum1D * f2){ + return operate_spectra_flux_create(f1, f2, hdrl_image_mul_image); +} + +/**void + * @brief sum one spectrum to another spectrum + * @param f1 factor 1 + * @param f2 factor 2 + * @return a newly allocated spectrum whose flux values are f1+f2, + * with error propagation. + * + * Possible cpl-error-code set in this function: hdrl_image_add_image + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_add_spectrum_create(const hdrl_spectrum1D * f1, + const hdrl_spectrum1D * f2){ + return operate_spectra_flux_create(f1, f2, hdrl_image_add_image); +} + + +/** + * @brief subtract two spectra + * @param f1 factor 1 + * @param f2 factor 2 + * @return a newly allocated spectrum whose flux values are f1-f2, + * with error propagation. + * + * Possible cpl-error-code set in this function: hdrl_image_sub_image + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_sub_spectrum_create(const hdrl_spectrum1D * f1, + const hdrl_spectrum1D * f2){ + return operate_spectra_flux_create(f1, f2, hdrl_image_sub_image); +} + + +/** + * @brief divide one spectrum by another spectrum + * @param self numerator, it is mutated to contain self/other + * @param other denumerator + * @return error code, for possible return codes see hdrl_image_div_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_div_spectrum(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other){ + return operate_spectra_flux_mutate(self, other, hdrl_image_div_image); +} + +/** + * @brief multiply one spectrum by another spectrum + * @param self first factor, it is mutated to contain self*other + * @param other second factor + * @return error code, for possible return codes see hdrl_image_mul_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_mul_spectrum(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other){ + return operate_spectra_flux_mutate(self, other, hdrl_image_mul_image); +} + +/** + * @brief sum two spectra + * @param self first factor, it is mutated to contain self+other + * @param other second factor + * @return error code, for possible return codes see hdrl_image_add_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_add_spectrum(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other){ + return operate_spectra_flux_mutate(self, other, hdrl_image_add_image); +} + + +/** + * @brief subtract two spectra + * @param self first factor, it is mutated to contain self-other + * @param other second factor + * @return error code, for possible return codes see hdrl_image_sub_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_sub_spectrum(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other){ + return operate_spectra_flux_mutate(self, other, hdrl_image_sub_image); +} + +/** + * @brief divide a spectrum by a scalar + * @param self spectrum + * @param scalar_operator scalar factor + * @return a newly created spectrum, whose flux is calculated dividing every + * sample of self by scalar_operator. Returns NULL in case of error. + * + * Possible cpl-error-code set in this function: hdrl_image_div_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_div_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_create(self, scalar_operator, hdrl_image_div_scalar); +} + +/** + * @brief multiply a spectrum by a scalar + * @param self spectrum + * @param scalar_operator scalar factor + * @return a newly created spectrum, whose flux is calculated multiplying every + * sample of self by scalar_operator. Returns NULL in case of error. + * + * Possible cpl-error-code set in this function: hdrl_image_mul_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_mul_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_create(self, scalar_operator, hdrl_image_mul_scalar); +} + +/** + * @brief add a scalar to a spectrum + * @param self spectrum + * @param scalar_operator scalar factor + * @return a newly created spectrum, whose flux is calculated adding every + * sample of self to scalar_operator. Returns NULL in case of error. + * + * Possible cpl-error-code set in this function: hdrl_image_add_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_add_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_create(self, scalar_operator, hdrl_image_add_scalar); +} + +/** + * @brief subtract a scalar from a spectrum + * @param self spectrum + * @param scalar_operator scalar factor + * @return a newly created spectrum, whose flux is calculated subtracting from + * every sample of self the value of scalar_operator. Returns NULL in case of error. + * + * Possible cpl-error-code set in this function: hdrl_image_sub_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_sub_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_create(self, scalar_operator, hdrl_image_sub_scalar); +} + +/** + * @brief subtract a scalar from a spectrum + * @param self spectrum + * @param scalar_operator scalar factor + * @return a newly created spectrum, whose flux is calculated elevating + * every sample to the value of scalar_operator. Returns NULL in case of error. + * + * Possible cpl-error-code set in this function: hdrl_image_pow_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_pow_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_create(self, scalar_operator, hdrl_image_pow_scalar); +} + +/** + * @brief subtract a scalar from a spectrum + * @param self spectrum + * @param scalar_operator scalar factor + * @return a newly created spectrum, whose flux is calculated elevating + * the value of scalar_operator to the samples. Returns NULL in case of error. + * + * Possible cpl-error-code set in this function: hdrl_image_exp_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_exp_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_create(self, scalar_operator, hdrl_image_exp_scalar); +} + +/** + * @brief computes the elementwise division of a spectrum by a scalar, + * the self parameter is modified + * @param self spectrum + * @param scalar_operator scalar factor + * @return error code, for possible return codes see hdrl_image_div_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_div_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_mutate(self, scalar_operator, hdrl_image_div_scalar); +} + + +/** + * @brief computes the elementwise multiplication of a spectrum by a scalar, + * the self parameter is modified + * @param self spectrum + * @param scalar_operator scalar factor + * @return error code, for possible return codes see hdrl_image_mul_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_mul_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_mutate(self, scalar_operator, hdrl_image_mul_scalar); +} + +/** + * @brief computes the elementwise addition of a spectrum by a scalar, + * the self parameter is modified + * @param self spectrum + * @param scalar_operator scalar factor + * @return error code, for possible return codes see hdrl_image_add_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_add_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_mutate(self, scalar_operator, hdrl_image_add_scalar); +} + +/** + * @brief computes the elementwise subtraction of a spectrum by a scalar, + * the self parameter is modified + * @param self spectrum + * @param scalar_operator scalar factor + * @return error code, for possible return codes see hdrl_image_sub_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_sub_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_mutate(self, scalar_operator, hdrl_image_sub_scalar); +} + +/** + * @brief computes the elementwise power of the flux to the scalar, + * the self parameter is modified + * @param self spectrum + * @param scalar_operator scalar factor + * @return error code, for possible return codes see hdrl_image_pow_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_pow_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_mutate(self, scalar_operator, hdrl_image_pow_scalar); +} + +/** + * @brief computes the elementwise power of the scalar to the flux, + * the self parameter is modified + * @param self spectrum + * @param scalar_operator scalar factor + * @return error code, for possible return codes see hdrl_image_exp_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_exp_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator){ + return + operate_spectra_scalar_flux_mutate(self, scalar_operator, hdrl_image_exp_scalar); +} + +/** + * @brief computes the elementwise multiplication of the scalar for the + * wavelength. The scalar is assumed to be expressed in linear units. + * the self parameter is modified + * @param self spectrum + * @param scale_linear scalar factor + * @return error code, for possible return codes see cpl_array_multiply_scalar + * and cpl_array_add_scalar. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_wavelength_mult_scalar_linear(hdrl_spectrum1D * self, + hdrl_data_t scale_linear) +{ + cpl_ensure_code(scale_linear > 0, CPL_ERROR_INCOMPATIBLE_INPUT); + + if(self == NULL) return CPL_ERROR_NONE; + + if(self->wave_scale == hdrl_spectrum1D_wave_scale_linear) + return cpl_array_multiply_scalar(self->wavelength, scale_linear); + + return cpl_array_add_scalar(self->wavelength, log(scale_linear)); +} + +/** + * @brief computes the elementwise multiplication of the scalar for the + * wavelength. The scalar is assumed to be expressed in linear units. Self is + * unchanged and the function returns a newly allocated spectrum. + * @param self spectrum + * @param scale_linear scalar factor + * @return the modified spectrum + * + * Possible cpl-error-code set in this function: see + * cpl_array_multiply_scalar and cpl_array_add_scalar. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_mult_scalar_linear_create(const hdrl_spectrum1D * self, + hdrl_data_t scale_linear) +{ + if(!self) return NULL; + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_duplicate(self); + + cpl_error_code fail = + hdrl_spectrum1D_wavelength_mult_scalar_linear(to_ret, scale_linear); + if(fail){ + hdrl_spectrum1D_delete(&to_ret); + } + return to_ret; +} + +/** + * @brief computes the elementwise shift of the wavelength by the shift parameter. + * The self parameter is modified + * @param self spectrum + * @param shift scalar factor + * @return error code, for error codes see cpl_array_add_scalar + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_wavelength_shift(hdrl_spectrum1D * self, + hdrl_data_t shift) +{ + if(!self) return CPL_ERROR_NONE; + + return cpl_array_add_scalar(self->wavelength, shift); +} + +/** + * @brief computes the elementwise shift of the wavelength by the shift parameter. + * @param self spectrum + * @param shift scalar factor + * @return spectrum + * + * The self parameter is not modified, and a modified copy of self is returned. + * Possible cpl-error-code set in this function: see cpl_array_add_scalar + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_shift_create(const hdrl_spectrum1D * self, + hdrl_data_t shift){ + + if(!self) return NULL; + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_duplicate(self); + + cpl_error_code fail = hdrl_spectrum1D_wavelength_shift(to_ret, shift); + + if(fail){ + hdrl_spectrum1D_delete(&to_ret); + } + + return to_ret; +} + +/** + * @brief converts the wavelength scale to linear. + * @param self spectrum + * @return error code, for error codes see cpl_array_exponential + * + * If the spectrum is already in linear scale nothing is done. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_wavelength_convert_to_linear(hdrl_spectrum1D * self){ + + if(self == NULL || self->wave_scale == hdrl_spectrum1D_wave_scale_linear) + return CPL_ERROR_NONE; + + cpl_error_code fail = cpl_array_exponential(self->wavelength, CPL_MATH_E); + self->wave_scale = hdrl_spectrum1D_wave_scale_linear; + return fail; +} + +/** + * @brief converts the wavelength scale to linear. + * @param self spectrum + * @return the modified spectrum + * + * It returns a modified version of self. self is not modified. + * If self is already in linear, the function is equivalent to a duplication. + * Possible cpl-error-code set in this function: see cpl_array_exponential + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_convert_to_linear_create(const hdrl_spectrum1D * self){ + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_duplicate(self); + cpl_error_code fail = hdrl_spectrum1D_wavelength_convert_to_linear(to_ret); + + if(fail){ + hdrl_spectrum1D_delete(&to_ret); + } + return to_ret; +} + +/** + * @brief converts the wavelength scale to log. If the spectrum is already + * in log scale nothing is done. + * @param self spectrum + * @return error code, for error codes see cpl_array_logarithm + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_wavelength_convert_to_log(hdrl_spectrum1D * self){ + + if(self == NULL || self->wave_scale == hdrl_spectrum1D_wave_scale_log) + return CPL_ERROR_NONE; + + cpl_error_code fail = cpl_array_logarithm(self->wavelength, CPL_MATH_E); + self->wave_scale = hdrl_spectrum1D_wave_scale_log; + return fail; +} + +/** + * @brief converts the wavelength scale to log. It returns a modified version + * of self. self is not modified. If self is already in log, the function is + * equivalent to a duplication. + * @param self spectrum + * @return the modified spectrum + * + * It returns a modified version of self. self is not modified. + * If self is already in log, the function is equivalent to a duplication. + * Possible cpl-error-code set in this function: see cpl_array_logarithm + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_convert_to_log_create(const hdrl_spectrum1D * self){ + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_duplicate(self); + cpl_error_code fail = hdrl_spectrum1D_wavelength_convert_to_log(to_ret); + + if(fail){ + hdrl_spectrum1D_delete(&to_ret); + } + return to_ret; +} + +/** + * @brief the function selects or discards flux values according to whether the + * value of the corresponding wavelength belongs to the interval + * [min_lambda, max_lambda]. + * @param self spectrum + * @param windows the intervals required for selection + * @param is_internal parallel array to windows, specifies if selection is + * internal to the interval or external to the interval. + * @return the selected subset of self or NULL in case of error + * + * @note: the complexity is O(kn) where k is the number of windows and n is the + * number of samples in the spectrum. The assumption is that k << n, making the + * complexity O(n). + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_ILLEGAL_OUTPUT: if no samples falls in the selected interval + * - CPL_ERROR_ILLEGAL_INPUT: if windows and is_internal have different lengths, + * or if is_internal is not of type CPL_TYPE_INT + * - CPL_ERROR_NULL_INPUT: if any of the pointers is NULL + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_select_wavelengths(const hdrl_spectrum1D * self, + const cpl_bivector * windows, const cpl_boolean is_internal){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(windows != NULL, CPL_ERROR_NULL_INPUT, NULL); + + const cpl_size sz = hdrl_spectrum1D_get_size(self); + cpl_size num_selected = 0; + + for(cpl_size i = 0; i < sz; ++i){ + const hdrl_data_t w = hdrl_spectrum1D_get_wavelength_value(self, i, NULL); + if(is_wlen_selected(windows, is_internal, w)) + num_selected++; + } + + if(num_selected == sz) + return hdrl_spectrum1D_duplicate(self); + + cpl_ensure(num_selected > 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + cpl_image * flux = cpl_image_new(num_selected, 1, HDRL_TYPE_DATA); + cpl_image * flux_e = cpl_image_new(num_selected, 1, HDRL_TYPE_ERROR); + cpl_array * wavs = cpl_array_new(num_selected, HDRL_TYPE_DATA); + + cpl_size idx_this = 0; + for(cpl_size i = 0; i < sz; ++i){ + + int rej = 0; + const hdrl_data_t w = hdrl_spectrum1D_get_wavelength_value(self, i, NULL); + if(!is_wlen_selected(windows, is_internal, w)) continue; + + hdrl_value v = hdrl_spectrum1D_get_flux_value(self, i, &rej); + + if(!rej){ + cpl_image_set(flux, idx_this + 1, 1, v.data); + cpl_image_set(flux_e, idx_this + 1, 1, v.error); + } + else{ + cpl_image_reject(flux, idx_this + 1, 1); + cpl_image_reject(flux_e, idx_this + 1, 1); + } + + cpl_array_set(wavs, idx_this, w); + + idx_this++; + } + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_get_scale(self); + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create(flux,flux_e, wavs, scale); + + cpl_image_delete(flux); + cpl_image_delete(flux_e); + cpl_array_delete(wavs); + + return to_ret; +} + +/** + * @brief For every i-th element in bad_samples having value CPL_TRUE, the i-th + * pixel in the 1D spectrum is marked as bad. + * @param self spectrum + * @param bad_samples flags indicating whether the pixel is bad + * @return the spectrum having the appropriate bad pixels selected. + * + * It returns a modified version of self. self is not modified. + * Possible cpl-error-code set in this function: + * - CPL_ERROR_ILLEGAL_INPUT: if min_lambda < max_lambda; + * - CPL_ERROR_ILLEGAL_OUTPUT: if the length of bad_samples and the length of + * self are different. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_reject_pixels(const hdrl_spectrum1D * self, + const cpl_array * bad_samples){ + + const cpl_size sz = cpl_array_get_size(bad_samples); + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(bad_samples != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(sz == hdrl_spectrum1D_get_size(self), CPL_ERROR_ILLEGAL_INPUT, NULL); + + hdrl_image * flux = hdrl_image_duplicate(hdrl_spectrum1D_get_flux(self)); + + for(cpl_size i = 0; i < sz; ++i){ + + if(cpl_array_get_int(bad_samples, i, NULL)) + hdrl_image_reject(flux, i + 1, 1); + } + + const cpl_image * flx_cpl = hdrl_image_get_image(flux); + const cpl_image * flx_e_cpl = hdrl_image_get_error(flux); + hdrl_spectrum1D_wavelength wlen = hdrl_spectrum1D_get_wavelength(self); + + hdrl_spectrum1D * to_ret = + hdrl_spectrum1D_create(flx_cpl, flx_e_cpl, + wlen.wavelength, wlen.scale); + + hdrl_image_delete(flux); + return to_ret; +} + +/** + * @brief converts a spectrum in a table. + * @param self spectrum + * @param flux_col_name name of the column containing the flux + * @param wavelength_col_name name of the column containing the wavelengths + * @param flux_e_col_name name of the column containing the flux error + * @param flux_bpm_col_name name of the column containing the flux bpm + * + * @return the newly allocated table. NULL if error occurs. + * + * If NULL is provided instead of a name, the corresponding column is not + * inserted in the table. At least one between wavelength_col_name and + * flux_col_name must be not NULL. + * + * Possible cpl-error-code set in this function: see cpl_table_wrap_double + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_table * hdrl_spectrum1D_convert_to_table( + const hdrl_spectrum1D * self, const char * flux_col_name, + const char* wavelength_col_name, const char * flux_e_col_name, + const char * flux_bpm_col_name){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(flux_col_name != NULL || wavelength_col_name != NULL, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_size sz = hdrl_spectrum1D_get_size(self); + + cpl_table * tb = cpl_table_new(sz); + cpl_ensure(tb != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_error_code fail = hdrl_spectrum1D_append_to_table + (self, tb, flux_col_name, wavelength_col_name, flux_e_col_name, + flux_bpm_col_name); + + if(fail){ + cpl_table_delete(tb); + tb = NULL; + } + return tb; +} + +/** + * @brief append a spectrum to a table. + * @param self spectrum + * @param dest table + * @param flux_col_name name of the column containing the flux + * @param wavelength_col_name name of the column containing the wavelengths + * @param flux_e_col_name name of the column containing the flux error + * @param flux_bpm_col_name name of the column containing the flux bpm + * + * @return cpl_error_code, for error codes see cpl_table_wrap_double + * + * If NULL is provided instead of a name, the corresponding column is not + * inserted in the table. At least one between wavelength_col_name and + * flux_col_name must be not NULL. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code hdrl_spectrum1D_append_to_table +(const hdrl_spectrum1D * self, cpl_table * dest, +const char * flux_col_name, const char* wavelength_col_name, +const char * flux_e_col_name, const char * flux_bpm_col_name){ + + cpl_ensure_code(self != NULL && dest != NULL,CPL_ERROR_NULL_INPUT); + cpl_ensure_code(flux_col_name != NULL || wavelength_col_name != NULL, + CPL_ERROR_NULL_INPUT); + + cpl_size cl_sz = cpl_table_get_nrow(dest); + cpl_size sz = hdrl_spectrum1D_get_size(self); + + cpl_ensure_code(sz == cl_sz, CPL_ERROR_INCOMPATIBLE_INPUT); + + if(wavelength_col_name){ + double * lambdas = cpl_calloc(sz ,sizeof(double)); + for(cpl_size i = 0; i < sz; i++){ + lambdas[i] = hdrl_spectrum1D_get_wavelength_value(self, i, NULL); + } + cpl_error_code fail = + cpl_table_wrap_double(dest, lambdas, wavelength_col_name); + + if(fail){ + cpl_free(lambdas); + return fail; + } + } + + if(flux_col_name){ + double * flux = cpl_calloc(sz ,sizeof(double)); + for(cpl_size i = 0; i < sz; i++){ + flux[i] = hdrl_spectrum1D_get_flux_value(self, i, NULL).data; + } + + cpl_error_code fail = cpl_table_wrap_double(dest, flux, flux_col_name); + if(fail){ + cpl_free(flux); + return fail; + } + } + + if(flux_e_col_name){ + double * e_flux = cpl_calloc(sz ,sizeof(double)); + for(cpl_size i = 0; i < sz; i++){ + e_flux[i] = hdrl_spectrum1D_get_flux_value(self, i, NULL).error; + } + cpl_error_code fail = + cpl_table_wrap_double(dest, e_flux, flux_e_col_name); + + if(fail){ + cpl_free(e_flux); + return fail; + } + } + + if(flux_bpm_col_name){ + int * bpm_flux = cpl_calloc(sz ,sizeof(int)); + for(cpl_size i = 0; i < sz; i++){ + hdrl_spectrum1D_get_flux_value(self, i, &bpm_flux[i]); + } + cpl_error_code fail = + cpl_table_wrap_int(dest, bpm_flux, flux_bpm_col_name); + if(fail){ + cpl_free(bpm_flux); + return fail; + } + } + + return CPL_ERROR_NONE; +} + +/** + * @brief convert a table to a spectrum + * @param self table + * @param flux_col_name name of the column containing the flux + * @param wavelength_col_name name of the column containing the wavelengths + * @param flux_e_col_name name of the column containing the flux error + * @param flux_bpm_col_name name of the column containing the flux bpm + * @param scale scale of the spectrum + * @return the newly allocated spectrum. NULL if error occurs. If NULL is provided + * instead of flux_e_col_name, the spectrum is assumed error free. + * + * Possible cpl-error-code set in this function: see error free spectrum ctor + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_convert_from_table +(const cpl_table * self, const char * flux_col_name, +const char* wavelength_col_name, const char * flux_e_col_name, +const char * flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(flux_col_name != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(wavelength_col_name != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_size sz = cpl_table_get_nrow(self); + + cpl_ensure(sz > 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + + cpl_image * flux = cpl_image_new(sz, 1, HDRL_TYPE_DATA); + cpl_image * flux_e = cpl_image_new(sz, 1, HDRL_TYPE_ERROR); + cpl_array * lambdas = cpl_array_new(sz, HDRL_TYPE_DATA); + + + for(cpl_size i = 0; i < sz; ++i){ + const double fx = cpl_table_get(self, flux_col_name, i, NULL); + const double l = cpl_table_get(self, wavelength_col_name, i, NULL); + + double fx_e = 0; + if(flux_e_col_name) + fx_e = cpl_table_get(self, flux_e_col_name, i, NULL); + + int rej = 0; + if(flux_bpm_col_name) + rej = cpl_table_get_int(self, flux_bpm_col_name, i, NULL); + + cpl_image_set(flux, i + 1, 1, fx); + + if(rej) + cpl_image_reject(flux, i + 1, 1); + + cpl_image_set(flux_e, i + 1, 1, fx_e); + cpl_array_set(lambdas, i, l); + } + + hdrl_spectrum1D * sp = hdrl_spectrum1D_create(flux, flux_e, lambdas, scale); + + cpl_image_delete(flux); + cpl_image_delete(flux_e); + cpl_array_delete(lambdas); + return sp; +} + +void hdrl_spectrum1D_save(const hdrl_spectrum1D * s, const char * fname){ + if(s == NULL) return; + cpl_table * tb = hdrl_spectrum1D_convert_to_table(s, "FLX", "WLN", "FLX_E", + "FLX_BPM"); + cpl_table_save(tb, NULL, NULL, fname, CPL_IO_CREATE); + cpl_table_delete(tb); +} + +/** + * @brief checks if two wavelengths array are defined on the same wavelengths. + * @param w1 first wavelength array + * @param w2 first wavelength array + * @return CPL_TRUE if compatible, CPL_FALSE otherwise. + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean +hdrl_spectrum1D_are_wavelengths_compatible(const cpl_array * w1, + const cpl_array * w2){ + if(w1 == NULL && w2 == NULL) return CPL_TRUE; + + if(w1 == NULL) return CPL_FALSE; + + if(w2 == NULL) return CPL_FALSE; + + cpl_size sz = cpl_array_get_size(w1); + if(sz != cpl_array_get_size(w2)) return CPL_FALSE; + for(cpl_size i = 0; i < sz; i++){ + const double wa = cpl_array_get(w1, i, NULL); + const double wb = cpl_array_get(w2, i, NULL); + + const double d = wa - wb; + if(fabs(d) > 1e-10 * CPL_MIN(wa, wb)){ + return CPL_FALSE; + } + } + + return CPL_TRUE; +} + +/** + * @brief checks if two spectrum wavelengths are equal. + * @param s1 first spectrum wavelength + * @param s2 second spectrum wavelength + * @return CPL_TRUE if compatible, CPL_FALSE otherwise. + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean +hdrl_spectrum1D_are_spectra_compatible(const hdrl_spectrum1D_wavelength* s1, + const hdrl_spectrum1D_wavelength* s2){ + + if(s1 == NULL && s2 == NULL) return CPL_TRUE; + + if(s1 == NULL) return CPL_FALSE; + + if(s2 == NULL) return CPL_FALSE; + + if(s1->scale != s2->scale) return CPL_FALSE; + + return hdrl_spectrum1D_are_wavelengths_compatible(s1->wavelength, + s2->wavelength); +} + +/** + * @brief checks if the spectrum is defined on uniformly sampled wavelengths. + * @param self the input spectrum + * @param bin bin width - output parameter + * + * @return CPL_TRUE if if the spectrum is defined on uniformly sampled wavelengths, + * false otherwise. + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_spectrum1D_is_uniformly_sampled(const hdrl_spectrum1D * self, + double * bin){ + + *bin = 0.0; + + if(self == NULL) return CPL_FALSE; + + const cpl_size sz = hdrl_spectrum1D_get_size(self); + + if(sz <= 2) return CPL_TRUE; + + double * vd = cpl_calloc(sz, sizeof(double)); + + for(cpl_size i = 0; i < sz; ++i){ + vd[i] = hdrl_spectrum1D_get_wavelength_value(self, i, NULL); + } + + qsort(vd, sz, sizeof(double), compare_double); + + cpl_boolean to_ret = is_uniformly_sampled(vd, sz, bin); + + cpl_free(vd); + + return to_ret; + +} + +/*----------------------------------------------------------------------------- + Private Functions Implementation + -----------------------------------------------------------------------------*/ +/** + * @brief execute the passed function on self and other. Used to centralize the + * compatibility checks. Mutate self. + * @param self first spectrum, the one mutated + * @param other second spectrum, will not be mutated + * @param func function that implements the operation between + * self and other + * @return error code + */ +/* ---------------------------------------------------------------------------*/ +static inline cpl_error_code operate_spectra_flux_mutate(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other, + operate_image_mutable func){ + cpl_ensure_code(self != NULL && other != NULL, + CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D_wavelength w_self = hdrl_spectrum1D_get_wavelength(self); + hdrl_spectrum1D_wavelength w_other = hdrl_spectrum1D_get_wavelength(other); + cpl_ensure_code(hdrl_spectrum1D_are_spectra_compatible(&w_self, &w_other), + CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_image * f1 = self->flux; + const hdrl_image * f2 = other->flux; + + cpl_ensure_code(f1 != NULL && f2 != NULL, + CPL_ERROR_NULL_INPUT); + + func(f1, f2); + + return CPL_ERROR_NONE; +} + +/** + * @brief execute the passed function on self and other. Return the newly + * calculated spectrum. + * @param self first spectrum, will not be mutated + * @param other second spectrum, will not be mutated + * @param func function that implements the operation between + * self and other + * @return the new spectrum. NULL in case of error. + */ +/* ---------------------------------------------------------------------------*/ +static inline hdrl_spectrum1D * +operate_spectra_flux_create(const hdrl_spectrum1D * self, + const hdrl_spectrum1D * other, + operate_image_mutable func){ + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_duplicate(self); + + cpl_error_code fail = operate_spectra_flux_mutate(to_ret, other, func); + + if(fail){ + hdrl_spectrum1D_delete(&to_ret); + } + return to_ret; +} + +/** + * @brief execute the passed function on self and scalar. Used to centralize the + * compatibility checks. Mutate self. + * @param self spectrum, will be mutated + * @param scalar scalar value + * @param func function that implements the operation between + * self and scalar + * @return error code + */ +/* ---------------------------------------------------------------------------*/ +static inline cpl_error_code +operate_spectra_scalar_flux_mutate(hdrl_spectrum1D * self, + hdrl_value scalar, + operate_image_scalar_mutable func){ + + if(!self) return CPL_ERROR_NONE; + + hdrl_image * f1 = self->flux; + + cpl_ensure_code(f1 != NULL, CPL_ERROR_NULL_INPUT); + + func(f1, scalar); + + return CPL_ERROR_NONE; +} + +/** + * @brief execute the passed function on self and scalar. Return the newly + * calculated spectrum. + * @param self first spectrum, will not be mutated + * @param scalar scalar value + * @param func function that implements the operation between + * self and scalar + * @return the new spectrum. NULL in case of error. + */ +/* ---------------------------------------------------------------------------*/ +static inline hdrl_spectrum1D * +operate_spectra_scalar_flux_create(const hdrl_spectrum1D * self, + hdrl_value scalar, + operate_image_scalar_mutable func){ + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_duplicate(self); + + cpl_error_code fail = + operate_spectra_scalar_flux_mutate(to_ret, scalar, func); + + if(fail){ + hdrl_spectrum1D_delete(&to_ret); + } + + return to_ret; +} + +static inline +hdrl_spectrum1D * hdrl_spectrum1D_wrap(hdrl_image * arg_flux, + cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale){ + + hdrl_spectrum1D * to_ret = cpl_calloc(1, sizeof(*to_ret)); + + to_ret->flux = arg_flux; + to_ret->wavelength = wavelength; + to_ret->wave_scale = scale; + return to_ret; +} + +static inline +int compare_double(const void * a, const void * b){ + const double ad = *((const double *)a); + const double bd = *((const double *)b); + const double delta = ad - bd; + if(delta > 0.0) return 1; + if(delta < 0.0) return -1; + return 0; +} + +static inline +cpl_boolean is_uniformly_sampled(const double * v, cpl_size sz, double * bin){ + + const double d = v[1] - v[0]; + *bin = d; + for(cpl_size i = 1; i < sz - 1; ++i){ + const double d2 = (v[i + 1] - v[i]); + const double eps = (fabs(d2 - d) / d); + if(eps > 1e-6){ + return CPL_FALSE; + } + } + + return CPL_TRUE; +} + + +static inline cpl_boolean +is_contained_in_at_least_one_window(const cpl_bivector * windows, const hdrl_data_t w){ + const cpl_size sz = cpl_bivector_get_size(windows); + + for(cpl_size i = 0; i < sz; ++i){ + const double wmin = cpl_vector_get(cpl_bivector_get_x_const(windows), i); + const double wmax = cpl_vector_get(cpl_bivector_get_y_const(windows), i); + + if(w >= wmin && w <= wmax) return CPL_TRUE; + } + + return CPL_FALSE; +} + +static inline cpl_boolean +is_wlen_selected(const cpl_bivector * windows, const cpl_boolean is_internal, + const hdrl_data_t w){ + + if(is_internal) return is_contained_in_at_least_one_window(windows, w); + + return !is_contained_in_at_least_one_window(windows, w); + +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_defs.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_defs.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_defs.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_defs.h 2017-04-28 08:24:15.000000000 +0000 @@ -0,0 +1,52 @@ +/* $Id: hdrl_image_defs.h,v 1.0 2017-03-27 15:26:45 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-03-27 15:26:45 $ + * $Revision: 1.0 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_SPECTRUM_DEFS_H +#define HDRL_SPECTRUM_DEFS_H + +#include "hdrl_types.h" +#include "hdrl_image.h" +#include + +CPL_BEGIN_DECLS + + +typedef enum{ + hdrl_spectrum1D_wave_scale_linear, + hdrl_spectrum1D_wave_scale_log +}hdrl_spectrum1D_wave_scale; + + +typedef struct{ + hdrl_image * flux; + cpl_array * wavelength; + hdrl_spectrum1D_wave_scale wave_scale; +}hdrl_spectrum1D; + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum.h 2018-01-10 10:09:38.000000000 +0000 @@ -0,0 +1,264 @@ +/* $Id: hdrl_spectrum.h,v 0.1 2017-02-28 16:20:00 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-02-28 16:20:00 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_SPECTRUM_H +#define HDRL_SPECTRUM_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_image.h" +#include "hdrl_correlation.h" +#include "hdrl_spectrum_defs.h" + +#include + +CPL_BEGIN_DECLS + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE + +cpl_boolean +hdrl_spectrum1D_is_uniformly_sampled(const hdrl_spectrum1D * self, double * bin); + +void hdrl_spectrum1D_save(const hdrl_spectrum1D * s, const char * fname); + +#endif + +/*----------------------------------------------------------------------------- + Functions - Constructors + -----------------------------------------------------------------------------*/ +hdrl_spectrum1D * hdrl_spectrum1D_create(const cpl_image * arg_flux, + const cpl_image * arg_flux_e, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale wave_scale); + +hdrl_spectrum1D * hdrl_spectrum1D_create_error_free + (const cpl_image * arg_flux, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale); + +hdrl_spectrum1D * hdrl_spectrum1D_create_error_DER_SNR + (const cpl_image * arg_flux, + cpl_size half_window, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale); + +typedef hdrl_value (* calculate_analytic_spectrum_point) (hdrl_data_t lambda); + +hdrl_spectrum1D * hdrl_spectrum1D_create_analytic( + calculate_analytic_spectrum_point func, + const cpl_array * wavelength, + hdrl_spectrum1D_wave_scale scale); + +hdrl_spectrum1D * hdrl_spectrum1D_duplicate(const hdrl_spectrum1D* self); + +void hdrl_spectrum1D_delete(hdrl_spectrum1D ** p_self); + + +/*----------------------------------------------------------------------------- + Functions - Getter operations + -----------------------------------------------------------------------------*/ + +cpl_size hdrl_spectrum1D_get_size(const hdrl_spectrum1D * self); + +const hdrl_image* +hdrl_spectrum1D_get_flux(const hdrl_spectrum1D * self); + + +typedef struct{ + const cpl_array * wavelength; + const cpl_mask * bpm; + hdrl_spectrum1D_wave_scale scale; +}hdrl_spectrum1D_wavelength; + +hdrl_spectrum1D_wavelength +hdrl_spectrum1D_get_wavelength(const hdrl_spectrum1D * self); + +hdrl_spectrum1D_wave_scale +hdrl_spectrum1D_get_scale(const hdrl_spectrum1D * self); + + +hdrl_value +hdrl_spectrum1D_get_flux_value(const hdrl_spectrum1D * self, int idx, int* rej); + +hdrl_data_t +hdrl_spectrum1D_get_wavelength_value(const hdrl_spectrum1D * self, int idx, int* rej); + + +/*----------------------------------------------------------------------------- + Functions - Vectorial flux operations + -----------------------------------------------------------------------------*/ + +cpl_boolean +hdrl_spectrum1D_are_spectra_compatible(const hdrl_spectrum1D_wavelength* s1, + const hdrl_spectrum1D_wavelength* s2); +cpl_boolean +hdrl_spectrum1D_are_wavelengths_compatible(const cpl_array* w1, + const cpl_array* w2); +hdrl_spectrum1D * +hdrl_spectrum1D_div_spectrum_create(const hdrl_spectrum1D * num, + const hdrl_spectrum1D * den); + +hdrl_spectrum1D * +hdrl_spectrum1D_mul_spectrum_create(const hdrl_spectrum1D * f1, + const hdrl_spectrum1D * f2); + +hdrl_spectrum1D * +hdrl_spectrum1D_add_spectrum_create(const hdrl_spectrum1D * f1, + const hdrl_spectrum1D * f2); + +hdrl_spectrum1D * +hdrl_spectrum1D_sub_spectrum_create(const hdrl_spectrum1D * f1, + const hdrl_spectrum1D * f2); + + +cpl_error_code hdrl_spectrum1D_div_spectrum( hdrl_spectrum1D * self, + const hdrl_spectrum1D * other); + +cpl_error_code hdrl_spectrum1D_mul_spectrum( hdrl_spectrum1D * self, + const hdrl_spectrum1D * other); + +cpl_error_code hdrl_spectrum1D_add_spectrum( hdrl_spectrum1D * self, + const hdrl_spectrum1D * other); + +cpl_error_code hdrl_spectrum1D_sub_spectrum( hdrl_spectrum1D * self, + const hdrl_spectrum1D * other); + +/*----------------------------------------------------------------------------- + Functions - Scalar flux operations + -----------------------------------------------------------------------------*/ + +hdrl_spectrum1D * +hdrl_spectrum1D_div_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +hdrl_spectrum1D * +hdrl_spectrum1D_mul_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +hdrl_spectrum1D * +hdrl_spectrum1D_add_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +hdrl_spectrum1D * +hdrl_spectrum1D_sub_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +hdrl_spectrum1D * +hdrl_spectrum1D_pow_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +hdrl_spectrum1D * +hdrl_spectrum1D_exp_scalar_create(const hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +cpl_error_code hdrl_spectrum1D_div_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +cpl_error_code hdrl_spectrum1D_mul_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +cpl_error_code hdrl_spectrum1D_add_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +cpl_error_code hdrl_spectrum1D_sub_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +cpl_error_code hdrl_spectrum1D_pow_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +cpl_error_code hdrl_spectrum1D_exp_scalar(hdrl_spectrum1D * self, + hdrl_value scalar_operator); + +/*----------------------------------------------------------------------------- + Functions - Wavelength operations + -----------------------------------------------------------------------------*/ + +cpl_error_code hdrl_spectrum1D_wavelength_mult_scalar_linear(hdrl_spectrum1D * self, + hdrl_data_t scale_linear); + +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_mult_scalar_linear_create(const hdrl_spectrum1D * self, + hdrl_data_t scale_linear); + + +cpl_error_code hdrl_spectrum1D_wavelength_shift(hdrl_spectrum1D * self, + hdrl_data_t shift); + +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_shift_create(const hdrl_spectrum1D * self, + hdrl_data_t shift); + + +cpl_error_code hdrl_spectrum1D_wavelength_convert_to_linear(hdrl_spectrum1D * self); + +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_convert_to_linear_create(const hdrl_spectrum1D * self); + +cpl_error_code hdrl_spectrum1D_wavelength_convert_to_log(hdrl_spectrum1D * self); + + +hdrl_spectrum1D * +hdrl_spectrum1D_wavelength_convert_to_log_create(const hdrl_spectrum1D * self); + +/*----------------------------------------------------------------------------- + Functions - Selectors + -----------------------------------------------------------------------------*/ + +hdrl_spectrum1D * +hdrl_spectrum1D_select_wavelengths(const hdrl_spectrum1D * self, + const cpl_bivector * windows, const cpl_boolean is_internal); + +hdrl_spectrum1D * +hdrl_spectrum1D_reject_pixels(const hdrl_spectrum1D * self, + const cpl_array * bad_samples); + + +/*----------------------------------------------------------------------------- + Functions - Table conversions + -----------------------------------------------------------------------------*/ + +cpl_table * hdrl_spectrum1D_convert_to_table +(const hdrl_spectrum1D * self, const char * flux_col_name, +const char* wavelength_col_name, const char * flux_e_col_name, +const char * flux_bpm_col_name); + +hdrl_spectrum1D * hdrl_spectrum1D_convert_from_table +(const cpl_table * self, const char * flux_col_name, +const char* wavelength_col_name, const char * flux_e_col_name, +const char * flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale); + +cpl_error_code hdrl_spectrum1D_append_to_table +(const hdrl_spectrum1D * self, cpl_table * dest, +const char * flux_col_name, const char* wavelength_col_name, +const char * flux_e_col_name, const char * flux_bpm_col_name); + + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrumlist.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrumlist.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrumlist.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrumlist.c 2017-08-25 12:02:49.000000000 +0000 @@ -0,0 +1,680 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_spectrumlist.h" +#include "hdrl_spectrum_resample.h" +#include "hdrl_imagelist.h" + +#include + +/** + * + * @addtogroup hdrl_spectrum1D + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ +static inline +cpl_error_code check_getter(const hdrl_spectrum1Dlist * s, const cpl_size idx); + +static inline +void push_back(hdrl_spectrum1Dlist *self, hdrl_spectrum1D * s); + +static inline hdrl_spectrum1D ** +safe_realloc(hdrl_spectrum1D ** current, const cpl_size old_capacity, + const cpl_size new_capacity); + +static inline hdrl_imagelist * +create_list(hdrl_spectrum1D ** resampled_spectra, + const hdrl_spectrum1Dlist * ori_spectra, + const cpl_boolean mark_bpm_in_interpolation); + +static inline void +delete_spectrum1D_array(hdrl_spectrum1D ** resampled_spectra, + const cpl_size num_spectra); + +static inline hdrl_image * +get_padded_flux(const hdrl_spectrum1D * resampled_spectrum, + const hdrl_spectrum1D * ori_spectrum, + const cpl_boolean mark_bpm_in_interpolation); + +static inline cpl_boolean +are_spectra_valid(const hdrl_spectrum1Dlist * list); + +static inline cpl_error_code +get_first_error_code(const cpl_error_code * cds, const cpl_size length); + +static inline cpl_boolean +check_scales_are_same(const hdrl_spectrum1Dlist * list); + +static inline double +get_wmin_valid(const hdrl_spectrum1D * s); + +static inline double +get_wmax_valid(const hdrl_spectrum1D * s); + +static inline void +remove_if_neighbors_are_rejected(hdrl_image * flx, + const hdrl_spectrum1D * ori_spectrum, const cpl_array * wlens); + +static inline hdrl_spectrum1D * +get_interp_bpm(const hdrl_spectrum1D * s, const cpl_array * wlens); + +static inline cpl_boolean +contains(const hdrl_spectrum1Dlist * list, const hdrl_spectrum1D * s); +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1Dlist default constructor + * @return a newly allocated hdrl_spectrum1Dlist + * + * The constructor allocates memory of a hdrl_spectrum1Dlist structure. The struct + * has zero capacity when allocated. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_new(void){ + hdrl_spectrum1Dlist * to_ret = cpl_calloc(1, sizeof(*to_ret)); + + to_ret->length = 0; + to_ret->capacity= 0; + to_ret->spectra = NULL; + return to_ret; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief hdrl_spectrum1Dlist copy-constructor + * @param l input list + * @return a copy of the input list + * + * The constructor allocates memory of a new hdrl_spectrum1Dlist structure. Each + * element of the new list is a copy of the corresponding element in the source + * list. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_duplicate(const hdrl_spectrum1Dlist * l){ + + if(l == NULL) return NULL; + + hdrl_spectrum1Dlist * to_ret = hdrl_spectrum1Dlist_new(); + + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(l); ++i){ + const hdrl_spectrum1D * s_old = hdrl_spectrum1Dlist_get_const(l, i); + hdrl_spectrum1D * s = hdrl_spectrum1D_duplicate(s_old); + hdrl_spectrum1Dlist_set(to_ret, s, i); + } + return to_ret; +} + +/** + * @brief hdrl_spectrum1Dlist wrapper + * @param self array of pointers to hdrl_spectrum1D + * @param sz number of elements in self + * @return self wrapped in a hdrl_spectrum1Dlist. The returned structure takes + * ownership of the self pointer. + * + * The constructor allocates memory of a new hdrl_spectrum1Dlist structure. The + * structure takes ownership of self, and therefore it is responsible for its + * de-allocation. Self must not contain duplicate or NULL pointers. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1Dlist * +hdrl_spectrum1Dlist_wrap(hdrl_spectrum1D ** self, const cpl_size sz){ + hdrl_spectrum1Dlist * to_ret = hdrl_spectrum1Dlist_new(); + to_ret->spectra = self; + to_ret->capacity = to_ret->length = sz; + return to_ret; +} + +/** + * @brief hdrl_spectrum1Dlist getter of the i-th element + * @param self hdrl_spectrum1Dlist + * @param idx index of the element we want. 0 <= index < size + * @return a pointer to the i-th element. NULL in case of error. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if self is NULL + * - CPL_ERROR_ACCESS_OUT_OF_RANGE: index is less than 0 or index >= size + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1Dlist_get(hdrl_spectrum1Dlist * self, const cpl_size idx){ + + cpl_error_code fail = check_getter(self, idx); + cpl_ensure(fail == CPL_ERROR_NONE, fail, NULL); + + return self->spectra[idx]; + +} + +/** + * @brief hdrl_spectrum1Dlist getter of the i-th element + * @param self hdrl_spectrum1Dlist + * @param idx index of the element we want. 0 <= index < size + * @return a const pointer to the i-th element. NULL in case of error. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if self is NULL + * - CPL_ERROR_ACCESS_OUT_OF_RANGE: index is less than 0 or index >= size + */ +/* ---------------------------------------------------------------------------*/ +const hdrl_spectrum1D * +hdrl_spectrum1Dlist_get_const(const hdrl_spectrum1Dlist *self , const cpl_size idx){ + + cpl_error_code fail = check_getter(self, idx); + cpl_ensure(fail == CPL_ERROR_NONE, fail, NULL); + + return self->spectra[idx]; +} + +/** + * @brief hdrl_spectrum1Dlist setter of the i-th element + * @param self hdrl_spectrum1Dlist + * @param s hdrl_spectrum1D we want to insert + * @param idx position the spectrum is inserted in. 0 <= index <= size + * @return a cpl_error_code. + * + * The function insert s inside self. if index == size, the capacity of the list + * is increased to accommodate the new element. If a spectrum was already contained + * in the i-th position, it is de-allocated. The list becomes responsible for the + * memory management of s. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if self is NULL + * - CPL_ERROR_ACCESS_OUT_OF_RANGE: index < 0 or index > size + * - CPL_ERROR_ILLEGAL_INPUT: if s is already contained inside self + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_spectrum1Dlist_set(hdrl_spectrum1Dlist * self, + hdrl_spectrum1D * s, const cpl_size idx){ + + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self->length >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(idx <= self->length, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(!contains(self, s), CPL_ERROR_ILLEGAL_INPUT); + + if(idx == self->length){ + push_back(self, s); + return CPL_ERROR_NONE; + } + + hdrl_spectrum1D * old = self->spectra[idx]; + hdrl_spectrum1D_delete(&old); + + self->spectra[idx] = s; + + return CPL_ERROR_NONE; +} + +/** + * @brief hdrl_spectrum1Dlist remove of the i-th element + * @param self hdrl_spectrum1Dlist + * @param idx position of element we want to remove from the list. + * 0 <= index < size + * @return the removed element. NULL in case of error of if the idx-th element was NULL + * + * The function extract the idx-th element from the list. It shifts all the elements + * from idx + 1 to size - 1 down of one position. If the new size is less than half + * the capacity, the capacity is reduced. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if self is NULL + * - CPL_ERROR_ACCESS_OUT_OF_RANGE: index < 0 or index >= size + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1Dlist_unset(hdrl_spectrum1Dlist * self, const cpl_size idx){ + + cpl_error_code fail = check_getter(self, idx); + cpl_ensure(fail == CPL_ERROR_NONE, fail, NULL); + + hdrl_spectrum1D * to_ret = self->spectra[idx]; + + const cpl_size sz = hdrl_spectrum1Dlist_get_size(self); + + for(cpl_size i = idx; i < sz - 1; ++i){ + self->spectra[i] = self->spectra[i + 1]; + } + self->length--; + + const cpl_size new_capacity = self->capacity / 2; + + if(hdrl_spectrum1Dlist_get_size(self) <= new_capacity){ + self->spectra = safe_realloc(self->spectra, self->capacity, new_capacity); + self->capacity = new_capacity; + } + + return to_ret; +} + +/** + * @brief hdrl_spectrum1Dlist destructor + * @param l hdrl_spectrum1Dlist + * + * The function deallocates the list and all the spectra it was containing. If l + * is NULL no operation is performed. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_spectrum1Dlist_delete(hdrl_spectrum1Dlist * l){ + + if(l == NULL) return; + + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(l); ++i){ + hdrl_spectrum1D_delete(&l->spectra[i]); + } + cpl_free(l->spectra); + cpl_free(l); +} + +/** + * @brief hdrl_spectrum1Dlist getter for size + * @param l hdrl_spectrum1Dlist + * + * @return the size of the list. The size can be less or equal than the capacity + * of the list. The size refers to the number of valid elements in the list. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if l is NULL + */ +/* ---------------------------------------------------------------------------*/ +cpl_size +hdrl_spectrum1Dlist_get_size(const hdrl_spectrum1Dlist * l){ + + cpl_ensure(l != NULL, CPL_ERROR_NULL_INPUT, 0); + + return l->length; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief collapsing a hdrl_spectrum1Dlist. The spectra in list are first + * resampled on the wavelengths wlengths. The resampling method is regulated + * by the resample_par. For more information on samplig_par see + * hdrl_spectrum1D_resample_on_array. + * The resampled fluxes are collapsed as in hdrl_imagelist_collapse and the + * collapsing is regulated by the parameter stacking_par. + * For more information on stacking_par please see the documentation of + * hdrl_imagelist_collapse. + * + * @param list hdrl_spectrum1D list + * @param stacking_par parameter regulating the stacking + * @param wlengths wavelengths the resulting spectrum is + * defined on + * @param resample_par parameter regulating the resampling + * @param mark_bpm_in_interpolation if true interpolated pixels whose + * neighbors (in the original spectrum) + * are rejected, are not considered + * during collapsing + * @param result the resulting spectrum + * @param contrib output contribution mask + * @param resampled_and_aligned_fluxes resampled and aligned fluxes to be + * collapsed + * @return cpl_error_code + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any among input pointers in NULL of if any of the + * spectra inside the list are NULL. + * - CPL_ERROR_ILLEGAL_INPUT: if all the elements inside list are not defined on + * the same scale. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_spectrum1Dlist_collapse (const hdrl_spectrum1Dlist *list, + const hdrl_parameter * stacking_par, + const cpl_array * wlengths, const hdrl_parameter * resample_par, + const cpl_boolean mark_bpm_in_interpolation, + hdrl_spectrum1D ** result, cpl_image ** contrib, + hdrl_imagelist ** resampled_and_aligned_fluxes){ + + cpl_ensure_code(are_spectra_valid(list), CPL_ERROR_NULL_INPUT); + cpl_ensure_code(wlengths != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(check_scales_are_same(list), CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(result != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(resampled_and_aligned_fluxes != NULL, CPL_ERROR_NULL_INPUT); + *result = NULL; + *contrib = NULL; + + const cpl_size num_spectra = hdrl_spectrum1Dlist_get_size(list); + hdrl_spectrum1D ** resampled_spectra = + cpl_calloc(num_spectra, sizeof(hdrl_spectrum1D*)); + + cpl_ensure_code(num_spectra > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_error_code * errors = cpl_calloc(num_spectra, sizeof(cpl_error_code)); + + HDRL_OMP(omp parallel for) + for(cpl_size i = 0; i < num_spectra; ++i){ + const hdrl_spectrum1D * this_s = hdrl_spectrum1Dlist_get_const(list, i); + resampled_spectra[i] = + hdrl_spectrum1D_resample_on_array(this_s, wlengths, resample_par); + errors[i] = cpl_error_get_code(); + } + + + cpl_error_code err = get_first_error_code(errors, num_spectra); + cpl_free(errors); + + if(!err){ + hdrl_imagelist * stack_list = + create_list(resampled_spectra, list, mark_bpm_in_interpolation); + + hdrl_image * stacked_img = NULL; + + err = hdrl_imagelist_collapse(stack_list, stacking_par, + &stacked_img, contrib); + + *resampled_and_aligned_fluxes = stack_list; + + if(!err){ + const hdrl_spectrum1D_wave_scale scale = + hdrl_spectrum1D_get_scale(hdrl_spectrum1Dlist_get_const(list, 0)); + + *result = hdrl_spectrum1D_create(hdrl_image_get_image(stacked_img), + hdrl_image_get_error(stacked_img), + wlengths, + scale); + } + + hdrl_image_delete(stacked_img); + } + + delete_spectrum1D_array(resampled_spectra, num_spectra); + return err; +} + +/*----------------------------------------------------------------------------- + Private Functions Implementation + -----------------------------------------------------------------------------*/ +/*Gets the minimum wavelengths ignoring bad pixels*/ +static inline double +get_wmin_valid(const hdrl_spectrum1D * s){ + const cpl_size sz = hdrl_spectrum1D_get_size(s); + + double wmin = INFINITY; + + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + double w = hdrl_spectrum1D_get_wavelength_value(s, i, &rej); + if(rej) continue; + if(w < wmin) wmin = w; + } + return wmin; +} +/*Gets the maximum wavelengths ignoring bad pixels*/ +static inline double +get_wmax_valid(const hdrl_spectrum1D * s){ + const cpl_size sz = hdrl_spectrum1D_get_size(s); + + double wmax = -INFINITY; + + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + double w = hdrl_spectrum1D_get_wavelength_value(s, i, &rej); + if(rej) continue; + if(w > wmax) wmax = w; + } + return wmax; +} + +static inline cpl_image * +get_img_from_bpm(hdrl_spectrum1D_wavelength * w){ + if(w->bpm) + return cpl_image_new_from_mask(w->bpm); + + const cpl_size sz = cpl_array_get_size(w->wavelength); + return cpl_image_new(sz, 1, CPL_TYPE_INT); +} + +static inline hdrl_spectrum1D * +get_interp_bpm(const hdrl_spectrum1D * s, const cpl_array * wlens){ + + hdrl_spectrum1D_wavelength wlen_ori = hdrl_spectrum1D_get_wavelength(s); + cpl_image * flx = get_img_from_bpm(&wlen_ori); + hdrl_spectrum1D * bpm = hdrl_spectrum1D_create_error_free(flx, + wlen_ori.wavelength, wlen_ori.scale); + cpl_image_delete(flx); + + hdrl_parameter * par = + hdrl_spectrum1D_resample_interpolate_parameter_create( + hdrl_spectrum1D_interp_linear); + hdrl_spectrum1D * interp_bpm = hdrl_spectrum1D_resample_on_array(bpm, wlens, + par); + hdrl_spectrum1D_delete(&bpm); + hdrl_parameter_delete(par); + return interp_bpm; +} + +static inline void +remove_if_neighbors_are_rejected(hdrl_image * flx, + const hdrl_spectrum1D * ori_spectrum, const cpl_array * wlens){ + /*We interpolate the bpm to see if the elements in wlens have a bad pixel + * close by. If that is the case we reject them.*/ + hdrl_spectrum1D * interp_bpm = get_interp_bpm(ori_spectrum, wlens); + + for(cpl_size i = 0; i < hdrl_spectrum1D_get_size(interp_bpm); ++i){ + const double v = hdrl_spectrum1D_get_flux_value(interp_bpm, i, NULL).data; + if(v > HDRL_EPS_DATA){ + hdrl_image_reject(flx, i + 1, 1); + } + } + hdrl_spectrum1D_delete(&interp_bpm); +} + +static inline hdrl_image * +get_padded_flux(const hdrl_spectrum1D * resampled_spectrum, + const hdrl_spectrum1D * ori_spectrum, + const cpl_boolean mark_bpm_in_interpolation){ + + if(resampled_spectrum == NULL) return NULL; + + const double wmin = get_wmin_valid(ori_spectrum); + + const double wmax = get_wmax_valid(ori_spectrum); + + if(isinf(wmin) || isinf(wmax)) return NULL; + + hdrl_image * flx = + hdrl_image_duplicate(hdrl_spectrum1D_get_flux(resampled_spectrum)); + + const cpl_array * wlens = + hdrl_spectrum1D_get_wavelength(resampled_spectrum).wavelength; + + for(cpl_size i = 0; i < hdrl_spectrum1D_get_size(resampled_spectrum); ++i){ + const double wlen = cpl_array_get(wlens, i, NULL); + if(wlen < wmin || wlen > wmax) { + hdrl_image_reject(flx, i + 1, 1); + } + } + + if(mark_bpm_in_interpolation) + remove_if_neighbors_are_rejected(flx, ori_spectrum, wlens); + + return flx; +} + +static inline cpl_boolean +check_scales_are_same(const hdrl_spectrum1Dlist * list){ + if(list == NULL) return CPL_TRUE; + const cpl_size sz = hdrl_spectrum1Dlist_get_size(list); + + if(sz <= 1) return CPL_TRUE; + + const hdrl_spectrum1D_wave_scale scale = + hdrl_spectrum1D_get_scale(hdrl_spectrum1Dlist_get_const(list, 0)); + + for(cpl_size i = 1; i < sz; ++i){ + const hdrl_spectrum1D_wave_scale scale_this = + hdrl_spectrum1D_get_scale(hdrl_spectrum1Dlist_get_const(list, 0)); + + if(scale_this != scale) return CPL_FALSE; + } + + return CPL_TRUE; +} +/*Given a array of hdrl_spectrum1D this function creates an hdrl_imagelist containing + * the fluxes of the spectra. The current implementation of resample extrapolates + * points outside the interval where values are available. We reject those points.*/ +static inline hdrl_imagelist * +create_list(hdrl_spectrum1D ** resampled_spectra, + const hdrl_spectrum1Dlist * ori_spectra, + const cpl_boolean mark_bpm_in_interpolation){ + + const cpl_size num_spectra = hdrl_spectrum1Dlist_get_size(ori_spectra); + hdrl_image ** images = cpl_calloc(num_spectra, sizeof(hdrl_image*)); + cpl_error_code * errs = cpl_calloc(num_spectra, sizeof(cpl_error_code)); + HDRL_OMP(omp parallel for) + for(cpl_size i = 0; i < num_spectra; i++){ + hdrl_image * img = get_padded_flux(resampled_spectra[i], + hdrl_spectrum1Dlist_get_const(ori_spectra, i), + mark_bpm_in_interpolation); + images[i] = img; + errs[i] = cpl_error_get_code(); + } + + cpl_error_code fail = get_first_error_code(errs, num_spectra); + cpl_free(errs); + + hdrl_imagelist * list = NULL; + if(!fail){ + list = hdrl_imagelist_new(); + + /* hdrl_imagelist_set has a race condition when growing the internal buffer + * it cannot be parallelized */ + for(cpl_size i = 0; i < num_spectra; i++){ + if(images[i] != NULL) + hdrl_imagelist_set(list, images[i], i); + } + } + cpl_free(images); + return list; +} +/*Function used in the getters: check that idx is in the correct ranges.*/ +static inline +cpl_error_code check_getter(const hdrl_spectrum1Dlist *s, const cpl_size idx){ + + if(s == NULL) return CPL_ERROR_NULL_INPUT; + + if(idx < 0) return CPL_ERROR_ACCESS_OUT_OF_RANGE; + + if(idx >= s->length) return CPL_ERROR_ACCESS_OUT_OF_RANGE; + + return CPL_ERROR_NONE; +} +/*wrapper around realloc, works are realloc, except if old_capacity == 0 (in this + * case it works like calloc) and if new_capacity == 0 (in this case it works like free)*/ +static inline hdrl_spectrum1D ** +safe_realloc(hdrl_spectrum1D ** current, const cpl_size old_capacity, + const cpl_size new_capacity){ + + /* Going from empty list to list with elements */ + if(old_capacity == 0 && new_capacity > 0){ + return cpl_calloc(new_capacity, sizeof(hdrl_spectrum1D * )); + } + + /* Clean capacity */ + if(new_capacity == 0){ + cpl_free(current); + return NULL; + } + + hdrl_spectrum1D ** to_ret = + cpl_realloc(current, sizeof(hdrl_spectrum1D * ) * new_capacity); + + for(cpl_size i = old_capacity + 1; i < new_capacity; ++i){ + to_ret[i] = NULL; + } + + return to_ret; +} + +/*increase the capacity of the list if length >= capacity*/ +static inline +void resize_if_needed(hdrl_spectrum1Dlist *self){ + + if(self->length < self->capacity) return; + + const cpl_size new_capacity = self->capacity == 0 ? 1 : 2 * self->capacity; + + self->spectra = safe_realloc(self->spectra, self->capacity, + new_capacity); + self->capacity = new_capacity; +} + +/*add an element in the back of a list, it can increase the capacity if needed*/ +static inline +void push_back(hdrl_spectrum1Dlist *self, hdrl_spectrum1D * s){ + + resize_if_needed(self); + self->spectra[self->length] = s; + self->length++; +} + +/*frees an array of spectrum1D and frees every spectrum1D*/ +static inline void +delete_spectrum1D_array(hdrl_spectrum1D ** resampled_spectra, + const cpl_size num_spectra){ + + hdrl_spectrum1Dlist * l = + hdrl_spectrum1Dlist_wrap(resampled_spectra, num_spectra); + hdrl_spectrum1Dlist_delete(l); +} + +/*check that all the spectra in the list are != NULL*/ +static inline cpl_boolean +are_spectra_valid(const hdrl_spectrum1Dlist * list){ + if(list == NULL) return CPL_FALSE; + + const cpl_size length = hdrl_spectrum1Dlist_get_size(list); + for(cpl_size i = 0; i < length; ++i){ + const hdrl_spectrum1D * s = hdrl_spectrum1Dlist_get_const(list, i); + if(s == NULL) return CPL_FALSE; + } + return CPL_TRUE; +} +/*get the first element in the array different from CPL_ERROR_NONE*/ +static inline cpl_error_code +get_first_error_code(const cpl_error_code * cds, const cpl_size length){ + for(cpl_size i = 0; i < length; ++i){ + if(cds[i]) return cds[i]; + } + return CPL_ERROR_NONE; +} + +static inline cpl_boolean +contains(const hdrl_spectrum1Dlist * list, const hdrl_spectrum1D * s){ + const cpl_size sz = hdrl_spectrum1Dlist_get_size(list); + for(cpl_size i = 0; i < sz; ++i){ + const hdrl_spectrum1D * s_in = hdrl_spectrum1Dlist_get_const(list, i); + if(s_in == s) return CPL_TRUE; + } + return CPL_FALSE; +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrumlist.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrumlist.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrumlist.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrumlist.h 2017-08-24 13:46:42.000000000 +0000 @@ -0,0 +1,92 @@ +/* $Id: hdrl_spectrum1Dlist.h,v 0.1 2017-04-26 18:30:28 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-04-26 18:30:28 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_SPECTRUMLIST_H +#define HDRL_SPECTRUMLIST_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Data Structures + -----------------------------------------------------------------------------*/ +typedef struct{ + cpl_size length; /*Number of valid spectra*/ + cpl_size capacity; /*Number of spectra that can fit in the internal buffer*/ + hdrl_spectrum1D ** spectra; /*Internal buffer*/ +}hdrl_spectrum1Dlist; + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_new(void); + +hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_duplicate(const hdrl_spectrum1Dlist * l); + +hdrl_spectrum1D * +hdrl_spectrum1Dlist_get(hdrl_spectrum1Dlist *, const cpl_size); + +const hdrl_spectrum1D * +hdrl_spectrum1Dlist_get_const(const hdrl_spectrum1Dlist *, const cpl_size); + +cpl_error_code +hdrl_spectrum1Dlist_set(hdrl_spectrum1Dlist *, hdrl_spectrum1D *, const cpl_size); + +hdrl_spectrum1D * +hdrl_spectrum1Dlist_unset(hdrl_spectrum1Dlist *, const cpl_size); + +void hdrl_spectrum1Dlist_delete(hdrl_spectrum1Dlist *); + +cpl_size +hdrl_spectrum1Dlist_get_size(const hdrl_spectrum1Dlist *); + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE + +hdrl_spectrum1Dlist * +hdrl_spectrum1Dlist_wrap(hdrl_spectrum1D ** self, const cpl_size sz); + +cpl_error_code +hdrl_spectrum1Dlist_collapse(const hdrl_spectrum1Dlist *list, + const hdrl_parameter * stacking_par, + const cpl_array * wlengths, const hdrl_parameter * resample_par, + const cpl_boolean mark_bpm_in_interpolation, + hdrl_spectrum1D ** result, cpl_image ** contrib, + hdrl_imagelist ** resampled_and_aligned_fluxes); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_resample.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_resample.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_resample.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_resample.c 2017-08-25 12:11:38.000000000 +0000 @@ -0,0 +1,1141 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum_resample.h" +#include "hdrl_spectrum_defs.h" +#include "hdrl_parameter.h" +#include "hdrl_utils.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +/*----------------------------------------------------------------------------- + Private Functions and Data Structures + -----------------------------------------------------------------------------*/ +/*Allocate gsl workspace*/ +static inline +gsl_bspline_workspace * alloc_workspace(int k, int nCoeff, + const double * x_dest, const cpl_size sample_len); + +/*Filling gsl structs for fitting*/ +static inline int +fit_matrixes(const double * x_raw, const double * y_raw, + const cpl_size sample_len, const int nCoeff, + gsl_bspline_workspace * ws, gsl_vector* B, + gsl_vector* c, gsl_matrix * cov); + +/*Private function used for the fit*/ +static inline cpl_error_code +hdrl_spectrum1D_bspline_fit_internal +(const double* x_raw, const double* y_raw, const cpl_size sample_len, +const cpl_array * lambdas_dest, const cpl_size lambdas_dest_start, +const cpl_size lambdas_dest_stop, cpl_image * flux_dest, +const int k, const int nCoeff); + +/*Private function used for the windowed fit*/ +static inline cpl_error_code +hdrl_spectrum1D_fit_windowed_internal +(const double* x_raw, const double* y_raw, const cpl_size sample_len, + const cpl_array * lambdas_dest, cpl_image * flux_dest, const int k, + const int nCoeff, const long window, const double factor); + +/* finds the closest element to l in arr*/ +static inline cpl_size +get_closest_lambda(const double *arr, const cpl_size num_els, const double l); + +/*See doc for hdrl_spectrum1D_resample*/ +static inline hdrl_spectrum1D * +resample_internal(const hdrl_spectrum1D * self, + const cpl_array * lambdas_dest, const hdrl_parameter * par); + + +static inline cpl_error_code +integrate_internal(double * x, const double * y, const double * y_var, + const cpl_size sample_len, const cpl_array * arg_lambdas_dest, + hdrl_image * flux_dest); + +static inline cpl_boolean +is_destination_outside_source_spectrum(const double * source, + const cpl_size source_length, const double dest_start, + const double dest_stop); + +static inline double +integrate(const double start_dest, const double stop_dest, + cpl_size * source_idx, const double * x, const double * y, + const cpl_size sample_len); + +static inline double +get_stop(const double * v, const cpl_size length, const cpl_size i); + +static inline double +get_start(const double * v, const cpl_size i); + + +/*Parameter used for the interpolation*/ +typedef struct { + HDRL_PARAMETER_HEAD; + hdrl_spectrum1D_interpolation_method method; +} hdrl_spectrum1D_resample_interpolate_parameter; + +static hdrl_parameter_typeobj +hdrl_spectrum1D_resample_interpolate_parameter_type = { + HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTERPOLATE, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_spectrum1D_resample_interpolate_parameter), /* obj_size */ +}; + +/*Parameter used for the integration*/ +typedef struct { + HDRL_PARAMETER_HEAD; +} hdrl_spectrum1D_resample_integrate_parameter; + +static hdrl_parameter_typeobj +hdrl_spectrum1D_resample_integrate_parameter_type = { + HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTEGRATE, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_spectrum1D_resample_integrate_parameter), /* obj_size */ +}; + + +/*getter for the type of the interpolation*/ +hdrl_spectrum1D_interpolation_method +hdrl_spectrum1D_resample_interpolate_parameter_get_method(const hdrl_parameter * par){ + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTERPOLATE, + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + + const hdrl_spectrum1D_resample_interpolate_parameter * p = + (const hdrl_spectrum1D_resample_interpolate_parameter *)par; + + return p->method; +} + +/*Parameter used for the fit*/ +typedef struct { + HDRL_PARAMETER_HEAD; + int k; + int nCoeff; + long window; + double factor; +} hdrl_spectrum1D_resample_fit_parameter; + +static hdrl_parameter_typeobj +hdrl_spectrum1D_resample_fit_parameter_type = { + HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_spectrum1D_resample_fit_parameter), /* obj_size */ +}; + +/*getter for the k parameter in fit*/ +int hdrl_spectrum1D_resample_fit_parameter_get_k(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT, + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + + const hdrl_spectrum1D_resample_fit_parameter * p = + (const hdrl_spectrum1D_resample_fit_parameter *)par; + return p->k; +} + +/*getter for the nCoeff parameter in fit*/ +int hdrl_spectrum1D_resample_fit_parameter_get_nCoeff +(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT, + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + + const hdrl_spectrum1D_resample_fit_parameter * p = + (const hdrl_spectrum1D_resample_fit_parameter *)par; + return p->nCoeff; +} + +/*getter for the window parameter in fit*/ +long hdrl_spectrum1D_resample_fit_parameter_get_window +(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT, + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + + const hdrl_spectrum1D_resample_fit_parameter * p = + (const hdrl_spectrum1D_resample_fit_parameter *)par; + return p->window; +} + +/*getter for the window parameter in fit*/ +long hdrl_spectrum1D_resample_fit_parameter_get_factor +(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT, + CPL_ERROR_INCOMPATIBLE_INPUT, 0); + + const hdrl_spectrum1D_resample_fit_parameter * p = + (const hdrl_spectrum1D_resample_fit_parameter *)par; + return p->factor; +} + +/** + * @addtogroup hdrl_spectrum1D + * @{ + */ +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief constructor for the hdrl_parameter in the case of interpolation + * @param method interpolation methods, see the enum + * hdrl_spectrum1D_interpolation_method + * + * @return the constructed parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter* hdrl_spectrum1D_resample_interpolate_parameter_create +(const hdrl_spectrum1D_interpolation_method method){ + hdrl_spectrum1D_resample_interpolate_parameter * p + = (hdrl_spectrum1D_resample_interpolate_parameter *) + hdrl_parameter_new(&hdrl_spectrum1D_resample_interpolate_parameter_type); + p->method = method; + return (hdrl_parameter*) p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief constructor for the hdrl_parameter in the case of integration + * + * @return the constructed parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter* hdrl_spectrum1D_resample_integrate_parameter_create(void){ + hdrl_spectrum1D_resample_integrate_parameter * p + = (hdrl_spectrum1D_resample_integrate_parameter *) + hdrl_parameter_new(&hdrl_spectrum1D_resample_integrate_parameter_type); + return (hdrl_parameter*) p; +} + + +hdrl_parameter * hdrl_spectrum1D_resample_interpolate_parameter_parse_parlist( + const cpl_parameterlist * parlist, const char * prefix){ + + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + + /* Get the Method parameter */ + char * name = hdrl_join_string(".", 2, prefix, "method"); + + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + const char * value = cpl_parameter_get_string(par); + if (value == NULL) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Parameter %s not found", name); + cpl_free(name); + return NULL; + } + + hdrl_spectrum1D_interpolation_method met = hdrl_spectrum1D_interp_linear; + /* Switch on the methods */ + if(!strcmp(value, "LINEAR")) + met = hdrl_spectrum1D_interp_linear; + + else if(!strcmp(value, "CSPLINE")) + met = hdrl_spectrum1D_interp_cspline; + + else if (!strcmp(value, "AKIMA")) + met = hdrl_spectrum1D_interp_akima; + + else{ + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Interpolation method %s not found", value); + cpl_free(name); + return NULL; + } + + cpl_free(name); + return hdrl_spectrum1D_resample_interpolate_parameter_create(met); +} + +cpl_parameterlist * +hdrl_spectrum1D_resample_interpolate_parameter_create_parlist(const char * base_context, + const char * prefix, const char * method_def) { + + cpl_ensure(base_context && prefix, CPL_ERROR_NULL_INPUT, NULL); + char * name ; + cpl_parameterlist * parlist = cpl_parameterlist_new(); + cpl_parameter * p ; + char * context = hdrl_join_string(".", 2, base_context, prefix); + + /* --prefix.method */ + name = hdrl_join_string(".", 2, context, "method"); + p = cpl_parameter_new_enum(name, CPL_TYPE_STRING, + "Method used for Spectrum1D interpolation", context, + method_def, 3, "LINEAR", "CSPLINE", "AKIMA"); + cpl_free(name) ; + name = hdrl_join_string(".", 2, prefix, "method"); + cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, name); + cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV); + cpl_free(name) ; + cpl_parameterlist_append(parlist, p); + + cpl_free(context); + return parlist; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief constructor for the hdrl_parameter in the case of interpolation + * @param k order of the B-spline + * @param nCoeff number of coefficients used for the fit + * + * @return the constructed parameter + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter* hdrl_spectrum1D_resample_fit_parameter_create( + const int k, const int nCoeff){ + + hdrl_spectrum1D_resample_fit_parameter * p + = (hdrl_spectrum1D_resample_fit_parameter *) + hdrl_parameter_new(&hdrl_spectrum1D_resample_fit_parameter_type); + p->k = k; + p->nCoeff = nCoeff; + p->window = 0; + p->factor = 1.0; + return (hdrl_parameter*) p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief constructor for the hdrl_parameter in the case of interpolation + * @param k order of the B-spline + * @param nCoeff number of coefficients used for the fit + * @param window number of destination wavelengths whose flux values are + * computed using the same model + * @param factor Given window2 = window * factor. window2 is the number of + * source wavelengths used to compute the fit model + * + * @return the constructed parameter, NULL in case of error + * + * @note window must be greater than 0 and factor greater or equal than 1.0 + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter* hdrl_spectrum1D_resample_fit_windowed_parameter_create( + const int k, const int nCoeff, const long window, const double factor){ + + cpl_ensure(window > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(factor >= 1.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + hdrl_spectrum1D_resample_fit_parameter * p + = (hdrl_spectrum1D_resample_fit_parameter *) + hdrl_parameter_new(&hdrl_spectrum1D_resample_fit_parameter_type); + p->k = k; + p->nCoeff = nCoeff; + p->window = window; + p->factor = factor; + return (hdrl_parameter*) p; +} + +cpl_error_code +hdrl_resample_parameter_verify(const hdrl_parameter * par){ + + cpl_ensure_code(par != NULL, CPL_ERROR_NULL_INPUT); + + hdrl_parameter_enum method = hdrl_parameter_get_parameter_enum(par); + + cpl_ensure_code(method == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTERPOLATE || + method == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT || + method == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTEGRATE, + CPL_ERROR_INCOMPATIBLE_INPUT); + + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief resample a hdrl_spectrum1D on the wavelengths contained in waves + * @param self the spectrum to be resampled + * @param waves the waves the spectrum has to be resampled on + * @param par hdrl_parameter, see + * hdrl_spectrum1D_resample_fit_parameter_create(), + * hdrl_spectrum1D_resample_interpolate_parameter_create() or + * hdrl_spectrum1D_resample_integrate_parameter_create(). + * + * @return the resampled spectrum, NULL in case of error (see below). + * + * @note providing a spectrum with sorted, strictly monotonic increasing wavelength + * values will provide the best performance. If the spectrum is not sorted, the + * routine will create a copy of it and sort the copy. In case of duplicated + * wavelengths they are collapsed in a single wavelength and the corresponding + * flux is calculated as the median of the fluxes. Error propagation is performed + * through linear interpolation of the variance (error^2) of the spectrum in case + * of fit or interpolation. In case of integration we integrate the variance using + * the same weights used for the flux. The integration is done assuming that the + * flux is constant inside the bin and that the bin is centered on the sample. + * The only exceptions are the first bin (it starts at the sample) and the last + * bin (it ends at the sample). + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the pointers are NULL + * - CPL_ERROR_INCOMPATIBLE_INPUT: if the scale of self and waves are different + * or if par cannot be casted to any of the resample parameters (fit, + * interpolation, integration) + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_resample(const hdrl_spectrum1D * self, + const hdrl_spectrum1D_wavelength* waves, + const hdrl_parameter* par){ + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self-> flux != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(waves != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(waves->wavelength != NULL, CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(self->wave_scale == waves->scale, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + if(hdrl_resample_parameter_verify(par)) return NULL; + + /* if the two spectra are already compatible and we not fitting, + * simply return a copy of self */ + hdrl_spectrum1D_wavelength self_w = hdrl_spectrum1D_get_wavelength(self); + if(hdrl_spectrum1D_are_spectra_compatible(&self_w, waves) && + hdrl_parameter_get_parameter_enum(par) != HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_FIT) + return hdrl_spectrum1D_duplicate(self); + + return resample_internal(self, waves->wavelength, par); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief resample a hdrl_spectrum1D on the wavelengths contained in waves + * @param self the spectrum to be resampled + * @param waves the waves the spectrum has to be resampled on + * @param par hdrl_parameter, see + * hdrl_spectrum1D_resample_fit_parameter_create(), + * hdrl_spectrum1D_resample_interpolate_parameter_create() or + * hdrl_spectrum1D_resample_integrate_parameter_create(). + * + * @return the resampled spectrum, NULL in case of error (see below). + * + * @note providing a spectrum with sorted, strictly monotonic increasing wavelength + * values will provide the best performance. If the spectrum is not sorted, the + * routine will create a copy of it and sort the copy. In case of duplicated + * wavelengths they are collapsed in a single wavelength and the corresponding + * flux is calculated as the median of the fluxes. Error propagation is performed + * through linear interpolation of the variance (error^2) of the spectrum in case + * of fit or interpolation. In case of integration we integrate the variance using + * the same weights used for the flux. The integration is done assuming that the + * flux is constant inside the bin and that the bin is centered on the sample. + * The only exceptions are the first bin (it starts at the sample) and the last + * bin (it ends at the sample). + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: if any of the pointers are NULL + * - CPL_ERROR_INCOMPATIBLE_INPUT: if par cannot be casted to any of the resample + * parameters (fit, interpolation, integration) + */ +/* ---------------------------------------------------------------------------*/ +hdrl_spectrum1D * +hdrl_spectrum1D_resample_on_array(const hdrl_spectrum1D * self, + const cpl_array * waves, + const hdrl_parameter* par){ + + cpl_ensure(waves != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self-> flux != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, NULL); + + if(hdrl_resample_parameter_verify(par)) return NULL; + + /* if the two spectra are already compatible and we NOT fitting, + * simply return a copy of self */ + hdrl_spectrum1D_wavelength self_w = hdrl_spectrum1D_get_wavelength(self); + if(hdrl_parameter_get_parameter_enum(par) == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTERPOLATE && + hdrl_spectrum1D_are_wavelengths_compatible(self_w.wavelength, waves)) + return hdrl_spectrum1D_duplicate(self); + + hdrl_spectrum1D * to_ret = resample_internal(self, waves, par); + + return to_ret; +} + +/*----------------------------------------------------------------------------- + Private Functions Implementation + -----------------------------------------------------------------------------*/ + +/*wrapper around the allocation function provided by gsl. It maps our enum in + * gls types.*/ +static inline gsl_spline * get_interp_spline +(const hdrl_spectrum1D_interpolation_method method, const int sample_len){ + + switch(method){ + case hdrl_spectrum1D_interp_linear: + return gsl_spline_alloc (gsl_interp_linear, sample_len); + case hdrl_spectrum1D_interp_cspline: + return gsl_spline_alloc (gsl_interp_cspline, sample_len); + case hdrl_spectrum1D_interp_akima: + return gsl_spline_alloc (gsl_interp_akima, sample_len); + default: + cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL); + } + /*To avoid warning*/ + return NULL; +} + +/* cleanup for the gsl interpolation structs*/ +static inline void +cleanup_gsl_interpolate(gsl_interp_accel ** acc_flux, gsl_spline ** spline_flux){ + if(acc_flux != NULL && *acc_flux != NULL){ + gsl_interp_accel_free (*acc_flux); + *acc_flux = NULL; + } + + if(spline_flux != NULL && *spline_flux != NULL){ + gsl_spline_free (*spline_flux); + *spline_flux = NULL; + } +} +/*Init of the gls interpolation data structures. + * If fails, the memory is cleaned-up */ +static inline cpl_error_code +init_gsl_interpolate( + const double *x, const double *y, const cpl_size sample_len, + const hdrl_spectrum1D_interpolation_method method, + gsl_interp_accel ** acc_flux, gsl_spline ** spline_flux){ + + *acc_flux = gsl_interp_accel_alloc (); + + cpl_ensure_code(*acc_flux, CPL_ERROR_UNSPECIFIED); + + *spline_flux = get_interp_spline(method, sample_len); + + if(!*spline_flux){ + cleanup_gsl_interpolate(acc_flux, spline_flux); + cpl_ensure_code(0, CPL_ERROR_UNSPECIFIED); + } + + int fail = gsl_spline_init(*spline_flux, x, y, sample_len); + + if(fail){ + cleanup_gsl_interpolate(acc_flux, spline_flux); + cpl_ensure_code(0, CPL_ERROR_UNSPECIFIED); + } + + return CPL_ERROR_NONE; +} + +/*Wrapper around gsl_spline_eval. If x is outside the interval provided during + * init phase we return NAN. GSL would abort the program.*/ +static inline +double spline_eval_internal +(const gsl_spline * spline, double x, gsl_interp_accel * a, cpl_boolean * is_rej){ + + *is_rej = x < spline->x[0] || x > spline->x[spline->size - 1]; + + if (*is_rej){ + return NAN; + } + + return gsl_spline_eval(spline, x, a); +} + +static inline cpl_size +get_closest_lambda(const double *arr, const cpl_size num_els, const double l){ + + cpl_size best_idx = 0; + double smallest_diff = fabs(arr[0] - l); + + for(cpl_size i = 1; i < num_els; i++){ + const double diff = fabs(arr[i] - l); + + if(diff < smallest_diff){ + smallest_diff = diff; + best_idx = i; + } + + /*we assume arr sorted*/ + if(arr[i] >= l) break; + } + return best_idx; +} + +static inline cpl_error_code +fill_cpl_image_with_interpolation(const double *x, const double *y, + const cpl_size sample_len, const hdrl_spectrum1D_interpolation_method method, + const cpl_array * lambdas_dest, cpl_image * dest){ + + cpl_size dest_len = cpl_array_get_size(lambdas_dest); + + gsl_interp_accel * acc_flux = NULL; + gsl_spline * spline_flux = NULL; + + cpl_error_code fail = + init_gsl_interpolate(x, y, sample_len, method, &acc_flux, &spline_flux); + + cpl_ensure_code(fail == CPL_ERROR_NONE, fail); + + for(cpl_size i = 0; i < dest_len; i++){ + const double lambda = cpl_array_get(lambdas_dest, i, NULL); + cpl_boolean is_rejected = CPL_FALSE; + const double val = spline_eval_internal(spline_flux, lambda, + acc_flux, &is_rejected); + if(is_rejected){ + cpl_image_reject(dest, i + 1, 1); + } + else{ + cpl_image_set(dest, i + 1, 1, val); + } + } + cleanup_gsl_interpolate(&acc_flux, &spline_flux); + + return CPL_ERROR_NONE; +} + +static inline double +get_min(const double * x, cpl_size length){ + double best = x[0]; + for(cpl_size i = 1; i < length; ++i){ + if(x[i] < best) best = x[i]; + } + return best; +} + +static inline double +get_max(const double * x, cpl_size length){ + double best = x[0]; + for(cpl_size i = 1; i < length; ++i){ + if(x[i] > best) best = x[i]; + } + return best; +} + +static inline +gsl_bspline_workspace * alloc_workspace(int k, int nCoeff, + const double * x_dest, const cpl_size sample_len){ + + const int nKnots = nCoeff + 2 - k; + + gsl_bspline_workspace * ws = gsl_bspline_alloc(k, nKnots); + + double lambda_min = get_min(x_dest, sample_len); + double lambda_max = get_max(x_dest, sample_len); + + gsl_bspline_knots_uniform(lambda_min, lambda_max, ws); + return ws; +} + +static inline cpl_error_code +hdrl_spectrum1D_fit_windowed_internal +(const double* x_raw, const double* y_raw, const cpl_size sample_len, + const cpl_array * lambdas_dest, cpl_image * flux_dest, const int k, + const int nCoeff, const long window, const double factor){ + + const cpl_size dest_size = cpl_array_get_size(lambdas_dest); + + const cpl_size fit_win = (cpl_size)((double)window * factor); + const cpl_size extra_samples_for_fit = (fit_win - window) / 2; + + for(cpl_size dest_start = 0; dest_start < dest_size; dest_start += window){ + + const cpl_size dest_stop = CPL_MIN(dest_size - 1, dest_start + window - 1); + + const double min_dest_lambda = + cpl_array_get(lambdas_dest, dest_start, NULL); + const double max_dest_lambda = + cpl_array_get(lambdas_dest, dest_stop, NULL); + + /*get corresponding indexes in x_raw (we need to be sure that + * min_dest_lambda and max_dest_lambda are inside the interval, + * hence the +1 and -1)*/ + cpl_size raw_start = + get_closest_lambda(x_raw, sample_len, min_dest_lambda) - 1; + cpl_size raw_end = + get_closest_lambda(x_raw, sample_len, max_dest_lambda) + 1; + + /*expand the fit window*/ + raw_end += extra_samples_for_fit; + raw_start -= extra_samples_for_fit; + + raw_end = CPL_MIN(sample_len - 1, raw_end); + raw_start = CPL_MAX(0, raw_start); + + const cpl_size win_len = raw_end - raw_start + 1; + + cpl_error_code fail = hdrl_spectrum1D_bspline_fit_internal( + x_raw + raw_start, y_raw + raw_start, win_len, + lambdas_dest, dest_start, dest_stop, flux_dest, k, nCoeff); + + if(fail) return fail; + } + + return CPL_ERROR_NONE; +} + +static inline cpl_error_code +hdrl_spectrum1D_bspline_fit_internal +(const double* x_raw, const double* y_raw, +const cpl_size sample_len, const cpl_array * lambdas_dest, +const cpl_size lambdas_dest_start, const cpl_size lambdas_dest_stop, +cpl_image * flux_dest, const int k, const int nCoeff){ + + cpl_ensure_code(sample_len >= nCoeff, CPL_ERROR_INCOMPATIBLE_INPUT); + + gsl_vector* B = gsl_vector_alloc(nCoeff); + gsl_vector* c = gsl_vector_alloc(nCoeff); + gsl_matrix * cov = gsl_matrix_alloc(nCoeff, nCoeff); + gsl_bspline_workspace * ws = alloc_workspace(k, nCoeff, x_raw, sample_len); + + int fail = fit_matrixes(x_raw, y_raw, sample_len, nCoeff, ws, B, c, cov); + + cpl_error_code error = !fail ? CPL_ERROR_NONE : CPL_ERROR_UNSPECIFIED; + const double x_raw_min = x_raw[0]; + const double x_raw_max = x_raw[sample_len - 1]; + + if(!error) + { + cpl_size dest_len = cpl_array_get_size(lambdas_dest); + + for (cpl_size i = CPL_MAX(0, lambdas_dest_start); + i <= CPL_MIN(dest_len - 1, lambdas_dest_stop); i++) + { + const double x_dest = cpl_array_get(lambdas_dest, i, NULL); + + /*If outside boundaries reject*/ + if(x_dest < x_raw_min || x_dest > x_raw_max){ + cpl_image_reject(flux_dest, i + 1, 1); + continue; + } + + gsl_bspline_eval(x_dest, B, ws); + double y_dest = 0.0, irrelevant = 0.0; + gsl_multifit_linear_est(B, c, cov, &y_dest, &irrelevant); + + cpl_image_set(flux_dest, i + 1, 1, y_dest); + } + } + + gsl_matrix_free(cov); + gsl_vector_free(B); + gsl_vector_free(c); + gsl_bspline_free(ws); + + return error; +} + +static inline +cpl_size count_equals_from_i +(const double * x, const cpl_size i, const cpl_size sample_len){ + + cpl_size idx = i; + while( (idx < sample_len - 1) && x[idx] == x[idx + 1]) + idx++; + + return idx - i + 1; +} + +static inline int compare_d(const void * a, const void * b){ + const double * a_d = (const double*)a; + const double * b_d = (const double*)b; + + const double delta = *a_d - *b_d; + if(delta > 0.0) return 1; + if(delta < 0.0) return -1; + return 0; +} + +static inline +double get_median(double * x, const cpl_size first, const cpl_size n){ + + double * v = x + first; + qsort(v, n, sizeof(x[0]), compare_d); + + if(n % 2 != 0) return v[n / 2]; + + return (v[n / 2] + v[(n - 1)/2]) / 2.0; +} + +cpl_size +hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median(double * x, + double * y1, double * y2, cpl_size sample_len){ + + for(cpl_size i = 0; i < sample_len - 1; i++){ + + const cpl_size n_equals = count_equals_from_i(x, i, sample_len); + + if(n_equals <= 1) continue; + + y1[i] = get_median(y1, i, n_equals); + y2[i] = get_median(y2, i, n_equals); + + const cpl_size num_els_to_copy = sample_len - (i + n_equals); + const cpl_size num_bytes = sizeof(double) * num_els_to_copy; + + if(num_bytes > 0){ + /* using memmove because memory overlaps*/ + memmove( x + i + 1, x + i + n_equals, (size_t)num_bytes); + memmove(y1 + i + 1, y1 + i + n_equals, (size_t)num_bytes); + memmove(y2 + i + 1, y2 + i + n_equals, (size_t)num_bytes); + } + /* one of the n_equals elements is survived (it is median now), hence the + * -1*/ + sample_len -= n_equals - 1; + } + + return sample_len; +} + + +static inline int +fit_matrixes(const double * x_raw, const double * y_raw, + const cpl_size sample_len, const int nCoeff, + gsl_bspline_workspace * ws, gsl_vector* B, + gsl_vector* c, gsl_matrix * cov){ + + gsl_matrix* X = gsl_matrix_alloc(sample_len, nCoeff); + + for(cpl_size i = 0; i < sample_len; ++i){ + int fail = gsl_bspline_eval(x_raw[i], B, ws); + if(fail) continue; + for(cpl_size j = 0; j < nCoeff; j++){ + gsl_matrix_set(X, i, j, gsl_vector_get(B, j)); + } + } + + double chisq = 0.0; + gsl_vector_const_view y = gsl_vector_const_view_array(y_raw, sample_len); + gsl_multifit_linear_workspace* mw = + gsl_multifit_linear_alloc(sample_len, nCoeff); + + const int error = gsl_multifit_linear(X, &y.vector, c, cov, &chisq, mw); + + gsl_multifit_linear_free(mw); + gsl_matrix_free(X); + + return error; +} + +static inline cpl_error_code +resample_with_interpol_on_variance(const hdrl_parameter * par, + const cpl_boolean interpolate, const double * x, const double * y, + const double * y_var, const cpl_size sample_len, + const cpl_array * lambdas_dest, hdrl_image * flux_dest){ + + cpl_error_code fail = CPL_ERROR_NONE; + + if(interpolate){ + hdrl_spectrum1D_interpolation_method int_met = + hdrl_spectrum1D_resample_interpolate_parameter_get_method(par); + + fail = fill_cpl_image_with_interpolation(x, y, sample_len, int_met, + lambdas_dest, hdrl_image_get_image(flux_dest)); + } else { + + int k = hdrl_spectrum1D_resample_fit_parameter_get_k(par); + int nCoeff = hdrl_spectrum1D_resample_fit_parameter_get_nCoeff(par); + long window1 = hdrl_spectrum1D_resample_fit_parameter_get_window(par); + double factor= hdrl_spectrum1D_resample_fit_parameter_get_factor(par); + + if(window1 == 0){ + fail = hdrl_spectrum1D_bspline_fit_internal(x, y, + sample_len, lambdas_dest, 0, + cpl_array_get_size(lambdas_dest) - 1, + hdrl_image_get_image(flux_dest), k, nCoeff); + } else{ + fail = hdrl_spectrum1D_fit_windowed_internal(x, y, + sample_len, lambdas_dest, + hdrl_image_get_image(flux_dest), k, + nCoeff, window1, factor); + } + } + + if(!fail){ + /* linear interpolate variance */ + fill_cpl_image_with_interpolation(x, y_var, sample_len, + hdrl_spectrum1D_interp_linear, + lambdas_dest, hdrl_image_get_error(flux_dest)); + /* convert variance into error taking the square root*/ + cpl_image_power(hdrl_image_get_error(flux_dest), 0.5); + } + + return fail; +} + +static inline double +get_start(const double * v, const cpl_size i){ + + if(i <= 0){ + return v[0]; + } + + const double post = v[i]; + const double pre = v[i - 1]; + + return (post + pre) / 2.0; +} + +static inline double +get_stop(const double * v, const cpl_size length, const cpl_size i){ + + if(i >= length - 1){ + return v[length - 1]; + } + + const double post = v[i + 1]; + const double pre = v[i]; + + return (post + pre) / 2.0; +} + + +static inline cpl_boolean +is_destination_outside_source_spectrum(const double * source, + const cpl_size source_length, const double dest_start, + const double dest_stop){ + /*edge case, source cover a smaller interval than dest, hence starting and/or + * ending bins in destination might be NAN*/ + const double source_lower_bound = get_start(source, 0); + const double source_upper_bound = get_stop(source, source_length, source_length - 1); + + /* destination starts before the start of the first bin*/ + if(dest_start < source_lower_bound) return CPL_TRUE; + /* destination ends after the end of the last bin*/ + if(dest_stop > source_upper_bound) return CPL_TRUE; + + return CPL_FALSE; +} + + +static inline double +integrate(const double start_dest, const double stop_dest, + cpl_size * source_idx, const double * x, const double * y, + const cpl_size sample_len){ + + double start_source = NAN; + double stop_source = NAN; + double val = 0.0; + + if(is_destination_outside_source_spectrum(x, sample_len, start_dest, stop_dest)) + return NAN; + + /*area of destination bin*/ + const double den = stop_dest - start_dest; + *source_idx = CPL_MIN(*source_idx, sample_len - 1); + + do{ + /*start and stop of source bin*/ + start_source = get_start(x, *source_idx); + stop_source = get_stop(x, sample_len, *source_idx); + + /* There is no intersection, source starts after the end of dest. + * We are done with this bin, go back one step so that the next + * destination can use the source bin. */ + if(start_source >= stop_dest) { + *source_idx = CPL_MAX(*source_idx - 1, 0); + break; + } + + /* If stop_source <= start_dest, there is no intersection, + * source ends before the start of dest. We can skip this element of source + * increase the index so that the next element can be used. We are sure + * that there will be an acceptable element because we already checked boundaries + * before starting the loop.*/ + if(stop_source > start_dest){ + /*Get common area*/ + const double common_slice_start = CPL_MAX(start_source, start_dest); + const double common_slice_stop = CPL_MIN(stop_source, stop_dest); + const double num = common_slice_stop - common_slice_start; + + val += y[*source_idx] * num / den; + } + + *source_idx = *source_idx + 1; + + }while(*source_idx < sample_len); + + return val; +} + +static inline cpl_error_code +integrate_internal(double * x, const double * y, const double * y_var, + const cpl_size sample_len, const cpl_array * arg_lambdas_dest, + hdrl_image * flux_dest){ + + const cpl_size size_dest = cpl_array_get_size(arg_lambdas_dest); + cpl_bivector * lamb_dest = cpl_bivector_new(size_dest); + + for(cpl_size i = 0; i < size_dest ; ++i){ + const double val = cpl_array_get(arg_lambdas_dest, i, NULL); + cpl_vector_set(cpl_bivector_get_x(lamb_dest), i, val); + cpl_vector_set(cpl_bivector_get_y(lamb_dest), i, i); + } + /*Sort dest lambdas keeping track of the original position*/ + cpl_bivector_sort(lamb_dest, lamb_dest, CPL_SORT_ASCENDING, CPL_SORT_BY_X); + cpl_size source_idx = 0; + const double * lambdas_dest_sorted = + cpl_vector_get_data_const(cpl_bivector_get_x(lamb_dest)); + + for(cpl_size i = 0; i < size_dest; ++i){ + + const double start_destination = get_start(lambdas_dest_sorted, i); + const double stop_destination = get_stop(lambdas_dest_sorted, size_dest , i); + + /*copy index before increase for error computation*/ + cpl_size old_idx = source_idx; + const double val = integrate(start_destination, stop_destination, + &source_idx, x, y, sample_len); + + const double val_e = sqrt(integrate(start_destination, stop_destination, + &old_idx, x, y_var, sample_len)); + + const cpl_size dest_idx = + (cpl_size) cpl_vector_get(cpl_bivector_get_y(lamb_dest), i); + + if(!isfinite(val) || !isfinite(val_e)) { + hdrl_image_reject(flux_dest, dest_idx + 1, 1); + continue; + } + + hdrl_image_set_pixel(flux_dest, dest_idx + 1, 1, (hdrl_value){val, val_e}); + } + + cpl_bivector_delete(lamb_dest); + + return CPL_ERROR_NONE; +} + +static inline hdrl_spectrum1D * +resample_internal(const hdrl_spectrum1D * self, + const cpl_array * lambdas_dest, const hdrl_parameter * par){ + + const cpl_size f_len = hdrl_spectrum1D_get_size(self); + cpl_size sample_len = 0; + + double * y = cpl_calloc(f_len, sizeof(double)); + double * y_var = cpl_calloc(f_len, sizeof(double)); + double * x = cpl_calloc(f_len, sizeof(double)); + + const cpl_boolean reject_bad_pix = + hdrl_parameter_get_parameter_enum(par) != HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTEGRATE; + + for(cpl_size i = 0; i < f_len; i++){ + + int rej = 0; + const hdrl_value v = hdrl_spectrum1D_get_flux_value(self, i, &rej); + rej = rej || isnan((double)v.data) || isinf((double)v.data); + + if(reject_bad_pix && rej) continue; + + y[sample_len] = rej ? NAN : v.data; + /*We interpolate the VARIANCE*/ + y_var[sample_len] = rej ? NAN : pow(v.error, 2.0); + x[sample_len] = hdrl_spectrum1D_get_wavelength_value(self, i, NULL); + sample_len++; + } + + if(sample_len == 0){ + cpl_free(x); + cpl_free(y); + cpl_free(y_var); + cpl_ensure(CPL_FALSE, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + } + + /* If wavelengths are not strictly increasing, sort and collapse in case of + * duplicate wavelengths. */ + if(!hdrl_is_strictly_monotonic_increasing(x, sample_len)){ + /* we need to sort the three arrays so x is strictly increasing*/ + hdrl_sort_on_x(x, y, y_var, sample_len, CPL_FALSE); + /* remove duplicated lambdas and substitute flux with median*/ + sample_len = + hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y, y_var, sample_len); + } + + if(sample_len == 0){ + cpl_free(x); + cpl_free(y); + cpl_free(y_var); + cpl_ensure(CPL_FALSE, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + } + + cpl_size dest_len = cpl_array_get_size(lambdas_dest); + hdrl_image * flux_dest = hdrl_image_new(dest_len, 1); + + cpl_error_code fail = CPL_ERROR_NONE; + + hdrl_parameter_enum method = hdrl_parameter_get_parameter_enum(par); + + if(method != HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTEGRATE){ + const cpl_boolean is_interpolation = + method == HDRL_PARAMETER_SPECTRUM1D_RESAMPLE_INTERPOLATE; + fail = resample_with_interpol_on_variance(par, is_interpolation, x, y, + y_var, sample_len, lambdas_dest, flux_dest); + } + else{ + fail = integrate_internal(x, y, y_var, sample_len, lambdas_dest, + flux_dest); + } + cpl_free(x); + cpl_free(y); + cpl_free(y_var); + + hdrl_spectrum1D * to_ret = NULL; + + if(fail == CPL_ERROR_NONE) + { + const cpl_image * img = hdrl_image_get_image_const(flux_dest); + const cpl_image * img_e = hdrl_image_get_error_const(flux_dest); + to_ret = hdrl_spectrum1D_create(img, img_e, lambdas_dest, + self->wave_scale); + } + hdrl_image_delete(flux_dest); + + cpl_ensure(fail == CPL_ERROR_NONE, fail, NULL); + + return to_ret; +} +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_resample.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_resample.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_resample.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_resample.h 2017-08-25 12:11:38.000000000 +0000 @@ -0,0 +1,108 @@ +/* $Id: hdrl_spectrum_resample.h,v 0.1 2017-03-14 16:49:00 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-03-14 16:49:00 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_SPECTRUM_RESAMPLE_H +#define HDRL_SPECTRUM_RESAMPLE_H + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum.h" +#include "hdrl_parameter.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Data structures + -----------------------------------------------------------------------------*/ +/* Possible methods for interpolation possible */ +typedef enum{ + hdrl_spectrum1D_interp_linear, + hdrl_spectrum1D_interp_cspline, + hdrl_spectrum1D_interp_akima, +}hdrl_spectrum1D_interpolation_method; + + +hdrl_parameter* hdrl_spectrum1D_resample_interpolate_parameter_create +(const hdrl_spectrum1D_interpolation_method method); + +hdrl_parameter* hdrl_spectrum1D_resample_integrate_parameter_create(void); + +hdrl_parameter * hdrl_spectrum1D_resample_interpolate_parameter_parse_parlist( + const cpl_parameterlist *, const char *); +cpl_parameterlist * hdrl_spectrum1D_resample_interpolate_parameter_create_parlist( + const char *, const char *, const char *) ; + +hdrl_parameter* +hdrl_spectrum1D_resample_fit_parameter_create(const int k, const int nCoeff); + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +hdrl_parameter* +hdrl_spectrum1D_resample_fit_windowed_parameter_create( + const int k, const int nCoeff, const long window, const double factor); +#endif + +cpl_error_code hdrl_resample_parameter_verify(const hdrl_parameter *); + +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ + +hdrl_spectrum1D * +hdrl_spectrum1D_resample(const hdrl_spectrum1D * self, + const hdrl_spectrum1D_wavelength* waves, + const hdrl_parameter* par); + +hdrl_spectrum1D * +hdrl_spectrum1D_resample_on_array(const hdrl_spectrum1D * self, + const cpl_array* waves, + const hdrl_parameter* par); + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE + +void +hdrl_spectrum1D_resample_sort_on_x(double * x, double * y1, double * y2, cpl_size sample_len); + +cpl_size hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median(double * x, double * y1, + double * y2, const cpl_size sample_len); + + +cpl_boolean hdrl_spectrum1D_resample_is_strictly_monotonic_increasing(double * x, cpl_size l); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_shift.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_shift.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_shift.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_shift.c 2017-08-23 14:34:38.000000000 +0000 @@ -0,0 +1,511 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_spectrum_shift.h" +#include "hdrl_parameter.h" +#include "hdrl_spectrum_resample.h" + +#include + +/** + * + * @addtogroup hdrl_spectrum1D + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ +/*----------------------------------------------------------------------------- + Private Functions + -----------------------------------------------------------------------------*/ + +static inline hdrl_data_t +hdrl_spectrum1D_compute_min_fit(const hdrl_spectrum1D * s, + const hdrl_parameter * shift_par); + +static inline cpl_bivector * get_win(hdrl_data_t wmin, hdrl_data_t wmax); + + +static inline cpl_array * +convert_to_sorted_array(const hdrl_spectrum1D * s1); + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_fit_half_win(const hdrl_parameter * par); +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_fit_wmax(const hdrl_parameter * par); +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_fit_wmin(const hdrl_parameter * par); +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_range_wmin(const hdrl_parameter * par); +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_range_wmax(const hdrl_parameter * par); +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_wguess(const hdrl_parameter * par); + +static inline hdrl_spectrum1D * +get_polyfit_for_slope(const int degree, const hdrl_spectrum1D * s, + const cpl_array * wlengths); + +static inline hdrl_spectrum1D * +hdrl_spectrum1D_fit(const hdrl_spectrum1D * obs, const int degree, + const hdrl_data_t wmin, const hdrl_data_t wmax); +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ +/** + * @brief The function computes the shift between the two spectra. + * + * @param s1 first spectrum + * @param s2 second spectrum + * @param half_win half window where the correlation will be calculated + * @param normalize normalize mean and stdev in cross-correlation calculation + * @return estimation of the shift after gaussian fit. + * + * Possible cpl-error-code set in this function: + * - CPL_ERROR_NULL_INPUT: s1 or s2 is NULL; + * - CPL_ERROR_INCOMPATIBLE_INPUT: if wavelengths are not uniformly sampled, + * or if the two spectra are not compatible; + */ +/* ---------------------------------------------------------------------------*/ +hdrl_xcorrelation_result * +hdrl_spectrum1D_compute_shift_xcorrelation(const hdrl_spectrum1D * s1, + const hdrl_spectrum1D * s2, + cpl_size half_win, + const cpl_boolean normalize){ + + + cpl_ensure(s1 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(s2 != NULL, CPL_ERROR_NULL_INPUT, NULL); + + { + const hdrl_spectrum1D_wavelength wav1 = hdrl_spectrum1D_get_wavelength(s1); + const hdrl_spectrum1D_wavelength wav2 = hdrl_spectrum1D_get_wavelength(s2); + + cpl_ensure(hdrl_spectrum1D_are_spectra_compatible(&wav1, &wav2), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + } + + double bin = 0.0; + cpl_ensure(hdrl_spectrum1D_is_uniformly_sampled(s1, &bin), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_array * f1 = convert_to_sorted_array(s1); + cpl_array * f2 = convert_to_sorted_array(s2); + + hdrl_xcorrelation_result * to_ret = hdrl_compute_offset_gaussian(f2, f1, + half_win, normalize, bin, 0.0005); + + cpl_array_delete(f1); + cpl_array_delete(f2); + + return to_ret; +} + +/*Parameter used for the shift slope calculation*/ +typedef struct { + HDRL_PARAMETER_HEAD; + hdrl_data_t wguess; + hdrl_data_t range_wmin; + hdrl_data_t range_wmax; + hdrl_data_t fit_wmin; + hdrl_data_t fit_wmax; + hdrl_data_t fit_half_win; +} hdrl_spectrum1D_shift_parameter; + +static hdrl_parameter_typeobj +hdrl_shift_fit_parameters_type = { + HDRL_PARAMETER_SPECTRUM1D_SHIFT, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_spectrum1D_shift_parameter), /* obj_size */ +}; + +/* ---------------------------------------------------------------------------*/ +/** + * @brief The function create a hdrl_spectrum1D_shift_parameter to be used in + * hdrl_spectrum1D_compute_shift_fit. + * + * @param wguess Reference line wavelength position + * @param range_wmin Minimum of wavelength box for line fit + * @param range_wmax Maximum of wavelength box for line fit + * @param fit_wmin Minimum wavelength value used to fit line slope + * @param fit_wmax Maximum wavelength value used to fit line slope + * @param fit_half_win Half box where polynomial fit is performed + * @return the constructed hdrl_parameter. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * +hdrl_spectrum1D_shift_fit_parameter_create(const hdrl_data_t wguess, + const hdrl_data_t range_wmin, const hdrl_data_t range_wmax, + const hdrl_data_t fit_wmin, const hdrl_data_t fit_wmax, + const hdrl_data_t fit_half_win){ + + hdrl_spectrum1D_shift_parameter * p + = (hdrl_spectrum1D_shift_parameter *) + hdrl_parameter_new(&hdrl_shift_fit_parameters_type); + + p->fit_half_win = fit_half_win; + p->fit_wmax = fit_wmax; + p->fit_wmin = fit_wmin; + p->range_wmax = range_wmax; + p->range_wmin = range_wmin; + p->wguess = wguess; + + return (hdrl_parameter*) p; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief The function compute the shift due to radial velocity. If wguess is + * the reference line and wfound is its position in the obs spectrum, the function + * returns (wfound - wguess) / wguess. The algorithm generate a smoothed fit of the + * spectrum, between [range_wmin, range_wmax] but the wavelengths between [fit_wim, + * fit_wmax] are ignored when fitting. obs is then divided by the fitted spectrum. + * The ratio is then smoothed again via fitting inside the window [wguess - fit_half_win, + * wguess + fit_half_win]. The wavelength corresponding to the minimum value is wfound. + * + * @param obs The spectrum the shift has to be computed on + * @param par The shift parameter, see hdrl_spectrum1D_shift_fit_parameter_create + * + * @return (wfound - wguess) / wguess. + */ +/* ---------------------------------------------------------------------------*/ +hdrl_data_t +hdrl_spectrum1D_compute_shift_fit(const hdrl_spectrum1D * obs, + const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + cpl_ensure(hdrl_shift_fit_parameter_get_range_wmin(par) + < hdrl_shift_fit_parameter_get_range_wmax(par), CPL_ERROR_ILLEGAL_INPUT, 0.0); + + cpl_ensure(hdrl_shift_fit_parameter_get_fit_wmin(par) + < hdrl_shift_fit_parameter_get_fit_wmax(par), CPL_ERROR_ILLEGAL_INPUT, 0.0); + + cpl_ensure(hdrl_shift_fit_parameter_get_range_wmin(par) + < hdrl_shift_fit_parameter_get_fit_wmin(par), CPL_ERROR_ILLEGAL_INPUT, 0.0); + + cpl_ensure(hdrl_shift_fit_parameter_get_range_wmax(par) + > hdrl_shift_fit_parameter_get_fit_wmax(par), CPL_ERROR_ILLEGAL_INPUT, 0.0); + + cpl_bivector * win = get_win(hdrl_shift_fit_parameter_get_range_wmin(par), + hdrl_shift_fit_parameter_get_range_wmax(par)); + + hdrl_spectrum1D * obs_sel = hdrl_spectrum1D_select_wavelengths(obs, win, CPL_TRUE); + + { + const int degree = 4; + + hdrl_spectrum1D * obs_fitted = hdrl_spectrum1D_fit(obs_sel, degree, + hdrl_shift_fit_parameter_get_fit_wmin(par), + hdrl_shift_fit_parameter_get_fit_wmax(par)); + + cpl_ensure(obs_fitted != NULL, CPL_ERROR_ILLEGAL_OUTPUT, 0.0); + + hdrl_spectrum1D_div_spectrum(obs_sel, obs_fitted); + + hdrl_spectrum1D_add_scalar(obs_sel, (hdrl_value){2.0, 0.0}); + + hdrl_spectrum1D_delete(&obs_fitted); + } + + hdrl_data_t min_wlen = hdrl_spectrum1D_compute_min_fit(obs_sel, par); + + hdrl_spectrum1D_delete(&obs_sel); + cpl_bivector_delete(win); + const hdrl_data_t wguess = hdrl_shift_fit_parameter_get_wguess(par); + const hdrl_data_t offset = (min_wlen - wguess)/wguess; + return offset; +} + + +/*----------------------------------------------------------------------------- + Private Functions Implementation + -----------------------------------------------------------------------------*/ + +cpl_size convert_to_matrix_and_vector(cpl_matrix ** x, cpl_vector ** values, + const hdrl_spectrum1D * s){ + + *x = NULL; + *values = NULL; + + const cpl_size sz = hdrl_spectrum1D_get_size(s); + double * x_vals = cpl_calloc(sz, sizeof(double)); + double * p_values = cpl_calloc(sz, sizeof(double)); + + cpl_size real_sz = 0; + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + hdrl_data_t f = hdrl_spectrum1D_get_flux_value(s, i, &rej).data; + if(rej) continue; + hdrl_data_t w = hdrl_spectrum1D_get_wavelength_value(s, i, &rej); + x_vals[real_sz] = w; + p_values[real_sz] = f; + real_sz++; + } + + if(real_sz == 0){ + *values = NULL; + *x = NULL; + cpl_free(x_vals); + cpl_free(p_values); + return real_sz; + } + + *values = cpl_vector_wrap(real_sz, p_values); + *x = cpl_matrix_wrap(1, real_sz, x_vals); + return real_sz; +} + +static inline cpl_polynomial * +polynomial_fit_1d_create( + const hdrl_spectrum1D * s, + int degree) +{ + cpl_polynomial * fit1d = cpl_polynomial_new(1); + double rechisq = 0; + + cpl_size loc_deg=(cpl_size)degree; + cpl_matrix * samppos = NULL; + cpl_vector * values = NULL; + + const cpl_size x_size = convert_to_matrix_and_vector(&samppos, &values, s); + + cpl_ensure(x_size > 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + cpl_vector * fitresidual = cpl_vector_new(x_size); + + cpl_polynomial_fit(fit1d, samppos, NULL, values, NULL, + CPL_FALSE, NULL, &loc_deg); + cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL); + + if ( x_size > (degree + 1) ) { + cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit1d, + samppos, &rechisq); + cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL); + } + + cpl_matrix_delete(samppos); + cpl_vector_delete(fitresidual); + cpl_vector_delete(values); + return fit1d; +} + + +static inline hdrl_spectrum1D * +get_polyfit_for_slope(const int degree, const hdrl_spectrum1D * s, + const cpl_array * wlengths){ + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_get_scale(s); + + cpl_polynomial* pfit = polynomial_fit_1d_create(s, degree); + cpl_ensure(pfit != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + const cpl_size sz = cpl_array_get_size(wlengths); + cpl_image * new_flux = cpl_image_new(sz, 1, HDRL_TYPE_DATA); + for(cpl_size i = 0; i < sz; ++i){ + double v = cpl_polynomial_eval_1d( pfit, cpl_array_get(wlengths, i, NULL), NULL); + cpl_image_set(new_flux, i + 1, 1, v); + } + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create_error_free(new_flux, wlengths, scale); + + cpl_polynomial_delete(pfit); + cpl_image_delete(new_flux); + return to_ret; +} + +/* Fits obs with a polynomial of degree "degree". The wavelengths between wmin and wmax + * are ignored when building the fit. */ +static inline hdrl_spectrum1D * +hdrl_spectrum1D_fit( + const hdrl_spectrum1D * obs, const int degree, const hdrl_data_t wmin, + const hdrl_data_t wmax){ + + cpl_bivector * win = get_win(wmin, wmax); + + hdrl_spectrum1D * obs_sel = hdrl_spectrum1D_select_wavelengths(obs, win, CPL_FALSE); + + cpl_ensure(obs_sel != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + hdrl_spectrum1D * obs_fitted = get_polyfit_for_slope(degree, obs_sel, + hdrl_spectrum1D_get_wavelength(obs).wavelength); + + cpl_ensure(obs_fitted != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + cpl_bivector_delete(win); + hdrl_spectrum1D_delete(&obs_sel); + return obs_fitted; +} + +static inline hdrl_data_t +hdrl_spectrum1D_compute_min_fit(const hdrl_spectrum1D * s, + const hdrl_parameter * shift_par){ + + const hdrl_data_t wguess = hdrl_shift_fit_parameter_get_wguess(shift_par); + const hdrl_data_t fit_half_win = + hdrl_shift_fit_parameter_get_fit_half_win(shift_par); + cpl_bivector * win = get_win(wguess - fit_half_win, wguess + fit_half_win); + + hdrl_spectrum1D * s_core = + hdrl_spectrum1D_select_wavelengths(s, win, CPL_TRUE); + + hdrl_spectrum1D_wavelength waves = hdrl_spectrum1D_get_wavelength(s_core); + + hdrl_spectrum1D * s_resampled = + get_polyfit_for_slope(4, s_core, waves.wavelength); + + cpl_bivector_delete(win); + hdrl_spectrum1D_delete(&s_core); + + const hdrl_image * flux = hdrl_spectrum1D_get_flux(s_resampled); + cpl_size x = 0, y = 0; + cpl_image_get_minpos(hdrl_image_get_image_const(flux), &x, &y); + + const hdrl_data_t real_min = + hdrl_spectrum1D_get_wavelength_value(s_resampled, x - 1, NULL); + + hdrl_spectrum1D_delete(&s_resampled); + return real_min; +} + +static inline cpl_bivector * get_win(hdrl_data_t wmin, hdrl_data_t wmax){ + cpl_bivector * v = cpl_bivector_new(1); + + cpl_vector_set(cpl_bivector_get_x(v), 0, wmin); + cpl_vector_set(cpl_bivector_get_y(v), 0, wmax); + + return v; +} + +/* Converts the flux spectrum to an array of double. Rejected pixels are mapped + * to NAN. */ +static inline cpl_array * +convert_to_sorted_array(const hdrl_spectrum1D * s1){ + + const cpl_size sz = hdrl_spectrum1D_get_size(s1); + double * flx = cpl_calloc(sz, sizeof(double)); + double * wav = cpl_calloc(sz, sizeof(double)); + double * is_rej = cpl_calloc(sz, sizeof(double)); + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + flx[i] = hdrl_spectrum1D_get_flux_value(s1, i, &rej).data; + is_rej[i] = rej; + wav[i] = hdrl_spectrum1D_get_wavelength_value(s1, i, NULL); + } + + hdrl_sort_on_x(wav, flx, is_rej, sz, CPL_FALSE); + + cpl_free(wav); + + cpl_array * to_ret = cpl_array_wrap_double(flx, sz); + + for(cpl_size i = 0; i < sz; ++i){ + if(fabs(is_rej[i]) < 1e-4) continue; + + cpl_array_set_invalid(to_ret, i); + } + + cpl_free(is_rej); + + return to_ret; +} + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_fit_half_win(const hdrl_parameter * par){ + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_spectrum1D_shift_parameter * p = + (const hdrl_spectrum1D_shift_parameter *)par; + return p->fit_half_win; +} + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_fit_wmax(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_spectrum1D_shift_parameter * p = + (const hdrl_spectrum1D_shift_parameter *)par; + return p->fit_wmax; +} + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_fit_wmin(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_spectrum1D_shift_parameter * p = + (const hdrl_spectrum1D_shift_parameter *)par; + return p->fit_wmin; +} + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_range_wmin(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_spectrum1D_shift_parameter * p = + (const hdrl_spectrum1D_shift_parameter *)par; + return p->range_wmin; +} + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_range_wmax(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_spectrum1D_shift_parameter * p = + (const hdrl_spectrum1D_shift_parameter *)par; + return p->range_wmax; +} + +static inline hdrl_data_t +hdrl_shift_fit_parameter_get_wguess(const hdrl_parameter * par){ + + cpl_ensure(par != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(hdrl_parameter_get_parameter_enum(par) + == HDRL_PARAMETER_SPECTRUM1D_SHIFT, CPL_ERROR_ILLEGAL_INPUT, 0.0); + + const hdrl_spectrum1D_shift_parameter * p = + (const hdrl_spectrum1D_shift_parameter *)par; + return p->wguess; +} +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_shift.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_shift.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_spectrum_shift.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_spectrum_shift.h 2017-08-25 12:18:43.000000000 +0000 @@ -0,0 +1,59 @@ +/* $Id: hdrl_spectrum_shift.h,v 0.1 2017-06-06 13:23:28 msalmist Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2017 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: msalmist $ + * $Date: 2017-06-06 13:23:28 $ + * $Revision: 0.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_SPECTRUM_SHIFT_H +#define HDRL_SPECTRUM_SHIFT_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum.h" + +#include + +CPL_BEGIN_DECLS +/*----------------------------------------------------------------------------- + Functions + -----------------------------------------------------------------------------*/ +hdrl_xcorrelation_result * +hdrl_spectrum1D_compute_shift_xcorrelation(const hdrl_spectrum1D * s1, + const hdrl_spectrum1D * s2, + const cpl_size half_win, + const cpl_boolean normalize); +hdrl_parameter * +hdrl_spectrum1D_shift_fit_parameter_create(const hdrl_data_t wguess, const hdrl_data_t range_wmin, + const hdrl_data_t range_wmax, const hdrl_data_t fit_wmin, + const hdrl_data_t fit_wmax, const hdrl_data_t fit_half_win); + +hdrl_data_t +hdrl_spectrum1D_compute_shift_fit(const hdrl_spectrum1D * obs, + const hdrl_parameter * par); + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_strehl.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_strehl.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_strehl.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_strehl.c 2017-10-20 09:39:42.000000000 +0000 @@ -0,0 +1,1340 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ +/* for j1 */ +#define _XOPEN_SOURCE 600 + +#include "hdrl_strehl.h" +#include "hdrl_image.h" +#include "hdrl_types.h" +#include "hdrl_utils.h" + +#include +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + + +static hdrl_strehl_result bad_result = { + {NAN, NAN}, + NAN, NAN, + {NAN, NAN}, + {NAN, NAN}, + {NAN, NAN}, + NAN, + 0 +}; + +/** + * + * @defgroup hdrl_strehl Strehl Computation + * + * @brief + * Function to compute the Strehl ratio on an image. + * + * The most commonly used metrics for evaluating the AO correction is the Strehl + * ratio. The Strehl ratio is defined as the ratio of the peak image intensity + * from a point source compared to the maximum attainable intensity using an + * ideal optical system limited only by diffraction over the telescope aperture. + * The Strehl ratio is very frequently used to perform the quality control of + * the scientific data obtained with the AO assisted instrumentation. + * + * The calculation is performed by calling the top-level function + * hdrl_strehl_compute() and the parameters passed to this function can be + * created by calling hdrl_strehl_parameter_create(). + * + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + + +/*----------------------------------------------------------------------------- + Strehl parameters Definition + -----------------------------------------------------------------------------*/ + +/** @cond PRIVATE */ + +typedef struct { + HDRL_PARAMETER_HEAD; + double wavelength ; + double m1 ; + double m2 ; + double pixel_scale_x; + double pixel_scale_y; + double flux_radius; + double bkg_radius_low; + double bkg_radius_high; +} hdrl_strehl_parameter; + +/* parameter type */ +static hdrl_parameter_typeobj hdrl_strehl_parameter_type = { + HDRL_PARAMETER_STREHL, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_strehl_parameter), /* obj_size */ +}; + + + +/*----------------------------------------------------------------------------*/ +/** + * @internal + * @brief Verify basic correctness of the Strehl parameters + * @param param Strehl parameters + * @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code +hdrl_strehl_parameter_verify(const hdrl_parameter * param) +{ + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_strehl_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected Strehl parameter") ; + + const hdrl_strehl_parameter * param_loc = (const hdrl_strehl_parameter *)param ; + + cpl_error_ensure(param_loc->wavelength >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "wavelength must be >=0"); + cpl_error_ensure(param_loc->m1 >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "m1 radius must be >=0"); + cpl_error_ensure(param_loc->m2 >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "m2 radius must be >=0"); + cpl_error_ensure(param_loc->m1 > param_loc->m2, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "m1 radius must be larger than m2 radius"); + cpl_error_ensure(param_loc->pixel_scale_x >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "pixel_scale_x must be >=0"); + cpl_error_ensure(param_loc->pixel_scale_y >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "pixel_scale_y must be >=0"); + + cpl_error_ensure(param_loc->flux_radius >= 0, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "flux_radius must be >=0"); + + cpl_error_ensure(param_loc->m1 >= param_loc->m2, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, "m1 must be >=m2"); + if (param_loc->bkg_radius_low > 0) { + cpl_error_ensure(param_loc->bkg_radius_low >= param_loc->flux_radius, + CPL_ERROR_ILLEGAL_INPUT,return CPL_ERROR_ILLEGAL_INPUT, + "bkg_radius_low must be >=flux_radius"); + cpl_error_ensure(param_loc->bkg_radius_high > param_loc->bkg_radius_low, + CPL_ERROR_ILLEGAL_INPUT,return CPL_ERROR_ILLEGAL_INPUT, + "bkg_radius_high must be >bkg_radius_low"); + } + else { + cpl_error_ensure(param_loc->bkg_radius_high < 0, + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "bkg_radius_high must be < 0 if bkg_radius_low is < 0"); + } + + return CPL_ERROR_NONE ; + +} + +/** @endcond */ + +/*----------------------------------------------------------------------------*/ +/** + * @brief Creates Strehl Parameters object + * + * @param wavelength Nominal filter wavelength [m] + * @param m1_radius primary mirror radius [m] + * @param m2_radius obstruction radius [m] + * @param pixel_scale_x image X pixel scale in [arcsec] + * @param pixel_scale_y image Y pixel scale in [arcsec] + * @param flux_radius radius used to sum the flux [arcsec] + * @param bkg_radius_low radius used to determine the background [arcsec] + * @param bkg_radius_high radius used to determine the background [arcsec] + * + * @return The Strehl parameters object. + * It needs to be deallocated with hdrl_parameter_delete() + * @see hdrl_parameter_delete() + * @see hdrl_strehl_compute() + * The method creates a parameter to compute the Strehl + */ + +hdrl_parameter * hdrl_strehl_parameter_create(double wavelength, + double m1_radius, double m2_radius, + double pixel_scale_x, double pixel_scale_y, double flux_radius, + double bkg_radius_low, double bkg_radius_high) { + + + hdrl_strehl_parameter * p = (hdrl_strehl_parameter *) + hdrl_parameter_new(&hdrl_strehl_parameter_type); + + p->wavelength = wavelength ; + p->m1 = m1_radius; + p->m2 = m2_radius; + p->pixel_scale_x = pixel_scale_x; + p->pixel_scale_y = pixel_scale_y; + p->flux_radius = flux_radius; + p->bkg_radius_low = bkg_radius_low; + p->bkg_radius_high = bkg_radius_high; + + if (hdrl_strehl_parameter_verify((hdrl_parameter *)p)) { + cpl_free(p); + return NULL; + } + return (hdrl_parameter *)p; + +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Check that the parameter is a Strehl parameter + * @param self The parameter to check + * @return True or False + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_strehl_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_strehl_parameter_type); +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the wavelength in the Strehl parameter + * @param p The Strehl parameter + * @return The wavelength value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_wavelength( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->wavelength : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the primary mirror radius in the Strehl parameter + * @param p The Strehl parameter + * @return The primary mirror radius value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_m1( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->m1 : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the obstruction radius in the Strehl parameter + * @param p The Strehl parameter + * @return The obstruction radius value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_m2( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->m2 : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the image X pixel scale in the Strehl parameter + * @param p The Strehl parameter + * @return The image X pixel scale value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_pixel_scale_x( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->pixel_scale_x : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the image Y pixel scale in the Strehl parameter + * @param p The Strehl parameter + * @return The image Y pixel scale value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_pixel_scale_y( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->pixel_scale_y : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the total flux radius in the Strehl parameter + * @param p The Strehl parameter + * @return The total flux radius value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_flux_radius( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->flux_radius : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the background region internal radius in the Strehl parameter + * @param p The Strehl parameter + * @return The background region internal radius value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_bkg_radius_low( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->bkg_radius_low : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Access the background region external radius in the Strehl parameter + * @param p The Strehl parameter + * @return The background region external radius value + */ +/*----------------------------------------------------------------------------*/ +double hdrl_strehl_parameter_get_bkg_radius_high( + const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1.0); + return p != NULL ? ((const hdrl_strehl_parameter *)p)->bkg_radius_high : 0.; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Create parameter list for the Strehl computation + * @param base_context base context of parameter (e.g. recipe name) + * @param prefix prefix of parameter, may be an empty string + * @param par hdrl_parameter defining the defaults + * @see hdrl_strehl_parameter_create() + * + * + * Creates a parameter list with the Strehl parameters: + * - base_context.prefix.wavelength + * - base_context.prefix.m1 + * - base_context.prefix.m2 + * - base_context.prefix.pixel-scale-x + * - base_context.prefix.pixel-scale-y + * - base_context.prefix.flux-radius + * - base_context.prefix.bkg-radius-low + * - base_context.prefix.bkg-radius-high + * + * The CLI aliases omit the base_context. + */ +/*----------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_strehl_parameter_create_parlist( + const char *base_context, + const char *prefix, + hdrl_parameter *par) +{ + + cpl_ensure(prefix && base_context && par, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_strehl_parameter_check(par), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist *parlist = cpl_parameterlist_new(); + + /* --prefix.wavelength */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "wavelength", base_context, + "Wavelength [m].", CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_wavelength(par)); + + /* --prefix.m1 */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "m1", base_context, + "Telescope radius [m].", CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_m1(par)); + + /* --prefix.m2 */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "m2", base_context, + "Telescope obstruction radius [m].", CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_m2(par)); + + /* --prefix.pixscale_x */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "pixel-scale-x", base_context, + "Detector X pixel scale on sky [arcsec].", + CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_pixel_scale_x(par)); + + /* --prefix.pixscale_y */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "pixel-scale-y", base_context, + "Detector Y pixel scale on sky [arcsec].", + CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_pixel_scale_y(par)); + + /* --prefix.flux_radius */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "flux-radius", base_context, + "PSF Flux integration radius [arcsec].", + CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_flux_radius(par)); + + /* --prefix.bkg_radius_low_def */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "bkg-radius-low", base_context, + "PSF background inner radii [arcsec].", + CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_bkg_radius_low(par)); + + /* --prefix.bkg_radius_high_def */ + hdrl_setup_vparameter(parlist, prefix, ".", "", "bkg-radius-high", base_context, + "PSF background outer radius [arcsec].", + CPL_TYPE_DOUBLE, + hdrl_strehl_parameter_get_bkg_radius_high(par)); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/*----------------------------------------------------------------------------*/ +/** + * @brief Parse parameter list to create input parameters for the Strehl + * @param parlist parameter list to parse + * @param prefix prefix of parameter name + * @return Input parameters for the Strehl computation + * + * Reads a parameter list in order to create Strehl parameters. + * + * Expects a parameter list containing: + * - base_context.prefix.wavelength + * - base_context.prefix.m1 + * - base_context.prefix.m2 + * - base_context.prefix.pixel-scale-x + * - base_context.prefix.pixel-scale-y + * - base_context.prefix.flux-radius + * - base_context.prefix.bkg-radius-low + * - base_context.prefix.bkg-radius-high + * + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_strehl_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix) +{ + cpl_ensure(prefix && parlist, CPL_ERROR_NULL_INPUT, NULL); + char * name; + const cpl_parameter * par; + double wavelength, m1, m2, pixel_scale_x, pixel_scale_y, + flux_radius, bkg_radius_low,bkg_radius_high; + + + /* --wavelength */ + name = hdrl_join_string(".", 2, prefix, "wavelength"); + par=cpl_parameterlist_find_const(parlist, name); + wavelength = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --m1 */ + name = hdrl_join_string(".", 2, prefix, "m1"); + par=cpl_parameterlist_find_const(parlist, name); + m1 = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --m2 */ + name = hdrl_join_string(".", 2, prefix, "m2"); + par=cpl_parameterlist_find_const(parlist, name); + m2 = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --pixel_scale_x */ + name = hdrl_join_string(".", 2, prefix, "pixel-scale-x"); + par=cpl_parameterlist_find_const(parlist, name); + pixel_scale_x = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --pixel_scale_y */ + name = hdrl_join_string(".", 2, prefix, "pixel-scale-y"); + par=cpl_parameterlist_find_const(parlist, name); + pixel_scale_y = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --flux_radius */ + name = hdrl_join_string(".", 2, prefix, "flux-radius"); + par=cpl_parameterlist_find_const(parlist, name); + flux_radius = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --bkg_radius_low */ + name = hdrl_join_string(".", 2, prefix, "bkg-radius-low"); + par=cpl_parameterlist_find_const(parlist, name); + bkg_radius_low = cpl_parameter_get_double(par); + cpl_free(name) ; + + /* --bkg_radius_high */ + name = hdrl_join_string(".", 2, prefix, "bkg-radius-high"); + par=cpl_parameterlist_find_const(parlist, name); + bkg_radius_high = cpl_parameter_get_double(par); + cpl_free(name) ; + + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist with prefix %s", prefix); + return NULL; + } else { + return hdrl_strehl_parameter_create(wavelength, m1,m2, + pixel_scale_x, pixel_scale_y, + flux_radius, bkg_radius_low, bkg_radius_high) ; + } + +} + + +/** @cond PRIVATE */ + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief mask where mask is valid + * @param himg hdrl image + * @param mask mask defining where to find max + * @return max and its error + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_value +hdrl_image_max_where(const hdrl_image * himg, cpl_mask * mask) +{ + hdrl_image * tmpimg = hdrl_image_duplicate(himg); + cpl_size px, py; + hdrl_value mx; + hdrl_image_reject_from_mask(tmpimg, mask); + cpl_image_get_maxpos(hdrl_image_get_image(tmpimg), &px, &py); + mx = hdrl_image_get_pixel(tmpimg, px, py, NULL); + hdrl_image_delete(tmpimg); + return mx; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief sum where mask is valid + * @param himg hdrl image + * @param mask mask defining where to sum + * @return sum and its error + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_value +hdrl_image_sum_where(const hdrl_image * himg, cpl_mask * mask) +{ + hdrl_image * tmpimg = hdrl_image_duplicate(himg); + hdrl_value flux; + hdrl_image_reject_from_mask(tmpimg, mask); + flux = hdrl_image_get_sum(tmpimg); + hdrl_image_delete(tmpimg); + return flux; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief median where mask is valid + * @param himg hdrl image + * @param mask mask defining where to sum + * @return sum and its error + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_value +hdrl_image_median_where(const hdrl_image * himg, cpl_mask * mask) +{ + hdrl_image * tmpimg = hdrl_image_duplicate(himg); + hdrl_value flux; + hdrl_image_reject_from_mask(tmpimg, mask); + flux = hdrl_image_get_median(tmpimg); + hdrl_image_delete(tmpimg); + return flux; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief stdev where mask is valid + * @param himg hdrl image + * @param mask mask defining where to compute + * @return computed standard deviation + */ +/* ---------------------------------------------------------------------------*/ +static double +hdrl_image_stdev_where(const hdrl_image * himg, cpl_mask * mask) +{ + hdrl_image * tmpimg = hdrl_image_duplicate(himg); + double mad; + hdrl_image_reject_from_mask(tmpimg, mask); + cpl_image_get_mad(hdrl_image_get_image_const(tmpimg), &mad); + hdrl_image_delete(tmpimg); + return mad * CPL_MATH_STD_MAD; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief compute obstructed Airy disk + * + * @param lam wavelength [m] + * @param m1 radius of primary mirror [m] + * @param m2 radius of secondary mirror [m] + * @param pixscale_x pixel scale in x direction [arcseconds] + * @param pixscale_y pixel scale in y direction [arcseconds] + * @param cx position of center in x direction (FITS) [pixel] + * @param cy position of center in y direction (FITS) [pixel] + * @param nx size of image in x direction [pixel] + * @param ny size of image in y direction [pixel] + * + * Computes an obstructed Airy for one wavelength from following formula: + * + * \f$ + * I(r) = \frac{1}{1 - e^2} \left(\frac{2 j_1(r)}{r} - \frac{2 e j_1(er)}{r}\right)^2 + * \f$ + * with: + * \f$ + * e = \frac{m_2}{m_2} + * \; + * r = k m_1 \sin{\theta} = \frac{2 \pi m_1}{\lambda} \sqrt{x^2 + y^2} + * \f$ + * See Wikipedia. + * + * The parameters cx and cy define the center of the Airy disk. + * E.g. a value of nx // 2 means the disk will be centered exactly at the + * middle of the central pixel while a value of nx // 2 - 0.5 means the peak of + * the disk will be at the origin and the flux evenly distributed among the + * four neighboring pixels. + */ +/* ---------------------------------------------------------------------------*/ +static cpl_image * +compute_psf(double lam, double m1, double m2, + double pixscale_x, double pixscale_y, + double cx, double cy, + size_t nx, size_t ny) +{ + cpl_image * psf = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + double * data = cpl_image_get_data(psf); + double e = m2 / m1; + double as_2_rad = CPL_MATH_2PI / (360. * 3600); + /* inclusive linear space with pixel center at the middle. integer cx and cy + * will result in a psf exactly centered around the middle of the central + * pixel, cx/cy are in fits convention [1,nx/ny] with pixel origin in the + * middle */ + double centerx = (-(nx / 2.) + cx - 1 + 0.5) * pixscale_x; + double centery = (-(ny / 2.) + cy - 1 + 0.5) * pixscale_y; + double xhigh = ((nx - 1) * pixscale_x / 2) - centerx; + double yhigh = ((ny - 1) * pixscale_y / 2) - centery; + double xlow = -((nx - 1) * pixscale_x / 2) - centerx; + double ylow = -((ny - 1) * pixscale_y / 2) - centery; + double step_x = (xhigh - xlow) / (nx - 1); + double step_y = (yhigh - ylow) / (ny - 1); + + HDRL_OMP(omp parallel for) + for (size_t iy = 0; iy < ny; iy++) { + double y = iy == ny - 1 ? yhigh : ylow + iy * step_y; + for (size_t ix = 0; ix < nx; ix++) { + double x = ix == nx - 1 ? xhigh : xlow + ix * step_x; + double r = sqrt(x*x + y*y) * as_2_rad * CPL_MATH_2PI * m1 / lam; + if (r == 0.) { + data[iy * nx + ix] = 1.; + } + else { + double airy = (2 * j1(r) / r - 2 * e * j1(e * r) / r); + double c = (1 - e * e); + data[iy * nx + ix] = 1 / (c * c) * airy * airy; + } + } + } + return psf; +} + +/*----------------------------------------------------------------------------*/ +/** + * @internal + * @brief Find the aperture(s) with the greatest flux + * @param self The aperture object + * @param ind The aperture-indices in order of decreasing flux + * @param nfind Number of indices to find + * @return CPL_ERROR_NONE or the relevant _cpl_error_code_ on error + * + * nfind must be at least 1 and at most the size of the aperture object. + * + * The ind array must be able to hold (at least) nfind integers. + * On success the first nfind elements of ind point to indices of the + * aperture object. + * + * To find the single ind of the aperture with the maximum flux use simply: + * int ind; + * apertures_find_max_flux(self, &ind, 1); + * + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code apertures_find_max_flux(const cpl_apertures * self, + int * ind, int nfind) +{ + const int nsize = cpl_apertures_get_size(self); + int ifind; + + + cpl_ensure_code(nsize > 0, cpl_error_get_code()); + cpl_ensure_code(ind, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(nfind > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nfind <= nsize, CPL_ERROR_ILLEGAL_INPUT); + + for (ifind=0; ifind < nfind; ifind++) { + double maxflux = -1; + int maxind = -1; + int i; + for (i=1; i <= nsize; i++) { + int k; + + /* The flux has to be the highest among those not already found */ + for (k=0; k < ifind; k++) if (ind[k] == i) break; + + if (k == ifind) { + /* i has not been inserted into ind */ + const double flux = cpl_apertures_get_flux(self, i); + + if (maxind < 0 || flux > maxflux) { + maxind = i; + maxflux = flux; + } + } + } + ind[ifind] = maxind; + } + + return CPL_ERROR_NONE; + +} + +/*----------------------------------------------------------------------------*/ +/** + * @internal + * @brief Find the peak flux, peak sum and position of a Gaussian + * @param self Image to process + * @param sigma The initial detection level [ADU] + * @param pxpos On success, the refined X-position [pixel] + * @param pypos On success, the refined Y-position [pixel] + * @param ppeak On success, the refined peak flux [ADU] + * @return CPL_ERROR_NONE or the relevant CPL error code on error + * + * The routine initially determines the approximate position and flux value of + * the PSF with a robust Gaussian fit: first are identified all sources that lie + * 5 sigmas above the median of the image, then is determined the position of + * the barycenter of the region with highest peak. Finally is performed the fit + * of a Gaussian centered on the found barycenter position. + * + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code +gaussian_maxpos(const cpl_image * self, + double sigma, + double * pxpos, + double * pypos, + double * ppeak) +{ + /* copied from irplib_strehl.c r163170 */ + const cpl_size nx = cpl_image_get_size_x(self); + const cpl_size ny = cpl_image_get_size_y(self); + int iretry = 3; /* Number retries with decreasing sigma */ + int ifluxapert = 0; + double med_dist; + const double median = cpl_image_get_median_dev(self, &med_dist); + cpl_mask * selection; + cpl_size nlabels = 0; + cpl_image * labels = NULL; + cpl_apertures * aperts; + cpl_size npixobj; + double objradius; + cpl_size winsize; + cpl_size xposmax, yposmax; + double xposcen, yposcen; + double valmax, valfit = -1.0; + cpl_array * gauss_parameters = NULL; + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_error_code code = CPL_ERROR_NONE; + + + cpl_ensure_code( sigma > 0.0, CPL_ERROR_ILLEGAL_INPUT); + + selection = cpl_mask_new(nx, ny); + + /* find aperture with signal larger than sigma * median deviation */ + for (; iretry > 0 && nlabels == 0; iretry--, sigma *= 0.5) { + + /* Compute the threshold */ + const double threshold = median + sigma * med_dist; + + + /* Select the pixel above the threshold */ + code = cpl_mask_threshold_image(selection, self, threshold, DBL_MAX, + CPL_BINARY_1); + + if (code) break; + + /* Labelise the thresholded selection */ + cpl_image_delete(labels); + labels = cpl_image_labelise_mask_create(selection, &nlabels); + } + sigma *= 2.0; /* reverse last iteration that found no labels */ + + cpl_mask_delete(selection); + + if (code) { + cpl_image_delete(labels); + return cpl_error_set_where(cpl_func); + } else if (nlabels == 0) { + cpl_image_delete(labels); + return cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); + } + + aperts = cpl_apertures_new_from_image(self, labels); + + /* Find the aperture with the greatest flux */ + code = apertures_find_max_flux(aperts, &ifluxapert, 1); + + if (code) { + cpl_apertures_delete(aperts); + cpl_image_delete(labels); + return cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); + } + + npixobj = cpl_apertures_get_npix(aperts, ifluxapert); + objradius = sqrt((double)npixobj * CPL_MATH_1_PI); + winsize = CX_MIN(CX_MIN(nx, ny), (3.0 * objradius)); + + xposmax = cpl_apertures_get_maxpos_x(aperts, ifluxapert); + yposmax = cpl_apertures_get_maxpos_y(aperts, ifluxapert); + xposcen = cpl_apertures_get_centroid_x(aperts, ifluxapert); + yposcen = cpl_apertures_get_centroid_y(aperts, ifluxapert); + valmax = cpl_apertures_get_max(aperts, ifluxapert); + + cpl_apertures_delete(aperts); + cpl_image_delete(labels); + + cpl_msg_debug(cpl_func, "Object radius at S/R=%g: %g (window-size=%u)", + sigma, objradius, (unsigned)winsize); + cpl_msg_debug(cpl_func, "Object-peak @ (%d, %d) = %g", (int)xposmax, + (int)yposmax, valmax); + + /* fit gaussian to get subpixel peak position */ + + gauss_parameters = cpl_array_new(7, CPL_TYPE_DOUBLE); + cpl_array_set_double(gauss_parameters, 0, median); + + code = cpl_fit_image_gaussian(self, NULL, xposmax, yposmax, + winsize, winsize, gauss_parameters, + NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL); + if (!code) { + const double M_x = cpl_array_get_double(gauss_parameters, 3, NULL); + const double M_y = cpl_array_get_double(gauss_parameters, 4, NULL); + + valfit = hcpl_gaussian_eval_2d(gauss_parameters, M_x, M_y); + + if (!cpl_errorstate_is_equal(prestate)) { + code = cpl_error_get_code(); + } else { + *pxpos = M_x; + *pypos = M_y; + *ppeak = valfit; + + cpl_msg_debug(cpl_func, "Gauss-fit @ (%g, %g) = %g", + M_x, M_y, valfit); + } + } + cpl_array_delete(gauss_parameters); + + if (code || valfit < valmax) { + cpl_errorstate_set(prestate); + *pxpos = xposcen; + *pypos = yposcen; + *ppeak = valmax; + } + + return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief create a disk mask + @param im Image to compute from + @param xpos the x position of the disk center [pixel, C indexing] + @param ypos the y position of the disk center [pixel, C indexing] + @param rad the radius [pixel] + @return a mask with valid pixels inside the disk + @note (xpos, ypos) and may be outside the image, if so then a sufficiently + small rad will cause no pixels to be encircled + */ +/*----------------------------------------------------------------------------*/ +static cpl_mask * +strehl_disk_mask(const cpl_image * im, + double xpos, + double ypos, + double rad) +{ + const intptr_t nx = cpl_image_get_size_x(im); + const intptr_t ny = cpl_image_get_size_y(im); + /* Round down */ + const intptr_t lx = (intptr_t)(xpos - rad); + const intptr_t ly = (intptr_t)(ypos - rad); + /* Round up */ + const intptr_t ux = (intptr_t)(xpos + rad) + 1; + const intptr_t uy = (intptr_t)(ypos + rad) + 1; + + const double sqr = rad * rad; + cpl_mask * m; + + + /* Check entries */ + cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(rad > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + m = cpl_mask_new(nx, ny); + + for (intptr_t j = CX_MAX(ly, 0); j < CX_MIN(uy, ny); j++) { + const double yj = (double)j - ypos; + for (intptr_t i = CX_MAX(lx, 0); i < CX_MIN(ux, nx); i++) { + const double xi = (double)i - xpos; + const double dist = yj * yj + xi * xi; + if (dist <= sqr) { + if (!cpl_image_is_rejected(im, i + 1, j + 1)) { + cpl_mask_set(m, i + 1, j + 1, CPL_BINARY_1); + } + } + } + } + cpl_mask_not(m); + + return m; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief rebin image + * @param img image to rebin, size must be a multiple of sampling + * @param sampling rebin factor + * @return rebinned image + */ +/* ---------------------------------------------------------------------------*/ +static inline cpl_image * hdrl_rebin(cpl_image * img, size_t sampling) +{ + cpl_size lnx = cpl_image_get_size_x(img); + cpl_size lny = cpl_image_get_size_y(img); + cpl_size nx = lnx / sampling; + cpl_size ny = lny / sampling; + cpl_image * n = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + double * ld = cpl_image_get_data_double(img); + double * nd = cpl_image_get_data_double(n); + for (size_t iy = 0; iy < (size_t)ny; iy++) { + for (size_t ix = 0; ix < (size_t)nx; ix++) { + for (size_t ly = 0; ly < sampling; ly++) { + for (size_t lx = 0; lx < sampling; lx++) { + nd[iy * nx + ix] += ld[((iy*sampling) + ly) * lnx + lx + (ix*sampling)]; + } + } + } + } + return n; +} +#if 0 +/* ---------------------------------------------------------------------------*/ +/** + * @brief compute encircled energy of psf + * @param lam wavelength + * @param m1 primary mirror radius + * @param m2 obstruction radius + * @param r integration radius + * + * + * \f[ + * EE(v_{0}) = \frac{1}{1 - \epsilon^2} \left(1 - J_{0}^{2}(v_{0}) - J_{1}^{2}(v_{0}) + * + \epsilon^{2} (1- J_{0}^{2}(v_{0}) - J_{1}^{2}(\epsilon v_{0})) + * -2\epsilon\int_{0}^{v_{0}} J_{1}(\epsilon v) \frac{2J_{1}(v)}{v}dv \right) + * \f] + * + * where + * \f$J_{1}\f$ is the Bessel function or order \f$0\f$, + * \f$J_{1}\f$ is the Bessel function or order \f$1\f$, + * \f$\epsilon = \frac{m_2}{m_2}\f$ is the telescope central obstruction + * (fraction of telescope diameter), + * v is the radial distance from Airy function center (2 * Nyquist/ units), and + * \f$v_{0}\f$ is the maximum radial distance from Airy function center for EE + * calculation (2 * Nyquist/ units). During \f$EE\f$ computation we neglect + * the integral term. + * + */ +/* ---------------------------------------------------------------------------*/ +static inline double +compute_psf_flux(double lam, double m1, double m2, double r) +{ + /* currently unused */ + double e = m2 / m1; + r *= CPL_MATH_2PI * m1 / lam; + double E = 1 - j0(r) * j0(r) - j1(r) * j1(r) + e*e * + (1 - j0(e*r)*j0(e*r) - j1(e*r)*j1(e*r)); + E *= 1 / (1 - e * e); + /* Note compared to analytical formula iof the encircled energy, here we + neglect the contribute from integral term: -2*e*integral(j1*j1*2/v dv) */ + return E; +} +#endif + +/* ---------------------------------------------------------------------------*/ +/** + * @internal + * @brief compute Strehl parameter + * @param himg background corrected image + * @param lam wavelength [m] + * @param m1_radius primary mirror radius [m] + * @param m2_radius obstruction radius [m] + * @param pixscale_x image X pixel scale in [arcsec] + * @param pixscale_y image Y pixel scale in [arcsec] + * @param flux_radius radius used to sum the flux [arcsec] + * + * @return an hdrl_value containing the computed Strehl value and its error + * or NAN in case of error. + * + * @note strehl function, assumes background corrected image with peak at + * peak_x/peak_y + * + * @note + * This function assumes that the input image is background corrected. + * + * Initially a synthetic PSF is generated with parameters: + * - base_context.prefix.wavelength + * - base_context.prefix.m1 + * - base_context.prefix.m2 + * - base_context.prefix.pixel-scale-x + * - base_context.prefix.pixel-scale-y + * and pixel scale upsampling factor 16. + * @see compute_psf() + * + * The synthetic PSF is shifted of an arbitrary value equal to 7 pixels + * (determined ad hoc) and then the synthetic PSF is down-sampled to the + * original PSF sampling. Then synthetic PSF is normalized dividing it by a + * value equal to the ratio of the synthetic PSF peak and the observed PSF peak + * values. + * + * Then the position and the peak of the PSF are determined by a robust fit of + * a 2D Gaussian. @see gaussian_maxpos() + * + * Then an approximate position of the maximum on the observed PSF standard + * is determined, later refined using the associated error (and bad pixel) + * information. This define the value of PSFo_peak + * + * Then is determined the observed PSF flux, PSFo_flux, within the ring centered + * on the peak and user set radius. This is used to compute the ratio + * Ro=PSFo_peak/PSFo_flux + * + * The same ratio is also determined similarly for the synthetic PSF. + * Rt=PSFt_peak/PSFt_flux + * + * Finally the strehl is computed as + * strehl=Ro/Rt + * + * along with its associated error: + * strehl_err=strehl*sqrt((peak_err/peak_val^2)+(flux_err/flux_val^2)) + * + */ + +static hdrl_strehl_result +compute_strehl2(const hdrl_image * himg, double lam, + double m1_radius, double m2_radius, + double pixscale_x, double pixscale_y, + double peak_x, double peak_y, + double radius_arcsec) +{ + const cpl_image * img = hdrl_image_get_image_const(himg); + double min_pscale = CX_MIN(pixscale_x, pixscale_y); + double radius_pix = (radius_arcsec / min_pscale); + /* could be shrunk for better performance as flux beyond a few rings is negligible + * using analytic encircled energy would probably also work */ + cpl_size wins = 2 * radius_pix; + cpl_msg_debug(cpl_func, "strehl psf window size %d", (int)wins); + double smallx = peak_x - (floor(peak_x) - wins/2); + double smally = peak_y - (floor(peak_y) - wins/2); + /* sample psf on larger grid for a primitive integration of the flux */ + size_t sampling = 16; + intptr_t nnx = wins * sampling; + intptr_t nny = wins * sampling; + cpl_image * lpsf = compute_psf(lam, m1_radius, m2_radius, + pixscale_x / sampling, pixscale_y / sampling, + smallx*sampling,smally*sampling, + nnx, nny); + /* Note: o is a hard-coded offset to get the peak in same position as in data + * after down-sampling, 7 seems to work reasonably well for sampling 16 */ + int o = 7; + cpl_image * epsf = cpl_image_extract(lpsf, 1 + o, 1 + o, nnx - o, nny - o); + cpl_image * psf = hdrl_rebin(epsf, sampling); + cpl_image_delete(epsf); + cpl_image_delete(lpsf); + /* normalize for easier comparison, not required */ + cpl_image_divide_scalar(psf, cpl_image_get_max(psf)/cpl_image_get_max(img)); + cpl_msg_debug(cpl_func, "position/peak of data: %g %g", peak_x, peak_y); + { + /* fit not required, just for debugging */ + double xposfit, yposfit, peak; + gaussian_maxpos(psf, 5, &xposfit, &yposfit, &peak); + cpl_msg_debug(cpl_func, "position/peak of psf: %g %g", xposfit, yposfit); + } + + /* computes ratio peak/flux over the observed PSF standard */ + cpl_mask * im = strehl_disk_mask(img, peak_x, peak_y, radius_pix); + hdrl_value ipeak = hdrl_image_max_where(himg, im); + cpl_msg_debug(cpl_func, "Computing flux on %d pixel radius, total pixels %ld", + (int)(radius_pix), + (long)(cpl_mask_get_size_x(im) * cpl_mask_get_size_y(im) - + cpl_mask_count(im))); + hdrl_value iflux = hdrl_image_sum_where(himg, im); + cpl_msg_debug(cpl_func, "flux ring/total data: %g (%g) %g", iflux.data, + iflux.error, cpl_image_get_flux(img)); + cpl_mask_delete(im); + + double ratio_img = ipeak.data / iflux.data; + + /* computes ratio peak/flux over the synthetic PSF */ + double ppeak = cpl_image_get_max(psf); + cpl_mask * pm = + strehl_disk_mask(psf, wins / 2 - 1, wins / 2 - 1, radius_pix); + hdrl_image * tmpimg = hdrl_image_create(psf, NULL); + hdrl_value pflux = hdrl_image_sum_where(tmpimg, pm); + hdrl_image_delete(tmpimg); + cpl_msg_debug(cpl_func, "flux ring/total psf: %g %g", pflux.data, + cpl_image_get_flux(psf)); + cpl_mask_delete(pm); + + double ratio_psf = ppeak / pflux.data; + + cpl_msg_debug(cpl_func, "data peak,flux,ratio: %g %g: %g", + ipeak.data, iflux.data, ratio_img); + cpl_msg_debug(cpl_func, "psf peak,flux,ratio: %g %g: %g", + ppeak, pflux.data, ratio_psf); + + double strehl = ratio_img / ratio_psf; + double strehl_err = strehl * + sqrt(ipeak.error * ipeak.error / (ipeak.data * ipeak.data) + + iflux.error * iflux.error / (iflux.data * iflux.data)); + + cpl_msg_debug(cpl_func, "Strehl ratio %g +/- %g", strehl, strehl_err); + cpl_image_delete(psf); + + hdrl_strehl_result r; + r.strehl_value = (hdrl_value){strehl, strehl_err}; + r.star_peak = ipeak; + r.star_flux = iflux; + r.star_background = (hdrl_value){0, 0}; + /* TODO: + * error on negative flux, error on disk max position != fit position */ + return r; +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief compute image Strehl + * @param himg background corrected image + * @param lam wavelength [m] + * @param m1_radius primary mirror radius [m] + * @param m2_radius obstruction radius [m] + * @param pixscale_x image X pixel scale in [arcsec] + * @param pixscale_y image Y pixel scale in [arcsec] + * @param flux_radius radius used to sum the flux [arcsec] + * @param bkg_radius_low_def radius used to determine the background [arcsec] + * @param bkg_radius_high_def radius used to determine the background [arcsec] + * + * @return an hdrl_strehl_result containing the computed Strehl value and its error + * or NAN in case of error. + * + * @doc + * This function assumes that the input image is pre-processed to remove + * instrument signatures (flag bad pixels, etc.) and correct for the natural + * noise sources (sky background, etc.). Bad pixels are interpolated. + * + * The routine initially determines the approximate position and flux value of + * the PSF with a Gaussian fit. + * @see gaussian_maxpos() + * + * If the user sets the parameters bkg_radius_low, bkg_radius_high to -1, the + * routine assumes that the input image has zero background level. + * Else if the user set the parameters bkg_radius_low, bkg_radius_high to proper + * values the routine measure the background in the corresponding annular + * region and subtract it. This second option is recommended. + * + * Then the strehl ratio and its associated error are computed. + * @see compute_streh2() + * + */ +/* ---------------------------------------------------------------------------*/ +static hdrl_strehl_result +compute_strehl(const hdrl_image * himg_, double lam, + double m1_radius, double m2_radius, + double pixscale_x, double pixscale_y, double flux_radius, + double bkg_radius_low, double bkg_radius_high) +{ + hdrl_image * himg = hdrl_image_duplicate(himg_); + double xposfit, yposfit, peak; + double min_pscale = CX_MIN(pixscale_x, pixscale_y); + const cpl_image * img = hdrl_image_get_image_const(himg); + /* interpolate bad pixels, */ + if (hdrl_image_count_rejected(himg) != 0) { + cpl_msg_warning(cpl_func, + "%zu bad pixels in strehl input, interpolating.", + (size_t)hdrl_image_count_rejected(himg) ); + cpl_detector_interpolate_rejected(hdrl_image_get_image(himg)); + /* should have error propagation here .. */ + cpl_detector_interpolate_rejected(hdrl_image_get_error(himg)); + } + + if (gaussian_maxpos(img, 5, &xposfit, &yposfit, &peak) != CPL_ERROR_NONE) { + goto error; + } + if (peak <= 0) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "detected peak of star smaller than zero, " + "gaussian fit likely failed to fit the star"); + goto error; + } + hdrl_value bkg = {0, 0}; + double comp_bkg_error = -1; + size_t nbkg_pix = 0; + if ((bkg_radius_low < 0 && bkg_radius_high >= 0) || + (bkg_radius_low >= 0 && bkg_radius_high < 0)) { + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "background radius parameters must be larger " + "zero or both negative"); + goto error; + } + else if (bkg_radius_low >= 0 && bkg_radius_high >= 0) { + if (bkg_radius_low >= bkg_radius_high) { + cpl_error_set_message(cpl_func, CPL_ERROR_INCOMPATIBLE_INPUT, + "low background radius parameters must be smaller " + "than large background radius"); + goto error; + } + /* compute mask of background ring */ + cpl_mask * high = strehl_disk_mask(img, xposfit, yposfit, + bkg_radius_high / min_pscale); + cpl_mask * low = strehl_disk_mask(img, xposfit, yposfit, + bkg_radius_low / min_pscale); + cpl_mask_xor(low, high); + nbkg_pix = cpl_mask_count(low); + if (nbkg_pix == 0) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "No valid pixels in background"); + cpl_mask_delete(low); + cpl_mask_delete(high); + goto error; + } + + cpl_mask_not(low); + bkg = hdrl_image_median_where(himg, low); + comp_bkg_error = hdrl_image_stdev_where(himg, low) / sqrt(nbkg_pix); + /* expected difference sqrt(pi / 2) due to median */ + cpl_msg_debug(cpl_func, "Median estimated background: %g +- %g " + "(computed error %g)", bkg.data, bkg.error, + comp_bkg_error); + cpl_mask_delete(low); + cpl_mask_delete(high); + + hdrl_image_sub_scalar(himg, bkg); + } + + hdrl_strehl_result r = compute_strehl2(himg, lam, m1_radius, m2_radius, + pixscale_x, pixscale_y, xposfit, yposfit, + flux_radius); + hdrl_image_delete(himg); + r.star_background = bkg; + r.star_x = xposfit; + r.star_y = yposfit; + r.computed_background_error = comp_bkg_error; + r.nbackground_pixels = nbkg_pix; + return r; + +error: + hdrl_image_delete(himg); + return bad_result; +} +/** @endcond */ + +/* TODO: missing doxygen, add more comments */ +/* ---------------------------------------------------------------------------*/ +/** + * @brief This function computes the Strehl ratio. + * @param himg input hdrl image + * @param params input hdrl parameters + * + * @see hdrl_strehl_parameter_create() + * + * The raw image is assumed to be pre-processed to remove the instrument + * signatures (bad pixels, etc.) and the natural noise sources (sky background, + * etc.). Nethertheless this function allows also the user to correct a residual + * background by setting the parameters \e bkg_radius_low, \e bkg_radius_high. + * The PSF is identified and its integrated flux (controlled by the parameter + * \e flux_radius) is normalized to 1. The + * PSF baricenter is computed and used to generate the ideal PSF (with + * integrated flux normalized to 1) which takes into account the telescope pupil + * characteristics (radius \e m1, central obstruction, \e m2, .…), the + * wavelength \e wavelength, at which the image has been obtained and the + * related pixel scale (\e pixel_scale_x, \e pixel_scale_y,). Finally the Strehl + * ratio is computed dividing the maximum intensity of the image PSF by the + * maximum intensity of the ideal PSF and the associated error is also computed. + * + */ +/* ---------------------------------------------------------------------------*/ +hdrl_strehl_result +hdrl_strehl_compute(const hdrl_image * himg, hdrl_parameter* params) +{ + hdrl_strehl_result r; + /* Check Entries */ + + cpl_error_ensure(himg && params, CPL_ERROR_NULL_INPUT, + return bad_result, + "NULL input"); + if (hdrl_strehl_parameter_verify(params) != CPL_ERROR_NONE) { + return bad_result; + } + + /* Local Usage Parameters */ + const hdrl_strehl_parameter * p_loc = (hdrl_strehl_parameter *)params ; + + r = compute_strehl(himg,p_loc->wavelength, p_loc->m1, p_loc->m2, + p_loc->pixel_scale_x, p_loc->pixel_scale_y, + p_loc->flux_radius, p_loc->bkg_radius_low, + p_loc->bkg_radius_high); + return r; +} + +/**@}*/ + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_strehl.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_strehl.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_strehl.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_strehl.h 2017-11-29 09:48:40.000000000 +0000 @@ -0,0 +1,93 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifndef HDRL_STREHL_H +#define HDRL_STREHL_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_types.h" +#include "hdrl_image.h" +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +typedef struct { + /* computed strehl value and its propagated error */ + hdrl_value strehl_value; + /* computed x and y position of the star peak */ + double star_x, star_y; + /* star peak and its propagated error */ + hdrl_value star_peak; + /* star flux and its propagated error */ + hdrl_value star_flux; + /* star background and its propagated error */ + hdrl_value star_background; + /* star background error estimated from image + * on normal data sqrt(pi / 2) larger that star_background error as it is + * estimated via a median */ + double computed_background_error; + /* number of pixels used for background estimation */ + size_t nbackground_pixels; +} hdrl_strehl_result; + +hdrl_parameter * hdrl_strehl_parameter_create(double wavelength, + double m1_radius, double m2_radius, + double pixel_scale_x, double pixel_scale_y, double flux_radius, + double bkg_radius_low, double bkg_radius_high); + +cpl_parameterlist * hdrl_strehl_parameter_create_parlist( + const char * base_context, + const char * prefix, + hdrl_parameter * par); + +hdrl_parameter * hdrl_strehl_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * prefix); + +hdrl_strehl_result +hdrl_strehl_compute(const hdrl_image * himg, hdrl_parameter* params); + +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE + +cpl_boolean hdrl_strehl_parameter_check(const hdrl_parameter *); + +double hdrl_strehl_parameter_get_wavelength(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_m1(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_m2(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_pixel_scale_x(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_pixel_scale_y(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_flux_radius(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_bkg_radius_low(const hdrl_parameter * p); +double hdrl_strehl_parameter_get_bkg_radius_high(const hdrl_parameter * p); + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_test.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_test.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_test.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_test.h 2013-11-04 14:28:44.000000000 +0000 @@ -0,0 +1,54 @@ +/* $Id: hdrl_test.h,v 1.1 2013-10-22 08:26:11 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-22 08:26:11 $ + * $Revision: 1.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_TEST_H +#define HDRL_TEST_H + +#include "hdrl_image.h" +#include "hdrl_types.h" + +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Macros + -----------------------------------------------------------------------------*/ + +#define hdrl_test_image_abs(himg1, himg2, tol) \ +{ \ + cpl_test_image_abs(hdrl_image_get_image_const(himg1), \ + hdrl_image_get_image_const(himg2), tol * \ + HDRL_EPS_ERROR / HDRL_EPS_DATA); \ + cpl_test_image_abs(hdrl_image_get_error_const(himg1), \ + hdrl_image_get_error_const(himg2), tol * \ + HDRL_EPS_ERROR / HDRL_EPS_DATA); \ +} + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_types.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_types.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_types.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_types.h 2014-08-06 14:12:19.000000000 +0000 @@ -0,0 +1,82 @@ +/* $Id: hdrl_types.h,v 1.2 2013-10-11 13:46:00 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-11 13:46:00 $ + * $Revision: 1.2 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_TYPES_H +#define HDRL_TYPES_H + +#include /* for epsilon */ +#include /* for size_t */ + +/*----------------------------------------------------------------------------- + Generic types + -----------------------------------------------------------------------------*/ + +typedef void * (hdrl_alloc)(size_t); +typedef void (hdrl_free)(void *); + +/* basic type for bit mask values, e.g. bad pixel classifications */ +typedef unsigned int hdrl_bitmask_t; + +#ifndef HDRL_SIZEOF_DATA +#define HDRL_SIZEOF_DATA 8 +#endif +#ifndef HDRL_SIZEOF_ERROR +#define HDRL_SIZEOF_ERROR 8 +#endif + +/* makes little sense and causes problems when error propagation + * mixes the two types (mul/div) */ +#if HDRL_SIZEOF_ERROR > HDRL_SIZEOF_DATA +#error HDRL_SIZEOF_ERROR must not be larger than HDRL_SIZEOF_DATA +#endif + +#if HDRL_SIZEOF_DATA == 4 +typedef float hdrl_data_t; +#define HDRL_TYPE_DATA CPL_TYPE_FLOAT +#define HDRL_EPS_DATA FLT_EPSILON +#else +typedef double hdrl_data_t; +#define HDRL_TYPE_DATA CPL_TYPE_DOUBLE +#define HDRL_EPS_DATA DBL_EPSILON +#endif + +#if HDRL_SIZEOF_ERROR == 4 +typedef float hdrl_error_t; +#define HDRL_TYPE_ERROR CPL_TYPE_FLOAT +#define HDRL_EPS_ERROR FLT_EPSILON +#else +typedef double hdrl_error_t; +#define HDRL_TYPE_ERROR CPL_TYPE_DOUBLE +#define HDRL_EPS_ERROR DBL_EPSILON +#endif + +typedef struct { + hdrl_data_t data; + hdrl_error_t error; +} hdrl_value; + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_utils.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_utils.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_utils.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_utils.c 2017-10-13 09:59:32.000000000 +0000 @@ -0,0 +1,2004 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes +-----------------------------------------------------------------------------*/ + +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 500 /* posix 2001, mkstemp */ +#endif + +#include "hdrl_utils.h" +#include "hdrl_types.h" +#include "hdrl_elemop.h" +#include "hdrl_prototyping.h" +#include "hdrl_imagelist.h" +#include +#include +#include +#include +#include +#include +#include + +/*----------------------------------------------------------------------------- + Static + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_utils General Utility Functions + + This module contain various utilities functions that might be used in several + of the HDRL modules. + */ +/*----------------------------------------------------------------------------*/ + +/**@{*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Get the pipeline copyright and license + @return The copyright and license string + + The function returns a pointer to the statically allocated license string. + This string should not be modified using the returned pointer. + */ +/*----------------------------------------------------------------------------*/ +const char * hdrl_get_license(void) +{ + static const char * hdrl_license = + "This file is part of the HDRL Instrument Pipeline\n" + "Copyright (C) 2012,2013 European Southern Observatory\n" + "\n" + "This program is free software; you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation; either version 2 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program; if not, write to the Free Software\n" + "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, \n" + "MA 02110-1301 USA"; + + return hdrl_license; +} + +/*----------------------------------------------------------------------------- + Rectangular Region Parameters Definition + -----------------------------------------------------------------------------*/ + +/** @cond PRIVATE */ +typedef struct { + HDRL_PARAMETER_HEAD; + cpl_size llx ; + cpl_size lly ; + cpl_size urx ; + cpl_size ury ; +} hdrl_rect_region_parameter; + +/* Parameter type */ +static hdrl_parameter_typeobj hdrl_rect_region_parameter_type = { + HDRL_PARAMETER_RECT_REGION, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_rect_region_parameter), /* obj_size */ +}; + +/** @endcond */ + +/*----------------------------------------------------------------------------*/ +/** + @brief Creates Rect Region Parameters object + @param llx + @param lly + @param urx + @param ury + @return the Rect Region parameters + */ +/*----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_rect_region_parameter_create( + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) +{ + hdrl_rect_region_parameter * p = (hdrl_rect_region_parameter *) + hdrl_parameter_new(&hdrl_rect_region_parameter_type); + p->llx = llx ; + p->lly = lly ; + p->urx = urx ; + p->ury = ury ; + return (hdrl_parameter *)p; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Update Rect Region Parameters object + @param rect_region The region to update + @param llx + @param lly + @param urx + @param ury + @return the error code in case of error or CPL_ERROR_NONE + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_rect_region_parameter_update( + hdrl_parameter * rect_region, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) +{ + hdrl_rect_region_parameter * p = (hdrl_rect_region_parameter *)rect_region ; + p->llx = llx ; + p->lly = lly ; + p->urx = urx ; + p->ury = ury ; + return hdrl_rect_region_parameter_verify(rect_region, -1, -1); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check that the parameter is hdrl_rect_region parameter + @return the parameter to check + */ +/*----------------------------------------------------------------------------*/ +cpl_boolean hdrl_rect_region_parameter_check(const hdrl_parameter * self) +{ + return hdrl_parameter_check_type(self, &hdrl_rect_region_parameter_type); +} + +/*----------------------------------------------------------------------------- + Rect Region Parameters Accessors + -----------------------------------------------------------------------------*/ + +/** + * @brief get lower left x coordinate of rectangual region + */ +cpl_size hdrl_rect_region_get_llx(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1) ; + return ((const hdrl_rect_region_parameter *)p)->llx; +} + +/** + * @brief get lower left y coordinate of rectangual region + */ +cpl_size hdrl_rect_region_get_lly(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1) ; + return ((const hdrl_rect_region_parameter *)p)->lly; +} + +/** + * @brief get upper right x coordinate of rectangular region + */ +cpl_size hdrl_rect_region_get_urx(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1) ; + return ((const hdrl_rect_region_parameter *)p)->urx; +} + +/** + * @brief get upper right y coordinate of rectangual region + */ +cpl_size hdrl_rect_region_get_ury(const hdrl_parameter * p) +{ + cpl_ensure(p, CPL_ERROR_NULL_INPUT, -1) ; + return ((const hdrl_rect_region_parameter *)p)->ury; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Verify basic correctness of the parameters + @param param rect region parameters + @param max_x max value for upper x bound, set to < 0 to skip check + @param max_y max value for upper y bound, set to < 0 to skip check + @return CPL_ERROR_NONE if everything is ok, an error code otherwise + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_rect_region_parameter_verify( + const hdrl_parameter * param, + const cpl_size max_x, + const cpl_size max_y) +{ + const hdrl_rect_region_parameter * param_loc = + (const hdrl_rect_region_parameter *)param ; + + cpl_error_ensure(param != NULL, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "NULL Input Parameters"); + cpl_error_ensure(hdrl_rect_region_parameter_check(param), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected Rect Region parameter") ; + cpl_error_ensure(param_loc->llx >= 1 && param_loc->lly >= 1 && + param_loc->urx >= 1 && param_loc->ury >= 1, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "Coordinates must be strictly positive"); + + cpl_error_ensure(param_loc->urx >= param_loc->llx, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "urx (%ld) must be larger equal than llx (%ld)", + (long)param_loc->urx, (long)param_loc->llx); + cpl_error_ensure(param_loc->ury >= param_loc->lly, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "ury (%ld) must be larger equal than lly (%ld)", + (long)param_loc->ury, (long)param_loc->lly); + if (max_x > 0) + cpl_error_ensure(param_loc->urx <= max_x, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "urx %zu larger than maximum %zu", + (size_t)param_loc->urx, (size_t)max_x); + if (max_y > 0) + cpl_error_ensure(param_loc->ury <= max_y, CPL_ERROR_ILLEGAL_INPUT, + return CPL_ERROR_ILLEGAL_INPUT, + "ury %zu larger than maximum %zu", + (size_t)param_loc->ury, (size_t)max_y); + return CPL_ERROR_NONE; +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief Create parameter list for hdrl_rect_region + @param base_context base context of parameter (e.g. recipe name) + @param prefix prefix of parameter, may be empty string + @param name_prefix prefix for the parameter names, may be empty string + @param defaults default parameters values + @return cpl_parameterlist + Creates a parameterlist containing + base_context.prefix.name-prefixllx + base_context.prefix.name-prefixlly + base_context.prefix.name-prefixurx + base_context.prefix.name-prefixury + The CLI aliases omit the base_context. + */ +/* ---------------------------------------------------------------------------*/ +cpl_parameterlist * hdrl_rect_region_parameter_create_parlist( + const char *base_context, + const char *prefix, + const char *name_prefix, + const hdrl_parameter *defaults) +{ + cpl_ensure(base_context && prefix && name_prefix && defaults, + CPL_ERROR_NULL_INPUT, NULL); + + cpl_ensure(hdrl_rect_region_parameter_check(defaults), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + cpl_parameterlist *parlist = cpl_parameterlist_new(); + + /* --prefix.llx */ + hdrl_setup_vparameter(parlist, prefix, ".", name_prefix, + "llx", base_context, + "Lower left x pos. (FITS) defining the region", + CPL_TYPE_INT, (int)hdrl_rect_region_get_llx(defaults)); + /* --prefix.lly */ + hdrl_setup_vparameter(parlist, prefix, ".", name_prefix, + "lly", base_context, + "Lower left y pos. (FITS) defining the region", + CPL_TYPE_INT, (int)hdrl_rect_region_get_lly(defaults)); + + /* --prefix.urx */ + hdrl_setup_vparameter(parlist, prefix, ".", name_prefix, + "urx", base_context, + "Upper right x pos. (FITS) defining the region", + CPL_TYPE_INT, (int)hdrl_rect_region_get_urx(defaults)); + + /* --prefix.ury */ + hdrl_setup_vparameter(parlist, prefix, ".", name_prefix, + "ury", base_context, + "Upper right y pos. (FITS) defining the region", + CPL_TYPE_INT, (int)hdrl_rect_region_get_ury(defaults)); + + if (cpl_error_get_code()) { + cpl_parameterlist_delete(parlist); + return NULL; + } + + return parlist; +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief parse parameterlist for rectangle parameters + @param parlist parameter list to parse + @param base_context prefix of parameter + @param name_prefix prefix of parameter name, may be empty string + @see hdrl_rect_get_parlist() + @return A newly allocated hdrl_rect_region parameter or NULL in error case + + The returned object must be deallocated with hdrl_parameter_delete() + parameterlist should have been created with hdrl_rect_get_parlist or have the + same name hierachy + */ +/* ---------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_rect_region_parameter_parse_parlist( + const cpl_parameterlist * parlist, + const char * base_context, + const char * name_prefix) +{ + cpl_size llx, lly, urx, ury ; + cpl_error_ensure(base_context && parlist, CPL_ERROR_NULL_INPUT, + return NULL, "NULL Input Parameters"); + const char * sep = strlen(base_context) > 0 ? "." : ""; + const char * points[] = {"llx", "lly", "urx", "ury"}; + cpl_size * dest[] = {&llx, &lly, &urx, &ury}; + for (size_t i = 0; i < 4; i++) { + char * name = cpl_sprintf("%s%s%s%s", base_context, sep, + name_prefix, points[i]); + const cpl_parameter * par = cpl_parameterlist_find_const(parlist, name); + *(dest[i]) = cpl_parameter_get_int(par); + cpl_free(name); + } + + if (cpl_error_get_code()) { + cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Error while parsing parameterlist " + "with base_context %s", base_context); + return NULL; + } + + return hdrl_rect_region_parameter_create(llx, lly, urx, ury) ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief wrap negative or zero coordinates around full image size + @param rect_region rect region to wrap + @param nx image size in x, nx is added to entries < 1 + @param ny image size in y, ny is added to entries < 1 + @return cpl_error_code + + allows reverse indexing: 0 would be nx, -2 would be nx - 2 etc + Wrapping is based in FITS convention: 1 first pixel, nx last pixel inclusive + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_rect_region_fix_negatives( + hdrl_parameter * rect_region, + const cpl_size nx, + const cpl_size ny) +{ + hdrl_rect_region_parameter * rr_loc = + (hdrl_rect_region_parameter *)rect_region ; + + cpl_error_ensure(rect_region != 0, CPL_ERROR_NULL_INPUT, + return CPL_ERROR_NULL_INPUT, "region input must not be NULL"); + cpl_error_ensure(hdrl_rect_region_parameter_check(rect_region), + CPL_ERROR_ILLEGAL_INPUT, return CPL_ERROR_ILLEGAL_INPUT, + "Expected Rect Region parameter") ; + + if (nx > 0 && rr_loc->llx < 1) rr_loc->llx += nx; + if (ny > 0 && rr_loc->lly < 1) rr_loc->lly += ny; + if (nx > 0 && rr_loc->urx < 1) rr_loc->urx += nx; + if (ny > 0 && rr_loc->ury < 1) rr_loc->ury += ny; + + return hdrl_rect_region_parameter_verify(rect_region, nx, ny); +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief returns CPL_TRUE if x is strictly monotonic increasing + @param x array to check for being strictly monotonic increasing + @param l length of the array + @return CPL_TRUE if x is strictly monotonic increasing, CPL_FALSE otherwise + */ +/* ---------------------------------------------------------------------------*/ +cpl_boolean hdrl_is_strictly_monotonic_increasing(const double * x, cpl_size l){ + + if(x == NULL || l <= 1) return CPL_TRUE; + + for(cpl_size i = 0; i < l - 1; i++){ + if(x[i] >= x[i + 1]) return CPL_FALSE; + } + return CPL_TRUE; +} + +/* ---------------------------------------------------------------------------*/ +/** + @brief sort in increasing or decreasing order x. Keep aligned with y1 and y2. + @param x x array + @param y1 y1 array + @param y2 y2 array + @param sample_len length of the arrays + @param sort_decreasing if CPL_TRUE sort as decreasing, otherwise increasing + + @return nothing + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_sort_on_x(double * x, double * y1, double * y2, + const cpl_size sample_len, const cpl_boolean sort_decreasing){ + + cpl_propertylist * col_list = cpl_propertylist_new(); + + cpl_propertylist_append_bool(col_list, "x", sort_decreasing); + + cpl_table * tb = cpl_table_new(sample_len); + + cpl_table_wrap_double(tb, x, "x"); + + if(y1) + cpl_table_wrap_double(tb, y1, "y1"); + + if(y2) + cpl_table_wrap_double(tb, y2, "y2"); + + cpl_table_sort(tb, col_list); + + cpl_table_unwrap(tb, "x"); + + if(y1) + cpl_table_unwrap(tb, "y1"); + + if(y2) + cpl_table_unwrap(tb, "y2"); + + cpl_table_delete(tb); + cpl_propertylist_delete(col_list); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief join strings together + * + * @param sep_ separator to place between strings, NULL equals empty string + * @param n number of strings to join + * + * The input strings may be empty or NULL in which case it skips the entry + * adding no extra separator. + * + * @return joined string, must be deallocated by user with cpl_free + */ +/* ---------------------------------------------------------------------------*/ +char * hdrl_join_string(const char * sep_, int n, ...) +{ + va_list vl; + char * res = NULL; + const char * sep = sep_ ? sep_ : ""; + cpl_ensure(n > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + va_start(vl, n); + for (int i = 0; i < n; i++) { + char * tmp = res; + char * val = va_arg(vl, char *); + if (val == NULL || strlen(val) == 0) { + continue; + } + if (!res) { + res = cpl_strdup(val); + } + else { + res = cpl_sprintf("%s%s%s", res, sep, val); + } + cpl_free(tmp); + } + va_end(vl); + + return res; +} + + +/** @cond EXPERIMENTAL */ + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return file descriptor of a temporary file + * @param dir directory prefix to place the file in, may be NULL + * @param unlink unlink the file from the filesystem immediately + * @return file descriptor or -1 on error + * @note if dir is NULL or not writable it tries to create a file in following + * directories in decreasing order of preference: + * $TMPDIR, /var/tmp, /tmp, $PWD + */ +/* ---------------------------------------------------------------------------*/ +int hdrl_get_tempfile(const char * dir, cpl_boolean unlink) +{ + /* options in decreasing preference */ + const char * tmpdirs[] = { + /* user override */ + getenv("TMPDIR"), + /* large file temp */ + "/var/tmp/", + /* small file temp, may be tmpfs */ + "/tmp/" + }; + const size_t ndirs = sizeof(tmpdirs) / sizeof(tmpdirs[0]); + const char * tmpdir = NULL; + + if (dir && access(dir, W_OK) == 0) { + tmpdir = dir; + } + else { + for (size_t i = 0; i < ndirs; i++) { + if (tmpdirs[i] && access(tmpdirs[i], W_OK) == 0) { + tmpdir = tmpdirs[i]; + break; + } + } + } + + { + /* try $PWD if no tmpdir found */ + char * template = hdrl_join_string("/", 2, tmpdir, "hdrl_tmp_XXXXXX"); + int fd = mkstemp(template); + if (fd == -1) { + cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, + "Temporary file creation failed: %s", + strerror(errno)); + cpl_free(template); + return -1; + } + + cpl_msg_debug(cpl_func, "Created tempfile %s", template); + + if (unlink) { + remove(template); + } + cpl_free(template); + + return fd; + } +} + + +/* ---------------------------------------------------------------------------*/ +/** + @brief get the absoluet current working directory + @return char string, must be deleted by the user with cpl_free + */ +/* ---------------------------------------------------------------------------*/ +char * hdrl_get_cwd(void) +{ + size_t n = 4096; + char * buf; + errno = 0; + /* if only we could use sane GNU functions instead of this posix crap */ + while (1) { + buf = cpl_malloc(n); + if (getcwd(buf, n) != 0) { + break; + } + else if (errno == ERANGE) { + /* increase buffer, repeat */ + errno = 0; + n *= 2; + cpl_free(buf); + } + else { + cpl_free(buf); + cpl_error_set_message(cpl_func, CPL_ERROR_FILE_IO, + "Could not determine current working " + "directory: %s", strerror(errno)); + return NULL; + } + } + + return buf; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief scale a imagelist using scaling factors in a vector + * + * @param scale vector containing scaling factors, the first element + * defines the value to scale to + * @param scale_e errors of the scaling factors + * @param scale_type scale type, additive or multiplicative + * @param data imagelist to be scaled + * @param errors errors of imagelist to be scaled + * + * If scale_type is HDRL_SCALE_ADDITIVE the difference of each value in the + * scaling vector is subtracted from the first element of the vector and added + * to each image in the imagelist. + * + * for i in vector.size: + * data[i] += vector[0] - vector[i] + * + * If scale_type is HDRL_SCALE_MULTIPLICATIVE the quotient of each value in + * the scaling vector to the first element of the vector is multiplied + * to each image in the imagelist. + * If an element of the scaling vector is zero the image will have all its + * pixels marked as bad in its bad pixel map. + * + * for i in vector.size: + * data[i] *= vector[0] / vector[i] + * + * The errors are propagated using error propagation of first order + * and assuming no correlations between the values. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_normalize_imagelist_by_vector(const cpl_vector * scale, + const cpl_vector * scale_e, + const hdrl_scale_type scale_type, + cpl_imagelist * data, + cpl_imagelist * errors) +{ + cpl_ensure_code(scale, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(scale_e, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(data, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(errors, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_vector_get_size(scale) == cpl_imagelist_get_size(data), + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_vector_get_size(scale_e) == cpl_vector_get_size(scale), + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(errors) == + cpl_imagelist_get_size(data), CPL_ERROR_ILLEGAL_INPUT); + + for (size_t i = 1; i < (size_t)cpl_imagelist_get_size(data); i++) { + const hdrl_data_t dfirst = cpl_vector_get(scale, 0); + const hdrl_error_t efirst = cpl_vector_get(scale_e, 0); + cpl_image * dimg = cpl_imagelist_get(data, i); + cpl_image * eimg = cpl_imagelist_get(errors, i); + if (scale_type == HDRL_SCALE_ADDITIVE) { + hdrl_data_t dscale_o = cpl_vector_get(scale, i); + hdrl_error_t escale_o = cpl_vector_get(scale_e, i); + + /* dscale = dfirst - dscale_o */ + hdrl_data_t dscale = dfirst; + hdrl_error_t escale = efirst; + hdrl_elemop_sub(&dscale, &escale, 1, &dscale_o, &escale_o, 1, NULL); + + /* dimg = dimg + dscale */ + hdrl_elemop_image_add_scalar(dimg, eimg, dscale, escale); + } + else if (scale_type == HDRL_SCALE_MULTIPLICATIVE) { + hdrl_data_t dscale_o = cpl_vector_get(scale, i); + hdrl_error_t escale_o = cpl_vector_get(scale_e, i); + + if (dscale_o == 0.) { + cpl_msg_warning(cpl_func, "scale factor of image %zu is " + "not a number", i); + cpl_image_add_scalar(dimg, NAN); + cpl_image_add_scalar(eimg, NAN); + cpl_image_reject_value(dimg, CPL_VALUE_NAN); + cpl_image_reject_value(eimg, CPL_VALUE_NAN); + continue; + } + + /* dscale = dfirst / dscale_o */ + hdrl_data_t dscale = dfirst; + hdrl_error_t escale = efirst; + hdrl_elemop_div(&dscale, &escale, 1, &dscale_o, &escale_o, 1, NULL); + + /* dimg = dimg * dscale */ + hdrl_elemop_image_mul_scalar(dimg, eimg, dscale, escale); + } + else { + return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, + "Unsupported scale type"); + } + + if (cpl_error_get_code()) + break; + } + + return cpl_error_get_code(); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief scale a imagelist using scaling images + * + * @param scale imagelist containing scaling factors, the first element + * defines the value to scale to + * @param scale_e errors of the scaling factors + * @param scale_type scale type, additive or multiplicative + * @param data imagelist to be scaled + * @param errors errors of imagelist to be scaled + * + * If scale_type is HDRL_SCALE_ADDITIVE the difference of each value in the + * scaling imagelist is subtracted from the first element of the vector and + * added to each image in the imagelist. + * + * for i in vector.size: + * data[i] += scale[0] - scale[i] + * + * If scale_type is HDRL_SCALE_MULTIPLICATIVE the quotient of each value in + * the scaling vector to the first element of the imagelist is multiplied + * to each image in the imagelist. + * If an element of the scaling vector is zero the image will have all its + * pixels marked as bad in its bad pixel map. + * + * for i in vector.size: + * data[i] *= scale[0] / scale[i] + * + * The errors are propagated using error propagation of first order + * and assuming no correlations between the values. + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_normalize_imagelist_by_imagelist(const cpl_imagelist * scale, + const cpl_imagelist * scale_e, + const hdrl_scale_type scale_type, + cpl_imagelist * data, + cpl_imagelist * errors) +{ + cpl_ensure_code(scale, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(scale_e, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(data, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(errors, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(scale) == + cpl_imagelist_get_size(data), CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(scale_e) == + cpl_imagelist_get_size(scale), CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_imagelist_get_size(errors) == + cpl_imagelist_get_size(data), CPL_ERROR_ILLEGAL_INPUT); + + for (size_t i = 1; i < (size_t)cpl_imagelist_get_size(data); i++) { + cpl_image * dscale = + cpl_image_duplicate(cpl_imagelist_get_const(scale, 0)); + cpl_image * escale = + cpl_image_duplicate(cpl_imagelist_get_const(scale_e, 0)); + cpl_image * dimg = cpl_imagelist_get(data, i); + cpl_image * eimg = cpl_imagelist_get(errors, i); + const cpl_image * dscale_o = cpl_imagelist_get_const(scale, i); + const cpl_image * escale_o = cpl_imagelist_get_const(scale_e, i); + + if (scale_type == HDRL_SCALE_ADDITIVE) { + /* dscale = dfirst - dscale_o */ + hdrl_elemop_image_sub_image(dscale, escale, dscale_o, escale_o); + + /* dimg = dimg + dscale */ + hdrl_elemop_image_add_image(dimg, eimg, dscale, escale); + } + else if (scale_type == HDRL_SCALE_MULTIPLICATIVE) { + /* dscale = dfirst / dscale_o */ + hdrl_elemop_image_div_image(dscale, escale, dscale_o, escale_o); + + /* dimg = dimg * dscale */ + hdrl_elemop_image_mul_image(dimg, eimg, dscale, escale); + } + else { + cpl_image_delete(dscale); + cpl_image_delete(escale); + return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE, + "Unsupported scale type"); + } + + cpl_image_delete(dscale); + cpl_image_delete(escale); + + if (cpl_error_get_code()) + break; + } + + return cpl_error_get_code(); +} + +/** @endcond */ + + +/** @cond PRIVATE */ + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief compress an image to a vector removing bad pixels + @param source image to compress + @param bpm optional bpm to use instead of the one in the image + @return cpl_vector or NULL if no good pixels or error + @note vector can't have size 0 so NULL is returned if all pixels are bad + */ +/*----------------------------------------------------------------------------*/ +cpl_vector * hdrl_image_to_vector( + const cpl_image * source, + const cpl_mask * bpm) +{ + cpl_ensure(source != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_vector * vec_source = NULL; + /* only cast if required, extra copying of non double data is still + * faster than a loop with cpl_image_get */ + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + cpl_image * d_img = cpl_image_get_type(source) == CPL_TYPE_DOUBLE ? + (cpl_image *)source : cpl_image_cast(source, CPL_TYPE_DOUBLE); + CPL_DIAG_PRAGMA_POP; + + const cpl_size naxis1 = cpl_image_get_size_x(source); + const cpl_size naxis2 = cpl_image_get_size_y(source); + + /* get raw data */ + const double * restrict sdata = cpl_image_get_data_double_const(d_img); + const cpl_binary * restrict bpmd = NULL; + + /* allocate output buffer */ + double * restrict ddata = cpl_malloc(naxis1 * naxis2 * + sizeof(ddata[0])); + long j = 0; + + if (bpm) + bpmd = cpl_mask_get_data_const(bpm); + else if (cpl_image_get_bpm_const(source) != NULL) + bpmd = cpl_mask_get_data_const(cpl_image_get_bpm_const(source)); + + if (bpmd == NULL) { + memcpy(ddata, sdata, naxis1 * naxis2 * sizeof(ddata[0])); + j = naxis1 * naxis2; + } + else { + /* copy only good pixels */ + for (long i = 0; i < naxis1 * naxis2; i++) { + if (bpmd[i] == CPL_BINARY_0) { + ddata[j] = sdata[i]; + j++; + } + } + } + + assert(j == naxis1 * naxis2 - + (bpm ? cpl_mask_count(bpm) : cpl_image_count_rejected(source))); + + if (j > 0) { + vec_source = cpl_vector_wrap(j, ddata); + } + else { + cpl_free(ddata); + } + + if (d_img != source) cpl_image_delete(d_img); + + return vec_source; +} + +typedef struct { + size_t available; /* number of cached pointers */ + size_t nspace; /* max cache pointers */ + void ** ptrs; +} cache_bucket; + +struct hdrl_vector_cache_ { + cpl_size nbuckets; + cache_bucket buckets[]; +}; + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create a cpl_vector cache + * + * @param max_cached_size maximum size of vectors that will be cached + * @param ncached_entries number of vectors of each size that can be cached + * + * Allows storing allocated vectors in a temporary structure for fast retrieval later. + * Useful when one needs to allocate and delete many small vectors with high + * frequency, this avoids two calls to malloc that would cause high overheads + * in this case. + * + * Vectors can be retrieved from the cache with hdrl_vector_new_from_cache() + * and returned to the cache with hdrl_vector_delete_to_cache(). + * + * The cache can store max_cached_size * ncached_entries vectors. + * + * May return NULL which is an no-opt cache and is a valid value for functions + * working on it. + * + * @note the cache has no global state but it is not thread-safe + * + * @return cache structure that must be deleted with hdrl_vector_cache_delete() + */ +/* ---------------------------------------------------------------------------*/ +hdrl_vector_cache * hdrl_vector_cache_new(cpl_size max_cached_size, + cpl_size ncached_entries) +{ + /* for largish vectors a cache is not worthwhile, save the memory */ + if (max_cached_size > 50) + return NULL; + hdrl_vector_cache * c = cpl_malloc(sizeof(hdrl_vector_cache) + + sizeof(cache_bucket) * (max_cached_size + 1)); + c->nbuckets = max_cached_size + 1; + for (cpl_size i = 0; i < c->nbuckets; i++) { + c->buckets[i].available = 0; + c->buckets[i].nspace = ncached_entries; + c->buckets[i].ptrs = cpl_calloc(sizeof(cpl_vector*), ncached_entries); + } + return c; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Delete cpl_vector cache and all its entries + * + * @param cache cache to delete + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_vector_cache_delete(hdrl_vector_cache * cache) +{ + if (!cache) + return; + for (cpl_size i = 0; i < cache->nbuckets; i++) { + for (size_t j = 0; j < cache->buckets[i].available; j++) { + cpl_vector_delete(cache->buckets[i].ptrs[j]); + } + cpl_free(cache->buckets[i].ptrs); + } + cpl_free(cache); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Allocate cpl_vector + * + * @param cache pointer vector cache structure, may be NULL + * @param sz size of vector to allocate + * + * returns a cpl_vector as cpl_vector_new() would but if a matching vector is in + * the cache it returns that instead of allocating a new one. + * The returned vector is a normal cpl_vector with no restrictions on usage. + * + * @see cpl_vector_new() + * + * @return cpl_vector that must be deleted with cpl_vector_delete or + * hdrl_cplvector_delete_to_cache() + */ +/* ---------------------------------------------------------------------------*/ +cpl_vector * hdrl_cplvector_new_from_cache(hdrl_vector_cache * cache, cpl_size sz) +{ + if (!cache) { + return cpl_vector_new(sz); + } + if (sz < cache->nbuckets) { + if (cache->buckets[sz].available > 0) { + return cache->buckets[sz].ptrs[--(cache->buckets[sz].available)]; + } + } + return cpl_vector_new(sz); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief Return cpl_vector to a cache + * + * @param cache cache to place the vector in, may be NULL + * @param v vector to be deleted or cached + * + * Returns a vector to the cache for later reuse, if the cache is full it + * will be deleted. + */ +/* ---------------------------------------------------------------------------*/ +void hdrl_cplvector_delete_to_cache(hdrl_vector_cache * cache, cpl_vector * v) +{ + if (!v) { + return; + } + if (cache) { + const cpl_size sz = cpl_vector_get_size(v); + if (sz < cache->nbuckets) { + if (cache->buckets[sz].available < cache->buckets[sz].nspace) { + cache->buckets[sz].ptrs[(cache->buckets[sz].available)++] = v; + return; + } + } + } + cpl_vector_delete(v); +} + + +/* internal if imgdatabuf and maskbuf are not NULL they are assumed to hold the + * data buffers of the image in the list in order to save on cpl_image_get + * calls, error and type checking must be done by caller */ +static cpl_vector * imagelist_to_vector(const cpl_imagelist * list, + const cpl_size nx, + const cpl_size x, + const cpl_size y, + const double ** imgdatabuf, + const cpl_binary ** maskbuf, hdrl_vector_cache * cache) +{ + const long nz = list ? cpl_imagelist_get_size(list) : -1; + unsigned long j = 0; + cpl_vector * vec = hdrl_cplvector_new_from_cache(cache, nz); + double * restrict ddata = cpl_vector_get_data(vec); + + if (imgdatabuf && maskbuf) { + for (long k = 0; k < nz; k++) { + double v = imgdatabuf[k][(y - 1) * nx + (x - 1)]; + cpl_binary rej = maskbuf[k] ? + maskbuf[k][(y - 1) * nx + (x - 1)] : 0; + + if (!rej) { + ddata[j] = v; + j++; + } + } + } + else { + for (long k = 0; k < nz; k++) { + int rej; + const cpl_image * img = cpl_imagelist_get_const(list, k); + double v = cpl_image_get(img, x, y, &rej); + + if (!rej) { + ddata[j] = v; + j++; + } + } + } + + if (j > 0) { + if ((cpl_size)j != nz) { + cpl_vector_set_size(vec, j); + } + } + else { + hdrl_cplvector_delete_to_cache(cache, vec); + vec = NULL; + } + + return vec; +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief compress an imagelist to a vector via z axis, removing bad pixels + @param list imagelist to compress + @param x x coordinate to compress over (FITS convention) + @param y y coordinate to compress over (FITS convention) + @return cpl_vector or NULL if no good pixels or error + @note vector can't have size 0 so NULL is returned if all pixels are bad + */ +/*----------------------------------------------------------------------------*/ +cpl_vector * hdrl_imagelist_to_vector(const cpl_imagelist * list, + const cpl_size x, + const cpl_size y) +{ + cpl_size nx; + const cpl_size nz = list ? cpl_imagelist_get_size(list) : -1; + cpl_ensure(list != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(nz > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(x > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(y > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + + { + const cpl_image * img = cpl_imagelist_get_const(list, 0); + const cpl_size ny = cpl_image_get_size_y(img); + nx = cpl_image_get_size_x(img); + cpl_ensure(x <= nx, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(y <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + } + return imagelist_to_vector(list, nx, x, y, NULL, NULL, NULL); +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief compress an imagelist to a vector via z axis for a row + @param list imagelist to compress + @param y y coordinate to compress over (FITS convention) + @param out output array of vector pointers of size nx + @param cache vector cache to avoid unnecessary memory allocations + may be NULL + @return cpl_error_code + @note vector can't have size 0 so NULL is returned if all pixels are bad + + more efficient than hdrl_imagelist_to_vector for double images as it will + call cpl_image_get less often by caching the data buffers + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code hdrl_imagelist_to_vector_row(const cpl_imagelist * list, + const cpl_size y, + cpl_vector ** out, + hdrl_vector_cache * cache) +{ + long nx; + int isdouble; + const long nz = list ? (long)cpl_imagelist_get_size(list) : 0; + cpl_ensure_code(list != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(nz > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(y > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + + { + const cpl_image * img = cpl_imagelist_get_const(list, 0); + const cpl_size ny = cpl_image_get_size_y(img); + cpl_ensure_code(y <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); + nx = (long)cpl_image_get_size_x(img); + isdouble = cpl_image_get_type(img) == CPL_TYPE_DOUBLE; + } + + const double * imgdatabuf[nz]; + const cpl_binary * maskbuf[nz]; + for (long i = 0; i < nz && isdouble; i++) { + const cpl_image * img = cpl_imagelist_get_const(list, i); + const cpl_mask * bpm = cpl_image_get_bpm_const(img); + imgdatabuf[i] = cpl_image_get_data_double_const(img); + if (bpm) { + maskbuf[i] = cpl_mask_get_data_const(bpm); + } + else { + maskbuf[i] = NULL; + } + } + for (long x = 0; x < nx; x++) { + if (isdouble) { + out[x] = imagelist_to_vector(list, nx, x + 1, y, + imgdatabuf, maskbuf, cache); + } + else { + out[x] = imagelist_to_vector(list, nx, x + 1, y, NULL, NULL, cache); + } + } + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief wrap two cpl_imagelist around data and errors in hdrl_imagelist + * + * @param list input hdrl_imagelist + * @param data output data cpl_imagelist (may be NULL) + * @param errs output error cpl_imagelist (may be NULL) + * @return cpl_error_code + * + * @note the imagelists only wrap the images and must be deleted with + * cpl_imagelist_unwrap + */ +/* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_imagelist_to_cplwrap(const hdrl_imagelist * list, + cpl_imagelist ** data, + cpl_imagelist ** errs) +{ + cpl_ensure_code(list, CPL_ERROR_NULL_INPUT); + if (data) { + *data = cpl_imagelist_new(); + } + if (errs) { + *errs = cpl_imagelist_new(); + } + for (cpl_size i = 0; i < hdrl_imagelist_get_size(list); i++) { + hdrl_image * img = hdrl_imagelist_get(list, i); + if (data) { + cpl_imagelist_set(*data, hdrl_image_get_image(img), i); + } + if (errs) { + cpl_imagelist_set(*errs, hdrl_image_get_error(img), i); + } + } + + if (cpl_error_get_code()) { + if (data) { + cpl_imagelist_unwrap(*data); + *data = NULL; + } + if (errs) { + cpl_imagelist_unwrap(*errs); + *errs = NULL; + } + } + return cpl_error_get_code(); +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief filter image on a grid + * + * @param ima image to filter + * @param x row vector of coordinates to filter on + * @param y row vector of coordinates to filter on + * @param filtersize_x size of the median filter + * @param filtersize_y size of the median filter + * @return filtered image of size of the grid + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * +hdrl_medianfilter_image_grid(const cpl_image * ima, cpl_matrix * x, cpl_matrix * y, + cpl_size filtersize_x, cpl_size filtersize_y) +{ + cpl_error_ensure(ima != NULL, CPL_ERROR_NULL_INPUT, return NULL, + "NULL input image"); + cpl_error_ensure(filtersize_x > 0 && filtersize_y > 0 , + CPL_ERROR_INCOMPATIBLE_INPUT, return NULL, + "All function parameters must be greater then Zero"); + + const cpl_size nx = cpl_image_get_size_x(ima); + const cpl_size ny = cpl_image_get_size_y(ima); + const cpl_size steps_x = cpl_matrix_get_nrow(x); + const cpl_size steps_y = cpl_matrix_get_nrow(y); + + cpl_image * ima_local = cpl_image_new(steps_x, steps_y, CPL_TYPE_DOUBLE); + + for (cpl_size iy = 0; iy < steps_y; iy++) { + cpl_size middlep_y = cpl_matrix_get(y, iy, 0); + for (cpl_size ix = 0; ix < steps_x; ix++) { + cpl_size middlep_x = cpl_matrix_get(x, ix, 0); + + cpl_size lowerlimit_x = CX_MAX(middlep_x - filtersize_x, 1); + cpl_size lowerlimit_y = CX_MAX(middlep_y - filtersize_y, 1); + cpl_size upperlimit_x = CX_MIN(middlep_x + filtersize_x, nx); + cpl_size upperlimit_y = CX_MIN(middlep_y + filtersize_y, ny); + + double median = cpl_image_get_median_window(ima, lowerlimit_x, + lowerlimit_y, upperlimit_x, upperlimit_y); + + cpl_image_set(ima_local, ix + 1, iy + 1, median); + + cpl_msg_debug(cpl_func, "middlep_x: %lld, middlep_y: %lld, median: " + "%g", middlep_x, middlep_y, median); + } + } + return ima_local; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief create linear space row vector + * @param start starting point + * @param stop end point, exclusive + * @param step step size + * + * @returns matrix with one row filled equally spaced points from start to end + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_matrix * hdrl_matrix_linspace( + cpl_size start, + cpl_size stop, + cpl_size step) +{ + cpl_matrix * x = cpl_matrix_new(stop / step, 1); + for (intptr_t i = 0; start + i * step < stop && i < stop / step; i++) { + cpl_matrix_set(x, i, 0, start + i * step); + } + return x; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief fit 2D legendre polynomials to img + * + * @param img image to be fitted + * @param order_x order of x polynomial + * @param order_y order of y polynomial + * @param grid_x x grid to evaluate on + * @param grid_y y grid to evaluate on + * @param orig_nx upper limit in x, exclusive + * @param orig_ny upper limit in y, exclusive + * + * @return coefficient matrix of the fitted 2-D polynomial + * @see hdrl_mime_linalg_pairwise_column_tensor_products_create, + * hdrl_legendre_to_image + */ +/* ---------------------------------------------------------------------------*/ +cpl_matrix * hdrl_fit_legendre( + cpl_image * img, + int order_x, + int order_y, + cpl_matrix * grid_x, + cpl_matrix * grid_y, + cpl_size orig_nx, + cpl_size orig_ny) +{ + cpl_size nx2 = cpl_matrix_get_nrow(grid_x); + cpl_size ny2 = cpl_matrix_get_nrow(grid_y); + cpl_matrix * xpolys = + hdrl_mime_legendre_polynomials_create(order_x + 1, 0, orig_nx - 1, grid_x); + cpl_matrix * ypolys = + hdrl_mime_legendre_polynomials_create(order_y + 1, 0, orig_ny - 1, grid_y); + cpl_matrix * tensors = + hdrl_mime_linalg_pairwise_column_tensor_products_create(ypolys, + xpolys); + cpl_matrix * mimage = cpl_matrix_wrap(nx2 * ny2, 1, cpl_image_get_data(img)); + cpl_matrix * coeffs = cpl_matrix_solve_normal(tensors, mimage); + cpl_matrix_unwrap(mimage); + cpl_matrix_delete(xpolys); + cpl_matrix_delete(ypolys); + cpl_matrix_delete(tensors); + + return coeffs; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief evaluate 2D legendre polynomials on image + * + * @param coeffs legendre coefficients + * @param order_x order of x polynomial + * @param order_y order of y polynomial + * @param nx x size of image + * @param ny y size of image + * @return legendre polynomial evaluated on an image + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * hdrl_legendre_to_image( + cpl_matrix * coeffs, + int order_x, + int order_y, + cpl_size nx, + cpl_size ny) +{ + /* evaluate on full image */ + /* TODO need grid of original fit here? */ + cpl_matrix * x = hdrl_matrix_linspace(0, nx, 1); + cpl_matrix * y = hdrl_matrix_linspace(0, ny, 1); + cpl_matrix * xpolys = + hdrl_mime_legendre_polynomials_create(order_x + 1, 0, nx - 1, x); + cpl_matrix * ypolys = + hdrl_mime_legendre_polynomials_create(order_y + 1, 0, ny - 1, y); + cpl_matrix * tensors = + hdrl_mime_linalg_pairwise_column_tensor_products_create(ypolys, + xpolys); + cpl_matrix * result = cpl_matrix_product_create(tensors, coeffs); + cpl_image * iresult = cpl_image_wrap(nx, ny, CPL_TYPE_DOUBLE, + cpl_matrix_get_data(result)); + cpl_matrix_delete(x); + cpl_matrix_delete(y); + cpl_matrix_delete(xpolys); + cpl_matrix_delete(ypolys); + cpl_matrix_delete(tensors); + cpl_matrix_unwrap(result); + + return iresult; +} +/* ---------------------------------------------------------------------------*/ +/** + * @brief check if bad pixel masks are identical. + * @param mask1 input mask 1 to be compared with input mask 2 + * @param mask2 input mask 2 to be compared with input mask 1 + * + * @return 0 if the masks are identical - in all other cases 1 + */ +/* ---------------------------------------------------------------------------*/ +int hdrl_check_maskequality(const cpl_mask * mask1, const cpl_mask * mask2) +{ + cpl_ensure(mask1, CPL_ERROR_NULL_INPUT, 1); + cpl_ensure(mask2, CPL_ERROR_NULL_INPUT, 1); + + cpl_size m1nx = cpl_mask_get_size_x(mask1); + cpl_size m1ny = cpl_mask_get_size_y(mask1); + cpl_size m2nx = cpl_mask_get_size_x(mask2); + cpl_size m2ny = cpl_mask_get_size_y(mask2); + cpl_ensure(m1nx == m2nx, CPL_ERROR_NONE, 1); + cpl_ensure(m1ny == m2ny, CPL_ERROR_NONE, 1); + + const cpl_binary * dm1bpm = cpl_mask_get_data_const(mask1); + const cpl_binary * dm2bpm = cpl_mask_get_data_const(mask2); + if (memcmp(dm1bpm, dm2bpm, m1nx * m1ny) != 0) { + return 1; + } + else { + return 0; + } +} + +static const cpl_image * +image_const_row_view_create(const cpl_image * img, + cpl_size ly, + cpl_size uy) +{ + const size_t dsz = cpl_type_get_sizeof(cpl_image_get_type(img)); + const cpl_size nx = cpl_image_get_size_x(img); + const char * d = cpl_image_get_data_const(img); + size_t offset = (ly - 1) * nx; + cpl_size nny = uy - ly + 1; + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + + cpl_image * wimg = cpl_image_wrap(nx, nny, cpl_image_get_type(img), + (char*)d + offset * dsz); + + const cpl_mask * omask = cpl_image_get_bpm_const(img); + if (omask) { + cpl_mask * mask = cpl_mask_wrap(nx, nny, + (cpl_binary*)cpl_mask_get_data_const(omask) + offset); + cpl_mask_delete(hcpl_image_set_bpm(wimg, mask)); + } + + CPL_DIAG_PRAGMA_POP; + + return wimg; +} + +static void +image_const_row_view_delete(const cpl_image * img) +{ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + + cpl_mask_unwrap(cpl_image_unset_bpm((cpl_image*)(img))); + cpl_image_unwrap((cpl_image *)img); + + CPL_DIAG_PRAGMA_POP; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief compute a filter in parallel + * + * @param img image to filter + * @param kernel filter kernel (mutually exclusive with mask) + * @param mask filter mask (mutually exclusive with kernel) + * @param mode filter mode + * @return filtered image, must be deleted with cpl_image_delete + * + * if kernel is not NULL and mask is NULL cpl_image_filter is used + * if mask is not NULL and kernel is NULL cpl_image_filter_mask is used + * + * the kernel or mask size must be odd and less equal to the image size + * + */ +/* ---------------------------------------------------------------------------*/ +cpl_image * +hdrl_parallel_filter_image(const cpl_image * img, + const cpl_matrix * kernel, + const cpl_mask * mask, + const cpl_filter_mode mode) +{ + cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); + intptr_t nx = cpl_image_get_size_x(img); + intptr_t ny = cpl_image_get_size_y(img); + intptr_t ky, kx; + /* TODO probably one can use all except COPY */ + const cpl_border_mode border = CPL_BORDER_FILTER; + cpl_ensure((kernel && !mask) || (!kernel && mask), + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + if (kernel) { + ky = cpl_matrix_get_nrow(kernel); + kx = cpl_matrix_get_ncol(kernel); + } + else { + ky = cpl_mask_get_size_y(mask); + kx = cpl_mask_get_size_x(mask); + } + cpl_ensure(ky % 2 == 1, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(ny >= ky, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(nx >= kx, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + + intptr_t hk = (ky / 2); + cpl_image * res = cpl_image_new(nx, ny, cpl_image_get_type(img)); + /* make sure image has a bpm to avoid creation races later */ + cpl_image_get_bpm(res); + + /* filter first half-kernel rows (needs full kernel image) */ + if (hk) { + const cpl_image * slice = image_const_row_view_create(img, 1, ky); + cpl_image * slres = cpl_image_duplicate(slice); + if (kernel) { + cpl_image_filter(slres, slice, kernel, mode, border); + } + else { + cpl_image_filter_mask(slres, slice, mask, mode, border); + } + + const cpl_image * slice2 = image_const_row_view_create(slres, 1, hk); + cpl_image_copy(res, slice2, 1, 1); + image_const_row_view_delete(slice2); + image_const_row_view_delete(slice); + cpl_image_delete(slres); + } + intptr_t y = hk; + const intptr_t s = 200; + /* filter s sized row chunks needs one kernel overlap */ +HDRL_OMP(omp parallel for lastprivate(y) if (ny > s + ky)) + for (y = hk; y < ny - ky - (ny - ky) % s; y+=s) { + intptr_t l = (y + 1) - hk; + intptr_t u = (y + 1 + s) + hk - 1; + const cpl_image * slice = image_const_row_view_create(img, l, u); + cpl_image * slres = cpl_image_new(nx, u - l + 1, + cpl_image_get_type(slice)); + if (kernel) { + cpl_image_filter(slres, slice, kernel, mode, border); + } + else { + cpl_image_filter_mask(slres, slice, mask, mode, border); + } + const cpl_image * slice2 = + image_const_row_view_create(slres, hk + 1, hk + s); + cpl_image_copy(res, slice2, 1, y + 1); + image_const_row_view_delete(slice); + image_const_row_view_delete(slice2); + cpl_image_delete(slres); + } + /* filter remainder, needs half kernel overlap */ + if (y + 1 - hk < ny) { + const cpl_image * slice = image_const_row_view_create(img, y + 1 - hk, ny); + cpl_image * slres = cpl_image_duplicate(slice); + if (kernel) { + cpl_image_filter(slres, slice, kernel, mode, border); + } + else { + cpl_image_filter_mask(slres, slice, mask, mode, border); + } + const cpl_image * slice2 = + image_const_row_view_create(slres, hk + 1, cpl_image_get_size_y(slice)); + cpl_image_copy(res, slice2, 1, y + 1); + image_const_row_view_delete(slice); + image_const_row_view_delete(slice2); + cpl_image_delete(slres); + } + return res; +} + + +/** + * @brief + * Convert between physical and world coordinates using multiple threads + * + * @param wcs The input cpl_wcs structure + * @param from The input coordinate matrix + * @param to The output coordinate matrix + * @param status The output status array + * @param transform The transformation mode + * + * @return An appropriate error code + * + * @see cpl_wcs_convert() + * + * This function is a wrapper around cpl_wcs_convert using OpenMP for + * parallelization, see the cpl documentation for details on the functionality. + */ + /* ---------------------------------------------------------------------------*/ +cpl_error_code +hdrl_wcs_convert(const cpl_wcs *wcs, const cpl_matrix *from, + cpl_matrix **to, cpl_array **status, + cpl_wcs_trans_mode transform) +{ + size_t nr = cpl_matrix_get_nrow(from); + size_t nc = cpl_matrix_get_ncol(from); + const size_t s = 4000; + size_t i; + int * dstatus; + cpl_ensure_code(to, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(status, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(wcs, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(from, CPL_ERROR_NULL_INPUT); + + *status = cpl_array_new(nr, CPL_TYPE_INT); + cpl_ensure_code(*status, CPL_ERROR_NULL_INPUT); + dstatus = cpl_array_get_data_int(*status); + *to = cpl_matrix_new(nr, nc); + cpl_error_code err = CPL_ERROR_NONE; + +HDRL_OMP(omp parallel for if (nr > s)) + for (i = 0; i < nr; i+=s) { + cpl_matrix * lfrom = cpl_matrix_extract(from, i, 0, 1, 1, CPL_MIN(s, nr - i), nc); + cpl_matrix * lto = NULL; + cpl_array * lstatus = NULL; + cpl_error_code lerr = cpl_wcs_convert(wcs, lfrom, <o, &lstatus, transform); + if (lto != NULL) { + cpl_matrix_copy(*to, lto, i, 0); + } + if (lstatus != NULL) { + memcpy(&dstatus[i], cpl_array_get_data_int(lstatus), + cpl_array_get_size(lstatus) * sizeof(*dstatus)); + } + cpl_array_delete(lstatus); + cpl_matrix_delete(lfrom); + cpl_matrix_delete(lto); + if (lerr != CPL_ERROR_NONE) { +HDRL_OMP(omp critical(hdrlwcserror)) + err = lerr; + } + } + + if (err == CPL_ERROR_UNSUPPORTED_MODE) { + cpl_matrix_delete(*to); + *to = NULL; + cpl_array_delete(*status); + *status = NULL; + } + + return cpl_error_set(cpl_func, err); +} + +/* cpl_image_set_bpm from cpl 6.4 which we can't require yet for VLTSW 2014 */ +struct _cpl_image_ { + /* Size of the image in x and y */ + cpl_size nx, ny; + /* Type of the pixels used for the cpl_image */ + cpl_type type; + /* Pointer to pixel buffer as a 1d buffer */ + void * pixels; + /* Bad Pixels mask */ + cpl_mask * bpm; +}; + +cpl_mask * hcpl_image_set_bpm(cpl_image * self, cpl_mask * bpm) +{ +#if CPL_VERSION_CODE < CPL_VERSION(6, 4, 0) + cpl_mask * oldbpm; + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + + oldbpm = self->bpm; + self->bpm = bpm; + + return oldbpm; +#else + return cpl_image_set_bpm(self, bpm); +#endif +} + +double hcpl_vector_get_mad_window(cpl_vector * vec, + cpl_size llx, + cpl_size urx, + double * sigma) +{ + /* TODO use cpl directly when PIPE-4792 is fixed */ + struct _cpl_image_ img; + img.pixels = cpl_vector_get_data(vec); + img.nx = cpl_vector_get_size(vec); + img.ny = 1; + img.bpm = NULL; + img.type = CPL_TYPE_DOUBLE; + return cpl_image_get_mad_window(&img, llx, 1, urx, 1, sigma); +} + +double hcpl_gaussian_eval_2d(const cpl_array * self, double x, double y) +{ +#if CPL_VERSION_CODE < CPL_VERSION(6, 4, 0) + cpl_errorstate prestate = cpl_errorstate_get(); + const double B = cpl_array_get_double(self, 0, NULL); + const double A = cpl_array_get_double(self, 1, NULL); + const double R = cpl_array_get_double(self, 2, NULL); + const double M_x = cpl_array_get_double(self, 3, NULL); + const double M_y = cpl_array_get_double(self, 4, NULL); + const double S_x = cpl_array_get_double(self, 5, NULL); + const double S_y = cpl_array_get_double(self, 6, NULL); + + double value = 0.0; + + if (!cpl_errorstate_is_equal(prestate)) { + (void)cpl_error_set_where(cpl_func); + } else if (cpl_array_get_size(self) != 7) { + (void)cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + } else if (fabs(R) < 1.0 && S_x != 0.0 && S_y != 0.0) { + const double x_n = (x - M_x) / S_x; + const double y_n = (y - M_y) / S_y; + + value = B + A / (CPL_MATH_2PI * S_x * S_y * sqrt(1 - R * R)) * + exp(-0.5 / (1 - R * R) * ( x_n * x_n + y_n * y_n + - 2.0 * R * x_n * y_n)); + } else if (fabs(R) > 1.0) { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT, + "fabs(R=%g) > 1", R); + } else { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_DIVISION_BY_ZERO, + "R=%g. Sigma=(%g, %g)", R, S_x, S_y); + } + + return value; +#else + return cpl_gaussian_eval_2d(self, x, y); +#endif +} + + +/** @endcond */ + + +/*----------------------------------------------------------------------------*/ +/** + * + * @brief Compute the effective airmass of an observation. Takes in count the + * error propagation if you enter the relative error of the input parameters + * in a hdrl_value structure {data,error} + * + * The function calculates the average airmass for the line of sight given by the + * right ascension (ra) and the declination (dec). The latitude (geolat) in + * degrees of the observatory site and the local siderial time (lst) at + * observation start has to be given, as well as the duration of the observation, + * i.e. the exposure time (exptime). If the exposure time is zero then only one + * value of airmass is computed, instead of weighting beginning, middle, and + * end of exposure according to Stetson (Stetson P., 1987, PASP 99, 191). + * + * @param aRA right ascension in degrees + * @param aDEC declination in degrees + * @param aLST local sideral time (s.) elapsed since siderial midnight + * @param aExptime integration time in seconds + * @param aLatitude latitude of the observatory site in degrees + * @param type kind of approximation (see hdrl_airmass_approx enumtype) + * + * @return The computed average airmass or {-1,0.} on error. + * + * @note This function can be calcule different kinds of approximation specified + * in the hdrl_airmass_approx enum type, explain as follow. 1) The formula given + * by Hardie (Hardie 1962, In: "Astronomical Techniques", ed. Hiltner, p. 184) + * to compute the airmass as a function of zenith distance. 2) The formula of + * Young and Irvine (Young A. T., Irvine W. M., 1967, Astron. J. 72, 945). + * The range of trustworthy airmass outputs is only between 1 and 4. 3) + * The formula of Young (Young A. T., 1994 ApOpt, 33, 1108). + * + * @note You can to find in Interpolative formulas + * an interesting collection of approximations. + * + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_utils_airmass( + hdrl_value aRA, hdrl_value aDEC, hdrl_value aLST, + hdrl_value aExptime, hdrl_value aLatitude, + hdrl_airmass_approx type) +{ + + hdrl_value retErr = {-1.,0.}; + cpl_ensure( aRA.data >= 0. && aRA.data < 360. && aRA.error >= 0. + && aDEC.data >= -90. && aDEC.data <= 90. && aDEC.error >= 0. + && aLST.data >= 0. && aLST.data < 86400. && aLST.error >= 0. + && aExptime.data >= 0. && aExptime.error >= 0. + && aLatitude.data >= -90. && aLatitude.data <= 90. && aLatitude.error >= 0. + && (type == HDRL_AIRMASS_APPROX_HARDIE || type == HDRL_AIRMASS_APPROX_YOUNG_IRVINE || type == HDRL_AIRMASS_APPROX_YOUNG), + CPL_ERROR_ILLEGAL_INPUT, + retErr); + + /* Compute hour angle of the observation in degrees. */ + hdrl_value HA = {aLST.data * 15. / 3600. - aRA.data, + aLST.error * fabs(15. / 3600.) + aRA.error * fabs(-1.)}; + + /* Range adjustments.Angle between line of sight and meridian is needed. */ + if (HA.data < -180.) HA.data += 360.; + if (HA.data > 180.) HA.data -= 360.; + + /* Convert angles from degrees to radians. */ + + hdrl_value delta = {aDEC.data * CPL_MATH_RAD_DEG, + aDEC.error * fabs(CPL_MATH_RAD_DEG)}; + + hdrl_value latitude = {aLatitude.data * CPL_MATH_RAD_DEG, + aLatitude.error * fabs(CPL_MATH_RAD_DEG)}; + + hdrl_value hourangle = {HA.data * CPL_MATH_RAD_DEG, + HA.error * fabs(CPL_MATH_RAD_DEG)}; + + + /* Calculate airmass of the observation using the approximation given * + * by Young (1994). For non-zero exposure times these airmass values are * + * averaged using the weights given by Stetson. */ + + hdrl_value cosz = hdrl_get_zenith_distance(hourangle, delta, latitude); + hdrl_value z = {0., cosz.error}; + double zlimit = 80.; + + if (type == HDRL_AIRMASS_APPROX_HARDIE) { + + z.data = acos(cosz.data) * CPL_MATH_DEG_RAD; + z.error = cosz.error * fabs(-CPL_MATH_DEG_RAD / sqrt(1. + pow(cosz.data, 2))); + + cpl_error_ensure(z.data <= zlimit, CPL_ERROR_ILLEGAL_OUTPUT, return retErr, + "Zenith angle %f+-[%f] > %f!", z.data, z.error, zlimit); + } + + cpl_error_ensure( + cosz.data != 0. && fabs(1./cosz.data) >= FLT_EPSILON && acos(cosz.data) <= CPL_MATH_PI_2, + CPL_ERROR_ILLEGAL_OUTPUT, + return retErr, + "Airmass computation unsuccessful. Object is below the horizon at start (z = %f). Return the error", + cosz.error * fabs(-CPL_MATH_DEG_RAD / sqrt(1. + pow(cosz.data, 2))) ); + + hdrl_value airmass = {0.,0.}; + hdrl_value secansZdist = {1. / cosz.data, cosz.error * fabs(-1. / pow(cosz.data, 2))}; + + switch(type){ + case HDRL_AIRMASS_APPROX_HARDIE: + airmass = hdrl_get_airmass_hardie(secansZdist); + break; + case HDRL_AIRMASS_APPROX_YOUNG_IRVINE: + airmass = hdrl_get_airmass_youngirvine(secansZdist); + break; + case HDRL_AIRMASS_APPROX_YOUNG: + airmass = hdrl_get_airmass_young(cosz); + break; + } + + /* if the exposure time is larger than zero, weight in airmass * + * at mid and end exposure according to Stetson's weights (which * + * are also used in IRAF/astcalc for the airmass function */ + if (aExptime.data > 0.) { + + const double weights[] = {1./6., 2./3., 1./6.}; + const cpl_size nweights = sizeof(weights) / sizeof(double); + + hdrl_value timeStep = {aExptime.data / (nweights - 1.) * 15. / 3600. * CPL_MATH_RAD_DEG, 0.}; + timeStep.error = aExptime.error * fabs( 1. / (nweights - 1.) * 15. / 3600. * CPL_MATH_RAD_DEG); + + airmass.data *= weights[0]; + airmass.error *= fabs(weights[0]); + + for (cpl_size i = 1; i < nweights; i++) { + + hdrl_value aux_hourangle = { hourangle.data + i * timeStep.data, + hourangle.error + i * timeStep.error }; + + cosz = hdrl_get_zenith_distance(aux_hourangle, delta, latitude); + + if (type == HDRL_AIRMASS_APPROX_HARDIE) { + + z = (hdrl_value){acos(cosz.data) * CPL_MATH_DEG_RAD, 0.}; + z.error = cosz.error * fabs(-CPL_MATH_DEG_RAD / sqrt(1. + pow(cosz.data, 2))); + + cpl_error_ensure(z.data <= zlimit, CPL_ERROR_ILLEGAL_OUTPUT, return retErr, + "Zenith angle %f+-[%f] > %f!", z.data, z.error, zlimit); + } + + cpl_error_ensure( + cosz.data != 0. && fabs(1./cosz.data) >= FLT_EPSILON && acos(cosz.data) <= CPL_MATH_PI_2, + CPL_ERROR_ILLEGAL_OUTPUT, + return retErr, + "timeStep. Object is below the horizon at %s exposure (z=%f).", + i==1 ? "mid. Return the error" : "end. Return the error", + cosz.error * fabs(-CPL_MATH_DEG_RAD / sqrt(1. + pow(cosz.data, 2))) ); + + hdrl_value weight = {0., 0.}; + secansZdist = (hdrl_value){1. / cosz.data, cosz.error * fabs(-1. / pow(cosz.data, 2))}; + + switch(type){ + case HDRL_AIRMASS_APPROX_HARDIE: + weight = hdrl_get_airmass_hardie(secansZdist); + break; + case HDRL_AIRMASS_APPROX_YOUNG_IRVINE: + weight = hdrl_get_airmass_youngirvine(secansZdist); + break; + case HDRL_AIRMASS_APPROX_YOUNG: + weight = hdrl_get_airmass_young(cosz); + break; + } + airmass.data += weights[i] *weight.data; + airmass.error += weights[i] *weight.error; + } + } + + if (type == HDRL_AIRMASS_APPROX_YOUNG_IRVINE) { + + /* Accuracy limit for airmass approximation of Young & Irvine */ + const double airmasslimit = 4.; + + cpl_error_ensure(airmass.data <= airmasslimit, CPL_ERROR_ILLEGAL_OUTPUT, + return retErr, "Airmass larger than %f", airmasslimit); + } + + return airmass; +} + +/*----------------------------------------------------------------------------*/ +/** + @private + @brief Compute the zenith distance for an observation. + @param aHourAngle Hour angle in radians. + @param aDelta Declination in radians. + @param aLatitude Latitude of the observatory in radians. + @return cos(z) on success or 0. on error. + + The function computes the cosine of the zenith distance for an observation + taken at an angle aHourAngle from the meridian, which can take values in the + range extending from @f$-\pi@f$ to @f$\pi@f$, and the declination aDelta with + possible values between @f$-0.5\pi@f$ and @f$0.5\pi@f$. The latitude + aLatitude of the observing site may take values in the range @f$0@f$ to + @f$2\pi@f$. + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_get_zenith_distance( + hdrl_value aHourAngle, hdrl_value aDelta, hdrl_value aLatitude) +{ + + hdrl_value p0 = {sin(aLatitude.data) * sin(aDelta.data), + aLatitude.error * fabs( cos(aLatitude.data) * sin(aDelta.data) + + aDelta.error * fabs( sin(aLatitude.data) * cos(aDelta.data)))}; + + hdrl_value p1 = {cos(aLatitude.data) * cos(aDelta.data), + aLatitude.error * fabs(-sin(aLatitude.data) * cos(aDelta.data) + + aDelta.error * fabs(-cos(aLatitude.data) * sin(aDelta.data)))}; + + hdrl_value z = {p0.data + cos(aHourAngle.data) * p1.data, + p0.error * fabs(1.) + + aHourAngle.error * fabs(-sin(aHourAngle.data) * p1.data) + + p1.error * fabs( cos(aHourAngle.data))}; + + return fabs(z.data) < FLT_EPSILON ? (hdrl_value){0.,0.} : z; +} + +/*----------------------------------------------------------------------------*/ +/** + @private + @brief Compute airmass with Hardie (1962) approximation. + @param aSecZ The secans of the zenith distance. + @return The function returns the airmass. + + The function uses the approximation given by Hardie (Hardie 1962, In: + "Astronomical Techniques", ed. Hiltner, p. 184) to compute the airmass as a + function of zenith angle which is given in terms of its secons aSecZ. + It is supposedy more accurate than Young & Irvine (1967) and usable for zenith + angles below 85 degrees. + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_get_airmass_hardie(hdrl_value hvaSecZ) +{ + double aSecZ = hvaSecZ.data, + aSecZErr = hvaSecZ.error; + + hdrl_value secm1 = {aSecZ - 1, aSecZErr}; + + hdrl_value airmass = {aSecZ - 0.0018167 * secm1.data + - 0.002875 * secm1.data * secm1.data + - 0.0008083 * secm1.data * secm1.data * secm1.data, + aSecZErr +secm1.error * fabs( - 0.0018167 + - 2. * 0.002875 * secm1.data + - 3. * 0.0008083 * secm1.data * secm1.data)}; + + return airmass; +} + +/*----------------------------------------------------------------------------*/ +/** + @private + @brief Compute airmass with Young and Irvine (1997) approximation. + @param hvaSecZ Secans of the zenith distance. + @return The function returns the airmass. + + The function uses the approximation given by Young and Irvine (Young A. T., + Irvine W. M., 1967, Astron. J. 72, 945) to compute the airmass for a given + sec(z) aSecZ. This approximation takes into account atmosphere refraction and + curvature, but is in principle only valid at sea level. + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_get_airmass_youngirvine(hdrl_value hvaSecZ) +{ + double aSecZ = hvaSecZ.data, + aSecZErr = hvaSecZ.error; + + hdrl_value airmass = {aSecZ * (1. - 0.0012 * (pow(aSecZ, 2) - 1.)), + aSecZErr * fabs( (1. - 0.0012 * (pow(aSecZ, 2) - 1.)) - 2. * 0.0012 * pow(aSecZ, 2))}; + + return airmass; +} + +/*----------------------------------------------------------------------------*/ +/** + @private + @brief Compute airmass with Young (1994) approximation. + @param aCosZt The cosine of the true zenith distance. + @return The function returns the airmass. + + The function uses the approximation given by Young (Young A. T., 1994 ApOpt, + 33, 1108) to compute the relative optical air mass as a function of true, + rather than refracted, zenith angle which is given in terms of its cosine + aCosZt. + It is supposedy more accurate than Young & Irvine (1967) but restrictions are + not known. + */ +/*----------------------------------------------------------------------------*/ +hdrl_value hdrl_get_airmass_young(hdrl_value hvaCosZt) +{ + double aCosZt = hvaCosZt.data, + aCosZtErr = hvaCosZt.error; + + hdrl_value airmass = {(1.002432 * aCosZt * aCosZt + 0.148386 * aCosZt + 0.0096467) + / (aCosZt * aCosZt * aCosZt + 0.149864 * aCosZt * aCosZt + 0.0102963 * aCosZt + + 0.000303978), + aCosZtErr * fabs( ( (2. * 1.002432 * aCosZt + 0.148386) * (aCosZt * aCosZt * aCosZt + 0.149864 * aCosZt * aCosZt + 0.0102963 * aCosZt + 0.000303978) + - (3. * aCosZt * aCosZt + 2. * 0.149864 * aCosZt + 0.0102963) * (1.002432 * aCosZt * aCosZt + 0.148386 * aCosZt + 0.0096467) + ) / pow(aCosZt * aCosZt * aCosZt + 0.149864 * aCosZt * aCosZt + 0.0102963 * aCosZt + 0.000303978, 2) )}; + + return airmass; +} + + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_utils.h cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_utils.h --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/hdrl_utils.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/hdrl_utils.h 2017-08-25 11:51:19.000000000 +0000 @@ -0,0 +1,342 @@ +/* $Id: hdrl_utils.h,v 1.32 2013-10-23 09:13:12 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2012,2013 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: jtaylor $ + * $Date: 2013-10-23 09:13:12 $ + * $Revision: 1.32 $ + * $Name: not supported by cvs2svn $ + */ + +#ifndef HDRL_UTILS_H +#define HDRL_UTILS_H + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_parameter.h" +#include "hdrl_image.h" +#include "hdrl_imagelist.h" +#include + +#include +#include + +CPL_BEGIN_DECLS + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @enum hdrl_direction + @brief Define an image direction e.g along X or Y + */ +/*----------------------------------------------------------------------------*/ +typedef enum { + + /** X axis, equivalent to NAXIS1 in FITS convention */ + HDRL_X_AXIS, + /** Y axis, equivalent to NAXIS2 in FITS convention */ + HDRL_Y_AXIS, + /** Reserved value for undefined direction */ + HDRL_UNDEFINED_AXIS +} hdrl_direction; + +/*----------------------------------------------------------------------------*/ +/** + @enum hdrl_airmass_approx + @brief Define the kind of airmass approximation + */ +/*----------------------------------------------------------------------------*/ +typedef enum { + HDRL_AIRMASS_APPROX_HARDIE = 1, /* Hardie(1962) */ + HDRL_AIRMASS_APPROX_YOUNG_IRVINE, /* Young & Irvine (1967) */ + HDRL_AIRMASS_APPROX_YOUNG /* Young(1994) */ +} hdrl_airmass_approx; + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ + +const char * hdrl_get_license(void); + +/*---------------------------------------------------------------------------- + Rect region Parameters + ----------------------------------------------------------------------------*/ +hdrl_parameter * hdrl_rect_region_parameter_create(cpl_size, cpl_size, + cpl_size, cpl_size) ; +cpl_error_code hdrl_rect_region_parameter_update(hdrl_parameter *, cpl_size, + cpl_size, cpl_size, cpl_size) ; +cpl_boolean hdrl_rect_region_parameter_check(const hdrl_parameter *) ; +cpl_size hdrl_rect_region_get_llx(const hdrl_parameter *) ; +cpl_size hdrl_rect_region_get_lly(const hdrl_parameter *) ; +cpl_size hdrl_rect_region_get_urx(const hdrl_parameter *) ; +cpl_size hdrl_rect_region_get_ury(const hdrl_parameter *) ; +cpl_error_code hdrl_rect_region_parameter_verify(const hdrl_parameter *, + const cpl_size, const cpl_size) ; +cpl_parameterlist * hdrl_rect_region_parameter_create_parlist(const char *, + const char *, const char *, const hdrl_parameter *) ; +hdrl_parameter * hdrl_rect_region_parameter_parse_parlist( + const cpl_parameterlist *, const char *, const char *) ; +cpl_boolean hdrl_is_strictly_monotonic_increasing(const double * x, cpl_size l); +void hdrl_sort_on_x(double * x, double * y1, double * y2, + const cpl_size sample_len, const cpl_boolean sort_decreasing); + +/*----------------------------------------------------------------------------- + Experimental declarations - can be used, but no guarantees on api stability + -----------------------------------------------------------------------------*/ +#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE +typedef enum { + HDRL_SCALE_ADDITIVE, + HDRL_SCALE_MULTIPLICATIVE +} hdrl_scale_type; + +cpl_error_code +hdrl_normalize_imagelist_by_vector(const cpl_vector * scale, + const cpl_vector * scale_e, + const hdrl_scale_type scale_type, + cpl_imagelist * data, + cpl_imagelist * errors); + +cpl_error_code +hdrl_normalize_imagelist_by_imagelist(const cpl_imagelist * scale, + const cpl_imagelist * scale_e, + const hdrl_scale_type scale_type, + cpl_imagelist * data, + cpl_imagelist * errors); + +int hdrl_get_tempfile(const char * dir, cpl_boolean unlink); +char * hdrl_get_cwd(void); +cpl_error_code hdrl_rect_region_fix_negatives(hdrl_parameter *, const cpl_size, + const cpl_size) ; + +cpl_error_code +hdrl_wcs_convert(const cpl_wcs *wcs, const cpl_matrix *from, + cpl_matrix **to, cpl_array **status, + cpl_wcs_trans_mode transform); +#endif + +/* --------------- * + * Airmass funcion * + * --------------- */ +hdrl_value hdrl_utils_airmass( + hdrl_value aRA, hdrl_value aDEC, hdrl_value aLST, + hdrl_value aExptime, hdrl_value aLatitude, + hdrl_airmass_approx type); + +/*----------------------------------------------------------------------------- + Private declarations - must not be used outside of hdrl + -----------------------------------------------------------------------------*/ +#ifdef HDRL_USE_PRIVATE + +/* Private functions for airmass calculations */ +hdrl_value hdrl_get_zenith_distance( + hdrl_value aHourAngle, hdrl_value aDelta, hdrl_value aLatitude); + +hdrl_value hdrl_get_airmass_hardie( hdrl_value hvaSecZ); +hdrl_value hdrl_get_airmass_youngirvine( hdrl_value hvaSecZ); +hdrl_value hdrl_get_airmass_young( hdrl_value hvaCosZt); +/* ---------------------- */ + + +cpl_image * +hdrl_medianfilter_image_grid(const cpl_image * ima, cpl_matrix * x, cpl_matrix * y, + cpl_size filtersize_x, cpl_size filtersize_y); + +cpl_matrix * hdrl_matrix_linspace(cpl_size start, cpl_size stop, cpl_size step); + +cpl_matrix * hdrl_fit_legendre(cpl_image * img, int order_x, int order_y, + cpl_matrix * grid_x, cpl_matrix * grid_y, + cpl_size orig_nx, cpl_size orig_ny); + +cpl_image * hdrl_legendre_to_image(cpl_matrix * coeffs, int order_x, + int order_y, cpl_size nx, cpl_size ny); + +int hdrl_check_maskequality(const cpl_mask * mask1, const cpl_mask * mask2); + +/* must not be followed by a semicolon! + * gcc on mac has omp but it doesn't work for nontrivial cases as libc lacks + * alloca */ +#if defined (_OPENMP) && !defined( __APPLE__) +#define HDRL_OMP(x) _Pragma (#x) +#else +#define HDRL_OMP(x) +#endif + +typedef struct hdrl_vector_cache_ hdrl_vector_cache; + +hdrl_vector_cache * hdrl_vector_cache_new(cpl_size max_cached_size, + cpl_size ncached_entries); +void hdrl_vector_cache_delete(hdrl_vector_cache * cache); +cpl_vector * hdrl_cplvector_new_from_cache(hdrl_vector_cache * cache, cpl_size sz); +void hdrl_cplvector_delete_to_cache(hdrl_vector_cache * cache, cpl_vector * v); + +/* setup a value parameter and append it into parlist */ +#define hdrl_setup_vparameter(parlist, \ + prefix, \ + sep, \ + name_prefix, \ + pname, \ + context, \ + descr, \ + type, \ + pdefault) \ +do { \ + char * fname = cpl_sprintf("%s%s", name_prefix, pname); \ + char * setup_name = hdrl_join_string(sep, 3, context, prefix, fname); \ + cpl_parameter * setup_p = cpl_parameter_new_value(setup_name, type, \ + descr, context, pdefault) ; \ + cpl_free(setup_name); \ + setup_name = hdrl_join_string(sep, 2, prefix, fname); \ + cpl_parameter_set_alias(setup_p, CPL_PARAMETER_MODE_CLI, setup_name); \ + cpl_parameter_disable(setup_p, CPL_PARAMETER_MODE_ENV); \ + cpl_free(setup_name); \ + cpl_free(fname); \ + cpl_parameterlist_append(parlist, setup_p); \ + } while (0) + +cpl_vector * hdrl_image_to_vector(const cpl_image * source, const + cpl_mask * bpm); +cpl_vector * hdrl_imagelist_to_vector(const cpl_imagelist * list, + const cpl_size x, const cpl_size y); +cpl_error_code hdrl_imagelist_to_vector_row(const cpl_imagelist * list, + const cpl_size y, + cpl_vector ** out, + hdrl_vector_cache * cache); + +cpl_error_code +hdrl_imagelist_to_cplwrap(const hdrl_imagelist * list, + cpl_imagelist ** data, + cpl_imagelist ** errs); + +cpl_image * +hdrl_parallel_filter_image(const cpl_image * img, + const cpl_matrix * kernel, + const cpl_mask * mask, + const cpl_filter_mode mode); + +cpl_mask * hcpl_image_set_bpm(cpl_image * self, cpl_mask * bpm) ; +double hcpl_vector_get_mad_window(cpl_vector * vec, + cpl_size llx, + cpl_size urx, + double * sigma); +double hcpl_gaussian_eval_2d(const cpl_array * self, double x, double y); + +static inline int hdrl_int_is_power_of_two(unsigned long long x) +{ + return (x & (x - 1)) == 0; +} + +static inline size_t hdrl_get_image_npix(const cpl_image * img) +{ + return cpl_image_get_size_x(img) * cpl_image_get_size_y(img); +} + +static inline size_t hdrl_get_image_good_npix(const cpl_image * img) +{ + return (cpl_image_get_size_x(img) * cpl_image_get_size_y(img)) - + cpl_image_count_rejected(img); +} + +static inline cpl_mask * hdrl_copy_image_mask(const cpl_image * img) +{ + /* always returns a mask even it image has none */ + const cpl_mask * bpm = cpl_image_get_bpm_const(img); + + if (bpm) { + return cpl_mask_duplicate(bpm); + } + else { + return cpl_mask_new(cpl_image_get_size_x(img), + cpl_image_get_size_y(img)); + } +} + +char * hdrl_join_string(const char * sep_, int n, ...); + +static inline hdrl_data_t * hdrl_get_image_data(cpl_image * image) +{ +#if HDRL_SIZEOF_DATA == 8 + return cpl_image_get_data_double(image); +#else + return cpl_image_get_data_float(image); +#endif +} + +static inline cpl_error_code +hdrl_wrap_table(cpl_table * tb, hdrl_data_t * data, const char * name) +{ +#if HDRL_SIZEOF_DATA == 8 + return cpl_table_wrap_double(tb, data, name); +#else + return cpl_table_wrap_float(tb, data, name); +#endif +} + +static inline hdrl_error_t * hdrl_get_image_error(cpl_image * image) +{ +#if HDRL_SIZEOF_ERROR == 8 + return cpl_image_get_data_double(image); +#else + return cpl_image_get_data_float(image); +#endif +} + + +static inline const +hdrl_data_t * hdrl_get_image_data_const(const cpl_image * image) +{ +#if HDRL_SIZEOF_DATA == 8 + return cpl_image_get_data_double_const(image); +#else + return cpl_image_get_data_float_const(image); +#endif +} + +static inline const +hdrl_error_t * hdrl_get_image_error_const(const cpl_image * image) +{ +#if HDRL_SIZEOF_ERROR == 8 + return cpl_image_get_data_double_const(image); +#else + return cpl_image_get_data_float_const(image); +#endif +} + +#ifndef HDRL_ATTR_UNUSED + #if defined(__GNUC__) || defined(__ICC) || defined(__clang__) + #define HDRL_ATTR_UNUSED __attribute__ ((__unused__)) + #else + #define HDRL_ATTR_UNUSED + #endif +#endif + +/* Use this to tag a variable as not used. It will remove unused variable + * warning and mangle the variable to avoid accidental use */ +#define HDRL_UNUSED(x) (__HDRL_UNUSED_TAGGED ## x) HDRL_ATTR_UNUSED + +#endif + +CPL_END_DECLS + +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/igam.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/igam.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/igam.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/igam.c 2017-08-28 08:09:28.000000000 +0000 @@ -0,0 +1,249 @@ +/* +igam.c from torch-cephes which is a BSD licensed redistribution of cephes [0] +Minor modifications to use C99 lgamma and removed K&R syntax. + +[0] https://github.com/jucor/torch-cephes/blob/master/LICENSE.txt + +Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the organization nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* + * Incomplete gamma integral -> igam.c + * + * + * + * SYNOPSIS: + * + * double a, x, y, igam(); + * + * y = igam( a, x ); + * + * DESCRIPTION: + * + * The function is defined by + * + * x + * - + * 1 | | -t a-1 + * igam(a,x) = ----- | e t dt. + * - | | + * | (a) - + * 0 + * + * + * In this implementation both arguments must be positive. + * The integral is evaluated by either a power series or + * continued fraction expansion, depending on the relative + * values of a and x. + * + * ACCURACY: + * + * Relative error: + * arithmetic domain # trials peak rms + * IEEE 0,30 200000 3.6e-14 2.9e-15 + * IEEE 0,100 300000 9.9e-14 1.5e-14 + */ + +/* + * Complemented incomplete gamma integral --> igamc() + * + * + * + * SYNOPSIS: + * + * double a, x, y, igamc(); + * + * y = igamc( a, x ); + * + * DESCRIPTION: + * + * The function is defined by + * + * + * igamc(a,x) = 1 - igam(a,x) + * + * inf. + * - + * 1 | | -t a-1 + * = ----- | e t dt. + * - | | + * | (a) - + * x + * + * + * In this implementation both arguments must be positive. + * The integral is evaluated by either a power series or + * continued fraction expansion, depending on the relative + * values of a and x. + * + * ACCURACY: + * + * Tested at random a, x. + * a x Relative error: + * arithmetic domain domain # trials peak rms + * IEEE 0.5,100 0,100 200000 1.9e-14 1.7e-15 + * IEEE 0.01,0.5 0,100 200000 1.4e-13 1.6e-15 + */ + +/* + * Cephes Math Library Release 2.8: June, 2000 + * Copyright 1985, 1987, 2000 by Stephen L. Moshier + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include + +double igam(double, double); +double igamc(double, double); + +#define MACHEP DBL_EPSILON +#define MAXLOG log(FLT_MAX) +#define mtherr(x, y) + +static double big = 4.503599627370496e15; +static double biginv = 2.22044604925031308085e-16; + +double igamc(double a, double x) +{ + double ans, ax, c, r, t, y, z; + double pkm1, pkm2, qkm1, qkm2; + + if ((x < 0) || ( a <= 0)) { + mtherr("igamc", DOMAIN); + return(NAN); + } + + if ((x < 1.0) || (x < a)) { + return(1. - igam(a,x)); + } + ax = a * log(x) - x - lgamma(a); + + if (ax < -MAXLOG) { + mtherr("igamc", UNDERFLOW); + return(0.); + } + ax = exp(ax); + + /* continued fraction */ + y = 1. - a; + z = x + y + 1.; + c = 0.; + pkm2 = 1.; + qkm2 = x; + pkm1 = x + 1.; + qkm1 = z * x; + ans = pkm1/qkm1; + + do { + c += 1.; + y += 1.; + z += 2.; + + double yc = y * c; + double pk = pkm1 * z - pkm2 * yc; + double qk = qkm1 * z - qkm2 * yc; + + if (qk != 0) { + r = pk / qk; + t = fabs((ans - r) / r); + ans = r; + } else { + t = 1.; + } + + pkm2 = pkm1; + pkm1 = pk; + qkm2 = qkm1; + qkm1 = qk; + + if (fabs(pk) > big) { + pkm2 *= biginv; + pkm1 *= biginv; + qkm2 *= biginv; + qkm1 *= biginv; + } + + } while(t > MACHEP); + + return( ans * ax ); +} + + +/* left tail of incomplete gamma function: +* +* inf. k +* a -x - x +* x e > ---------- +* - - +* k=0 | (a+k+1) +* +*/ + +double igam(double a, double x) +{ + double ans, ax, c, r; + + /* Check zero integration limit first */ + if (x == 0) { + return(0.); + } + + if ((x < 0) || (a <= 0)) { + mtherr("igam", DOMAIN); + return(NAN); + } + + if ((x > 1.) && (x > a)) { + return(1. - igamc(a,x)); + } + + /* Compute x**a * exp(-x) / gamma(a) */ + ax = a * log(x) - x - lgamma(a); + if (ax < -MAXLOG) { + mtherr("igam", UNDERFLOW); + return(0.); + } + ax = exp(ax); + + /* power series */ + r = a; + c = 1.; + ans = 1.; + + do { + r += 1.; + c *= x / r; + ans += c; + + } while(c/ans > MACHEP); + + return(ans * ax / a); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/cpl-pipeline.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/cpl-pipeline.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/cpl-pipeline.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/cpl-pipeline.m4 2016-12-13 10:30:12.000000000 +0000 @@ -0,0 +1,112 @@ +# ESO_CHECK_CPL +#--------------- +# Checks for the CPL libraries and header files. Intended for use by pipelines +# Sets: +# CPL_INCLUDES +# CPL_LDFLAGS +# LIBCPLCORE +# LIBCPLDRS +# LIBCPLUI +# LIBCPLDFS +# LIBCEXT +AC_DEFUN([ESO_CHECK_CPL], +[ + + AC_MSG_CHECKING([for CPL]) + + # assumes if one is there all are there as there is no way to do a partial + # install with cpl + cpl_check_cpl_lib="-lcplcore" + + cpl_includes="" + cpl_ldflags="" + + AC_ARG_WITH(cpl, + AS_HELP_STRING([--with-cpl], + [location where CPL is installed]), + [ + cpl_with_cpl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + cpl_with_cpl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + ]) + + AC_ARG_WITH(cpl-includes, + AS_HELP_STRING([--with-cpl-includes], + [location of the CPL header files]), + cpl_with_cpl_includes=$withval) + + AC_ARG_WITH(cpl-libs, + AS_HELP_STRING([--with-cpl-libs], + [location of the CPL library]), + cpl_with_cpl_libs=-L$withval) + + AC_ARG_ENABLE(cpl-test, + AS_HELP_STRING([--disable-cpl-test], + [disables checks for the CPL library and headers]), + cpl_enable_cpl_test=$enableval, + cpl_enable_cpl_test=yes) + + + if test "x$cpl_enable_cpl_test" = xyes; then + + AC_MSG_CHECKING(checking for cpl) + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$cpl_with_cpl_libs"; then + LDFLAGS="$cpl_with_cpl_libs" + elif test -n "$CPLDIR"; then + LDFLAGS="-L$CPLDIR/lib -L$CPLDIR/lib64 -L$CPLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$cpl_with_cpl_includes"; then + CFLAGS="-I$cpl_with_cpl_includes" + elif test -n "$CPLDIR"; then + CFLAGS="-I$CPLDIR/include" + else + CFLAGS="" + fi + LIBS=$cpl_check_cpl_lib + + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[cpl_init(0);]])],[ + AC_MSG_RESULT(yes) + cpl_includes=$CFLAGS + cpl_ldflags=$LDFLAGS + ],[ + AC_MSG_ERROR([CPL not found]) + ]) + + # Set up the symbols + + CPL_INCLUDES="$cpl_includes" + CPL_LDFLAGS="$cpl_ldflags" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + LIBCPLCORE='-lcplcore' + LIBCPLDRS='-lcpldrs' + LIBCPLUI='-lcplui' + LIBCPLDFS='-lcpldfs' + LIBCEXT='-lcext' + else + AC_MSG_RESULT([disabled]) + AC_MSG_WARN([CPL checks have been disabled! This package may not build!]) + CPL_INCLUDES="" + CPL_LDFLAGS="" + LIBCPLCORE="" + LIBCPLDRS="" + LIBCPLUI="" + LIBCPLDFS="" + LIBCEXT="" + fi + + AC_SUBST(CPL_INCLUDES) + AC_SUBST(CPL_LDFLAGS) + AC_SUBST(LIBCPLCORE) + AC_SUBST(LIBCPLDRS) + AC_SUBST(LIBCPLUI) + AC_SUBST(LIBCPLDFS) + AC_SUBST(LIBCEXT) +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/eso.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/eso.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/eso.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/eso.m4 2017-09-05 11:58:51.000000000 +0000 @@ -0,0 +1,1156 @@ +# ESO_PROG_CC_FLAG(FLAG, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +#----------------------------------------------------------------- +AC_DEFUN([ESO_PROG_CC_FLAG], +[ + AC_REQUIRE([AC_PROG_CC]) + + flag=`echo $1 | sed 'y%.=/+-%___p_%'` + AC_CACHE_CHECK([whether $CC supports -$1], + [eso_cv_prog_cc_$flag], + [ + eval "eso_cv_prog_cc_$flag=no" + AC_LANG_PUSH(C) + + echo 'int main() { return 0; }' >conftest.$ac_ext + + try_compile="`$CC -$1 -c conftest.$ac_ext 2>&1`" + if test -z "$try_compile"; then + try_link="`$CC -$1 -o conftest$ac_exeext \ + conftest.$ac_ext 2>&1`" + if test -z "$try_link"; then + eval "eso_cv_prog_cc_$flag=yes" + fi + fi + rm -f conftest* + + AC_LANG_POP(C) + ]) + + if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then + : + $2 + else + : + $3 + fi +]) + + +# ESO_PROG_CC_ATTRIBUTE(VARIANT1, [VARIANT2], [CODE], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +#---------------------------------------------------------------------------------------------- +AC_DEFUN([ESO_PROG_CC_ATTRIBUTE], +[ + + AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))], + AS_TR_SH([eso_cv_prog_cc_attribute_$1]), + [ + eso_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS" + + AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])], + [eval "AS_TR_SH([eso_cv_prog_cc_attribute_$1])='yes'"], + [eval "AS_TR_SH([eso_cv_prog_cc_attribute_$1])='no'"]) + CFLAGS="$eso_save_CFLAGS" + ]) + + if eval "test x\$AS_TR_SH([eso_cv_prog_cc_attribute_$1]) = xyes"; then + : + $4 + else + : + $5 + fi + +]) + + +# ESO_PROG_CC_ATTRIBUTE_VISIBILITY(ARG, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +#-------------------------------------------------------------------------------- +AC_DEFUN([ESO_PROG_CC_ATTRIBUTE_VISIBILITY], +[ + + ESO_PROG_CC_ATTRIBUTE([visibility_$1], [visibility("$1")], + [void __attribute__((visibility("$1"))) $1_function() { }], + [$2], [$3]) + +]) + + +# ESO_ENABLE_DEBUG(debug=no) +#--------------------------- +AC_DEFUN([ESO_ENABLE_DEBUG], +[ + AC_REQUIRE([AC_PROG_CC]) + + AC_ARG_ENABLE(debug, + AS_HELP_STRING([--enable-debug], + [creates debugging code [default=$1]]), + eso_enable_debug=$enableval, eso_enable_debug=$1) + + AC_CACHE_CHECK([whether debugging code should be created], + eso_cv_enable_debug, + eso_cv_enable_debug=$eso_enable_debug) + + if test x"$eso_cv_enable_debug" = xyes; then + + eso_clean_CFLAGS="`echo $CFLAGS | sed -e 's/-O[[0-9]]//g' \ + -e 's/-g[[0-9]]//g' \ + -e 's/-g[[a-z,A-Z]]* / /g' \ + -e 's/-[[Og]]//g'`" + + ESO_PROG_CC_FLAG([g3], [CFLAGS="$CFLAGS -g3"]) + + if test x"$eso_cv_prog_cc_g3" = xyes; then + CFLAGS="-g3" + else + if test x"$ac_cv_prog_cc_g" = xyes; then + CFLAGS="-g" + else + CFLAGS="" + fi + fi + + ESO_PROG_CC_FLAG([ggdb], [CFLAGS="$CFLAGS -ggdb"]) + ESO_PROG_CC_FLAG([O0], [CFLAGS="$CFLAGS -O0"]) + ESO_PROG_CC_FLAG([rdynamic], [CFLAGS="$CFLAGS -rdynamic"]) + ESO_PROG_CC_FLAG([Wall], [CFLAGS="$CFLAGS -Wall"]) + ESO_PROG_CC_FLAG([W], [CFLAGS="$CFLAGS -W"]) + + CFLAGS="$CFLAGS $eso_clean_CFLAGS" + ESO_DEBUG_FLAGS="-DESO_ENABLE_DEBUG" + else + ESO_DEBUG_FLAGS="-DNDEBUG" + fi + + AC_SUBST(ESO_DEBUG_FLAGS) +]) + + +# ESO_ENABLE_TSAN(tsan=no) +# add option to enable gcc and clangs thread sanitizer, needs sanitized +# libgomp, cpl and esorex to be effective. These can be retrieved from jenkins. +#--------------------------- +AC_DEFUN([ESO_ENABLE_TSAN], +[ + AC_ARG_ENABLE(tsan, + AS_HELP_STRING([--enable-tsan], + [compiles with thread sanitizer, may need + sanitized libgomp, cpl and esorex to be effective. + [[default=$1]]]), + eso_enable_tsan=$enableval, eso_enable_tsan=$1) + + if test x"$eso_enable_tsan" = xyes; then + ESO_PROG_CC_FLAG([fsanitize=thread], [CFLAGS="$CFLAGS -fsanitize=thread" + LDFLAGS="$LDFLAGS -fsanitize=thread"]) + fi +]) + +# ESO_ENABLE_ASAN(asan=no) +# add option to enable gcc and clangs address sanitizer, needs sanitized +# cpl to be effective. This can be retrieved from jenkins. +# Note that valgrind does more than asan, but slower +#--------------------------- +AC_DEFUN([ESO_ENABLE_ASAN], +[ + AC_ARG_ENABLE(asan, + AS_HELP_STRING([--enable-asan], + [compiles with address sanitizer, may need + sanitized cpl to be effective. + [[default=$1]]]), + eso_enable_asan=$enableval, eso_enable_asan=$1) + + if test x"$eso_enable_asan" = xyes; then + ESO_PROG_CC_FLAG([fsanitize=address], [CFLAGS="$CFLAGS -fsanitize=address" + LDFLAGS="$LDFLAGS -fsanitize=address"]) + fi +]) + + +# ESO_ENABLE_STRICT(strict=no) +#----------------------------- +AC_DEFUN([ESO_ENABLE_STRICT], +[ + AC_REQUIRE([AC_PROG_EGREP]) + AC_REQUIRE([AC_PROG_CC]) + + AC_ARG_ENABLE(strict, + AS_HELP_STRING([--enable-strict], + [compiles with strict compiler options (may not work!) [default=$1]]), + eso_enable_strict=$enableval, eso_enable_strict=$1) + + AC_CACHE_CHECK([whether strict compiler options should be used], + eso_cv_enable_strict, + eso_cv_enable_strict=$eso_enable_strict) + + + if test x"$eso_cv_enable_strict" = xyes; then + + eso_enable_strict_std_set=no + + if test -n "$CFLAGS"; then + echo $CFLAGS | $EGREP '(\-std=|-ansi)' >/dev/null 2>&1 + if test x"$?" = x0; then + eso_enable_strict_std_set=yes + fi + fi + + if test x"$eso_enable_strict_std_set" = xno; then + ESO_PROG_CC_FLAG([std=c99], [CFLAGS="$CFLAGS -std=c99"]) + fi + + ESO_PROG_CC_FLAG([pedantic], [CFLAGS="$CFLAGS -pedantic"]) + + fi +]) + + +# ESO_ENABLE_PROFILE(profile=no) +#----------------------------- +AC_DEFUN([ESO_ENABLE_PROFILE], +[ + AC_REQUIRE([AC_PROG_CC]) + + AC_ARG_ENABLE(profile, + AS_HELP_STRING([--enable-profile], + [compiles with compiler options necessary for profiling (may not work!) [default=$1]]), + eso_enable_profile=$enableval, eso_enable_profile=$1) + + AC_CACHE_CHECK([whether profiling compiler options should be used], + eso_cv_enable_profile, + eso_cv_enable_profile=$eso_enable_profile) + + + if test x"$eso_cv_enable_profile" = xyes; then + ESO_PROG_CC_FLAG([pg], [CFLAGS="$CFLAGS -pg"]) + ESO_PROG_CC_FLAG([g], [CFLAGS="$CFLAGS -g"]) + ESO_PROG_CC_FLAG([static-libgcc], [CFLAGS="$CFLAGS -static-libgcc"]) + + AC_ENABLE_SHARED(no) + AC_ENABLE_STATIC(yes) + fi +]) + + +# ESO_CHECK_DOCTOOLS +#------------------- +AC_DEFUN([ESO_CHECK_DOCTOOLS], +[ + AC_ARG_VAR([DOXYGEN], [doxygen command]) + AC_PATH_PROG([DOXYGEN], [doxygen]) + + AC_ARG_VAR([LATEX], [latex command]) + AC_PATH_PROG([LATEX], [latex]) + + + if test -z "${DOXYGEN}"; then + DOXYGEN=":" + fi + + if test -z "${LATEX}"; then + LATEX=":" + fi + +]) + + +# ESO_PROG_AR +#------------ +# Checks if ar is in the path +AC_DEFUN([ESO_PROG_AR], +[ + AC_CHECK_PROG(AR, ar, ar, NONE) + + if test x"$AR" = xNONE; then + AC_MSG_ERROR([Cannot find \'ar\']) + fi + +]) + + +# ESO_PROG_PKGCONFIG +#------------------- +# Checks if pkg-config is in the path +AC_DEFUN([ESO_PROG_PKGCONFIG], +[ + AC_ARG_VAR([PKGCONFIG], [pkg-config command]) + AC_CHECK_PROG([PKGCONFIG], [pkg-config], [pkg-config]) + +]) + + +# ESO_CHECK_EXTRA_LIBS +#--------------------- +# Check for non-standard headers and libraries +AC_DEFUN([ESO_CHECK_EXTRA_LIBS], +[ + + AC_ARG_WITH(extra-includes, + AS_HELP_STRING([--with-extra-includes=DIR], + [adds non standard include paths]), + eso_with_extra_includes=$withval, eso_with_extra_includes=NONE) + + AC_ARG_WITH(extra-libs, + AS_HELP_STRING([--with-extra-libs=DIR], + [adds non standard library paths]), + eso_with_extra_libs=$withval, eso_with_extra_libs=NONE) + + AC_MSG_CHECKING([for extra includes]) + AC_CACHE_VAL([eso_cv_with_extra_includes], + [ + eso_cv_with_extra_includes=$eso_with_extra_includes + ]) + + if test x"$eso_cv_with_extra_includes" != xNONE; then + eso_save_IFS=$IFS + IFS=':' + + for dir in $eso_cv_with_extra_includes; do + EXTRA_INCLUDES="$EXTRA_INCLUDES -I$dir" + done + + IFS=$eso_save_IFS + AC_MSG_RESULT(added) + else + AC_MSG_RESULT(no) + fi + + + AC_MSG_CHECKING([for extra libs]) + AC_CACHE_VAL([eso_cv_with_extra_libs], + [ + eso_cv_with_extra_libs=$eso_with_extra_libs + ]) + + if test x"$eso_cv_with_extra_libs" != xNONE; then + eso_save_IFS=$IFS + IFS=':' + + for dir in $eso_cv_with_extra_libs; do + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$dir" + done + + IFS=$eso_save_IFS + AC_MSG_RESULT(added) + else + AC_MSG_RESULT(no) + fi + +]) + + +# ESO_CHECK_THREADS_POSIX +#------------------------ +# Check whether the POSIX threads are available. The cached result is +# set to 'yes' if either the compiler supports the '-pthread' flag, or linking +# with the POSIX thread library works, and the header file defining the POSIX +# threads symbols is present. If POSIX threads are not supported, the +# result is set to 'no'. Whether the compiler supports POSIX threads, +# or whether the library, and the header are available is stored in cache +# variables. +AC_DEFUN([ESO_CHECK_THREADS_POSIX], +[ + AC_REQUIRE([AC_PROG_CC]) + + ESO_PROG_CC_FLAG([pthread], [], []) + + AC_CHECK_LIB([pthread], [pthread_create], + [eso_threads_have_libpthread=yes], + [eso_threads_have_libpthread=no]) + + AC_CHECK_HEADER([pthread.h], + [eso_threads_have_pthread_h=yes], + [eso_threads_have_pthread_h=no]) + + if test x"$eso_threads_have_pthread_h" != xyes; then + eso_threads_posix=no + else + if test x"$eso_threads_have_libpthread" != xyes && \ + test x"$eso_cv_prog_cc_pthread" != xyes; then + eso_threads_posix=no + else + eso_threads_posix=yes + fi + fi + + + # Setup the POSIX thread symbols + + if test x"$eso_threads_have_pthread_h" = xyes; then + AC_DEFINE([HAVE_PTHREAD_H], [1], + [Define to 1 if you have .]) + fi + + if test x"$eso_threads_posix" = xyes; then + + if test x"$eso_cv_prog_cc_pthread" = xyes; then + PTHREAD_CFLAGS="-pthread" + else + PTHREAD_CFLAGS="" + fi + + if test x"$eso_threads_have_libpthread" = xyes; then + LIBPTHREAD="-lpthread" + else + LIBPTHREAD="" + fi + + fi + + AC_CACHE_VAL(eso_cv_threads_posix_header, + eso_cv_threads_posix_header=$eso_threads_have_pthread_h) + AC_CACHE_VAL(eso_cv_threads_posix_lib, + eso_cv_threads_posix_lib=$eso_threads_have_libpthread) + AC_CACHE_VAL(eso_cv_threads_posix_flags, + eso_cv_threads_posix_flags=$eso_cv_prog_cc_pthread) + AC_CACHE_VAL(eso_cv_threads_posix, + eso_cv_threads_posix=$eso_threads_posix) + + AC_SUBST(PTHREAD_CFLAGS) + AC_SUBST(LIBPTHREAD) + +]) + + +# ESO_CHECK_FUNC(FUNCTION, INCLUDES, SYMBOL) +#------------------------------------------- +# Checks whether a function is available and declared. +AC_DEFUN([ESO_CHECK_FUNC], +[ + + AC_LANG_PUSH(C) + + AC_CHECK_DECL($1, [], [], [$2]) + + eso_save_CFLAGS="$CFLAGS" + + if test x"$GCC" = xyes; then + CFLAGS="$CFLAGS -pedantic-errors" + fi + + AC_CHECK_FUNC($1) + + CFLAGS="$eso_save_CFLAGS" + + AC_LANG_POP(C) + + if test x"$ac_cv_have_decl_$1" = xyes && + test x"$ac_cv_func_$1" = xyes; then + AC_DEFINE($3) + fi + +]) + + +# ESO_FUNC_VSNPRINTF_C99 +#----------------------- +# Check whether vsnprintf() has C99 semantics. +AC_DEFUN([ESO_FUNC_VSNPRINTF_C99], +[ + + AH_TEMPLATE([HAVE_VSNPRINTF_C99], + [Define if you have the C99 `vsnprintf' function.]) + + AC_CACHE_CHECK([whether vsnprintf has C99 semantics], + [eso_cv_func_vsnprintf_c99], + [ + AC_LANG_PUSH(C) + + eso_cppflags_save="$CPPFLAGS" + eso_cflags_save="$CFLAGS" + eso_ldflags_save="$LDFLAGS" + eso_libs_save="$LIBS" + + if test x$GCC = xyes; then + CFLAGS="$CFLAGS -pedantic-errors" + CPPFLAGS="$CPPFLAGS $CFLAGS" + fi + + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +#include +#include + +int +doit(char * s, ...) +{ + char buffer[32]; + va_list args; + int q, r; + + va_start(args, s); + q = vsnprintf(NULL, 0, s, args); + r = vsnprintf(buffer, 5, s, args); + va_end(args); + + if (q != 7 || r != 7) + exit(1); + + exit(0); +} +]], +[[ + doit((char*)"1234567"); + exit(1); +]]) + ], + [eso_cv_func_vsnprintf_c99=yes], + [eso_cv_func_vsnprintf_c99=no], + [eso_cv_func_vsnprintf_c99=no]) + + CPPFLAGS="$eso_cppflags_save" + CFLAGS="$eso_cflags_save" + LDFLAGS="$eso_ldflags_save" + LIBS="$eso_libs_save" + + AC_LANG_POP(C) + ]) + +# Note that the default is to be pessimistic in the case of cross compilation. +# If you know that the target has a C99 vsnprintf(), you can get around this +# by setting eso_func_vsnprintf_c99 to yes, as described in the Autoconf +# manual. + + if test x$eso_cv_func_vsnprintf_c99 = xyes; then + AC_DEFINE(HAVE_VSNPRINTF_C99) + fi + +]) + + +# ESO_CHECK_PRINTF_FORMATS +#------------------------- +# Checks for printf() format peculiarities. +AC_DEFUN([ESO_CHECK_PRINTF_FORMATS], +[ + + # Check if string format for NULL is `(null)' + + AH_TEMPLATE([HAVE_PRINTF_STR_FMT_NULL], + [Define if printf outputs `(null)' when printing NULL using + `%s']) + + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +#include +]], +[[ + char s[128]; + + sprintf(s, "%s", NULL); + return strncmp(s, "(null)", 6) ? 1 : 0; +]]) + ], + [eso_have_printf_str_format_null=yes], + [eso_have_printf_str_format_null=no], + [eso_have_printf_str_format_null=no]) + + if test x$eso_have_printf_str_format_null = xyes; then + AC_DEFINE(HAVE_PRINTF_STR_FMT_NULL) + fi + + + # Check if pointer format for NULL is `(nil)' + + AH_TEMPLATE([HAVE_PRINTF_PTR_FMT_NIL], + [Define if printf outputs `(nil)' when printing NULL using + `%p']) + + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +#include +]], +[[ + char s[128]; + + sprintf(s, "%p", NULL); + return strncmp(s, "(nil)", 5) ? 1 : 0; +]]) + ], + [eso_have_printf_ptr_format_nil=yes], + [eso_have_printf_ptr_format_nil=no], + [eso_have_printf_ptr_format_nil=no]) + + if test x$eso_have_printf_ptr_format_nil = xyes; then + AC_DEFINE(HAVE_PRINTF_PTR_FMT_NIL) + fi + + + # Check if output for `%p' is the same as `%#x' + + AH_TEMPLATE([HAVE_PRINTF_PTR_FMT_ALTERNATE], + [Define if printf format `%p' produces the same output as + `%#x' or `%#lx']) + + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +#include +]], +[[ + char s1[128], s2[128]; + + sprintf(s1, "%p", s1); + sprintf(s2, "%#x", s1); + return strncmp(s1, s2, 3) ? 1 : 0; +]]) + ], + [eso_have_printf_ptr_format_alternate=yes], + [eso_have_printf_ptr_format_alternate=no], + [eso_have_printf_ptr_format_alternate=no]) + + if test x$eso_have_printf_ptr_format_alternate = xyes; then + AC_DEFINE(HAVE_PRINTF_PTR_FMT_ALTERNATE) + fi + + + # Check if pointers are treated as signed + + AH_TEMPLATE([HAVE_PRINTF_PTR_FMT_SIGNED], + [Define if printf treats pointers as signed when using a sign + flag]) + + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +]], +[[ + char s[128]; + + sprintf(s, "%+p", s); + return s[0] == '+' ? 0 : 1; +]]) + ], + [eso_have_printf_ptr_format_signed=yes], + [eso_have_printf_ptr_format_signed=no], + [eso_have_printf_ptr_format_signed=no]) + + if test x$eso_have_printf_ptr_format_signed = xyes; then + AC_DEFINE(HAVE_PRINTF_PTR_FMT_SIGNED) + fi + + + # Check if default precision for conversion specifier `g' is 1 (as + # required by ISO C) or 6. + + AH_TEMPLATE([HAVE_PRINTF_FLT_FMT_G_STD], + [Define if printf default precision for format `g' is 1 + (ISO C standard) or 6]) + + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +]], +[[ + char s1[128], s2[128]; + int n1, n2; + + sprintf(s1, "%g%n", 1.123456, &n1); + sprintf(s2, "%.1g%n", 1.123456, &n2); + return n1 > n2 ? 1 : 0; +]]) + ], + [eso_have_printf_flt_format_g_std=yes], + [eso_have_printf_flt_format_g_std=no], + [eso_have_printf_flt_format_g_std=no]) + + if test x$eso_have_printf_flt_format_g_std = xyes; then + AC_DEFINE(HAVE_PRINTF_FLT_FMT_G_STD) + fi + +]) + + +# ESO_FUNC_VSNPRINTF +#------------------- +# Checks for vsnprintf and snprintf declaration and function. +AC_DEFUN([ESO_FUNC_VSNPRINTF], +[ + + eso_compile_snprintf=no + + AH_TEMPLATE([HAVE_VSNPRINTF], + [Define if you have the `vsnprintf' function]) + ESO_CHECK_FUNC(vsnprintf, [ +#include +#include + ], HAVE_VSNPRINTF) + + if test x$ac_cv_func_vsnprintf = xyes && + test x$ac_cv_have_decl_vsnprintf = xyes; then + + ESO_FUNC_VSNPRINTF_C99 + + if test x$eso_cv_func_vsnprintf_c99 != xyes; then + eso_compile_snprintf=yes + fi + + else + eso_compile_snprintf=yes + fi + + if test x$eso_compile_snprintf = xyes; then + if test -n "$LIBTOOL"; then + SNPRINTF=snprintf.lo + else + SNPRINTF=snprintf.$ac_objext + fi + fi + + AC_SUBST(SNPRINTF) + + # The symbols defined by the following macro are only needed to setup the + # vsnprintf() replacement. May be useless if the vsnprintf implementation + # changes. + ESO_CHECK_PRINTF_FORMATS + + AH_TEMPLATE([HAVE_SNPRINTF], + [Define if you have the `snprintf' function]) + ESO_CHECK_FUNC(snprintf, [#include ], HAVE_SNPRINTF) + +]) + + +# ESO_FUNC_VASPRINTF +#------------------- +# Checks for vasprintf and asprintf declaration and function. +AC_DEFUN([ESO_FUNC_VASPRINTF], +[ + + AH_TEMPLATE([HAVE_VASPRINTF], + [Define if you have the `vasprintf' function]) + ESO_CHECK_FUNC(vasprintf, [ +#include +#include + ], HAVE_VASPRINTF) + + AH_TEMPLATE([HAVE_ASPRINTF], + [Define if you have the `asprintf' function]) + ESO_CHECK_FUNC(asprintf, [ +#include + ], HAVE_ASPRINTF) + +]) + + +# ESO_FUNC_FPATHCONF +#------------------- +# Checks for fpathconf declaration and function. +AC_DEFUN([ESO_FUNC_FPATHCONF], +[ + + AH_TEMPLATE([HAVE_FPATHCONF], + [Define if you have the `fpathconf' function]) + ESO_CHECK_FUNC(fpathconf, [#include ], HAVE_FPATHCONF) + + # If we have fpathconf we should also have pathconf, but who knows. + AH_TEMPLATE([HAVE_PATHCONF], + [Define if you have the `pathconf' function]) + ESO_CHECK_FUNC(pathconf, [#include ], HAVE_PATHCONF) + +]) + + +# ESO_FUNC_SYSCONF +#----------------- +# Checks for sysconf declaration and function. +AC_DEFUN([ESO_FUNC_SYSCONF], +[ + + AH_TEMPLATE([HAVE_SYSCONF], + [Define if you have the `sysconf' function]) + ESO_CHECK_FUNC(sysconf, [#include ], HAVE_SYSCONF) + +]) + + +# ESO_FUNC_GETOPT +#---------------- +# Checks for GNU getopt_long declaration and function. +AC_DEFUN([ESO_FUNC_GETOPT], +[ + + AH_TEMPLATE([HAVE_GETOPT_LONG], + [Define if you have the `getopt_long' function]) + + ESO_CHECK_FUNC(getopt_long, [#include ], HAVE_GETOPT_LONG) + + if test x"$ac_cv_func_getopt_long" = xno || + test x"$eso_cv_have_decl_getopt_long" = xno; then + if test -n "$LIBTOOL"; then + GETOPT="getopt.lo getopt1.lo" + else + GETOPT="getopt.$ac_objext getopt1.$ac_objext" + fi + fi + + AC_SUBST(GETOPT) + + +]) + + +# ESO_FUNC_GETPWUID +#------------------ +# Checks for getpwuid declaration and function. +AC_DEFUN([ESO_FUNC_GETPWUID], +[ + + AH_TEMPLATE([HAVE_GETPWUID], + [Define if you have the `getpwuid' function]) + + ESO_CHECK_FUNC(getpwuid, [#include ], HAVE_GETPWUID) + +]) + + +# ESO_FUNC_GETUID +#---------------- +AC_DEFUN([ESO_FUNC_GETUID], +[ + + AH_TEMPLATE([HAVE_GETUID], + [Define if you have the `getuid' function]) + + ESO_CHECK_FUNC(getuid, [#include ], HAVE_GETUID) + +]) + + +# ESO_FUNC_LSTAT +#--------------- +AC_DEFUN([ESO_FUNC_LSTAT], +[ + + AH_TEMPLATE([HAVE_LSTAT], + [Define if you have the `lstat' function]) + + ESO_CHECK_FUNC(lstat, [#include ], HAVE_LSTAT) + +]) + + +# ESO_FUNC_STRDUP +#---------------- +AC_DEFUN([ESO_FUNC_STRDUP], +[ + + AH_TEMPLATE([HAVE_STRDUP], + [Define if you have the `strdup' function]) + + ESO_CHECK_FUNC(strdup, [#include ], HAVE_STRDUP) + + AH_BOTTOM([ +#ifndef HAVE_STRDUP +# define strdup cx_strdup +#endif + ]) +]) + + +# ESO_FUNC_STPCPY +#---------------- +AC_DEFUN([ESO_FUNC_STPCPY], +[ + + AH_TEMPLATE([HAVE_STPCPY], + [Define if you have the `stpcpy' function]) + + ESO_CHECK_FUNC(stpcpy, [#include ], HAVE_STPCPY) + +]) + + +# ESO_FUNC_SYMLINK +#----------------- +AC_DEFUN([ESO_FUNC_SYMLINK], +[ + + AH_TEMPLATE([HAVE_SYMLINK], + [Define if you have the `symlink' function]) + + ESO_CHECK_FUNC(symlink, [#include ], HAVE_SYMLINK) + +]) + + +# ESO_FUNC_WORDEXP +#----------------- +AC_DEFUN([ESO_FUNC_WORDEXP], +[ + + AH_TEMPLATE([HAVE_WORDEXP], + [Define if you have the `wordexp' function]) + + ESO_CHECK_FUNC(wordexp, [#include ], HAVE_WORDEXP) + +]) + + +# ESO_FUNC_GETTIMEOFDAY +#---------------------- +AC_DEFUN([ESO_FUNC_GETTIMEOFDAY], +[ + + AH_TEMPLATE([HAVE_GETTIMEOFDAY], + [Define if you have the `gettimeofday' function]) + + ESO_CHECK_FUNC(gettimeofday, + [ + #include + #include + ], + HAVE_GETTIMEOFDAY) +]) + + +# ESO_FUNC_VA_COPY(symbol) +#------------------------- +# Check for an implementation of va_copy(). The argument which must be +# given is the preprocessor symbol that is defined to be either va_copy +# or __va_copy depending on the available function, provided that an +# implementation of va_copy is available at all. +AC_DEFUN([ESO_FUNC_VA_COPY], +[ + + # Check for all three va_copy possibilities, so we get + # all results in config.log for bug reports. + + # Check for availability of va_copy(). This is ISO C. Available with + # gcc since version 3.0. + AC_CACHE_CHECK([for an implementation of va_copy()], + [eso_cv_have_va_copy], + [ + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#ifdef HAVE_STDARG_H +#include +#endif + +void f(int i, ...) +{ + va_list args1, args2; + va_start (args1, i); + va_copy (args2, args1); + + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + + va_end (args1); + va_end (args2); +} +]], +[[ + f(0, 42); +]]) + ], + [eso_cv_have_va_copy=yes], + [eso_cv_have_va_copy=no], + [eso_cv_have_va_copy=no]) + ]) + + + # Check for availability of __va_copy(). Some compilers provide + # this. Available with gcc since version 2.8.1. + AC_CACHE_CHECK([for an implementation of __va_copy()], + [eso_cv_have__va_copy], + [ + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#ifdef HAVE_STDARG_H +#include +#endif + +void f(int i, ...) +{ + va_list args1, args2; + + va_start (args1, i); + __va_copy (args2, args1); + + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + + va_end (args1); + va_end (args2); +} +]], +[[ + f(0, 42); +]]) + ], + [eso_cv_have__va_copy=yes], + [eso_cv_have__va_copy=no], + [eso_cv_have__va_copy=no]) + ]) + + AH_TEMPLATE([HAVE_VA_COPY], + [Define if you have an implementation of `va_copy()'.]) + AH_TEMPLATE([HAVE___VA_COPY], + [Define if you have an implementation of `__va_copy()'.]) + + if test "x$eso_cv_have_va_copy" = "xyes"; then + eso_func_va_copy=va_copy + AC_DEFINE(HAVE_VA_COPY) + else + if test "x$eso_cv_have__va_copy" = "xyes"; then + eso_func_va_copy=__va_copy + AC_DEFINE(HAVE___VA_COPY) + fi + fi + + AH_TEMPLATE([HAVE_VA_COPY_STYLE_FUNCTION], + [Define if you have an implementation of a `va_copy()' style + function.]) + AH_TEMPLATE([$1], [A `va_copy()' style function]) + + if test -n "$eso_func_va_copy"; then + AC_DEFINE_UNQUOTED([$1], $eso_func_va_copy) + AC_DEFINE(HAVE_VA_COPY_STYLE_FUNCTION) + fi + + # Check whether va_lists can be copied by value + AC_CACHE_CHECK([whether va_lists can be copied by value], + [eso_cv_have_va_value_copy], + [ + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#ifdef HAVE_STDARG_H +#include +#endif + +void f(int i, ...) +{ + va_list args1, args2; + va_start (args1, i); + args2 = args1; + + if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42) + exit (1); + + va_end (args1); + va_end (args2); +} +]], +[[ + f(0, 42); +]]) + ], + [eso_cv_have_va_value_copy=yes], + [eso_cv_have_va_value_copy=no], + [eso_cv_have_va_value_copy=no]) + ]) + + AH_TEMPLATE([HAVE_VA_LIST_COPY_BY_VALUE], + [Define if `va_lists' can be copied by value]) + if test "x$eso_cv_have_va_value_copy" = "xyes"; then + AC_DEFINE(HAVE_VA_LIST_COPY_BY_VALUE) + fi + +]) + + +# ESO_FUNC_REALLOC_SANITY +#------------------------- +# Check whether realloc(NULL,) works. +AC_DEFUN([ESO_FUNC_REALLOC_SANITY], +[ + AC_CACHE_CHECK([whether realloc(NULL,) works], + [eso_cv_have_sane_realloc], + [ + AC_RUN_IFELSE( + [ +AC_LANG_PROGRAM( +[[ +#include +]], +[[ + return realloc (0, sizeof (int)) == 0; +]]) + ], + [eso_cv_have_sane_realloc=yes], + [eso_cv_have_sane_realloc=no], + [eso_cv_have_sane_realloc=no]) + ]) + + AH_TEMPLATE([HAVE_WORKING_REALLOC], + [Define if realloc(NULL,) works]) + + if test x$eso_cv_have_sane_realloc = xyes; then + AC_DEFINE(HAVE_WORKING_REALLOC) + fi + +]) + + +# ESO_FIND_FILE(file, directories, variable) +#------------------------------------------ +# Search for file in directories. Set variable to the first location +# where file was found, if file is not found at all variable is set to NO. +AC_DEFUN([ESO_FIND_FILE], +[ + $3=no + + for i in $2; do + for j in $1; do + + echo "configure: __oline__: $i/$j" >&AC_FD_CC + + if test -r "$i/$j"; then + echo "taking that" >&AC_FD_CC + $3=$i + break 2 + fi + done + done +]) + + +# ESO_SET_LIBRARY_VERSION([CURRENT], [REVISION], [AGE]) +#------------------------------------------------------ +# Sets the libtool versioning symbols LT_CURRENT, LT_REVISION, LT_AGE. +AC_DEFUN([ESO_SET_LIBRARY_VERSION], +[ + + if test -z "$1"; then + LT_CURRENT=0 + else + LT_CURRENT="$1" + fi + + if test -z "$2"; then + LT_REVISION=0 + else + LT_REVISION="$2" + fi + + if test -z "$3"; then + LT_AGE=0 + else + LT_AGE="$3" + fi + + AC_SUBST(LT_CURRENT) + AC_SUBST(LT_REVISION) + AC_SUBST(LT_AGE) +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/gsl.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/gsl.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/gsl.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/gsl.m4 2017-09-05 11:58:51.000000000 +0000 @@ -0,0 +1,123 @@ +# LIB_CHECK_GSL +#------------------ +# Checks for the gsl library and header files. +AC_DEFUN([CPL_CHECK_GSL], +[ + + AC_MSG_CHECKING([for gsl]) + + AC_ARG_WITH(gsl, + AS_HELP_STRING([--with-gsl], + [location where gsl is installed]), + [ + cpl_gsl_dir=$withval + ]) + + export PKG_CONFIG_PATH="$cpl_gsl_dir/lib/pkgconfig:$cpl_gsl_dir/lib64/pkgconfig:$GSLDIR/lib/pkgconfig/:$GSLDIR/lib64/pkgconfig/:$PKG_CONFIG_PATH" + + AC_SUBST(PKG_CONFIG_PATH) + PKG_CHECK_MODULES([GSL], [gsl], + [AC_DEFINE([HAVE_LIBGSL], [1], [Define to 1 iff you have GSL]) + AC_DEFINE(HAVE_GSL, 1, [Define to 1 iff you have GSL])], + AC_MSG_WARN([No GSL available])) + +]) + +# GSL_CHECK_LIBS +#--------------- +# Checks for the GSL libraries and header files, does not require pkg-config +# If the first argument is "optional" the check is allowed to fail, otherwise +# missing GSL is a fatal error +# adds --with-gsl{,-libs,-includes}, --disable-gsl-test and sets +# GSL_INCLUDES +# GSL_LDFLAGS +# GSL_LIBS +# It defines HAVE_GSL and HAVE_LIBGSL in config.h +AC_DEFUN([GSL_CHECK_LIBS], +[ + + AC_MSG_CHECKING([for GSL]) + + gsl_check_gsl_lib="-lgsl -lgslcblas" + + gsl_includes="" + gsl_libraries="" + + AC_ARG_WITH(gsl, + AS_HELP_STRING([--with-gsl], + [location where GSL is installed]), + [ + gsl_with_gsl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + gsl_with_gsl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + ]) + + AC_ARG_WITH(gsl-includes, + AS_HELP_STRING([--with-gsl-includes], + [location of the GSL header files]), + gsl_with_gsl_includes=$withval) + + AC_ARG_WITH(gsl-libs, + AS_HELP_STRING([--with-gsl-libs], + [location of the GSL library]), + gsl_with_gsl_libs=-L$withval) + + AC_ARG_ENABLE(gsl-test, + AS_HELP_STRING([--disable-gsl-test], + [disables checks for the GSL library and headers]), + gsl_enable_gsl_test=$enableval, + gsl_enable_gsl_test=yes) + + + if test "x$gsl_enable_gsl_test" = xyes; then + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$gsl_with_gsl_libs"; then + LDFLAGS="$gsl_with_gsl_libs" + elif test -n "$GSLDIR"; then + LDFLAGS="-L$GSLDIR/lib -L$GSLDIR/lib64 -L$GSLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$gsl_with_gsl_includes"; then + CFLAGS="-I$gsl_with_gsl_includes" + elif test -n "$GSLDIR"; then + CFLAGS="-I$GSLDIR/include" + else + CFLAGS="" + fi + LIBS=$gsl_check_gsl_lib + + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[gsl_sf_bessel_J0(5.);]])],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_GSL, 1, [Define to 1 iff you have GSL]) + AC_DEFINE(HAVE_LIBGSL, 1, [Define to 1 iff you have GSL]) + # Set up the symbols + GSL_INCLUDES="$CFLAGS" + GSL_LDFLAGS="$LDFLAGS" + GSL_LIBS="$gsl_check_gsl_lib" + ],[ + if test "x$1" = xoptional; then + AC_MSG_NOTICE([Optional GSL not found]) + else + AC_MSG_ERROR([GSL not found]) + fi + ]) + + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + else + AC_MSG_RESULT([disabled]) + AC_MSG_WARN([GSL checks have been disabled! This package may not build!]) + GSL_INCLUDES="" + GSL_LDFLAGS="" + GSL_LIBS="" + fi + + AC_SUBST(GSL_INCLUDES) + AC_SUBST(GSL_LDFLAGS) + AC_SUBST(GSL_LIBS) + +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/libtool.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/libtool.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/libtool.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/libtool.m4 2016-12-22 14:07:29.000000000 +0000 @@ -0,0 +1,8372 @@ +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +# +# Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc. +# Written by Gordon Matzigkeit, 1996 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +m4_define([_LT_COPYING], [dnl +# Copyright (C) 2014 Free Software Foundation, Inc. +# This is free software; see the source for copying conditions. There is NO +# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +# GNU Libtool 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 of the License, or +# (at your option) any later version. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program or library that is built +# using GNU Libtool, you may include this file under the same +# distribution terms that you use for the rest of that program. +# +# GNU Libtool 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, see . +]) + +# serial 58 LT_INIT + + +# LT_PREREQ(VERSION) +# ------------------ +# Complain and exit if this libtool version is less that VERSION. +m4_defun([LT_PREREQ], +[m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, + [m4_default([$3], + [m4_fatal([Libtool version $1 or higher is required], + 63)])], + [$2])]) + + +# _LT_CHECK_BUILDDIR +# ------------------ +# Complain if the absolute build directory name contains unusual characters +m4_defun([_LT_CHECK_BUILDDIR], +[case `pwd` in + *\ * | *\ *) + AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; +esac +]) + + +# LT_INIT([OPTIONS]) +# ------------------ +AC_DEFUN([LT_INIT], +[AC_PREREQ([2.62])dnl We use AC_PATH_PROGS_FEATURE_CHECK +AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +AC_BEFORE([$0], [LT_LANG])dnl +AC_BEFORE([$0], [LT_OUTPUT])dnl +AC_BEFORE([$0], [LTDL_INIT])dnl +m4_require([_LT_CHECK_BUILDDIR])dnl + +dnl Autoconf doesn't catch unexpanded LT_ macros by default: +m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl +m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl +dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 +dnl unless we require an AC_DEFUNed macro: +AC_REQUIRE([LTOPTIONS_VERSION])dnl +AC_REQUIRE([LTSUGAR_VERSION])dnl +AC_REQUIRE([LTVERSION_VERSION])dnl +AC_REQUIRE([LTOBSOLETE_VERSION])dnl +m4_require([_LT_PROG_LTMAIN])dnl + +_LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}]) + +dnl Parse OPTIONS +_LT_SET_OPTIONS([$0], [$1]) + +# This can be used to rebuild libtool when needed +LIBTOOL_DEPS=$ltmain + +# Always use our own libtool. +LIBTOOL='$(SHELL) $(top_builddir)/libtool' +AC_SUBST(LIBTOOL)dnl + +_LT_SETUP + +# Only expand once: +m4_define([LT_INIT]) +])# LT_INIT + +# Old names: +AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) +AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PROG_LIBTOOL], []) +dnl AC_DEFUN([AM_PROG_LIBTOOL], []) + + +# _LT_PREPARE_CC_BASENAME +# ----------------------- +m4_defun([_LT_PREPARE_CC_BASENAME], [ +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +func_cc_basename () +{ + for cc_temp in @S|@*""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac + done + func_cc_basename_result=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` +} +])# _LT_PREPARE_CC_BASENAME + + +# _LT_CC_BASENAME(CC) +# ------------------- +# It would be clearer to call AC_REQUIREs from _LT_PREPARE_CC_BASENAME, +# but that macro is also expanded into generated libtool script, which +# arranges for $SED and $ECHO to be set by different means. +m4_defun([_LT_CC_BASENAME], +[m4_require([_LT_PREPARE_CC_BASENAME])dnl +AC_REQUIRE([_LT_DECL_SED])dnl +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl +func_cc_basename $1 +cc_basename=$func_cc_basename_result +]) + + +# _LT_FILEUTILS_DEFAULTS +# ---------------------- +# It is okay to use these file commands and assume they have been set +# sensibly after 'm4_require([_LT_FILEUTILS_DEFAULTS])'. +m4_defun([_LT_FILEUTILS_DEFAULTS], +[: ${CP="cp -f"} +: ${MV="mv -f"} +: ${RM="rm -f"} +])# _LT_FILEUTILS_DEFAULTS + + +# _LT_SETUP +# --------- +m4_defun([_LT_SETUP], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl + +_LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl +dnl +_LT_DECL([], [host_alias], [0], [The host system])dnl +_LT_DECL([], [host], [0])dnl +_LT_DECL([], [host_os], [0])dnl +dnl +_LT_DECL([], [build_alias], [0], [The build system])dnl +_LT_DECL([], [build], [0])dnl +_LT_DECL([], [build_os], [0])dnl +dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +dnl +AC_REQUIRE([AC_PROG_LN_S])dnl +test -z "$LN_S" && LN_S="ln -s" +_LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl +dnl +AC_REQUIRE([LT_CMD_MAX_LEN])dnl +_LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl +_LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl +dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl +m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_CHECK_MAGIC_METHOD])dnl +m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl +m4_require([_LT_CMD_OLD_ARCHIVE])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_WITH_SYSROOT])dnl +m4_require([_LT_CMD_TRUNCATE])dnl + +_LT_CONFIG_LIBTOOL_INIT([ +# See if we are running on zsh, and set the options that allow our +# commands through without removal of \ escapes INIT. +if test -n "\${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi +]) +if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST +fi + +_LT_CHECK_OBJDIR + +m4_require([_LT_TAG_COMPILER])dnl + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; +esac + +# Global variables: +ofile=libtool +can_build_shared=yes + +# All known linkers require a '.a' archive for static linking (except MSVC, +# which needs '.lib'). +libext=a + +with_gnu_ld=$lt_cv_prog_gnu_ld + +old_CC=$CC +old_CFLAGS=$CFLAGS + +# Set sane defaults for various variables +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS +test -z "$LD" && LD=ld +test -z "$ac_objext" && ac_objext=o + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +test -z "$MAGIC_CMD" && MAGIC_CMD=file +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + _LT_PATH_MAGIC + fi + ;; +esac + +# Use C for the default configuration in the libtool script +LT_SUPPORTED_TAG([CC]) +_LT_LANG_C_CONFIG +_LT_LANG_DEFAULT_CONFIG +_LT_CONFIG_COMMANDS +])# _LT_SETUP + + +# _LT_PREPARE_SED_QUOTE_VARS +# -------------------------- +# Define a few sed substitution that help us do robust quoting. +m4_defun([_LT_PREPARE_SED_QUOTE_VARS], +[# Backslashify metacharacters that are still active within +# double-quoted strings. +sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' + +# Same as above, but do not quote variable references. +double_quote_subst='s/\([["`\\]]\)/\\\1/g' + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to delay expansion of an escaped single quote. +delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' +]) + +# _LT_PROG_LTMAIN +# --------------- +# Note that this code is called both from 'configure', and 'config.status' +# now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, +# 'config.status' has no value for ac_aux_dir unless we are using Automake, +# so we pass a copy along to make sure it has a sensible value anyway. +m4_defun([_LT_PROG_LTMAIN], +[m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl +_LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) +ltmain=$ac_aux_dir/ltmain.sh +])# _LT_PROG_LTMAIN + + +## ------------------------------------- ## +## Accumulate code for creating libtool. ## +## ------------------------------------- ## + +# So that we can recreate a full libtool script including additional +# tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS +# in macros and then make a single call at the end using the 'libtool' +# label. + + +# _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) +# ---------------------------------------- +# Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL_INIT], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_INIT], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_INIT]) + + +# _LT_CONFIG_LIBTOOL([COMMANDS]) +# ------------------------------ +# Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. +m4_define([_LT_CONFIG_LIBTOOL], +[m4_ifval([$1], + [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], + [$1 +])])]) + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) + + +# _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) +# ----------------------------------------------------- +m4_defun([_LT_CONFIG_SAVE_COMMANDS], +[_LT_CONFIG_LIBTOOL([$1]) +_LT_CONFIG_LIBTOOL_INIT([$2]) +]) + + +# _LT_FORMAT_COMMENT([COMMENT]) +# ----------------------------- +# Add leading comment marks to the start of each line, and a trailing +# full-stop to the whole comment if one is not present already. +m4_define([_LT_FORMAT_COMMENT], +[m4_ifval([$1], [ +m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], + [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) +)]) + + + +## ------------------------ ## +## FIXME: Eliminate VARNAME ## +## ------------------------ ## + + +# _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) +# ------------------------------------------------------------------- +# CONFIGNAME is the name given to the value in the libtool script. +# VARNAME is the (base) name used in the configure script. +# VALUE may be 0, 1 or 2 for a computed quote escaped value based on +# VARNAME. Any other value will be used directly. +m4_define([_LT_DECL], +[lt_if_append_uniq([lt_decl_varnames], [$2], [, ], + [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], + [m4_ifval([$1], [$1], [$2])]) + lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) + m4_ifval([$4], + [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) + lt_dict_add_subkey([lt_decl_dict], [$2], + [tagged?], [m4_ifval([$5], [yes], [no])])]) +]) + + +# _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) +# -------------------------------------------------------- +m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) + + +# lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_tag_varnames], +[_lt_decl_filter([tagged?], [yes], $@)]) + + +# _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) +# --------------------------------------------------------- +m4_define([_lt_decl_filter], +[m4_case([$#], + [0], [m4_fatal([$0: too few arguments: $#])], + [1], [m4_fatal([$0: too few arguments: $#: $1])], + [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], + [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], + [lt_dict_filter([lt_decl_dict], $@)])[]dnl +]) + + +# lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) +# -------------------------------------------------- +m4_define([lt_decl_quote_varnames], +[_lt_decl_filter([value], [1], $@)]) + + +# lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_dquote_varnames], +[_lt_decl_filter([value], [2], $@)]) + + +# lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) +# --------------------------------------------------- +m4_define([lt_decl_varnames_tagged], +[m4_assert([$# <= 2])dnl +_$0(m4_quote(m4_default([$1], [[, ]])), + m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), + m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) +m4_define([_lt_decl_varnames_tagged], +[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) + + +# lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) +# ------------------------------------------------ +m4_define([lt_decl_all_varnames], +[_$0(m4_quote(m4_default([$1], [[, ]])), + m4_if([$2], [], + m4_quote(lt_decl_varnames), + m4_quote(m4_shift($@))))[]dnl +]) +m4_define([_lt_decl_all_varnames], +[lt_join($@, lt_decl_varnames_tagged([$1], + lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl +]) + + +# _LT_CONFIG_STATUS_DECLARE([VARNAME]) +# ------------------------------------ +# Quote a variable value, and forward it to 'config.status' so that its +# declaration there will have the same value as in 'configure'. VARNAME +# must have a single quote delimited value for this to work. +m4_define([_LT_CONFIG_STATUS_DECLARE], +[$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`']) + + +# _LT_CONFIG_STATUS_DECLARATIONS +# ------------------------------ +# We delimit libtool config variables with single quotes, so when +# we write them to config.status, we have to be sure to quote all +# embedded single quotes properly. In configure, this macro expands +# each variable declared with _LT_DECL (and _LT_TAGDECL) into: +# +# ='`$ECHO "$" | $SED "$delay_single_quote_subst"`' +m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], +[m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), + [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAGS +# ---------------- +# Output comment and list of tags supported by the script +m4_defun([_LT_LIBTOOL_TAGS], +[_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl +available_tags='_LT_TAGS'dnl +]) + + +# _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) +# ----------------------------------- +# Extract the dictionary values for VARNAME (optionally with TAG) and +# expand to a commented shell variable setting: +# +# # Some comment about what VAR is for. +# visible_name=$lt_internal_name +m4_define([_LT_LIBTOOL_DECLARE], +[_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], + [description])))[]dnl +m4_pushdef([_libtool_name], + m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl +m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), + [0], [_libtool_name=[$]$1], + [1], [_libtool_name=$lt_[]$1], + [2], [_libtool_name=$lt_[]$1], + [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl +m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl +]) + + +# _LT_LIBTOOL_CONFIG_VARS +# ----------------------- +# Produce commented declarations of non-tagged libtool config variables +# suitable for insertion in the LIBTOOL CONFIG section of the 'libtool' +# script. Tagged libtool config variables (even for the LIBTOOL CONFIG +# section) are produced by _LT_LIBTOOL_TAG_VARS. +m4_defun([_LT_LIBTOOL_CONFIG_VARS], +[m4_foreach([_lt_var], + m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) + + +# _LT_LIBTOOL_TAG_VARS(TAG) +# ------------------------- +m4_define([_LT_LIBTOOL_TAG_VARS], +[m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), + [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) + + +# _LT_TAGVAR(VARNAME, [TAGNAME]) +# ------------------------------ +m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) + + +# _LT_CONFIG_COMMANDS +# ------------------- +# Send accumulated output to $CONFIG_STATUS. Thanks to the lists of +# variables for single and double quote escaping we saved from calls +# to _LT_DECL, we can put quote escaped variables declarations +# into 'config.status', and then the shell code to quote escape them in +# for loops in 'config.status'. Finally, any additional code accumulated +# from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. +m4_defun([_LT_CONFIG_COMMANDS], +[AC_PROVIDE_IFELSE([LT_OUTPUT], + dnl If the libtool generation code has been placed in $CONFIG_LT, + dnl instead of duplicating it all over again into config.status, + dnl then we will have config.status run $CONFIG_LT later, so it + dnl needs to know what name is stored there: + [AC_CONFIG_COMMANDS([libtool], + [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], + dnl If the libtool generation code is destined for config.status, + dnl expand the accumulated commands and init code now: + [AC_CONFIG_COMMANDS([libtool], + [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) +])#_LT_CONFIG_COMMANDS + + +# Initialize. +m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], +[ + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +sed_quote_subst='$sed_quote_subst' +double_quote_subst='$double_quote_subst' +delay_variable_subst='$delay_variable_subst' +_LT_CONFIG_STATUS_DECLARATIONS +LTCC='$LTCC' +LTCFLAGS='$LTCFLAGS' +compiler='$compiler_DEFAULT' + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +\$[]1 +_LTECHO_EOF' +} + +# Quote evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_quote_varnames); do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +# Double-quote double-evaled strings. +for var in lt_decl_all_varnames([[ \ +]], lt_decl_dquote_varnames); do + case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in + *[[\\\\\\\`\\"\\\$]]*) + eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ## exclude from sc_prohibit_nested_quotes + ;; + *) + eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" + ;; + esac +done + +_LT_OUTPUT_LIBTOOL_INIT +]) + +# _LT_GENERATED_FILE_INIT(FILE, [COMMENT]) +# ------------------------------------ +# Generate a child script FILE with all initialization necessary to +# reuse the environment learned by the parent script, and make the +# file executable. If COMMENT is supplied, it is inserted after the +# '#!' sequence but before initialization text begins. After this +# macro, additional text can be appended to FILE to form the body of +# the child script. The macro ends with non-zero status if the +# file could not be fully written (such as if the disk is full). +m4_ifdef([AS_INIT_GENERATED], +[m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])], +[m4_defun([_LT_GENERATED_FILE_INIT], +[m4_require([AS_PREPARE])]dnl +[m4_pushdef([AS_MESSAGE_LOG_FD])]dnl +[lt_write_fail=0 +cat >$1 <<_ASEOF || lt_write_fail=1 +#! $SHELL +# Generated by $as_me. +$2 +SHELL=\${CONFIG_SHELL-$SHELL} +export SHELL +_ASEOF +cat >>$1 <<\_ASEOF || lt_write_fail=1 +AS_SHELL_SANITIZE +_AS_PREPARE +exec AS_MESSAGE_FD>&1 +_ASEOF +test 0 = "$lt_write_fail" && chmod +x $1[]dnl +m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT + +# LT_OUTPUT +# --------- +# This macro allows early generation of the libtool script (before +# AC_OUTPUT is called), incase it is used in configure for compilation +# tests. +AC_DEFUN([LT_OUTPUT], +[: ${CONFIG_LT=./config.lt} +AC_MSG_NOTICE([creating $CONFIG_LT]) +_LT_GENERATED_FILE_INIT(["$CONFIG_LT"], +[# Run this file to recreate a libtool stub with the current configuration.]) + +cat >>"$CONFIG_LT" <<\_LTEOF +lt_cl_silent=false +exec AS_MESSAGE_LOG_FD>>config.log +{ + echo + AS_BOX([Running $as_me.]) +} >&AS_MESSAGE_LOG_FD + +lt_cl_help="\ +'$as_me' creates a local libtool stub from the current configuration, +for use in further configure time tests before the real libtool is +generated. + +Usage: $[0] [[OPTIONS]] + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + +Report bugs to ." + +lt_cl_version="\ +m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl +m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) +configured by $[0], generated by m4_PACKAGE_STRING. + +Copyright (C) 2011 Free Software Foundation, Inc. +This config.lt script is free software; the Free Software Foundation +gives unlimited permision to copy, distribute and modify it." + +while test 0 != $[#] +do + case $[1] in + --version | --v* | -V ) + echo "$lt_cl_version"; exit 0 ;; + --help | --h* | -h ) + echo "$lt_cl_help"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --quiet | --q* | --silent | --s* | -q ) + lt_cl_silent=: ;; + + -*) AC_MSG_ERROR([unrecognized option: $[1] +Try '$[0] --help' for more information.]) ;; + + *) AC_MSG_ERROR([unrecognized argument: $[1] +Try '$[0] --help' for more information.]) ;; + esac + shift +done + +if $lt_cl_silent; then + exec AS_MESSAGE_FD>/dev/null +fi +_LTEOF + +cat >>"$CONFIG_LT" <<_LTEOF +_LT_OUTPUT_LIBTOOL_COMMANDS_INIT +_LTEOF + +cat >>"$CONFIG_LT" <<\_LTEOF +AC_MSG_NOTICE([creating $ofile]) +_LT_OUTPUT_LIBTOOL_COMMANDS +AS_EXIT(0) +_LTEOF +chmod +x "$CONFIG_LT" + +# configure is writing to config.log, but config.lt does its own redirection, +# appending to config.log, which fails on DOS, as config.log is still kept +# open by configure. Here we exec the FD to /dev/null, effectively closing +# config.log, so it can be properly (re)opened and appended to by config.lt. +lt_cl_success=: +test yes = "$silent" && + lt_config_lt_args="$lt_config_lt_args --quiet" +exec AS_MESSAGE_LOG_FD>/dev/null +$SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false +exec AS_MESSAGE_LOG_FD>>config.log +$lt_cl_success || AS_EXIT(1) +])# LT_OUTPUT + + +# _LT_CONFIG(TAG) +# --------------- +# If TAG is the built-in tag, create an initial libtool script with a +# default configuration from the untagged config vars. Otherwise add code +# to config.status for appending the configuration named by TAG from the +# matching tagged config vars. +m4_defun([_LT_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_CONFIG_SAVE_COMMANDS([ + m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl + m4_if(_LT_TAG, [C], [ + # See if we are running on zsh, and set the options that allow our + # commands through without removal of \ escapes. + if test -n "${ZSH_VERSION+set}"; then + setopt NO_GLOB_SUBST + fi + + cfgfile=${ofile}T + trap "$RM \"$cfgfile\"; exit 1" 1 2 15 + $RM "$cfgfile" + + cat <<_LT_EOF >> "$cfgfile" +#! $SHELL +# Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# NOTE: Changes made to this file will be lost: look at ltmain.sh. + +# Provide generalized library-building support services. +# Written by Gordon Matzigkeit, 1996 + +_LT_COPYING +_LT_LIBTOOL_TAGS + +# Configured defaults for sys_lib_dlsearch_path munging. +: \${LT_SYS_LIBRARY_PATH="$configure_time_lt_sys_library_path"} + +# ### BEGIN LIBTOOL CONFIG +_LT_LIBTOOL_CONFIG_VARS +_LT_LIBTOOL_TAG_VARS +# ### END LIBTOOL CONFIG + +_LT_EOF + + cat <<'_LT_EOF' >> "$cfgfile" + +# ### BEGIN FUNCTIONS SHARED WITH CONFIGURE + +_LT_PREPARE_MUNGE_PATH_LIST +_LT_PREPARE_CC_BASENAME + +# ### END FUNCTIONS SHARED WITH CONFIGURE + +_LT_EOF + + case $host_os in + aix3*) + cat <<\_LT_EOF >> "$cfgfile" +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test set != "${COLLECT_NAMES+set}"; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +_LT_EOF + ;; + esac + + _LT_PROG_LTMAIN + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" \ + || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +], +[cat <<_LT_EOF >> "$ofile" + +dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded +dnl in a comment (ie after a #). +# ### BEGIN LIBTOOL TAG CONFIG: $1 +_LT_LIBTOOL_TAG_VARS(_LT_TAG) +# ### END LIBTOOL TAG CONFIG: $1 +_LT_EOF +])dnl /m4_if +], +[m4_if([$1], [], [ + PACKAGE='$PACKAGE' + VERSION='$VERSION' + RM='$RM' + ofile='$ofile'], []) +])dnl /_LT_CONFIG_SAVE_COMMANDS +])# _LT_CONFIG + + +# LT_SUPPORTED_TAG(TAG) +# --------------------- +# Trace this macro to discover what tags are supported by the libtool +# --tag option, using: +# autoconf --trace 'LT_SUPPORTED_TAG:$1' +AC_DEFUN([LT_SUPPORTED_TAG], []) + + +# C support is built-in for now +m4_define([_LT_LANG_C_enabled], []) +m4_define([_LT_TAGS], []) + + +# LT_LANG(LANG) +# ------------- +# Enable libtool support for the given language if not already enabled. +AC_DEFUN([LT_LANG], +[AC_BEFORE([$0], [LT_OUTPUT])dnl +m4_case([$1], + [C], [_LT_LANG(C)], + [C++], [_LT_LANG(CXX)], + [Go], [_LT_LANG(GO)], + [Java], [_LT_LANG(GCJ)], + [Fortran 77], [_LT_LANG(F77)], + [Fortran], [_LT_LANG(FC)], + [Windows Resource], [_LT_LANG(RC)], + [m4_ifdef([_LT_LANG_]$1[_CONFIG], + [_LT_LANG($1)], + [m4_fatal([$0: unsupported language: "$1"])])])dnl +])# LT_LANG + + +# _LT_LANG(LANGNAME) +# ------------------ +m4_defun([_LT_LANG], +[m4_ifdef([_LT_LANG_]$1[_enabled], [], + [LT_SUPPORTED_TAG([$1])dnl + m4_append([_LT_TAGS], [$1 ])dnl + m4_define([_LT_LANG_]$1[_enabled], [])dnl + _LT_LANG_$1_CONFIG($1)])dnl +])# _LT_LANG + + +m4_ifndef([AC_PROG_GO], [ +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_GO. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ +m4_defun([AC_PROG_GO], +[AC_LANG_PUSH(Go)dnl +AC_ARG_VAR([GOC], [Go compiler command])dnl +AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl +_AC_ARG_VAR_LDFLAGS()dnl +AC_CHECK_TOOL(GOC, gccgo) +if test -z "$GOC"; then + if test -n "$ac_tool_prefix"; then + AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo]) + fi +fi +if test -z "$GOC"; then + AC_CHECK_PROG(GOC, gccgo, gccgo, false) +fi +])#m4_defun +])#m4_ifndef + + +# _LT_LANG_DEFAULT_CONFIG +# ----------------------- +m4_defun([_LT_LANG_DEFAULT_CONFIG], +[AC_PROVIDE_IFELSE([AC_PROG_CXX], + [LT_LANG(CXX)], + [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) + +AC_PROVIDE_IFELSE([AC_PROG_F77], + [LT_LANG(F77)], + [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) + +AC_PROVIDE_IFELSE([AC_PROG_FC], + [LT_LANG(FC)], + [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) + +dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal +dnl pulling things in needlessly. +AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [LT_LANG(GCJ)], + [AC_PROVIDE_IFELSE([LT_PROG_GCJ], + [LT_LANG(GCJ)], + [m4_ifdef([AC_PROG_GCJ], + [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([A][M_PROG_GCJ], + [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) + m4_ifdef([LT_PROG_GCJ], + [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) + +AC_PROVIDE_IFELSE([AC_PROG_GO], + [LT_LANG(GO)], + [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])]) + +AC_PROVIDE_IFELSE([LT_PROG_RC], + [LT_LANG(RC)], + [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) +])# _LT_LANG_DEFAULT_CONFIG + +# Obsolete macros: +AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) +AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) +AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) +AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) +AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_CXX], []) +dnl AC_DEFUN([AC_LIBTOOL_F77], []) +dnl AC_DEFUN([AC_LIBTOOL_FC], []) +dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) +dnl AC_DEFUN([AC_LIBTOOL_RC], []) + + +# _LT_TAG_COMPILER +# ---------------- +m4_defun([_LT_TAG_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +_LT_DECL([LTCC], [CC], [1], [A C compiler])dnl +_LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl +_LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl +_LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# If no C compiler flags were specified, use CFLAGS. +LTCFLAGS=${LTCFLAGS-"$CFLAGS"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_TAG_COMPILER + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +m4_defun([_LT_COMPILER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$RM conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +m4_defun([_LT_LINKER_BOILERPLATE], +[m4_require([_LT_DECL_SED])dnl +ac_outfile=conftest.$ac_objext +echo "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$RM -r conftest* +])# _LT_LINKER_BOILERPLATE + +# _LT_REQUIRED_DARWIN_CHECKS +# ------------------------- +m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ + case $host_os in + rhapsody* | darwin*) + AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) + AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) + AC_CHECK_TOOL([LIPO], [lipo], [:]) + AC_CHECK_TOOL([OTOOL], [otool], [:]) + AC_CHECK_TOOL([OTOOL64], [otool64], [:]) + _LT_DECL([], [DSYMUTIL], [1], + [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) + _LT_DECL([], [NMEDIT], [1], + [Tool to change global to local symbols on Mac OS X]) + _LT_DECL([], [LIPO], [1], + [Tool to manipulate fat objects and archives on Mac OS X]) + _LT_DECL([], [OTOOL], [1], + [ldd/readelf like tool for Mach-O binaries on Mac OS X]) + _LT_DECL([], [OTOOL64], [1], + [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) + + AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], + [lt_cv_apple_cc_single_mod=no + if test -z "$LT_MULTI_MODULE"; then + # By default we will add the -single_module flag. You can override + # by either setting the environment variable LT_MULTI_MODULE + # non-empty at configure time, or by adding -multi_module to the + # link flags. + rm -rf libconftest.dylib* + echo "int foo(void){return 1;}" > conftest.c + echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ +-dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ + -dynamiclib -Wl,-single_module conftest.c 2>conftest.err + _lt_result=$? + # If there is a non-empty error log, and "single_module" + # appears in it, assume the flag caused a linker warning + if test -s conftest.err && $GREP single_module conftest.err; then + cat conftest.err >&AS_MESSAGE_LOG_FD + # Otherwise, if the output was created with a 0 exit code from + # the compiler, it worked. + elif test -f libconftest.dylib && test 0 = "$_lt_result"; then + lt_cv_apple_cc_single_mod=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -rf libconftest.dylib* + rm -f conftest.* + fi]) + + AC_CACHE_CHECK([for -exported_symbols_list linker flag], + [lt_cv_ld_exported_symbols_list], + [lt_cv_ld_exported_symbols_list=no + save_LDFLAGS=$LDFLAGS + echo "_main" > conftest.sym + LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [lt_cv_ld_exported_symbols_list=yes], + [lt_cv_ld_exported_symbols_list=no]) + LDFLAGS=$save_LDFLAGS + ]) + + AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load], + [lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD + echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD + $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -s conftest.err && $GREP force_load conftest.err; then + cat conftest.err >&AS_MESSAGE_LOG_FD + elif test -f conftest && test 0 = "$_lt_result" && $GREP forced_load conftest >/dev/null 2>&1; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -f conftest.err libconftest.a conftest conftest.c + rm -rf conftest.dSYM + ]) + case $host_os in + rhapsody* | darwin1.[[012]]) + _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; + darwin1.*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + darwin*) # darwin 5.x on + # if running on 10.5 or later, the deployment target defaults + # to the OS version, if on x86, and 10.4, the deployment + # target defaults to 10.4. Don't you love it? + case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in + 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + 10.[[012]][[,.]]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + 10.*) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + esac + ;; + esac + if test yes = "$lt_cv_apple_cc_single_mod"; then + _lt_dar_single_mod='$single_module' + fi + if test yes = "$lt_cv_ld_exported_symbols_list"; then + _lt_dar_export_syms=' $wl-exported_symbols_list,$output_objdir/$libname-symbols.expsym' + else + _lt_dar_export_syms='~$NMEDIT -s $output_objdir/$libname-symbols.expsym $lib' + fi + if test : != "$DSYMUTIL" && test no = "$lt_cv_ld_force_load"; then + _lt_dsymutil='~$DSYMUTIL $lib || :' + else + _lt_dsymutil= + fi + ;; + esac +]) + + +# _LT_DARWIN_LINKER_FEATURES([TAG]) +# --------------------------------- +# Checks for linker and compiler features on darwin +m4_defun([_LT_DARWIN_LINKER_FEATURES], +[ + m4_require([_LT_REQUIRED_DARWIN_CHECKS]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_automatic, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + if test yes = "$lt_cv_ld_force_load"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience $wl-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes], + [FC], [_LT_TAGVAR(compiler_needs_object, $1)=yes]) + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=$_lt_dar_allow_undefined + case $cc_basename in + ifort*|nagfor*) _lt_dar_can_shared=yes ;; + *) _lt_dar_can_shared=$GCC ;; + esac + if test yes = "$_lt_dar_can_shared"; then + output_verbose_link_cmd=func_echo_all + _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" + _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + m4_if([$1], [CXX], +[ if test yes != "$lt_cv_apple_cc_single_mod"; then + _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + fi +],[]) + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi +]) + +# _LT_SYS_MODULE_PATH_AIX([TAGNAME]) +# ---------------------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +# Store the results from the different compilers for each TAGNAME. +# Allow to override them for all tags through lt_cv_aix_libpath. +m4_defun([_LT_SYS_MODULE_PATH_AIX], +[m4_require([_LT_DECL_SED])dnl +if test set = "${lt_cv_aix_libpath+set}"; then + aix_libpath=$lt_cv_aix_libpath +else + AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])], + [AC_LINK_IFELSE([AC_LANG_PROGRAM],[ + lt_aix_libpath_sed='[ + /Import File Strings/,/^$/ { + /^0/ { + s/^0 *\([^ ]*\) *$/\1/ + p + } + }]' + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + # Check for a 64-bit object if we didn't find anything. + if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` + fi],[]) + if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then + _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=/usr/lib:/lib + fi + ]) + aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1]) +fi +])# _LT_SYS_MODULE_PATH_AIX + + +# _LT_SHELL_INIT(ARG) +# ------------------- +m4_define([_LT_SHELL_INIT], +[m4_divert_text([M4SH-INIT], [$1 +])])# _LT_SHELL_INIT + + + +# _LT_PROG_ECHO_BACKSLASH +# ----------------------- +# Find how we can fake an echo command that does not interpret backslash. +# In particular, with Autoconf 2.60 or later we add some code to the start +# of the generated configure script that will find a shell with a builtin +# printf (that we can use as an echo command). +m4_defun([_LT_PROG_ECHO_BACKSLASH], +[ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO +ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + +AC_MSG_CHECKING([how to print strings]) +# Test print first, because it will be a builtin if present. +if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ + test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='print -r --' +elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then + ECHO='printf %s\n' +else + # Use this function as a fallback that always works. + func_fallback_echo () + { + eval 'cat <<_LTECHO_EOF +$[]1 +_LTECHO_EOF' + } + ECHO='func_fallback_echo' +fi + +# func_echo_all arg... +# Invoke $ECHO with all args, space-separated. +func_echo_all () +{ + $ECHO "$*" +} + +case $ECHO in + printf*) AC_MSG_RESULT([printf]) ;; + print*) AC_MSG_RESULT([print -r]) ;; + *) AC_MSG_RESULT([cat]) ;; +esac + +m4_ifdef([_AS_DETECT_SUGGESTED], +[_AS_DETECT_SUGGESTED([ + test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || ( + ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' + ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO + ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO + PATH=/empty FPATH=/empty; export PATH FPATH + test "X`printf %s $ECHO`" = "X$ECHO" \ + || test "X`print -r -- $ECHO`" = "X$ECHO" )])]) + +_LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) +_LT_DECL([], [ECHO], [1], [An echo program that protects backslashes]) +])# _LT_PROG_ECHO_BACKSLASH + + +# _LT_WITH_SYSROOT +# ---------------- +AC_DEFUN([_LT_WITH_SYSROOT], +[AC_MSG_CHECKING([for sysroot]) +AC_ARG_WITH([sysroot], +[AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], + [Search for dependent libraries within DIR (or the compiler's sysroot + if not specified).])], +[], [with_sysroot=no]) + +dnl lt_sysroot will always be passed unquoted. We quote it here +dnl in case the user passed a directory name. +lt_sysroot= +case $with_sysroot in #( + yes) + if test yes = "$GCC"; then + lt_sysroot=`$CC --print-sysroot 2>/dev/null` + fi + ;; #( + /*) + lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + ;; #( + no|'') + ;; #( + *) + AC_MSG_RESULT([$with_sysroot]) + AC_MSG_ERROR([The sysroot must be an absolute path.]) + ;; +esac + + AC_MSG_RESULT([${lt_sysroot:-no}]) +_LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl +[dependent libraries, and where our libraries should be installed.])]) + +# _LT_ENABLE_LOCK +# --------------- +m4_defun([_LT_ENABLE_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AS_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test no = "$enable_libtool_lock" || enable_libtool_lock=yes + +# Some flags need to be propagated to the compiler or linker for good +# libtool support. +case $host in +ia64-*-hpux*) + # Find out what ABI is being produced by ac_compile, and set mode + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE=32 + ;; + *ELF-64*) + HPUX_IA64_MODE=64 + ;; + esac + fi + rm -rf conftest* + ;; +*-*-irix6*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + if test yes = "$lt_cv_prog_gnu_ld"; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -32" + ;; + *N32*) + LD="${LD-ld} -n32" + ;; + *64-bit*) + LD="${LD-ld} -64" + ;; + esac + fi + fi + rm -rf conftest* + ;; + +mips64*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + emul=elf + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + emul="${emul}32" + ;; + *64-bit*) + emul="${emul}64" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *MSB*) + emul="${emul}btsmip" + ;; + *LSB*) + emul="${emul}ltsmip" + ;; + esac + case `/usr/bin/file conftest.$ac_objext` in + *N32*) + emul="${emul}n32" + ;; + esac + LD="${LD-ld} -m $emul" + fi + rm -rf conftest* + ;; + +x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ +s390*-*linux*|s390*-*tpf*|sparc*-*linux*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. Note that the listed cases only cover the + # situations where additional linker options are needed (such as when + # doing 32-bit compilation for a host where ld defaults to 64-bit, or + # vice versa); the common cases where no linker options are needed do + # not appear in the list. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *32-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_i386_fbsd" + ;; + x86_64-*linux*) + case `/usr/bin/file conftest.o` in + *x86-64*) + LD="${LD-ld} -m elf32_x86_64" + ;; + *) + LD="${LD-ld} -m elf_i386" + ;; + esac + ;; + powerpc64le-*linux*) + LD="${LD-ld} -m elf32lppclinux" + ;; + powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*kfreebsd*-gnu) + LD="${LD-ld} -m elf_x86_64_fbsd" + ;; + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + powerpcle-*linux*) + LD="${LD-ld} -m elf64lppc" + ;; + powerpc-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*|s390*-*tpf*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; + +*-*-sco3.2v5*) + # On SCO OpenServer 5, we need -belf to get full-featured binaries. + SAVE_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -belf" + AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, + [AC_LANG_PUSH(C) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) + if test yes != "$lt_cv_cc_needs_belf"; then + # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf + CFLAGS=$SAVE_CFLAGS + fi + ;; +*-*solaris*) + # Find out what ABI is being produced by ac_compile, and set linker + # options accordingly. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.o` in + *64-bit*) + case $lt_cv_prog_gnu_ld in + yes*) + case $host in + i?86-*-solaris*|x86_64-*-solaris*) + LD="${LD-ld} -m elf_x86_64" + ;; + sparc*-*-solaris*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + # GNU ld 2.21 introduced _sol2 emulations. Use them if available. + if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then + LD=${LD-ld}_sol2 + fi + ;; + *) + if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then + LD="${LD-ld} -64" + fi + ;; + esac + ;; + esac + fi + rm -rf conftest* + ;; +esac + +need_locks=$enable_libtool_lock +])# _LT_ENABLE_LOCK + + +# _LT_PROG_AR +# ----------- +m4_defun([_LT_PROG_AR], +[AC_CHECK_TOOLS(AR, [ar], false) +: ${AR=ar} +: ${AR_FLAGS=cru} +_LT_DECL([], [AR], [1], [The archiver]) +_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) + +AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], + [lt_cv_ar_at_file=no + AC_COMPILE_IFELSE([AC_LANG_PROGRAM], + [echo conftest.$ac_objext > conftest.lst + lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD' + AC_TRY_EVAL([lt_ar_try]) + if test 0 -eq "$ac_status"; then + # Ensure the archiver fails upon bogus file names. + rm -f conftest.$ac_objext libconftest.a + AC_TRY_EVAL([lt_ar_try]) + if test 0 -ne "$ac_status"; then + lt_cv_ar_at_file=@ + fi + fi + rm -f conftest.* libconftest.a + ]) + ]) + +if test no = "$lt_cv_ar_at_file"; then + archiver_list_spec= +else + archiver_list_spec=$lt_cv_ar_at_file +fi +_LT_DECL([], [archiver_list_spec], [1], + [How to feed a file listing to the archiver]) +])# _LT_PROG_AR + + +# _LT_CMD_OLD_ARCHIVE +# ------------------- +m4_defun([_LT_CMD_OLD_ARCHIVE], +[_LT_PROG_AR + +AC_CHECK_TOOL(STRIP, strip, :) +test -z "$STRIP" && STRIP=: +_LT_DECL([], [STRIP], [1], [A symbol stripping program]) + +AC_CHECK_TOOL(RANLIB, ranlib, :) +test -z "$RANLIB" && RANLIB=: +_LT_DECL([], [RANLIB], [1], + [Commands used to install an old-style archive]) + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + bitrig* | openbsd*) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" + ;; + *) + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" +fi + +case $host_os in + darwin*) + lock_old_archive_extraction=yes ;; + *) + lock_old_archive_extraction=no ;; +esac +_LT_DECL([], [old_postinstall_cmds], [2]) +_LT_DECL([], [old_postuninstall_cmds], [2]) +_LT_TAGDECL([], [old_archive_cmds], [2], + [Commands used to build an old-style archive]) +_LT_DECL([], [lock_old_archive_extraction], [0], + [Whether to use a lock for old archive extraction]) +])# _LT_CMD_OLD_ARCHIVE + + +# _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([_LT_COMPILER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" ## exclude from sc_useless_quotes_in_assignment + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $RM conftest* +]) + +if test yes = "[$]$2"; then + m4_if([$5], , :, [$5]) +else + m4_if([$6], , :, [$6]) +fi +])# _LT_COMPILER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) + + +# _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------- +# Check whether the given linker option works +AC_DEFUN([_LT_LINKER_OPTION], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_SED])dnl +AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS $3" + echo "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The linker can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp + $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $RM -r conftest* + LDFLAGS=$save_LDFLAGS +]) + +if test yes = "[$]$2"; then + m4_if([$4], , :, [$4]) +else + m4_if([$5], , :, [$5]) +fi +])# _LT_LINKER_OPTION + +# Old name: +AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) + + +# LT_CMD_MAX_LEN +#--------------- +AC_DEFUN([LT_CMD_MAX_LEN], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring=ABCD + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw* | cegcc*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + mint*) + # On MiNT this can take a long time and run out of memory. + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + + interix*) + # We know the value 262144 and hardcode it with a safety zone (like BSD) + lt_cv_sys_max_cmd_len=196608 + ;; + + os2*) + # The test takes a long time on OS/2. + lt_cv_sys_max_cmd_len=8192 + ;; + + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi + ;; + sco3.2v5*) + lt_cv_sys_max_cmd_len=102400 + ;; + sysv5* | sco5v6* | sysv4.2uw2*) + kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` + if test -n "$kargmax"; then + lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + else + lt_cv_sys_max_cmd_len=32768 + fi + ;; + *) + lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` + if test -n "$lt_cv_sys_max_cmd_len" && \ + test undefined != "$lt_cv_sys_max_cmd_len"; then + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + else + # Make teststring a little bigger before we do anything with it. + # a 1K string should be a reasonable start. + for i in 1 2 3 4 5 6 7 8; do + teststring=$teststring$teststring + done + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + while { test X`env echo "$teststring$teststring" 2>/dev/null` \ + = "X$teststring$teststring"; } >/dev/null 2>&1 && + test 17 != "$i" # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + # Only check the string length outside the loop. + lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` + teststring= + # Add a significant safety factor because C++ compilers can tack on + # massive amounts of additional arguments before passing them to the + # linker. It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` + fi + ;; + esac +]) +if test -n "$lt_cv_sys_max_cmd_len"; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) +else + AC_MSG_RESULT(none) +fi +max_cmd_len=$lt_cv_sys_max_cmd_len +_LT_DECL([], [max_cmd_len], [0], + [What is the maximum length of a command?]) +])# LT_CMD_MAX_LEN + +# Old name: +AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) + + +# _LT_HEADER_DLFCN +# ---------------- +m4_defun([_LT_HEADER_DLFCN], +[AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl +])# _LT_HEADER_DLFCN + + +# _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ---------------------------------------------------------------- +m4_defun([_LT_TRY_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test yes = "$cross_compiling"; then : + [$4] +else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +[#line $LINENO "configure" +#include "confdefs.h" + +#if HAVE_DLFCN_H +#include +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +/* When -fvisibility=hidden is used, assume the code has been annotated + correspondingly for the symbols needed. */ +#if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) +int fnord () __attribute__((visibility("default"))); +#endif + +int fnord () { return 42; } +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else + { + if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + else puts (dlerror ()); + } + /* dlclose (self); */ + } + else + puts (dlerror ()); + + return status; +}] +_LT_EOF + if AC_TRY_EVAL(ac_link) && test -s "conftest$ac_exeext" 2>/dev/null; then + (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_dlunknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi +fi +rm -fr conftest* +])# _LT_TRY_DLOPEN_SELF + + +# LT_SYS_DLOPEN_SELF +# ------------------ +AC_DEFUN([LT_SYS_DLOPEN_SELF], +[m4_require([_LT_HEADER_DLFCN])dnl +if test yes != "$enable_dlopen"; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown +else + lt_cv_dlopen=no + lt_cv_dlopen_libs= + + case $host_os in + beos*) + lt_cv_dlopen=load_add_on + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; + + mingw* | pw32* | cegcc*) + lt_cv_dlopen=LoadLibrary + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl],[ + lt_cv_dlopen=dyld + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + tpf*) + # Don't try to run any link tests for TPF. We know it's impossible + # because TPF is a cross-compiler, and we know how we open DSOs. + lt_cv_dlopen=dlopen + lt_cv_dlopen_libs= + lt_cv_dlopen_self=no + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen=shl_load], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen=dlopen], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test no = "$lt_cv_dlopen"; then + enable_dlopen=no + else + enable_dlopen=yes + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS=$CPPFLAGS + test yes = "$ac_cv_header_dlfcn_h" && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS=$LDFLAGS + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS=$LIBS + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test yes = "$lt_cv_dlopen_self"; then + wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +_LT_DECL([dlopen_support], [enable_dlopen], [0], + [Whether dlopen is supported]) +_LT_DECL([dlopen_self], [enable_dlopen_self], [0], + [Whether dlopen of programs is supported]) +_LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], + [Whether dlopen of statically linked programs is supported]) +])# LT_SYS_DLOPEN_SELF + +# Old name: +AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) + + +# _LT_COMPILER_C_O([TAGNAME]) +# --------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler. +# This macro does not hard code the compiler like AC_PROG_CC_C_O. +m4_defun([_LT_COMPILER_C_O], +[m4_require([_LT_DECL_SED])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $RM -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp + $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . 2>&AS_MESSAGE_LOG_FD + $RM conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files + $RM out/* && rmdir out + cd .. + $RM -r conftest + $RM conftest* +]) +_LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], + [Does compiler simultaneously support -c and -o options?]) +])# _LT_COMPILER_C_O + + +# _LT_COMPILER_FILE_LOCKS([TAGNAME]) +# ---------------------------------- +# Check to see if we can do hard links to lock some files if needed +m4_defun([_LT_COMPILER_FILE_LOCKS], +[m4_require([_LT_ENABLE_LOCK])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +_LT_COMPILER_C_O([$1]) + +hard_links=nottested +if test no = "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" && test no != "$need_locks"; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $RM conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test no = "$hard_links"; then + AC_MSG_WARN(['$CC' does not support '-c -o', so 'make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +_LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) +])# _LT_COMPILER_FILE_LOCKS + + +# _LT_CHECK_OBJDIR +# ---------------- +m4_defun([_LT_CHECK_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +_LT_DECL([], [objdir], [0], + [The name of the directory that contains temporary libtool files])dnl +m4_pattern_allow([LT_OBJDIR])dnl +AC_DEFINE_UNQUOTED([LT_OBJDIR], "$lt_cv_objdir/", + [Define to the sub-directory where libtool stores uninstalled libraries.]) +])# _LT_CHECK_OBJDIR + + +# _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) +# -------------------------------------- +# Check hardcoding attributes. +m4_defun([_LT_LINKER_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || + test -n "$_LT_TAGVAR(runpath_var, $1)" || + test yes = "$_LT_TAGVAR(hardcode_automatic, $1)"; then + + # We can hardcode non-existent directories. + if test no != "$_LT_TAGVAR(hardcode_direct, $1)" && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test no != "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" && + test no != "$_LT_TAGVAR(hardcode_minus_L, $1)"; then + # Linking always hardcodes the temporary library directory. + _LT_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) + +if test relink = "$_LT_TAGVAR(hardcode_action, $1)" || + test yes = "$_LT_TAGVAR(inherit_rpath, $1)"; then + # Fast installation is not supported + enable_fast_install=no +elif test yes = "$shlibpath_overrides_runpath" || + test no = "$enable_shared"; then + # Fast installation is not necessary + enable_fast_install=needless +fi +_LT_TAGDECL([], [hardcode_action], [0], + [How to hardcode a shared library path into an executable]) +])# _LT_LINKER_HARDCODE_LIBPATH + + +# _LT_CMD_STRIPLIB +# ---------------- +m4_defun([_LT_CMD_STRIPLIB], +[m4_require([_LT_DECL_EGREP]) +striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP"; then + striplib="$STRIP -x" + old_striplib="$STRIP -S" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +_LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) +_LT_DECL([], [striplib], [1]) +])# _LT_CMD_STRIPLIB + + +# _LT_PREPARE_MUNGE_PATH_LIST +# --------------------------- +# Make sure func_munge_path_list() is defined correctly. +m4_defun([_LT_PREPARE_MUNGE_PATH_LIST], +[[# func_munge_path_list VARIABLE PATH +# ----------------------------------- +# VARIABLE is name of variable containing _space_ separated list of +# directories to be munged by the contents of PATH, which is string +# having a format: +# "DIR[:DIR]:" +# string "DIR[ DIR]" will be prepended to VARIABLE +# ":DIR[:DIR]" +# string "DIR[ DIR]" will be appended to VARIABLE +# "DIRP[:DIRP]::[DIRA:]DIRA" +# string "DIRP[ DIRP]" will be prepended to VARIABLE and string +# "DIRA[ DIRA]" will be appended to VARIABLE +# "DIR[:DIR]" +# VARIABLE will be replaced by "DIR[ DIR]" +func_munge_path_list () +{ + case x@S|@2 in + x) + ;; + *:) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'` \@S|@@S|@1\" + ;; + x:*) + eval @S|@1=\"\@S|@@S|@1 `$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + *::*) + eval @S|@1=\"\@S|@@S|@1\ `$ECHO @S|@2 | $SED -e 's/.*:://' -e 's/:/ /g'`\" + eval @S|@1=\"`$ECHO @S|@2 | $SED -e 's/::.*//' -e 's/:/ /g'`\ \@S|@@S|@1\" + ;; + *) + eval @S|@1=\"`$ECHO @S|@2 | $SED 's/:/ /g'`\" + ;; + esac +} +]])# _LT_PREPARE_PATH_LIST + + +# _LT_SYS_DYNAMIC_LINKER([TAG]) +# ----------------------------- +# PORTME Fill in your ld.so characteristics +m4_defun([_LT_SYS_DYNAMIC_LINKER], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_OBJDUMP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CHECK_SHELL_FEATURES])dnl +m4_require([_LT_PREPARE_MUNGE_PATH_LIST])dnl +AC_MSG_CHECKING([dynamic linker characteristics]) +m4_if([$1], + [], [ +if test yes = "$GCC"; then + case $host_os in + darwin*) lt_awk_arg='/^libraries:/,/LR/' ;; + *) lt_awk_arg='/^libraries:/' ;; + esac + case $host_os in + mingw* | cegcc*) lt_sed_strip_eq='s|=\([[A-Za-z]]:\)|\1|g' ;; + *) lt_sed_strip_eq='s|=/|/|g' ;; + esac + lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` + case $lt_search_path_spec in + *\;*) + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` + ;; + *) + lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` + ;; + esac + # Ok, now we have the path, separated by spaces, we can step through it + # and add multilib dir if necessary... + lt_tmp_lt_search_path_spec= + lt_multi_os_dir=/`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` + # ...but if some path component already ends with the multilib dir we assume + # that all is fine and trust -print-search-dirs as is (GCC 4.2? or newer). + case "$lt_multi_os_dir; $lt_search_path_spec " in + "/; "* | "/.; "* | "/./; "* | *"$lt_multi_os_dir "* | *"$lt_multi_os_dir/ "*) + lt_multi_os_dir= + ;; + esac + for lt_sys_path in $lt_search_path_spec; do + if test -d "$lt_sys_path$lt_multi_os_dir"; then + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path$lt_multi_os_dir" + elif test -n "$lt_multi_os_dir"; then + test -d "$lt_sys_path" && \ + lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" + fi + done + lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' +BEGIN {RS = " "; FS = "/|\n";} { + lt_foo = ""; + lt_count = 0; + for (lt_i = NF; lt_i > 0; lt_i--) { + if ($lt_i != "" && $lt_i != ".") { + if ($lt_i == "..") { + lt_count++; + } else { + if (lt_count == 0) { + lt_foo = "/" $lt_i lt_foo; + } else { + lt_count--; + } + } + } + } + if (lt_foo != "") { lt_freq[[lt_foo]]++; } + if (lt_freq[[lt_foo]] == 1) { print lt_foo; } +}'` + # AWK program above erroneously prepends '/' to C:/dos/paths + # for these hosts. + case $host_os in + mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + $SED 's|/\([[A-Za-z]]:\)|\1|g'` ;; + esac + sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=.so +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +AC_ARG_VAR([LT_SYS_LIBRARY_PATH], +[User-defined run-time library search path.]) + +case $host_os in +aix3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='$libname$release$shared_ext$major' + ;; + +aix[[4-9]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test ia64 = "$host_cpu"; then + # AIX 5 supports IA64 + library_names_spec='$libname$release$shared_ext$major $libname$release$shared_ext$versuffix $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line '#! .'. This would cause the generated library to + # depend on '.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | $CC -E - | $GREP yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # Using Import Files as archive members, it is possible to support + # filename-based versioning of shared library archives on AIX. While + # this would work for both with and without runtime linking, it will + # prevent static linking of such archives. So we do filename-based + # shared library versioning with .so extension only, which is used + # when both runtime linking and shared linking is enabled. + # Unfortunately, runtime linking may impact performance, so we do + # not want this to be the default eventually. Also, we use the + # versioned .so libs for executables only if there is the -brtl + # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # To allow for filename-based versioning support, we need to create + # libNAME.so.V as an archive file, containing: + # *) an Import File, referring to the versioned filename of the + # archive as well as the shared archive member, telling the + # bitwidth (32 or 64) of that shared object, and providing the + # list of exported symbols of that shared object, eventually + # decorated with the 'weak' keyword + # *) the shared object with the F_LOADONLY flag set, to really avoid + # it being seen by the linker. + # At run time we better use the real file rather than another symlink, + # but for link time we create the symlink libNAME.so -> libNAME.so.V + + case $with_aix_soname,$aix_use_runtimelinking in + # AIX (on Power*) has no versioning support, so currently we cannot hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + aix,yes) # traditional libtool + dynamic_linker='AIX unversionable lib.so' + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + aix,no) # traditional AIX only + dynamic_linker='AIX lib.a[(]lib.so.V[)]' + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + ;; + svr4,*) # full svr4 only + dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)]" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,yes) # both, prefer svr4 + dynamic_linker="AIX lib.so.V[(]$shared_archive_member_spec.o[)], lib.a[(]lib.so.V[)]" + library_names_spec='$libname$release$shared_ext$major $libname$shared_ext' + # unpreferred sharedlib libNAME.a needs extra handling + postinstall_cmds='test -n "$linkname" || linkname="$realname"~func_stripname "" ".so" "$linkname"~$install_shared_prog "$dir/$func_stripname_result.$libext" "$destdir/$func_stripname_result.$libext"~test -z "$tstripme" || test -z "$striplib" || $striplib "$destdir/$func_stripname_result.$libext"' + postuninstall_cmds='for n in $library_names $old_library; do :; done~func_stripname "" ".so" "$n"~test "$func_stripname_result" = "$n" || func_append rmfiles " $odir/$func_stripname_result.$libext"' + # We do not specify a path in Import Files, so LIBPATH fires. + shlibpath_overrides_runpath=yes + ;; + *,no) # both, prefer aix + dynamic_linker="AIX lib.a[(]lib.so.V[)], lib.so.V[(]$shared_archive_member_spec.o[)]" + library_names_spec='$libname$release.a $libname.a' + soname_spec='$libname$release$shared_ext$major' + # unpreferred sharedlib libNAME.so.V and symlink libNAME.so need extra handling + postinstall_cmds='test -z "$dlname" || $install_shared_prog $dir/$dlname $destdir/$dlname~test -z "$tstripme" || test -z "$striplib" || $striplib $destdir/$dlname~test -n "$linkname" || linkname=$realname~func_stripname "" ".a" "$linkname"~(cd "$destdir" && $LN_S -f $dlname $func_stripname_result.so)' + postuninstall_cmds='test -z "$dlname" || func_append rmfiles " $odir/$dlname"~for n in $old_library $library_names; do :; done~func_stripname "" ".a" "$n"~func_append rmfiles " $odir/$func_stripname_result.so"' + ;; + esac + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + case $host_cpu in + powerpc) + # Since July 2007 AmigaOS4 officially supports .so libraries. + # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + ;; + m68k) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + esac + ;; + +beos*) + library_names_spec='$libname$shared_ext' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32* | cegcc*) + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + + case $GCC,$cc_basename in + yes,*) + # gcc + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) + ;; + mingw* | cegcc*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + ;; + esac + dynamic_linker='Win32 ld.exe' + ;; + + *,cl*) + # Native MSVC + libname_spec='$name' + soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + library_names_spec='$libname.dll.lib' + + case $build_os in + mingw*) + sys_lib_search_path_spec= + lt_save_ifs=$IFS + IFS=';' + for lt_path in $LIB + do + IFS=$lt_save_ifs + # Let DOS variable expansion print the short 8.3 style file name. + lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` + sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" + done + IFS=$lt_save_ifs + # Convert to MSYS style. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` + ;; + cygwin*) + # Convert to unix form, then to dos form, then back to unix form + # but this time dos style (no spaces!) so that the unix form looks + # like /cygdrive/c/PROGRA~1:/cygdr... + sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` + sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` + sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + ;; + *) + sys_lib_search_path_spec=$LIB + if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH. + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + # FIXME: find the short name or the path components, as spaces are + # common. (e.g. "Program Files" -> "PROGRA~1") + ;; + esac + + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + shlibpath_overrides_runpath=yes + dynamic_linker='Win32 link.exe' + ;; + + *) + # Assume MSVC wrapper + library_names_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext $libname.lib' + dynamic_linker='Win32 ld.exe' + ;; + esac + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$major$shared_ext $libname$shared_ext' + soname_spec='$libname$release$major$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' +m4_if([$1], [],[ + sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + if test -x /usr/bin/objformat; then + objformat=`/usr/bin/objformat` + else + case $host_os in + freebsd[[23]].*) objformat=aout ;; + *) objformat=elf ;; + esac + fi + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2.*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ + freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + *) # from 4.6 on, and DragonFly + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + esac + ;; + +haiku*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + dynamic_linker="$host_os runtime_loader" + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LIBRARY_PATH + shlibpath_overrides_runpath=no + sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case $host_cpu in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + if test 32 = "$HPUX_IA64_MODE"; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + sys_lib_dlsearch_path_spec=/usr/lib/hpux32 + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + sys_lib_dlsearch_path_spec=/usr/lib/hpux64 + fi + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555, ... + postinstall_cmds='chmod 555 $lib' + # or fails outright, so override atomically: + install_override_mode=555 + ;; + +interix[[3-9]]*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test yes = "$lt_cv_prog_gnu_ld"; then + version_type=linux # correct to gnu/linux during the next big refactor + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$release$shared_ext $libname$shared_ext' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib$libsuff /lib$libsuff /usr/local/lib$libsuff" + sys_lib_dlsearch_path_spec="/usr/lib$libsuff /lib$libsuff" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +linux*android*) + version_type=none # Android doesn't support versioned libraries. + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext' + soname_spec='$libname$release$shared_ext' + finish_cmds= + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + dynamic_linker='Android linker' + # Don't embed -rpath directories since the linker doesn't support them. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + + # Some binutils ld are patched to set DT_RUNPATH + AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], + [lt_cv_shlibpath_overrides_runpath=no + save_LDFLAGS=$LDFLAGS + save_libdir=$libdir + eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ + LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" + AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], + [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], + [lt_cv_shlibpath_overrides_runpath=yes])]) + LDFLAGS=$save_LDFLAGS + libdir=$save_libdir + ]) + shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath + + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # Add ABI-specific directories to the system library path. + sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib" + + # Ideally, we could use ldconfig to report *all* directores which are + # searched for libraries, however this is still not possible. Aside from not + # being certain /sbin/ldconfig is available, command + # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, + # even though it is searched at run-time. Try to do the best guess by + # appending ld.so.conf contents (and includes) to the search path. + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +*nto* | *qnx*) + version_type=qnx + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='ldqnx.so' + ;; + +openbsd* | bitrig*) + version_type=sunos + sys_lib_dlsearch_path_spec=/usr/lib + need_lib_prefix=no + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + need_version=no + else + need_version=yes + fi + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +os2*) + libname_spec='$name' + version_type=windows + shrext_cmds=.dll + need_version=no + need_lib_prefix=no + # OS/2 can only load a DLL with a base name of 8 characters or less. + soname_spec='`test -n "$os2dllname" && libname="$os2dllname"; + v=$($ECHO $release$versuffix | tr -d .-); + n=$($ECHO $libname | cut -b -$((8 - ${#v})) | tr . _); + $ECHO $n$v`$shared_ext' + library_names_spec='${libname}_dll.$libext' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=BEGINLIBPATH + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; $ECHO \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname~ + chmod a+x \$dldir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; + fi' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; $ECHO \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $RM \$dlpath' + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='$libname$release$shared_ext$major' + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + +rdos*) + dynamic_linker=no + ;; + +solaris*) + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='$libname$release$shared_ext$versuffix $libname$shared_ext$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test yes = "$with_gnu_ld"; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.3*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec; then + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$shared_ext.$versuffix $libname$shared_ext.$major $libname$shared_ext' + soname_spec='$libname$shared_ext.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + version_type=sco + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + if test yes = "$with_gnu_ld"; then + sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' + else + sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' + case $host_os in + sco3.2v5*) + sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" + ;; + esac + fi + sys_lib_dlsearch_path_spec='/usr/lib' + ;; + +tpf*) + # TPF is a cross-target only. Preferred cross-host = GNU/Linux. + version_type=linux # correct to gnu/linux during the next big refactor + need_lib_prefix=no + need_version=no + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + +uts4*) + version_type=linux # correct to gnu/linux during the next big refactor + library_names_spec='$libname$release$shared_ext$versuffix $libname$release$shared_ext$major $libname$shared_ext' + soname_spec='$libname$release$shared_ext$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test no = "$dynamic_linker" && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test yes = "$GCC"; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +if test set = "${lt_cv_sys_lib_search_path_spec+set}"; then + sys_lib_search_path_spec=$lt_cv_sys_lib_search_path_spec +fi + +if test set = "${lt_cv_sys_lib_dlsearch_path_spec+set}"; then + sys_lib_dlsearch_path_spec=$lt_cv_sys_lib_dlsearch_path_spec +fi + +# remember unaugmented sys_lib_dlsearch_path content for libtool script decls... +configure_time_dlsearch_path=$sys_lib_dlsearch_path_spec + +# ... but it needs LT_SYS_LIBRARY_PATH munging for other configure-time code +func_munge_path_list sys_lib_dlsearch_path_spec "$LT_SYS_LIBRARY_PATH" + +# to be used as default LT_SYS_LIBRARY_PATH value in generated libtool +configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH + +_LT_DECL([], [variables_saved_for_relink], [1], + [Variables whose values should be saved in libtool wrapper scripts and + restored at link time]) +_LT_DECL([], [need_lib_prefix], [0], + [Do we need the "lib" prefix for modules?]) +_LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) +_LT_DECL([], [version_type], [0], [Library versioning type]) +_LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) +_LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) +_LT_DECL([], [shlibpath_overrides_runpath], [0], + [Is shlibpath searched before the hard-coded library search path?]) +_LT_DECL([], [libname_spec], [1], [Format of library name prefix]) +_LT_DECL([], [library_names_spec], [1], + [[List of archive names. First name is the real one, the rest are links. + The last name is the one that the linker finds with -lNAME]]) +_LT_DECL([], [soname_spec], [1], + [[The coded name of the library, if different from the real name]]) +_LT_DECL([], [install_override_mode], [1], + [Permission mode override for installation of shared libraries]) +_LT_DECL([], [postinstall_cmds], [2], + [Command to use after installation of a shared archive]) +_LT_DECL([], [postuninstall_cmds], [2], + [Command to use after uninstallation of a shared archive]) +_LT_DECL([], [finish_cmds], [2], + [Commands used to finish a libtool library installation in a directory]) +_LT_DECL([], [finish_eval], [1], + [[As "finish_cmds", except a single script fragment to be evaled but + not shown]]) +_LT_DECL([], [hardcode_into_libs], [0], + [Whether we should hardcode library paths into libraries]) +_LT_DECL([], [sys_lib_search_path_spec], [2], + [Compile-time system search path for libraries]) +_LT_DECL([sys_lib_dlsearch_path_spec], [configure_time_dlsearch_path], [2], + [Detected run-time system search path for libraries]) +_LT_DECL([], [configure_time_lt_sys_library_path], [2], + [Explicit LT_SYS_LIBRARY_PATH set during ./configure time]) +])# _LT_SYS_DYNAMIC_LINKER + + +# _LT_PATH_TOOL_PREFIX(TOOL) +# -------------------------- +# find a file program that can recognize shared library +AC_DEFUN([_LT_PATH_TOOL_PREFIX], +[m4_require([_LT_DECL_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD=$MAGIC_CMD + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="m4_if([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$1"; then + lt_cv_path_MAGIC_CMD=$ac_dir/"$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` + MAGIC_CMD=$lt_cv_path_MAGIC_CMD + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <<_LT_EOF 1>&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +_LT_EOF + fi ;; + esac + fi + break + fi + done + IFS=$lt_save_ifs + MAGIC_CMD=$lt_save_MAGIC_CMD + ;; +esac]) +MAGIC_CMD=$lt_cv_path_MAGIC_CMD +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +_LT_DECL([], [MAGIC_CMD], [0], + [Used to examine libraries when file_magic_cmd begins with "file"])dnl +])# _LT_PATH_TOOL_PREFIX + +# Old name: +AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) + + +# _LT_PATH_MAGIC +# -------------- +# find a file program that can recognize a shared library +m4_defun([_LT_PATH_MAGIC], +[_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# _LT_PATH_MAGIC + + +# LT_PATH_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([LT_PATH_LD], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PROG_ECHO_BACKSLASH])dnl + +AC_ARG_WITH([gnu-ld], + [AS_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test no = "$withval" || with_gnu_ld=yes], + [with_gnu_ld=no])dnl + +ac_prog=ld +if test yes = "$GCC"; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return, which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` + while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do + ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD=$ac_prog + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test yes = "$with_gnu_ld"; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD=$ac_dir/$ac_prog + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some variants of GNU ld only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 conftest.i +cat conftest.i conftest.i >conftest2.i +: ${lt_DD:=$DD} +AC_PATH_PROGS_FEATURE_CHECK([lt_DD], [dd], +[if "$ac_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && ac_cv_path_lt_DD="$ac_path_lt_DD" ac_path_lt_DD_found=: +fi]) +rm -f conftest.i conftest2.i conftest.out]) +])# _LT_PATH_DD + + +# _LT_CMD_TRUNCATE +# ---------------- +# find command to truncate a binary pipe +m4_defun([_LT_CMD_TRUNCATE], +[m4_require([_LT_PATH_DD]) +AC_CACHE_CHECK([how to truncate binary pipes], [lt_cv_truncate_bin], +[printf 0123456789abcdef0123456789abcdef >conftest.i +cat conftest.i conftest.i >conftest2.i +lt_cv_truncate_bin= +if "$ac_cv_path_lt_DD" bs=32 count=1 conftest.out 2>/dev/null; then + cmp -s conftest.i conftest.out \ + && lt_cv_truncate_bin="$ac_cv_path_lt_DD bs=4096 count=1" +fi +rm -f conftest.i conftest2.i conftest.out +test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q"]) +_LT_DECL([lt_truncate_bin], [lt_cv_truncate_bin], [1], + [Command to truncate a binary pipe]) +])# _LT_CMD_TRUNCATE + + +# _LT_CHECK_MAGIC_METHOD +# ---------------------- +# how to check for library dependencies +# -- PORTME fill in with the dynamic library characteristics +m4_defun([_LT_CHECK_MAGIC_METHOD], +[m4_require([_LT_DECL_EGREP]) +m4_require([_LT_DECL_OBJDUMP]) +AC_CACHE_CHECK([how to recognize dependent libraries], +lt_cv_deplibs_check_method, +[lt_cv_file_magic_cmd='$MAGIC_CMD' +lt_cv_file_magic_test_file= +lt_cv_deplibs_check_method='unknown' +# Need to set the preceding variable on all platforms that support +# interlibrary dependencies. +# 'none' -- dependencies not supported. +# 'unknown' -- same as none, but documents that we really don't know. +# 'pass_all' -- all dependencies passed with no checks. +# 'test_compile' -- check by making test program. +# 'file_magic [[regex]]' -- check by looking for files in library path +# that responds to the $file_magic_cmd with a given extended regex. +# If you have 'file' or equivalent on your system and you're not sure +# whether 'pass_all' will *always* work, you probably want this one. + +case $host_os in +aix[[4-9]]*) + lt_cv_deplibs_check_method=pass_all + ;; + +beos*) + lt_cv_deplibs_check_method=pass_all + ;; + +bsdi[[45]]*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)' + lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_test_file=/shlib/libc.so + ;; + +cygwin*) + # func_win32_libid is a shell function defined in ltmain.sh + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + ;; + +mingw* | pw32*) + # Base MSYS/MinGW do not provide the 'file' command needed by + # func_win32_libid shell function, so use a weaker test based on 'objdump', + # unless we find 'file', for example because we are cross-compiling. + if ( file / ) >/dev/null 2>&1; then + lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' + lt_cv_file_magic_cmd='func_win32_libid' + else + # Keep this pattern in sync with the one in func_win32_libid. + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_file_magic_cmd='$OBJDUMP -f' + fi + ;; + +cegcc*) + # use the weaker test based on 'objdump'. See mingw*. + lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' + lt_cv_file_magic_cmd='$OBJDUMP -f' + ;; + +darwin* | rhapsody*) + lt_cv_deplibs_check_method=pass_all + ;; + +freebsd* | dragonfly*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +haiku*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case $host_cpu in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +interix[[3-9]]*) + # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be glibc/ELF. +linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +*nto* | *qnx*) + lt_cv_deplibs_check_method=pass_all + ;; + +openbsd* | bitrig*) + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +rdos*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.3*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + pc) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +tpf*) + lt_cv_deplibs_check_method=pass_all + ;; +os2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) + +file_magic_glob= +want_nocaseglob=no +if test "$build" = "$host"; then + case $host_os in + mingw* | pw32*) + if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then + want_nocaseglob=yes + else + file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"` + fi + ;; + esac +fi + +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown + +_LT_DECL([], [deplibs_check_method], [1], + [Method to check whether dependent libraries are shared objects]) +_LT_DECL([], [file_magic_cmd], [1], + [Command to use when deplibs_check_method = "file_magic"]) +_LT_DECL([], [file_magic_glob], [1], + [How to find potential files when deplibs_check_method = "file_magic"]) +_LT_DECL([], [want_nocaseglob], [1], + [Find potential files using nocaseglob when deplibs_check_method = "file_magic"]) +])# _LT_CHECK_MAGIC_METHOD + + +# LT_PATH_NM +# ---------- +# find the pathname to a BSD- or MS-compatible name lister +AC_DEFUN([LT_PATH_NM], +[AC_REQUIRE([AC_PROG_CC])dnl +AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM=$NM +else + lt_nm_to_check=${ac_tool_prefix}nm + if test -n "$ac_tool_prefix" && test "$build" = "$host"; then + lt_nm_to_check="$lt_nm_to_check nm" + fi + for lt_tmp_nm in $lt_nm_to_check; do + lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do + IFS=$lt_save_ifs + test -z "$ac_dir" && ac_dir=. + tmp_nm=$ac_dir/$lt_tmp_nm + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext"; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the 'sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty + case $build_os in + mingw*) lt_bad_file=conftest.nm/nofile ;; + *) lt_bad_file=/dev/null ;; + esac + case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + *$lt_bad_file* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break 2 + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break 2 + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + ;; + esac + fi + done + IFS=$lt_save_ifs + done + : ${lt_cv_path_NM=no} +fi]) +if test no != "$lt_cv_path_NM"; then + NM=$lt_cv_path_NM +else + # Didn't find any BSD compatible name lister, look for dumpbin. + if test -n "$DUMPBIN"; then : + # Let the user override the test. + else + AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + *COFF*) + DUMPBIN="$DUMPBIN -symbols -headers" + ;; + *) + DUMPBIN=: + ;; + esac + fi + AC_SUBST([DUMPBIN]) + if test : != "$DUMPBIN"; then + NM=$DUMPBIN + fi +fi +test -z "$NM" && NM=nm +AC_SUBST([NM]) +_LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl + +AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], + [lt_cv_nm_interface="BSD nm" + echo "int some_variable = 0;" > conftest.$ac_ext + (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$ac_compile" 2>conftest.err) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) + (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) + cat conftest.err >&AS_MESSAGE_LOG_FD + (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD) + cat conftest.out >&AS_MESSAGE_LOG_FD + if $GREP 'External.*some_variable' conftest.out > /dev/null; then + lt_cv_nm_interface="MS dumpbin" + fi + rm -f conftest*]) +])# LT_PATH_NM + +# Old names: +AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) +AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_PROG_NM], []) +dnl AC_DEFUN([AC_PROG_NM], []) + +# _LT_CHECK_SHAREDLIB_FROM_LINKLIB +# -------------------------------- +# how to determine the name of the shared library +# associated with a specific link library. +# -- PORTME fill in with the dynamic library characteristics +m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB], +[m4_require([_LT_DECL_EGREP]) +m4_require([_LT_DECL_OBJDUMP]) +m4_require([_LT_DECL_DLLTOOL]) +AC_CACHE_CHECK([how to associate runtime and link libraries], +lt_cv_sharedlib_from_linklib_cmd, +[lt_cv_sharedlib_from_linklib_cmd='unknown' + +case $host_os in +cygwin* | mingw* | pw32* | cegcc*) + # two different shell functions defined in ltmain.sh; + # decide which one to use based on capabilities of $DLLTOOL + case `$DLLTOOL --help 2>&1` in + *--identify-strict*) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib + ;; + *) + lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback + ;; + esac + ;; +*) + # fallback: assume linklib IS sharedlib + lt_cv_sharedlib_from_linklib_cmd=$ECHO + ;; +esac +]) +sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd +test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO + +_LT_DECL([], [sharedlib_from_linklib_cmd], [1], + [Command to associate shared and link libraries]) +])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB + + +# _LT_PATH_MANIFEST_TOOL +# ---------------------- +# locate the manifest tool +m4_defun([_LT_PATH_MANIFEST_TOOL], +[AC_CHECK_TOOL(MANIFEST_TOOL, mt, :) +test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt +AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool], + [lt_cv_path_mainfest_tool=no + echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD + $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out + cat conftest.err >&AS_MESSAGE_LOG_FD + if $GREP 'Manifest Tool' conftest.out > /dev/null; then + lt_cv_path_mainfest_tool=yes + fi + rm -f conftest*]) +if test yes != "$lt_cv_path_mainfest_tool"; then + MANIFEST_TOOL=: +fi +_LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl +])# _LT_PATH_MANIFEST_TOOL + + +# _LT_DLL_DEF_P([FILE]) +# --------------------- +# True iff FILE is a Windows DLL '.def' file. +# Keep in sync with func_dll_def_p in the libtool script +AC_DEFUN([_LT_DLL_DEF_P], +[dnl + test DEF = "`$SED -n dnl + -e '\''s/^[[ ]]*//'\'' dnl Strip leading whitespace + -e '\''/^\(;.*\)*$/d'\'' dnl Delete empty lines and comments + -e '\''s/^\(EXPORTS\|LIBRARY\)\([[ ]].*\)*$/DEF/p'\'' dnl + -e q dnl Only consider the first "real" line + $1`" dnl +])# _LT_DLL_DEF_P + + +# LT_LIB_M +# -------- +# check for math library +AC_DEFUN([LT_LIB_M], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM=-lmw) + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM=-lm) + ;; +esac +AC_SUBST([LIBM]) +])# LT_LIB_M + +# Old name: +AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_CHECK_LIBM], []) + + +# _LT_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------- +m4_defun([_LT_COMPILER_NO_RTTI], +[m4_require([_LT_TAG_COMPILER])dnl + +_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test yes = "$GCC"; then + case $cc_basename in + nvcc*) + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;; + *) + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;; + esac + + _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +_LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], + [Compiler flag to turn off builtin functions]) +])# _LT_COMPILER_NO_RTTI + + +# _LT_CMD_GLOBAL_SYMBOLS +# ---------------------- +m4_defun([_LT_CMD_GLOBAL_SYMBOLS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_AWK])dnl +AC_REQUIRE([LT_PATH_NM])dnl +AC_REQUIRE([LT_PATH_LD])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_TAG_COMPILER])dnl + +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32* | cegcc*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) + if test ia64 = "$host_cpu"; then + symcode='[[ABCDEGRST]]' + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris*) + symcode='[[BDRT]]' + ;; +sco3.2v5*) + symcode='[[DT]]' + ;; +sysv4.2uw2*) + symcode='[[DT]]' + ;; +sysv5* | sco5v6* | unixware* | OpenUNIX*) + symcode='[[ABDT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Gets list of data symbols to import. + lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + # Adjust the below global symbol transforms to fixup imported variables. + lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" + lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" + lt_c_name_lib_hook="\ + -e 's/^I .* \(lib.*\)$/ {\"\1\", (void *) 0},/p'\ + -e 's/^I .* \(.*\)$/ {\"lib\1\", (void *) 0},/p'" +else + # Disable hooks by default. + lt_cv_sys_global_symbol_to_import= + lt_cdecl_hook= + lt_c_name_hook= + lt_c_name_lib_hook= +fi + +# Transform an extracted symbol line into a proper C declaration. +# Some systems (esp. on ia64) link data and code symbols differently, +# so use this general approach. +lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +$lt_cdecl_hook\ +" -e 's/^T .* \(.*\)$/extern int \1();/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +$lt_c_name_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" + +# Transform an extracted symbol line into symbol name with lib prefix and +# symbol address. +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +$lt_c_name_lib_hook\ +" -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ +" -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ +" -e 's/^$symcode$symcode* .* \(.*\)$/ {\"lib\1\", (void *) \&\1},/p'" + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# Try without a prefix underscore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + if test "$lt_cv_nm_interface" = "MS dumpbin"; then + # Fake it for dumpbin and say T for any non-static function, + # D for any global variable and I for any imported variable. + # Also find C++ and __fastcall symbols from MSVC++, + # which start with @ or ?. + lt_cv_sys_global_symbol_pipe="$AWK ['"\ +" {last_section=section; section=\$ 3};"\ +" /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ +" /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ +" /^ *Symbol name *: /{split(\$ 0,sn,\":\"); si=substr(sn[2],2)};"\ +" /^ *Type *: code/{print \"T\",si,substr(si,length(prfx))};"\ +" /^ *Type *: data/{print \"I\",si,substr(si,length(prfx))};"\ +" \$ 0!~/External *\|/{next};"\ +" / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ +" {if(hide[section]) next};"\ +" {f=\"D\"}; \$ 0~/\(\).*\|/{f=\"T\"};"\ +" {split(\$ 0,a,/\||\r/); split(a[2],s)};"\ +" s[1]~/^[@?]/{print f,s[1],s[1]; next};"\ +" s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ +" ' prfx=^$ac_symprfx]" + else + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + fi + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext <<_LT_EOF +#ifdef __cplusplus +extern "C" { +#endif +char nm_test_var; +void nm_test_func(void); +void nm_test_func(void){} +#ifdef __cplusplus +} +#endif +int main(){nm_test_var='a';nm_test_func();return(0);} +_LT_EOF + + if AC_TRY_EVAL(ac_compile); then + # Now try to grab the symbols. + nlist=conftest.nm + if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if $GREP ' nm_test_var$' "$nlist" >/dev/null; then + if $GREP ' nm_test_func$' "$nlist" >/dev/null; then + cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE +/* DATA imports from DLLs on WIN32 can't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT@&t@_DLSYM_CONST +#elif defined __osf__ +/* This system does not cope well with relocations in const data. */ +# define LT@&t@_DLSYM_CONST +#else +# define LT@&t@_DLSYM_CONST const +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +_LT_EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' + + cat <<_LT_EOF >> conftest.$ac_ext + +/* The mapping between symbol names and symbols. */ +LT@&t@_DLSYM_CONST struct { + const char *name; + void *address; +} +lt__PROGRAM__LTX_preloaded_symbols[[]] = +{ + { "@PROGRAM@", (void *) 0 }, +_LT_EOF + $SED "s/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext + cat <<\_LT_EOF >> conftest.$ac_ext + {0, (void *) 0} +}; + +/* This works around a problem in FreeBSD linker */ +#ifdef FREEBSD_WORKAROUND +static const void *lt_preloaded_setup() { + return lt__PROGRAM__LTX_preloaded_symbols; +} +#endif + +#ifdef __cplusplus +} +#endif +_LT_EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_globsym_save_LIBS=$LIBS + lt_globsym_save_CFLAGS=$CFLAGS + LIBS=conftstm.$ac_objext + CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest$ac_exeext; then + pipe_works=yes + fi + LIBS=$lt_globsym_save_LIBS + CFLAGS=$lt_globsym_save_CFLAGS + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -rf conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test yes = "$pipe_works"; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi + +# Response file support. +if test "$lt_cv_nm_interface" = "MS dumpbin"; then + nm_file_list_spec='@' +elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then + nm_file_list_spec='@' +fi + +_LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], + [Take the output of nm and produce a listing of raw symbols and C names]) +_LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], + [Transform the output of nm in a proper C declaration]) +_LT_DECL([global_symbol_to_import], [lt_cv_sys_global_symbol_to_import], [1], + [Transform the output of nm into a list of symbols to manually relocate]) +_LT_DECL([global_symbol_to_c_name_address], + [lt_cv_sys_global_symbol_to_c_name_address], [1], + [Transform the output of nm in a C name address pair]) +_LT_DECL([global_symbol_to_c_name_address_lib_prefix], + [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], + [Transform the output of nm in a C name address pair when lib prefix is needed]) +_LT_DECL([nm_interface], [lt_cv_nm_interface], [1], + [The name lister interface]) +_LT_DECL([], [nm_file_list_spec], [1], + [Specify filename containing input files for $NM]) +]) # _LT_CMD_GLOBAL_SYMBOLS + + +# _LT_COMPILER_PIC([TAGNAME]) +# --------------------------- +m4_defun([_LT_COMPILER_PIC], +[m4_require([_LT_TAG_COMPILER])dnl +_LT_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_TAGVAR(lt_prog_compiler_static, $1)= + +m4_if([$1], [CXX], [ + # C++ specific cases for pic, static, wl, etc. + if test yes = "$GXX"; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + _LT_TAGVAR(lt_prog_compiler_static, $1)= + ;; + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix[[4-9]]*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + mingw* | cygwin* | os2* | pw32* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + if test ia64 != "$host_cpu"; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + interix*) + # This is c89, which is MS Visual C++ (no shared libs) + # Anyone wants to do a port? + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + ecpc* ) + # old Intel C++ for x86_64, which still supported -KPIC. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + icpc* ) + # Intel C++, used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*) + # IBM XL 8.0, 9.0 on PPC and BlueGene + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + esac + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + *qnx* | *nto*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + case $cc_basename in + CC*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + vxworks*) + ;; + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test yes = "$GCC"; then + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + m68k) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the '-m68020' flag to GCC prevents building anything better, + # like '-m68040'. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + esac + ;; + + beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + # Although the cygwin gcc ignores -fPIC, still need this for old-style + # (--disable-auto-import) libraries + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + haiku*) + # PIC is the default for Haiku. + # The "-static" flag exists, but is broken. + _LT_TAGVAR(lt_prog_compiler_static, $1)= + ;; + + hpux*) + # PIC is the default for 64-bit PA HP-UX, but not for 32-bit + # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + case $host_cpu in + hppa*64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + interix[[3-9]]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + + case $cc_basename in + nvcc*) # Cuda Compiler Driver 2.2 + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker ' + if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)" + fi + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test ia64 = "$host_cpu"; then + # AIX 5 now supports IA64 processor + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + case $cc_basename in + nagfor*) + # NAG Fortran compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + + mingw* | cygwin* | pw32* | os2* | cegcc*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + m4_if([$1], [GCJ], [], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) + case $host_os in + os2*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-static' + ;; + esac + ;; + + hpux9* | hpux10* | hpux11*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case $host_cpu in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_TAGVAR(lt_prog_compiler_static, $1)='$wl-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + # old Intel for x86_64, which still supported -KPIC. + ecc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # icc used to be incompatible with GCC. + # ICC 10 doesn't accept -KPIC any more. + icc* | ifort*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + # Lahey Fortran 8.1. + lf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' + _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' + ;; + nagfor*) + # NAG Fortran compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + ccc*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + xl* | bgxl* | bgf* | mpixl*) + # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*) + # Sun Fortran 8.3 passes all unrecognized flags to the linker + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='' + ;; + *Sun\ F* | *Sun*Fortran*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + *Sun\ C*) + # Sun C 5.9 + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + *Intel*\ [[CF]]*Compiler*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + *Portland\ Group*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + esac + ;; + esac + ;; + + newsos6) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *nto* | *qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' + ;; + + osf3* | osf4* | osf5*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + rdos*) + _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + solaris*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + unicos*) + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +]) +case $host_os in + # For platforms that do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" + ;; +esac + +AC_CACHE_CHECK([for $compiler option to produce PIC], + [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)], + [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) +_LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1) + +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then + _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], + [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], + [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +_LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], + [Additional compiler flags for building library objects]) + +_LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], + [How to pass a linker flag through the compiler]) +# +# Check to make sure the static flag actually works. +# +wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" +_LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], + _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), + $lt_tmp_static_flag, + [], + [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) +_LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], + [Compiler flag to prevent dynamic linking]) +])# _LT_COMPILER_PIC + + +# _LT_LINKER_SHLIBS([TAGNAME]) +# ---------------------------- +# See if the linker supports building shared libraries. +m4_defun([_LT_LINKER_SHLIBS], +[AC_REQUIRE([LT_PATH_LD])dnl +AC_REQUIRE([LT_PATH_NM])dnl +m4_require([_LT_PATH_MANIFEST_TOOL])dnl +m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_DECL_SED])dnl +m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl +m4_require([_LT_TAG_COMPILER])dnl +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +m4_if([$1], [CXX], [ + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + case $host_os in + aix[[4-9]]*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_TAGVAR(export_symbols_cmds, $1)=$ltdll_cmds + ;; + cygwin* | mingw* | cegcc*) + case $cc_basename in + cl*) + _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] + ;; + esac + ;; + *) + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac +], [ + runpath_var= + _LT_TAGVAR(allow_undefined_flag, $1)= + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(archive_cmds, $1)= + _LT_TAGVAR(archive_expsym_cmds, $1)= + _LT_TAGVAR(compiler_needs_object, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(hardcode_automatic, $1)=no + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(hardcode_libdir_separator, $1)= + _LT_TAGVAR(hardcode_minus_L, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_TAGVAR(inherit_rpath, $1)=no + _LT_TAGVAR(link_all_deplibs, $1)=unknown + _LT_TAGVAR(module_cmds, $1)= + _LT_TAGVAR(module_expsym_cmds, $1)= + _LT_TAGVAR(old_archive_from_new_cmds, $1)= + _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_TAGVAR(thread_safe_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ' (' and ')$', so one must not match beginning or + # end of line. Example: 'a|bc|.*d.*' will exclude the symbols 'a' and 'bc', + # as well as any symbol that contains 'd'. + _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + # Exclude shared library initialization/finalization symbols. +dnl Note also adjust exclude_expsyms for C++ above. + extract_expsyms_cmds= + + case $host_os in + cygwin* | mingw* | pw32* | cegcc*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test yes != "$GCC"; then + with_gnu_ld=no + fi + ;; + interix*) + # we just hope/assume this is gcc and not c89 (= MSVC++) + with_gnu_ld=yes + ;; + openbsd* | bitrig*) + with_gnu_ld=no + ;; + esac + + _LT_TAGVAR(ld_shlibs, $1)=yes + + # On some targets, GNU ld is compatible enough with the native linker + # that we're better off using the native interface for both. + lt_use_gnu_ld_interface=no + if test yes = "$with_gnu_ld"; then + case $host_os in + aix*) + # The AIX port of GNU ld has always aspired to compatibility + # with the native linker. However, as the warning in the GNU ld + # block says, versions before 2.19.5* couldn't really create working + # shared libraries, regardless of the interface used. + case `$LD -v 2>&1` in + *\ \(GNU\ Binutils\)\ 2.19.5*) ;; + *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;; + *\ \(GNU\ Binutils\)\ [[3-9]]*) ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + ;; + *) + lt_use_gnu_ld_interface=yes + ;; + esac + fi + + if test yes = "$lt_use_gnu_ld_interface"; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='$wl' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v | $SED -e 's/([^)]\+)\s\+//' 2>&1` in + *GNU\ gold*) supports_anon_versioning=yes ;; + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix[[3-9]]*) + # On AIX/PPC, the GNU linker is very broken + if test ia64 != "$host_cpu"; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: the GNU linker, at least up to release 2.19, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to install binutils +*** 2.20 or above, or modify your PATH so that a non-GNU linker is found. +*** You will then need to restart the configuration process. + +_LT_EOF + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' + _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + haiku*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + + gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + tmp_diet=no + if test linux-dietlibc = "$host_os"; then + case $cc_basename in + diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) + esac + fi + if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ + && test no = "$tmp_diet" + then + tmp_addflag=' $pic_flag' + tmp_sharedflag='-shared' + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* | pgf95* | pgfortran*) + # Portland Group f77 and f90 compilers + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + lf95*) # Lahey Fortran 8.1 + _LT_TAGVAR(whole_archive_flag_spec, $1)= + tmp_sharedflag='--shared' ;; + nagfor*) # NAGFOR 5.3 + tmp_sharedflag='-Wl,-shared' ;; + xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) + tmp_sharedflag='-qmkshrobj' + tmp_addflag= ;; + nvcc*) # Cuda Compiler Driver 2.2 + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + ;; + esac + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) # Sun C 5.9 + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + tmp_sharedflag='-G' ;; + *Sun\ F*) # Sun Fortran 8.3 + tmp_sharedflag='-G' ;; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + + case $cc_basename in + tcc*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-rdynamic' + ;; + xlf* | bgf* | bgxlf* | mpixlf*) + # IBM XL Fortran 10.1 on PPC cannot create shared libs itself + _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' + fi + ;; + esac + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris*) + if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) + case `$LD -v 2>&1` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) + _LT_TAGVAR(ld_shlibs, $1)=no + cat <<_LT_EOF 1>&2 + +*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 cannot +*** reliably create shared libraries on SCO systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.16.91.0.3 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +_LT_EOF + ;; + *) + # For security reasons, it is highly recommended that you always + # use absolute paths for naming shared libraries, and exclude the + # DT_RUNPATH tag from executables and libraries. But doing so + # requires that you compile everything twice, which is a pain. + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + sunos4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test no = "$_LT_TAGVAR(ld_shlibs, $1)"; then + runpath_var= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + if test yes = "$GCC" && test -z "$lt_prog_compiler_static"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix[[4-9]]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to GNU nm, but means don't demangle to AIX nm. + # Without the "-l" option, or with the "-B" option, AIX nm treats + # weak defined symbols like other global defined symbols, whereas + # GNU nm marks them as "W". + # While the 'weak' keyword is ignored in the Export File, we need + # it in the Import File for the 'aix-soname' feature, so we have + # to replace the "-B" option with "-P" for AIX nm. + if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then + _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' + else + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + if (test x-brtl = "x$ld_flag" || test x-Wl,-brtl = "x$ld_flag"); then + aix_use_runtimelinking=yes + break + fi + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # traditional, no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + ;; + esac + + if test yes = "$GCC"; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + ;; + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag="$shared_flag "'$wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared libraries. + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + amigaos*) + case $host_cpu in + powerpc) + # see comment about AmigaOS4 .so support + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='' + ;; + m68k) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + ;; + + bsdi[[45]]*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32* | cegcc*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + case $cc_basename in + cl*) + # Native MSVC + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' + _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' + # Don't use ranlib + _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' + _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # Assume MSVC wrapper + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + esac + ;; + + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + dgux*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2.*) + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | dragonfly*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + ;; + + hpux10*) + if test yes,no = "$GCC,$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + fi + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + fi + ;; + + hpux11*) + if test yes,no = "$GCC,$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + m4_if($1, [], [ + # Older versions of the 11.00 compiler do not understand -b yet + # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) + _LT_LINKER_OPTION([if $CC understands -b], + _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b], + [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags'], + [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])], + [_LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags']) + ;; + esac + fi + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + # Try to use the -exported_symbol ld option, if it does not + # work, assume that -exports_file does not work either and + # implicitly export all symbols. + # This should be the same for all languages, so no per-tag cache variable. + AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol], + [lt_cv_irix_exported_symbol], + [save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" + AC_LINK_IFELSE( + [AC_LANG_SOURCE( + [AC_LANG_CASE([C], [[int foo (void) { return 0; }]], + [C++], [[int foo (void) { return 0; }]], + [Fortran 77], [[ + subroutine foo + end]], + [Fortran], [[ + subroutine foo + end]])])], + [lt_cv_irix_exported_symbol=yes], + [lt_cv_irix_exported_symbol=no]) + LDFLAGS=$save_LDFLAGS]) + if test yes = "$lt_cv_irix_exported_symbol"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' + fi + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + linux*) + case $cc_basename in + tcc*) + # Fabrice Bellard et al's Tiny C Compiler + _LT_TAGVAR(ld_shlibs, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *nto* | *qnx*) + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags $wl-retain-symbols-file,$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + fi + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + osf3*) + if test yes = "$GCC"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test yes = "$GCC"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $pic_flag $libobjs $deplibs $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + else + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $wl-input $wl$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~$RM $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)='no' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + solaris*) + _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' + if test yes = "$GCC"; then + wlarc='$wl' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $wl-z ${wl}text $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag $wl-z ${wl}text $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + else + case `$CC -V 2>&1` in + *"Compilers 5.0"*) + wlarc='' + _LT_TAGVAR(archive_cmds, $1)='$LD -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $LD -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' + ;; + *) + wlarc='$wl' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h $soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' + ;; + esac + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. GCC discards it without '$wl', + # but is careful enough not to reorder. + # Supported since Solaris 2.6 (maybe 2.5.1?) + if test yes = "$GCC"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + fi + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test sequent = "$host_vendor"; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + if test yes = "$GCC"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + ;; + + uts4*) + _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + if test sni = "$host_vendor"; then + case $host in + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Blargedynsym' + ;; + esac + fi + fi +]) +AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) +test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no + +_LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld + +_LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl +_LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl +_LT_DECL([], [extract_expsyms_cmds], [2], + [The commands to extract the exported symbol list from a shared archive]) + +# +# Do we need to explicitly link libc? +# +case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test yes,yes = "$GCC,$enable_shared"; then + case $_LT_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_CACHE_CHECK([whether -lc should be explicitly linked in], + [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), + [$RM conftest* + echo "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) + pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) + _LT_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) + then + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no + else + lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $RM conftest* + ]) + _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) + ;; + esac + fi + ;; +esac + +_LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], + [Whether or not to add -lc for building shared libraries]) +_LT_TAGDECL([allow_libtool_libs_with_static_runtimes], + [enable_shared_with_static_runtimes], [0], + [Whether or not to disallow shared libs when runtime libs are static]) +_LT_TAGDECL([], [export_dynamic_flag_spec], [1], + [Compiler flag to allow reflexive dlopens]) +_LT_TAGDECL([], [whole_archive_flag_spec], [1], + [Compiler flag to generate shared objects directly from archives]) +_LT_TAGDECL([], [compiler_needs_object], [1], + [Whether the compiler copes with passing no objects directly]) +_LT_TAGDECL([], [old_archive_from_new_cmds], [2], + [Create an old-style archive from a shared archive]) +_LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], + [Create a temporary old-style archive to link instead of a shared archive]) +_LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) +_LT_TAGDECL([], [archive_expsym_cmds], [2]) +_LT_TAGDECL([], [module_cmds], [2], + [Commands used to build a loadable module if different from building + a shared archive.]) +_LT_TAGDECL([], [module_expsym_cmds], [2]) +_LT_TAGDECL([], [with_gnu_ld], [1], + [Whether we are building with GNU ld or not]) +_LT_TAGDECL([], [allow_undefined_flag], [1], + [Flag that allows shared libraries with undefined symbols to be built]) +_LT_TAGDECL([], [no_undefined_flag], [1], + [Flag that enforces no undefined symbols]) +_LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], + [Flag to hardcode $libdir into a binary during linking. + This must work even if $libdir does not exist]) +_LT_TAGDECL([], [hardcode_libdir_separator], [1], + [Whether we need a single "-rpath" flag with a separated argument]) +_LT_TAGDECL([], [hardcode_direct], [0], + [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes + DIR into the resulting binary]) +_LT_TAGDECL([], [hardcode_direct_absolute], [0], + [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes + DIR into the resulting binary and the resulting library dependency is + "absolute", i.e impossible to change by setting $shlibpath_var if the + library is relocated]) +_LT_TAGDECL([], [hardcode_minus_L], [0], + [Set to "yes" if using the -LDIR flag during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_shlibpath_var], [0], + [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR + into the resulting binary]) +_LT_TAGDECL([], [hardcode_automatic], [0], + [Set to "yes" if building a shared library automatically hardcodes DIR + into the library and all subsequent libraries and executables linked + against it]) +_LT_TAGDECL([], [inherit_rpath], [0], + [Set to yes if linker adds runtime paths of dependent libraries + to runtime path list]) +_LT_TAGDECL([], [link_all_deplibs], [0], + [Whether libtool must link a program against all its dependency libraries]) +_LT_TAGDECL([], [always_export_symbols], [0], + [Set to "yes" if exported symbols are required]) +_LT_TAGDECL([], [export_symbols_cmds], [2], + [The commands to list exported symbols]) +_LT_TAGDECL([], [exclude_expsyms], [1], + [Symbols that should not be listed in the preloaded symbols]) +_LT_TAGDECL([], [include_expsyms], [1], + [Symbols that must always be exported]) +_LT_TAGDECL([], [prelink_cmds], [2], + [Commands necessary for linking programs (against libraries) with templates]) +_LT_TAGDECL([], [postlink_cmds], [2], + [Commands necessary for finishing linking programs]) +_LT_TAGDECL([], [file_list_spec], [1], + [Specify filename containing input files]) +dnl FIXME: Not yet implemented +dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], +dnl [Compiler flag to generate thread safe objects]) +])# _LT_LINKER_SHLIBS + + +# _LT_LANG_C_CONFIG([TAG]) +# ------------------------ +# Ensure that the configuration variables for a C compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_C_CONFIG], +[m4_require([_LT_DECL_EGREP])dnl +lt_save_CC=$CC +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}' + +_LT_TAG_COMPILER +# Save the default compiler, since it gets overwritten when the other +# tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. +compiler_DEFAULT=$CC + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + LT_SYS_DLOPEN_SELF + _LT_CMD_STRIPLIB + + # Report what library types will actually be built + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_CONFIG($1) +fi +AC_LANG_POP +CC=$lt_save_CC +])# _LT_LANG_C_CONFIG + + +# _LT_LANG_CXX_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a C++ compiler are suitably +# defined. These variables are subsequently used by _LT_CONFIG to write +# the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_CXX_CONFIG], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +m4_require([_LT_DECL_EGREP])dnl +m4_require([_LT_PATH_MANIFEST_TOOL])dnl +if test -n "$CXX" && ( test no != "$CXX" && + ( (test g++ = "$CXX" && `g++ -v >/dev/null 2>&1` ) || + (test g++ != "$CXX"))); then + AC_PROG_CXXCPP +else + _lt_caught_CXX_error=yes +fi + +AC_LANG_PUSH(C++) +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(compiler_needs_object, $1)=no +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for C++ test sources. +ac_ext=cpp + +# Object file extension for compiled C++ test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the CXX compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_caught_CXX_error"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="int some_variable = 0;" + + # Code to be used in simple link tests + lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_CFLAGS=$CFLAGS + lt_save_LD=$LD + lt_save_GCC=$GCC + GCC=$GXX + lt_save_with_gnu_ld=$with_gnu_ld + lt_save_path_LD=$lt_cv_path_LD + if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx + else + $as_unset lt_cv_prog_gnu_ld + fi + if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX + else + $as_unset lt_cv_path_LD + fi + test -z "${LDCXX+set}" || LD=$LDCXX + CC=${CXX-"c++"} + CFLAGS=$CXXFLAGS + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + # We don't want -fno-exception when compiling C++ code, so set the + # no_builtin_flag separately + if test yes = "$GXX"; then + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + else + _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + fi + + if test yes = "$GXX"; then + # Set up default GNU C++ configuration + + LT_PATH_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test yes = "$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='$wl' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | + $GREP 'no-whole-archive' > /dev/null; then + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + GXX=no + with_gnu_ld=no + wlarc= + fi + + # PORTME: fill in a description of your system's C++ link characteristics + AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) + _LT_TAGVAR(ld_shlibs, $1)=yes + case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aix[[4-9]]*) + if test ia64 = "$host_cpu"; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag= + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # have runtime linking enabled, and use it for executables. + # For shared libraries, we enable/disable runtime linking + # depending on the kind of the shared library created - + # when "with_aix_soname,aix_use_runtimelinking" is: + # "aix,no" lib.a(lib.so.V) shared, rtl:no, for executables + # "aix,yes" lib.so shared, rtl:yes, for executables + # lib.a static archive + # "both,no" lib.so.V(shr.o) shared, rtl:yes + # lib.a(lib.so.V) shared, rtl:no, for executables + # "both,yes" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a(lib.so.V) shared, rtl:no + # "svr4,*" lib.so.V(shr.o) shared, rtl:yes, for executables + # lib.a static archive + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + if test svr4,no = "$with_aix_soname,$aix_use_runtimelinking"; then + # With aix-soname=svr4, we create the lib.so.V shared archives only, + # so we don't have lib.a shared libs to link our executables. + # We have to force runtime linking in this case. + aix_use_runtimelinking=yes + LDFLAGS="$LDFLAGS -Wl,-brtl" + fi + ;; + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_TAGVAR(archive_cmds, $1)='' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='$wl-f,' + case $with_aix_soname,$aix_use_runtimelinking in + aix,*) ;; # no import file + svr4,* | *,yes) # use import file + # The Import File defines what to hardcode. + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=no + ;; + esac + + if test yes = "$GXX"; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`$CC -print-prog-name=collect2` + if test -f "$collect2name" && + strings "$collect2name" | $GREP resolve_lib_name >/dev/null + then + # We have reworked collect2 + : + else + # We have old collect2 + _LT_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test yes = "$aix_use_runtimelinking"; then + shared_flag=$shared_flag' $wl-G' + fi + # Need to ensure runtime linking is disabled for the traditional + # shared library, or the linker may eventually find shared libraries + # /with/ Import File - we do not want to mix them. + shared_flag_aix='-shared' + shared_flag_svr4='-shared $wl-G' + else + # not using gcc + if test ia64 = "$host_cpu"; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test yes = "$aix_use_runtimelinking"; then + shared_flag='$wl-G' + else + shared_flag='$wl-bM:SRE' + fi + shared_flag_aix='$wl-bM:SRE' + shared_flag_svr4='$wl-G' + fi + fi + + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-bexpall' + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to + # export. + _LT_TAGVAR(always_export_symbols, $1)=yes + if test aix,yes = "$with_aix_soname,$aix_use_runtimelinking"; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + # The "-G" linker flag allows undefined symbols. + _LT_TAGVAR(no_undefined_flag, $1)='-bernotok' + # Determine the default libpath from the value encoded in an empty + # executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs $wl'$no_entry_flag' $compiler_flags `if test -n "$allow_undefined_flag"; then func_echo_all "$wl$allow_undefined_flag"; else :; fi` $wl'$exp_sym_flag:\$export_symbols' '$shared_flag + else + if test ia64 = "$host_cpu"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $libdir:/usr/lib:/lib' + _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\$wl$no_entry_flag"' $compiler_flags $wl$allow_undefined_flag '"\$wl$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an + # empty executable. + _LT_SYS_MODULE_PATH_AIX([$1]) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-bernotok' + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-berok' + if test yes = "$with_gnu_ld"; then + # We only use this code for GNU lds that support --whole-archive. + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + else + # Exported symbols can be pulled into shared objects from archives + _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' + fi + _LT_TAGVAR(archive_cmds_need_lc, $1)=yes + _LT_TAGVAR(archive_expsym_cmds, $1)='$RM -r $output_objdir/$realname.d~$MKDIR $output_objdir/$realname.d' + # -brtl affects multiple linker settings, -berok does not and is overridden later + compiler_flags_filtered='`func_echo_all "$compiler_flags " | $SED -e "s%-brtl\\([[, ]]\\)%-berok\\1%g"`' + if test svr4 != "$with_aix_soname"; then + # This is similar to how AIX traditionally builds its shared + # libraries. Need -bnortl late, we may have -brtl in LDFLAGS. + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_aix' -o $output_objdir/$realname.d/$soname $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$realname.d/$soname' + fi + if test aix != "$with_aix_soname"; then + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$CC '$shared_flag_svr4' -o $output_objdir/$realname.d/$shared_archive_member_spec.o $libobjs $deplibs $wl-bnoentry '$compiler_flags_filtered'$wl-bE:$export_symbols$allow_undefined_flag~$STRIP -e $output_objdir/$realname.d/$shared_archive_member_spec.o~( func_echo_all "#! $soname($shared_archive_member_spec.o)"; if test shr_64 = "$shared_archive_member_spec"; then func_echo_all "# 64"; else func_echo_all "# 32"; fi; cat $export_symbols ) > $output_objdir/$realname.d/$shared_archive_member_spec.imp~$AR $AR_FLAGS $output_objdir/$soname $output_objdir/$realname.d/$shared_archive_member_spec.o $output_objdir/$realname.d/$shared_archive_member_spec.imp' + else + # used by -dlpreopen to get the symbols + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$MV $output_objdir/$realname.d/$soname $output_objdir' + fi + _LT_TAGVAR(archive_expsym_cmds, $1)="$_LT_TAGVAR(archive_expsym_cmds, $1)"'~$RM -r $output_objdir/$realname.d' + fi + fi + ;; + + beos*) + if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + cygwin* | mingw* | pw32* | cegcc*) + case $GXX,$cc_basename in + ,cl* | no,cl*) + # Native MSVC + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=.dll + # FIXME: Setting linknames here is a bad hack. + _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp "$export_symbols" "$output_objdir/$soname.def"; + echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; + else + $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; + fi~ + $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + linknames=' + # The linker will not automatically build a static lib if we build a DLL. + # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + # Don't use ranlib + _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' + _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ + lt_tool_outputfile="@TOOL_OUTPUT@"~ + case $lt_outputfile in + *.exe|*.EXE) ;; + *) + lt_outputfile=$lt_outputfile.exe + lt_tool_outputfile=$lt_tool_outputfile.exe + ;; + esac~ + func_to_tool_file "$lt_outputfile"~ + if test : != "$MANIFEST_TOOL" && test -f "$lt_outputfile.manifest"; then + $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; + $RM "$lt_outputfile.manifest"; + fi' + ;; + *) + # g++ + # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-all-symbols' + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_TAGVAR(always_export_symbols, $1)=no + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + # If the export-symbols file already is a .def file, use it as + # is; otherwise, prepend EXPORTS... + _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname $wl--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + darwin* | rhapsody*) + _LT_DARWIN_LINKER_FEATURES($1) + ;; + + os2*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_TAGVAR(hardcode_minus_L, $1)=yes + _LT_TAGVAR(allow_undefined_flag, $1)=unsupported + shrext_cmds=.dll + _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + emxexp $libobjs | $SED /"_DLL_InitTerm"/d >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(archive_expsym_cmds, $1)='$ECHO "LIBRARY ${soname%$shared_ext} INITINSTANCE TERMINSTANCE" > $output_objdir/$libname.def~ + $ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~ + $ECHO "DATA MULTIPLE NONSHARED" >> $output_objdir/$libname.def~ + $ECHO EXPORTS >> $output_objdir/$libname.def~ + prefix_cmds="$SED"~ + if test EXPORTS = "`$SED 1q $export_symbols`"; then + prefix_cmds="$prefix_cmds -e 1d"; + fi~ + prefix_cmds="$prefix_cmds -e \"s/^\(.*\)$/_\1/g\""~ + cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ + $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ + emximp -o $lib $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + freebsd2.*) + # C++ shared libraries reported to be fairly broken before + # switch to ELF + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + freebsd-elf*) + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + + freebsd* | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + haiku*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + + hpux9*) + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag $wl+b $wl$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test "x$output_objdir/$soname" = "x$lib" || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + hpux10*|hpux11*) + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl+b $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + case $host_cpu in + hppa*64*|ia64*) + ;; + *) + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + ;; + esac + fi + case $host_cpu in + hppa*64*|ia64*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + *) + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + case $host_cpu in + hppa*64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC $wl+h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + ia64*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + interix[[3-9]]*) + _LT_TAGVAR(hardcode_direct, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. + # Instead, shared libraries are loaded at an image base (0x10000000 by + # default) and relocated if they conflict, which is a slow very memory + # consuming and fragmenting process. To avoid this, we pick a random, + # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link + # time. Moving up from 0x10000000 also allows more sbrk(2) space. + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test yes = "$GXX"; then + if test no = "$with_gnu_ld"; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + else + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` -o $lib' + fi + fi + _LT_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_TAGVAR(inherit_rpath, $1)=yes + ;; + + linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib $wl-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc* | ecpc* ) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive$convenience $wl--no-whole-archive' + ;; + pgCC* | pgcpp*) + # Portland Group C++ compiler + case `$CC -V` in + *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*) + _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ + compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' + _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ + $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ + $RANLIB $oldlib' + _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ + rm -rf $tpldir~ + $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ + $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 6 and above use weak symbols + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname $wl-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl--rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname -o $lib $wl-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' + ;; + xl* | mpixl* | bgxl*) + # IBM XL 8.0 on PPC, with GNU ld + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl--export-dynamic' + _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' + if test yes = "$supports_anon_versioning"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' + fi + ;; + *) + case `$CC -V 2>&1 | sed 5q` in + *Sun\ C*) + # Sun C++ 5.9 + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file $wl$export_symbols' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' + _LT_TAGVAR(compiler_needs_object, $1)=yes + + # Not sure whether something based on + # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 + # would be better. + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + esac + ;; + esac + ;; + + lynxos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + m88k*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + + *nto* | *qnx*) + _LT_TAGVAR(ld_shlibs, $1)=yes + ;; + + openbsd* | bitrig*) + if test -f /usr/libexec/ld.so; then + _LT_TAGVAR(hardcode_direct, $1)=yes + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_direct_absolute, $1)=yes + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`"; then + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-retain-symbols-file,$export_symbols -o $lib' + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-E' + _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' + fi + output_verbose_link_cmd=func_echo_all + else + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\$tempext\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + case $host in + osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; + *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; + esac + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + case $host in + osf3*) + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $soname `test -n "$verstring" && func_echo_all "$wl-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + ;; + *) + _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_TAGVAR(archive_cmds, $1)='$CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname $wl-input $wl$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib~ + $RM $lib.exp' + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + ;; + *) + if test yes,no = "$GXX,$with_gnu_ld"; then + _LT_TAGVAR(allow_undefined_flag, $1)=' $wl-expect_unresolved $wl\*' + case $host in + osf3*) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-msym $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations -o $lib' + ;; + esac + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + + psos*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + solaris*) + case $cc_basename in + CC* | sunCC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_TAGVAR(archive_cmds_need_lc,$1)=yes + _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_TAGVAR(archive_cmds, $1)='$CC -G$allow_undefined_flag -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G$allow_undefined_flag $wl-M $wl$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine and reorder linker options, + # but understands '-z linker_flag'. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' + ;; + esac + _LT_TAGVAR(link_all_deplibs, $1)=yes + + output_verbose_link_cmd='func_echo_all' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test yes,no = "$GXX,$with_gnu_ld"; then + _LT_TAGVAR(no_undefined_flag, $1)=' $wl-z ${wl}defs' + if $CC --version | $GREP -v '^2\.7' > /dev/null; then + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -shared $pic_flag -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + else + # g++ 2.7 appears to require '-G' NOT '-shared' on this + # platform. + _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags $wl-h $wl$soname -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib $wl-M $wl$lib.exp $wl-h $wl$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + fi + + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl-z ${wl}allextract$convenience $wl-z ${wl}defaultextract' + ;; + esac + fi + ;; + esac + ;; + + sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + sysv5* | sco3.2v5* | sco5v6*) + # Note: We CANNOT use -z defs as we might desire, because we do not + # link with -lc, and that would cause any symbols used from libc to + # always be unresolved, which means just about no library would + # ever link correctly. If we're not using GNU ld we use -z text + # though, which does catch some bad symbols but isn't as heavy-handed + # as -z defs. + _LT_TAGVAR(no_undefined_flag, $1)='$wl-z,text' + _LT_TAGVAR(allow_undefined_flag, $1)='$wl-z,nodefs' + _LT_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R,$libdir' + _LT_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_TAGVAR(link_all_deplibs, $1)=yes + _LT_TAGVAR(export_dynamic_flag_spec, $1)='$wl-Bexport' + runpath_var='LD_RUN_PATH' + + case $cc_basename in + CC*) + _LT_TAGVAR(archive_cmds, $1)='$CC -G $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~ + '"$_LT_TAGVAR(old_archive_cmds, $1)" + _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~ + '"$_LT_TAGVAR(reload_cmds, $1)" + ;; + *) + _LT_TAGVAR(archive_cmds, $1)='$CC -shared $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $wl-Bexport:$export_symbols $wl-h,$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + ;; + + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + vxworks*) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + + *) + # FIXME: insert proper C++ library support + _LT_TAGVAR(ld_shlibs, $1)=no + ;; + esac + + AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) + test no = "$_LT_TAGVAR(ld_shlibs, $1)" && can_build_shared=no + + _LT_TAGVAR(GCC, $1)=$GXX + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS + LDCXX=$LD + LD=$lt_save_LD + GCC=$lt_save_GCC + with_gnu_ld=$lt_save_with_gnu_ld + lt_cv_path_LDCXX=$lt_cv_path_LD + lt_cv_path_LD=$lt_save_path_LD + lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld + lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +fi # test yes != "$_lt_caught_CXX_error" + +AC_LANG_POP +])# _LT_LANG_CXX_CONFIG + + +# _LT_FUNC_STRIPNAME_CNF +# ---------------------- +# func_stripname_cnf prefix suffix name +# strip PREFIX and SUFFIX off of NAME. +# PREFIX and SUFFIX must not contain globbing or regex special +# characters, hashes, percent signs, but SUFFIX may contain a leading +# dot (in which case that matches only a dot). +# +# This function is identical to the (non-XSI) version of func_stripname, +# except this one can be used by m4 code that may be executed by configure, +# rather than the libtool script. +m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl +AC_REQUIRE([_LT_DECL_SED]) +AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH]) +func_stripname_cnf () +{ + case @S|@2 in + .*) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%\\\\@S|@2\$%%"`;; + *) func_stripname_result=`$ECHO "@S|@3" | $SED "s%^@S|@1%%; s%@S|@2\$%%"`;; + esac +} # func_stripname_cnf +])# _LT_FUNC_STRIPNAME_CNF + + +# _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) +# --------------------------------- +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +m4_defun([_LT_SYS_HIDDEN_LIBDEPS], +[m4_require([_LT_FILEUTILS_DEFAULTS])dnl +AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl +# Dependencies to place before and after the object being linked: +_LT_TAGVAR(predep_objects, $1)= +_LT_TAGVAR(postdep_objects, $1)= +_LT_TAGVAR(predeps, $1)= +_LT_TAGVAR(postdeps, $1)= +_LT_TAGVAR(compiler_lib_search_path, $1)= + +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF +int a; +void foo (void) { a = 0; } +_LT_EOF +], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF +class Foo +{ +public: + Foo (void) { a = 0; } +private: + int a; +}; +_LT_EOF +], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer*4 a + a=0 + return + end +_LT_EOF +], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF + subroutine foo + implicit none + integer a + a=0 + return + end +_LT_EOF +], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF +public class foo { + private int a; + public void bar (void) { + a = 0; + } +}; +_LT_EOF +], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF +package foo +func foo() { +} +_LT_EOF +]) + +_lt_libdeps_save_CFLAGS=$CFLAGS +case "$CC $CFLAGS " in #( +*\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; +*\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; +*\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; +esac + +dnl Parse the compiler output and extract the necessary +dnl objects, libraries and library flags. +if AC_TRY_EVAL(ac_compile); then + # Parse the compiler output and extract the necessary + # objects, libraries and library flags. + + # Sentinel used to keep track of whether or not we are before + # the conftest object file. + pre_test_object_deps_done=no + + for p in `eval "$output_verbose_link_cmd"`; do + case $prev$p in + + -L* | -R* | -l*) + # Some compilers place space between "-{L,R}" and the path. + # Remove the space. + if test x-L = "$p" || + test x-R = "$p"; then + prev=$p + continue + fi + + # Expand the sysroot to ease extracting the directories later. + if test -z "$prev"; then + case $p in + -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; + -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; + -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; + esac + fi + case $p in + =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; + esac + if test no = "$pre_test_object_deps_done"; then + case $prev in + -L | -R) + # Internal compiler library paths should come after those + # provided the user. The postdeps already come after the + # user supplied libs so there is no need to process them. + if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then + _LT_TAGVAR(compiler_lib_search_path, $1)=$prev$p + else + _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} $prev$p" + fi + ;; + # The "-l" case would never come before the object being + # linked, so don't bother handling this case. + esac + else + if test -z "$_LT_TAGVAR(postdeps, $1)"; then + _LT_TAGVAR(postdeps, $1)=$prev$p + else + _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} $prev$p" + fi + fi + prev= + ;; + + *.lto.$objext) ;; # Ignore GCC LTO objects + *.$objext) + # This assumes that the test object file only shows up + # once in the compiler output. + if test "$p" = "conftest.$objext"; then + pre_test_object_deps_done=yes + continue + fi + + if test no = "$pre_test_object_deps_done"; then + if test -z "$_LT_TAGVAR(predep_objects, $1)"; then + _LT_TAGVAR(predep_objects, $1)=$p + else + _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" + fi + else + if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then + _LT_TAGVAR(postdep_objects, $1)=$p + else + _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" + fi + fi + ;; + + *) ;; # Ignore the rest. + + esac + done + + # Clean up. + rm -f a.out a.exe +else + echo "libtool.m4: error: problem compiling $1 test program" +fi + +$RM -f confest.$objext +CFLAGS=$_lt_libdeps_save_CFLAGS + +# PORTME: override above test on systems where it is broken +m4_if([$1], [CXX], +[case $host_os in +interix[[3-9]]*) + # Interix 3.5 installs completely hosed .la files for C++, so rather than + # hack all around it, let's just trust "g++" to DTRT. + _LT_TAGVAR(predep_objects,$1)= + _LT_TAGVAR(postdep_objects,$1)= + _LT_TAGVAR(postdeps,$1)= + ;; +esac +]) + +case " $_LT_TAGVAR(postdeps, $1) " in +*" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; +esac + _LT_TAGVAR(compiler_lib_search_dirs, $1)= +if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then + _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | $SED -e 's! -L! !g' -e 's!^ !!'` +fi +_LT_TAGDECL([], [compiler_lib_search_dirs], [1], + [The directories searched by this compiler when creating a shared library]) +_LT_TAGDECL([], [predep_objects], [1], + [Dependencies to place before and after the objects being linked to + create a shared library]) +_LT_TAGDECL([], [postdep_objects], [1]) +_LT_TAGDECL([], [predeps], [1]) +_LT_TAGDECL([], [postdeps], [1]) +_LT_TAGDECL([], [compiler_lib_search_path], [1], + [The library search path used internally by the compiler when linking + a shared library]) +])# _LT_SYS_HIDDEN_LIBDEPS + + +# _LT_LANG_F77_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for a Fortran 77 compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_F77_CONFIG], +[AC_LANG_PUSH(Fortran 77) +if test -z "$F77" || test no = "$F77"; then + _lt_disable_F77=yes +fi + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for f77 test sources. +ac_ext=f + +# Object file extension for compiled f77 test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the F77 compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_disable_F77"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_GCC=$GCC + lt_save_CFLAGS=$CFLAGS + CC=${F77-"f77"} + CFLAGS=$FFLAGS + compiler=$CC + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + GCC=$G77 + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)=$G77 + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS +fi # test yes != "$_lt_disable_F77" + +AC_LANG_POP +])# _LT_LANG_F77_CONFIG + + +# _LT_LANG_FC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for a Fortran compiler are +# suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_FC_CONFIG], +[AC_LANG_PUSH(Fortran) + +if test -z "$FC" || test no = "$FC"; then + _lt_disable_FC=yes +fi + +_LT_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_TAGVAR(allow_undefined_flag, $1)= +_LT_TAGVAR(always_export_symbols, $1)=no +_LT_TAGVAR(archive_expsym_cmds, $1)= +_LT_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_TAGVAR(hardcode_direct, $1)=no +_LT_TAGVAR(hardcode_direct_absolute, $1)=no +_LT_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_TAGVAR(hardcode_libdir_separator, $1)= +_LT_TAGVAR(hardcode_minus_L, $1)=no +_LT_TAGVAR(hardcode_automatic, $1)=no +_LT_TAGVAR(inherit_rpath, $1)=no +_LT_TAGVAR(module_cmds, $1)= +_LT_TAGVAR(module_expsym_cmds, $1)= +_LT_TAGVAR(link_all_deplibs, $1)=unknown +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds +_LT_TAGVAR(no_undefined_flag, $1)= +_LT_TAGVAR(whole_archive_flag_spec, $1)= +_LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Source file extension for fc test sources. +ac_ext=${ac_fc_srcext-f} + +# Object file extension for compiled fc test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# No sense in running all these tests if we already determined that +# the FC compiler isn't working. Some variables (like enable_shared) +# are currently assumed to apply to all compilers on this platform, +# and will be corrupted by setting them based on a non-working compiler. +if test yes != "$_lt_disable_FC"; then + # Code to be used in simple compile tests + lt_simple_compile_test_code="\ + subroutine t + return + end +" + + # Code to be used in simple link tests + lt_simple_link_test_code="\ + program t + end +" + + # ltmain only uses $CC for tagged configurations so make sure $CC is set. + _LT_TAG_COMPILER + + # save warnings/boilerplate of simple test code + _LT_COMPILER_BOILERPLATE + _LT_LINKER_BOILERPLATE + + # Allow CC to be a program name with arguments. + lt_save_CC=$CC + lt_save_GCC=$GCC + lt_save_CFLAGS=$CFLAGS + CC=${FC-"f95"} + CFLAGS=$FCFLAGS + compiler=$CC + GCC=$ac_cv_fc_compiler_gnu + + _LT_TAGVAR(compiler, $1)=$CC + _LT_CC_BASENAME([$compiler]) + + if test -n "$compiler"; then + AC_MSG_CHECKING([if libtool supports shared libraries]) + AC_MSG_RESULT([$can_build_shared]) + + AC_MSG_CHECKING([whether to build shared libraries]) + test no = "$can_build_shared" && enable_shared=no + + # On AIX, shared libraries and static libraries use the same namespace, and + # are all built from PIC. + case $host_os in + aix3*) + test yes = "$enable_shared" && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + aix[[4-9]]*) + if test ia64 != "$host_cpu"; then + case $enable_shared,$with_aix_soname,$aix_use_runtimelinking in + yes,aix,yes) ;; # shared object as lib.so file only + yes,svr4,*) ;; # shared object as lib.so archive member only + yes,*) enable_static=no ;; # shared object in lib.a archive as well + esac + fi + ;; + esac + AC_MSG_RESULT([$enable_shared]) + + AC_MSG_CHECKING([whether to build static libraries]) + # Make sure either enable_shared or enable_static is yes. + test yes = "$enable_shared" || enable_static=yes + AC_MSG_RESULT([$enable_static]) + + _LT_TAGVAR(GCC, $1)=$ac_cv_fc_compiler_gnu + _LT_TAGVAR(LD, $1)=$LD + + ## CAVEAT EMPTOR: + ## There is no encapsulation within the following macros, do not change + ## the running order or otherwise move them around unless you know exactly + ## what you are doing... + _LT_SYS_HIDDEN_LIBDEPS($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_SYS_DYNAMIC_LINKER($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) + fi # test -n "$compiler" + + GCC=$lt_save_GCC + CC=$lt_save_CC + CFLAGS=$lt_save_CFLAGS +fi # test yes != "$_lt_disable_FC" + +AC_LANG_POP +])# _LT_LANG_FC_CONFIG + + +# _LT_LANG_GCJ_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Java Compiler compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_GCJ_CONFIG], +[AC_REQUIRE([LT_PROG_GCJ])dnl +AC_LANG_SAVE + +# Source file extension for Java test sources. +ac_ext=java + +# Object file extension for compiled Java test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="class foo {}" + +# Code to be used in simple link tests +lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC=yes +CC=${GCJ-"gcj"} +CFLAGS=$GCJFLAGS +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)=$LD +_LT_CC_BASENAME([$compiler]) + +# GCJ did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_GCJ_CONFIG + + +# _LT_LANG_GO_CONFIG([TAG]) +# -------------------------- +# Ensure that the configuration variables for the GNU Go compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_GO_CONFIG], +[AC_REQUIRE([LT_PROG_GO])dnl +AC_LANG_SAVE + +# Source file extension for Go test sources. +ac_ext=go + +# Object file extension for compiled Go test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="package main; func main() { }" + +# Code to be used in simple link tests +lt_simple_link_test_code='package main; func main() { }' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC=yes +CC=${GOC-"gccgo"} +CFLAGS=$GOFLAGS +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_TAGVAR(LD, $1)=$LD +_LT_CC_BASENAME([$compiler]) + +# Go did not exist at the time GCC didn't implicitly link libc in. +_LT_TAGVAR(archive_cmds_need_lc, $1)=no + +_LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_TAGVAR(reload_flag, $1)=$reload_flag +_LT_TAGVAR(reload_cmds, $1)=$reload_cmds + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +if test -n "$compiler"; then + _LT_COMPILER_NO_RTTI($1) + _LT_COMPILER_PIC($1) + _LT_COMPILER_C_O($1) + _LT_COMPILER_FILE_LOCKS($1) + _LT_LINKER_SHLIBS($1) + _LT_LINKER_HARDCODE_LIBPATH($1) + + _LT_CONFIG($1) +fi + +AC_LANG_RESTORE + +GCC=$lt_save_GCC +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_GO_CONFIG + + +# _LT_LANG_RC_CONFIG([TAG]) +# ------------------------- +# Ensure that the configuration variables for the Windows resource compiler +# are suitably defined. These variables are subsequently used by _LT_CONFIG +# to write the compiler configuration to 'libtool'. +m4_defun([_LT_LANG_RC_CONFIG], +[AC_REQUIRE([LT_PROG_RC])dnl +AC_LANG_SAVE + +# Source file extension for RC test sources. +ac_ext=rc + +# Object file extension for compiled RC test sources. +objext=o +_LT_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' + +# Code to be used in simple link tests +lt_simple_link_test_code=$lt_simple_compile_test_code + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_TAG_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_CFLAGS=$CFLAGS +lt_save_GCC=$GCC +GCC= +CC=${RC-"windres"} +CFLAGS= +compiler=$CC +_LT_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) +_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + +if test -n "$compiler"; then + : + _LT_CONFIG($1) +fi + +GCC=$lt_save_GCC +AC_LANG_RESTORE +CC=$lt_save_CC +CFLAGS=$lt_save_CFLAGS +])# _LT_LANG_RC_CONFIG + + +# LT_PROG_GCJ +# ----------- +AC_DEFUN([LT_PROG_GCJ], +[m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], + [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], + [AC_CHECK_TOOL(GCJ, gcj,) + test set = "${GCJFLAGS+set}" || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS)])])[]dnl +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_GCJ], []) + + +# LT_PROG_GO +# ---------- +AC_DEFUN([LT_PROG_GO], +[AC_CHECK_TOOL(GOC, gccgo,) +]) + + +# LT_PROG_RC +# ---------- +AC_DEFUN([LT_PROG_RC], +[AC_CHECK_TOOL(RC, windres,) +]) + +# Old name: +AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_RC], []) + + +# _LT_DECL_EGREP +# -------------- +# If we don't have a new enough Autoconf to choose the best grep +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_EGREP], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_REQUIRE([AC_PROG_FGREP])dnl +test -z "$GREP" && GREP=grep +_LT_DECL([], [GREP], [1], [A grep program that handles long lines]) +_LT_DECL([], [EGREP], [1], [An ERE matcher]) +_LT_DECL([], [FGREP], [1], [A literal string matcher]) +dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too +AC_SUBST([GREP]) +]) + + +# _LT_DECL_OBJDUMP +# -------------- +# If we don't have a new enough Autoconf to choose the best objdump +# available, choose the one first in the user's PATH. +m4_defun([_LT_DECL_OBJDUMP], +[AC_CHECK_TOOL(OBJDUMP, objdump, false) +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) +AC_SUBST([OBJDUMP]) +]) + +# _LT_DECL_DLLTOOL +# ---------------- +# Ensure DLLTOOL variable is set. +m4_defun([_LT_DECL_DLLTOOL], +[AC_CHECK_TOOL(DLLTOOL, dlltool, false) +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [1], [DLL creation program]) +AC_SUBST([DLLTOOL]) +]) + +# _LT_DECL_SED +# ------------ +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +m4_defun([_LT_DECL_SED], +[AC_PROG_SED +test -z "$SED" && SED=sed +Xsed="$SED -e 1s/^X//" +_LT_DECL([], [SED], [1], [A sed program that does not truncate output]) +_LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], + [Sed that helps us avoid accidentally triggering echo(1) options like -n]) +])# _LT_DECL_SED + +m4_ifndef([AC_PROG_SED], [ +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ + +m4_defun([AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +IFS=$as_save_IFS +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f "$lt_ac_sed" && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test 10 -lt "$lt_ac_count" && break + lt_ac_count=`expr $lt_ac_count + 1` + if test "$lt_ac_count" -gt "$lt_ac_max"; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_SUBST([SED]) +AC_MSG_RESULT([$SED]) +])#AC_PROG_SED +])#m4_ifndef + +# Old name: +AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([LT_AC_PROG_SED], []) + + +# _LT_CHECK_SHELL_FEATURES +# ------------------------ +# Find out whether the shell is Bourne or XSI compatible, +# or has some other useful features. +m4_defun([_LT_CHECK_SHELL_FEATURES], +[if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + lt_unset=unset +else + lt_unset=false +fi +_LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl + +# test EBCDIC or ASCII +case `echo X|tr X '\101'` in + A) # ASCII based system + # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr + lt_SP2NL='tr \040 \012' + lt_NL2SP='tr \015\012 \040\040' + ;; + *) # EBCDIC based system + lt_SP2NL='tr \100 \n' + lt_NL2SP='tr \r\n \100\100' + ;; +esac +_LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl +_LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl +])# _LT_CHECK_SHELL_FEATURES + + +# _LT_PATH_CONVERSION_FUNCTIONS +# ----------------------------- +# Determine what file name conversion functions should be used by +# func_to_host_file (and, implicitly, by func_to_host_path). These are needed +# for certain cross-compile configurations and native mingw. +m4_defun([_LT_PATH_CONVERSION_FUNCTIONS], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +AC_MSG_CHECKING([how to convert $build file names to $host format]) +AC_CACHE_VAL(lt_cv_to_host_file_cmd, +[case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 + ;; + esac + ;; + *-*-cygwin* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin + ;; + *-*-cygwin* ) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; + * ) # otherwise, assume *nix + lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin + ;; + esac + ;; + * ) # unhandled hosts (and "normal" native builds) + lt_cv_to_host_file_cmd=func_convert_file_noop + ;; +esac +]) +to_host_file_cmd=$lt_cv_to_host_file_cmd +AC_MSG_RESULT([$lt_cv_to_host_file_cmd]) +_LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd], + [0], [convert $build file names to $host format])dnl + +AC_MSG_CHECKING([how to convert $build file names to toolchain format]) +AC_CACHE_VAL(lt_cv_to_tool_file_cmd, +[#assume ordinary cross tools, or native build. +lt_cv_to_tool_file_cmd=func_convert_file_noop +case $host in + *-*-mingw* ) + case $build in + *-*-mingw* ) # actually msys + lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 + ;; + esac + ;; +esac +]) +to_tool_file_cmd=$lt_cv_to_tool_file_cmd +AC_MSG_RESULT([$lt_cv_to_tool_file_cmd]) +_LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd], + [0], [convert $build files to toolchain format])dnl +])# _LT_PATH_CONVERSION_FUNCTIONS diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/lt~obsolete.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/lt~obsolete.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/lt~obsolete.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/lt~obsolete.m4 2016-12-22 14:07:29.000000000 +0000 @@ -0,0 +1,99 @@ +# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- +# +# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software +# Foundation, Inc. +# Written by Scott James Remnant, 2004. +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 5 lt~obsolete.m4 + +# These exist entirely to fool aclocal when bootstrapping libtool. +# +# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN), +# which have later been changed to m4_define as they aren't part of the +# exported API, or moved to Autoconf or Automake where they belong. +# +# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN +# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us +# using a macro with the same name in our local m4/libtool.m4 it'll +# pull the old libtool.m4 in (it doesn't see our shiny new m4_define +# and doesn't know about Autoconf macros at all.) +# +# So we provide this file, which has a silly filename so it's always +# included after everything else. This provides aclocal with the +# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything +# because those macros already exist, or will be overwritten later. +# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. +# +# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. +# Yes, that means every name once taken will need to remain here until +# we give up compatibility with versions before 1.7, at which point +# we need to keep only those names which we still refer to. + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) + +m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) +m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) +m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) +m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) +m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) +m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) +m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) +m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) +m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) +m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) +m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) +m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) +m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) +m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) +m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) +m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) +m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) +m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) +m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) +m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) +m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) +m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) +m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) +m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) +m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) +m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) +m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) +m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) +m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) +m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) +m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) +m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) +m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) +m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) +m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) +m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) +m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) +m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) +m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) +m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) +m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) +m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) +m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) +m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) +m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) +m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) +m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) +m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) +m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) +m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) +m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) +m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) +m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) +m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/ltoptions.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/ltoptions.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/ltoptions.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/ltoptions.m4 2016-12-22 14:07:29.000000000 +0000 @@ -0,0 +1,437 @@ +# Helper functions for option handling. -*- Autoconf -*- +# +# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software +# Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 8 ltoptions.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) + + +# _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) +# ------------------------------------------ +m4_define([_LT_MANGLE_OPTION], +[[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) + + +# _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) +# --------------------------------------- +# Set option OPTION-NAME for macro MACRO-NAME, and if there is a +# matching handler defined, dispatch to it. Other OPTION-NAMEs are +# saved as a flag. +m4_define([_LT_SET_OPTION], +[m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl +m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), + _LT_MANGLE_DEFUN([$1], [$2]), + [m4_warning([Unknown $1 option '$2'])])[]dnl +]) + + +# _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) +# ------------------------------------------------------------ +# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. +m4_define([_LT_IF_OPTION], +[m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) + + +# _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) +# ------------------------------------------------------- +# Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME +# are set. +m4_define([_LT_UNLESS_OPTIONS], +[m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), + [m4_define([$0_found])])])[]dnl +m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 +])[]dnl +]) + + +# _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) +# ---------------------------------------- +# OPTION-LIST is a space-separated list of Libtool options associated +# with MACRO-NAME. If any OPTION has a matching handler declared with +# LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about +# the unknown option and exit. +m4_defun([_LT_SET_OPTIONS], +[# Set options +m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), + [_LT_SET_OPTION([$1], _LT_Option)]) + +m4_if([$1],[LT_INIT],[ + dnl + dnl Simply set some default values (i.e off) if boolean options were not + dnl specified: + _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no + ]) + _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no + ]) + dnl + dnl If no reference was made to various pairs of opposing options, then + dnl we run the default mode handler for the pair. For example, if neither + dnl 'shared' nor 'disable-shared' was passed, we enable building of shared + dnl archives by default: + _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) + _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) + _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], + [_LT_ENABLE_FAST_INSTALL]) + _LT_UNLESS_OPTIONS([LT_INIT], [aix-soname=aix aix-soname=both aix-soname=svr4], + [_LT_WITH_AIX_SONAME([aix])]) + ]) +])# _LT_SET_OPTIONS + + +## --------------------------------- ## +## Macros to handle LT_INIT options. ## +## --------------------------------- ## + +# _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) +# ----------------------------------------- +m4_define([_LT_MANGLE_DEFUN], +[[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) + + +# LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) +# ----------------------------------------------- +m4_define([LT_OPTION_DEFINE], +[m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl +])# LT_OPTION_DEFINE + + +# dlopen +# ------ +LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes +]) + +AU_DEFUN([AC_LIBTOOL_DLOPEN], +[_LT_SET_OPTION([LT_INIT], [dlopen]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'dlopen' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) + + +# win32-dll +# --------- +# Declare package support for building win32 dll's. +LT_OPTION_DEFINE([LT_INIT], [win32-dll], +[enable_win32_dll=yes + +case $host in +*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) + AC_CHECK_TOOL(AS, as, false) + AC_CHECK_TOOL(DLLTOOL, dlltool, false) + AC_CHECK_TOOL(OBJDUMP, objdump, false) + ;; +esac + +test -z "$AS" && AS=as +_LT_DECL([], [AS], [1], [Assembler program])dnl + +test -z "$DLLTOOL" && DLLTOOL=dlltool +_LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl + +test -z "$OBJDUMP" && OBJDUMP=objdump +_LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl +])# win32-dll + +AU_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +_LT_SET_OPTION([LT_INIT], [win32-dll]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'win32-dll' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) + + +# _LT_ENABLE_SHARED([DEFAULT]) +# ---------------------------- +# implement the --enable-shared flag, and supports the 'shared' and +# 'disable-shared' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_SHARED], +[m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([shared], + [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) + + _LT_DECL([build_libtool_libs], [enable_shared], [0], + [Whether or not to build shared libraries]) +])# _LT_ENABLE_SHARED + +LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) +]) + +AC_DEFUN([AC_DISABLE_SHARED], +[_LT_SET_OPTION([LT_INIT], [disable-shared]) +]) + +AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_SHARED], []) +dnl AC_DEFUN([AM_DISABLE_SHARED], []) + + + +# _LT_ENABLE_STATIC([DEFAULT]) +# ---------------------------- +# implement the --enable-static flag, and support the 'static' and +# 'disable-static' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_STATIC], +[m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([static], + [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_static=]_LT_ENABLE_STATIC_DEFAULT) + + _LT_DECL([build_old_libs], [enable_static], [0], + [Whether or not to build static libraries]) +])# _LT_ENABLE_STATIC + +LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) + +# Old names: +AC_DEFUN([AC_ENABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) +]) + +AC_DEFUN([AC_DISABLE_STATIC], +[_LT_SET_OPTION([LT_INIT], [disable-static]) +]) + +AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AM_ENABLE_STATIC], []) +dnl AC_DEFUN([AM_DISABLE_STATIC], []) + + + +# _LT_ENABLE_FAST_INSTALL([DEFAULT]) +# ---------------------------------- +# implement the --enable-fast-install flag, and support the 'fast-install' +# and 'disable-fast-install' LT_INIT options. +# DEFAULT is either 'yes' or 'no'. If omitted, it defaults to 'yes'. +m4_define([_LT_ENABLE_FAST_INSTALL], +[m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl +AC_ARG_ENABLE([fast-install], + [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) + +_LT_DECL([fast_install], [enable_fast_install], [0], + [Whether or not to optimize for fast installation])dnl +])# _LT_ENABLE_FAST_INSTALL + +LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) +LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) + +# Old names: +AU_DEFUN([AC_ENABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'fast-install' option into LT_INIT's first parameter.]) +]) + +AU_DEFUN([AC_DISABLE_FAST_INSTALL], +[_LT_SET_OPTION([LT_INIT], [disable-fast-install]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you put +the 'disable-fast-install' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) +dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) + + +# _LT_WITH_AIX_SONAME([DEFAULT]) +# ---------------------------------- +# implement the --with-aix-soname flag, and support the `aix-soname=aix' +# and `aix-soname=both' and `aix-soname=svr4' LT_INIT options. DEFAULT +# is either `aix', `both' or `svr4'. If omitted, it defaults to `aix'. +m4_define([_LT_WITH_AIX_SONAME], +[m4_define([_LT_WITH_AIX_SONAME_DEFAULT], [m4_if($1, svr4, svr4, m4_if($1, both, both, aix))])dnl +shared_archive_member_spec= +case $host,$enable_shared in +power*-*-aix[[5-9]]*,yes) + AC_MSG_CHECKING([which variant of shared library versioning to provide]) + AC_ARG_WITH([aix-soname], + [AS_HELP_STRING([--with-aix-soname=aix|svr4|both], + [shared library versioning (aka "SONAME") variant to provide on AIX, @<:@default=]_LT_WITH_AIX_SONAME_DEFAULT[@:>@.])], + [case $withval in + aix|svr4|both) + ;; + *) + AC_MSG_ERROR([Unknown argument to --with-aix-soname]) + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname], + [AC_CACHE_VAL([lt_cv_with_aix_soname], + [lt_cv_with_aix_soname=]_LT_WITH_AIX_SONAME_DEFAULT) + with_aix_soname=$lt_cv_with_aix_soname]) + AC_MSG_RESULT([$with_aix_soname]) + if test aix != "$with_aix_soname"; then + # For the AIX way of multilib, we name the shared archive member + # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', + # and 'shr.imp' or 'shr_64.imp', respectively, for the Import File. + # Even when GNU compilers ignore OBJECT_MODE but need '-maix64' flag, + # the AIX toolchain works better with OBJECT_MODE set (default 32). + if test 64 = "${OBJECT_MODE-32}"; then + shared_archive_member_spec=shr_64 + else + shared_archive_member_spec=shr + fi + fi + ;; +*) + with_aix_soname=aix + ;; +esac + +_LT_DECL([], [shared_archive_member_spec], [0], + [Shared archive member basename, for filename based shared library versioning on AIX])dnl +])# _LT_WITH_AIX_SONAME + +LT_OPTION_DEFINE([LT_INIT], [aix-soname=aix], [_LT_WITH_AIX_SONAME([aix])]) +LT_OPTION_DEFINE([LT_INIT], [aix-soname=both], [_LT_WITH_AIX_SONAME([both])]) +LT_OPTION_DEFINE([LT_INIT], [aix-soname=svr4], [_LT_WITH_AIX_SONAME([svr4])]) + + +# _LT_WITH_PIC([MODE]) +# -------------------- +# implement the --with-pic flag, and support the 'pic-only' and 'no-pic' +# LT_INIT options. +# MODE is either 'yes' or 'no'. If omitted, it defaults to 'both'. +m4_define([_LT_WITH_PIC], +[AC_ARG_WITH([pic], + [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [pic_mode=m4_default([$1], [default])]) + +_LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl +])# _LT_WITH_PIC + +LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) +LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) + +# Old name: +AU_DEFUN([AC_LIBTOOL_PICMODE], +[_LT_SET_OPTION([LT_INIT], [pic-only]) +AC_DIAGNOSE([obsolete], +[$0: Remove this warning and the call to _LT_SET_OPTION when you +put the 'pic-only' option into LT_INIT's first parameter.]) +]) + +dnl aclocal-1.4 backwards compatibility: +dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) + +## ----------------- ## +## LTDL_INIT Options ## +## ----------------- ## + +m4_define([_LTDL_MODE], []) +LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], + [m4_define([_LTDL_MODE], [nonrecursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [recursive], + [m4_define([_LTDL_MODE], [recursive])]) +LT_OPTION_DEFINE([LTDL_INIT], [subproject], + [m4_define([_LTDL_MODE], [subproject])]) + +m4_define([_LTDL_TYPE], []) +LT_OPTION_DEFINE([LTDL_INIT], [installable], + [m4_define([_LTDL_TYPE], [installable])]) +LT_OPTION_DEFINE([LTDL_INIT], [convenience], + [m4_define([_LTDL_TYPE], [convenience])]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/ltsugar.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/ltsugar.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/ltsugar.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/ltsugar.m4 2016-12-22 14:07:29.000000000 +0000 @@ -0,0 +1,124 @@ +# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- +# +# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software +# Foundation, Inc. +# Written by Gary V. Vaughan, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# serial 6 ltsugar.m4 + +# This is to help aclocal find these macros, as it can't see m4_define. +AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) + + +# lt_join(SEP, ARG1, [ARG2...]) +# ----------------------------- +# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their +# associated separator. +# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier +# versions in m4sugar had bugs. +m4_define([lt_join], +[m4_if([$#], [1], [], + [$#], [2], [[$2]], + [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) +m4_define([_lt_join], +[m4_if([$#$2], [2], [], + [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) + + +# lt_car(LIST) +# lt_cdr(LIST) +# ------------ +# Manipulate m4 lists. +# These macros are necessary as long as will still need to support +# Autoconf-2.59, which quotes differently. +m4_define([lt_car], [[$1]]) +m4_define([lt_cdr], +[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], + [$#], 1, [], + [m4_dquote(m4_shift($@))])]) +m4_define([lt_unquote], $1) + + +# lt_append(MACRO-NAME, STRING, [SEPARATOR]) +# ------------------------------------------ +# Redefine MACRO-NAME to hold its former content plus 'SEPARATOR''STRING'. +# Note that neither SEPARATOR nor STRING are expanded; they are appended +# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). +# No SEPARATOR is output if MACRO-NAME was previously undefined (different +# than defined and empty). +# +# This macro is needed until we can rely on Autoconf 2.62, since earlier +# versions of m4sugar mistakenly expanded SEPARATOR but not STRING. +m4_define([lt_append], +[m4_define([$1], + m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) + + + +# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) +# ---------------------------------------------------------- +# Produce a SEP delimited list of all paired combinations of elements of +# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list +# has the form PREFIXmINFIXSUFFIXn. +# Needed until we can rely on m4_combine added in Autoconf 2.62. +m4_define([lt_combine], +[m4_if(m4_eval([$# > 3]), [1], + [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl +[[m4_foreach([_Lt_prefix], [$2], + [m4_foreach([_Lt_suffix], + ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, + [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) + + +# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) +# ----------------------------------------------------------------------- +# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited +# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. +m4_define([lt_if_append_uniq], +[m4_ifdef([$1], + [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], + [lt_append([$1], [$2], [$3])$4], + [$5])], + [lt_append([$1], [$2], [$3])$4])]) + + +# lt_dict_add(DICT, KEY, VALUE) +# ----------------------------- +m4_define([lt_dict_add], +[m4_define([$1($2)], [$3])]) + + +# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) +# -------------------------------------------- +m4_define([lt_dict_add_subkey], +[m4_define([$1($2:$3)], [$4])]) + + +# lt_dict_fetch(DICT, KEY, [SUBKEY]) +# ---------------------------------- +m4_define([lt_dict_fetch], +[m4_ifval([$3], + m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), + m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) + + +# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) +# ----------------------------------------------------------------- +m4_define([lt_if_dict_fetch], +[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], + [$5], + [$6])]) + + +# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) +# -------------------------------------------------------------- +m4_define([lt_dict_filter], +[m4_if([$5], [], [], + [lt_join(m4_quote(m4_default([$4], [[, ]])), + lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), + [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/ltversion.m4 cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/ltversion.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/m4macros/ltversion.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/m4macros/ltversion.m4 2016-12-22 14:07:29.000000000 +0000 @@ -0,0 +1,23 @@ +# ltversion.m4 -- version numbers -*- Autoconf -*- +# +# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. +# Written by Scott James Remnant, 2004 +# +# This file is free software; the Free Software Foundation gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. + +# @configure_input@ + +# serial 4179 ltversion.m4 +# This file is part of GNU Libtool + +m4_define([LT_PACKAGE_VERSION], [2.4.6]) +m4_define([LT_PACKAGE_REVISION], [2.4.6]) + +AC_DEFUN([LTVERSION_VERSION], +[macro_version='2.4.6' +macro_revision='2.4.6' +_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) +_LT_DECL(, macro_revision, 0) +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/hdrl/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/Makefile.am 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/Makefile.am 2017-09-06 12:50:09.000000000 +0000 @@ -0,0 +1,133 @@ +## Process this file with automake to produce Makefile.in + +## This file is part of the HDRL Pipeline +## Copyright (C) 2012,2013 European Southern Observatory + +## This library 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 + +AUTOMAKE_OPTIONS = 1.8 foreign + +DISTCLEANFILES = *~ + +SUBDIRS = catalogue . catalogue/tests tests + +EXTRA_DIST = m4macros/eso.m4 m4macros/cpl-pipeline.m4 + +if MAINTAINER_MODE + +MAINTAINERCLEANFILES = Makefile.in + +endif + +ACLOCAL_AMFLAGS = -I m4macros + +AM_CPPFLAGS = -DCX_LOG_DOMAIN=\"HdrlLib\" -DHDRL_USE_PRIVATE $(CPL_INCLUDES) $(GSL_INCLUDES) + +hdrlHEADERS = hdrl_overscan.h \ + hdrl_sigclip.h \ + hdrl_utils.h \ + hdrl_combine.h \ + hdrl_bpm_2d.h \ + hdrl_bpm_3d.h \ + hdrl_bpm_fit.h \ + hdrl_bpm_utils.h \ + hdrl_iter.h \ + hdrl_frameiter.h \ + hdrl_multiiter.h \ + hdrl_collapse.h \ + hdrl_elemop.h \ + hdrl_flat.h \ + hdrl_prototyping.h \ + hdrl_image.h \ + hdrl_image_math.h \ + hdrl_imagelist.h \ + hdrl_imagelist_io.h \ + hdrl_imagelist_basic.h \ + hdrl_imagelist_view.h \ + hdrl_parameter.h \ + hdrl_parameter_defs.h \ + hdrl_strehl.h \ + hdrl_types.h \ + hdrl_test.h \ + hdrl_buffer.h \ + hdrl_overscan_defs.h \ + hdrl_image_defs.h \ + hdrl_imagelist_defs.h \ + hdrl_spectrum_defs.h \ + hdrl_lacosmics.h \ + hdrl_fit.h \ + hdrl_fringe.h \ + hdrl_catalogue.h \ + hdrl_random.h \ + hdrl_spectrum.h \ + hdrl_spectrumlist.h \ + hdrl_spectrum_resample.h \ + hdrl_spectrum_shift.h \ + hdrl_DER_SNR.h \ + hdrl_correlation.h \ + hdrl_efficiency.h \ + hdrl_response.h \ + hdrl_dar.h \ + hdrl.h + +libhdrl_la_SOURCES = hdrl_overscan.c \ + hdrl_sigclip.c \ + hdrl_utils.c \ + hdrl_combine.c \ + hdrl_bpm_2d.c \ + hdrl_bpm_3d.c \ + hdrl_bpm_fit.c \ + hdrl_bpm_utils.c \ + hdrl_iter.c \ + hdrl_frameiter.c \ + hdrl_multiiter.c \ + hdrl_collapse.c \ + hdrl_elemop.c \ + hdrl_flat.c \ + hdrl_fit.c \ + hdrl_strehl.c \ + hdrl_prototyping.c \ + hdrl_image.c \ + hdrl_image_math.c \ + hdrl_imagelist_io.c \ + hdrl_imagelist_basic.c \ + hdrl_imagelist_view.c \ + hdrl_parameter.c \ + hdrl_lacosmics.c \ + hdrl_buffer.c \ + hdrl_fringe.c \ + hdrl_catalogue.c \ + hdrl_random.c \ + hdrl_spectrum.c \ + hdrl_spectrumlist.c \ + hdrl_spectrum_resample.c \ + hdrl_spectrum_shift.c \ + hdrl_DER_SNR.c \ + hdrl_correlation.c \ + hdrl_response.c \ + hdrl_efficiency.c \ + hdrl_dar.c \ + igam.c + +libhdrl_la_CFLAGS = $(AM_CFLAGS) +libhdrl_la_LDFLAGS = $(CPL_LDFLAGS) $(GSL_LDFLAGS) -static +libhdrl_la_LIBADD = $(LIBCPLDFS) $(LIBCPLUI) $(LIBCPLDRS) $(LIBCPLCORE) $(GSL_LIBS) catalogue/libcatalogue.la + +if VLTSW +lib_LTLIBRARIES = libhdrl.la +pkginclude_HEADERS = $(hdrlHEADERS) +else +noinst_LTLIBRARIES = libhdrl.la +noinst_HEADERS = $(hdrlHEADERS) +endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/hdrl/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/Makefile.in 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/Makefile.in 2018-04-13 15:46:32.000000000 +0000 @@ -0,0 +1,1486 @@ +# Makefile.in generated by automake 1.15 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2014 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = . +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/m4macros/cpl-pipeline.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ + $(am__configure_deps) $(am__noinst_HEADERS_DIST) \ + $(am__pkginclude_HEADERS_DIST) $(am__DIST_COMMON) +am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ + configure.lineno config.status.lineno +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgincludedir)" +LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) +am__DEPENDENCIES_1 = +libhdrl_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) catalogue/libcatalogue.la +am_libhdrl_la_OBJECTS = libhdrl_la-hdrl_overscan.lo \ + libhdrl_la-hdrl_sigclip.lo libhdrl_la-hdrl_utils.lo \ + libhdrl_la-hdrl_combine.lo libhdrl_la-hdrl_bpm_2d.lo \ + libhdrl_la-hdrl_bpm_3d.lo libhdrl_la-hdrl_bpm_fit.lo \ + libhdrl_la-hdrl_bpm_utils.lo libhdrl_la-hdrl_iter.lo \ + libhdrl_la-hdrl_frameiter.lo libhdrl_la-hdrl_multiiter.lo \ + libhdrl_la-hdrl_collapse.lo libhdrl_la-hdrl_elemop.lo \ + libhdrl_la-hdrl_flat.lo libhdrl_la-hdrl_fit.lo \ + libhdrl_la-hdrl_strehl.lo libhdrl_la-hdrl_prototyping.lo \ + libhdrl_la-hdrl_image.lo libhdrl_la-hdrl_image_math.lo \ + libhdrl_la-hdrl_imagelist_io.lo \ + libhdrl_la-hdrl_imagelist_basic.lo \ + libhdrl_la-hdrl_imagelist_view.lo libhdrl_la-hdrl_parameter.lo \ + libhdrl_la-hdrl_lacosmics.lo libhdrl_la-hdrl_buffer.lo \ + libhdrl_la-hdrl_fringe.lo libhdrl_la-hdrl_catalogue.lo \ + libhdrl_la-hdrl_random.lo libhdrl_la-hdrl_spectrum.lo \ + libhdrl_la-hdrl_spectrumlist.lo \ + libhdrl_la-hdrl_spectrum_resample.lo \ + libhdrl_la-hdrl_spectrum_shift.lo libhdrl_la-hdrl_DER_SNR.lo \ + libhdrl_la-hdrl_correlation.lo libhdrl_la-hdrl_response.lo \ + libhdrl_la-hdrl_efficiency.lo libhdrl_la-hdrl_dar.lo \ + libhdrl_la-igam.lo +libhdrl_la_OBJECTS = $(am_libhdrl_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +libhdrl_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libhdrl_la_CFLAGS) \ + $(CFLAGS) $(libhdrl_la_LDFLAGS) $(LDFLAGS) -o $@ +@VLTSW_FALSE@am_libhdrl_la_rpath = +@VLTSW_TRUE@am_libhdrl_la_rpath = -rpath $(libdir) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/admin/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libhdrl_la_SOURCES) +DIST_SOURCES = $(libhdrl_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ + ctags-recursive dvi-recursive html-recursive info-recursive \ + install-data-recursive install-dvi-recursive \ + install-exec-recursive install-html-recursive \ + install-info-recursive install-pdf-recursive \ + install-ps-recursive install-recursive installcheck-recursive \ + installdirs-recursive pdf-recursive ps-recursive \ + tags-recursive uninstall-recursive +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__noinst_HEADERS_DIST = hdrl_overscan.h hdrl_sigclip.h hdrl_utils.h \ + hdrl_combine.h hdrl_bpm_2d.h hdrl_bpm_3d.h hdrl_bpm_fit.h \ + hdrl_bpm_utils.h hdrl_iter.h hdrl_frameiter.h hdrl_multiiter.h \ + hdrl_collapse.h hdrl_elemop.h hdrl_flat.h hdrl_prototyping.h \ + hdrl_image.h hdrl_image_math.h hdrl_imagelist.h \ + hdrl_imagelist_io.h hdrl_imagelist_basic.h \ + hdrl_imagelist_view.h hdrl_parameter.h hdrl_parameter_defs.h \ + hdrl_strehl.h hdrl_types.h hdrl_test.h hdrl_buffer.h \ + hdrl_overscan_defs.h hdrl_image_defs.h hdrl_imagelist_defs.h \ + hdrl_spectrum_defs.h hdrl_lacosmics.h hdrl_fit.h hdrl_fringe.h \ + hdrl_catalogue.h hdrl_random.h hdrl_spectrum.h \ + hdrl_spectrumlist.h hdrl_spectrum_resample.h \ + hdrl_spectrum_shift.h hdrl_DER_SNR.h hdrl_correlation.h \ + hdrl_efficiency.h hdrl_response.h hdrl_dar.h hdrl.h +am__pkginclude_HEADERS_DIST = hdrl_overscan.h hdrl_sigclip.h \ + hdrl_utils.h hdrl_combine.h hdrl_bpm_2d.h hdrl_bpm_3d.h \ + hdrl_bpm_fit.h hdrl_bpm_utils.h hdrl_iter.h hdrl_frameiter.h \ + hdrl_multiiter.h hdrl_collapse.h hdrl_elemop.h hdrl_flat.h \ + hdrl_prototyping.h hdrl_image.h hdrl_image_math.h \ + hdrl_imagelist.h hdrl_imagelist_io.h hdrl_imagelist_basic.h \ + hdrl_imagelist_view.h hdrl_parameter.h hdrl_parameter_defs.h \ + hdrl_strehl.h hdrl_types.h hdrl_test.h hdrl_buffer.h \ + hdrl_overscan_defs.h hdrl_image_defs.h hdrl_imagelist_defs.h \ + hdrl_spectrum_defs.h hdrl_lacosmics.h hdrl_fit.h hdrl_fringe.h \ + hdrl_catalogue.h hdrl_random.h hdrl_spectrum.h \ + hdrl_spectrumlist.h hdrl_spectrum_resample.h \ + hdrl_spectrum_shift.h hdrl_DER_SNR.h hdrl_correlation.h \ + hdrl_efficiency.h hdrl_response.h hdrl_dar.h hdrl.h +HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +am__recursive_targets = \ + $(RECURSIVE_TARGETS) \ + $(RECURSIVE_CLEAN_TARGETS) \ + $(am__extra_recursive_targets) +AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ + cscope distdir dist dist-all distcheck +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \ + $(LISP)config.h.in +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +CSCOPE = cscope +DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ + $(top_srcdir)/admin/compile $(top_srcdir)/admin/config.guess \ + $(top_srcdir)/admin/config.sub $(top_srcdir)/admin/depcomp \ + $(top_srcdir)/admin/install-sh $(top_srcdir)/admin/ltmain.sh \ + $(top_srcdir)/admin/missing admin/compile admin/config.guess \ + admin/config.sub admin/depcomp admin/install-sh \ + admin/ltmain.sh admin/missing +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +distdir = $(PACKAGE)-$(VERSION) +top_distdir = $(distdir) +am__remove_distdir = \ + if test -d "$(distdir)"; then \ + find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ + && rm -rf "$(distdir)" \ + || { sleep 5 && rm -rf "$(distdir)"; }; \ + else :; fi +am__post_remove_distdir = $(am__remove_distdir) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +DIST_ARCHIVES = $(distdir).tar.gz +GZIP_ENV = --best +DIST_TARGETS = dist-gzip +distuninstallcheck_listfiles = find . -type f -print +am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ + | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' +distcleancheck_listfiles = find . -type f -print +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPL_INCLUDES = @CPL_INCLUDES@ +CPL_LDFLAGS = @CPL_LDFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DOXYGEN = @DOXYGEN@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_BINARY_AGE = @HDRL_BINARY_AGE@ +HDRL_BINARY_VERSION = @HDRL_BINARY_VERSION@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERFACE_AGE = @HDRL_INTERFACE_AGE@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_MAJOR_VERSION = @HDRL_MAJOR_VERSION@ +HDRL_MICRO_VERSION = @HDRL_MICRO_VERSION@ +HDRL_MINOR_VERSION = @HDRL_MINOR_VERSION@ +HDRL_VERSION = @HDRL_VERSION@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LATEX = @LATEX@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBCEXT = @LIBCEXT@ +LIBCPLCORE = @LIBCPLCORE@ +LIBCPLDFS = @LIBCPLDFS@ +LIBCPLDRS = @LIBCPLDRS@ +LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_AGE = @LT_AGE@ +LT_CURRENT = @LT_CURRENT@ +LT_REVISION = @LT_REVISION@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +all_includes = @all_includes@ +all_ldflags = @all_ldflags@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AUTOMAKE_OPTIONS = 1.8 foreign +DISTCLEANFILES = *~ +SUBDIRS = catalogue . catalogue/tests tests +EXTRA_DIST = m4macros/eso.m4 m4macros/cpl-pipeline.m4 +@MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = Makefile.in +ACLOCAL_AMFLAGS = -I m4macros +AM_CPPFLAGS = -DCX_LOG_DOMAIN=\"HdrlLib\" -DHDRL_USE_PRIVATE $(CPL_INCLUDES) $(GSL_INCLUDES) +hdrlHEADERS = hdrl_overscan.h \ + hdrl_sigclip.h \ + hdrl_utils.h \ + hdrl_combine.h \ + hdrl_bpm_2d.h \ + hdrl_bpm_3d.h \ + hdrl_bpm_fit.h \ + hdrl_bpm_utils.h \ + hdrl_iter.h \ + hdrl_frameiter.h \ + hdrl_multiiter.h \ + hdrl_collapse.h \ + hdrl_elemop.h \ + hdrl_flat.h \ + hdrl_prototyping.h \ + hdrl_image.h \ + hdrl_image_math.h \ + hdrl_imagelist.h \ + hdrl_imagelist_io.h \ + hdrl_imagelist_basic.h \ + hdrl_imagelist_view.h \ + hdrl_parameter.h \ + hdrl_parameter_defs.h \ + hdrl_strehl.h \ + hdrl_types.h \ + hdrl_test.h \ + hdrl_buffer.h \ + hdrl_overscan_defs.h \ + hdrl_image_defs.h \ + hdrl_imagelist_defs.h \ + hdrl_spectrum_defs.h \ + hdrl_lacosmics.h \ + hdrl_fit.h \ + hdrl_fringe.h \ + hdrl_catalogue.h \ + hdrl_random.h \ + hdrl_spectrum.h \ + hdrl_spectrumlist.h \ + hdrl_spectrum_resample.h \ + hdrl_spectrum_shift.h \ + hdrl_DER_SNR.h \ + hdrl_correlation.h \ + hdrl_efficiency.h \ + hdrl_response.h \ + hdrl_dar.h \ + hdrl.h + +libhdrl_la_SOURCES = hdrl_overscan.c \ + hdrl_sigclip.c \ + hdrl_utils.c \ + hdrl_combine.c \ + hdrl_bpm_2d.c \ + hdrl_bpm_3d.c \ + hdrl_bpm_fit.c \ + hdrl_bpm_utils.c \ + hdrl_iter.c \ + hdrl_frameiter.c \ + hdrl_multiiter.c \ + hdrl_collapse.c \ + hdrl_elemop.c \ + hdrl_flat.c \ + hdrl_fit.c \ + hdrl_strehl.c \ + hdrl_prototyping.c \ + hdrl_image.c \ + hdrl_image_math.c \ + hdrl_imagelist_io.c \ + hdrl_imagelist_basic.c \ + hdrl_imagelist_view.c \ + hdrl_parameter.c \ + hdrl_lacosmics.c \ + hdrl_buffer.c \ + hdrl_fringe.c \ + hdrl_catalogue.c \ + hdrl_random.c \ + hdrl_spectrum.c \ + hdrl_spectrumlist.c \ + hdrl_spectrum_resample.c \ + hdrl_spectrum_shift.c \ + hdrl_DER_SNR.c \ + hdrl_correlation.c \ + hdrl_response.c \ + hdrl_efficiency.c \ + hdrl_dar.c \ + igam.c + +libhdrl_la_CFLAGS = $(AM_CFLAGS) +libhdrl_la_LDFLAGS = $(CPL_LDFLAGS) $(GSL_LDFLAGS) -static +libhdrl_la_LIBADD = $(LIBCPLDFS) $(LIBCPLUI) $(LIBCPLDRS) $(LIBCPLCORE) $(GSL_LIBS) catalogue/libcatalogue.la +@VLTSW_TRUE@lib_LTLIBRARIES = libhdrl.la +@VLTSW_TRUE@pkginclude_HEADERS = $(hdrlHEADERS) +@VLTSW_FALSE@noinst_LTLIBRARIES = libhdrl.la +@VLTSW_FALSE@noinst_HEADERS = $(hdrlHEADERS) +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-recursive + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +am--refresh: Makefile + @: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ + $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + echo ' $(SHELL) ./config.status'; \ + $(SHELL) ./config.status;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + $(SHELL) ./config.status --recheck + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + $(am__cd) $(srcdir) && $(AUTOCONF) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) +$(am__aclocal_m4_deps): + +config.h: stamp-h1 + @test -f $@ || rm -f stamp-h1 + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status config.h +$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +distclean-hdr: + -rm -f config.h stamp-h1 + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libhdrl.la: $(libhdrl_la_OBJECTS) $(libhdrl_la_DEPENDENCIES) $(EXTRA_libhdrl_la_DEPENDENCIES) + $(AM_V_CCLD)$(libhdrl_la_LINK) $(am_libhdrl_la_rpath) $(libhdrl_la_OBJECTS) $(libhdrl_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_DER_SNR.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_bpm_2d.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_bpm_3d.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_bpm_fit.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_bpm_utils.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_buffer.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_catalogue.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_collapse.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_combine.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_correlation.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_dar.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_efficiency.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_elemop.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_fit.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_flat.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_frameiter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_fringe.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_image.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_image_math.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_imagelist_basic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_imagelist_io.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_imagelist_view.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_iter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_lacosmics.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_multiiter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_overscan.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_parameter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_prototyping.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_random.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_response.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_sigclip.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_spectrum.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_spectrum_resample.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_spectrum_shift.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_spectrumlist.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_strehl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-hdrl_utils.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhdrl_la-igam.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +libhdrl_la-hdrl_overscan.lo: hdrl_overscan.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_overscan.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_overscan.Tpo -c -o libhdrl_la-hdrl_overscan.lo `test -f 'hdrl_overscan.c' || echo '$(srcdir)/'`hdrl_overscan.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_overscan.Tpo $(DEPDIR)/libhdrl_la-hdrl_overscan.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_overscan.c' object='libhdrl_la-hdrl_overscan.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_overscan.lo `test -f 'hdrl_overscan.c' || echo '$(srcdir)/'`hdrl_overscan.c + +libhdrl_la-hdrl_sigclip.lo: hdrl_sigclip.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_sigclip.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_sigclip.Tpo -c -o libhdrl_la-hdrl_sigclip.lo `test -f 'hdrl_sigclip.c' || echo '$(srcdir)/'`hdrl_sigclip.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_sigclip.Tpo $(DEPDIR)/libhdrl_la-hdrl_sigclip.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_sigclip.c' object='libhdrl_la-hdrl_sigclip.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_sigclip.lo `test -f 'hdrl_sigclip.c' || echo '$(srcdir)/'`hdrl_sigclip.c + +libhdrl_la-hdrl_utils.lo: hdrl_utils.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_utils.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_utils.Tpo -c -o libhdrl_la-hdrl_utils.lo `test -f 'hdrl_utils.c' || echo '$(srcdir)/'`hdrl_utils.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_utils.Tpo $(DEPDIR)/libhdrl_la-hdrl_utils.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_utils.c' object='libhdrl_la-hdrl_utils.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_utils.lo `test -f 'hdrl_utils.c' || echo '$(srcdir)/'`hdrl_utils.c + +libhdrl_la-hdrl_combine.lo: hdrl_combine.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_combine.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_combine.Tpo -c -o libhdrl_la-hdrl_combine.lo `test -f 'hdrl_combine.c' || echo '$(srcdir)/'`hdrl_combine.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_combine.Tpo $(DEPDIR)/libhdrl_la-hdrl_combine.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_combine.c' object='libhdrl_la-hdrl_combine.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_combine.lo `test -f 'hdrl_combine.c' || echo '$(srcdir)/'`hdrl_combine.c + +libhdrl_la-hdrl_bpm_2d.lo: hdrl_bpm_2d.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_bpm_2d.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_bpm_2d.Tpo -c -o libhdrl_la-hdrl_bpm_2d.lo `test -f 'hdrl_bpm_2d.c' || echo '$(srcdir)/'`hdrl_bpm_2d.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_bpm_2d.Tpo $(DEPDIR)/libhdrl_la-hdrl_bpm_2d.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_bpm_2d.c' object='libhdrl_la-hdrl_bpm_2d.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_bpm_2d.lo `test -f 'hdrl_bpm_2d.c' || echo '$(srcdir)/'`hdrl_bpm_2d.c + +libhdrl_la-hdrl_bpm_3d.lo: hdrl_bpm_3d.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_bpm_3d.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_bpm_3d.Tpo -c -o libhdrl_la-hdrl_bpm_3d.lo `test -f 'hdrl_bpm_3d.c' || echo '$(srcdir)/'`hdrl_bpm_3d.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_bpm_3d.Tpo $(DEPDIR)/libhdrl_la-hdrl_bpm_3d.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_bpm_3d.c' object='libhdrl_la-hdrl_bpm_3d.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_bpm_3d.lo `test -f 'hdrl_bpm_3d.c' || echo '$(srcdir)/'`hdrl_bpm_3d.c + +libhdrl_la-hdrl_bpm_fit.lo: hdrl_bpm_fit.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_bpm_fit.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_bpm_fit.Tpo -c -o libhdrl_la-hdrl_bpm_fit.lo `test -f 'hdrl_bpm_fit.c' || echo '$(srcdir)/'`hdrl_bpm_fit.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_bpm_fit.Tpo $(DEPDIR)/libhdrl_la-hdrl_bpm_fit.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_bpm_fit.c' object='libhdrl_la-hdrl_bpm_fit.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_bpm_fit.lo `test -f 'hdrl_bpm_fit.c' || echo '$(srcdir)/'`hdrl_bpm_fit.c + +libhdrl_la-hdrl_bpm_utils.lo: hdrl_bpm_utils.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_bpm_utils.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_bpm_utils.Tpo -c -o libhdrl_la-hdrl_bpm_utils.lo `test -f 'hdrl_bpm_utils.c' || echo '$(srcdir)/'`hdrl_bpm_utils.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_bpm_utils.Tpo $(DEPDIR)/libhdrl_la-hdrl_bpm_utils.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_bpm_utils.c' object='libhdrl_la-hdrl_bpm_utils.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_bpm_utils.lo `test -f 'hdrl_bpm_utils.c' || echo '$(srcdir)/'`hdrl_bpm_utils.c + +libhdrl_la-hdrl_iter.lo: hdrl_iter.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_iter.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_iter.Tpo -c -o libhdrl_la-hdrl_iter.lo `test -f 'hdrl_iter.c' || echo '$(srcdir)/'`hdrl_iter.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_iter.Tpo $(DEPDIR)/libhdrl_la-hdrl_iter.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_iter.c' object='libhdrl_la-hdrl_iter.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_iter.lo `test -f 'hdrl_iter.c' || echo '$(srcdir)/'`hdrl_iter.c + +libhdrl_la-hdrl_frameiter.lo: hdrl_frameiter.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_frameiter.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_frameiter.Tpo -c -o libhdrl_la-hdrl_frameiter.lo `test -f 'hdrl_frameiter.c' || echo '$(srcdir)/'`hdrl_frameiter.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_frameiter.Tpo $(DEPDIR)/libhdrl_la-hdrl_frameiter.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_frameiter.c' object='libhdrl_la-hdrl_frameiter.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_frameiter.lo `test -f 'hdrl_frameiter.c' || echo '$(srcdir)/'`hdrl_frameiter.c + +libhdrl_la-hdrl_multiiter.lo: hdrl_multiiter.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_multiiter.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_multiiter.Tpo -c -o libhdrl_la-hdrl_multiiter.lo `test -f 'hdrl_multiiter.c' || echo '$(srcdir)/'`hdrl_multiiter.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_multiiter.Tpo $(DEPDIR)/libhdrl_la-hdrl_multiiter.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_multiiter.c' object='libhdrl_la-hdrl_multiiter.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_multiiter.lo `test -f 'hdrl_multiiter.c' || echo '$(srcdir)/'`hdrl_multiiter.c + +libhdrl_la-hdrl_collapse.lo: hdrl_collapse.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_collapse.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_collapse.Tpo -c -o libhdrl_la-hdrl_collapse.lo `test -f 'hdrl_collapse.c' || echo '$(srcdir)/'`hdrl_collapse.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_collapse.Tpo $(DEPDIR)/libhdrl_la-hdrl_collapse.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_collapse.c' object='libhdrl_la-hdrl_collapse.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_collapse.lo `test -f 'hdrl_collapse.c' || echo '$(srcdir)/'`hdrl_collapse.c + +libhdrl_la-hdrl_elemop.lo: hdrl_elemop.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_elemop.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_elemop.Tpo -c -o libhdrl_la-hdrl_elemop.lo `test -f 'hdrl_elemop.c' || echo '$(srcdir)/'`hdrl_elemop.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_elemop.Tpo $(DEPDIR)/libhdrl_la-hdrl_elemop.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_elemop.c' object='libhdrl_la-hdrl_elemop.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_elemop.lo `test -f 'hdrl_elemop.c' || echo '$(srcdir)/'`hdrl_elemop.c + +libhdrl_la-hdrl_flat.lo: hdrl_flat.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_flat.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_flat.Tpo -c -o libhdrl_la-hdrl_flat.lo `test -f 'hdrl_flat.c' || echo '$(srcdir)/'`hdrl_flat.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_flat.Tpo $(DEPDIR)/libhdrl_la-hdrl_flat.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_flat.c' object='libhdrl_la-hdrl_flat.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_flat.lo `test -f 'hdrl_flat.c' || echo '$(srcdir)/'`hdrl_flat.c + +libhdrl_la-hdrl_fit.lo: hdrl_fit.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_fit.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_fit.Tpo -c -o libhdrl_la-hdrl_fit.lo `test -f 'hdrl_fit.c' || echo '$(srcdir)/'`hdrl_fit.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_fit.Tpo $(DEPDIR)/libhdrl_la-hdrl_fit.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_fit.c' object='libhdrl_la-hdrl_fit.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_fit.lo `test -f 'hdrl_fit.c' || echo '$(srcdir)/'`hdrl_fit.c + +libhdrl_la-hdrl_strehl.lo: hdrl_strehl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_strehl.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_strehl.Tpo -c -o libhdrl_la-hdrl_strehl.lo `test -f 'hdrl_strehl.c' || echo '$(srcdir)/'`hdrl_strehl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_strehl.Tpo $(DEPDIR)/libhdrl_la-hdrl_strehl.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_strehl.c' object='libhdrl_la-hdrl_strehl.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_strehl.lo `test -f 'hdrl_strehl.c' || echo '$(srcdir)/'`hdrl_strehl.c + +libhdrl_la-hdrl_prototyping.lo: hdrl_prototyping.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_prototyping.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_prototyping.Tpo -c -o libhdrl_la-hdrl_prototyping.lo `test -f 'hdrl_prototyping.c' || echo '$(srcdir)/'`hdrl_prototyping.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_prototyping.Tpo $(DEPDIR)/libhdrl_la-hdrl_prototyping.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_prototyping.c' object='libhdrl_la-hdrl_prototyping.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_prototyping.lo `test -f 'hdrl_prototyping.c' || echo '$(srcdir)/'`hdrl_prototyping.c + +libhdrl_la-hdrl_image.lo: hdrl_image.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_image.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_image.Tpo -c -o libhdrl_la-hdrl_image.lo `test -f 'hdrl_image.c' || echo '$(srcdir)/'`hdrl_image.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_image.Tpo $(DEPDIR)/libhdrl_la-hdrl_image.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_image.c' object='libhdrl_la-hdrl_image.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_image.lo `test -f 'hdrl_image.c' || echo '$(srcdir)/'`hdrl_image.c + +libhdrl_la-hdrl_image_math.lo: hdrl_image_math.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_image_math.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_image_math.Tpo -c -o libhdrl_la-hdrl_image_math.lo `test -f 'hdrl_image_math.c' || echo '$(srcdir)/'`hdrl_image_math.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_image_math.Tpo $(DEPDIR)/libhdrl_la-hdrl_image_math.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_image_math.c' object='libhdrl_la-hdrl_image_math.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_image_math.lo `test -f 'hdrl_image_math.c' || echo '$(srcdir)/'`hdrl_image_math.c + +libhdrl_la-hdrl_imagelist_io.lo: hdrl_imagelist_io.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_imagelist_io.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_imagelist_io.Tpo -c -o libhdrl_la-hdrl_imagelist_io.lo `test -f 'hdrl_imagelist_io.c' || echo '$(srcdir)/'`hdrl_imagelist_io.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_imagelist_io.Tpo $(DEPDIR)/libhdrl_la-hdrl_imagelist_io.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_imagelist_io.c' object='libhdrl_la-hdrl_imagelist_io.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_imagelist_io.lo `test -f 'hdrl_imagelist_io.c' || echo '$(srcdir)/'`hdrl_imagelist_io.c + +libhdrl_la-hdrl_imagelist_basic.lo: hdrl_imagelist_basic.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_imagelist_basic.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_imagelist_basic.Tpo -c -o libhdrl_la-hdrl_imagelist_basic.lo `test -f 'hdrl_imagelist_basic.c' || echo '$(srcdir)/'`hdrl_imagelist_basic.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_imagelist_basic.Tpo $(DEPDIR)/libhdrl_la-hdrl_imagelist_basic.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_imagelist_basic.c' object='libhdrl_la-hdrl_imagelist_basic.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_imagelist_basic.lo `test -f 'hdrl_imagelist_basic.c' || echo '$(srcdir)/'`hdrl_imagelist_basic.c + +libhdrl_la-hdrl_imagelist_view.lo: hdrl_imagelist_view.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_imagelist_view.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_imagelist_view.Tpo -c -o libhdrl_la-hdrl_imagelist_view.lo `test -f 'hdrl_imagelist_view.c' || echo '$(srcdir)/'`hdrl_imagelist_view.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_imagelist_view.Tpo $(DEPDIR)/libhdrl_la-hdrl_imagelist_view.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_imagelist_view.c' object='libhdrl_la-hdrl_imagelist_view.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_imagelist_view.lo `test -f 'hdrl_imagelist_view.c' || echo '$(srcdir)/'`hdrl_imagelist_view.c + +libhdrl_la-hdrl_parameter.lo: hdrl_parameter.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_parameter.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_parameter.Tpo -c -o libhdrl_la-hdrl_parameter.lo `test -f 'hdrl_parameter.c' || echo '$(srcdir)/'`hdrl_parameter.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_parameter.Tpo $(DEPDIR)/libhdrl_la-hdrl_parameter.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_parameter.c' object='libhdrl_la-hdrl_parameter.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_parameter.lo `test -f 'hdrl_parameter.c' || echo '$(srcdir)/'`hdrl_parameter.c + +libhdrl_la-hdrl_lacosmics.lo: hdrl_lacosmics.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_lacosmics.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_lacosmics.Tpo -c -o libhdrl_la-hdrl_lacosmics.lo `test -f 'hdrl_lacosmics.c' || echo '$(srcdir)/'`hdrl_lacosmics.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_lacosmics.Tpo $(DEPDIR)/libhdrl_la-hdrl_lacosmics.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_lacosmics.c' object='libhdrl_la-hdrl_lacosmics.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_lacosmics.lo `test -f 'hdrl_lacosmics.c' || echo '$(srcdir)/'`hdrl_lacosmics.c + +libhdrl_la-hdrl_buffer.lo: hdrl_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_buffer.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_buffer.Tpo -c -o libhdrl_la-hdrl_buffer.lo `test -f 'hdrl_buffer.c' || echo '$(srcdir)/'`hdrl_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_buffer.Tpo $(DEPDIR)/libhdrl_la-hdrl_buffer.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_buffer.c' object='libhdrl_la-hdrl_buffer.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_buffer.lo `test -f 'hdrl_buffer.c' || echo '$(srcdir)/'`hdrl_buffer.c + +libhdrl_la-hdrl_fringe.lo: hdrl_fringe.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_fringe.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_fringe.Tpo -c -o libhdrl_la-hdrl_fringe.lo `test -f 'hdrl_fringe.c' || echo '$(srcdir)/'`hdrl_fringe.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_fringe.Tpo $(DEPDIR)/libhdrl_la-hdrl_fringe.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_fringe.c' object='libhdrl_la-hdrl_fringe.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_fringe.lo `test -f 'hdrl_fringe.c' || echo '$(srcdir)/'`hdrl_fringe.c + +libhdrl_la-hdrl_catalogue.lo: hdrl_catalogue.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_catalogue.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_catalogue.Tpo -c -o libhdrl_la-hdrl_catalogue.lo `test -f 'hdrl_catalogue.c' || echo '$(srcdir)/'`hdrl_catalogue.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_catalogue.Tpo $(DEPDIR)/libhdrl_la-hdrl_catalogue.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_catalogue.c' object='libhdrl_la-hdrl_catalogue.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_catalogue.lo `test -f 'hdrl_catalogue.c' || echo '$(srcdir)/'`hdrl_catalogue.c + +libhdrl_la-hdrl_random.lo: hdrl_random.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_random.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_random.Tpo -c -o libhdrl_la-hdrl_random.lo `test -f 'hdrl_random.c' || echo '$(srcdir)/'`hdrl_random.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_random.Tpo $(DEPDIR)/libhdrl_la-hdrl_random.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_random.c' object='libhdrl_la-hdrl_random.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_random.lo `test -f 'hdrl_random.c' || echo '$(srcdir)/'`hdrl_random.c + +libhdrl_la-hdrl_spectrum.lo: hdrl_spectrum.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_spectrum.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_spectrum.Tpo -c -o libhdrl_la-hdrl_spectrum.lo `test -f 'hdrl_spectrum.c' || echo '$(srcdir)/'`hdrl_spectrum.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_spectrum.Tpo $(DEPDIR)/libhdrl_la-hdrl_spectrum.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_spectrum.c' object='libhdrl_la-hdrl_spectrum.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_spectrum.lo `test -f 'hdrl_spectrum.c' || echo '$(srcdir)/'`hdrl_spectrum.c + +libhdrl_la-hdrl_spectrumlist.lo: hdrl_spectrumlist.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_spectrumlist.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_spectrumlist.Tpo -c -o libhdrl_la-hdrl_spectrumlist.lo `test -f 'hdrl_spectrumlist.c' || echo '$(srcdir)/'`hdrl_spectrumlist.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_spectrumlist.Tpo $(DEPDIR)/libhdrl_la-hdrl_spectrumlist.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_spectrumlist.c' object='libhdrl_la-hdrl_spectrumlist.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_spectrumlist.lo `test -f 'hdrl_spectrumlist.c' || echo '$(srcdir)/'`hdrl_spectrumlist.c + +libhdrl_la-hdrl_spectrum_resample.lo: hdrl_spectrum_resample.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_spectrum_resample.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_spectrum_resample.Tpo -c -o libhdrl_la-hdrl_spectrum_resample.lo `test -f 'hdrl_spectrum_resample.c' || echo '$(srcdir)/'`hdrl_spectrum_resample.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_spectrum_resample.Tpo $(DEPDIR)/libhdrl_la-hdrl_spectrum_resample.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_spectrum_resample.c' object='libhdrl_la-hdrl_spectrum_resample.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_spectrum_resample.lo `test -f 'hdrl_spectrum_resample.c' || echo '$(srcdir)/'`hdrl_spectrum_resample.c + +libhdrl_la-hdrl_spectrum_shift.lo: hdrl_spectrum_shift.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_spectrum_shift.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_spectrum_shift.Tpo -c -o libhdrl_la-hdrl_spectrum_shift.lo `test -f 'hdrl_spectrum_shift.c' || echo '$(srcdir)/'`hdrl_spectrum_shift.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_spectrum_shift.Tpo $(DEPDIR)/libhdrl_la-hdrl_spectrum_shift.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_spectrum_shift.c' object='libhdrl_la-hdrl_spectrum_shift.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_spectrum_shift.lo `test -f 'hdrl_spectrum_shift.c' || echo '$(srcdir)/'`hdrl_spectrum_shift.c + +libhdrl_la-hdrl_DER_SNR.lo: hdrl_DER_SNR.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_DER_SNR.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_DER_SNR.Tpo -c -o libhdrl_la-hdrl_DER_SNR.lo `test -f 'hdrl_DER_SNR.c' || echo '$(srcdir)/'`hdrl_DER_SNR.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_DER_SNR.Tpo $(DEPDIR)/libhdrl_la-hdrl_DER_SNR.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_DER_SNR.c' object='libhdrl_la-hdrl_DER_SNR.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_DER_SNR.lo `test -f 'hdrl_DER_SNR.c' || echo '$(srcdir)/'`hdrl_DER_SNR.c + +libhdrl_la-hdrl_correlation.lo: hdrl_correlation.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_correlation.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_correlation.Tpo -c -o libhdrl_la-hdrl_correlation.lo `test -f 'hdrl_correlation.c' || echo '$(srcdir)/'`hdrl_correlation.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_correlation.Tpo $(DEPDIR)/libhdrl_la-hdrl_correlation.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_correlation.c' object='libhdrl_la-hdrl_correlation.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_correlation.lo `test -f 'hdrl_correlation.c' || echo '$(srcdir)/'`hdrl_correlation.c + +libhdrl_la-hdrl_response.lo: hdrl_response.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_response.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_response.Tpo -c -o libhdrl_la-hdrl_response.lo `test -f 'hdrl_response.c' || echo '$(srcdir)/'`hdrl_response.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_response.Tpo $(DEPDIR)/libhdrl_la-hdrl_response.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_response.c' object='libhdrl_la-hdrl_response.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_response.lo `test -f 'hdrl_response.c' || echo '$(srcdir)/'`hdrl_response.c + +libhdrl_la-hdrl_efficiency.lo: hdrl_efficiency.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_efficiency.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_efficiency.Tpo -c -o libhdrl_la-hdrl_efficiency.lo `test -f 'hdrl_efficiency.c' || echo '$(srcdir)/'`hdrl_efficiency.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_efficiency.Tpo $(DEPDIR)/libhdrl_la-hdrl_efficiency.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_efficiency.c' object='libhdrl_la-hdrl_efficiency.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_efficiency.lo `test -f 'hdrl_efficiency.c' || echo '$(srcdir)/'`hdrl_efficiency.c + +libhdrl_la-hdrl_dar.lo: hdrl_dar.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-hdrl_dar.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-hdrl_dar.Tpo -c -o libhdrl_la-hdrl_dar.lo `test -f 'hdrl_dar.c' || echo '$(srcdir)/'`hdrl_dar.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-hdrl_dar.Tpo $(DEPDIR)/libhdrl_la-hdrl_dar.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hdrl_dar.c' object='libhdrl_la-hdrl_dar.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-hdrl_dar.lo `test -f 'hdrl_dar.c' || echo '$(srcdir)/'`hdrl_dar.c + +libhdrl_la-igam.lo: igam.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -MT libhdrl_la-igam.lo -MD -MP -MF $(DEPDIR)/libhdrl_la-igam.Tpo -c -o libhdrl_la-igam.lo `test -f 'igam.c' || echo '$(srcdir)/'`igam.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhdrl_la-igam.Tpo $(DEPDIR)/libhdrl_la-igam.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='igam.c' object='libhdrl_la-igam.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libhdrl_la_CFLAGS) $(CFLAGS) -c -o libhdrl_la-igam.lo `test -f 'igam.c' || echo '$(srcdir)/'`igam.c + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool config.lt +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkgincludedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkgincludedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkgincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkgincludedir)" || exit $$?; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; test -n "$(pkgincludedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(pkgincludedir)'; $(am__uninstall_files_from_dir) + +# This directory's subdirectories are mostly independent; you can cd +# into them and run 'make' without going through this Makefile. +# To change the values of 'make' variables: instead of editing Makefiles, +# (1) if the variable is set in 'config.status', edit 'config.status' +# (which will cause the Makefiles to be regenerated when you run 'make'); +# (2) otherwise, pass the desired values on the 'make' command line. +$(am__recursive_targets): + @fail=; \ + if $(am__make_keepgoing); then \ + failcom='fail=yes'; \ + else \ + failcom='exit 1'; \ + fi; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-recursive +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-recursive + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscope: cscope.files + test ! -s cscope.files \ + || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) +clean-cscope: + -rm -f cscope.files +cscope.files: clean-cscope cscopelist +cscopelist: cscopelist-recursive + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f cscope.out cscope.in.out cscope.po.out cscope.files + +distdir: $(DISTFILES) + $(am__remove_distdir) + test -d "$(distdir)" || mkdir "$(distdir)" + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done + -test -n "$(am__skip_mode_fix)" \ + || find "$(distdir)" -type d ! -perm -755 \ + -exec chmod u+rwx,go+rx {} \; -o \ + ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ + ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ + || chmod -R a+r "$(distdir)" +dist-gzip: distdir + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + $(am__post_remove_distdir) + +dist-bzip2: distdir + tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 + $(am__post_remove_distdir) + +dist-lzip: distdir + tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz + $(am__post_remove_distdir) + +dist-xz: distdir + tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz + $(am__post_remove_distdir) + +dist-tarZ: distdir + @echo WARNING: "Support for distribution archives compressed with" \ + "legacy program 'compress' is deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z + $(am__post_remove_distdir) + +dist-shar: distdir + @echo WARNING: "Support for shar distribution archives is" \ + "deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + $(am__post_remove_distdir) + +dist-zip: distdir + -rm -f $(distdir).zip + zip -rq $(distdir).zip $(distdir) + $(am__post_remove_distdir) + +dist dist-all: + $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' + $(am__post_remove_distdir) + +# This target untars the dist file and tries a VPATH configuration. Then +# it guarantees that the distribution is self-contained by making another +# tarfile. +distcheck: dist + case '$(DIST_ARCHIVES)' in \ + *.tar.gz*) \ + GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + *.tar.bz2*) \ + bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ + *.tar.lz*) \ + lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ + *.tar.xz*) \ + xz -dc $(distdir).tar.xz | $(am__untar) ;;\ + *.tar.Z*) \ + uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ + *.shar.gz*) \ + GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + *.zip*) \ + unzip $(distdir).zip ;;\ + esac + chmod -R a-w $(distdir) + chmod u+w $(distdir) + mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst + chmod a-w $(distdir) + test -d $(distdir)/_build || exit 0; \ + dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ + && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ + && am__cwd=`pwd` \ + && $(am__cd) $(distdir)/_build/sub \ + && ../../configure \ + $(AM_DISTCHECK_CONFIGURE_FLAGS) \ + $(DISTCHECK_CONFIGURE_FLAGS) \ + --srcdir=../.. --prefix="$$dc_install_base" \ + && $(MAKE) $(AM_MAKEFLAGS) \ + && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) check \ + && $(MAKE) $(AM_MAKEFLAGS) install \ + && $(MAKE) $(AM_MAKEFLAGS) installcheck \ + && $(MAKE) $(AM_MAKEFLAGS) uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ + distuninstallcheck \ + && chmod -R a-w "$$dc_install_base" \ + && ({ \ + (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ + && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ + distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ + } || { rm -rf "$$dc_destdir"; exit 1; }) \ + && rm -rf "$$dc_destdir" \ + && $(MAKE) $(AM_MAKEFLAGS) dist \ + && rm -rf $(DIST_ARCHIVES) \ + && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ + && cd "$$am__cwd" \ + || exit 1 + $(am__post_remove_distdir) + @(echo "$(distdir) archives ready for distribution: "; \ + list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ + sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' +distuninstallcheck: + @test -n '$(distuninstallcheck_dir)' || { \ + echo 'ERROR: trying to run $@ with an empty' \ + '$$(distuninstallcheck_dir)' >&2; \ + exit 1; \ + }; \ + $(am__cd) '$(distuninstallcheck_dir)' || { \ + echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ + exit 1; \ + }; \ + test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left after uninstall:" ; \ + if test -n "$(DESTDIR)"; then \ + echo " (check DESTDIR support)"; \ + fi ; \ + $(distuninstallcheck_listfiles) ; \ + exit 1; } >&2 +distcleancheck: distclean + @if test '$(srcdir)' = . ; then \ + echo "ERROR: distcleancheck can only run from a VPATH build" ; \ + exit 1 ; \ + fi + @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ + || { echo "ERROR: files left in build directory after distclean:" ; \ + $(distcleancheck_listfiles) ; \ + exit 1; } >&2 +check-am: all-am +check: check-recursive +all-am: Makefile $(LTLIBRARIES) $(HEADERS) config.h +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-recursive +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-recursive + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + clean-noinstLTLIBRARIES mostlyclean-am + +distclean: distclean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-hdr distclean-libtool distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: install-pkgincludeHEADERS + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f $(am__CONFIG_DISTCLEAN_FILES) + -rm -rf $(top_srcdir)/autom4te.cache + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-libLTLIBRARIES uninstall-pkgincludeHEADERS + +.MAKE: $(am__recursive_targets) all install-am install-strip + +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--refresh check check-am clean clean-cscope clean-generic \ + clean-libLTLIBRARIES clean-libtool clean-noinstLTLIBRARIES \ + cscope cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \ + dist-gzip dist-lzip dist-shar dist-tarZ dist-xz dist-zip \ + distcheck distclean distclean-compile distclean-generic \ + distclean-hdr distclean-libtool distclean-tags distcleancheck \ + distdir distuninstallcheck dvi dvi-am html html-am info \ + info-am install install-am install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-pkgincludeHEADERS install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + installdirs-am maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-libLTLIBRARIES \ + uninstall-pkgincludeHEADERS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_2d-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_2d-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_2d-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_2d-test.c 2017-09-20 10:02:45.000000000 +0000 @@ -0,0 +1,520 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_bpm_2d.h" +#include "hdrl_bpm_2d.c" +#include "hdrl_image.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_2d_test Testing of the HDRL bpm_2d + */ +/*----------------------------------------------------------------------------*/ + +void test_parlist(void) +{ + /* parameter parsing smoketest */ + hdrl_parameter * hpar; + + /* Create hdrl_parameter of filter and legendre */ + hdrl_parameter * fil_def = + hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, + CPL_FILTER_MEDIAN, + CPL_BORDER_NOP, + 7, 9); + + hdrl_parameter * leg_def = + hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, + 20, 21, + 11, 12, 2, 10); + + /* Check parameters */ + cpl_test(hdrl_bpm_2d_parameter_check(fil_def)); + cpl_test(hdrl_bpm_2d_parameter_check(leg_def)); + + + /* Verify hdrl_parameter */ + hdrl_parameter *pErr; + + hdrl_bpm_2d_parameter_verify(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_bpm_2d_parameter_verify(fil_def); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_bpm_2d_parameter_verify(leg_def); + cpl_test_error(CPL_ERROR_NONE); + + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(-1., 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 9); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, -1., 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 9); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, -1, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 9); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_STDEV, CPL_BORDER_NOP, 7, 9); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, -1, 9); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, -1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 0, 9); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 0); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(-1., 5, 6, 20, 21, 11, 12, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, -1., 6, 20, 21, 11, 12, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, -1, 20, 21, 11, 12, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 11, 12, -1, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 11, 12, 2, -1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 0, 12, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 11, 0, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 0, 21, 11, 12, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 0, 11, 12, 2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(pErr); + + + + cpl_parameterlist *plErr; + hdrl_parameter *parseErr; + + /* Create parlist: hdrl_bpm_2d_filtersmooth_parameter_create_parlist */ + + plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist(NULL, "filter", fil_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist("test", NULL, fil_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist("test", "filter", NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist("test", "filter", fil_def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plErr); + + parseErr = hdrl_bpm_2d_parameter_parse_parlist(NULL, "filter"); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(parseErr); + + parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(parseErr); + + parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, "filter"); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + cpl_test_null(parseErr); + + cpl_parameterlist_delete(plErr); + + + + /* Create parlist: hdrl_bpm_2d_legendresmooth_parameter_create_parlist */ + + plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist(NULL, "legendre", leg_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist("test", NULL, leg_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist("test", "legendre", NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist("test", "legendre", leg_def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plErr); + + parseErr = hdrl_bpm_2d_parameter_parse_parlist(NULL, "legendre"); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(parseErr); + + parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(parseErr); + + parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, "legendre"); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + cpl_test_null(parseErr); + + cpl_parameterlist_delete(plErr); + + + + + /* Create parlist: hdrl_bpm_2d_parameter_create_parlist */ + plErr = hdrl_bpm_2d_parameter_create_parlist(NULL, "bpm", "FILTER", fil_def, leg_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", NULL, "FILTER", fil_def, leg_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", NULL, fil_def, leg_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", "FILTER", NULL, leg_def); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", "FILTER", fil_def, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plErr); + + cpl_parameterlist * pos = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", "FILTER", fil_def, leg_def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(pos), 17); + + + + + + + + hpar = hdrl_bpm_2d_parameter_parse_parlist(pos, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hpar = hdrl_bpm_2d_parameter_parse_parlist(pos, "RECIPE.bpm"); + cpl_parameterlist_delete(pos); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter(NULL), CPL_FILTER_EROSION); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter(hpar), CPL_FILTER_MEDIAN); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_border(NULL), CPL_BORDER_FILTER); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_border(hpar), CPL_BORDER_NOP); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_low(NULL), -1.); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_low(hpar), 4); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_high(NULL), -1.); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_high(hpar), 5); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_maxiter(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_maxiter(hpar), 6); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_x(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_x(hpar), 7); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_y(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_y(hpar), 9); + cpl_test_error(CPL_ERROR_NONE); + + /* TODO wrong par error? */ + cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_x(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_x(hpar), 0); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_y(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_y(hpar), 0); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_x(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_x(hpar), 0); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_y(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_y(hpar), 0); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_order_x(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_order_x(hpar), 0); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_order_y(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_order_y(hpar), 0); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_parameter_delete(hpar); + + pos = hdrl_bpm_2d_parameter_create_parlist( + "RECIPE", "bpm", "LEGENDRE", fil_def, leg_def); + cpl_test_error(CPL_ERROR_NONE); + + hpar = hdrl_bpm_2d_parameter_parse_parlist(pos, "RECIPE.bpm"); + cpl_parameterlist_delete(pos); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_low(hpar), 4); + cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_high(hpar), 5); + cpl_test_eq(hdrl_bpm_2d_parameter_get_maxiter(hpar), 6); + cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_x(hpar), 20); + cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_y(hpar), 21); + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_x(hpar), 11); + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_y(hpar), 12); + cpl_test_eq(hdrl_bpm_2d_parameter_get_order_x(hpar), 2); + cpl_test_eq(hdrl_bpm_2d_parameter_get_order_y(hpar), 10); + /* TODO wrong par error? */ + cpl_test_eq(hdrl_bpm_2d_parameter_get_filter(hpar), CPL_FILTER_MEDIAN); + cpl_test_eq(hdrl_bpm_2d_parameter_get_border(hpar), CPL_BORDER_FILTER); + cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_x(hpar), 0); + cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_y(hpar), 0); + + hdrl_bpm_2d_parameter_get_method(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_bpm_2d_parameter_get_method(hpar), HDRL_BPM_2D_LEGENDRESMOOTH); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_parameter_delete(hpar); + + + cpl_test(!strcmp(filter_to_string(CPL_FILTER_EROSION), "EROSION")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_DILATION), "DILATION")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_OPENING), "OPENING")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_CLOSING), "CLOSING")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_LINEAR), "LINEAR")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_LINEAR_SCALE), "LINEAR_SCALE")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_AVERAGE), "AVERAGE")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_AVERAGE_FAST), "AVERAGE_FAST")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_MEDIAN), "MEDIAN")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_STDEV), "STDEV")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_STDEV_FAST), "STDEV_FAST")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_MORPHO), "MORPHO")); + cpl_test(!strcmp(filter_to_string(CPL_FILTER_MORPHO_SCALE), "MORPHO_SCALE")); + + cpl_test(!strcmp(border_to_string(CPL_BORDER_FILTER), "FILTER")); + cpl_test(!strcmp(border_to_string(CPL_BORDER_ZERO), "ZERO")); + cpl_test(!strcmp(border_to_string(CPL_BORDER_CROP), "CROP")); + cpl_test(!strcmp(border_to_string(CPL_BORDER_NOP), "NOP")); + cpl_test(!strcmp(border_to_string(CPL_BORDER_COPY), "COPY")); + + + hdrl_parameter_delete(leg_def); + hdrl_parameter_delete(fil_def); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_bpm_2d_compute() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_2d_test_compute(void) +{ + cpl_image * data = NULL; + cpl_image * errors = NULL; + cpl_mask * mask_out = NULL; + hdrl_parameter * bpm_param; + + /* Create BPM parameters */ + bpm_param = hdrl_bpm_2d_parameter_create_filtersmooth(3., 3., 2, + CPL_FILTER_MEDIAN, CPL_BORDER_FILTER, 3, 3) ; + cpl_test(hdrl_bpm_2d_parameter_check(bpm_param)); + + { /* Test sigmaclipped mean */ + /* gauss mean 100 sigma 3.5 and 2 outliers */ + double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 500, 600 }; + + data = cpl_image_wrap(7, 7, CPL_TYPE_DOUBLE, values); + errors = cpl_image_new(7, 7, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(errors, 1); + + cpl_image_set(errors, 7, 7, 100000.); + cpl_image_set(errors, 6, 7, 10000.); + + hdrl_image * sigimage = hdrl_image_create(data, errors); + + mask_out = hdrl_bpm_2d_compute(NULL, bpm_param); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(mask_out); + + mask_out = hdrl_bpm_2d_compute(sigimage, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(mask_out); + + + mask_out = hdrl_bpm_2d_compute(sigimage, bpm_param); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(mask_out); + + cpl_mask_delete(mask_out); + + hdrl_parameter_delete(bpm_param) ; + bpm_param = hdrl_bpm_2d_parameter_create_legendresmooth(3., 3., + 2, 20, 20, 11, 11, 3, 3); + cpl_test(hdrl_bpm_2d_parameter_check(bpm_param)); + + + mask_out = hdrl_bpm_2d_compute(sigimage, bpm_param) ; + + //cpl_mask_save(mask_out, "bpm1.fits", NULL, CPL_IO_CREATE); + + cpl_mask_delete(mask_out); + cpl_image_unwrap(data); + cpl_image_delete(errors); + hdrl_image_delete(sigimage); + } + + { + cpl_mask * data_bpm = cpl_mask_new(200, 300); + data = cpl_image_new(200, 300, CPL_TYPE_FLOAT); + + cpl_image_fill_noise_uniform(data, 90, 110); + cpl_image_set(data, 50, 50, 300.); + cpl_image_set(data, 100, 100, 300.); + cpl_image_set(data, 150, 150, 300.); + cpl_image_set(data, 110, 260, 300.); + + cpl_mask_set(data_bpm, 120,120, CPL_BINARY_1); + cpl_mask_set(data_bpm, 120,121, CPL_BINARY_1); + cpl_mask_set(data_bpm, 120,122, CPL_BINARY_1); + cpl_mask_set(data_bpm, 121,120, CPL_BINARY_1); + cpl_mask_set(data_bpm, 121,121, CPL_BINARY_1); + cpl_mask_set(data_bpm, 121,122, CPL_BINARY_1); + cpl_mask_set(data_bpm, 122,120, CPL_BINARY_1); + cpl_mask_set(data_bpm, 122,121, CPL_BINARY_1); + cpl_mask_set(data_bpm, 122,122, CPL_BINARY_1); + /*set one outlier on a bad pixel*/ + cpl_image_set(data, 122, 122, 300.); + + cpl_image_reject_from_mask(data, data_bpm); + + errors=cpl_image_power_create(data, 0.5); + hdrl_image * image = hdrl_image_create(data, errors); + + /* Note that for CPL_FILTER_STDEV one gets more false positives!! */ + hdrl_parameter_delete(bpm_param) ; + bpm_param = hdrl_bpm_2d_parameter_create_filtersmooth(3., 3., 5, + CPL_FILTER_MEDIAN, CPL_BORDER_FILTER, 3, 3) ; + cpl_test(hdrl_bpm_2d_parameter_check(bpm_param)); + mask_out = hdrl_bpm_2d_compute(image, bpm_param) ; + cpl_test_eq(cpl_mask_get(mask_out, 50, 50), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 100, 100), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 150, 150), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 110, 260), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 122, 122), CPL_BINARY_0); + cpl_mask_delete(mask_out); + + hdrl_parameter_delete(bpm_param) ; + bpm_param = hdrl_bpm_2d_parameter_create_legendresmooth(3., 3., + 5, 20, 20, 11, 11, 3, 3); + cpl_test(hdrl_bpm_2d_parameter_check(bpm_param)); + mask_out = hdrl_bpm_2d_compute(image, bpm_param) ; + cpl_test_eq(cpl_mask_get(mask_out, 50, 50), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 100, 100), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 150, 150), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 110, 260), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(mask_out, 122, 122), CPL_BINARY_0); + + cpl_mask_delete(data_bpm); + cpl_mask_delete(mask_out); + cpl_image_delete(data); + cpl_image_delete(errors); + hdrl_image_delete(image); + } + hdrl_parameter_delete(bpm_param) ; + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of BPM module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + hdrl_bpm_2d_test_compute(); + test_parlist(); + cpl_test_error(CPL_ERROR_NONE); + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_3d-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_3d-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_3d-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_3d-test.c 2017-09-19 14:35:18.000000000 +0000 @@ -0,0 +1,277 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_bpm_3d.h" +#include "hdrl_image.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_3d_test Testing of the HDRL bpm_3d + */ +/*----------------------------------------------------------------------------*/ + +void test_parlist(void) +{ + /* parameter parsing smoketest */ + hdrl_parameter * hpar; + hdrl_parameter * deflts; + + deflts = hdrl_bpm_3d_parameter_create(4, 5, HDRL_BPM_3D_THRESHOLD_ERROR); + cpl_parameterlist *pos = hdrl_bpm_3d_parameter_create_parlist( + "RECIPE", "bpm", deflts); + hdrl_parameter *parse = hdrl_bpm_3d_parameter_parse_parlist(pos, "RECIPE.bpm"); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(parse); + hdrl_parameter_delete(parse); + hdrl_parameter_delete(deflts); + cpl_parameterlist_delete(pos); + + deflts = hdrl_bpm_3d_parameter_create(4, 5, HDRL_BPM_3D_THRESHOLD_RELATIVE); + pos = hdrl_bpm_3d_parameter_create_parlist("RECIPE", "bpm", deflts); + hdrl_parameter_delete(deflts) ; + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(pos), 3); + + hpar = hdrl_bpm_3d_parameter_parse_parlist(pos, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hpar = hdrl_bpm_3d_parameter_parse_parlist(pos, "RECIPE.bpm"); + cpl_parameterlist_delete(pos); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_bpm_3d_parameter_get_method(hpar), + HDRL_BPM_3D_THRESHOLD_RELATIVE); + cpl_test_eq(hdrl_bpm_3d_parameter_get_kappa_low(hpar), 4); + cpl_test_eq(hdrl_bpm_3d_parameter_get_kappa_high(hpar), 5); + hdrl_parameter_delete(hpar); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_bpm_3d_compute() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_3d_test_compute(void) +{ + cpl_image * img_tmp = NULL; + cpl_imagelist * result_data = NULL; + hdrl_imagelist * imglist = hdrl_imagelist_new(); + int bad = 0; + hdrl_parameter * bpm_param ; + for (int var = 0; var <5 ; ++var) { + cpl_image * data = cpl_image_new(200, 300, CPL_TYPE_DOUBLE); + cpl_mask * data_bpm = cpl_mask_new(200, 300); + /* STDEV is about 10 for these images */ + cpl_image_fill_noise_uniform(data, 82, 118); + if(var == 0) { + /* Negative outlier set and marked as bad */ + cpl_image_set(data, 10, 10, 20.); + cpl_mask_set(data_bpm, 10, 10, CPL_BINARY_1); + + /* Positive outlier set and marked as bad */ + cpl_image_set(data, 50, 50, 300.); + cpl_mask_set(data_bpm, 50, 50, CPL_BINARY_1); + + /* Positive outliers set */ + cpl_image_set(data, 60, 60, 300.); + cpl_image_set(data, 61, 61, 300.); + cpl_image_set(data, 62, 62, 300.); + + /* Negative outliers set */ + cpl_image_set(data, 70, 70, 20.); + cpl_image_set(data, 71, 71, 20.); + cpl_image_set(data, 72, 72, 20.); + + /*Some pixels marked as bad*/ + cpl_mask_set(data_bpm, 80, 80, CPL_BINARY_1); + cpl_mask_set(data_bpm, 81, 80, CPL_BINARY_1); + cpl_mask_set(data_bpm, 82, 80, CPL_BINARY_1); + + } else if (var == 3) { + cpl_image_set(data, 150, 150, 300.); + cpl_image_set(data, 110, 260, 300.); + cpl_mask_set(data_bpm, 70, 70, CPL_BINARY_1); + cpl_mask_set(data_bpm, 80, 80, CPL_BINARY_1); + } + + cpl_image_reject_from_mask(data, data_bpm); + cpl_image * errors=cpl_image_power_create(data, 0.5); + hdrl_image * image = hdrl_image_create(data, errors); + + hdrl_imagelist_set(imglist, image, var); + /* free the memory */ + cpl_mask_delete(data_bpm); + cpl_image_delete(data); + cpl_image_delete(errors); + + } + //---------------------------------------------------------------------- + bpm_param = hdrl_bpm_3d_parameter_create(-50.0, 50.0, + HDRL_BPM_3D_THRESHOLD_ABSOLUTE) ; + cpl_test(hdrl_bpm_3d_parameter_check(bpm_param)); + + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + img_tmp = cpl_imagelist_get(result_data, 0); + cpl_test_eq(cpl_image_get(img_tmp, 10, 10, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 50, 50, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 60, 60, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 61, 61, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 62, 62, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 70, 70, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 71, 71, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 72, 72, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 80, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 81, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 82, 80, &bad), 0); + cpl_imagelist_delete(result_data); + //---------------------------------------------------------------------- + + //---------------------------------------------------------------------- + bpm_param = hdrl_bpm_3d_parameter_create(5., 5., + HDRL_BPM_3D_THRESHOLD_RELATIVE) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + img_tmp = cpl_imagelist_get(result_data, 0); + cpl_test_eq(cpl_image_get(img_tmp, 10, 10, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 50, 50, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 60, 60, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 61, 61, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 62, 62, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 70, 70, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 71, 71, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 72, 72, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 80, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 81, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 82, 80, &bad), 0); + cpl_imagelist_delete(result_data); + //---------------------------------------------------------------------- + + //---------------------------------------------------------------------- + bpm_param = hdrl_bpm_3d_parameter_create(5., 5., + HDRL_BPM_3D_THRESHOLD_ERROR) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + cpl_test_error(CPL_ERROR_NONE); + + img_tmp = cpl_imagelist_get(result_data, 0); + + cpl_test_eq(cpl_image_get(img_tmp, 10, 10, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 50, 50, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 60, 60, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 61, 61, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 62, 62, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 70, 70, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 71, 71, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 72, 72, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 80, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 81, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 82, 80, &bad), 0); + /*cpl_imagelist_save(result_data, "result.fits", CPL_TYPE_INT, NULL, + CPL_IO_CREATE);*/ + cpl_imagelist_delete(result_data); + //---------------------------------------------------------------------- + + //---------------------------------------------------------------------- + bpm_param = hdrl_bpm_3d_parameter_create(500., 5., + HDRL_BPM_3D_THRESHOLD_ERROR) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + cpl_test_error(CPL_ERROR_NONE); + + img_tmp = cpl_imagelist_get(result_data, 0); + + cpl_test_eq(cpl_image_get(img_tmp, 10, 10, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 50, 50, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 60, 60, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 61, 61, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 62, 62, &bad), 1); + cpl_test_eq(cpl_image_get(img_tmp, 70, 70, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 71, 71, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 72, 72, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 80, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 81, 80, &bad), 0); + cpl_test_eq(cpl_image_get(img_tmp, 82, 80, &bad), 0); + cpl_imagelist_delete(result_data); + //---------------------------------------------------------------------- + + bpm_param = hdrl_bpm_3d_parameter_create(5., 5., + HDRL_BPM_3D_THRESHOLD_ERROR) ; + result_data = hdrl_bpm_3d_compute(NULL, bpm_param); + hdrl_parameter_delete(bpm_param) ; + cpl_test_null(result_data); + cpl_test_error(CPL_ERROR_NULL_INPUT); + bpm_param = hdrl_bpm_3d_parameter_create(5.1, 5., + HDRL_BPM_3D_THRESHOLD_ABSOLUTE) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + cpl_test_null(result_data); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + bpm_param = hdrl_bpm_3d_parameter_create(-5., 5., + HDRL_BPM_3D_THRESHOLD_RELATIVE) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + cpl_test_null(result_data); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + bpm_param = hdrl_bpm_3d_parameter_create(-5., 5., + HDRL_BPM_3D_THRESHOLD_ERROR) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + cpl_test_null(result_data); + hdrl_parameter_delete(bpm_param) ; + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + bpm_param = hdrl_bpm_3d_parameter_create(5., -5., + HDRL_BPM_3D_THRESHOLD_ERROR) ; + result_data = hdrl_bpm_3d_compute(imglist, bpm_param); + hdrl_parameter_delete(bpm_param) ; + cpl_test_null(result_data); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_imagelist_delete(imglist); + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of BPM module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + hdrl_bpm_3d_test_compute(); + test_parlist(); + cpl_test_error(CPL_ERROR_NONE); + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_fit-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_fit-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_fit-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_fit-test.c 2017-09-20 13:52:02.000000000 +0000 @@ -0,0 +1,291 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "igam.c" +#include "hdrl_bpm_fit.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_fit_test Testing of the HDRL bpm_fit + */ +/*----------------------------------------------------------------------------*/ + +void test_invalid_parameter(void) +{ + hdrl_parameter * p; + /* invalid degree */ + p = hdrl_bpm_fit_parameter_create_pval(-1, 0.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + p = hdrl_bpm_fit_parameter_create_rel_chi(-1, 0.1, 0.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + p = hdrl_bpm_fit_parameter_create_rel_coef(-1, 0.1, 0.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* invalid threshold */ + p = hdrl_bpm_fit_parameter_create_pval(1, -0.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + p = hdrl_bpm_fit_parameter_create_pval(1, 100.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + p = hdrl_bpm_fit_parameter_create_rel_chi(1, -0.1, 0.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + p = hdrl_bpm_fit_parameter_create_rel_coef(1, -0.1, -0.1); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* NULL input */ + hdrl_bpm_fit_parameter_get_pval(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_bpm_fit_parameter_get_rel_chi_low(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_bpm_fit_parameter_get_rel_coef_high(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); +} + +void test_parameter(void) +{ + hdrl_parameter * p; + + p = hdrl_bpm_fit_parameter_create_pval(1, 10.); + cpl_test(hdrl_bpm_fit_parameter_check(p)); + cpl_test_abs(hdrl_bpm_fit_parameter_get_pval(p), 10., 0); + cpl_test_lt((hdrl_bpm_fit_parameter_get_rel_chi_low(p)), 0); + cpl_test_lt((hdrl_bpm_fit_parameter_get_rel_coef_high(p)), 0); + hdrl_parameter_delete(p); + + p = hdrl_bpm_fit_parameter_create_rel_chi(1, 10., 5.); + cpl_test(hdrl_bpm_fit_parameter_check(p)); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_chi_low(p), 10.); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_chi_high(p), 5.); + cpl_test_lt(hdrl_bpm_fit_parameter_get_pval(p), 0); + cpl_test_lt(hdrl_bpm_fit_parameter_get_rel_coef_low(p), 0); + cpl_test_lt(hdrl_bpm_fit_parameter_get_rel_coef_high(p), 0); + hdrl_parameter_delete(p); + + p = hdrl_bpm_fit_parameter_create_rel_coef(1, 10., 3.); + cpl_test(hdrl_bpm_fit_parameter_check(p)); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_coef_low(p), 10.); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_coef_high(p), 3.); + cpl_test_lt(hdrl_bpm_fit_parameter_get_pval(p), 0); + cpl_test_lt(hdrl_bpm_fit_parameter_get_rel_chi_low(p), 0); + cpl_test_lt(hdrl_bpm_fit_parameter_get_rel_chi_high(p), 0); + + hdrl_parameter_delete(p); +} + +void test_parameterlist(void) +{ + hdrl_parameter * p; + hdrl_parameter * def; + cpl_parameterlist * parlist; + + def = hdrl_bpm_fit_parameter_create_pval(-2, 0.1) ; + parlist = hdrl_bpm_fit_parameter_create_parlist("RECIPE", "bpm_fit", def); + hdrl_parameter_delete(def); + p = hdrl_bpm_fit_parameter_parse_parlist(parlist, "RECIPE.bpm_fit"); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_parameterlist_delete(parlist); + + def = hdrl_bpm_fit_parameter_create_pval(2, -1) ; + parlist = hdrl_bpm_fit_parameter_create_parlist("RECIPE", "bpm_fit", def); + hdrl_parameter_delete(def); + p = hdrl_bpm_fit_parameter_parse_parlist(parlist, "RECIPE.bpm_fit"); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_parameterlist_delete(parlist); + + def = hdrl_bpm_fit_parameter_create_pval(2, 0.1) ; + parlist = hdrl_bpm_fit_parameter_create_parlist("RECIPE", "bpm_fit", def); + hdrl_parameter_delete(def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(parlist), 6); + + p = hdrl_bpm_fit_parameter_parse_parlist(parlist, "RECIPE.invalid"); + cpl_test_null(p); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + p = hdrl_bpm_fit_parameter_parse_parlist(parlist, "RECIPE.bpm_fit"); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(parlist), 6); + cpl_test_eq(hdrl_bpm_fit_parameter_get_degree(p), 2); + cpl_test_abs(hdrl_bpm_fit_parameter_get_pval(p), 0.1, 0); + hdrl_parameter_delete(p); + cpl_parameterlist_delete(parlist); + + def = hdrl_bpm_fit_parameter_create_rel_chi(2, 3., 2.) ; + parlist = hdrl_bpm_fit_parameter_create_parlist( "RECIPE", "bpm_fit", def); + hdrl_parameter_delete(def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(parlist), 6); + p = hdrl_bpm_fit_parameter_parse_parlist(parlist, "RECIPE.bpm_fit"); + cpl_test_eq(hdrl_bpm_fit_parameter_get_degree(p), 2); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_chi_low(p), 3.); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_chi_high(p), 2.); + hdrl_parameter_delete(p); + cpl_parameterlist_delete(parlist); + + def = hdrl_bpm_fit_parameter_create_rel_coef(2, 2., 3.) ; + parlist = hdrl_bpm_fit_parameter_create_parlist("RECIPE", "bpm_fit", def); + hdrl_parameter_delete(def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(parlist), 6); + p = hdrl_bpm_fit_parameter_parse_parlist(parlist, "RECIPE.bpm_fit"); + cpl_test_eq(hdrl_bpm_fit_parameter_get_degree(p), 2); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_coef_low(p), 2.); + cpl_test_eq(hdrl_bpm_fit_parameter_get_rel_coef_high(p), 3.); + hdrl_parameter_delete(p); + cpl_parameterlist_delete(parlist); +} + +void test_bpm_fit(void) +{ + int rej; + hdrl_imagelist * hl = hdrl_imagelist_new(); + cpl_vector * sample = cpl_vector_new(10); + for (size_t i = 0; i < 10; i++) { + hdrl_image * himg = hdrl_image_new(13, 4); + hdrl_image_add_scalar(himg, (hdrl_value){i + 1, sqrt(i + 1)}); + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){1.01, 1.}); + hdrl_imagelist_set(hl, himg, i); + cpl_vector_set(sample, i, i); + } + + hdrl_parameter * p; + cpl_image * out_mask; + + p = hdrl_bpm_fit_parameter_create_pval(1, 0.1); + hdrl_bpm_fit_compute(p, hl, sample, &out_mask); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_image_get_flux(out_mask), 0.); + cpl_image_delete(out_mask); + hdrl_parameter_delete(p); + + p = hdrl_bpm_fit_parameter_create_rel_coef(1, 1., 1.); + hdrl_bpm_fit_compute(p, hl, sample, &out_mask); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_image_get(out_mask, 1, 1, &rej), 3); + cpl_image_delete(out_mask); + hdrl_parameter_delete(p); + + p = hdrl_bpm_fit_parameter_create_rel_chi(1, 1., 1.); + hdrl_image_add_scalar(hdrl_imagelist_get(hl, 4), + (hdrl_value){5.1 , sqrt(5.1)}); + hdrl_bpm_fit_compute(p, hl, sample, &out_mask); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_image_get_flux(out_mask), 1.); + cpl_test_eq(cpl_image_get(out_mask, 1, 1, &rej), 1.); + cpl_image_delete(out_mask); + hdrl_parameter_delete(p); + + hdrl_imagelist_delete(hl); + cpl_vector_delete(sample); +} + +void test_igam(void){ + + cpl_test_error(CPL_ERROR_NONE); + + /* Fail test */ + cpl_test(isnan(igamc(-1, 1))); + cpl_test(isnan(igamc(1, -1))); + cpl_test(isnan(igamc(-1, -1))); + + cpl_test(!isnan(igamc(1, 1))); + + + /* Normal test */ + double a = 1.; + double x = 2.; + + double res1 = igamc(a, x); + cpl_test_eq(res1, 0.); + + double res2 = igamc(x, a); + cpl_test_eq(res2, 0.); + + double res3 = igam(a, x); + cpl_test_eq(res3, 0.); + + double res4 = igam(x, a); + cpl_test_eq(res4, 0.); + + + double res11 = igamc(0., 0.); + cpl_test(res11 != 0.); + + double res12 = igamc(0., 1.); + cpl_test(res12 != 0.); + + double res13 = igamc(1., 0.); + cpl_test(res13 != 0.); + + + double res21 = igamc(0., 1e10); + cpl_test(res21 != 0.); + + double res22 = igamc(1., 1e20); + cpl_test_eq(res22, 0.); + + double res23 = igamc(1e10, 0.); + cpl_test_eq(res23, 1.); + + double res24 = igamc(1e20, 1.); + cpl_test_eq(res24, 1.); + + + cpl_test_error(CPL_ERROR_NONE); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of BPM module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_invalid_parameter(); + test_parameter(); + test_parameterlist(); + test_bpm_fit(); + + test_igam(); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_utils-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_utils-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_bpm_utils-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_bpm_utils-test.c 2017-09-20 11:07:12.000000000 +0000 @@ -0,0 +1,478 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_bpm_utils.h" +#include "hdrl_image.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_bpm_utils_test Testing of the HDRL bpm_utils + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_bpm_to_mask() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_test_bpm_to_mask(void) +{ + cpl_size nx = 20; + cpl_size ny = 20; + { + cpl_mask * mask = hdrl_bpm_to_mask(NULL, 0); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(mask); + } + /* non int input */ + { + cpl_image * bpm = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_mask * mask = hdrl_bpm_to_mask(bpm, 0); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(mask); + cpl_image_delete(bpm); + + /* too big mask */ + bpm = cpl_image_new(nx, ny, CPL_TYPE_INT); + mask = hdrl_bpm_to_mask(bpm, ~0LLU); + cpl_test_null(mask); + cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); + + cpl_image_delete(bpm); + } + /* empty bpm */ + { + cpl_image * bpm = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_mask * mask = hdrl_bpm_to_mask(bpm, 0); + cpl_test_nonnull(mask); + cpl_test_eq(cpl_mask_count(mask), 0); + cpl_image_delete(bpm); + cpl_mask_delete(mask); + } + /* range of codes */ + { + cpl_image * bpm = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_image_set(bpm, 1, 1, 1); + cpl_image_set(bpm, 1, 2, 2); + cpl_image_set(bpm, 1, 3, 3); + cpl_image_set(bpm, 1, 4, 4); + + cpl_mask * mask; + + mask = hdrl_bpm_to_mask(bpm, 1); + cpl_test_nonnull(mask); + cpl_test_eq(cpl_mask_count(mask), 2); + cpl_mask_delete(mask); + + mask = hdrl_bpm_to_mask(bpm, ~0u); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(mask); + cpl_test_eq(cpl_mask_count(mask), 4); + cpl_mask_delete(mask); + + cpl_image_delete(bpm); + } + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_mask_to_bpm() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_test_mask_to_bpm(void) +{ + cpl_size nx = 20; + cpl_size ny = 20; + { + cpl_image * bpm = hdrl_mask_to_bpm(NULL, 0); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(bpm); + } + /* empty mask */ + { + cpl_image * bpm; + cpl_mask * mask = cpl_mask_new(nx, ny); + bpm = hdrl_mask_to_bpm(mask, 0); + cpl_test_nonnull(bpm); + cpl_test_eq(cpl_image_get_flux(bpm), 0); + cpl_image_delete(bpm); + cpl_mask_delete(mask); + } + /* non-empty mask */ + { + cpl_mask * mask = cpl_mask_new(nx, ny); + cpl_mask_set(mask, 1, 1, CPL_BINARY_1); + cpl_mask_set(mask, 1, 2, CPL_BINARY_1); + cpl_mask_set(mask, 1, 3, CPL_BINARY_1); + cpl_mask_set(mask, 1, 4, CPL_BINARY_1); + + cpl_image * bpm; + + bpm = hdrl_mask_to_bpm(mask, 1); + cpl_test_nonnull(bpm); + cpl_test_eq(cpl_image_get_flux(bpm), 4); + cpl_image_delete(bpm); + + bpm = hdrl_mask_to_bpm(mask, 5); + cpl_test_nonnull(bpm); + cpl_test_eq(cpl_image_get_flux(bpm), 5 * 4); + cpl_image_delete(bpm); + + cpl_mask_delete(mask); + } + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_bpm_filter() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_test_hdrl_bpm_filter(void) +{ + cpl_mask *img_mask = cpl_mask_new(200, 300); + + cpl_mask_set(img_mask, 50, 50, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 100, CPL_BINARY_1); + cpl_mask_set(img_mask, 150, 150, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 250, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 102, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 102, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 102, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 198, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 198, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 198, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 300, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 299, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 298, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 300, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 299, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 298, CPL_BINARY_1); + /*Test the border behaviour*/ + cpl_mask_set(img_mask, 199, 200, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 198, CPL_BINARY_1); + + + /*cpl_mask_save(img_mask, "img_mask.fits", NULL, CPL_IO_CREATE);*/ + + { + cpl_mask *filtered_mask = hdrl_bpm_filter(img_mask, 3, 3, CPL_FILTER_CLOSING); + + cpl_test_eq(cpl_mask_get(filtered_mask, 100, 255), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 101, 255), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 102, 255), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 103, 255), CPL_BINARY_0); + + cpl_test_eq(cpl_mask_get(filtered_mask, 100, 251), CPL_BINARY_1); + + cpl_test_eq(cpl_mask_get(filtered_mask, 198, 255), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 199, 255), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 200, 255), CPL_BINARY_1); + + cpl_test_eq(cpl_mask_get(filtered_mask, 198, 254), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 199, 254), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(filtered_mask, 200, 254), CPL_BINARY_1); + + /*Test the border behaviour*/ + cpl_test_eq(cpl_mask_get(filtered_mask, 200, 199), CPL_BINARY_0); + + /*cpl_mask_save(filtered_mask, "filtered_closing_mask.fits", NULL, + CPL_IO_CREATE);*/ + cpl_mask_delete(filtered_mask); + } + + /* free the memory */ + cpl_mask_delete(img_mask); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Can be used to test additional bad pixel growing algoritms + @return cpl_error_code + NOT TRIGGERED + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_test_bpmgrow(void) +{ + const char* img_mask_name = "img_mask.fits"; + const char* filtered_morpho_mask_name = "filtered_morpho_mask.fits"; + const char* filtered_average_mask_name = "filtered_average_mask.fits"; + const char* file_gauss_name = "gauss.fits"; + const char* filtered_gauss_data_name = "filtered_gauss_data.fits"; + const char* filtered_gauss_mask_name = "filtered_gauss_mask.fits"; + + + cpl_mask *img_mask = cpl_mask_new(200, 300); + + cpl_mask_set(img_mask, 50, 50, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 100, CPL_BINARY_1); + cpl_mask_set(img_mask, 150, 150, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 250, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 100, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 102, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 102, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 102, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 198, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 198, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 198, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 252, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 254, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 256, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 300, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 299, CPL_BINARY_1); + cpl_mask_set(img_mask, 199, 298, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 300, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 299, CPL_BINARY_1); + cpl_mask_set(img_mask, 200, 298, CPL_BINARY_1); + + cpl_mask_save(img_mask, "img_mask.fits", NULL, CPL_IO_CREATE); + + if(1){ + /* Set all pixels to bad, if there are a predefined number of bad + * pixels in the neighborhood - it uses the morpho filter which + * is much slower than e.g. the CPL_FILTER_AVERAGE_FAST filter */ + + cpl_matrix * kernel = cpl_matrix_new(3, 3); + cpl_matrix_fill(kernel, 1.0); + cpl_image * result_data = cpl_image_new_from_mask(img_mask); + + cpl_image * filtered_data = cpl_image_new( + cpl_image_get_size_x(result_data), + cpl_image_get_size_y(result_data), + CPL_TYPE_FLOAT); + + cpl_image_filter(filtered_data, result_data, kernel, + CPL_FILTER_MORPHO_SCALE, CPL_BORDER_FILTER); + + + cpl_mask * filtered_mask = cpl_mask_threshold_image_create( + filtered_data, 3.-0.5, DBL_MAX); + + cpl_mask_save(filtered_mask, filtered_morpho_mask_name, NULL, + CPL_IO_CREATE); + + cpl_mask_delete(filtered_mask); + cpl_image_delete(result_data); + cpl_image_delete(filtered_data); + cpl_matrix_delete(kernel); + + } + + if(1){ + /* Set all pixels to bad, if there are a predefined number of bad + * pixels in the neighborhood - it uses the CPL_FILTER_AVERAGE_FAST + * filter. This filter is fast but shrinks the window at the border. + * Therefore a simple scaling to the number of bad pixels in the + * neighborhood (nx * ny * average) can not be done at the image-border. + * Nevertheless one can never detect less, but only more neighboring + * bad pixels near the border (the bad pixel density increases at the + * border as the windows shrinks) - + * so it would be a conservative approach. + * + * */ + + cpl_mask * kernel = cpl_mask_new(3, 3); + cpl_mask_not(kernel); /* All values set to unity*/ + + + cpl_image * result_data = cpl_image_new_from_mask(img_mask); + + cpl_image * filtered_data = cpl_image_new( + cpl_image_get_size_x(result_data), + cpl_image_get_size_y(result_data), + CPL_TYPE_FLOAT); + + + + cpl_image_filter_mask(filtered_data, result_data, kernel, + CPL_FILTER_AVERAGE_FAST, CPL_BORDER_FILTER); + + + + cpl_mask * filtered_mask = cpl_mask_threshold_image_create( + filtered_data, (3.-0.5)/(3.*3.), DBL_MAX); + + + cpl_mask_save(filtered_mask, filtered_average_mask_name, NULL, CPL_IO_CREATE); + + cpl_mask_delete(filtered_mask); + cpl_image_delete(result_data); + cpl_image_delete(filtered_data); + cpl_mask_delete(kernel); + + } + + if(1){ + /* This algo first smoothed the bad pixels by a gaussian kernel and + * then one can use a threshold to detect new bad pixels on the + * smoothed image. Here it is difficult to find good parameters for the + * gaussian and the subsequent thresholding. + * */ + + double sig_x = 3.; /*Sigma in x for the gaussian distribution.*/ + double sig_y = 3.; /*Sigma in y for the gaussian distribution.*/ + + + /* creating the Gaussian kernel */ + cpl_size n = 5; + cpl_image * gauss = cpl_image_new(2 * n + 1, 2 * n + 1, CPL_TYPE_DOUBLE); + + cpl_image_fill_gaussian(gauss, n + 1, n + 1, (double)121.0, sig_x, sig_y); + + /* filtering the image */ + cpl_matrix * kernel = cpl_matrix_wrap(2 * n + 1, 2 * n + 1, + cpl_image_get_data_double(gauss)); + /*cpl_image_filter(im1, im2, gauss_data, CPL_FILTER_LINEAR, + CPL_BORDER_FILTER);*/ + + /*cpl_matrix * kernel = cpl_matrix_new(3, 3); + cpl_matrix_fill(kernel, 1.0);*/ + + cpl_image * result_data = cpl_image_new_from_mask(img_mask); + + cpl_image * filtered_data = cpl_image_new( + cpl_image_get_size_x(result_data), + cpl_image_get_size_y(result_data), + CPL_TYPE_DOUBLE); + + cpl_image_filter(filtered_data, result_data, kernel, + CPL_FILTER_LINEAR, CPL_BORDER_FILTER); + + + cpl_mask * filtered_mask = cpl_mask_threshold_image_create( + filtered_data, 3.-0.5, DBL_MAX); + + cpl_image_save(filtered_data, filtered_gauss_data_name, + CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE); + cpl_image_save(gauss, file_gauss_name, + CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE); + + cpl_mask_save(filtered_mask, filtered_gauss_mask_name, NULL, CPL_IO_CREATE); + + cpl_matrix_unwrap(kernel); + cpl_image_delete(gauss); + cpl_mask_delete(filtered_mask); + cpl_image_delete(result_data); + cpl_image_delete(filtered_data); + } + + /* free the memory */ + cpl_mask_delete(img_mask); + + /* Remove to disk */ + remove(img_mask_name); + remove(filtered_morpho_mask_name); + remove(filtered_average_mask_name); + remove(file_gauss_name); + remove(filtered_gauss_data_name); + remove(filtered_gauss_mask_name); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Can be used to test how to apply masks to imagelist + @return cpl_error_code + NOT TRIGGERED + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_bpm_test_apply_masks_to_imagelist(void) +{ + #define NUM_IMAGES 2 + + int nx = 64; + int ny = 64; + + + /* Create a imagelist */ + cpl_image *img = cpl_image_fill_test_create(nx, ny); + cpl_imagelist *list = cpl_imagelist_new(); + for (cpl_size i=0; i < NUM_IMAGES; i++) { + cpl_imagelist_set(list, cpl_image_duplicate(img), i); + } + cpl_image_delete(img); + + + /* join masks -> fill with a new allocated mask the vector*/ + cpl_mask *new_mask = cpl_mask_new(nx, ny); + cpl_mask **orig_masks; + hdrl_join_mask_on_imagelist(list, new_mask, &orig_masks); + cpl_mask_delete(new_mask); + + + /* restore original mask */ + hdrl_set_masks_on_imagelist(list, orig_masks); + + + /* free memory */ + cpl_imagelist_delete(list); + for (cpl_size i = 0; i < NUM_IMAGES; i++) { + cpl_mask_delete(orig_masks[i]); + } + cpl_free(orig_masks); + + return CPL_ERROR_NONE; +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of BPM module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_bpm_test_bpm_to_mask(); + hdrl_bpm_test_mask_to_bpm(); + hdrl_bpm_test_hdrl_bpm_filter(); + hdrl_bpm_test_bpmgrow() ; + hdrl_bpm_test_apply_masks_to_imagelist(); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_buffer-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_buffer-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_buffer-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_buffer-test.c 2017-09-20 13:52:02.000000000 +0000 @@ -0,0 +1,117 @@ +/* $Id: hdrl_buffer-test.c,v 1.1 2013-10-23 09:13:56 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-23 09:13:56 $ + * $Revision: 1.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112L +#endif +#include "hdrl_buffer.h" + +#include + +#include +#include + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_buffer_test + Testing of hdrl_buffer module + */ +/*----------------------------------------------------------------------------*/ + +cpl_error_code test_basic(void) +{ + hdrl_buffer *buf = hdrl_buffer_new(); + + hdrl_buffer_readonly(buf, CPL_TRUE); + hdrl_buffer_readonly(buf, CPL_FALSE); + + char * p2 = hdrl_buffer_allocate(buf, 10023); + memset(p2, 1, 10023); + + size_t size = hdrl_buffer_set_malloc_threshold(buf, sizeof(int)); + cpl_test_error(CPL_ERROR_NONE); + cpl_test(size == 0.); + + hdrl_buffer_readonly(buf, CPL_TRUE); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_buffer_readonly(buf, CPL_FALSE); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_buffer_free(buf, p2); + hdrl_buffer_delete(buf); + + cpl_msg_info(cpl_func, "test pool <= object"); + buf = hdrl_buffer_new(); + for (size_t i = 0; i < 100; i++) { + char * p = hdrl_buffer_allocate(buf, 1<<20); + memset(p, 1, 1<<20); + hdrl_buffer_free(buf, p); + } + hdrl_buffer_delete(buf); + + cpl_msg_info(cpl_func, "test pool > object"); + buf = hdrl_buffer_new(); + for (size_t i = 0; i < 1000; i++) { + char * p = hdrl_buffer_allocate(buf, 1<<18); + p[(1<<18) - 1] = 1; + hdrl_buffer_free(buf, p); + } + + hdrl_buffer_delete(NULL); + + hdrl_buffer_delete(buf); + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_basic(); + + setenv("HDRL_BUFFER_MALLOC", "1", 1); + test_basic(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_catalogue-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_catalogue-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_catalogue-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_catalogue-test.c 2017-10-13 09:59:32.000000000 +0000 @@ -0,0 +1,428 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_catalogue_test Testing of the HDRL catalogue + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_catalogue_compute() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_catalogue_test_compute(void) +{ + cpl_image * img, * cnf, * flat_img, * peak_img; + cpl_wcs * wcs; + hdrl_parameter * par; + hdrl_catalogue_result * r; + cpl_size nx = 1001, ny = 753; + + img = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cnf = cpl_image_new(nx, ny, CPL_TYPE_INT); + + /* Create a completely flat image with all pixels set to 1.0 */ + flat_img = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_test_nonnull(flat_img); + cpl_image_add_scalar(flat_img, 1.0); + cpl_test_error(CPL_ERROR_NONE); + + /* Create an image with all pixels set to 1.0 and a single sharp Gaussian + peak in the image at coordinate (100, 100). */ + peak_img = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_test_nonnull(peak_img); + cpl_image_fill_gaussian(peak_img, 100, 100, 1000.0, 1.0, 1.0); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_add_scalar(peak_img, 1.0); + cpl_test_error(CPL_ERROR_NONE); + + cpl_propertylist * pl = cpl_propertylist_new(); + cpl_propertylist_update_string(pl, "CTYPE1", "RA---TAN"); + cpl_propertylist_update_string(pl, "CTYPE2", "DEC--TAN"); + cpl_propertylist_update_double(pl, "CRVAL1", 30.0); + cpl_propertylist_update_double(pl, "CRVAL2", 12.0); + cpl_propertylist_update_double(pl, "CRPIX1", 512.0); + cpl_propertylist_update_double(pl, "CRPIX2", 512.0); + cpl_propertylist_update_double(pl, "CD1_1", -1.0 / 3600); + cpl_propertylist_update_double(pl, "CD1_2", 0.0); + cpl_propertylist_update_double(pl, "CD2_1", 0.0); + cpl_propertylist_update_double(pl, "CD2_2", 1.0 / 3600); + cpl_propertylist_update_int(pl, "NAXIS1", nx); + cpl_propertylist_update_int(pl, "NAXIS2", ny); + wcs = cpl_wcs_new_from_propertylist(pl); + cpl_propertylist_delete(pl); + + par = hdrl_catalogue_parameter_create(3, 2.5, CPL_FALSE, 3., CPL_TRUE, 64, + 2., 2.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_ALL); + + /* check null input errors */ + for (size_t i = 0; i < 2; i++) { + for (size_t j = 0; j < 2; j++) { + for (size_t k = 0; k < 2; k++) { + for (size_t l = 0; l < 2; l++) { + /* img and par are enough, rest optional */ + if (i && l) + continue; + r = hdrl_catalogue_compute(i ? img : NULL, + j ? cnf : NULL, + k ? wcs : NULL, + l ? par : NULL); + cpl_test_null(r); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_catalogue_result_delete(r); + } + } + } + } + + /* zero image */ + // TODO mem-leaks + //r = hdrl_catalogue_compute(img , NULL, NULL, par); + //cpl_test_null(r); + //cpl_test_error(CPL_ERROR_TODO); + + /* check basic object detection and results */ + hdrl_parameter_destroy(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_ALL); + cpl_image *bkg = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + double sigma = 2., sky = 500.; + double norm2 = 2.0 * CPL_MATH_PI * sigma * sigma; + cpl_image_add_scalar(cnf, 100.); + double xpos[] = {100.0,200.0,300.0,400.0,500.0,600.0,700.0,800.0,900.0, + 950.0}; + double ypos[] = {100.0,200.0,300.0,400.0,550.0,600.0,650.0,700.0,230.0, + 170.0}; + double norm[] = {1000.0,100.0,200.0,500.0,550.0,600.0,650.0,700.0, + 750.0,800.0}; + size_t nobj = sizeof(xpos) / sizeof(xpos[0]); + for (size_t i = 0; i < nobj; i++) { + cpl_image_fill_gaussian(bkg, xpos[i], ypos[i], norm[i] * norm2, sigma, + sigma); + cpl_image_add(img, bkg); + } + cpl_image_fill_noise_uniform(bkg, -10.0, 10.0); + cpl_image_add_scalar(bkg, sky); + cpl_image_add(img, bkg); + cpl_image_delete(bkg); + + r = hdrl_catalogue_compute(img , NULL, NULL, par); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(r->catalogue); + cpl_test_eq(cpl_table_get_nrow(r->catalogue), nobj); + cpl_test_nonnull(r->segmentation_map); + cpl_test_eq(cpl_image_get_max(r->segmentation_map), nobj); + cpl_test_eq(cpl_image_get_min(r->segmentation_map), 0); + cpl_test_nonnull(r->background); + cpl_test_abs(cpl_image_get_mean(r->background), sky, 5); + cpl_test_nonnull(r->qclist); + // TODO check required keys + hdrl_catalogue_result_delete(r); + + /* smoke test no background subtraction */ + hdrl_parameter * bpar = + hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_FALSE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_ALL); + cpl_image * imgcor = cpl_image_subtract_scalar_create(img, sky); + r = hdrl_catalogue_compute(imgcor, NULL, NULL, bpar); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(r->catalogue); + cpl_test_eq(cpl_table_get_nrow(r->catalogue), nobj); + cpl_test_nonnull(r->segmentation_map); + cpl_test_eq(cpl_image_get_max(r->segmentation_map), nobj); + cpl_test_eq(cpl_image_get_min(r->segmentation_map), 0); + cpl_test_null(r->background); + cpl_test_nonnull(r->qclist); + cpl_image_delete(imgcor); + hdrl_parameter_delete(bpar); + hdrl_catalogue_result_delete(r); + + /* test too big nbsize */ + bpar = hdrl_catalogue_parameter_create(3, 2.5, CPL_FALSE, 3., CPL_TRUE, + nx + 23, 2., 2.0, + HDRL_SATURATION_INIT, + HDRL_CATALOGUE_ALL); + + /* Check parameter */ + cpl_test(hdrl_catalogue_parameter_check(bpar)); + + + /* Change option */ + hdrl_catalogue_parameter_set_option(NULL, HDRL_CATALOGUE_ALL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_catalogue_parameter_set_option(bpar, HDRL_CATALOGUE_BKG); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_catalogue_parameter_set_option(bpar, HDRL_CATALOGUE_ALL); + cpl_test_error(CPL_ERROR_NONE); + + + /* Create ParameterList */ + cpl_parameterlist *plCat; + + plCat = hdrl_catalogue_parameter_create_parlist(NULL, "catalogue", bpar); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plCat); + + plCat = hdrl_catalogue_parameter_create_parlist("test", NULL, bpar); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plCat); + + plCat = hdrl_catalogue_parameter_create_parlist("test", "catalogue", NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plCat); + + plCat = hdrl_catalogue_parameter_create_parlist("test", "catalogue", bpar); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plCat); + + + /* Parse ParameterList */ + hdrl_parameter *check; + + check = hdrl_catalogue_parameter_parse_parlist(NULL, "test.catalogue"); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(check); + + check = hdrl_catalogue_parameter_parse_parlist(plCat, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(check); + + check = hdrl_catalogue_parameter_parse_parlist(plCat, "test.catalogue"); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(check); + + + cpl_parameterlist_delete(plCat); + hdrl_parameter_delete(check); + + + + /* Compute */ + r = hdrl_catalogue_compute(img , NULL, NULL, bpar); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + hdrl_parameter_delete(bpar); + + /* test bad confidence */ + cpl_image_subtract_scalar(cnf, 200); + r = hdrl_catalogue_compute(img , cnf, NULL, par); + cpl_test_null(r); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_image_add_scalar(cnf, 200); + + /* test double confidence */ + cpl_image * dcnf = cpl_image_cast(cnf, CPL_TYPE_DOUBLE); + r = hdrl_catalogue_compute(img , dcnf, NULL, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* smoketest image with bad pixels */ + cpl_image_reject(img, 60, 23); + r = hdrl_catalogue_compute(img , NULL, NULL, par); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* smoketest image with bad pixels and confidence */ + r = hdrl_catalogue_compute(img , cnf, NULL, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* smoketest image with bad pixels and double confidence */ + r = hdrl_catalogue_compute(img , dcnf, NULL, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + cpl_image_delete(dcnf); + + /* smoketest image and confidence */ + cpl_image_accept_all(img); + r = hdrl_catalogue_compute(img , cnf, NULL, par); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* smoketest image, confidence and wcs */ + cpl_image_accept_all(img); + r = hdrl_catalogue_compute(img , cnf, wcs, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* smoketest double image, confidence and wcs */ + cpl_image * dimg = cpl_image_cast(img, CPL_TYPE_DOUBLE); + cpl_image_accept_all(img); + r = hdrl_catalogue_compute(dimg , cnf, wcs, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(dimg); + hdrl_catalogue_result_delete(r); + + /* test no segmap and background */ + hdrl_parameter_delete(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_CAT_COMPLETE); + r = hdrl_catalogue_compute(img , cnf, wcs, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_null(r->segmentation_map); + cpl_test_null(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* test no segmap */ + hdrl_parameter_delete(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_CAT_COMPLETE | + HDRL_CATALOGUE_BKG); + r = hdrl_catalogue_compute(img , cnf, wcs, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_null(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* test no background */ + hdrl_parameter_delete(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_CAT_COMPLETE | + HDRL_CATALOGUE_SEGMAP); + r = hdrl_catalogue_compute(img , cnf, wcs, par); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_null(r->background); + hdrl_catalogue_result_delete(r); + + /* test no catalogue */ + hdrl_parameter_delete(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_SEGMAP | + HDRL_CATALOGUE_BKG); + r = hdrl_catalogue_compute(img , cnf, wcs, par); + cpl_test_nonnull(r); + cpl_test_nonnull(r->catalogue); + cpl_test_eq(cpl_table_get_nrow(r->catalogue), 0); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + cpl_test_error(CPL_ERROR_NONE); + hdrl_catalogue_result_delete(r); + + /* Test pathological case with a completely flat image. */ + hdrl_parameter_delete(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_CAT_COMPLETE | + HDRL_CATALOGUE_SEGMAP | + HDRL_CATALOGUE_BKG); + cpl_test_nonnull(par); + r = hdrl_catalogue_compute(flat_img , NULL, NULL, par); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + cpl_test_nonnull(r); + hdrl_catalogue_result_delete(r); + + /* Test pathological case with a single sharp peak in the image. */ + hdrl_parameter_delete(par); + par = hdrl_catalogue_parameter_create(5, 1.5, CPL_FALSE, 5., CPL_TRUE, 64, + 3., 1.0, HDRL_SATURATION_INIT, + HDRL_CATALOGUE_CAT_COMPLETE | + HDRL_CATALOGUE_SEGMAP | + HDRL_CATALOGUE_BKG); + cpl_test_nonnull(par); + r = hdrl_catalogue_compute(peak_img , NULL, NULL, par); + cpl_test_nonnull(r); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(r->catalogue); + cpl_test_nonnull(r->segmentation_map); + cpl_test_nonnull(r->background); + hdrl_catalogue_result_delete(r); + + cpl_image_delete(flat_img); + cpl_image_delete(peak_img); + cpl_image_delete(img); + cpl_image_delete(cnf); + cpl_wcs_delete(wcs); + hdrl_parameter_delete(par); + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of catalogue module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_catalogue_test_compute(); + cpl_test_error(CPL_ERROR_NONE); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_collapse-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_collapse-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_collapse-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_collapse-test.c 2017-09-19 14:35:18.000000000 +0000 @@ -0,0 +1,806 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_combine.h" +#include "hdrl_types.h" + +#include + +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_collapse_test Testing of the HDRL reduce module + */ +/*----------------------------------------------------------------------------*/ +typedef struct { + double v1; + double v2; +} pair; + +/* cpl_test_abs that handles nan, rej is the rej variable of cpl_image_get to + * test if NAN is marked as a bad pixel or -1 if not applicable */ +#define hdrl_test_abs(a, b, tol, rej) \ + if (isnan(a)) { \ + cpl_test_eq(isnan(a), isnan(b)); \ + cpl_test(rej == -1 || rej != 0); \ + } \ + else { \ + cpl_test_abs(a, b, tol); \ + } + + +/* cpl_image_get that really returns the value regardless of bad or not */ +static double +_hdrl_image_get(cpl_image * img, cpl_size x, cpl_size y, int * rej) +{ + double v = cpl_image_get(img, x, y, rej); + if (*rej) { + size_t nx = cpl_image_get_size_x(img); + v = cpl_image_get_data_double(img)[(y - 1) * nx + (x - 1)]; + } + return v; +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief convert list to image format to list to vector format + * + * @param data image + * @param errs errors + * @param x x coordinate to extract (FITS) + * @param y y coordinate to extract (FITS) + * @param vl imagelist to put new data list into + * @param el imagelist to put new error list into + */ +/* ---------------------------------------------------------------------------*/ +static void +prep_l2v_input(cpl_imagelist * data, + cpl_imagelist * errs, + cpl_size x, + cpl_size y, + cpl_imagelist * vl, + cpl_imagelist * el) +{ + int d; + size_t n = cpl_imagelist_get_size(data); + cpl_image * vimg = cpl_image_new(1, n, HDRL_TYPE_DATA); + cpl_image * verr = cpl_image_new(1, n, HDRL_TYPE_ERROR); + for (size_t i = 0; i < n; i++) { + cpl_image * img = cpl_imagelist_get(data, i); + cpl_image_set(vimg, 1, i + 1, cpl_image_get(img, x, y, &d)); + if (d) { + cpl_image_reject(vimg, 1, i + 1); + } + img = cpl_imagelist_get(errs, i); + cpl_image_set(verr, 1, i + 1, cpl_image_get(img, x, y, &d)); + if (d) { + cpl_image_reject(verr, 1, i + 1); + } + } + cpl_imagelist_set(vl, vimg, 0); + cpl_imagelist_set(el, verr, 0); +} + + +/* ---------------------------------------------------------------------------*/ +/** + * @brief test list to image and list to vector collapses + * + * @param data data for list to image + * @param errs errors for list to image + * @param l2im list to image reduction method + * @param l2vm list to vector reduction method + * @param x x coordinate to extract for l2v (FITS) + * @param y y coordinate to extract for l2v (FITS) + * @param v value tolerance pair for expected data result at x, y + * @param e value tolerance pair for expected error result at x, y + * @param expcontrib expected contribution map + */ +/* ---------------------------------------------------------------------------*/ +void test_l2i_and_l2v(cpl_imagelist * data, + cpl_imagelist * errs, + hdrl_collapse_imagelist_to_image_t * l2im, + hdrl_collapse_imagelist_to_vector_t * l2vm, + cpl_size x, + cpl_size y, + pair v, + pair e, + cpl_image * expcontrib) +{ + int d; + /* test list to image */ + cpl_image * outimg, *outerr, *contrib; + hdrl_imagelist_combine(data, errs, l2im, &outimg, &outerr, &contrib); + + hdrl_test_abs(_hdrl_image_get(outimg, x, y, &d), v.v1, v.v2, d); + hdrl_test_abs(_hdrl_image_get(outerr, x, y, &d), e.v1, e.v2, d); + cpl_test_image_abs(contrib, expcontrib, 0); + cpl_image_delete(outimg); + cpl_image_delete(outerr); + cpl_image_delete(contrib); + + /* map the list to image input into a list to vector input that should give + * the same result */ + cpl_imagelist * vl = cpl_imagelist_new(); + cpl_imagelist * el = cpl_imagelist_new(); + prep_l2v_input(data, errs, x, y, vl, el); + + /* test list to vector */ + cpl_vector * voutimg, *vouterr; + cpl_array * acontrib; + hdrl_collapse_imagelist_to_vector_call(l2vm, vl, el, + &voutimg, &vouterr, &acontrib, + NULL); + cpl_imagelist_delete(vl); + cpl_imagelist_delete(el); + + hdrl_test_abs(cpl_vector_get(voutimg, 0), v.v1, v.v2, -1); + hdrl_test_abs(cpl_vector_get(vouterr, 0), e.v1, e.v2, -1); + + cpl_test_abs(cpl_array_get_int(acontrib, 0, NULL), + cpl_image_get(expcontrib, x, y, &d), 0); + + cpl_vector_delete(voutimg); + cpl_vector_delete(vouterr); + cpl_array_delete(acontrib); + hdrl_collapse_imagelist_to_image_delete(l2im); + hdrl_collapse_imagelist_to_vector_delete(l2vm); +} + +void test_parameters(void) +{ + hdrl_parameter * hpar = hdrl_collapse_mean_parameter_create(); + cpl_test(hdrl_collapse_parameter_is_mean(hpar)); + hdrl_parameter_delete(hpar); + hpar = hdrl_collapse_median_parameter_create(); + cpl_test(hdrl_collapse_parameter_is_median(hpar)); + hdrl_parameter_delete(hpar); + hpar = hdrl_collapse_weighted_mean_parameter_create(); + cpl_test(hdrl_collapse_parameter_is_weighted_mean(hpar)); + hdrl_parameter_delete(hpar); + + cpl_test(hdrl_collapse_parameter_is_mean(HDRL_COLLAPSE_MEAN)); + cpl_test(!hdrl_collapse_parameter_is_mean(HDRL_COLLAPSE_MEDIAN)); + hdrl_parameter_delete((hdrl_parameter*)HDRL_COLLAPSE_MEAN); + + cpl_test(hdrl_collapse_parameter_is_median(HDRL_COLLAPSE_MEDIAN)); + hdrl_parameter_delete((hdrl_parameter*)HDRL_COLLAPSE_MEDIAN); + + cpl_test(hdrl_collapse_parameter_is_weighted_mean( + HDRL_COLLAPSE_WEIGHTED_MEAN)); + hdrl_parameter_delete((hdrl_parameter*)HDRL_COLLAPSE_WEIGHTED_MEAN); +} + + +void test_parlist(void) +{ + /* parameter parsing smoketest */ + hdrl_parameter * hpar; + hdrl_parameter * sigclip_def = + hdrl_collapse_sigclip_parameter_create(1., 2., 5); + hdrl_parameter * minmax_def = + hdrl_collapse_minmax_parameter_create(1., 1.); + + cpl_parameterlist *parlist = hdrl_collapse_parameter_create_parlist( + "RECIPE", "collapse", "UNKNOWN", sigclip_def, minmax_def) ; + cpl_test_error(CPL_ERROR_NONE); + + cpl_parameterlist *parlist1 = hdrl_collapse_parameter_create_parlist( + "RECIPE", "collapse", "MEAN", sigclip_def, minmax_def) ; + cpl_test_error(CPL_ERROR_NONE); + + cpl_parameterlist *parlist2 = hdrl_collapse_parameter_create_parlist( + "RECIPE", "collapse", "WEIGHTED_MEAN", sigclip_def, minmax_def) ; + cpl_test_error(CPL_ERROR_NONE); + + cpl_parameterlist *parlist3 = hdrl_collapse_parameter_create_parlist( + "RECIPE", "collapse", "MEDIAN", sigclip_def, minmax_def) ; + cpl_test_error(CPL_ERROR_NONE); + + cpl_parameterlist *parlist4 = hdrl_collapse_parameter_create_parlist( + "RECIPE", "collapse", "SIGCLIP", sigclip_def, minmax_def) ; + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(parlist4), 6); + + hdrl_parameter_delete(sigclip_def); + hdrl_parameter_delete(minmax_def); + + + /* UNKNOWN */ +/* hpar = hdrl_collapse_parameter_parse_parlist(parlist, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + hpar = hdrl_collapse_parameter_parse_parlist(parlist, "RECIPE.collapse"); + cpl_test_error(CPL_ERROR_NONE); + hdrl_parameter_delete(hpar); +*/ + /* MEAN */ + hpar = hdrl_collapse_parameter_parse_parlist(parlist1, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + hpar = hdrl_collapse_parameter_parse_parlist(parlist1, "RECIPE.collapse"); + cpl_test_error(CPL_ERROR_NONE); + hdrl_parameter_delete(hpar); + + + /* WEIGHTED_MEAN */ + hpar = hdrl_collapse_parameter_parse_parlist(parlist2, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + hpar = hdrl_collapse_parameter_parse_parlist(parlist2, "RECIPE.collapse"); + cpl_test_error(CPL_ERROR_NONE); + hdrl_parameter_delete(hpar); + + + /* MEDIAN */ + hpar = hdrl_collapse_parameter_parse_parlist(parlist3, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + hpar = hdrl_collapse_parameter_parse_parlist(parlist3, "RECIPE.collapse"); + cpl_test_error(CPL_ERROR_NONE); + hdrl_parameter_delete(hpar); + + + /* SIGCLIP */ + hpar = hdrl_collapse_parameter_parse_parlist(parlist4, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + hpar = hdrl_collapse_parameter_parse_parlist(parlist4, "RECIPE.collapse"); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test(hdrl_collapse_parameter_is_sigclip(hpar)); + cpl_test(!hdrl_collapse_parameter_is_median(hpar)); + cpl_test_eq(hdrl_collapse_sigclip_parameter_get_kappa_high(hpar), 2.); + cpl_test_eq(hdrl_collapse_sigclip_parameter_get_kappa_low(hpar), 1.); + cpl_test_eq(hdrl_collapse_sigclip_parameter_get_niter(hpar), 5); + + hdrl_parameter_delete(hpar); + + + /* Clean up */ + cpl_parameterlist_delete(parlist ); + cpl_parameterlist_delete(parlist1); + cpl_parameterlist_delete(parlist2); + cpl_parameterlist_delete(parlist3); + cpl_parameterlist_delete(parlist4); + + + hpar = hdrl_collapse_mean_parameter_create(); + cpl_test(hdrl_collapse_parameter_is_mean(hpar)); + hdrl_parameter_delete(hpar); + hpar = hdrl_collapse_median_parameter_create(); + cpl_test(hdrl_collapse_parameter_is_median(hpar)); + hdrl_parameter_delete(hpar); + hpar = hdrl_collapse_weighted_mean_parameter_create(); + cpl_test(hdrl_collapse_parameter_is_weighted_mean(hpar)); + hdrl_parameter_delete(hpar); +} + + +void test_eout(void) +{ + cpl_size n = 40; + + + /* Method with vector mean */ + hdrl_collapse_imagelist_to_vector_t * vMethod1; + vMethod1 = hdrl_collapse_imagelist_to_vector_mean(); + + void *eout1 = hdrl_collapse_imagelist_to_vector_create_eout(vMethod1, n); + + void *eout2 = NULL; + hdrl_collapse_imagelist_to_vector_move_eout(vMethod1, eout1, eout2, n); + + hdrl_collapse_imagelist_to_vector_delete_eout(vMethod1, eout2); + hdrl_collapse_imagelist_to_vector_delete_eout(vMethod1, eout1); + hdrl_collapse_imagelist_to_vector_delete(vMethod1); + + + /* Method with vector minmax */ + hdrl_collapse_imagelist_to_vector_t *vMethod2; + vMethod2 = hdrl_collapse_imagelist_to_vector_minmax(3., 3.); + + void *eout3 = hdrl_collapse_imagelist_to_vector_create_eout(vMethod2, n); + + hdrl_collapse_imagelist_to_vector_delete_eout(vMethod2, eout3); + hdrl_collapse_imagelist_to_vector_delete(vMethod2); + + + /* Method with vector sigclip */ + hdrl_collapse_imagelist_to_vector_t *vMethod3; + vMethod3 = hdrl_collapse_imagelist_to_vector_sigclip(3., 3., 3); + + void *eout4 = hdrl_collapse_imagelist_to_vector_create_eout(vMethod3, n); + void *eout5 = hdrl_collapse_imagelist_to_vector_create_eout(vMethod3, n); + + hdrl_collapse_imagelist_to_vector_move_eout(vMethod3, NULL, eout5, n); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_collapse_imagelist_to_vector_move_eout(vMethod3, eout4, NULL, n); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_collapse_imagelist_to_vector_move_eout(vMethod3, eout4, eout4, n); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + hdrl_collapse_imagelist_to_vector_move_eout(vMethod3, eout4, eout5, n); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + hdrl_collapse_imagelist_to_vector_move_eout(vMethod3, eout5, eout4, n); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + hdrl_collapse_imagelist_to_vector_move_eout(vMethod3, eout5, eout5, n); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + + hdrl_collapse_imagelist_to_vector_delete_eout(vMethod3, eout4); + hdrl_collapse_imagelist_to_vector_delete_eout(vMethod3, eout5); + hdrl_collapse_imagelist_to_vector_delete(vMethod3); + + + /* Method with image */ + hdrl_collapse_imagelist_to_image_t *vMethod4; + vMethod4 = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + + cpl_image *img = cpl_image_new(10, 10, CPL_TYPE_DOUBLE); + void *eout6 = hdrl_collapse_imagelist_to_image_create_eout(vMethod4, img); + cpl_image_delete(img); + + hdrl_collapse_imagelist_to_image_delete_eout(vMethod4, eout6); + hdrl_collapse_imagelist_to_image_delete(vMethod4); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of reduce module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_parameters(); + test_parlist(); + test_eout(); + +#define TST_FREE \ + cpl_image_delete(outimg); outimg = NULL; \ + cpl_image_delete(outerr); outerr = NULL; \ + cpl_image_delete(contrib); contrib = NULL; \ + cpl_vector_delete(voutimg); voutimg = NULL; \ + cpl_vector_delete(vouterr); vouterr = NULL; \ + cpl_array_delete(acontrib); acontrib = NULL; \ + hdrl_collapse_imagelist_to_image_delete(method); + + /* create data, value 5., error +-1 */ + cpl_imagelist * data = cpl_imagelist_new(); + cpl_imagelist * errs = cpl_imagelist_new(); + cpl_size nz = 5; + cpl_size nx = 40; + cpl_size ny = 37; + cpl_image * img = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_image * err = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img, 5.); + cpl_image_add_scalar(err, 2.); + + /* create expected results (err / sqrt(nz) for mean) */ + cpl_image * expect_err = cpl_image_duplicate(err); + cpl_image_divide_scalar(expect_err, sqrt(nz)); + cpl_image * expect_contrib = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_image_add_scalar(expect_contrib, nz); + for (cpl_size i = 0; i < nz; i++) { + cpl_imagelist_set(data, cpl_image_duplicate(img), + cpl_imagelist_get_size(data)); + cpl_imagelist_set(errs, cpl_image_duplicate(err), + cpl_imagelist_get_size(errs)); + } + cpl_image * outimg, * outerr, * contrib; + + cpl_vector * expect_vimg = cpl_vector_new(nz); + cpl_vector * expect_verr = cpl_vector_new(nz); + cpl_array * expect_acontrib = cpl_array_new(nz, CPL_TYPE_INT); + cpl_vector * voutimg, * vouterr; + cpl_array * acontrib; + cpl_vector_fill(expect_vimg, 5.); + cpl_vector_fill(expect_verr, 2. / sqrt(nx * ny)); + cpl_array_fill_window_int(expect_acontrib, 0, nz, nx * ny); + + /* test reductions on uniform error cases */ + { + /* mean */ + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_collapse_imagelist_to_image_call(method, data, errs, + &outimg, &outerr, &contrib, + NULL); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_mean(); + hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs, + &voutimg, &vouterr, &acontrib, + NULL); + cpl_test_vector_abs(voutimg, expect_vimg, HDRL_EPS_DATA); + cpl_test_vector_abs(vouterr, expect_verr, HDRL_EPS_ERROR); + cpl_test_array_abs(acontrib, expect_acontrib, 0); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + TST_FREE; + + /* sigclip */ + method = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + hdrl_collapse_imagelist_to_image_call(method, data, errs, + &outimg, &outerr, &contrib, + NULL); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + + + vmethod = hdrl_collapse_imagelist_to_vector_sigclip(3., 3., 3); + hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs, + &voutimg, &vouterr, &acontrib, + NULL); + cpl_test_vector_abs(voutimg, expect_vimg, HDRL_EPS_DATA); + cpl_test_vector_abs(vouterr, expect_verr, HDRL_EPS_ERROR); + cpl_test_array_abs(acontrib, expect_acontrib, 0); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + TST_FREE; + + /* minmax */ + method = hdrl_collapse_imagelist_to_image_minmax(0., 0.); + hdrl_collapse_imagelist_to_image_call(method, data, errs, + &outimg, &outerr, &contrib, + NULL); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + + + vmethod = hdrl_collapse_imagelist_to_vector_minmax(0., 0.); + hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs, + &voutimg, &vouterr, &acontrib, + NULL); + cpl_test_vector_abs(voutimg, expect_vimg, HDRL_EPS_DATA); + cpl_test_vector_abs(vouterr, expect_verr, HDRL_EPS_ERROR); + cpl_test_array_abs(acontrib, expect_acontrib, 0); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + TST_FREE; + + /* weighted mean */ + method = hdrl_collapse_imagelist_to_image_weighted_mean(); + hdrl_collapse_imagelist_to_image_call(method, data, errs, + &outimg, &outerr, &contrib, + NULL); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + /* median */ + cpl_image_multiply_scalar(expect_err, sqrt(CPL_MATH_PI_2)); + method = hdrl_collapse_imagelist_to_image_median(); + hdrl_collapse_imagelist_to_image_call(method, data, errs, + &outimg, &outerr, &contrib, + NULL); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + + cpl_vector_multiply_scalar(expect_verr, sqrt(CPL_MATH_PI_2)); + vmethod = hdrl_collapse_imagelist_to_vector_median(); + hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs, + &voutimg, &vouterr, &acontrib, + NULL); + cpl_test_vector_abs(voutimg, expect_vimg, HDRL_EPS_DATA); + cpl_test_vector_abs(vouterr, expect_verr, HDRL_EPS_ERROR); + cpl_test_array_abs(acontrib, expect_acontrib, 0); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + TST_FREE; + } + /* test non uniform error cases */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {0.5, 0.7, 0.1, 1.0, 0.01}; + for (cpl_size i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + } + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_mean(); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){1.8, HDRL_EPS_DATA}, + (pair){0.26458269028793246, HDRL_EPS_ERROR}, + expect_contrib); + + method = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + vmethod = hdrl_collapse_imagelist_to_vector_sigclip(3., 3., 3); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){1.8, HDRL_EPS_DATA}, + (pair){0.26458269028793246, HDRL_EPS_ERROR}, + expect_contrib); + + method = hdrl_collapse_imagelist_to_image_minmax(1, 1); + vmethod = hdrl_collapse_imagelist_to_vector_minmax(1, 1); + cpl_image * expect_contrib_minmax = + cpl_image_subtract_scalar_create(expect_contrib, 2); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){5. / 3., HDRL_EPS_DATA}, + (pair){sqrt(0.1 * 0.1 + 0.7 * 0.7 + 0.01 * 0.01) / 3., + HDRL_EPS_ERROR}, + expect_contrib_minmax); + cpl_image_delete(expect_contrib_minmax); + + method = hdrl_collapse_imagelist_to_image_weighted_mean(); + vmethod = hdrl_collapse_imagelist_to_vector_weighted_mean(); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){1.9898090843925733, HDRL_EPS_ERROR}, + (pair){0.0099469054598625289, HDRL_EPS_ERROR}, + expect_contrib); + } + /* test non uniform error cases with rejected values */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {0.5, 0.7, 0.1, 1.0, 0.01}; + for (cpl_size i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + if (i == 3) { + cpl_image_reject(tmp, 1, 1); + } + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + if (i == 3) { + cpl_image_reject(tmp, 1, 1); + } + } + cpl_image_delete(expect_contrib); + expect_contrib = cpl_image_new_from_accepted(data); + + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_mean(); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){1.5, HDRL_EPS_DATA}, + (pair){0.21652078422174625, HDRL_EPS_ERROR}, + expect_contrib); + + method = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + vmethod = hdrl_collapse_imagelist_to_vector_sigclip(3., 3., 3); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){1.5, HDRL_EPS_DATA}, + (pair){0.21652078422174625, HDRL_EPS_ERROR}, + expect_contrib); + + method = hdrl_collapse_imagelist_to_image_minmax(1, 1); + vmethod = hdrl_collapse_imagelist_to_vector_minmax(1, 1); + cpl_image * expect_contrib_minmax = + cpl_image_subtract_scalar_create(expect_contrib, 2); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){3. / 2., HDRL_EPS_DATA}, + (pair){sqrt(0.1 * 0.1 + 0.01 * 0.01) / 2., + HDRL_EPS_ERROR}, + expect_contrib_minmax); + cpl_image_delete(expect_contrib_minmax); + + method = hdrl_collapse_imagelist_to_image_weighted_mean(); + vmethod = hdrl_collapse_imagelist_to_vector_weighted_mean(); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){1.9897091252756485, HDRL_EPS_ERROR}, + (pair){0.0099473975744101273, HDRL_EPS_ERROR}, + expect_contrib); + } + /* test all values rejected in line, list to image */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {0.5, 0.7, 0.1, 1.0, 0.01}; + for (cpl_size i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + cpl_image_reject(tmp, 1, 1); + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + cpl_image_reject(tmp, 1, 1); + } + cpl_image_delete(expect_contrib); + expect_contrib = cpl_image_new_from_accepted(data); + + hdrl_collapse_imagelist_to_image_t * img_meth[] = { + hdrl_collapse_imagelist_to_image_mean(), + hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3), + hdrl_collapse_imagelist_to_image_weighted_mean(), + hdrl_collapse_imagelist_to_image_median(), + }; + hdrl_collapse_imagelist_to_vector_t * vec_meth[] = { + hdrl_collapse_imagelist_to_vector_mean(), + hdrl_collapse_imagelist_to_vector_sigclip(3., 3., 3), + hdrl_collapse_imagelist_to_vector_weighted_mean(), + hdrl_collapse_imagelist_to_vector_median(), + }; + + for (size_t i = 0; i < ARRAY_LEN(img_meth); i++) { + test_l2i_and_l2v(data, errs, img_meth[i], vec_meth[i], 1, 1, + (pair){NAN, HDRL_EPS_DATA}, + (pair){NAN, HDRL_EPS_ERROR}, + expect_contrib); + } + + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_minmax(1., 1.); + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_minmax(1., 1.); + cpl_image * expect_contrib_minmax = + cpl_image_subtract_scalar_create(expect_contrib, 2); + cpl_image_set(expect_contrib_minmax, 1, 1, 0); + test_l2i_and_l2v(data, errs, method, vmethod, 1, 1, + (pair){NAN, HDRL_EPS_DATA}, + (pair){NAN, HDRL_EPS_ERROR}, + expect_contrib_minmax); + cpl_image_delete(expect_contrib_minmax); + } + /* test all values rejected, list to image */ + { + for (cpl_size i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_accept_all(tmp); + cpl_mask_not(cpl_image_get_bpm(tmp)); + } + cpl_image_delete(expect_contrib); + expect_contrib = cpl_image_new_from_accepted(data); + + hdrl_collapse_imagelist_to_image_t * img_meth[] = { + hdrl_collapse_imagelist_to_image_mean(), + hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3), + hdrl_collapse_imagelist_to_image_weighted_mean(), + hdrl_collapse_imagelist_to_image_median(), + hdrl_collapse_imagelist_to_image_minmax(1., 1.), + }; + hdrl_collapse_imagelist_to_vector_t * vec_meth[] = { + hdrl_collapse_imagelist_to_vector_mean(), + hdrl_collapse_imagelist_to_vector_sigclip(3., 3., 3), + hdrl_collapse_imagelist_to_vector_weighted_mean(), + hdrl_collapse_imagelist_to_vector_median(), + hdrl_collapse_imagelist_to_vector_minmax(1., 1.), + }; + + for (size_t i = 0; i < ARRAY_LEN(img_meth); i++) { + cpl_image * outimg_loc, *outerr_loc, *contrib_loc; + hdrl_imagelist_combine(data, errs, img_meth[i], &outimg_loc, &outerr_loc, &contrib_loc); + /* unlike cpl, don't emit error */ + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_image_abs(contrib_loc, expect_contrib, 0); + cpl_test_eq(cpl_image_count_rejected(outimg_loc), nx *ny); + cpl_test_eq(cpl_image_count_rejected(outerr_loc), nx *ny); + cpl_image_delete(outimg_loc); + cpl_image_delete(outerr_loc); + cpl_image_delete(contrib_loc); + + /* also check vector variant */ + test_l2i_and_l2v(data, errs, img_meth[i], vec_meth[i], 1, 1, + (pair){NAN, HDRL_EPS_DATA}, + (pair){NAN, HDRL_EPS_ERROR}, + expect_contrib); + cpl_test_error(CPL_ERROR_NONE); + } + } + /* test median error propagation with rejects, only makes sense on uniform + * errors as the scaling relies on gaussian errors */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {1., 1., 1., 1., 1.}; + int d; + for (cpl_size i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + cpl_image_set(tmp, 2, 2, v[i]); + if (i > 1) { + cpl_image_reject(tmp, 1, 1); + } + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + cpl_image_set(tmp, 2, 2, e[i]); + if (i > 1) { + cpl_image_reject(tmp, 1, 1); + } + } + cpl_image_delete(expect_contrib); + expect_contrib = cpl_image_new_from_accepted(data); + + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_median(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + /* contrib > 2 -> sqrt(nz * pi / 2) error scaling */ + cpl_test_abs(cpl_image_get(outimg, 2, 2, &d), 2., HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 2, 2, &d), + 1. / sqrt(nz) * sqrt(CPL_MATH_PI_2), HDRL_EPS_ERROR); + /* contrib <= 2 -> median is a mean, no scaling */ + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.5, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 1. / sqrt(2.), HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + + cpl_imagelist * vl = cpl_imagelist_new(); + cpl_imagelist * el = cpl_imagelist_new(); + prep_l2v_input(data, errs, 1, 1, vl, el); + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_median(); + hdrl_collapse_imagelist_to_vector_call(vmethod, vl, el, + &voutimg, &vouterr, &acontrib, + NULL); + + cpl_test_abs(cpl_vector_get(voutimg, 0), 1.5, HDRL_EPS_DATA); + cpl_test_abs(cpl_vector_get(vouterr, 0), 1. / sqrt(2.), HDRL_EPS_ERROR); + + cpl_test_abs(cpl_array_get_int(acontrib, 0, NULL), 2, 0); + cpl_vector_delete(voutimg); + cpl_vector_delete(vouterr); + cpl_array_delete(acontrib); + cpl_imagelist_empty(vl); + cpl_imagelist_empty(el); + + prep_l2v_input(data, errs, 2, 2, vl, el); + hdrl_collapse_imagelist_to_vector_call(vmethod, vl, el, + &voutimg, &vouterr, &acontrib, + NULL); + + cpl_test_abs(cpl_vector_get(voutimg, 0), 2., HDRL_EPS_DATA); + cpl_test_abs(cpl_vector_get(vouterr, 0), + 1. / sqrt(nz) * sqrt(CPL_MATH_PI_2), HDRL_EPS_ERROR); + + cpl_test_abs(cpl_array_get_int(acontrib, 0, NULL), 5, 0); + cpl_imagelist_delete(vl); + cpl_imagelist_delete(el); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + + TST_FREE; + } + + cpl_imagelist_delete(data); + cpl_imagelist_delete(errs); + cpl_image_delete(expect_err); + cpl_image_delete(expect_contrib); + cpl_image_delete(img); + cpl_image_delete(err); + cpl_vector_delete(expect_vimg); + cpl_vector_delete(expect_verr); + cpl_array_delete(expect_acontrib); + + return cpl_test_end(0); +#undef TST_FREE +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_combine-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_combine-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_combine-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_combine-test.c 2014-09-05 06:47:56.000000000 +0000 @@ -0,0 +1,333 @@ +/* $Id: hdrl_combine-test.c,v 1.7 2013-09-24 14:58:54 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-09-24 14:58:54 $ + * $Revision: 1.7 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_combine.h" +#include + +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_combine_test Testing of the HDRL combine module + */ +/*----------------------------------------------------------------------------*/ + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of combine module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + +#define TST_FREE \ + cpl_image_delete(outimg); \ + cpl_image_delete(outerr); \ + cpl_image_delete(contrib); \ + hdrl_collapse_imagelist_to_image_delete(method); + + /* create data, value 5., error +-1 */ + cpl_imagelist * data = cpl_imagelist_new(); + cpl_imagelist * errs = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(40, 40, CPL_TYPE_DOUBLE); + cpl_image * err = cpl_image_new(40, 40, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img, 5.); + cpl_image_add_scalar(err, 2.); + size_t nz = 5; + + /* create expected results (err / sqrt(nz) for mean) */ + cpl_image * expect_err = cpl_image_duplicate(err); + cpl_image_divide_scalar(expect_err, sqrt(nz)); + cpl_image * expect_contrib = cpl_image_new(40, 40, CPL_TYPE_INT); + cpl_image_add_scalar(expect_contrib, 5); + for (size_t i = 0; i < nz; i++) { + cpl_imagelist_set(data, cpl_image_duplicate(img), cpl_imagelist_get_size(data)); + cpl_imagelist_set(errs, cpl_image_duplicate(err), cpl_imagelist_get_size(errs)); + } + cpl_image * outimg, * outerr, * contrib; + + /* test inputs */ + { + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_imagelist_combine(data, errs, method, &outimg, NULL, &contrib); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_imagelist_combine(data, errs, method, NULL, &outerr, &contrib); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_imagelist_combine(data, errs, NULL, &outimg, &outerr, &contrib); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_imagelist_combine(data, NULL, method, &outimg, &outerr, &contrib); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_imagelist_combine(NULL, errs, method, &outimg, &outerr, &contrib); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_collapse_imagelist_to_image_delete(method); + } + /* wrong imagelist sizes */ + { + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + cpl_imagelist * data2 = cpl_imagelist_duplicate(data); + cpl_imagelist * errs2; + cpl_image_delete(cpl_imagelist_unset(data2, 0)); + hdrl_imagelist_combine(data2, errs, method, &outimg, &outerr, &contrib); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_imagelist_delete(data2); + + data2 = cpl_imagelist_new(); + errs2 = cpl_imagelist_new(); + hdrl_imagelist_combine(data2, errs2, method, &outimg, &outerr, &contrib); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_imagelist_delete(data2); + cpl_imagelist_delete(errs2); + hdrl_collapse_imagelist_to_image_delete(method); + } + /* test reductions on uniform error cases */ + { + /* mean */ + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + /* sigclip */ + method = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + /* minmax */ + method = hdrl_collapse_imagelist_to_image_minmax(0, 0); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + /* weighted mean */ + method = hdrl_collapse_imagelist_to_image_weighted_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + /* median */ + cpl_image_multiply_scalar(expect_err, sqrt(CPL_MATH_PI_2)); + method = hdrl_collapse_imagelist_to_image_median(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_image_abs(outimg, img, HDRL_EPS_DATA); + cpl_test_image_abs(outerr, expect_err, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + } + /* test non uniform error cases */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {0.5, 0.7, 0.1, 1.0, 0.01}; + int d; + for (size_t i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + } + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.8, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 0.26458269028793246, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + method = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.8, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 0.26458269028793246, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + method = hdrl_collapse_imagelist_to_image_minmax(1, 1); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 5./3., HDRL_EPS_DATA); + + /* The minmax rejection algorithm has a + * intrinsic problem with same values but different errors. If for + * example the two lowest values are 1+-0.5 and 1+-500 what "1" should + * be kept? It doesn't matter for the mean, but for the propagated + * error - the implemented algorithm propagates the smaller error */ + + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), + sqrt(0.1 * 0.1 + 0.7 * 0.7 + 0.01 * 0.01) / 3., + HDRL_EPS_ERROR); + cpl_image * expect_contrib_minmax = + cpl_image_subtract_scalar_create(expect_contrib, 2); + cpl_test_image_abs(contrib, expect_contrib_minmax, 0); + cpl_image_delete(expect_contrib_minmax); + TST_FREE; + + method = hdrl_collapse_imagelist_to_image_weighted_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.9898090843925733, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 0.0099469054598625289, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + } + /* test non uniform error cases with rejected values */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {0.5, 0.7, 0.1, 1.0, 0.01}; + int d; + for (size_t i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + if (i == 3) { + cpl_image_reject(tmp, 1, 1); + } + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + if (i == 3) { + cpl_image_reject(tmp, 1, 1); + } + } + cpl_image_delete(expect_contrib); + expect_contrib = cpl_image_new_from_accepted(data); + + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.5, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 0.21652078422174625, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + method = hdrl_collapse_imagelist_to_image_sigclip(3., 3., 3); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.5, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 0.21652078422174625, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + + method = hdrl_collapse_imagelist_to_image_minmax(1, 1); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 3./2., HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), + sqrt(0.01 * 0.01 + 0.1 * 0.1) / 2., HDRL_EPS_ERROR); + cpl_image * expect_contrib_minmax = + cpl_image_subtract_scalar_create(expect_contrib, 2); + cpl_test_image_abs(contrib, expect_contrib_minmax, 0); + cpl_image_delete(expect_contrib_minmax); + TST_FREE; + + method = hdrl_collapse_imagelist_to_image_weighted_mean(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.9897091252756485, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 0.0099473975744101273, HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + } + /* test median error propagation with rejects, only makes sense on uniform + * errors as the scaling relies on gaussian errors */ + { + double v[] = {1, 2, 1, 3, 2}; + double e[] = {1., 1., 1., 1., 1.}; + int d; + for (size_t i = 0; i < nz; i++) { + cpl_image * tmp = cpl_imagelist_get(data, i); + cpl_image_set(tmp, 1, 1, v[i]); + cpl_image_set(tmp, 2, 2, v[i]); + if (i > 1) { + cpl_image_reject(tmp, 1, 1); + } + tmp = cpl_imagelist_get(errs, i); + cpl_image_set(tmp, 1, 1, e[i]); + cpl_image_set(tmp, 2, 2, e[i]); + if (i > 1) { + cpl_image_reject(tmp, 1, 1); + } + } + cpl_image_delete(expect_contrib); + expect_contrib = cpl_image_new_from_accepted(data); + + hdrl_collapse_imagelist_to_image_t * method = + hdrl_collapse_imagelist_to_image_median(); + hdrl_imagelist_combine(data, errs, method, &outimg, &outerr, &contrib); + + /* contrib > 2 -> sqrt(nz * pi / 2) error scaling */ + cpl_test_abs(cpl_image_get(outimg, 2, 2, &d), 2., HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 2, 2, &d), + 1. / sqrt(nz) * sqrt(CPL_MATH_PI_2), HDRL_EPS_ERROR); + /* contrib <= 2 -> median is a mean, no scaling */ + cpl_test_abs(cpl_image_get(outimg, 1, 1, &d), 1.5, HDRL_EPS_DATA); + cpl_test_abs(cpl_image_get(outerr, 1, 1, &d), 1. / sqrt(2.), HDRL_EPS_ERROR); + cpl_test_image_abs(contrib, expect_contrib, 0); + TST_FREE; + } + + cpl_imagelist_delete(data); + cpl_imagelist_delete(errs); + cpl_image_delete(expect_err); + cpl_image_delete(expect_contrib); + cpl_image_delete(img); + cpl_image_delete(err); + + return cpl_test_end(0); +#undef TST_FREE +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_correlation-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_correlation-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_correlation-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_correlation-test.c 2017-09-05 08:27:08.000000000 +0000 @@ -0,0 +1,190 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_correlation.h" + +#include +#include + +cpl_array * +create_rect(const cpl_size sz, const cpl_size start, const cpl_size stop){ + + cpl_array * v = cpl_array_new(sz, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < sz; ++i){ + + double p = 0.0; + + if(i >= start && i <= stop) + p = 5.0; + + cpl_array_set(v, i, p); + } + + return v; +} + +cpl_array * +create_gaussian(cpl_size num_samples, const double mean, const double stdev, + const double center, double * delta_out){ + + cpl_array * v = cpl_array_new(num_samples, CPL_TYPE_DOUBLE); + const double size = 8.0; + const double delta = size * stdev / (double)num_samples; + const double start = -size * .5 * stdev + center; + for(cpl_size i = 0; i < num_samples; ++i){ + const double x = delta * ((double)i) + start; + const double val = (x - mean) / stdev; + const double exponential = -.5 * pow(val, 2.0); + const double y = exp(exponential)/(stdev * sqrt(2. * CPL_MATH_PI)); + cpl_array_set(v, i, y); + } + + *delta_out = delta; + + return v; +} + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_correlation_test + */ +/*----------------------------------------------------------------------------*/ + +void test_shift_pixel_precision(const cpl_size in_shift){ + + const cpl_size sz = 28; + const cpl_size win = 14; + cpl_array * v1 = create_rect(sz, 3, 5); + cpl_array * v2 = create_rect(sz, 3 + llabs(in_shift), 5 + llabs(in_shift)); + + if(in_shift < 0){ + cpl_array * tmp = v1; + v1 = v2; + v2 = tmp; + } + + hdrl_xcorrelation_result * res = + hdrl_compute_xcorrelation(v1, v2, win, CPL_FALSE); + + const cpl_size idx = hdrl_xcorrelation_result_get_peak_pixel(res); + const cpl_size shift = idx - win; + + const cpl_array * xcorr = hdrl_xcorrelation_result_get_correlation(res); + + cpl_test_eq(shift, -in_shift); + + if(in_shift == 0){ + cpl_test_rel(cpl_array_get(xcorr, idx, NULL), + 25.0 * 3.0 /((double)sz), 1e-5); + cpl_test_rel(cpl_array_get(xcorr, idx - 1, NULL), + 25.0 * 2.0 /((double)sz - 1.0), 1e-5); + cpl_test_rel(cpl_array_get(xcorr, idx + 1, NULL), + 25.0 * 2.0 /((double)sz - 1.0), 1e-5); + cpl_test_rel(cpl_array_get(xcorr, idx - 2, NULL), + 25.0 * 1.0 /((double)sz - 2.0), 1e-5); + cpl_test_rel(cpl_array_get(xcorr, idx + 2, NULL), + 25.0 * 1.0 /((double)sz - 2.0), 1e-5); + for(cpl_size i = 0; i < win * 2 + 1; i++){ + if(i >= idx - 2 && i <= idx + 2) continue; + cpl_test_rel(cpl_array_get(xcorr, i, NULL), 0.0, 1e-5); + } + } + + hdrl_xcorrelation_result_delete(res); + + cpl_array_delete(v1); + cpl_array_delete(v2); +} + +void test_shift_gaussian_fit(const double mean_diff, + const cpl_boolean use_win_refinement){ + + const double m1 = 1.0; + const double m2 = m1 + mean_diff; + const double std_dev = sqrt(.5); + const cpl_size sz = 100; + cpl_size half_w = 180; + double delta = .0; + cpl_array * arr1 = create_gaussian(sz, m1, std_dev, .5 * (m1 + m2), &delta); + cpl_array * arr2 = create_gaussian(sz, m2, std_dev, .5 * (m1 + m2), &delta); + + hdrl_xcorrelation_result * r = NULL; + + if(use_win_refinement) + r = hdrl_compute_offset_gaussian(arr1, arr2, + half_w, CPL_TRUE, delta, 0.5); + else + r = hdrl_compute_offset_gaussian_internal(arr1, arr2, + half_w, CPL_TRUE, delta, 0.5); + + const double peak = hdrl_xcorrelation_result_get_peak_subpixel(r); + const cpl_size used_win = hdrl_xcorrelation_result_get_half_window(r); + const double tolerance = use_win_refinement ? 5.6e-2 : 6e-2; + if (mean_diff != 0.0) { // Needed -> check the definition of the cpl macro + cpl_test_rel(-peak + used_win * delta, mean_diff, tolerance); + } else { + cpl_test_abs(peak, used_win * delta, tolerance); + } + + hdrl_xcorrelation_result_delete(r); + cpl_array_delete(arr1); + cpl_array_delete(arr2); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of correlation and shift + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_shift_pixel_precision(0); + test_shift_pixel_precision(2); + test_shift_pixel_precision(6); + test_shift_pixel_precision(-2); + test_shift_pixel_precision(-6); + + + test_shift_gaussian_fit(2.4, CPL_FALSE); + test_shift_gaussian_fit(-2.4, CPL_FALSE); + test_shift_gaussian_fit(1.8, CPL_FALSE); + test_shift_gaussian_fit(0.0, CPL_FALSE); + + test_shift_gaussian_fit(2.4, CPL_TRUE); + test_shift_gaussian_fit(-2.4, CPL_TRUE); + test_shift_gaussian_fit(1.8, CPL_TRUE); + test_shift_gaussian_fit(0.0, CPL_TRUE); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_dar-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_dar-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_dar-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_dar-test.c 2017-09-14 09:25:28.000000000 +0000 @@ -0,0 +1,1122 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ +#include "hdrl_dar.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_dar_test Testing of the HDRL DAR + */ +/*----------------------------------------------------------------------------*/ + +/* maximum number of wavelength planes = pixels in table to expect */ +#define NMAX 300 + +/* standard star 1: BD+75d325 at airmass ~ 1.27922 (run86_00131b.fits) */ +const float kStd1[][5] = { /* every 10th wavelength plane of the centroid */ + { 3737.84, -0.27, 0.007, 0.774, 0.008 }, + { 3770.84, -0.265, 0.007, 0.732, 0.007 }, + { 3803.84, -0.268, 0.007, 0.702, 0.007 }, + { 3836.84, -0.255, 0.006, 0.665, 0.007 }, + { 3869.84, -0.25, 0.006, 0.644, 0.006 }, + { 3902.84, -0.248, 0.006, 0.613, 0.006 }, + { 3935.84, -0.236, 0.006, 0.589, 0.006 }, + { 3968.84, -0.244, 0.006, 0.569, 0.006 }, + { 4001.84, -0.23, 0.005, 0.543, 0.005 }, + { 4034.84, -0.19, 0.005, 0.517, 0.005 }, + { 4067.84, -0.2, 0.005, 0.507, 0.005 }, + { 4100.84, -0.207, 0.005, 0.493, 0.005 }, + /* { 4133.84, -0.141, 0.005, 0.485, 0.005 }, high x values */ + /* { 4166.84, -0.131, 0.005, 0.479, 0.005 }, high x values */ + { 4199.84, -0.186, 0.005, 0.444, 0.005 }, + { 4232.84, -0.162, 0.005, 0.417, 0.005 }, + { 4265.84, -0.166, 0.005, 0.405, 0.005 }, + { 4298.84, -0.17, 0.005, 0.39, 0.005 }, + { 4331.84, -0.163, 0.005, 0.368, 0.005 }, + { 4364.84, -0.112, 0.005, 0.346, 0.005 }, + { 4397.84, -0.148, 0.005, 0.34, 0.005 }, + { 4430.84, -0.145, 0.005, 0.325, 0.005 }, + { 4463.84, -0.131, 0.005, 0.308, 0.005 }, + { 4496.84, -0.104, 0.005, 0.285, 0.005 }, + { 4529.84, -0.118, 0.005, 0.276, 0.005 }, + { 4562.84, -0.093, 0.005, 0.253, 0.005 }, + /* { 4595.84, -0.069, 0.005, 0.306, 0.005 }, high y value */ + { 4628.84, -0.085, 0.005, 0.236, 0.005 }, + { 4661.84, -0.072, 0.005, 0.219, 0.005 }, + { 4694.84, -0.1, 0.005, 0.213, 0.005 }, + { 4727.84, -0.072, 0.005, 0.191, 0.005 }, + { 4760.84, -0.082, 0.005, 0.183, 0.005 }, + { 4793.84, -0.074, 0.005, 0.171, 0.005 }, + { 4826.84, -0.061, 0.005, 0.16, 0.005 }, + { 4859.84, -0.057, 0.005, 0.145, 0.005 }, + /* { 4892.84, 0, 0.005, 0.119, 0.005 }, high x value */ + { 4925.84, -0.033, 0.005, 0.117, 0.005 }, + { 4958.84, -0.029, 0.005, 0.099, 0.005 }, + { 4991.84, -0.028, 0.005, 0.091, 0.005 }, + { 5024.84, -0.031, 0.005, 0.08, 0.005 }, + { 5057.84, -0.029, 0.005, 0.07, 0.005 }, + { 5090.84, -0.021, 0.005, 0.055, 0.005 }, + { 5123.84, -0.021, 0.005, 0.054, 0.005 }, + { 5156.84, -0.017, 0.005, 0.036, 0.005 }, + { 5189.84, -0.012, 0.005, 0.028, 0.005 }, + { 5222.84, -0.009, 0.005, 0.018, 0.005 }, + { 5255.84, -0.004, 0.005, 0.008, 0.005 }, + { 5288.84, 0.002, 0.005, -0.008, 0.005 }, + { 5321.84, 0.003, 0.005, -0.009, 0.005 }, + { 5354.84, 0.011, 0.005, -0.025, 0.005 }, + { 5387.84, 0.011, 0.005, -0.033, 0.005 }, + /* { 5420.84, -0.01, 0.005, -0.036, 0.005 }, low x value */ + { 5453.84, 0.031, 0.005, -0.057, 0.005 }, + { 5486.84, 0.021, 0.005, -0.068, 0.005 }, + { 5519.84, 0.028, 0.005, -0.077, 0.005 }, + { 5552.84, 0.035, 0.005, -0.088, 0.005 }, + { 5585.84, 0.035, 0.005, -0.092, 0.005 }, + { 5618.84, 0.048, 0.005, -0.106, 0.005 }, + { 5651.84, 0.054, 0.005, -0.113, 0.005 }, + { 5684.84, 0.06, 0.005, -0.118, 0.005 }, + { 5717.84, 0.066, 0.005, -0.13, 0.005 }, + { 5750.84, 0.063, 0.005, -0.131, 0.005 }, + { 5783.84, 0.067, 0.005, -0.136, 0.005 }, + { 5816.84, 0.063, 0.005, -0.148, 0.005 }, + { 5849.84, 0.064, 0.005, -0.153, 0.005 }, + { 5882.84, 0.062, 0.005, -0.162, 0.005 }, + { 5915.84, 0.081, 0.005, -0.174, 0.005 }, + /* { 5948.84, 0.066, 0.005, -0.194, 0.006 }, low y value */ + { 5981.84, 0.091, 0.006, -0.187, 0.006 }, + { 6014.84, 0.095, 0.006, -0.193, 0.006 }, + { 6047.84, 0.094, 0.006, -0.193, 0.006 }, + { 6080.84, 0.087, 0.006, -0.201, 0.006 }, + { 6113.84, 0.089, 0.006, -0.21, 0.006 }, + { 6146.84, 0.103, 0.006, -0.222, 0.006 }, + { 6179.84, 0.114, 0.006, -0.225, 0.006 }, + { 6212.84, 0.114, 0.006, -0.23, 0.006 }, + { 6245.84, 0.101, 0.006, -0.235, 0.006 }, + { 6278.84, 0.093, 0.006, -0.239, 0.006 }, + { 6311.84, 0.11, 0.006, -0.247, 0.006 }, + { 6344.84, 0.119, 0.006, -0.253, 0.006 }, + { 6377.84, 0.119, 0.006, -0.253, 0.006 }, + { 6410.84, 0.107, 0.006, -0.257, 0.006 }, + { 6443.84, 0.113, 0.006, -0.267, 0.006 }, + { 6476.84, 0.124, 0.006, -0.276, 0.006 }, + { 6509.84, 0.125, 0.007, -0.277, 0.006 }, + { 6542.84, 0.111, 0.007, -0.28, 0.007 }, + /* { 6575.84, 0.147, 0.007, -0.297, 0.007 }, high x value */ + { 6608.84, 0.132, 0.007, -0.294, 0.007 }, + { 6641.84, 0.13, 0.007, -0.295, 0.007 }, + { 6674.84, 0.118, 0.007, -0.299, 0.007 }, + { 6707.84, 0.129, 0.007, -0.311, 0.007 }, + { 6740.84, 0.138, 0.007, -0.316, 0.007 }, + { 6773.84, 0.134, 0.007, -0.316, 0.007 }, + { 6806.84, 0.126, 0.007, -0.325, 0.007 }, + { 6839.84, 0.138, 0.007, -0.325, 0.007 }, + /* { 6872.84, 0.199, 0.008, -0.334, 0.008 }, high x value */ + { 6905.84, 0.15, 0.008, -0.333, 0.008 }, + { 6938.84, 0.142, 0.007, -0.332, 0.008 }, + { 0.0, 0.0, 0.0, 0.0, 0.0 } +}; + +/* standard star 2: bd332642 at airmass ~ 1.02331 (run86_00175b.fits) */ +const float kStd2[][5] = { /* every 10th wavelength plane of the centroid */ + /* { 3736.2, 0.156, 0.010, -0.049, 0.012 }, weird values */ + /* { 3769.2, 0.337, 0.009, -0.124, 0.011 }, noise?! */ + /* { 3802.2, 0.263, 0.009, -0.108, 0.010 }, noise?! */ + /* { 3835.2, 0.329, 0.009, -0.115, 0.010 }, noise?! */ + { 3868.2, 0.184, 0.008, -0.093, 0.009 }, + { 3901.2, 0.193, 0.008, -0.089, 0.009 }, + { 3934.2, 0.182, 0.008, -0.088, 0.009 }, + /* { 3967.2, 0.046, 0.008, -0.058, 0.009 }, low x value */ + { 4000.2, 0.154, 0.007, -0.075, 0.008 }, + /* { 4033.2, 0.188, 0.007, -0.087, 0.008 }, high x value */ + { 4066.2, 0.138, 0.007, -0.061, 0.008 }, + /* { 4099.2, 0.074, 0.007, -0.051, 0.008 }, low x value */ + /* { 4132.2, 0.17, 0.007, -0.065, 0.008 }, weird values */ + /* { 4165.2, 0.16, 0.006, -0.056, 0.008 }, weird values */ + { 4198.2, 0.131, 0.007, -0.059, 0.007 }, + { 4231.2, 0.112, 0.007, -0.055, 0.008 }, + { 4264.2, 0.102, 0.007, -0.049, 0.007 }, + { 4297.2, 0.101, 0.007, -0.054, 0.007 }, + { 4330.2, 0.097, 0.007, -0.052, 0.007 }, + /* { 4363.2, 0.149, 0.007, -0.063, 0.008 }, weird values */ + /* { 4396.2, 0.059, 0.007, -0.043, 0.007 }, weird values */ + { 4429.2, 0.089, 0.007, -0.046, 0.007 }, + { 4462.2, 0.088, 0.006, -0.045, 0.007 }, + { 4495.2, 0.098, 0.006, -0.042, 0.007 }, + { 4528.2, 0.07, 0.006, -0.037, 0.007 }, + { 4561.2, 0.062, 0.006, -0.034, 0.007 }, + { 4594.2, 0.073, 0.006, -0.044, 0.007 }, + { 4627.2, 0.067, 0.006, -0.04, 0.007 }, + { 4660.2, 0.055, 0.006, -0.037, 0.007 }, + { 4693.2, 0.054, 0.006, -0.027, 0.007 }, + { 4726.2, 0.036, 0.006, -0.024, 0.007 }, + { 4759.2, 0.044, 0.006, -0.026, 0.007 }, + { 4792.2, 0.045, 0.006, -0.024, 0.007 }, + { 4825.2, 0.038, 0.006, -0.027, 0.007 }, + { 4858.2, 0.04, 0.006, -0.023, 0.007 }, + /* { 4891.2, 0.094, 0.006, -0.034, 0.007 }, weird values */ + { 4924.2, 0.031, 0.006, -0.013, 0.007 }, + { 4957.2, 0.029, 0.006, -0.013, 0.007 }, + { 4990.2, 0.021, 0.006, -0.012, 0.007 }, + { 5023.2, 0.01, 0.006, -0.002, 0.007 }, + { 5056.2, 0.017, 0.006, -0.003, 0.007 }, + { 5089.2, 0.019, 0.006, -0.003, 0.007 }, + { 5122.2, 0.015, 0.006, -0.006, 0.007 }, + { 5155.2, 0.016, 0.006, -0.004, 0.007 }, + { 5188.2, 0.007, 0.006, -0.004, 0.007 }, + { 5221.2, 0.008, 0.006, -0.002, 0.007 }, + { 5254.2, 0.005, 0.006, 0, 0.007 }, + { 5287.2, 0.001, 0.006, 0.001, 0.007 }, + { 5320.2, -0.002, 0.006, 0.006, 0.007 }, + { 5353.2, -0.002, 0.006, 0.005, 0.007 }, + { 5386.2, -0.008, 0.006, 0.007, 0.007 }, + { 5419.2, -0.013, 0.006, 0.007, 0.007 }, + { 5452.2, -0.014, 0.006, 0.006, 0.007 }, + { 5485.2, -0.019, 0.006, 0.011, 0.007 }, + { 5518.2, -0.017, 0.006, 0.007, 0.007 }, + { 5551.2, -0.02, 0.007, 0.013, 0.007 }, + { 5584.2, -0.03, 0.007, 0.013, 0.007 }, + { 5617.2, -0.028, 0.007, 0.012, 0.007 }, + { 5650.2, -0.034, 0.007, 0.01, 0.007 }, + { 5683.2, -0.034, 0.007, 0.009, 0.007 }, + { 5716.2, -0.031, 0.007, 0.011, 0.007 }, + /* { 5749.2, 0.059, 0.008, 0.04, 0.007 }, high values */ + { 5782.2, -0.031, 0.007, 0.016, 0.007 }, + { 5815.2, -0.03, 0.007, 0.02, 0.007 }, + { 5848.2, -0.03, 0.007, 0.005, 0.007 }, + { 5881.2, -0.044, 0.007, 0.022, 0.007 }, + { 5914.2, -0.029, 0.007, 0.023, 0.007 }, + { 5947.2, -0.04, 0.007, 0.01, 0.007 }, + { 5980.2, -0.037, 0.007, 0.019, 0.007 }, + { 6013.2, -0.035, 0.007, 0.015, 0.008 }, + { 6046.2, -0.034, 0.007, 0.019, 0.008 }, + { 6079.2, -0.037, 0.007, 0.014, 0.008 }, + { 6112.2, -0.041, 0.007, 0.024, 0.008 }, + { 6145.2, -0.043, 0.007, 0.02, 0.008 }, + { 6178.2, -0.044, 0.007, 0.02, 0.008 }, + { 6211.2, -0.043, 0.007, 0.021, 0.008 }, + { 6244.2, -0.046, 0.007, 0.025, 0.008 }, + { 6277.2, -0.055, 0.007, 0.025, 0.008 }, + { 6310.2, -0.049, 0.008, 0.027, 0.008 }, + { 6343.2, -0.052, 0.008, 0.02, 0.008 }, + { 6376.2, -0.048, 0.008, 0.022, 0.008 }, + { 6409.2, -0.054, 0.008, 0.025, 0.008 }, + { 6442.2, -0.064, 0.008, 0.028, 0.008 }, + { 6475.2, -0.068, 0.008, 0.027, 0.009 }, + { 6508.2, -0.058, 0.008, 0.022, 0.009 }, + { 6541.2, -0.057, 0.008, 0.029, 0.009 }, + /* { 6574.2, -0.089, 0.009, 0.031, 0.009 }, low x value */ + { 6607.2, -0.068, 0.008, 0.034, 0.009 }, + { 6640.2, -0.066, 0.008, 0.025, 0.009 }, + /* { 6673.2, -0.091, 0.009, 0.028, 0.009 }, low x value */ + { 6706.2, -0.069, 0.009, 0.028, 0.009 }, + { 6739.2, -0.07, 0.009, 0.03, 0.009 }, + { 6772.2, -0.065, 0.009, 0.034, 0.009 }, + { 6805.2, -0.075, 0.009, 0.034, 0.009 }, + { 6838.2, -0.079, 0.009, 0.026, 0.009 }, + /* { 6871.2, -0.002, 0.010, 0.016, 0.011 }, high x value */ + { 6904.2, -0.057, 0.009, 0.032, 0.010 }, + { 6937.2, -0.075, 0.009, 0.034, 0.010 }, + { 0.0, 0.0, 0.0, 0.0, 0.0 } +}; + +/* imcentroid of star in Pre-Dry-Run_001_001_002_float.fits */ +const float kMuse1[][5] = { /* peak centroid shifts of three objects */ + { 4651.657, -6.732, 0.499, -1.614, 0.500 }, + { 4701.657, -6.337, 0.477, -1.624, 0.463 }, + { 4714.157, -6.311, 0.470, -1.569, 0.460 }, + { 4726.657, -6.309, 0.465, -1.566, 0.465 }, + { 4739.157, -6.124, 0.475, -1.560, 0.469 }, + { 4751.657, -6.108, 0.471, -1.503, 0.466 }, + { 4764.157, -6.118, 0.474, -1.500, 0.472 }, + { 4776.657, -5.966, 0.468, -1.499, 0.467 }, + { 4789.157, -5.958, 0.492, -1.481, 0.486 }, + { 4801.657, -5.961, 0.465, -1.490, 0.463 }, + { 4814.157, -5.854, 0.460, -1.566, 0.448 }, + { 4826.657, -5.801, 0.461, -1.491, 0.462 }, + { 4839.157, -5.807, 0.460, -1.435, 0.462 }, + { 4851.657, -5.788, 0.450, -1.527, 0.461 }, + { 4864.157, -5.619, 0.464, -1.503, 0.457 }, + { 4876.657, -5.591, 0.467, -1.379, 0.470 }, + { 4889.157, -5.624, 0.475, -1.426, 0.475 }, + { 4901.657, -5.432, 0.450, -1.418, 0.452 }, + { 4914.157, -5.390, 0.452, -1.420, 0.459 }, + { 4926.657, -5.361, 0.462, -1.262, 0.463 }, + { 4939.157, -5.375, 0.466, -1.313, 0.439 }, + { 4951.657, -5.170, 0.443, -1.384, 0.448 }, + { 4964.157, -5.165, 0.451, -1.295, 0.452 }, + { 4976.657, -5.172, 0.456, -1.295, 0.463 }, + { 4989.157, -5.153, 0.469, -1.317, 0.469 }, + { 5001.657, -4.976, 0.464, -1.261, 0.460 }, + { 5014.157, -4.978, 0.486, -1.335, 0.487 }, + { 5026.657, -4.967, 0.476, -1.231, 0.476 }, + { 5039.157, -4.959, 0.487, -1.268, 0.497 }, + { 5051.657, -4.818, 0.475, -1.274, 0.496 }, + { 5064.157, -4.807, 0.485, -1.209, 0.483 }, + { 5076.657, -4.815, 0.487, -1.274, 0.488 }, + { 5089.157, -4.743, 0.497, -1.251, 0.487 }, + { 5101.657, -4.609, 0.501, -1.177, 0.505 }, + { 5114.157, -4.612, 0.512, -1.184, 0.510 }, + { 5126.657, -4.612, 0.521, -1.105, 0.530 }, + { 5139.157, -4.569, 0.500, -1.070, 0.505 }, + { 5151.657, -4.415, 0.539, -1.065, 0.546 }, + { 5164.157, -4.438, 0.494, -1.103, 0.517 }, + { 5176.657, -4.376, 0.597, -1.017, 0.605 }, + { 5189.157, -4.401, 0.536, -1.085, 0.543 }, + { 5201.657, -4.233, 0.505, -1.093, 0.503 }, + { 5214.157, -4.222, 0.492, -1.137, 0.481 }, + { 5226.657, -4.233, 0.470, -1.220, 0.497 }, + { 5251.657, -4.020, 0.456, -1.030, 0.440 }, + { 5264.157, -4.027, 0.477, -1.009, 0.447 }, + { 5289.157, -4.002, 0.439, -0.993, 0.440 }, + { 5301.657, -4.005, 0.455, -1.096, 0.462 }, + { 5314.157, -3.823, 0.423, -1.055, 0.460 }, + { 5326.657, -3.859, 0.472, -1.126, 0.441 }, + { 5339.157, -3.803, 0.439, -0.994, 0.446 }, + { 5351.657, -3.786, 0.441, -0.922, 0.455 }, + { 5364.157, -3.585, 0.432, -0.843, 0.440 }, + { 5376.657, -3.569, 0.450, -0.809, 0.449 }, + { 5389.157, -3.584, 0.435, -0.862, 0.444 }, + { 5401.657, -3.567, 0.456, -0.829, 0.452 }, + { 5414.157, -3.573, 0.451, -0.847, 0.464 }, + { 5426.657, -3.427, 0.437, -0.884, 0.450 }, + { 5439.157, -3.412, 0.444, -0.896, 0.453 }, + { 5451.657, -3.383, 0.444, -0.833, 0.445 }, + { 5464.157, -3.381, 0.438, -0.829, 0.448 }, + { 5476.657, -3.393, 0.441, -0.862, 0.450 }, + { 5489.157, -3.205, 0.441, -0.778, 0.443 }, + { 5501.657, -3.196, 0.444, -0.766, 0.454 }, + { 5514.157, -3.175, 0.450, -0.753, 0.454 }, + { 5526.657, -3.184, 0.439, -0.755, 0.443 }, + { 5539.157, -3.206, 0.436, -0.837, 0.433 }, + { 5551.657, -3.009, 0.432, -0.815, 0.438 }, + { 5564.157, -3.027, 0.436, -0.771, 0.494 }, + { 5589.157, -3.008, 0.456, -0.748, 0.457 }, + { 5601.657, -3.003, 0.443, -0.855, 0.453 }, + { 5614.157, -2.964, 0.427, -0.743, 0.435 }, + { 5626.657, -2.805, 0.433, -0.815, 0.455 }, + { 5639.157, -2.767, 0.429, -0.525, 0.444 }, + { 5651.657, -2.765, 0.429, -0.644, 0.436 }, + { 5664.157, -2.775, 0.436, -0.585, 0.466 }, + { 5676.657, -2.757, 0.429, -0.639, 0.438 }, + { 5689.157, -2.561, 0.435, -0.667, 0.440 }, + { 5701.657, -2.561, 0.434, -0.625, 0.443 }, + { 5714.157, -2.563, 0.440, -0.687, 0.446 }, + { 5726.657, -2.570, 0.430, -0.683, 0.435 }, + { 5739.157, -2.567, 0.429, -0.671, 0.435 }, + { 5751.657, -2.572, 0.425, -0.672, 0.431 }, + { 5764.157, -2.395, 0.424, -0.587, 0.435 }, + { 5776.657, -2.386, 0.420, -0.560, 0.435 }, + { 5789.157, -2.412, 0.428, -0.573, 0.440 }, + { 5801.657, -2.419, 0.421, -0.577, 0.435 }, + { 5814.157, -2.431, 0.424, -0.556, 0.438 }, + { 5826.657, -2.412, 0.420, -0.582, 0.430 }, + { 5839.157, -2.207, 0.422, -0.567, 0.432 }, + { 5851.657, -2.201, 0.423, -0.583, 0.430 }, + { 5876.657, -2.221, 0.424, -0.601, 0.432 }, + { 5889.157, -2.586, 0.527, -0.440, 0.536 }, + { 5926.657, -1.979, 0.429, -0.421, 0.425 }, + { 5939.157, -1.985, 0.421, -0.436, 0.438 }, + { 5951.657, -2.039, 0.410, -0.523, 0.426 }, + { 5964.157, -2.010, 0.422, -0.459, 0.436 }, + { 5989.157, -2.006, 0.422, -0.445, 0.431 }, + { 6001.657, -1.809, 0.428, -0.420, 0.425 }, + { 6014.157, -1.850, 0.425, -0.506, 0.435 }, + { 6026.657, -1.828, 0.430, -0.498, 0.433 }, + { 6039.157, -1.823, 0.418, -0.457, 0.432 }, + { 6051.657, -1.852, 0.418, -0.483, 0.430 }, + { 6064.157, -1.846, 0.419, -0.466, 0.430 }, + { 6076.657, -1.791, 0.416, -0.488, 0.430 }, + { 6089.157, -1.657, 0.421, -0.480, 0.437 }, + { 6101.657, -1.676, 0.421, -0.451, 0.447 }, + { 6114.157, -1.667, 0.420, -0.370, 0.431 }, + { 6126.657, -1.677, 0.431, -0.399, 0.444 }, + { 6139.157, -1.685, 0.431, -0.329, 0.453 }, + { 6151.657, -1.647, 0.413, -0.345, 0.444 }, + { 6164.157, -1.685, 0.452, -0.413, 0.464 }, + { 6176.657, -1.455, 0.423, -0.353, 0.455 }, + { 6189.157, -1.447, 0.412, -0.396, 0.436 }, + { 6201.657, -1.527, 0.411, -0.336, 0.489 }, + { 6214.157, -1.424, 0.425, -0.327, 0.408 }, + { 6226.657, -1.486, 0.416, -0.397, 0.438 }, + { 6239.157, -1.464, 0.414, -0.487, 0.460 }, + { 6251.657, -1.485, 0.418, -0.398, 0.441 }, + { 6264.157, -1.210, 0.427, -0.405, 0.401 }, + { 6276.657, -1.233, 0.425, -0.428, 0.413 }, + { 6314.157, -1.271, 0.414, -0.253, 0.434 }, + { 6326.657, -1.217, 0.419, -0.284, 0.404 }, + { 6339.157, -1.262, 0.419, -0.244, 0.437 }, + { 6351.657, -1.240, 0.410, -0.348, 0.422 }, + { 6376.657, -1.082, 0.412, -0.238, 0.427 }, + { 6389.157, -1.060, 0.415, -0.274, 0.423 }, + { 6401.657, -1.076, 0.420, -0.238, 0.427 }, + { 6414.157, -1.049, 0.414, -0.276, 0.406 }, + { 6426.657, -1.060, 0.415, -0.241, 0.431 }, + { 6439.157, -1.086, 0.415, -0.302, 0.425 }, + { 6451.657, -1.054, 0.412, -0.266, 0.426 }, + { 6464.157, -0.887, 0.427, -0.457, 0.388 }, + { 6476.657, -0.868, 0.414, -0.334, 0.399 }, + { 6489.157, -0.915, 0.414, -0.307, 0.425 }, + { 6514.157, -0.901, 0.412, -0.020, 0.443 }, + { 6526.657, -0.910, 0.408, -0.226, 0.420 }, + { 6539.157, -0.910, 0.412, -0.088, 0.421 }, + { 6589.157, -0.713, 0.406, -0.224, 0.425 }, + { 6614.157, -0.729, 0.411, -0.213, 0.425 }, + { 6626.657, -0.748, 0.410, -0.268, 0.425 }, + { 6639.157, -0.711, 0.405, -0.239, 0.423 }, + { 6651.657, -0.715, 0.408, -0.204, 0.418 }, + { 6664.157, -0.740, 0.409, -0.204, 0.416 }, + { 6676.657, -0.708, 0.406, -0.185, 0.419 }, + { 6689.157, -0.531, 0.406, -0.276, 0.421 }, + { 6701.657, -0.528, 0.407, -0.163, 0.422 }, + { 6714.157, -0.544, 0.405, -0.261, 0.425 }, + { 6726.657, -0.532, 0.408, -0.208, 0.418 }, + { 6739.157, -0.561, 0.400, -0.265, 0.419 }, + { 6751.657, -0.496, 0.403, -0.108, 0.420 }, + { 6764.157, -0.512, 0.403, -0.159, 0.420 }, + { 6776.657, -0.522, 0.404, -0.127, 0.421 }, + { 6789.157, -0.521, 0.406, -0.047, 0.412 }, + { 6801.657, -0.417, 0.401, -0.103, 0.417 }, + { 6814.157, -0.316, 0.396, -0.105, 0.414 }, + { 6826.657, -0.346, 0.400, -0.218, 0.446 }, + { 6839.157, -0.329, 0.396, -0.110, 0.422 }, + { 6851.657, -0.318, 0.404, -0.106, 0.406 }, + { 6876.657, -0.339, 0.436, -0.111, 0.467 }, + { 6889.157, -0.287, 0.407, 0.134, 0.403 }, + { 6901.657, -0.296, 0.422, 0.090, 0.383 }, + { 6914.157, -0.428, 0.408, 0.104, 0.441 }, + { 6926.657, -0.344, 0.396, -0.160, 0.426 }, + { 6939.157, -0.129, 0.408, 0.002, 0.384 }, + { 6951.657, -0.144, 0.401, -0.225, 0.445 }, + { 6964.157, -0.136, 0.396, -0.167, 0.414 }, + { 6989.157, -0.171, 0.397, -0.116, 0.418 }, + { 7001.657, -0.192, 0.395, -0.285, 0.431 }, + { 7014.157, -0.158, 0.396, -0.017, 0.418 }, + { 7026.657, -0.147, 0.400, -0.007, 0.412 }, + { 7039.157, -0.110, 0.397, -0.222, 0.420 }, + { 7051.657, -0.161, 0.397, 0.015, 0.416 }, + { 7064.157, 0.017, 0.403, -0.030, 0.426 }, + { 7076.657, 0.020, 0.402, -0.184, 0.409 }, + { 7089.157, 0.000, 0.407, 0.197, 0.409 }, + { 7101.657, -0.000, 0.400, -0.000, 0.418 }, + { 7114.157, 0.009, 0.398, -0.043, 0.420 }, + { 7126.657, 0.001, 0.400, -0.128, 0.391 }, + { 7139.157, 0.016, 0.402, -0.158, 0.409 }, + { 7151.657, 0.037, 0.405, 0.096, 0.419 }, + { 7164.157, 0.007, 0.403, -0.173, 0.411 }, + { 7176.657, 0.031, 0.413, 0.118, 0.419 }, + { 7189.157, 0.048, 0.418, 0.088, 0.425 }, + { 7201.657, 0.044, 0.406, 0.134, 0.415 }, + { 7214.157, 0.230, 0.401, -0.061, 0.413 }, + { 7226.657, 0.233, 0.403, -0.050, 0.428 }, + { 7264.157, 0.236, 0.400, 0.022, 0.413 }, + { 7351.657, 0.180, 0.398, 0.112, 0.406 }, + { 7364.157, 0.351, 0.397, -0.049, 0.411 }, + { 7376.657, 0.378, 0.394, 0.044, 0.407 }, + { 7389.157, 0.438, 0.398, 0.112, 0.403 }, + { 7414.157, 0.437, 0.392, 0.068, 0.416 }, + { 7426.657, 0.431, 0.398, 0.101, 0.390 }, + { 7451.657, 0.382, 0.392, 0.048, 0.411 }, + { 7464.157, 0.467, 0.390, 0.189, 0.420 }, + { 7476.657, 0.435, 0.391, 0.058, 0.405 }, + { 7489.157, 0.390, 0.391, 0.067, 0.416 }, + { 7501.657, 0.399, 0.392, 0.033, 0.408 }, + { 7514.157, 0.398, 0.391, 0.048, 0.414 }, + { 7526.657, 0.541, 0.387, -0.125, 0.423 }, + { 7539.157, 0.604, 0.394, 0.064, 0.400 }, + { 7551.657, 0.576, 0.389, 0.042, 0.407 }, + { 7564.157, 0.595, 0.390, 0.095, 0.405 }, + { 7576.657, 0.600, 0.392, 0.037, 0.410 }, + { 7589.157, 0.580, 0.394, 0.087, 0.413 }, + { 7601.657, 0.578, 0.613, 0.136, 0.693 }, + { 7626.657, 0.518, 0.515, 0.096, 0.794 }, + { 7639.157, 0.581, 0.427, 0.104, 0.405 }, + { 7664.157, 0.564, 0.404, 0.054, 0.358 }, + { 7676.657, 0.586, 0.406, 0.148, 0.416 }, + { 7689.157, 0.578, 0.405, 0.115, 0.376 }, + { 7701.657, 0.787, 0.404, -0.034, 0.395 }, + { 7764.157, 0.743, 0.393, 0.126, 0.406 }, + { 7776.657, 0.747, 0.395, -0.004, 0.408 }, + { 7801.657, 0.714, 0.396, -0.083, 0.399 }, + { 7814.157, 0.722, 0.401, -0.079, 0.396 }, + { 7826.657, 0.764, 0.396, -0.054, 0.420 }, + { 7864.157, 0.770, 0.393, 0.222, 0.406 }, + { 7889.157, 0.926, 0.399, -0.081, 0.457 }, + { 7939.157, 0.953, 0.401, 0.137, 0.408 }, + { 7951.657, 0.910, 0.401, -0.054, 0.399 }, + { 7989.157, 0.921, 0.404, 0.021, 0.394 }, + { 8001.657, 0.978, 0.400, 0.180, 0.410 }, + { 8039.157, 0.932, 0.401, 0.067, 0.399 }, + { 8051.657, 0.912, 0.407, 0.223, 0.451 }, + { 8076.657, 0.981, 0.400, 0.305, 0.402 }, + { 8089.157, 1.162, 0.403, 0.280, 0.413 }, + { 8101.657, 1.236, 0.408, 0.405, 0.375 }, + { 8114.157, 1.177, 0.407, 0.304, 0.411 }, + { 8126.657, 1.150, 0.407, 0.217, 0.406 }, + { 8139.157, 1.179, 0.398, 0.336, 0.410 }, + { 8151.657, 1.178, 0.411, 0.281, 0.426 }, + { 8164.157, 1.138, 0.429, 0.261, 0.427 }, + { 8176.657, 1.188, 0.415, 0.255, 0.423 }, + { 8189.157, 1.176, 0.410, 0.028, 0.451 }, + { 8201.657, 1.173, 0.426, 0.267, 0.424 }, + { 8214.157, 1.153, 0.415, 0.329, 0.419 }, + { 8226.657, 1.172, 0.410, 0.223, 0.442 }, + { 8239.157, 1.205, 0.404, 0.125, 0.420 }, + { 8251.657, 1.181, 0.406, 0.243, 0.414 }, + { 8264.157, 1.167, 0.406, 0.276, 0.412 }, + { 8301.657, 1.332, 0.402, 0.311, 0.409 }, + { 8314.157, 1.367, 0.404, 0.247, 0.414 }, + { 8326.657, 1.366, 0.404, 0.238, 0.417 }, + { 8339.157, 1.356, 0.405, 0.033, 0.429 }, + { 8376.657, 1.348, 0.401, 0.386, 0.421 }, + { 8389.157, 1.347, 0.410, 0.055, 0.427 }, + { 8439.157, 1.367, 0.412, 0.248, 0.423 }, + { 8476.657, 1.389, 0.401, 0.152, 0.417 }, + { 8489.157, 1.375, 0.402, 0.216, 0.409 }, + { 8514.157, 1.380, 0.401, 0.250, 0.413 }, + { 8526.657, 1.363, 0.403, 0.343, 0.415 }, + { 8551.657, 1.576, 0.412, 0.306, 0.425 }, + { 8564.157, 1.571, 0.398, 0.346, 0.412 }, + { 8576.657, 1.550, 0.401, 0.322, 0.411 }, + { 8589.157, 1.605, 0.408, 0.393, 0.402 }, + { 8601.657, 1.579, 0.400, 0.307, 0.409 }, + { 8614.157, 1.605, 0.402, 0.323, 0.406 }, + { 8639.157, 1.577, 0.409, 0.369, 0.397 }, + { 8689.157, 1.603, 0.411, 0.226, 0.392 }, + { 8701.657, 1.618, 0.412, 0.125, 0.394 }, + { 8714.157, 1.601, 0.401, 0.315, 0.409 }, + { 8726.657, 1.590, 0.396, 0.467, 0.426 }, + { 8739.157, 1.608, 0.407, 0.358, 0.407 }, + { 8751.657, 1.596, 0.394, 0.370, 0.426 }, + { 8776.657, 1.320, 0.351, 0.323, 0.388 }, + { 8801.657, 1.820, 0.402, 0.389, 0.424 }, + { 8814.157, 1.832, 0.404, 0.373, 0.418 }, + { 8876.657, 1.861, 0.404, 0.378, 0.417 }, + { 8889.157, 1.855, 0.403, 0.247, 0.418 }, + { 8914.157, 1.873, 0.403, 0.334, 0.409 }, + { 8926.657, 1.855, 0.412, 0.313, 0.383 }, + { 8939.157, 1.894, 0.404, 0.218, 0.423 }, + { 8951.657, 1.868, 0.412, 0.404, 0.425 }, + { 8964.157, 1.876, 0.431, 0.237, 0.432 }, + { 8976.657, 1.888, 0.407, 0.547, 0.421 }, + { 9014.157, 1.889, 0.422, 0.361, 0.429 }, + { 9026.657, 1.845, 0.425, 0.307, 0.437 }, + { 9076.657, 2.072, 0.417, 0.343, 0.427 }, + { 9101.657, 1.878, 0.459, 0.380, 0.345 }, + { 9114.157, 2.075, 0.412, 0.462, 0.424 }, + { 9126.657, 2.076, 0.412, 0.462, 0.425 }, + { 9139.157, 2.064, 0.418, 0.530, 0.431 }, + { 9164.157, 2.058, 0.414, 0.460, 0.421 }, + { 9176.657, 2.057, 0.421, 0.489, 0.440 }, + { 9189.157, 2.048, 0.412, 0.464, 0.426 }, + { 9201.657, 2.038, 0.408, 0.469, 0.422 }, + { 9214.157, 2.038, 0.418, 0.482, 0.433 }, + { 9226.657, 2.022, 0.410, 0.460, 0.423 }, + { 9239.157, 2.007, 0.414, 0.445, 0.426 }, + { 9251.657, 2.011, 0.413, 0.467, 0.426 }, + { 9264.157, 2.007, 0.419, 0.464, 0.433 }, + { 9276.657, 2.004, 0.415, 0.487, 0.428 }, + { 9289.157, 1.975, 0.412, 0.464, 0.424 }, + { 9301.657, 1.950, 0.435, 0.311, 0.455 }, + { 0.0, 0.0, 0.0, 0.0, 0.0 } +}; + +/* Reference wavelenghts */ +const float kStd1Ref = 5275.644, + kStd2Ref = 5273.996, + kMuse1Ref = 7100.; + +/* Aproximation method */ +hdrl_airmass_approx typeAirmassAprox = HDRL_AIRMASS_APPROX_HARDIE; + + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_test_dar_correct() in various conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_test_dar_correct(void) +{ + /* create minimal headers for testing; first, add * + * generic stuff, same for both standard star exposures * + * PMAS has a position angle of about -90 deg, but the position * + * table to create the data orients it to a pos. angle of 0 deg. * + * add some fake pixel table limits */ + + cpl_propertylist *header1 = cpl_propertylist_new(); + cpl_propertylist_append_double(header1, "RA", 122.994945); + cpl_propertylist_append_double(header1, "DEC", 74.95304); + cpl_propertylist_append_double(header1, "LST", 25407.072748); + cpl_propertylist_append_double(header1, "EXPTIME", 120.); + cpl_propertylist_append_double(header1, "ESO TEL GEOLAT", 37.2236); + cpl_propertylist_append_double(header1, "ESO TEL AIRM START", 1.2784545043); + cpl_propertylist_append_double(header1, "ESO TEL AIRM END", 1.2776009017); + + cpl_propertylist *header2 = cpl_propertylist_new(); + cpl_propertylist_append_double(header2, "RA", 238.071555); + cpl_propertylist_append_double(header2, "DEC", 32.92533); + cpl_propertylist_append_double(header2, "LST", 60515.584209); + cpl_propertylist_append_double(header2, "EXPTIME", 300.); + cpl_propertylist_append_double(header2, "ESO TEL GEOLAT", 37.2236); + cpl_propertylist_append_double(header2, "ESO TEL AIRM START", 1.0233752603); + cpl_propertylist_append_double(header2, "ESO TEL AIRM END", 1.02725831881); + + cpl_propertylist *header3 = cpl_propertylist_new(); + cpl_propertylist_append_double(header3, "RA", 0.125); + cpl_propertylist_append_double(header3, "DEC", -30.); + cpl_propertylist_append_double(header3, "LST", 69446.2765265328); + cpl_propertylist_append_double(header3, "EXPTIME", 3600.); + cpl_propertylist_append_double(header3, "ESO TEL GEOLAT", -24.625278); + cpl_propertylist_append_double(header3, "ESO TEL AIRM START", 2.14734965358319); + cpl_propertylist_append_double(header3, "ESO TEL AIRM END", 1.5383756343353); + + /* Try again with a table that was astrometrically calibrated * + * this is PMAS data, so cannot use hdrl_wcs_create_default() */ + + cpl_propertylist *plWCS = cpl_propertylist_new(); + cpl_propertylist_append_string( plWCS, "CTYPE1", "RA---TAN" ); + cpl_propertylist_append_string( plWCS, "CTYPE2", "DEC--TAN" ); + cpl_propertylist_append_double( plWCS, "CRVAL1", 30.0 ); + cpl_propertylist_append_double( plWCS, "CRVAL2", 12.0 ); + cpl_propertylist_append_double( plWCS, "CRPIX1", 8. ); + cpl_propertylist_append_double( plWCS, "CRPIX2", 8. ); + cpl_propertylist_append_double( plWCS, "CD1_1", -0.2 /3600. ); + cpl_propertylist_append_double( plWCS, "CD1_2", 0. ); + cpl_propertylist_append_double( plWCS, "CD2_2", 0.2 /3600. ); + cpl_propertylist_append_double( plWCS, "CD2_1", 0. ); + cpl_propertylist_append_string( plWCS, "CUNIT1", "deg" ); + cpl_propertylist_append_string( plWCS, "CUNIT2", "deg" ); + cpl_propertylist_append_int( plWCS, "WCSAXES", 2 ); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(plWCS); + + + + /******* Charge data *************/ + + /* MUSE DataSheet 1 */ + cpl_size ind = 0; + while (kStd1[ind][0] > 1000. && ind - 1 < NMAX) { + ind++; + } + cpl_vector *lambdaIn1 = cpl_vector_new(ind); + cpl_vector *xShift1 = cpl_vector_new(ind); + cpl_vector *yShift1 = cpl_vector_new(ind); + cpl_vector *xShift1Err = cpl_vector_new(ind); + cpl_vector *yShift1Err = cpl_vector_new(ind); + cpl_vector *xCorrect1 = cpl_vector_new(ind); + cpl_vector *yCorrect1 = cpl_vector_new(ind); + ind = 0; + while (kStd1[ind][0] > 1000. && ind - 1 < NMAX) { + cpl_vector_set(lambdaIn1, ind, kStd1[ind][0]); + ind++; + } + + + /* MUSE DataSheet 2 */ + ind = 0; + while (kStd2[ind][0] > 1000. && ind - 1 < NMAX) { + ind++; + } + cpl_vector *lambdaIn2 = cpl_vector_new(ind); + cpl_vector *xShift2 = cpl_vector_new(ind); + cpl_vector *yShift2 = cpl_vector_new(ind); + cpl_vector *xShift2Err = cpl_vector_new(ind); + cpl_vector *yShift2Err = cpl_vector_new(ind); + cpl_vector *xCorrect2 = cpl_vector_new(ind); + cpl_vector *yCorrect2 = cpl_vector_new(ind); + + cpl_vector *xShift4 = cpl_vector_new(ind); + cpl_vector *xShift5 = cpl_vector_new(ind); + cpl_vector *xShift6 = cpl_vector_new(ind); + cpl_vector *xShift7 = cpl_vector_new(ind); + cpl_vector *xShift8 = cpl_vector_new(ind); + + cpl_vector *yShift4 = cpl_vector_new(ind); + cpl_vector *yShift5 = cpl_vector_new(ind); + cpl_vector *yShift6 = cpl_vector_new(ind); + cpl_vector *yShift7 = cpl_vector_new(ind); + cpl_vector *yShift8 = cpl_vector_new(ind); + + cpl_vector *xShift4Err = cpl_vector_new(ind); + cpl_vector *xShift5Err = cpl_vector_new(ind); + cpl_vector *xShift6Err = cpl_vector_new(ind); + cpl_vector *xShift7Err = cpl_vector_new(ind); + cpl_vector *xShift8Err = cpl_vector_new(ind); + + cpl_vector *yShift4Err = cpl_vector_new(ind); + cpl_vector *yShift5Err = cpl_vector_new(ind); + cpl_vector *yShift6Err = cpl_vector_new(ind); + cpl_vector *yShift7Err = cpl_vector_new(ind); + cpl_vector *yShift8Err = cpl_vector_new(ind); + + ind = 0; + while (kStd2[ind][0] > 1000. && ind - 1 < NMAX) { + cpl_vector_set(lambdaIn2, ind, kStd2[ind][0]); + ind++; + } + + + /* MUSE DataSheet 3 */ + ind = 0; + while (kMuse1[ind][0] > 1000. && ind - 1 < NMAX) { + ind++; + } + cpl_vector *lambdaIn3 = cpl_vector_new(ind); + cpl_vector *xShift3 = cpl_vector_new(ind); + cpl_vector *yShift3 = cpl_vector_new(ind); + cpl_vector *xShift3Err = cpl_vector_new(ind); + cpl_vector *yShift3Err = cpl_vector_new(ind); + cpl_vector *xCorrect3 = cpl_vector_new(ind); + cpl_vector *yCorrect3 = cpl_vector_new(ind); + ind = 0; + while (kMuse1[ind][0] > 1000. && ind - 1 < NMAX) { + cpl_vector_set(lambdaIn3, ind, kMuse1[ind][0]); + ind++; + } + + + /* Random value for errors */ + + double delta = 1e-2; + double deltaAirmass = 1e-4; + + double lambdaRefErr = delta; + double parangErr = delta; + double posangErr = delta; + double tempErr = delta; + double rhumErr = delta; + double presErr = delta; + + /********************* Do the test *************************/ + cpl_errorstate prestate; + + /* Input parameters and airmass (and error propagation) with MUSE datasheet 1 */ + hdrl_value ra1 = {cpl_propertylist_get_double(header1, "RA" ), 0.}; + hdrl_value dec1 = {cpl_propertylist_get_double(header1, "DEC" ), 0.}; + hdrl_value lst1 = {cpl_propertylist_get_double(header1, "LST" ), 0.}; + hdrl_value exptime1 = {cpl_propertylist_get_double(header1, "EXPTIME" ), 0.}; + hdrl_value geolat1 = {cpl_propertylist_get_double(header1, "ESO TEL GEOLAT" ), 0.}; + + ra1.error = deltaAirmass * fabs(ra1.data); + dec1.error = deltaAirmass * fabs(dec1.data); + lst1.error = deltaAirmass * fabs(lst1.data); + exptime1.error = deltaAirmass * fabs(exptime1.data); + geolat1.error = deltaAirmass * fabs(geolat1.data); + + hdrl_value airmass1 = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, typeAirmassAprox); + + hdrl_parameter *h_par1 = hdrl_dar_parameter_create( + (hdrl_value){ airmass1.data, airmass1.error}, + (hdrl_value){ -157.90507882793, parangErr * fabs(-157.90507882793)}, + (hdrl_value){ 0., posangErr * fabs(0.) +posangErr}, + (hdrl_value){ -6.2, tempErr * fabs(-6.2)}, + (hdrl_value){ 65., rhumErr * fabs(65.)}, + (hdrl_value){ 768.4, presErr * fabs(768.4)}, + wcs); + + /* Input parameters and airmass (and error propagation) with MUSE datasheet 2 */ + hdrl_value ra2 = {cpl_propertylist_get_double(header2, "RA" ), 0.}; + hdrl_value dec2 = {cpl_propertylist_get_double(header2, "DEC" ), 0.}; + hdrl_value lst2 = {cpl_propertylist_get_double(header2, "LST" ), 0.}; + hdrl_value exptime2 = {cpl_propertylist_get_double(header2, "EXPTIME" ), 0.}; + hdrl_value geolat2 = {cpl_propertylist_get_double(header2, "ESO TEL GEOLAT" ), 0.}; + + ra2.error = deltaAirmass * fabs(ra2.data); + dec2.error = deltaAirmass * fabs(dec2.data); + lst2.error = deltaAirmass * fabs(lst2.data); + exptime2.error = deltaAirmass * fabs(exptime2.data); + geolat2.error = deltaAirmass * fabs(geolat2.data); + + hdrl_value airmass2 = hdrl_utils_airmass(ra2, dec2, lst2, exptime2, geolat2, typeAirmassAprox); + + hdrl_parameter *h_par2 = hdrl_dar_parameter_create( + (hdrl_value){ airmass2.data, airmass2.error}, + (hdrl_value){ 65.577407, parangErr * fabs(65.577407)}, + (hdrl_value){ 0., posangErr * fabs(0.) + posangErr}, + (hdrl_value){ -5.7, tempErr * fabs(-5.7)}, + (hdrl_value){ 81., rhumErr * fabs(81.)}, + (hdrl_value){ 768.4, presErr * fabs(768.4)}, + wcs); + + + /* Input parameters and airmass (and error propagation) with MUSE datasheet 1 */ + hdrl_value ra3 = {cpl_propertylist_get_double(header3, "RA" ), 0.}; + hdrl_value dec3 = {cpl_propertylist_get_double(header3, "DEC" ), 0.}; + hdrl_value lst3 = {cpl_propertylist_get_double(header3, "LST" ), 0.}; + hdrl_value exptime3 = {cpl_propertylist_get_double(header3, "EXPTIME" ), 0.}; + hdrl_value geolat3 = {cpl_propertylist_get_double(header3, "ESO TEL GEOLAT" ), 0.}; + + ra3.error = deltaAirmass * fabs(ra3.data); + dec3.error = deltaAirmass * fabs(dec3.data); + lst3.error = deltaAirmass * fabs(lst3.data); + exptime3.error = deltaAirmass * fabs(exptime3.data); + geolat3.error = deltaAirmass * fabs(geolat3.data); + + hdrl_value airmass3 = hdrl_utils_airmass(ra3, dec3, lst3, exptime3, geolat3, typeAirmassAprox); + + hdrl_parameter *h_par3 = hdrl_dar_parameter_create( + (hdrl_value){ airmass3.data, airmass3.error}, + (hdrl_value){ -100.978115969, parangErr * fabs(-100.978115969)}, + (hdrl_value){ 0., posangErr * fabs(0.) + posangErr}, + (hdrl_value){ 10., tempErr * fabs(10.)}, + (hdrl_value){ 10., rhumErr * fabs(10.)}, + (hdrl_value){ 775., presErr * fabs(775.)}, + wcs); + + /********** Test hdrl_dar_wcs_get_scales with deformed scales **********/ + + /* Create propertylist for build a non-equal scale wcs */ + cpl_propertylist *header = cpl_propertylist_new(); + + const char *skeys[2] = {"CTYPE1", "CTYPE2"}; + const char *svals[2] = {"RA---ZPN", "DEC--ZPN"}; + for (int i = 0; i < 2; i++) { + cpl_propertylist_append_string(header,skeys[i],svals[i]); + } + + const char *dkeys[13] = {"CRVAL1", "CRVAL2", "CRPIX1", "CRPIX2", + "CD1_1", "CD1_2", "CD2_1", "CD2_2", "PV2_1", + "PV2_2", "PV2_3", "PV2_4", "PV2_5"}; + const double dvals[13] = {5.57368333333, -72.0576388889, 5401.6, 6860.8, + 5.81347849634012E-21, 9.49444444444444E-05, + -9.49444444444444E-05, -5.81347849634012E-21, + 1.0, 0.0, 42.0, 0.0, 0.0}; + for (int i = 0; i < 13; i++) { + cpl_propertylist_append_double(header,dkeys[i],dvals[i]); + } + + const char *ikeys[3] = {"NAXIS","NAXIS1","NAXIS2"}; + const int ivals[3] = {2, 2048, 2048}; + for (int i = 0; i < 3; i++) { + cpl_propertylist_append_int(header,ikeys[i],ivals[i]); + } + + /* Create the WCS header */ + cpl_wcs *wcsFake = cpl_wcs_new_from_propertylist(header); + + /* Test scales from WCS */ + double xscale, yscale; + cpl_test(hdrl_dar_wcs_get_scales(wcsFake, &xscale, &yscale) == CPL_ERROR_NONE); + + cpl_propertylist_delete(header); + cpl_wcs_delete(wcsFake); + + + /*************** Test of failure cases ************************/ + + /* Test failure case: Create hdrl_parameter with non valid data */ + cpl_test( hdrl_dar_parameter_create( (hdrl_value){-1.,0.}, + (hdrl_value){-1.,0.}, + (hdrl_value){-1.,0.}, + (hdrl_value){-1.,0.}, + (hdrl_value){-1.,0.}, + (hdrl_value){-1.,0.}, + NULL) == NULL); + + /* Test failure case: Null h_par input */ + hdrl_dar_compute( NULL, + (hdrl_value){kStd1Ref, lambdaRefErr * kStd1Ref}, + lambdaIn1, + xShift1, yShift1, + xShift1Err, yShift1Err); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* Test failure case: Null lambda input */ + hdrl_dar_compute( h_par1, + (hdrl_value){kStd1Ref, lambdaRefErr * kStd1Ref}, + NULL, + xShift1, yShift1, + xShift1Err, yShift1Err); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* Test failure case: Null xshift/yshift output */ + hdrl_dar_compute( h_par1, + (hdrl_value){kStd1Ref, lambdaRefErr * kStd1Ref}, + lambdaIn1, + NULL, NULL, + NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + + /*************** Test with Lambda fake (with NANs) *********************/ + + /* Test failure case: Lambda with NaNs */ + cpl_vector *lambdaIn = cpl_vector_new(1); + cpl_vector_set(lambdaIn, 0, NAN); + hdrl_dar_compute( h_par1, + (hdrl_value){kStd1Ref, lambdaRefErr * kStd1Ref}, + lambdaIn, + xShift1, yShift1, + xShift1Err, yShift1Err); + //cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_vector_delete(lambdaIn); + + + /********************* Test with MUSE real data *************************/ + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par1, + (hdrl_value){kStd1Ref, lambdaRefErr * kStd1Ref}, + lambdaIn1, + xShift1, yShift1, + xShift1Err, yShift1Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par2, + (hdrl_value){kStd2Ref, lambdaRefErr * kStd2Ref}, + lambdaIn2, + xShift2, yShift2, + xShift2Err, yShift2Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par3, + (hdrl_value){kMuse1Ref, lambdaRefErr * kMuse1Ref}, + lambdaIn3, + xShift3, yShift3, + xShift3Err, yShift3Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + + + /* check the result */ + + double size1 = cpl_vector_get_size(lambdaIn1); + cpl_vector_set_size(xCorrect1, size1); + cpl_vector_set_size(yCorrect1, size1); + for (cpl_size i = 0; i < cpl_vector_get_size(lambdaIn1); i++) { + cpl_vector_set(xCorrect1, i, -kStd1[i][1] / 0.2 + cpl_vector_get(xShift1, i)); + cpl_vector_set(yCorrect1, i, -kStd1[i][3] / 0.2 + cpl_vector_get(yShift1, i)); + } + + double size2 = cpl_vector_get_size(lambdaIn2); + cpl_vector_set_size(xCorrect2, size2); + cpl_vector_set_size(yCorrect2, size2); + for (cpl_size i = 0; i < cpl_vector_get_size(lambdaIn2); i++) { + cpl_vector_set(xCorrect2, i, -kStd2[i][1] / 0.2 + cpl_vector_get(xShift2, i)); + cpl_vector_set(yCorrect2, i, -kStd2[i][3] / 0.2 + cpl_vector_get(yShift2, i)); + } + + double size3 = cpl_vector_get_size(lambdaIn3); + cpl_vector_set_size(xCorrect3, size3); + cpl_vector_set_size(yCorrect3, size3); + for (cpl_size i = 0; i < cpl_vector_get_size(lambdaIn3); i++) { + cpl_vector_set(xCorrect3, i, -kMuse1[i][1] + cpl_vector_get(xShift3, i)); + cpl_vector_set(yCorrect3, i, kMuse1[i][3] + cpl_vector_get(yShift3, i)); + } + + + double x1mean = cpl_vector_get_mean( xCorrect1), + x1med = cpl_vector_get_median( xCorrect1), + x1std = cpl_vector_get_stdev( xCorrect1), + y1mean = cpl_vector_get_mean( yCorrect1), + y1med = cpl_vector_get_median( yCorrect1), + y1std = cpl_vector_get_stdev( yCorrect1); + + double x2mean = cpl_vector_get_mean( xCorrect2), + x2med = cpl_vector_get_median( xCorrect2), + x2std = cpl_vector_get_stdev( xCorrect2), + y2mean = cpl_vector_get_mean( yCorrect2), + y2med = cpl_vector_get_median( yCorrect2), + y2std = cpl_vector_get_stdev( yCorrect2); + + double x3mean = cpl_vector_get_mean( xCorrect3), + x3med = cpl_vector_get_median( xCorrect3), + x3std = cpl_vector_get_stdev( xCorrect3), + y3mean = cpl_vector_get_mean( yCorrect3), + y3med = cpl_vector_get_median( yCorrect3), + y3std = cpl_vector_get_stdev( yCorrect3); + + + /* Residual mean, median, and stdev should be below 1/10 pix; write tests * + * using account actual values if they provide more stringent constraints.*/ + + cpl_msg_info(cpl_func, "Std1: x %f(%f)+/-%f y %f(%f)+/-%f", + x1mean, x1med, x1std, y1mean, y1med, y1std); + cpl_test(fabs(x1mean) < 0.045 ); + cpl_test(fabs(x1med ) < 0.045 ); + cpl_test(fabs(x1std ) < 0.068 ); + + cpl_test(fabs(y1mean) < 0.0472); + cpl_test(fabs(y1med ) < 0.0632); + cpl_test(fabs(y1std ) < 0.085 ); + + cpl_test(fabs(x1mean) < x1std ); + cpl_test(fabs(x1med ) < x1std ); + + cpl_test(fabs(y1mean) < y1std ); + cpl_test(fabs(y1med ) < y1std ); + + cpl_msg_info(cpl_func, "Std2: x %f(%f)+/-%f y %f(%f)+/-%f", + x2mean, x2med, x2std, y2mean, y2med, y2std); + cpl_test(fabs(x2mean) < 0.020 ); + cpl_test(fabs(x2med ) < 0.0171); + cpl_test(fabs(x2std ) < 0.039 ); + + cpl_test(fabs(y2mean) < 0.015 ); + cpl_test(fabs(y2med ) < 0.014 ); + cpl_test(fabs(y2std ) < 0.024 ); + + cpl_test(fabs(x2mean) < x2std ); + cpl_test(fabs(x2med ) < x2std ); + + cpl_test(fabs(y2mean) < y2std ); + cpl_test(fabs(y2med ) < y2std ); + + /* Larger residuals because of scale "problem" with INM data */ + cpl_msg_info(cpl_func, "Muse1 x %f(%f)+/-%f y %f(%f)+/-%f", + x3mean, x3med, x3std, y3mean, y3med, y3std); + cpl_test(fabs(x3mean) < 0.27 ); + cpl_test(fabs(x3med ) < 0.13 ); + cpl_test(fabs(x3std ) < 0.58 ); + + cpl_test(fabs(y3mean) < 0.15 ); + cpl_test(fabs(y3med ) < 0.12 ); + cpl_test(fabs(y3std ) < 0.24 ); + + cpl_test(fabs(x3mean) < x3std ); + cpl_test(fabs(x3med ) < x3std ); + + cpl_test(fabs(y3mean) < y3std ); + cpl_test(fabs(y3med ) < y3std ); + + + /******* More test with MUSE data: header2 with other lambdaRef *******/ + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par2, + (hdrl_value){2000., lambdaRefErr * 2000.}, + lambdaIn2, + xShift4, yShift4, + xShift4Err, yShift4Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate)); + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par2, + (hdrl_value){7000., lambdaRefErr * 7000.}, + lambdaIn2, + xShift5, yShift5, + xShift5Err, yShift5Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate)); + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par2, + (hdrl_value){30000., lambdaRefErr * 30000.}, + lambdaIn2, + xShift6, yShift6, + xShift6Err, yShift6Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate)); + + + /*** Check MUSE data: header2 with other lambdaRef with/without errors ***/ + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par2, + (hdrl_value){19500., lambdaRefErr * 19500.}, + lambdaIn2, + xShift7, yShift7, + xShift7Err, yShift7Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate)); + + prestate = cpl_errorstate_get(); + cpl_test(hdrl_dar_compute( h_par2, + (hdrl_value){19500., 0.}, + lambdaIn2, + xShift8, yShift8, + xShift8Err, yShift8Err) + == CPL_ERROR_NONE); + cpl_test(cpl_errorstate_is_equal(prestate)); + + + /******************** Delete Storage memory **********************/ + + cpl_propertylist_delete(header1); header1 = NULL; + cpl_propertylist_delete(header2); header2 = NULL; + cpl_propertylist_delete(header3); header3 = NULL; + + cpl_propertylist_delete(plWCS); plWCS = NULL; + + cpl_wcs_delete(wcs); + + cpl_vector_delete(lambdaIn1); + cpl_vector_delete(lambdaIn2); + cpl_vector_delete(lambdaIn3); + + cpl_vector_delete(xShift1); cpl_vector_delete(yShift1); + cpl_vector_delete(xShift2); cpl_vector_delete(yShift2); + cpl_vector_delete(xShift3); cpl_vector_delete(yShift3); + cpl_vector_delete(xShift4); cpl_vector_delete(yShift4); + cpl_vector_delete(xShift5); cpl_vector_delete(yShift5); + cpl_vector_delete(xShift6); cpl_vector_delete(yShift6); + cpl_vector_delete(xShift7); cpl_vector_delete(yShift7); + cpl_vector_delete(xShift8); cpl_vector_delete(yShift8); + + cpl_vector_delete(xShift1Err); cpl_vector_delete(yShift1Err); + cpl_vector_delete(xShift2Err); cpl_vector_delete(yShift2Err); + cpl_vector_delete(xShift3Err); cpl_vector_delete(yShift3Err); + cpl_vector_delete(xShift4Err); cpl_vector_delete(yShift4Err); + cpl_vector_delete(xShift5Err); cpl_vector_delete(yShift5Err); + cpl_vector_delete(xShift6Err); cpl_vector_delete(yShift6Err); + cpl_vector_delete(xShift7Err); cpl_vector_delete(yShift7Err); + cpl_vector_delete(xShift8Err); cpl_vector_delete(yShift8Err); + + cpl_vector_delete(xCorrect1); cpl_vector_delete(yCorrect1); + cpl_vector_delete(xCorrect2); cpl_vector_delete(yCorrect2); + cpl_vector_delete(xCorrect3); cpl_vector_delete(yCorrect3); + + hdrl_parameter_delete(h_par1); + hdrl_parameter_delete(h_par2); + hdrl_parameter_delete(h_par3); + + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of DAR + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_test_dar_correct(); + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_der_snr-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_der_snr-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_der_snr-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_der_snr-test.c 2017-09-14 13:12:16.000000000 +0000 @@ -0,0 +1,300 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_DER_SNR.h" +#include "hdrl_spectrum.h" +#include "hdrl_random.h" + +#include +#include +#include +#include + + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_der_snr_test + */ +/*----------------------------------------------------------------------------*/ + +static inline cpl_image * get_noisy_flux(const cpl_image * img); + +#define ARR_SIZE(a) ((cpl_size)((sizeof((a)) / sizeof((a[0]))))) + +static inline +cpl_image * get_error(const int* data, const int* map, cpl_size length){ + /* map[j] is the position in unsorted where the j-th element is going to + * be inserted*/ + cpl_array * wav = cpl_array_new(length, HDRL_TYPE_DATA); + cpl_image * flux = cpl_image_new(length, 1, HDRL_TYPE_DATA); + + for(cpl_size j = 0; j < length; ++j){ + cpl_image_set(flux, map[j] + 1, 1, data[j]); + cpl_array_set(wav, map[j], j + 1); + } + + const hdrl_data_t *flux_p = + (const hdrl_data_t *)cpl_image_get_data_const(flux); + + const cpl_binary *msk = NULL; + cpl_image *flux_e = estimate_noise_DER_SNR(flux_p, msk, wav, length, 5); + + cpl_image_delete(flux); + cpl_array_delete(wav); + + return flux_e; +} + +void test_DER_SNR_sort(void){ + + int data[] = { + 1, 5, 10, 5, 23, 1, 8, 17, 21, 7, 11, 13, 5, 99, 12, 4, + 1, 5, 10, 5, 23, 1, 8, 17, 21, 7, 11, 13, 5, 99, 12, 4 + }; + + int map1[ARR_SIZE(data)] = {0}; + int map2[ARR_SIZE(data)] = {0}; + + const cpl_size length = ARR_SIZE(data); + + for(cpl_size i = 0; i < length; ++i){ + map1[i] = i; + map2[i] = i; + } + + for(cpl_size i = 0; i < length; ++i){ + + const cpl_size source = i; + const cpl_size dest = ((double)rand() / (double)RAND_MAX) * (length - 1); + + cpl_test(dest >= 0 && dest < length); + + const int data_s = map1[source]; + const int data_d = map1[dest]; + + map1[source] = data_d; + map1[dest] = data_s; + } + + cpl_image * flux_e_unsorted = get_error(data, map1, length); + cpl_image * flux_e_sorted = get_error(data, map2, length); + + /* map1[i] is the position in unsorted where the i-th element of sorted + * is inserted.*/ + for(cpl_size i = 0; i < length; ++i){ + int rej1; + const double data1 = cpl_image_get(flux_e_sorted, i + 1, 1, &rej1); + + int rej2; + const double data2 = cpl_image_get(flux_e_unsorted, map1[i] + 1, 1, &rej2); + + cpl_test_eq(rej1, rej2); + cpl_test_abs(data1, data2, 1e-3); + } + + cpl_image_delete(flux_e_sorted); + cpl_image_delete(flux_e_unsorted); +} + +void test_DER_SNR(void){ + + int data[] = { + 1, 5, 10, 5, 23, 1, 8, 17, 21, 7, 11, 13, 5, 99, 12, 4, + 1, 5, 10, 5, 23, 1, 8, 17, 21, 7, 11, 13, 5, 99, 12, 4 + }; + + cpl_array * wav = cpl_array_new(ARR_SIZE(data), HDRL_TYPE_DATA); + cpl_image * flux = cpl_image_new(ARR_SIZE(data), 1, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < ARR_SIZE(data); ++i){ + cpl_image_set(flux, i +1, 1, data[i]); + cpl_array_set(wav, i, i + 1); + } + + const hdrl_data_t * flux_p = + (const hdrl_data_t *)cpl_image_get_data_const(flux); + + const cpl_binary *msk = NULL; + hdrl_data_t err = + estimate_noise_window(flux_p, msk, 0, + ARR_SIZE(data) - 1, ARR_SIZE(data)); + cpl_test_abs(err, 12.105, 1e-3); + + cpl_image * flux_e = estimate_noise_DER_SNR(flux_p, msk, wav, + ARR_SIZE(data), 5); + + cpl_test_eq(cpl_image_get_size_x(flux), cpl_image_get_size_x(flux_e)); + cpl_test_eq(cpl_image_get_size_y(flux), cpl_image_get_size_y(flux_e)); + + int rej = 0; + err = cpl_image_get(flux_e, 7, 1, &rej); + cpl_test_abs(err, 13.921, 1e-3); + + err = cpl_image_get(flux_e, 6, 1, &rej); + cpl_test_abs(err, 13.921, 1e-3); + + err = cpl_image_get(flux_e, 1, 1, &rej); + cpl_test_abs(err, 2.421, 1e-3); + + cpl_image_delete(flux_e); + + + /*bad pixel is bad also in error*/ + cpl_image_reject(flux, 2, 1); + + flux_p = (const hdrl_data_t *)cpl_image_get_data_const(flux); + const cpl_mask *mask = cpl_image_get_bpm_const(flux); + msk = cpl_mask_get_data_const(mask); + + flux_e = estimate_noise_DER_SNR(flux_p, msk, wav, ARR_SIZE(data), 5); + + cpl_test(cpl_image_is_rejected(flux_e, 2, 1)); + + /*bad pixels in window are skipped*/ + err = cpl_image_get(flux_e, 6, 1, &rej); + cpl_test_abs(err, 14.829, 1e-3); + cpl_test_eq(rej, 0); + + /*good pixel surrounded by bad pixels so that there is no pixel to calculate + * error, becomes bad*/ + cpl_image_delete(flux_e); + + for(cpl_size i = 1; i <= 11; i++) + { + if(i == 6) continue; + cpl_image_reject(flux, i, 1); + } + + flux_p = (const hdrl_data_t *)cpl_image_get_data_const(flux); + mask = cpl_image_get_bpm_const(flux); + msk = cpl_mask_get_data_const(mask); + + flux_e = estimate_noise_DER_SNR(flux_p, msk, wav, ARR_SIZE(data), 5); + cpl_test(cpl_image_is_rejected(flux_e, 6, 1)); + cpl_test(!cpl_image_is_rejected(flux, 6, 1)); + + cpl_image_delete(flux_e); + cpl_image_delete(flux); + cpl_array_delete(wav); +} + +void test_DER_SNR_performance(void){ + + static const int sz = 2000; + static const double delta = 3.14 / 2000.0; + static const double peak = 1e3; + static const int n_iter = 100; + + cpl_image * flux = cpl_image_new(sz, 1, HDRL_TYPE_DATA); + cpl_array * lambdas = cpl_array_new(sz, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < sz; i++){ + double x = delta * (i+1); + cpl_array_set(lambdas, i, x); + cpl_image_set(flux, i + 1, 1, peak * sin(x)); + } + + cpl_image * std_dev_theo = cpl_image_power_create(flux, 1./2.); + cpl_image * DER_SNR_avg = cpl_image_new(sz, 1,HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < n_iter; ++i){ + cpl_image * noisy_flux_i = get_noisy_flux(flux); + + const hdrl_data_t * noisy_flux = + (const hdrl_data_t *)cpl_image_get_data_const(noisy_flux_i); + + const cpl_binary *msk = NULL; + cpl_image * e = estimate_noise_DER_SNR(noisy_flux, msk, lambdas, sz, 5); + + cpl_image_divide_scalar(e, n_iter); + cpl_image_add(DER_SNR_avg, e); + cpl_image_delete(e); + + cpl_image_delete(noisy_flux_i); + } + + cpl_image * ratio = cpl_image_divide_create(std_dev_theo, DER_SNR_avg); + double avg_ratio = cpl_image_get_absflux(ratio) / sz; + + cpl_test_leq(avg_ratio, 1.1); + cpl_test_leq(.9, avg_ratio); + + cpl_image_delete(flux); + cpl_image_delete(DER_SNR_avg); + cpl_array_delete(lambdas); + cpl_image_delete(ratio); + cpl_image_delete(std_dev_theo); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of DER_SNR calculation module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + srand (time(NULL)); + + test_DER_SNR(); + test_DER_SNR_sort(); + test_DER_SNR_performance(); + + return cpl_test_end(0); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Private functions + **/ +/*----------------------------------------------------------------------------*/ +static inline +cpl_image * get_noisy_flux(const cpl_image * img){ + + cpl_size sx = cpl_image_get_size_x(img); + cpl_size sy = cpl_image_get_size_y(img); + + cpl_image * to_ret = cpl_image_new(sx, sy, HDRL_TYPE_DATA); + + hdrl_random_state * rng = hdrl_random_state_new(1, NULL); + + for(cpl_size x = 1; x <= sx; x++){ + for(cpl_size y = 1; y <= sy; y++){ + int rej = 0; + double clean_value = cpl_image_get(img, x, y, &rej); + double noisy_value = hdrl_random_poisson(rng, clean_value); + cpl_image_set(to_ret, x, y, noisy_value); + } + } + + hdrl_random_state_delete(rng); + return to_ret; +} + + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_efficiency-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_efficiency-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_efficiency-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_efficiency-test.c 2017-08-21 13:54:20.000000000 +0000 @@ -0,0 +1,301 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "../hdrl_efficiency.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_efficiency_test + */ +/*----------------------------------------------------------------------------*/ + +void test_efficiency(void){ + + cpl_size sz = 10; + cpl_image * flux = cpl_image_new(sz,1, CPL_TYPE_DOUBLE); + cpl_image * flux_e = cpl_image_new(sz,1, CPL_TYPE_DOUBLE); + cpl_array * waves = cpl_array_new(sz, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_image_set(flux, i + 1, 1, (i + 1) * 2.5); + cpl_image_set(flux_e, i + 1, 1, (i + 1) * .02); + cpl_array_set(waves, i, (i + 1) * 3.0); + } + + hdrl_spectrum1D * sp_obs = + hdrl_spectrum1D_create(flux, flux_e, waves, hdrl_spectrum1D_wave_scale_linear); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_image_set(flux, i + 1, 1, (i + 1) * 0.5); + cpl_image_set(flux_e, i + 1, 1, 0.0); + cpl_array_set(waves, i, (i + 1) * 3.0); + } + + hdrl_spectrum1D * sp_std = + hdrl_spectrum1D_create(flux, flux_e, waves, hdrl_spectrum1D_wave_scale_linear); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_image_set(flux, i + 1, 1, (i + 1) * 1.5); + cpl_image_set(flux_e, i + 1, 1, 0.0); + cpl_array_set(waves, i, (i + 1) * 3.0); + } + + hdrl_spectrum1D * sp_ext = + hdrl_spectrum1D_create(flux, flux_e, waves, hdrl_spectrum1D_wave_scale_linear); + + + hdrl_parameter * pars = hdrl_efficiency_parameter_create( + (hdrl_value){1.2, 0.0}, + (hdrl_value){0.4, 0.0}, + (hdrl_value){11.*12., 0.0}, + (hdrl_value){1.1, 0.0}, + (hdrl_value){2.2, 0.0}); + + hdrl_spectrum1D * sp_eff = + hdrl_efficiency_compute(sp_obs, sp_std, sp_ext, pars); + + hdrl_parameter_delete(pars); pars = NULL; + + hdrl_value v = hdrl_spectrum1D_get_flux_value(sp_eff, 3, NULL); + cpl_test_abs(v.data, 3.75528e-06, 1e-5); + cpl_test_abs(v.error, 3.00422e-08, 1e-5); + + cpl_array_delete(waves); + cpl_image_delete(flux); + cpl_image_delete(flux_e); + hdrl_spectrum1D_delete(&sp_obs); + hdrl_spectrum1D_delete(&sp_std); + hdrl_spectrum1D_delete(&sp_eff); + hdrl_spectrum1D_delete(&sp_ext); +} + +/* Given the simplified formula: I_std * 10 ^(0.4 * E_x)* E_ph we calculated the + * analytical error propagation function using the Wolfram Alpha website and we + * check this analytical model against the error propagation in the hdrl library.*/ +hdrl_value get_error(const hdrl_value s, const hdrl_value x, const hdrl_data_t l){ + hdrl_error_t err = (hdrl_error_t)(exp(1.84207 * x.data)); + err *= (hdrl_error_t)(0.848304 * pow(x.error, 2.0) * pow(s.data, 2.0) + + pow(s.error, 2.0)); + + hdrl_data_t ephot = (hdrl_data_t)fabs(E_ph(l).data); + hdrl_data_t data = (hdrl_data_t)(s.data * pow(10.0, 0.4 * x.data)); + + const hdrl_value to_ret = {data * ephot, sqrt(err) * (hdrl_error_t)ephot}; + return to_ret; +} + +/* test error propagation using analytical model. We simplify the problem, + * everything, except extinction and observed spectrum are considered error-free. + * The values are set so that the formula becomes = I_std * 10 ^(0.4 * E_x)* E_ph. + * We want to exercise the exponential which has been implemented for this feature.*/ +void test_efficiency_error_propagation(void){ + + const cpl_size len = 20; + + cpl_image * std_obs_flux = cpl_image_new(len, 1, CPL_TYPE_DOUBLE); + cpl_image * std_obs_flux_e = cpl_image_new(len, 1, CPL_TYPE_DOUBLE); + + cpl_image * std_model_flux = cpl_image_new(len, 1, CPL_TYPE_DOUBLE); + cpl_image * std_model_flux_e = cpl_image_new(len, 1, CPL_TYPE_DOUBLE); + + cpl_image * ext_flux = cpl_image_new(len, 1, CPL_TYPE_DOUBLE); + cpl_image * ext_flux_e = cpl_image_new(len, 1, CPL_TYPE_DOUBLE); + + cpl_array * wave = cpl_array_new(len, CPL_TYPE_DOUBLE); + + hdrl_value Ap = {3.0, 0.0}; + hdrl_value Am = {2.0, 0.0}; + hdrl_value G = {1.0, 0.0}; + hdrl_value Tex = {1.0, 0.0}; + hdrl_value Atel = {1.0, 0.0}; + + + for(cpl_size i = 0; i < len; ++i){ + + const double l = (i * .3 + 1.0) * 1e-4; + cpl_array_set(wave, i, l); + + cpl_image_set(std_obs_flux, i + 1, 1, sin(l * CPL_MATH_PI)); + cpl_image_set(std_obs_flux_e, i + 1, 1, 0.2 * sin(l * CPL_MATH_PI)); + + cpl_image_set(ext_flux, i + 1, 1, 1.7 * sin(l * CPL_MATH_PI)); + cpl_image_set(ext_flux_e, i + 1, 1, 0.02 * sin(l * CPL_MATH_PI)); + + /* denominator must be always 1*/ + cpl_image_set(std_model_flux, i + 1, 1, 1.0); + cpl_image_set(std_model_flux_e, i + 1, 1, 0.0); + } + + hdrl_spectrum1D * I_std = hdrl_spectrum1D_create(std_obs_flux, std_obs_flux_e, + wave, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * I_ref_std = hdrl_spectrum1D_create(std_model_flux, + std_model_flux_e, wave, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * ext = hdrl_spectrum1D_create(ext_flux, ext_flux_e, + wave, hdrl_spectrum1D_wave_scale_linear); + + cpl_image_delete(std_obs_flux); + cpl_image_delete(std_obs_flux_e); + + cpl_image_delete(std_model_flux); + cpl_image_delete(std_model_flux_e); + + cpl_image_delete(ext_flux); + cpl_image_delete(ext_flux_e); + + + hdrl_parameter * pars = + hdrl_efficiency_parameter_create(Ap, Am, G, Tex, Atel); + + hdrl_spectrum1D * eff = hdrl_efficiency_compute(I_std, + I_ref_std, ext, pars); + + for(cpl_size i = 0; i < len; ++i){ + int rej; + const hdrl_value eff_i1 = hdrl_spectrum1D_get_flux_value(eff, i, &rej); + + const hdrl_value I_std_i = hdrl_spectrum1D_get_flux_value(I_std, i, &rej); + const hdrl_value ext_i = hdrl_spectrum1D_get_flux_value(ext, i, &rej); + + const hdrl_data_t w = cpl_array_get(wave, i, &rej); + + const hdrl_value eff_i2 = get_error(I_std_i, ext_i, w); + + cpl_test_rel(eff_i1.data, eff_i2.data, 1e-5); + cpl_test_rel(eff_i1.error, eff_i2.error, 1e-5); + } + + cpl_array_delete(wave); + + hdrl_parameter_delete(pars); + + hdrl_spectrum1D_delete(&I_std); + hdrl_spectrum1D_delete(&I_ref_std); + hdrl_spectrum1D_delete(&ext); + + hdrl_spectrum1D_delete(&eff); +} + +void test_efficiency_spectrum_external_to_models(void){ + + cpl_size sz = 10; + cpl_image * flux = cpl_image_new(sz,1, CPL_TYPE_DOUBLE); + cpl_image * flux_e = cpl_image_new(sz,1, CPL_TYPE_DOUBLE); + cpl_array * waves = cpl_array_new(sz, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_image_set(flux, i + 1, 1, (i + 1) * 2.5); + cpl_image_set(flux_e, i + 1, 1, (i + 1) * .02); + + if(i == sz - 1) + cpl_array_set(waves, i, 3.0 * (sz + 5)); + else + cpl_array_set(waves, i, (i - 1) * 3.0); + } + + cpl_array * waves_obs = cpl_array_duplicate(waves); + + hdrl_spectrum1D * sp_obs = + hdrl_spectrum1D_create(flux, flux_e, waves, hdrl_spectrum1D_wave_scale_linear); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_image_set(flux, i + 1, 1, (i + 1) * 0.5); + cpl_image_set(flux_e, i + 1, 1, 0.0); + cpl_array_set(waves, i, (i + 1) * 3.0); + } + + hdrl_spectrum1D * sp_std = + hdrl_spectrum1D_create(flux, flux_e, waves, hdrl_spectrum1D_wave_scale_linear); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_image_set(flux, i + 1, 1, (i + 1) * 1.5); + cpl_image_set(flux_e, i + 1, 1, 0.0); + cpl_array_set(waves, i, (i + 2) * 3.0); + } + + hdrl_spectrum1D * sp_ext = + hdrl_spectrum1D_create(flux, flux_e, waves, hdrl_spectrum1D_wave_scale_linear); + + + hdrl_parameter * pars = hdrl_efficiency_parameter_create( + (hdrl_value){1.2, 0.0}, + (hdrl_value){0.4, 0.0}, + (hdrl_value){11. * 12., 0.0}, + (hdrl_value){1.1, 0.0}, + (hdrl_value){2.2, 0.0}); + + hdrl_spectrum1D * sp_eff = + hdrl_efficiency_compute(sp_obs, sp_std, sp_ext, pars); + + hdrl_parameter_delete(pars); pars = NULL; + + cpl_test_eq(hdrl_spectrum1D_get_size(sp_eff), sz - 4); + + const cpl_array * wavs_eff = + hdrl_spectrum1D_get_wavelength(sp_eff).wavelength; + + for(cpl_size i = 3; i < sz - 1; ++i){ + + double w_f = cpl_array_get(wavs_eff, i - 3, NULL); + double w_obs = cpl_array_get(waves_obs, i, NULL); + + cpl_test_rel(w_f, w_obs, 1e-16); + } + + cpl_array_delete(waves); + cpl_array_delete(waves_obs); + cpl_image_delete(flux); + cpl_image_delete(flux_e); + hdrl_spectrum1D_delete(&sp_obs); + hdrl_spectrum1D_delete(&sp_std); + hdrl_spectrum1D_delete(&sp_eff); + hdrl_spectrum1D_delete(&sp_ext); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of efficiency calculation module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_efficiency(); + test_efficiency_error_propagation(); + test_efficiency_spectrum_external_to_models(); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_elemop-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_elemop-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_elemop-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_elemop-test.c 2017-09-15 08:49:15.000000000 +0000 @@ -0,0 +1,1244 @@ +/* $Id: hdrl_elemop-test.c,v 1.4 2013-09-25 12:06:52 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-09-25 12:06:52 $ + * $Revision: 1.4 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_elemop.h" +#include "hdrl_types.h" +#include + +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_elemop_test Testing of the HDRL variance module + */ +/*----------------------------------------------------------------------------*/ + +static cpl_error_code +hdrl_test_add(void) +{ + { + hdrl_data_t a = 0., b = 0.; + hdrl_error_t ea = 0., eb = 0.; + hdrl_elemop_add(&a, &ea, 1, &b, &eb, 2, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + const hdrl_data_t b = 2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_add(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, 4., HDRL_EPS_DATA); + cpl_test_rel(ea, sqrt(0.5), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + + hdrl_elemop_add(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 4., HDRL_EPS_DATA); + cpl_test_rel(ea, sqrt(1.0), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b[] = {-2, 6}; + const hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_add(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL); + + cpl_test_rel(a[0], 0., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR); + cpl_test_rel(a[1], 9., HDRL_EPS_DATA); + cpl_test_rel(ea[1], sqrt(1 * 1 + 3 * 3), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + + hdrl_elemop_add(a, ea, ARRAY_LEN(a), a, ea, ARRAY_LEN(a), NULL); + + cpl_test_rel(a[0], 4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], 1, HDRL_EPS_ERROR); + cpl_test_rel(a[1], 6., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 2., HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_add(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL); + + cpl_test_rel(a[0], 0., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR); + cpl_test_rel(a[1], 1., HDRL_EPS_DATA); + cpl_test_rel(ea[1], sqrt(1 * 1 + 0.5 * 0.5), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + cpl_binary mask[] = {0, 1}; + + hdrl_elemop_add(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask); + + cpl_test_rel(a[0], 0., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR); + cpl_test_rel(a[1], 3., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR); + } + + /*{ + hdrl_data_t a = 2; + hdrl_error_t ea = 0.7; + hdrl_data_t a2 = a; + hdrl_error_t ea2 = ea; + const hdrl_data_t b = 2; + const hdrl_error_t eb = 0.7; + const double covab = 1; + + hdrl_elemop_add(&a, &ea, &a, &ea, 1); + hdrl_elemop_add_cov(&a2, &ea2, &b, &eb, &covab, 1); + + cpl_test_rel(a, a2, HDRL_EPS_DATA); + cpl_test_rel(ea, ea2, HDRL_EPS_ERROR); + cpl_test_rel(ea, 1.4, HDRL_EPS_ERROR); + }*/ + + return cpl_error_get_code(); +} + +static cpl_error_code +hdrl_test_sub(void) +{ + { + hdrl_data_t a = 0., b = 0.; + hdrl_error_t ea = 0., eb = 0.; + hdrl_elemop_sub(&a, &ea, 1, &b, &eb, 2, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + const hdrl_data_t b = 2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_sub(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, 0., HDRL_EPS_DATA); + cpl_test_rel(ea, sqrt(0.5), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + + hdrl_elemop_sub(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 0., HDRL_EPS_DATA); + cpl_test_rel(ea, 0., HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b[] = {-2, 6}; + const hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_sub(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL); + + cpl_test_rel(a[0], 4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR); + cpl_test_rel(a[1], -3., HDRL_EPS_DATA); + cpl_test_rel(ea[1], sqrt(1 * 1 + 3 * 3), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + + hdrl_elemop_sub(a, ea, ARRAY_LEN(a), a, ea, ARRAY_LEN(a), NULL); + + cpl_test_rel(a[0], 0., HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0., HDRL_EPS_ERROR); + cpl_test_rel(a[1], 0., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 0., HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_sub(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL); + + cpl_test_rel(a[0], 4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR); + cpl_test_rel(a[1], 5., HDRL_EPS_DATA); + cpl_test_rel(ea[1], sqrt(1 * 1 + 0.5 * 0.5), HDRL_EPS_ERROR); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + cpl_binary mask[] = {0, 1}; + + hdrl_elemop_sub(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask); + + cpl_test_rel(a[0], 4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(0.5), HDRL_EPS_ERROR); + cpl_test_rel(a[1], 3., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR); + } + + return cpl_error_get_code(); +} + + +static cpl_error_code +hdrl_test_mul(void) +{ + { + hdrl_data_t a = 0., b = 0.; + hdrl_error_t ea = 0., eb = 0.; + hdrl_elemop_mul(&a, &ea, 1, &b, &eb, 2, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + const hdrl_data_t b = 3; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_mul(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, 6., HDRL_EPS_DATA); + cpl_test_rel(ea, sqrt(3.25), HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + + hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 4., HDRL_EPS_DATA); + cpl_test_rel(ea, 2., HDRL_EPS_ERROR * 10); + + a = 1.7; + ea = 2.8; + + hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 1.7 * 1.7, HDRL_EPS_DATA); + cpl_test_rel(ea, 9.52, HDRL_EPS_ERROR * 10); + + a = -1.7; + ea = 2.8; + + hdrl_elemop_mul(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 1.7 * 1.7, HDRL_EPS_DATA); + cpl_test_rel(ea, 9.52, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b[] = {-2, 6}; + const hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_mul(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL); + + cpl_test_rel(a[0], -4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(2), HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 18., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 10.816653826391969, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_mul(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL); + + cpl_test_rel(a[0], -4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(2.), HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], -6., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 2.5, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + cpl_binary mask[] = {0, 1}; + + hdrl_elemop_mul(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask); + + cpl_test_rel(a[0], -4., HDRL_EPS_DATA); + cpl_test_rel(ea[0], sqrt(2.), HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 3., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR); + } + + /* { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.7; + hdrl_data_t a2 = a; + hdrl_error_t ea2 = ea; + const hdrl_data_t b = 2; + const hdrl_error_t eb = 0.7; + const double covab = 1; + + hdrl_elemop_mul(&a, &ea, &a, &ea, 1); + hdrl_elemop_mul_cov(&a2, &ea2, &b, &eb, &covab, 1); + + cpl_test_rel(a, a2, HDRL_EPS_DATA); + cpl_test_rel(ea, ea2, HDRL_EPS_ERROR); + cpl_test_rel(ea, 2.8, HDRL_EPS_ERROR); + } */ + + return cpl_error_get_code(); +} + + +static cpl_error_code +hdrl_test_div(void) +{ + { + hdrl_data_t a = 0., b = 0.; + hdrl_error_t ea = 0., eb = 0.; + hdrl_elemop_div(&a, &ea, 1, &b, &eb, 2, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + const hdrl_data_t b = 3; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_div(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, 2. / 3., HDRL_EPS_DATA); + cpl_test_rel(ea, 0.20030840419244383, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a = 2; + hdrl_error_t ea = 0.5; + + hdrl_elemop_div(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 1., HDRL_EPS_DATA); + cpl_test_rel(ea, 0., HDRL_EPS_ERROR * 10); + + a = 1.7; + ea = 2.8; + + hdrl_elemop_div(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, 1., HDRL_EPS_DATA); + cpl_test_rel(ea, 0., HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b[] = {-2, 6}; + const hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL); + + cpl_test_rel(a[0], -1., HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 3./6., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 0.3004626062886658, HDRL_EPS_ERROR * 10); + } + + /* division by 0. */ + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + hdrl_data_t b[] = {-2, 0.}; + const hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL); + + cpl_test_rel(a[0], -1., HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10); + cpl_test(isnan(a[1])); + cpl_test(isnan(ea[1])); + + b[0] = 0.; + hdrl_elemop_div(a, ea, ARRAY_LEN(a), b, eb, 1, NULL); + + cpl_test(isnan(a[0])); + cpl_test(isnan(ea[0])); + cpl_test(isnan(a[1])); + cpl_test(isnan(ea[1])); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_div(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL); + + cpl_test_rel(a[0], -1., HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], -3. / 2., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 0.625, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + cpl_binary mask[] = {0, 1}; + + hdrl_elemop_div(a, ea, ARRAY_LEN(a), &b, &eb, 1, mask); + + cpl_test_rel(a[0], -1., HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.35355339059327379, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 3., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR); + } + + return cpl_error_get_code(); +} + +static cpl_error_code +hdrl_test_pow(void) +{ + { + hdrl_data_t a = 0., b = 0.; + hdrl_error_t ea = 0., eb = 0.; + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 2, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + } + + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.5; + + hdrl_elemop_pow(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, pow(1.2, 1.2), HDRL_EPS_DATA); + cpl_test_rel(ea, 0.7357378647225408, HDRL_EPS_ERROR * 10); + } + + /* square root test */ + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.6; + hdrl_data_t b = 0.5; + hdrl_error_t eb = 0.; + + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, sqrt(1.2), HDRL_EPS_DATA); + cpl_test_rel(ea, 0.27386127875258304, HDRL_EPS_ERROR * 10); + + a = -1.2; + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test(isnan(a)); + cpl_test(isnan(ea)); + + /* negative value test */ + a = -1.2; + ea = 0.6; + b = 3.; + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, pow(-1.2, 3.), HDRL_EPS_DATA); + cpl_test_rel(ea, 2.592, HDRL_EPS_ERROR * 10); + } + + /* pow with error free power 2 exponent == repeated multiplication */ + { + hdrl_data_t a = -1.2; + hdrl_error_t ea = 0.5; + hdrl_data_t b = 2.0; + hdrl_error_t eb = 0.0; + + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + hdrl_data_t a2 = -1.2; + hdrl_error_t ea2 = 0.5; + hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL); + + cpl_test_rel(a, a2, HDRL_EPS_DATA); + cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10); + + a = -1.2; + ea = 0.5; + b = 4.0; + eb = 0.0; + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL); + cpl_test_rel(a, a2, HDRL_EPS_DATA); + cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10); + } + /* array pow with error free power 2 exponent == repeated multiplication */ + { + hdrl_data_t a[] = {0.3, 10.}; + hdrl_error_t ea[] = {0.5, 2.}; + hdrl_data_t b[] = {2.0, 2.0}; + hdrl_error_t eb[] = {0., 0.}; + + hdrl_elemop_pow(a, ea, 2, b, eb, 2, NULL); + + hdrl_data_t a2[] = {0.3, 10.}; + hdrl_error_t ea2[] = {0.5, 2.}; + hdrl_elemop_mul(a2, ea2, 2, a2, ea2, 2, NULL); + + cpl_test_rel(a[0], a2[0], HDRL_EPS_DATA); + cpl_test_rel(ea[0], ea2[0], HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], a2[1], HDRL_EPS_DATA); + cpl_test_rel(ea[1], ea2[1], HDRL_EPS_ERROR * 10); + } + + /* pow with error free -1 exponent == reciprocal */ + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.5; + hdrl_data_t b = -1.0; + hdrl_error_t eb = 0.0; + + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + hdrl_data_t a2 = 1.0; + hdrl_error_t ea2 = 0.; + hdrl_data_t b2 = 1.2; + hdrl_error_t eb2 = 0.5; + hdrl_elemop_div(&a2, &ea2, 1, &b2, &eb2, 1, NULL); + + cpl_test_rel(a, a2, HDRL_EPS_DATA); + cpl_test_rel(ea, ea2, HDRL_EPS_ERROR * 10); + } + + /* array pow with error free -1 exponent == reciprocal*/ + { + hdrl_data_t a[] = {0.3, 10.}; + hdrl_error_t ea[] = {0.5, 2.}; + hdrl_data_t b[] = {-1.0, -1.0}; + hdrl_error_t eb[] = {0., 0.}; + + hdrl_elemop_pow(a, ea, 2, b, eb, 2, NULL); + + hdrl_data_t a2[] = {1.0, 1.0}; + hdrl_error_t ea2[] = {0., 0.}; + hdrl_data_t b2[] = {0.3, 10.}; + hdrl_error_t eb2[] = {0.5, 2.}; + hdrl_elemop_div(a2, ea2, 2, b2, eb2, 2, NULL); + + cpl_test_rel(a[0], a2[0], HDRL_EPS_DATA); + cpl_test_rel(ea[0], ea2[0], HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], a2[1], HDRL_EPS_DATA); + cpl_test_rel(ea[1], ea2[1], HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.5; + hdrl_data_t b = 2.0; + hdrl_error_t eb = 2.0; + + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test_rel(a, pow(1.2, b), HDRL_EPS_DATA); + cpl_test_rel(ea, 1.3098531960320208, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a = 0.; + hdrl_error_t ea = 0.5; + hdrl_data_t b = -1.; + hdrl_error_t eb = 0.; + + hdrl_elemop_pow(&a, &ea, 1, &b, &eb, 1, NULL); + + cpl_test(isnan(a)); + cpl_test(isnan(ea)); + } + + { + hdrl_data_t a[] = {0., 0.}; + hdrl_error_t ea[] = {0.5, 0.5}; + hdrl_data_t b = -1.; + hdrl_error_t eb = 0.; + + hdrl_elemop_pow(a, ea, 2, &b, &eb, 1, NULL); + + cpl_test(isnan(a[0])); + cpl_test(isnan(ea[0])); + cpl_test(isnan(a[1])); + cpl_test(isnan(ea[1])); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b[] = {-2, 6}; + const hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_pow(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), NULL); + + cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 729, HDRL_EPS_DATA); + cpl_test_rel(ea[1], 2810.438304633068, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b = -2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_pow(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL); + + cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 0.1111111111111111, HDRL_EPS_DATA); + cpl_test_rel(ea[1], 0.09597978726560344, HDRL_EPS_ERROR * 10); + } + + /* masked test */ + { + hdrl_data_t a[] = {2, 3}; + hdrl_error_t ea[] = {0.5, 1}; + const hdrl_data_t b[] = {-2, 6}; + const hdrl_error_t eb[] = {0.5, 3}; + cpl_binary mask[] = {0, 1}; + + hdrl_elemop_pow(a, ea, ARRAY_LEN(a), b, eb, ARRAY_LEN(b), mask); + + cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 3., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 1., HDRL_EPS_ERROR * 10); + } + + return cpl_error_get_code(); +} + + +static cpl_error_code +hdrl_test_pow_inverted(void) +{ + { + hdrl_data_t a = 0., b = 0.; + hdrl_error_t ea = 0., eb = 0.; + hdrl_elemop_pow_inverted(&a, &ea, 1, &b, &eb, 2, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + } + + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.5; + + hdrl_elemop_pow_inverted(&a, &ea, 1, &a, &ea, 1, NULL); + + cpl_test_rel(a, pow(1.2, 1.2), HDRL_EPS_DATA); + cpl_test_rel(ea, 0.7357378647225408, HDRL_EPS_ERROR * 10); + } + + /* square root test */ + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.6; + hdrl_data_t b = 0.5; + hdrl_error_t eb = 0.; + + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + cpl_test_rel(b, sqrt(1.2), HDRL_EPS_DATA); + cpl_test_rel(eb, 0.27386127875258304, HDRL_EPS_ERROR * 10); + + a = -1.2; + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + cpl_test(isnan(b)); + cpl_test(isnan(eb)); + + /* negative value test */ + a = -1.2; + ea = 0.6; + b = 3.; + eb = 0.0; + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + cpl_test_rel(b, pow(-1.2, 3.), HDRL_EPS_DATA); + cpl_test_rel(eb, 2.592, HDRL_EPS_ERROR * 10); + } + + /* pow with error free exper 2 exponent == repeated multiplication */ + { + hdrl_data_t a = -1.2; + hdrl_error_t ea = 0.5; + hdrl_data_t b = 2.0; + hdrl_error_t eb = 0.0; + + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + hdrl_data_t a2 = -1.2; + hdrl_error_t ea2 = 0.5; + hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL); + + cpl_test_rel(b, a2, HDRL_EPS_DATA); + cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10); + + a = -1.2; + ea = 0.5; + b = 4.0; + eb = 0.0; + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + hdrl_elemop_mul(&a2, &ea2, 1, &a2, &ea2, 1, NULL); + cpl_test_rel(b, a2, HDRL_EPS_DATA); + cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10); + } + /* array pow with error free exper 2 exponent == repeated multiplication */ + { + hdrl_data_t a[] = {0.3, 10.}; + hdrl_error_t ea[] = {0.5, 2.}; + hdrl_data_t b[] = {2.0, 2.0}; + hdrl_error_t eb[] = {0., 0.}; + + hdrl_elemop_pow_inverted(b, eb, 2, a, ea, 2, NULL); + + hdrl_data_t a2[] = {0.3, 10.}; + hdrl_error_t ea2[] = {0.5, 2.}; + hdrl_elemop_mul(a2, ea2, 2, a2, ea2, 2, NULL); + + cpl_test_rel(b[0], a2[0], HDRL_EPS_DATA); + cpl_test_rel(eb[0], ea2[0], HDRL_EPS_ERROR * 10); + cpl_test_rel(b[1], a2[1], HDRL_EPS_DATA); + cpl_test_rel(eb[1], ea2[1], HDRL_EPS_ERROR * 10); + } + + /* pow with error free -1 exponent == reciprocal */ + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.5; + hdrl_data_t b = -1.0; + hdrl_error_t eb = 0.0; + + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + hdrl_data_t a2 = 1.0; + hdrl_error_t ea2 = 0.; + hdrl_data_t b2 = 1.2; + hdrl_error_t eb2 = 0.5; + hdrl_elemop_div(&a2, &ea2, 1, &b2, &eb2, 1, NULL); + + cpl_test_rel(b, a2, HDRL_EPS_DATA); + cpl_test_rel(eb, ea2, HDRL_EPS_ERROR * 10); + } + + /* array pow with error free -1 exponent == reciprocal*/ + { + hdrl_data_t a[] = {0.3, 10.}; + hdrl_error_t ea[] = {0.5, 2.}; + hdrl_data_t b[] = {-1.0, -1.0}; + hdrl_error_t eb[] = {0., 0.}; + + hdrl_elemop_pow_inverted(b, eb, 2, a, ea, 2, NULL); + + hdrl_data_t a2[] = {1.0, 1.0}; + hdrl_error_t ea2[] = {0., 0.}; + hdrl_data_t b2[] = {0.3, 10.}; + hdrl_error_t eb2[] = {0.5, 2.}; + hdrl_elemop_div(a2, ea2, 2, b2, eb2, 2, NULL); + + cpl_test_rel(b[0], a2[0], HDRL_EPS_DATA); + cpl_test_rel(eb[0], ea2[0], HDRL_EPS_ERROR * 10); + cpl_test_rel(b[1], a2[1], HDRL_EPS_DATA); + cpl_test_rel(eb[1], ea2[1], HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a = 1.2; + hdrl_error_t ea = 0.5; + hdrl_data_t b = 2.0; + hdrl_error_t eb = 2.0; + + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + cpl_test_rel(b, pow(a, 2.0), HDRL_EPS_DATA); + cpl_test_rel(eb, 1.3098531960320208, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a = 0.; + hdrl_error_t ea = 0.5; + hdrl_data_t b = -1.; + hdrl_error_t eb = 0.; + + hdrl_elemop_pow_inverted(&b, &eb, 1, &a, &ea, 1, NULL); + + cpl_test(isnan(b)); + cpl_test(isnan(eb)); + } + + { + hdrl_data_t a[] = {-1., 3.}; + hdrl_error_t ea[] = {0.0, 0.1}; + hdrl_data_t b = 0.; + hdrl_error_t eb = 2.; + + hdrl_elemop_pow_inverted(a, ea, 2, &b, &eb, 1, NULL); + + cpl_test(isnan(a[0])); + cpl_test(isnan(ea[0])); + cpl_test(!isnan(a[1])); + cpl_test_rel(a[1], 0.0, HDRL_EPS_ERROR); + /* it is null because in the error calculation we divide by the base (0) */ + cpl_test(isnan(ea[1])); + } + + { + const hdrl_data_t a[] = {2, 3}; + const hdrl_error_t ea[] = {0.5, 1}; + hdrl_data_t b[] = {-2, 6}; + hdrl_error_t eb[] = {0.5, 3}; + + hdrl_elemop_pow_inverted(b, eb, ARRAY_LEN(a), a, ea, ARRAY_LEN(b), NULL); + + cpl_test_rel(b[0], 0.25, HDRL_EPS_DATA); + cpl_test_rel(eb[0], 0.15209233492346647, HDRL_EPS_ERROR * 10); + cpl_test_rel(b[1], 729, HDRL_EPS_DATA); + cpl_test_rel(eb[1], 2810.438304633068, HDRL_EPS_ERROR * 10); + } + + { + hdrl_data_t a[] = {-2, 3}; + hdrl_error_t ea[] = {0.5, .2}; + const hdrl_data_t b = 2; + const hdrl_error_t eb = 0.5; + + hdrl_elemop_pow_inverted(a, ea, ARRAY_LEN(a), &b, &eb, 1, NULL); + + cpl_test_rel(a[0], 0.25, HDRL_EPS_DATA); + cpl_test_rel(ea[0], 0.15209233492346647, HDRL_EPS_ERROR * 10); + cpl_test_rel(a[1], 8., HDRL_EPS_DATA); + cpl_test_rel(ea[1], 6.10163582292737, HDRL_EPS_ERROR * 10); + } + + /* masked test */ + { + const hdrl_data_t a[] = {2, 3}; + const hdrl_error_t ea[] = {0.5, 1}; + hdrl_data_t b[] = {-2, 6}; + hdrl_error_t eb[] = {0.5, 3}; + cpl_binary mask[] = {0, 1}; + + hdrl_elemop_pow_inverted(b, eb, ARRAY_LEN(b), a, ea, ARRAY_LEN(a), mask); + + cpl_test_rel(b[0], 0.25, HDRL_EPS_DATA); + cpl_test_rel(eb[0], 0.15209233492346647, HDRL_EPS_ERROR * 10); + cpl_test_rel(b[1], 6., HDRL_EPS_DATA); + cpl_test_rel(eb[1], 3., HDRL_EPS_ERROR * 10); + } + + return cpl_error_get_code(); +} + +static cpl_error_code +hdrl_test_image(void) +{ + int is_rej; + + hdrl_data_t ad[] = {2, 2}; + hdrl_error_t ae[] = {0.5, 0.5}; + cpl_image *iad = cpl_image_wrap(1, 2, HDRL_TYPE_DATA, ad); + cpl_image *iae = cpl_image_wrap(1, 2, HDRL_TYPE_ERROR, ae); + + hdrl_data_t bd[] = {3, 3}; + hdrl_error_t be[] = {0.5, 0.5}; + cpl_image *ibd = cpl_image_wrap(1, 2, HDRL_TYPE_DATA, bd); + cpl_image *ibe = cpl_image_wrap(1, 2, HDRL_TYPE_ERROR, be); + + hdrl_elemop_image_add_image(iad, iae, ibd, ibe); + + cpl_test_rel(ad[0], 5., HDRL_EPS_DATA); + cpl_test_rel(ae[0], sqrt(0.5), HDRL_EPS_ERROR); + + hdrl_elemop_image_sub_image(iad, iae, ibd, ibe); + cpl_test_rel(ad[0], 5. - 3., HDRL_EPS_DATA); + + hdrl_elemop_image_mul_image(iad, iae, ibd, ibe); + cpl_test_rel(ad[0], (5. - 3.) * 3., HDRL_EPS_DATA); + + hdrl_elemop_image_div_image(iad, iae, ibd, ibe); + cpl_test_rel(ad[0], ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA); + + hdrl_elemop_image_pow_image(iad, iae, ibd, ibe); + cpl_test_rel(ad[0], pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA); + + cpl_image_set(iad, 1, 1, 0.); + cpl_image_set(ibd, 1, 1, -1.); + hdrl_elemop_image_pow_image(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + + cpl_image_set(iad, 1, 1, 2.); + cpl_image_set(ibd, 1, 1, 0.); + cpl_image_accept_all(iad); + cpl_image_accept_all(iae); + hdrl_elemop_image_div_image(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + + /* test a has bpm */ + cpl_image_set(iad, 1, 1, 2. ); + cpl_image_set(iae, 1, 1, 0.5); + cpl_image_set(ibd, 1, 1, 3. ); + cpl_image_reject(iad, 1, 1); + hdrl_elemop_image_div_image(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + cpl_test_rel(ad[0], 2., 0); + + cpl_image_accept_all(iad); + cpl_test_rel(cpl_image_get(iad, 1, 1, &is_rej), 2., 0); + + /* test a and b have bpm */ + cpl_image_set(iad, 1, 1, 2. ); + cpl_image_set(iae, 1, 1, 0.5); + cpl_image_reject(iad, 1, 1); + cpl_image_reject(ibd, 1, 2); + hdrl_elemop_image_div_image(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + cpl_test(cpl_image_is_rejected(iad, 1, 2)); + cpl_test_rel(ad[0], 2., 0); + cpl_test_rel(ae[0], 0.5, 0); + + /* test b has bpm */ + cpl_image_set(iad, 1, 2, 2. ); + cpl_image_set(iae, 1, 2, 0.5); + cpl_image_set(ibd, 1, 2, 2. ); + cpl_image_set(ibe, 1, 2, 0.5); + cpl_image_accept_all(iad); + cpl_image_reject(ibd, 1, 2); + hdrl_elemop_image_div_image(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(iad, 1, 2)); + cpl_test_rel(ad[1], 2., 0); + cpl_test_rel(ae[1], 0.5, 0); + + cpl_image_unwrap(iad); + cpl_image_unwrap(iae); + cpl_image_unwrap(ibd); + cpl_image_unwrap(ibe); + + return cpl_error_get_code(); +} + + +static cpl_error_code +hdrl_test_image_scalar(void) +{ + int is_rej; + hdrl_data_t ad = 2; + hdrl_error_t ae = 0.5; + const hdrl_data_t bd = 3; + const hdrl_error_t be = 0.5; + cpl_image * iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad); + cpl_image * iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae); + + hdrl_elemop_image_add_scalar(iad, iae, bd, be); + + cpl_test_rel(ad, 5., HDRL_EPS_DATA); + cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR); + + hdrl_elemop_image_sub_scalar(iad, iae, bd, be); + cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA); + + hdrl_elemop_image_mul_scalar(iad, iae, bd, be); + cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA); + + hdrl_elemop_image_div_scalar(iad, iae, bd, be); + cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA); + + hdrl_data_t ad_old = ad; + hdrl_elemop_image_exp_scalar(iad, iae, bd, be); + cpl_test_rel(ad, pow(3., ((5. - 3.) * 3.) / 3.), HDRL_EPS_DATA); + + ad = ad_old; + hdrl_elemop_image_pow_scalar(iad, iae, bd, be); + cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA); + + /* divide image by scalar zero (emits warning) */ + hdrl_elemop_image_div_scalar(iad, iae, 0., be); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + + cpl_image_accept_all(iad); + cpl_image_set(iad, 1, 1, 0.); + hdrl_elemop_image_pow_scalar(iad, iae, -1., be); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + + cpl_image_set(iad, 1, 1, -1); + cpl_image_reject(iad, 1, 1); + hdrl_elemop_image_exp_scalar(iad, iae, 0., be); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + + cpl_image_set(iad, 1, 1, 2.); + cpl_image_reject(iad, 1, 1); + hdrl_elemop_image_div_scalar(iad, iae, bd, be); + cpl_test(cpl_image_is_rejected(iad, 1, 1)); + cpl_image_accept_all(iad); + cpl_test_rel(cpl_image_get(iad, 1, 1, &is_rej), 2., 0); + + cpl_image_unwrap(iad); + cpl_image_unwrap(iae); + + return cpl_error_get_code(); +} + + +static cpl_error_code +hdrl_test_imagelist(void) +{ + int is_rej; + hdrl_data_t ad = 2; + hdrl_error_t ae = 0.5; + hdrl_data_t bd = 3; + hdrl_error_t be = 0.5; + cpl_image * _iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad); + cpl_image * _iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae); + cpl_image * _ibd = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &bd); + cpl_image * _ibe = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &be); + cpl_imagelist * iad = cpl_imagelist_new(); + cpl_imagelist * iae = cpl_imagelist_new(); + cpl_imagelist * ibd = cpl_imagelist_new(); + cpl_imagelist * ibe = cpl_imagelist_new(); + cpl_imagelist_set(iad, _iad, 0); + cpl_imagelist_set(ibd, _ibd, 0); + cpl_imagelist_set(iae, _iae, 0); + cpl_imagelist_set(ibe, _ibe, 0); + + hdrl_elemop_imagelist_add_imagelist(iad, iae, ibd, ibe); + cpl_test_rel(ad, 5., HDRL_EPS_DATA); + cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR); + + hdrl_elemop_imagelist_sub_imagelist(iad, iae, ibd, ibe); + cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_mul_imagelist(iad, iae, ibd, ibe); + cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_div_imagelist(iad, iae, ibd, ibe); + cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_pow_imagelist(iad, iae, ibd, ibe); + cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA); + + cpl_image_set(_iad, 1, 1, 2.); + cpl_image_reject(_iad, 1, 1); + hdrl_elemop_imagelist_div_imagelist(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(_iad, 1, 1)); + cpl_image_accept_all(_iad); + cpl_test_rel(cpl_image_get(_iad, 1, 1, &is_rej), 2., 0); + cpl_imagelist_unwrap(iad); + cpl_imagelist_unwrap(iae); + cpl_imagelist_unwrap(ibd); + cpl_imagelist_unwrap(ibe); + cpl_image_unwrap(_iad); + cpl_image_unwrap(_iae); + cpl_image_unwrap(_ibd); + cpl_image_unwrap(_ibe); + + return cpl_error_get_code(); +} + +static cpl_error_code +hdrl_test_imagelist_image(void) +{ + int is_rej; + hdrl_data_t ad = 2; + hdrl_error_t ae = 0.5; + hdrl_data_t bd = 3; + hdrl_error_t be = 0.5; + cpl_image * _iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad); + cpl_image * _iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae); + cpl_image * ibd = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &bd); + cpl_image * ibe = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &be); + cpl_imagelist * iad = cpl_imagelist_new(); + cpl_imagelist * iae = cpl_imagelist_new(); + cpl_imagelist_set(iad, _iad, 0); + cpl_imagelist_set(iae, _iae, 0); + + hdrl_elemop_imagelist_add_image(iad, iae, ibd, ibe); + cpl_test_rel(ad, 5., HDRL_EPS_DATA); + cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR); + + hdrl_elemop_imagelist_sub_image(iad, iae, ibd, ibe); + cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_mul_image(iad, iae, ibd, ibe); + cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_div_image(iad, iae, ibd, ibe); + cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_pow_image(iad, iae, ibd, ibe); + cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA); + + cpl_image_set(_iad, 1, 1, 2.); + cpl_image_reject(_iad, 1, 1); + hdrl_elemop_imagelist_div_image(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(_iad, 1, 1)); + cpl_image_accept_all(_iad); + cpl_test_rel(cpl_image_get(_iad, 1, 1, &is_rej), 2., 0); + cpl_imagelist_unwrap(iad); + cpl_imagelist_unwrap(iae); + cpl_image_unwrap(_iad); + cpl_image_unwrap(_iae); + cpl_image_unwrap(ibd); + cpl_image_unwrap(ibe); + + return cpl_error_get_code(); +} + + +static cpl_error_code +hdrl_test_imagelist_vector(void) +{ + int is_rej; + + hdrl_data_t ad = 2; + hdrl_error_t ae = 0.5; + + double bd[1] = {3}; + double be[1] = {0.5}; + + cpl_image * _iad = cpl_image_wrap(1, 1, HDRL_TYPE_DATA, &ad); + cpl_image * _iae = cpl_image_wrap(1, 1, HDRL_TYPE_ERROR, &ae); + + cpl_vector * ibd = cpl_vector_wrap(ARRAY_LEN(bd), bd); + cpl_vector * ibe = cpl_vector_wrap(ARRAY_LEN(be), be); + + cpl_imagelist * iad = cpl_imagelist_new(); + cpl_imagelist * iae = cpl_imagelist_new(); + cpl_imagelist_set(iad, _iad, 0); + cpl_imagelist_set(iae, _iae, 0); + + hdrl_elemop_imagelist_add_vector(iad, iae, ibd, ibe); + cpl_test_rel(ad, 5., HDRL_EPS_DATA); + cpl_test_rel(ae, sqrt(0.5), HDRL_EPS_ERROR); + + hdrl_elemop_imagelist_sub_vector(iad, iae, ibd, ibe); + cpl_test_rel(ad, 5. - 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_mul_vector(iad, iae, ibd, ibe); + cpl_test_rel(ad, (5. - 3.) * 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_div_vector(iad, iae, ibd, ibe); + cpl_test_rel(ad, ((5. - 3.) * 3.) / 3., HDRL_EPS_DATA); + + hdrl_elemop_imagelist_pow_vector(iad, iae, ibd, ibe); + cpl_test_rel(ad, pow(((5. - 3.) * 3.) / 3., 3.), HDRL_EPS_DATA); + + cpl_image_set(_iad, 1, 1, 2.); + cpl_image_reject(_iad, 1, 1); + hdrl_elemop_imagelist_div_vector(iad, iae, ibd, ibe); + cpl_test(cpl_image_is_rejected(_iad, 1, 1)); + cpl_image_accept_all(_iad); + cpl_test_rel(cpl_image_get(_iad, 1, 1, &is_rej), 2., 0); + + cpl_imagelist_unwrap(iad); + cpl_imagelist_unwrap(iae); + cpl_image_unwrap(_iad); + cpl_image_unwrap(_iae); + cpl_vector_unwrap(ibd); + cpl_vector_unwrap(ibe); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of variance module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_test_add(); + hdrl_test_sub(); + hdrl_test_mul(); + hdrl_test_div(); + hdrl_test_pow(); + hdrl_test_pow_inverted(); + + hdrl_test_image(); + hdrl_test_image_scalar(); + + hdrl_test_imagelist(); + hdrl_test_imagelist_image(); + hdrl_test_imagelist_vector(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_fit-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_fit-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_fit-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_fit-test.c 2017-08-23 11:25:00.000000000 +0000 @@ -0,0 +1,471 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_fit.c" +#include "hdrl_imagelist.h" +#include "hdrl_test.h" + +#include + +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_fit_test + Testing of hdrl_fit module + */ +/*----------------------------------------------------------------------------*/ + +#define matrix_eq(m, exp, eps) \ + do { \ + for (size_t i = 0; i < (size_t)cpl_matrix_get_nrow(m); i++) { \ + for (size_t j = 0; j < (size_t)cpl_matrix_get_ncol(m); j++) { \ + cpl_test_abs(cpl_matrix_get(m, i, j), exp[i * \ + cpl_matrix_get_ncol(m) + j], eps); \ + } \ + } \ + } while (0) + +static void test_vander1d(void) +{ + { + double p[] = {1, 2, 3, 4}; + double exp[] = {1., 1., 1., + 1., 2., 4., + 1., 3., 9., + 1., 4., 16.}; + cpl_vector * pv = cpl_vector_wrap(ARRAY_LEN(p), p); + cpl_matrix * v = polyvander1d(pv, 2); + cpl_test_error(CPL_ERROR_NONE); + matrix_eq(v, exp, DBL_EPSILON * 5); + cpl_matrix_delete(v); + + v = polyvander1d(pv, 2); + cpl_test_error(CPL_ERROR_NONE); + matrix_eq(v, exp, DBL_EPSILON * 5); + cpl_matrix_delete(v); + + cpl_vector_unwrap(pv); + } + /* could be used for weight_design function */ + if (0) { + double p[] = {1, 2, 3, 4}; + double e[] = {1, 1, 4, 1}; + double exp[] = {1., 1., 1., + 1., 2., 4., + 0.25, 0.75, 2.25, + 1., 4., 16.}; + cpl_vector * pv = cpl_vector_wrap(ARRAY_LEN(p), p); + cpl_vector * ev = cpl_vector_wrap(ARRAY_LEN(e), e); + cpl_matrix * v = polyvander1d(pv, 2); + cpl_test_error(CPL_ERROR_NONE); + + matrix_eq(v, exp, DBL_EPSILON * 5); + cpl_vector_unwrap(pv); + cpl_vector_unwrap(ev); + cpl_matrix_delete(v); + } +} + +static void test_fit(void) +{ + { + double s[] = {1, 2, 3, 4}; + double p[] = {2, 2.5, 3, 3.5}; + double exp[] = {1.5, 0.5, 0.}; + double eres[] = {0., 0., 0., 0.}; + cpl_vector * sv = cpl_vector_wrap(ARRAY_LEN(s), s); + cpl_vector * pv = cpl_vector_wrap(ARRAY_LEN(p), p); + cpl_vector * vre = cpl_vector_wrap(ARRAY_LEN(eres), eres); + cpl_matrix * v = polyvander1d(sv, 2); + hdrl_ls_fit_result * r = fit(v, pv, NULL); + cpl_test_error(CPL_ERROR_NONE); + matrix_eq(r->coef, exp, DBL_EPSILON * 10); + cpl_vector * res = hdrl_ls_fit_result_get_residuals(r, pv); + cpl_test_vector_abs(res, vre, DBL_EPSILON * 5); + cpl_vector_unwrap(vre); + cpl_vector_delete(res); + cpl_matrix_delete(v); + cpl_vector_unwrap(pv); + cpl_vector_unwrap(sv); + hdrl_ls_fit_result_delete(r); + } + { + double s[] = {1, 2, 3, 4, 5}; + double p[] = {1.1, 2.5, 3.4, 3.8, 7}; + double e[] = {0.3, 0.2, 0.2, 0.1, 0.5}; + double exp[] = {0.54529, 0.858981}; + double cexp[] = {0.0756216, -0.0206541, -0.0206541, 0.00613226}; + cpl_vector * vfit = cpl_vector_new(ARRAY_LEN(s)); + cpl_vector * vres = cpl_vector_new(ARRAY_LEN(s)); + for (size_t i = 0; i < ARRAY_LEN(s); i++) { + cpl_vector_set(vfit, i, exp[0] + exp[1] * s[i]); + cpl_vector_set(vres, i, p[i] - (exp[0] + exp[1] * s[i])); + } + + cpl_vector * sv = cpl_vector_wrap(ARRAY_LEN(s), s); + cpl_vector * pv = cpl_vector_wrap(ARRAY_LEN(p), p); + cpl_vector * ev = cpl_vector_wrap(ARRAY_LEN(e), e); + cpl_matrix * v = polyvander1d(sv, 1); + + hdrl_ls_fit_result * r = fit(v, pv, ev); + cpl_test_error(CPL_ERROR_NONE); + matrix_eq(r->coef, exp, DBL_EPSILON * 1e10); + matrix_eq(r->cov, cexp, DBL_EPSILON * 1e10); + + cpl_vector * values = hdrl_ls_fit_result_get_fitted_values(r); + cpl_test_vector_abs(values, vfit, DBL_EPSILON * 1e10); + cpl_vector_delete(vfit); + cpl_vector_delete(values); + cpl_vector * resi = hdrl_ls_fit_result_get_residuals(r, pv); + cpl_test_vector_abs(resi, vres, DBL_EPSILON * 1e10); + cpl_vector_delete(vres); + cpl_vector_delete(resi); + cpl_matrix_delete(v); + + hdrl_ls_fit_result_delete(r); + + r = polyfit1d(sv, pv, ev, 1); + cpl_test_error(CPL_ERROR_NONE); + matrix_eq(r->coef, exp, DBL_EPSILON * 1e10); + hdrl_ls_fit_result_delete(r); + + cpl_vector_unwrap(pv); + cpl_vector_unwrap(ev); + cpl_vector_unwrap(sv); + } +} + +/* ---------------------------------------------------------------------------*/ +/** + * @brief return prediction interval for the data + * + * @param r fit result + * @param data data + * @param errors errors + * @return vector of symmetric prediction interval for data + * + * The prediction interval is the one sigma area in which new measurements from + * the same setup are going to lie. It is not the error of the fitted + * coefficients which is much smaller due to the use of all values from data to + * compute them. + */ +/* ---------------------------------------------------------------------------*/ +static inline cpl_vector * hdrl_ls_fit_result_get_fit_interval( + const hdrl_ls_fit_result * r, + const cpl_vector * data, + cpl_vector * errors) +{ + /* mse = sum(sqrt(weights) * residuals ** 2) / df */ + double mse = hdrl_ls_fit_result_get_chi2(r, data, errors) / + hdrl_ls_fit_result_get_residual_dof(r); + /* var = mse / weights */ + cpl_vector * serror = cpl_vector_duplicate(errors); + cpl_vector_multiply(serror, serror); + cpl_vector_multiply_scalar(serror, mse); + cpl_vector_power(serror, 0.5); + + /* TODO: accounting for covariance missing + * + (exog * np.dot(covb, exog.T).T).sum(axis=1) */ + + return serror; +} + + +void test_poisson(void) +{ + double x[] = { 10. , 62.1 , 114.2, 166.3, 218.4, 270.5, 322.6, + 374.7, 426.8, 478.9, 531.1, 583.2, 635.3, 687.4, 739.5, + 791.6, 843.7, 895.8, 947.9, 1000. }; + /* poisson data with lambda: x / 10 (== variance) and 100 offset */ + double y[] = { 103, 107, 111, 112, 117, 127, 126, 125, 139, 150, 157, 162, + 153, 158, 162, 184, 191, 195, 182, 196 }; + cpl_vector * vx = cpl_vector_wrap(ARRAY_LEN(x), x); + cpl_vector * vy = cpl_vector_wrap(ARRAY_LEN(y), y); + /* relative model errors (poisson model ~ sqrt(x)) */ + cpl_vector * ve_model = cpl_vector_duplicate(vx); + cpl_vector_power(ve_model, 0.5); + /* real absolute error of the population != relative model errors */ + cpl_vector * ve_real = cpl_vector_duplicate(vx); + cpl_vector_divide_scalar(ve_real, 10); + cpl_vector_power(ve_real, 0.5); + + + double exp_c[] = {101.4164, 0.0919476}; + cpl_matrix * design = polyvander1d(vx, 1); + hdrl_ls_fit_result * res = polyfit1d(vx, vy, ve_model, 1); + matrix_eq(res->coef, exp_c, DBL_EPSILON * 2e12); + /* get sample error */ + cpl_vector * pred_e = + hdrl_ls_fit_result_get_fit_interval(res, vy, ve_model); + /* should be less than < 20% deviation to population error */ + cpl_test_vector_abs(pred_e, ve_real, 0.7); + cpl_vector_delete(pred_e); + + cpl_vector_unwrap(vx); + cpl_vector_unwrap(vy); + cpl_vector_delete(ve_model); + cpl_vector_delete(ve_real); + cpl_matrix_delete(design); + hdrl_ls_fit_result_delete(res); +} + +void test_imglistfit(void) +{ + { + size_t n = 5; + hdrl_imagelist * input = hdrl_imagelist_new(); + cpl_vector * samp = cpl_vector_new(n); + hdrl_imagelist * out_coef = NULL; + cpl_image * out_chi2 = NULL; + cpl_image * out_dof = NULL; + hdrl_fit_polynomial_imagelist(NULL, NULL, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist(input, NULL, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist(NULL, samp, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist(input, samp, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist(input, samp, -1, &out_coef, &out_chi2, &out_dof); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_fit_polynomial_imagelist(input, samp, n + 2, &out_coef, &out_chi2, &out_dof); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + for (size_t i = 0; i < n; i++) { + double t = (i + 1) * 100; + hdrl_image * img = hdrl_image_new(10, 10); + /* slight deviation from linear to get nonzero scale */ + hdrl_image_add_scalar(img, + (hdrl_value){0.5 * t + 100 - i, sqrt(0.5 * t)}); + if (i == 3) { + hdrl_image_reject(img, 3, 4); + } + hdrl_imagelist_set(input, img, i); + cpl_vector_set(samp, i, t); + } + + hdrl_fit_polynomial_imagelist(input, samp, 1, &out_coef, &out_chi2, &out_dof); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_image_get_type(out_dof), HDRL_TYPE_DATA); + cpl_test_eq(cpl_image_get_type(out_chi2), HDRL_TYPE_DATA); + cpl_test_eq(hdrl_imagelist_get_size(out_coef), 2); + + hdrl_image * coef0 = hdrl_imagelist_get(out_coef, 0); + hdrl_image * expect = hdrl_image_new(10, 10); + hdrl_image_add_scalar(expect, (hdrl_value){101, 9.0045}); + hdrl_image_set_pixel(expect, 3, 4, (hdrl_value){101, 9.29448}); + hdrl_test_image_abs(coef0, expect, HDRL_EPS_DATA * 1e11); + hdrl_image_delete(expect); + + hdrl_image * coef1 = hdrl_imagelist_get(out_coef, 1); + expect = hdrl_image_new(10, 10); + hdrl_image_add_scalar(expect, (hdrl_value){0.49, 0.0351317}); + hdrl_image_set_pixel(expect, 3, 4, (hdrl_value){0.49, 0.0399607}); + hdrl_test_image_abs(coef1, expect, HDRL_EPS_DATA * 1e11); + hdrl_image_delete(expect); + + cpl_image * cexpect = cpl_image_new(10, 10, HDRL_TYPE_DATA); + /* dof*scaling between weights and measured error */ + cpl_image_add_scalar(cexpect, 1.831e-29); + cpl_test_image_abs(out_chi2, cexpect, DBL_EPSILON * 1e9); + cpl_image_delete(cexpect); + + cexpect = cpl_image_new(10, 10, HDRL_TYPE_DATA); + cpl_image_add_scalar(cexpect, 3); + cpl_image_set(cexpect, 3, 4, 2); + cpl_test_image_abs(out_dof, cexpect, 0); + cpl_image_delete(cexpect); + + hdrl_imagelist_delete(out_coef); + cpl_image_delete(out_chi2); + cpl_image_delete(out_dof); + + + /* smoke test less good pixels than fit degree */ + hdrl_image_reject(hdrl_imagelist_get(input, 0), 2, 2); + hdrl_image_reject(hdrl_imagelist_get(input, 1), 2, 2); + hdrl_image_reject(hdrl_imagelist_get(input, 2), 2, 2); + hdrl_image_reject(hdrl_imagelist_get(input, 3), 2, 2); + hdrl_fit_polynomial_imagelist(input, samp, 3, &out_coef, &out_chi2, &out_dof); + + hdrl_imagelist_delete(input); + cpl_vector_delete(samp); + hdrl_imagelist_delete(out_coef); + cpl_image_delete(out_chi2); + cpl_image_delete(out_dof); + } +} + +void test_imglistfit2(void) +{ + { + size_t n = 5; + hdrl_imagelist * input = hdrl_imagelist_new(); + cpl_imagelist * samp = cpl_imagelist_new(); + hdrl_imagelist * out_coef = NULL; + cpl_image * out_chi2 = NULL; + cpl_image * out_dof = NULL; + hdrl_fit_polynomial_imagelist2(NULL, NULL, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist2(input, NULL, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist2(NULL, samp, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist2(input, samp, 0, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_fit_polynomial_imagelist2(input, samp, -1, &out_coef, &out_chi2, &out_dof); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_fit_polynomial_imagelist2(input, samp, n + 2, &out_coef, &out_chi2, &out_dof); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + for (size_t i = 0; i < n; i++) { + double t = (i + 1) * 100; + hdrl_image * img = hdrl_image_new(10, 10); + /* slight deviation from linear to get nonzero scale */ + hdrl_image_add_scalar(img, + (hdrl_value){0.5 * t + 100 - i, sqrt(0.5 * t)}); + hdrl_imagelist_set(input, img, i); + cpl_image * sampi = cpl_image_new(10, 10, HDRL_TYPE_DATA); + cpl_image_add_scalar(sampi, t); + if (i == 3) { + cpl_image_reject(sampi, 3, 4); + } + cpl_imagelist_set(samp, sampi, i); + } + + hdrl_fit_polynomial_imagelist2(input, samp, 1, &out_coef, &out_chi2, &out_dof); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_image_get_type(out_dof), HDRL_TYPE_DATA); + cpl_test_eq(cpl_image_get_type(out_chi2), HDRL_TYPE_DATA); + cpl_test_eq(hdrl_imagelist_get_size(out_coef), 2); + + hdrl_image * coef0 = hdrl_imagelist_get(out_coef, 0); + hdrl_image * expect = hdrl_image_new(10, 10); + hdrl_image_add_scalar(expect, (hdrl_value){101, 9.0045}); + hdrl_image_set_pixel(expect, 3, 4, (hdrl_value){101, 9.29448}); + hdrl_test_image_abs(coef0, expect, HDRL_EPS_DATA * 1e11); + hdrl_image_delete(expect); + + hdrl_image * coef1 = hdrl_imagelist_get(out_coef, 1); + expect = hdrl_image_new(10, 10); + hdrl_image_add_scalar(expect, (hdrl_value){0.49, 0.0351317}); + hdrl_image_set_pixel(expect, 3, 4, (hdrl_value){0.49, 0.0399607}); + hdrl_test_image_abs(coef1, expect, HDRL_EPS_DATA * 1e11); + hdrl_image_delete(expect); + + cpl_image * cexpect = cpl_image_new(10, 10, HDRL_TYPE_DATA); + /* dof*scaling between weights and measured error */ + cpl_image_add_scalar(cexpect, 1.831e-29); + cpl_test_image_abs(out_chi2, cexpect, DBL_EPSILON * 1e9); + cpl_image_delete(cexpect); + + cexpect = cpl_image_new(10, 10, HDRL_TYPE_DATA); + cpl_image_add_scalar(cexpect, 3); + cpl_image_set(cexpect, 3, 4, 2); + cpl_test_image_abs(out_dof, cexpect, 0); + cpl_image_delete(cexpect); + + hdrl_imagelist_delete(out_coef); + cpl_image_delete(out_chi2); + cpl_image_delete(out_dof); + + + /* smoke test less good pixels than fit degree */ + hdrl_image_reject(hdrl_imagelist_get(input, 0), 2, 2); + hdrl_image_reject(hdrl_imagelist_get(input, 1), 2, 2); + hdrl_image_reject(hdrl_imagelist_get(input, 2), 2, 2); + hdrl_image_reject(hdrl_imagelist_get(input, 3), 2, 2); + hdrl_fit_polynomial_imagelist2(input, samp, 3, &out_coef, &out_chi2, &out_dof); + + hdrl_imagelist_delete(input); + cpl_imagelist_delete(samp); + hdrl_imagelist_delete(out_coef); + cpl_image_delete(out_chi2); + cpl_image_delete(out_dof); + } +} + +void test_real_data(void) +{ + /* pixel from vcam ramp data with poisson model error (gain 2.4, ron 10) */ + double x[] = { 3., 3., 5., 5., 7., 7., 10., 10., 12., 12., + 15., 15., 20., 20. }; + double y[] = { 3441, 3420, 5606, 5586, 7814, 7815, 11003, 10970, + 13292, 13198, 16347, 16175, 21267, 21318 }; + double e[] = { 39.16312027, 39.05124664, 49.35416031, 49.26966476, + 57.92955399, 57.93315125, 68.4440155 , 68.34349823, + 75.08883667, 74.82757568, 83.13392639, 82.7017746 , + 94.66387939, 94.77605438 }; + cpl_vector * vx = cpl_vector_wrap(ARRAY_LEN(x), x); + cpl_vector * vy = cpl_vector_wrap(ARRAY_LEN(y), y); + cpl_vector * ve = cpl_vector_wrap(ARRAY_LEN(e), e); + + double exp_c[] = {296.10245659, 1063.12005477}; + cpl_matrix * design = polyvander1d(vx, 1); + hdrl_ls_fit_result * res = polyfit1d(vx, vy, ve, 1); + matrix_eq(res->coef, exp_c, DBL_EPSILON * 2e10); + + cpl_vector_unwrap(vx); + cpl_vector_unwrap(vy); + cpl_vector_unwrap(ve); + cpl_matrix_delete(design); + hdrl_ls_fit_result_delete(res); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_vander1d(); + test_fit(); + test_poisson(); + test_imglistfit(); + test_imglistfit2(); + test_real_data(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_flat-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_flat-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_flat-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_flat-test.c 2017-09-19 14:35:18.000000000 +0000 @@ -0,0 +1,1157 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_flat.h" +#include "hdrl_image.h" +#include "hdrl_parameter.h" + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup test input parameter robustness on flat functionality + */ +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/** + @brief Test flat functions robustness to different kind of input parameters + + */ +/*----------------------------------------------------------------------------*/ +void hdrl_flat_test_parlist(void) +{ + /* parameter parsing smoketest */ + hdrl_parameter * hpar; + cpl_size filter_size_x=5; + cpl_size filter_size_y=5; + hdrl_flat_method method=HDRL_FLAT_FREQ_LOW; + + hdrl_parameter * deflts = hdrl_flat_parameter_create(filter_size_x, + filter_size_y, method); + cpl_test(hdrl_flat_parameter_check(deflts)); + cpl_test_error(CPL_ERROR_NONE); + + cpl_parameterlist * pflat = hdrl_flat_parameter_create_parlist("RECIPE", + "flat", deflts); + hdrl_parameter_delete(deflts) ; + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(pflat), 3); + + hpar = hdrl_flat_parameter_parse_parlist(pflat, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hpar = hdrl_flat_parameter_parse_parlist(pflat, "RECIPE.flat"); + cpl_parameterlist_delete(pflat); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_flat_parameter_get_method(hpar), + HDRL_FLAT_FREQ_LOW); + cpl_test_eq(hdrl_flat_parameter_get_filter_size_x(hpar), filter_size_x); + cpl_test_eq(hdrl_flat_parameter_get_filter_size_y(hpar), filter_size_x); + hdrl_parameter_delete(hpar); + + /* filter size x < 0 : CPL_ERROR_ILLEGAL_INPUT */ + /* filter size y < 0 : CPL_ERROR_ILLEGAL_INPUT */ + /* method: HDRL_FLAT_FREQ_LOW || HDRL_FLAT_FREQ_HIGH => + * 2==> CPL_ERROR_ILLEGAL_INPUT */ + deflts = hdrl_flat_parameter_create(-1, filter_size_y, method); + cpl_test_null(deflts); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(deflts) ; + + deflts = hdrl_flat_parameter_create(filter_size_x, -1, method); + cpl_test_null(deflts); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(deflts) ; + + deflts = hdrl_flat_parameter_create(filter_size_x, filter_size_y, 2); + cpl_test_null(deflts); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(deflts) ; + + deflts = hdrl_flat_parameter_create(2, filter_size_y, method); + cpl_test_null(deflts); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(deflts) ; + + deflts = hdrl_flat_parameter_create(filter_size_x, 2, method); + cpl_test_null(deflts); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(deflts) ; + + deflts = hdrl_flat_parameter_create(2, 2, method); + cpl_test_null(deflts); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(deflts) ; +} + +/* not yet used, comment it out (may be will be used later) +static cpl_error_code +hdrl_flat_flag_pixel_set(cpl_image * data, cpl_mask * data_bpm, const int var ) +{ + cpl_mask_set(data_bpm, 10, 10, CPL_BINARY_1); + if(var == 0) { + // Negative outlier set and marked as bad + cpl_image_set(data, 10, 10, 20.); + cpl_mask_set(data_bpm, 10, 10, CPL_BINARY_1); + + // Positive outlier set and marked as bad + cpl_image_set(data, 50, 50, 300.); + cpl_mask_set(data_bpm, 50, 50, CPL_BINARY_1); + + // Positive outliers set + cpl_image_set(data, 60, 60, 300.); + cpl_image_set(data, 61, 61, 300.); + cpl_image_set(data, 62, 62, 300.); + + // Negative outliers set + cpl_image_set(data, 70, 70, 20.); + cpl_image_set(data, 71, 71, 20.); + cpl_image_set(data, 72, 72, 20.); + + // Some pixels marked as bad + cpl_mask_set(data_bpm, 80, 80, CPL_BINARY_1); + cpl_mask_set(data_bpm, 81, 80, CPL_BINARY_1); + cpl_mask_set(data_bpm, 82, 80, CPL_BINARY_1); + + } else if (var == 3) { + cpl_image_set(data, 150, 150, 300.); + cpl_image_set(data, 110, 260, 300.); + cpl_mask_set(data_bpm, 70, 70, CPL_BINARY_1); + cpl_mask_set(data_bpm, 80, 80, CPL_BINARY_1); + } + return cpl_error_get_code(); + +} +*/ + +/* the following function flag as bad data points over a given region */ +static cpl_error_code +hdrl_flat_imlist_flag_region(hdrl_imagelist * imglist, + const hdrl_parameter * rect, + const double outlier, + const int mask_sw) +{ + const int nima=hdrl_imagelist_get_size(imglist); + + const cpl_size b_llx = hdrl_rect_region_get_llx(rect); + const cpl_size b_lly = hdrl_rect_region_get_lly(rect); + const cpl_size b_urx = hdrl_rect_region_get_urx(rect); + const cpl_size b_ury = hdrl_rect_region_get_ury(rect); + + hdrl_image * hima = hdrl_imagelist_get(imglist , 0); + + cpl_size ima_sx = cpl_image_get_size_x(hdrl_image_get_image(hima)); + cpl_size ima_sy = cpl_image_get_size_y(hdrl_image_get_image(hima)); + + for (int var = 0; var < nima ; ++var) { + + hima = hdrl_imagelist_get(imglist, var); + cpl_image * data = hdrl_image_get_image(hima); + cpl_mask * data_bpm = cpl_mask_new(ima_sx, ima_sy); + // STDEV is about 10 for these images + //cpl_image_fill_noise_uniform(data, 82, 118); + + //cpl_image_fill_window(data, b_llx, b_lly, b_urx, b_ury, outlier); + for(int j = b_lly; j < b_ury; j++) { + for(int i = b_llx; i < b_urx; i++) { + cpl_image_set(data, i, j, outlier); + } + } + + if(mask_sw == 1) { + for(int j = b_lly; j < b_ury; j++) { + for(int i = b_llx; i < b_urx; i++) { + cpl_mask_set(data_bpm, i, j, CPL_BINARY_1); + } + } + } + /* + hdrl_flat_flag_pixel_set(data, data_bpm, var); + */ + cpl_image_reject_from_mask(data, data_bpm); + + cpl_image * errors=cpl_image_power_create(data, 0.5); + hdrl_image * image = hdrl_image_create(data, errors); + /* + if(var == 0) { + + cpl_mask_save(cpl_image_get_bpm(data), "m_mask_flagged_region.fits", + NULL, CPL_IO_CREATE); + cpl_mask_save(cpl_image_get_bpm(hdrl_image_get_image(image)), + "h_mask_flagged_region.fits", NULL, CPL_IO_CREATE); + + cpl_image_save(data, "data_flagged_region.fits",CPL_TYPE_FLOAT, + NULL, CPL_IO_DEFAULT); + cpl_image_save(errors, "errs_flagged_region.fits",CPL_TYPE_FLOAT, + NULL, CPL_IO_DEFAULT); + cpl_mask_save(data_bpm, "mask_flagged_region.fits", NULL, + CPL_IO_CREATE); + + } + */ + hdrl_imagelist_set(imglist, image, var); + // free the memory + cpl_mask_delete(data_bpm); + //cpl_image_delete(data); + cpl_image_delete(errors); + } + + + cpl_imagelist* iml_data = NULL; + cpl_imagelist* iml_errs = NULL; + hdrl_imagelist_to_cplwrap(imglist, &iml_data, &iml_errs); + /* + cpl_imagelist_save(iml_data, "cube_data.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + cpl_imagelist_save(iml_errs, "cube_errs.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + */ + cpl_imagelist_unwrap(iml_data); + cpl_imagelist_unwrap(iml_errs); + + return cpl_error_get_code(); +} + +/* the following function generates a list of uniform images of given size + * and values */ +static hdrl_imagelist* +hdrl_flat_create_uniform_images( + const cpl_size nima, + const cpl_size ima_sx, + const cpl_size ima_sy, + const cpl_vector* values) +{ + hdrl_imagelist * imglist = hdrl_imagelist_new(); + + for (int var = 0; var < nima ; ++var) { + + cpl_image * data = cpl_image_new(ima_sx, ima_sy, CPL_TYPE_DOUBLE); + cpl_mask * data_bpm = cpl_mask_new(ima_sx, ima_sy); + // STDEV is about 10 for these images + //cpl_image_fill_noise_uniform(data, 82, 118); + cpl_image_add_scalar(data, cpl_vector_get(values, var)); + cpl_image * errors = cpl_image_power_create(data, 0.5); + /* + if(var == 0) { + cpl_image_save(data, "image_data.fits",CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + cpl_image_save(errors, "image_errs.fits",CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + } + */ + hdrl_image * image = hdrl_image_create(data, errors); + + hdrl_imagelist_set(imglist, image, var); + // free the memory + cpl_mask_delete(data_bpm); + cpl_image_delete(data); + cpl_image_delete(errors); + + } + + cpl_imagelist* iml_data = NULL; + cpl_imagelist* iml_errs = NULL; + hdrl_imagelist_to_cplwrap(imglist, &iml_data, &iml_errs); + /* + cpl_imagelist_save(iml_data, "cube_data.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + cpl_imagelist_save(iml_errs, "cube_errs.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + */ + cpl_imagelist_unwrap(iml_data); + cpl_imagelist_unwrap(iml_errs); + return imglist; +} + +static cpl_mask* +hdrl_flat_crea_static_mask(const cpl_size ima_sx, + const cpl_size ima_sy, + const hdrl_parameter * rect) +{ + const cpl_size b_llx = hdrl_rect_region_get_llx(rect); + const cpl_size b_lly = hdrl_rect_region_get_lly(rect); + const cpl_size b_urx = hdrl_rect_region_get_urx(rect); + const cpl_size b_ury = hdrl_rect_region_get_ury(rect); + + cpl_mask * stat_mask = cpl_mask_new(ima_sx, ima_sy); + for(int j = b_lly; j < b_ury; j++) { + for(int i = b_llx; i < b_urx; i++) { + cpl_mask_set(stat_mask, i, j, CPL_BINARY_1); + } + } + return stat_mask; + +} + +/* +static cpl_error_code +hdrl_flat_save_results(hdrl_image* master, cpl_image* cmap, cpl_mask* stat_mask) +{ + + cpl_image_save(hdrl_image_get_image(master), "master_data.fits", + CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT); + cpl_image_save(hdrl_image_get_error(master), "master_errs.fits", + CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT); + cpl_image_save(cmap, "master_map.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_DEFAULT); + + if (stat_mask != NULL) { + cpl_mask_save(stat_mask, "static_mask.fits", NULL, CPL_IO_DEFAULT); + } + + return cpl_error_get_code(); +} + */ + +/* this function is to verify that the image and error values in the + * lower left corner and at a given data point are as expected + */ +static cpl_error_code +hdrl_flat_test_case(hdrl_imagelist* imglist, + const hdrl_parameter * rect, + const hdrl_flat_method method, + const cpl_size fsx, + const cpl_size fsy, + const hdrl_parameter* collapse_params, + const int mask_sw, + const double val1, + const double err1, + const double val2, + const double err2) + +{ + hdrl_parameter * fparam ; + cpl_mask * stat_mask = NULL; + hdrl_image * hima; + cpl_size ima_sx; + cpl_size ima_sy; + + const cpl_size b_llx = hdrl_rect_region_get_llx(rect); + const cpl_size b_lly = hdrl_rect_region_get_lly(rect); + const cpl_size b_urx = hdrl_rect_region_get_urx(rect); + const cpl_size b_ury = hdrl_rect_region_get_ury(rect); + + cpl_size b_cx = (int)(0.5 * (b_llx + b_urx) + 0.5); + cpl_size b_cy = (int)(0.5 * (b_lly + b_ury) + 0.5); + hima = hdrl_imagelist_get(imglist,0); + ima_sx = hdrl_image_get_size_x(hima); + ima_sy = hdrl_image_get_size_y(hima); + int bad; + hdrl_image * master = NULL; + cpl_image * contrib_map = NULL; + + fparam = hdrl_flat_parameter_create(fsx, fsy, method); + + if(mask_sw) { + stat_mask=hdrl_flat_crea_static_mask(ima_sx, ima_sy, rect); + } + + hdrl_flat_compute(imglist, stat_mask, collapse_params, + fparam, &master, &contrib_map); + //hdrl_flat_save_results(master, contrib_map, stat_mask); + + cpl_test_eq(cpl_image_get(hdrl_image_get_image(master), 1, 1, &bad), val1); + cpl_test_eq(cpl_image_get(hdrl_image_get_error(master), 1, 1, &bad), err1); + + cpl_test_eq(cpl_image_get(hdrl_image_get_image(master), b_cx, b_cy, &bad), + val2); + + cpl_msg_warning(cpl_func,"Check for err2 = %g still to be implemented", + err2); + + /* + cpl_msg_warning(cpl_func,"check sub data=%g %g", + cpl_image_get(hdrl_image_get_image(master), 1, 1, &bad), val1); //ok + cpl_msg_warning(cpl_func,"check2 sub data=%g %g", + cpl_image_get(hdrl_image_get_image(master), + b_cx, b_cy, &bad),val2);//ok + + cpl_msg_warning(cpl_func,"check sub error=%g %g", + cpl_image_get(hdrl_image_get_error(master), 1, 1, &bad), err1);//nok + cpl_msg_warning(cpl_func,"check2 sub error=%g %g", + cpl_image_get(hdrl_image_get_error(master), + b_cx, b_cy, &bad),err2); + */ + + /* Note: HDRL fully propagates errors. The error on the mean is not per + * pixel but for uniform error image it is divided by sqrt(npix). + * Thus one cannot compare the pixel values of the image with the error + * computed on the image. + */ + + + hdrl_parameter_delete(fparam); + hdrl_image_delete(master); + cpl_mask_delete(stat_mask); + cpl_image_delete(contrib_map); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check flat algorithm for various collapsing/smoothing conditions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_flat_test_multi_options(void) +{ + /* input data */ + const cpl_size ima_sx = 200; + const cpl_size ima_sy = 300; + const cpl_size b_llx = 100; + const cpl_size b_lly = 100; + const cpl_size b_urx = 200; + const cpl_size b_ury = 200; + const cpl_size nima = 5; + const double outlier = 100000; + hdrl_parameter * rect_region_bad_area_def = + hdrl_rect_region_parameter_create(b_llx, b_lly, b_urx, + b_ury); + + /* image intensity values distributed as 2^n */ + cpl_vector * vals = cpl_vector_new(nima); + cpl_vector * valserr_rel = cpl_vector_new(nima); //relative error + const double base = 2; + + for (int i = 0; i < nima ; ++i) { + double intensity = pow(base, i); + cpl_vector_set(vals, i, intensity); + cpl_vector_set(valserr_rel, i, sqrt(intensity)/intensity); + } + + hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx, + ima_sy, vals); + hdrl_flat_imlist_flag_region(imglist, rect_region_bad_area_def, outlier, 0); + + /* flat parameters */ + cpl_size filter_size_x = 1; + cpl_size filter_size_y = 1; + const double r_median = 25000; + const double r_mean = 38750; + /* case 1: + * + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask=NULL, + * colapse_method: median + */ + + /* Error propagation for pixel 1,1 */ + cpl_vector_power(valserr_rel, 2); + + double error_expected_pix1_mean = sqrt(cpl_vector_get_sum(valserr_rel))/nima; + double error_expected_pix1_median = error_expected_pix1_mean* sqrt(CPL_MATH_PI_2); + + + hdrl_parameter *collapse_pMean = hdrl_collapse_mean_parameter_create(); + hdrl_parameter *collapse_pMedian = hdrl_collapse_median_parameter_create(); + + + /* in the following cases (2-8) it is difficult to verify the error value at + * the image centre because the image intensities are on purpose distributed + * with complex values. + */ + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW, + filter_size_x, filter_size_y, collapse_pMedian, 0, + 1, error_expected_pix1_median, r_median, 91.4844); + + /* case 2: + * + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask!=NULL, + * colapse_method: median + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW, + filter_size_x, filter_size_y, collapse_pMedian, 1, + 1, error_expected_pix1_median, r_median, 91.4844); + + /* case 3: + * + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask=NULL, + * colapse_method: mean + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW, + filter_size_x, filter_size_y, collapse_pMean, 0, + 1, error_expected_pix1_mean, r_mean, 72.994); + + /* case 4: + * + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask!=NULL, + * colapse_method: mean + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_LOW, + filter_size_x, filter_size_y, collapse_pMean, 1, + 1, error_expected_pix1_mean,r_mean,72.994);// error TBV + + /* case 5: + * + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: median + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH, + filter_size_x, filter_size_y, collapse_pMedian, 0, + 1, error_expected_pix1_median, 1, 0.00177245); + + /* case 6: + * + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask!=NULL, + * colapse_method: median + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH, + filter_size_x, filter_size_y, collapse_pMedian, 1, + 1, error_expected_pix1_median, 1, 0.00177245); + + /* case 7: + * + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: mean + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH, + filter_size_x, filter_size_y, collapse_pMean, 0, + 1, error_expected_pix1_mean, 1, 0.00141421); + + /* case 8: + * + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask!=NULL, + * colapse_method: mean + */ + + hdrl_flat_test_case(imglist, rect_region_bad_area_def, HDRL_FLAT_FREQ_HIGH, + filter_size_x, filter_size_y, collapse_pMean, 1, + 1, error_expected_pix1_mean, 1, 0.00141421); + + /* free memory */ + hdrl_parameter_delete(collapse_pMean); + hdrl_parameter_delete(collapse_pMedian); + + hdrl_parameter_delete(rect_region_bad_area_def); + hdrl_imagelist_delete(imglist); + cpl_vector_delete(vals); + cpl_vector_delete(valserr_rel); + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check flat results in case of a static mask on three regions + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_flat_test_static_mask(void) +{ + /* input data */ + const cpl_size ima_sx = 200; + const cpl_size ima_sy = 300; + + const cpl_size r1_llx = 50; + const cpl_size r1_lly = 50; + const cpl_size r1_urx = 80; + const cpl_size r1_ury = 250; + const double outlier1 = 100000; + + const cpl_size r2_llx = 100; + const cpl_size r2_lly = 90; + const cpl_size r2_urx = 130; + const cpl_size r2_ury = 260; + const double outlier2 = 200000; + + const cpl_size r3_llx = 150; + const cpl_size r3_lly = 80; + const cpl_size r3_urx = 180; + const cpl_size r3_ury = 270; + const double outlier3 = 300000; + + const cpl_size nima = 5; + hdrl_parameter * rect1 = hdrl_rect_region_parameter_create(r1_llx, r1_lly, + r1_urx, r1_ury); + + hdrl_parameter * rect2 = hdrl_rect_region_parameter_create(r2_llx, r2_lly, + r2_urx, r2_ury); + + hdrl_parameter * rect3 = hdrl_rect_region_parameter_create(r3_llx, r3_lly, + r3_urx, r3_ury); + + /* image intensity values distributed as 2^n */ + cpl_vector * vals = cpl_vector_new(nima); + + const double base = 2; + for (int i = 0; i < nima ; ++i) { + double intensity = pow(base, i); + cpl_vector_set(vals, i, intensity); + } + + hdrl_imagelist* imglist = hdrl_flat_create_uniform_images(nima, ima_sx, + ima_sy, vals); + hdrl_flat_imlist_flag_region(imglist, rect1, outlier1, 1); + hdrl_flat_imlist_flag_region(imglist, rect2, outlier2, 1); + hdrl_flat_imlist_flag_region(imglist, rect3, outlier3, 1); + + /* flat parameters */ + cpl_size filter_size_x = 1; + cpl_size filter_size_y = 1; + const double r_mean = 38750; + const double e_mean = 72.994; //TBV + //const double r_mean=25000; + + + + + hdrl_parameter *collapse_pMean = hdrl_collapse_mean_parameter_create(); + hdrl_parameter *collapse_pMedian = hdrl_collapse_median_parameter_create(); + + /* case 1: + * + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask=NULL, + * colapse_method: mean + */ + + hdrl_flat_test_case(imglist, rect1, HDRL_FLAT_FREQ_LOW, + filter_size_x, filter_size_y, collapse_pMean, 0, + 1, 0.278388, r_mean, e_mean); + + + + + /* case 2: + * + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: mean + */ + + hdrl_flat_test_case(imglist, rect1, HDRL_FLAT_FREQ_HIGH, + filter_size_x, filter_size_y, collapse_pMean, 0, + 1, 0.278388, 1, 0.00141421); // error TBV + + /* case 3: + * + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: median + */ + + hdrl_flat_test_case(imglist, rect1, HDRL_FLAT_FREQ_HIGH, + filter_size_x, filter_size_y, collapse_pMedian, 0, + 1, 0.278388, 1, 0.00141421); // error TBV + + + /* free memory */ + hdrl_parameter_delete(collapse_pMean); + hdrl_parameter_delete(collapse_pMedian); + + hdrl_parameter_delete(rect1); + hdrl_parameter_delete(rect2); + hdrl_parameter_delete(rect3); + hdrl_imagelist_delete(imglist); + cpl_vector_delete(vals); + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Check flat results in case of a uniform input + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_flat_test_data_value_basic(void) +{ + /* input data */ + const cpl_size ima_sx = 51; + const cpl_size ima_sy = 31; + int npix = ima_sx * ima_sy; + const cpl_size filter_size_x = 1; + const cpl_size filter_size_y = 1; + const cpl_size nima = 9; + + /* image intensity values distributed as 2^n */ + cpl_vector * vals = cpl_vector_new(nima); + double value = 9; + double error = sqrt(value); + cpl_vector_fill(vals, value); + + hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx, + ima_sy, vals); + cpl_vector_delete(vals); + + hdrl_parameter * flat_params; + hdrl_image * master = NULL; + cpl_image * contrib_map = NULL; + hdrl_value res; + double expected_error; + /* case 1: + * 9 images each of value 9, + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask=NULL, + * colapse_method: mean + * + * expected results: + * master should have value 1 (master is normalised), + * error 3./9./math.sqrt(9) / math.sqrt(51*31) + * contribution map should be NULL. + */ + flat_params = hdrl_flat_parameter_create(filter_size_x, filter_size_y, + HDRL_FLAT_FREQ_LOW); + + hdrl_parameter * collapse_params = hdrl_collapse_mean_parameter_create(); + hdrl_flat_compute(imglist, NULL, collapse_params, flat_params, &master, + &contrib_map); + hdrl_parameter_delete(flat_params); + + //hdrl_flat_save_results(master, contrib_map, NULL); + + expected_error = error / value / sqrt(nima) / sqrt(ima_sx * ima_sy); + + res = hdrl_image_get_mean(master); + cpl_test_abs( res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs( res.error, expected_error, HDRL_EPS_ERROR); + /* Note: HDRL fully propagates errors. The error on the mean is not per + * pixel but for uniform error image it is divided by sqrt(npix). + * Thus one cannot compare the pixel values of the image with the error + * computed on the image. + */ + + res = hdrl_image_get_median(master); + cpl_test_abs( res.data, 1, HDRL_EPS_ERROR); + /* here error changes with respect to mean case by a + * factor sqrt(CPL_MATH_PI_2), see HDRL documentation, section on + * Statistical estimators + */ + cpl_test_abs( res.error, expected_error * sqrt(CPL_MATH_PI_2), + HDRL_EPS_ERROR); + + /* TODO: why not stdev does not return hdrl_value (with stdev of error) */ + cpl_test_abs( hdrl_image_get_stdev(master), 0, HDRL_EPS_ERROR); + + res = hdrl_image_get_sum(master); + cpl_test_abs( res.data, npix, HDRL_EPS_ERROR); + /* Error associated to not normalised image is: sqrt (npix*err^2). + * As the data are normalised error is sqrt (npix*err_norm^2)/ ndata + * error = sqrt(npix) / ndata + */ + cpl_test_abs( res.error, sqrt(npix) / nima, npix * HDRL_EPS_ERROR); + + cpl_test_abs( cpl_image_get_mean(contrib_map), nima, HDRL_EPS_ERROR ); + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + + /* case 2: + * 9 images each of value 9, + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: mean + * + * expected results: + * master should have value 1 (master is normalised), + * error 3, + * contribution map should be NULL. + */ + flat_params = hdrl_flat_parameter_create(filter_size_x, filter_size_y, + HDRL_FLAT_FREQ_HIGH); + + hdrl_flat_compute(imglist, NULL, collapse_params, flat_params, &master, + &contrib_map); + hdrl_parameter_delete(flat_params); + + //hdrl_flat_save_results(master, contrib_map, NULL); + + expected_error = error / value / sqrt(nima) / sqrt(ima_sx * ima_sy); + res = hdrl_image_get_mean(master); + cpl_test_abs( res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs( res.error, expected_error, HDRL_EPS_ERROR); + + res = hdrl_image_get_median(master); + cpl_test_abs( res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs( res.error, expected_error * sqrt(CPL_MATH_PI_2), + HDRL_EPS_ERROR); + + cpl_test_abs( hdrl_image_get_stdev(master), 0, HDRL_EPS_ERROR); + + res = hdrl_image_get_sum(master); + cpl_test_abs( res.data, npix, HDRL_EPS_ERROR); + /* Error associated to not normalised image is: sqrt (npix*err^2). + * As the data are normalised error is sqrt (npix*err_norm^2)/ ndata + * error = sqrt(npix) / ndata + */ + cpl_test_abs( res.error, sqrt(npix) / nima, npix * HDRL_EPS_ERROR); + + cpl_test_abs( cpl_image_get_mean(contrib_map), nima, HDRL_EPS_ERROR); + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + /* free memory */ + hdrl_imagelist_delete(imglist); + hdrl_parameter_delete(collapse_params); + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Check flat results in case of a uniform input and a static mask + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_flat_test_data_value_bpm(void) +{ + /* input data */ + const cpl_size ima_sx = 51; + const cpl_size ima_sy = 31; + + const cpl_size filter_size_x = 1; + const cpl_size filter_size_y = 1; + + const cpl_size nima = 9; + + /* image intensity values distributed as 2^n */ + cpl_vector * vals = cpl_vector_new(nima); + double value = 9; + double error = sqrt(value); + cpl_vector_fill(vals, value); + + hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx, + ima_sy, vals); + cpl_vector_delete(vals); + const cpl_size r1_llx = 11; + const cpl_size r1_lly = 11; + const cpl_size r1_urx = 31; + const cpl_size r1_ury = 23; + cpl_size xsam=0; + cpl_size ysam=0; + const double outlier1 = 10000; + + hdrl_parameter * rect1 = + hdrl_rect_region_parameter_create(r1_llx, r1_lly, r1_urx, + r1_ury); + hdrl_flat_imlist_flag_region(imglist, rect1, outlier1, 1); + hdrl_parameter_delete(rect1); + + hdrl_parameter * flat_params; + hdrl_image * master = NULL; + cpl_image * contrib_map = NULL; + hdrl_value res; + double expected_error; + double expected_value; + /* case 1: + * 9 images each of value 9, + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask=NULL, + * colapse_method: mean + * + * expected results: + * master should have value 1 (master is normalised), + * error 3./9./math.sqrt(9) / math.sqrt(51*31) + * contribution map should be NULL. + */ + flat_params = hdrl_flat_parameter_create(filter_size_x, filter_size_y, + HDRL_FLAT_FREQ_LOW); + + hdrl_parameter * collapse_params = hdrl_collapse_mean_parameter_create(); + hdrl_flat_compute(imglist, NULL, collapse_params, flat_params, &master, + &contrib_map); + hdrl_parameter_delete(flat_params); + //hdrl_flat_save_results(master, contrib_map, NULL); + + xsam = 0.5 * (r1_llx+r1_urx); + ysam = 0.5 * (r1_lly+r1_ury); + int status; + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + cpl_test( isnan(res.data)); + cpl_test( isnan(res.error)); + cpl_test_abs( expected_value, 0, HDRL_EPS_ERROR ); + + /* 3./9./math.sqrt(9) */ + + xsam = 0.5 * (ima_sx+r1_urx); + ysam = 0.5 * (ima_sy+r1_ury); + expected_error = error / value / sqrt(nima); + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + cpl_test_abs(res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR); + cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR ); + + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + /* case 2: + * 9 images each of value 9, + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: mean + * + * expected results: + * master should have value 1 (master is normalised), + * error 3, + * contribution map should be NULL. + */ + flat_params = hdrl_flat_parameter_create(filter_size_x, filter_size_y, + HDRL_FLAT_FREQ_HIGH); + + hdrl_flat_compute(imglist, NULL, collapse_params, flat_params, &master, + &contrib_map); + hdrl_parameter_delete(flat_params); + //hdrl_flat_save_results(master, contrib_map, NULL); + + xsam = 0.5 * (r1_llx+r1_urx); + ysam = 0.5 * (r1_lly+r1_ury); + + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + cpl_test( isnan(res.data)); + cpl_test( isnan(res.error)); + + cpl_test_abs( expected_value, 0, HDRL_EPS_ERROR ); + /* 3./9./math.sqrt(9) */ + + xsam = 0.5 * (ima_sx+r1_urx); + ysam = 0.5 * (ima_sy+r1_ury); + expected_error = error / value / sqrt(nima); + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + cpl_test_abs(res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR); + cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR ); + + + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + /* free memory */ + hdrl_imagelist_delete(imglist); + hdrl_parameter_delete(collapse_params); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check flat results in case of a uniform input and a static mask + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_flat_test_data_value_bpm_static(void) +{ + /* input data */ + const cpl_size ima_sx = 51; + const cpl_size ima_sy = 31; + + const cpl_size filter_size_x = 1; + const cpl_size filter_size_y = 1; + const cpl_size nima = 9; + + /* image intensity values distributed as 2^n */ + cpl_vector * vals = cpl_vector_new(nima); + double value = 9; + double error = sqrt(value); + cpl_vector_fill(vals, value); + + hdrl_imagelist * imglist = hdrl_flat_create_uniform_images(nima, ima_sx, + ima_sy, vals); + cpl_vector_delete(vals); + const cpl_size r1_llx = 11; + const cpl_size r1_lly = 11; + const cpl_size r1_urx = 31; + const cpl_size r1_ury = 23; + cpl_size xsam=0; + cpl_size ysam=0; + const double outlier1 = 10000; + + hdrl_parameter * rect1 = + hdrl_rect_region_parameter_create(r1_llx, r1_lly, r1_urx, + r1_ury); + hdrl_flat_imlist_flag_region(imglist, rect1, outlier1, 0); + hdrl_parameter_delete(rect1); + + hdrl_parameter * flat_params; + hdrl_image * master = NULL; + cpl_image * contrib_map = NULL; + hdrl_value res; + double expected_error; + double expected_value; + /* case 1: + * 9 images each of value 9, + * flat method=HDRL_FLAT_FREQ_LOW, + * stat_mask=NULL, + * colapse_method: mean + * + * expected results: + * master has value 1 (master is normalised) where points are not masked, + * and outlier/nima=111.11 where points are masked + * error 3./9./math.sqrt(9) / math.sqrt(51*31) + * contribution map should be NULL. + */ + flat_params = hdrl_flat_parameter_create(filter_size_x, filter_size_y, + HDRL_FLAT_FREQ_LOW); + + hdrl_parameter * collapse_params = hdrl_collapse_mean_parameter_create(); + + /* creates and fill static mask */ + cpl_mask* static_bpm=cpl_mask_new(ima_sx,ima_sy); + for(int j = r1_lly; j < r1_ury; j++) { + for(int i = r1_llx; i < r1_urx; i++) { + cpl_mask_set(static_bpm, i, j, CPL_BINARY_1); + } + } + + hdrl_flat_compute(imglist, static_bpm, collapse_params, flat_params, + &master, &contrib_map); + hdrl_parameter_delete(flat_params); + //hdrl_flat_save_results(master, contrib_map, NULL); + + xsam = 0.5 * (r1_llx+r1_urx); + ysam = 0.5 * (r1_lly+r1_ury); + int status; + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + //expected_error = error / value / sqrt(nima); + expected_error = sqrt(outlier1) / value / sqrt(nima); + + cpl_test_abs( res.data, outlier1/nima, 13 * 21 * nima * HDRL_EPS_DATA); + cpl_test_abs( res.error, expected_error, 3 * HDRL_EPS_ERROR); + cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR ); + + + /* 3./9./math.sqrt(9) */ + + xsam = 0.5 * (ima_sx+r1_urx); + ysam = 0.5 * (ima_sy+r1_ury); + expected_error = error / value / sqrt(nima); + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + cpl_test_abs(res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR); + cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR ); + + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + /* case 2: + * 9 images each of value 9, + * flat method=HDRL_FLAT_FREQ_HIGH, + * stat_mask=NULL, + * colapse_method: mean + * + * expected results: + * master should have value 1 (master is normalised), + * error 3, + * contribution map should be NULL. + */ + flat_params = hdrl_flat_parameter_create(filter_size_x, filter_size_y, + HDRL_FLAT_FREQ_HIGH); + + hdrl_flat_compute(imglist, static_bpm, collapse_params, flat_params, + &master, &contrib_map); + hdrl_parameter_delete(flat_params); + //hdrl_flat_save_results(master, contrib_map, NULL); + + xsam = 0.5 * (r1_llx+r1_urx); + ysam = 0.5 * (r1_lly+r1_ury); + + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + expected_error = sqrt(outlier1) / outlier1 / sqrt(nima); + + cpl_test_abs( res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs( res.error, expected_error, 3 * HDRL_EPS_ERROR); + cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR ); + + + + /* 3./9./math.sqrt(9) */ + + xsam = 0.5 * (ima_sx+r1_urx); + ysam = 0.5 * (ima_sy+r1_ury); + expected_error = error / value / sqrt(nima); + expected_value = cpl_image_get(contrib_map, xsam, ysam, &status); + + res = hdrl_image_get_pixel(master, xsam, ysam, NULL); + + cpl_test_abs(res.data, 1, HDRL_EPS_ERROR); + cpl_test_abs(res.error, expected_error, HDRL_EPS_ERROR); + cpl_test_abs( expected_value, nima, HDRL_EPS_ERROR ); + + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + /* free memory */ + hdrl_imagelist_delete(imglist); + cpl_mask_delete(static_bpm); + hdrl_parameter_delete(collapse_params); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of BPM module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_flat_test_data_value_bpm(); + hdrl_flat_test_data_value_bpm_static(); + hdrl_flat_test_data_value_basic(); + hdrl_flat_test_multi_options(); + hdrl_flat_test_static_mask(); + hdrl_flat_test_parlist(); + + cpl_test_error(CPL_ERROR_NONE); + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_frameiter-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_frameiter-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_frameiter-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_frameiter-test.c 2017-09-20 10:02:45.000000000 +0000 @@ -0,0 +1,310 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_frameiter.h" + +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_frameiter_test + */ +/*----------------------------------------------------------------------------*/ + +static void check_strides(cpl_frameset * frames, intptr_t naxes, + intptr_t offsets[], intptr_t strides[], + intptr_t dims[], intptr_t values[], intptr_t len, + int swap) +{ + hdrl_iter * it; + char * soffset = cpl_sprintf("%s", "("); + char * sstride = cpl_sprintf("%s", "("); + char * sdim = cpl_sprintf("%s", "("); + for (intptr_t i = 0; i < naxes; i++) { + char * t = cpl_sprintf("%s%zd%s", soffset, offsets[i], + i == naxes - 1 ? ")" : ","); + cpl_free(soffset); + soffset = t; + t = cpl_sprintf("%s%zd%s", sstride, strides ? strides[i] : 0, + i == naxes - 1 ? ")" : ","); + cpl_free(sstride); + sstride = t; + t = cpl_sprintf("%s%zd%s", sdim, dims ? dims[i] : -1, + i == naxes - 1 ? ")" : ","); + cpl_free(sdim); + sdim = t; + } + cpl_msg_info(cpl_func, "testing offset %s, stride %s, dim %s, len %zd, " + "swap %d", soffset, sstride, sdim, len, swap); + cpl_free(soffset); + cpl_free(sstride); + cpl_free(sdim); + + intptr_t axes[] = {HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}; + if (swap) { + intptr_t tmp; + tmp = axes[0]; + axes[0] = axes[1]; + axes[1] = tmp; + } + it = hdrl_frameiter_new(frames, 0, naxes, axes, offsets, strides, dims); + cpl_test_eq(hdrl_iter_length(it), len); + int d; + int cnt = 0; + for (hdrl_frameiter_data * h = hdrl_iter_next(it); h != NULL; h = hdrl_iter_next(it)) { + cpl_test_eq(cpl_image_get(h->image, 1, 1, &d), values[cnt]); + cpl_image_delete(h->image); + cpl_propertylist_delete(h->plist); + cnt++; + } + cpl_test_eq(hdrl_iter_length(it), cnt); + hdrl_iter_delete(it); +} + +static void test_basic(void) +{ + size_t nframes = 5; + size_t next = 4; + cpl_frameset * frames = cpl_frameset_new(); + for (size_t i = 0; i < nframes; i++) { + char * fn = cpl_sprintf("frameiter%zu_%zd.fits", i, (intptr_t)getpid()); + cpl_propertylist * plist = cpl_propertylist_new(); + cpl_propertylist_update_string(plist, "TAG", fn); + cpl_propertylist_save(plist, fn, CPL_IO_CREATE); + cpl_propertylist_delete(plist); + for (size_t j = 1; j < next + 1; j++) { + cpl_image * img = cpl_image_new(50, 70, CPL_TYPE_INT); + cpl_image_add_scalar(img, i * next + j); + cpl_image_save(img, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND); + cpl_image_delete(img); + } + cpl_frame * frm = cpl_frame_new(); + cpl_frame_set_filename(frm, fn); + cpl_frame_set_tag(frm, "RAW"); + cpl_frameset_insert(frames, frm); + cpl_free(fn); + } + + /* empty iterator test */ + { + cpl_frameset * empty = cpl_frameset_new(); + hdrl_iter * it = + hdrl_frameiter_new(empty, 0, 1, (intptr_t[]){HDRL_FRAMEITER_AXIS_EXT}, + NULL, NULL, NULL); + cpl_test_eq(hdrl_iter_length(it), 0); + cpl_test_null(hdrl_iter_next(it)); + cpl_test_null(hdrl_iter_next(it)); + cpl_test_null(hdrl_iter_next(it)); + cpl_frameset_delete(empty); + hdrl_iter_delete(it); + } + /* one iteration axis */ + { + intptr_t values[next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = i + 1; + } + intptr_t offsets[] = {1}; + check_strides(frames, 1, offsets, NULL, NULL, values, ARRAY_LEN(values), 1); + } + /* two iteration axis basic */ + { + intptr_t values[nframes * next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = i + 1; + } + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {1, 1}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* two iteration axis offset (1,1) */ + { + intptr_t values[(nframes - 1) * next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = i + 1 + next; + } + intptr_t offsets[] = {1, 1}; + intptr_t strides[] = {1, 1}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* two iteration axis stride (1,2) */ + { + intptr_t values[nframes * (next / 2 + next % 2)]; + intptr_t c = 0; + for (size_t i = 0; i < nframes; i++) { + for (size_t j = 1; j < next + 1; j+=2) { + values[c++] = i * next + j; + } + } + cpl_test_eq(ARRAY_LEN(values), c); + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {1, 2}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* two iteration axis stride (2,1) */ + { + intptr_t values[(nframes / 2 + nframes % 2) * (next)]; + intptr_t c = 0; + for (size_t i = 0; i < nframes; i+=2) { + for (size_t j = 1; j < next + 1; j++) { + values[c++] = i * next + j; + } + } + cpl_test_eq(ARRAY_LEN(values), c); + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {2, 1}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* two iteration axis stride (2,2) */ + { + intptr_t values[(nframes / 2 + nframes % 2) * (next / 2 + next % 2)]; + intptr_t c = 0; + for (size_t i = 0; i < nframes; i+=2) { + for (size_t j = 1; j < next + 1; j+=2) { + values[c++] = i * next + j; + } + } + cpl_test_eq(ARRAY_LEN(values), c); + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {2, 2}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* stride 1,0 */ + { + intptr_t values[nframes * next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = (i / next) * next + 1; + } + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {1, 0}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* stride 0,1 */ + { + intptr_t values[nframes * next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = (i % next) + 1; + } + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {0, 1}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* stride 0,0 */ + { + intptr_t values[nframes * next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = 1; + } + intptr_t offsets[] = {0, 1}; + intptr_t strides[] = {0, 0}; + check_strides(frames, 2, offsets, strides, NULL, values, + ARRAY_LEN(values), 0); + } + /* swapped axes */ + { + intptr_t values[nframes * next]; + intptr_t c = 0; + for (size_t j = 1; j < next + 1; j++) { + for (size_t i = 0; i < nframes; i++) { + values[c++] = i * next + j; + } + } + cpl_test_eq(ARRAY_LEN(values), c); + intptr_t offsets[] = {1, 0}; + check_strides(frames, 2, offsets, NULL, NULL, values, + ARRAY_LEN(values), 1); + } + /* dim -1, -1 */ + { + intptr_t values[nframes * next]; + for (size_t i = 0; i < ARRAY_LEN(values); i++) { + values[i] = i + 1; + } + intptr_t offsets[] = {0, 1}; + intptr_t dims[] = {-1, -1}; + check_strides(frames, 2, offsets, NULL, dims, values, + ARRAY_LEN(values), 0); + } + /* dim -1, x*/ + { + intptr_t values[nframes * 3]; + intptr_t c = 0; + for (size_t i = 0; i < nframes; i++) { + for (size_t j = 1; j < 3 + 1; j++) { + values[c++] = i * next + j; + } + } + cpl_test_eq(ARRAY_LEN(values), c); + intptr_t offsets[] = {0, 1}; + intptr_t dims[] = {-1, 3}; + check_strides(frames, 2, offsets, NULL, dims, values, + ARRAY_LEN(values), 0); + } + /* dim x,-1*/ + { + intptr_t values[4 * next]; + intptr_t c = 0; + for (size_t i = 0; i < 4; i++) { + for (size_t j = 1; j < next + 1; j++) { + values[c++] = i * next + j; + } + } + cpl_test_eq(ARRAY_LEN(values), c); + intptr_t offsets[] = {0, 1}; + intptr_t dims[] = {4, -1}; + check_strides(frames, 2, offsets, NULL, dims, values, + ARRAY_LEN(values), 0); + } + + cpl_frameset_delete(frames); + if (system("rm -f frameiter*fits")) {} +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_basic(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_fringe-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_fringe-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_fringe-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_fringe-test.c 2017-09-18 14:35:28.000000000 +0000 @@ -0,0 +1,749 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + * + * hdrl_fringe-test.c + * + * Created on: May 11, 2015 + * Author: agabasch + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifndef HDRL_USE_PRIVATE +/* Make sure we pull in private functions like hdrl_mime_fringe_amplitudes. */ +#define HDRL_USE_PRIVATE +#endif + +#include "hdrl_fringe.h" +#include "hdrl_prototyping.h" +#include "hdrl_random.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_fringe_test Testing of the Fringe module + */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ +void test_hermite_sum(void); +void hdrl_fringe_compute_test_input(void); +void hdrl_fringe_correct_test_input(void); +void hdrl_fringe_hermite_test(void); +void hdrl_mime_fringe_amplitudes_test(void); +void hdrl_mime_fringe_amplitudes_ls_test(void); + +static cpl_matrix * hdrl_mime_hermite_functions_create(int n, double center, + double scale, const cpl_matrix * x); + + +void hdrl_fringe_hermite_test(void) +{ + cpl_matrix *x; + cpl_matrix *f; + cpl_matrix *funs; + cpl_matrix *coeffs; + cpl_matrix *hseries; + + double w, a, b; + double center, scale; + int i, n; + int nfun; + + + /* setting parameters: + n number of equispaced nodes + a, b endpoints of the interval of integration + nfun number of the Hermite functions + center center of the Hermite functions + scale scaling of the Hermite functions + */ + n = 10000; + a = -50.0; + b = 50.0; + + nfun = 20; + center = 0.1; + scale = 1.3; + + /* creating the equispaced nodes and weights */ + x = hdrl_mime_matrix_linspace_create(n, a, b); + cpl_test_nonnull(x); + w = (b - a) / (n - 1); + + /* creating the values of a test function */ + f = cpl_matrix_new(n, 1); + cpl_test_nonnull(f); + for (i = 0; i < n; i++) + { + double xi = (cpl_matrix_get_data(x))[i]; + (cpl_matrix_get_data(f))[i] = (1.0 + xi) * exp(-0.5 * xi * xi); + } + + /* test improper inputs are properly handled */ + funs = hdrl_mime_hermite_functions_create(nfun, center, scale, NULL); + cpl_test_null(funs); + cpl_test_error(CPL_ERROR_NULL_INPUT); + funs = hdrl_mime_hermite_functions_create(0, center, scale, x); + cpl_test_null(funs); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + funs = hdrl_mime_hermite_functions_create(nfun, center, 0.0, x); + cpl_test_null(funs); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + funs = hdrl_mime_hermite_functions_create(nfun, center, -1.0, x); + cpl_test_null(funs); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* test functionality is working */ + funs = hdrl_mime_hermite_functions_create(nfun, center, scale, x); + cpl_test_nonnull(funs); + cpl_test_error(CPL_ERROR_NONE); + + /* computing the Hermite coefficients of the function */ + coeffs = hdrl_mime_matrix_product_left_transpose_create(funs, f); + cpl_test_nonnull(coeffs); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_matrix_multiply_scalar(coeffs, w), CPL_ERROR_NONE); + + + /* Test error handling of hdrl_mime_hermite_series_create. */ + hseries = hdrl_mime_hermite_series_create(nfun, center, scale, NULL, x); + cpl_test_null(hseries); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hseries = hdrl_mime_hermite_series_create(nfun, center, scale, coeffs, NULL); + cpl_test_null(hseries); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hseries = hdrl_mime_hermite_series_create(nfun, center, scale, NULL, NULL); + cpl_test_null(hseries); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hseries = hdrl_mime_hermite_series_create(0, center, scale, coeffs, x); + cpl_test_null(hseries); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hseries = hdrl_mime_hermite_series_create(nfun, center, -1.0, coeffs, x); + cpl_test_null(hseries); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hseries = hdrl_mime_hermite_series_create(nfun, center, 0.0, coeffs, x); + cpl_test_null(hseries); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* comparing with the last partial sum */ + hseries = hdrl_mime_hermite_series_create(nfun, center, scale, coeffs, x); + cpl_test_nonnull(hseries); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_matrix_subtract(hseries, f), CPL_ERROR_NONE); + + /* cleaning up */ + cpl_matrix_delete(x); + cpl_matrix_delete(f); + cpl_matrix_delete(funs); + cpl_matrix_delete(coeffs); + cpl_matrix_delete(hseries); +} + + +void test_fringe_mime_gmx1(void) +{ + double x[1]; + double params[6]; + double result[6]; + double y; + +/* setting parameters */ + params[0] = 1.0; + params[1] = 2.0; + params[2] = sqrt(0.5); + + params[3] = 0.0; + params[4] = 2.0; + params[5] = sqrt(0.5); + +/* testing the values */ + x[0] = 1.0; + hdrl_mime_gmix1(x, params, &y); + cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15); + + x[0] = 2.0; + hdrl_mime_gmix1(x, params, &y); + cpl_test_leq(fabs(y - 1.0), 1e-15); + + x[0] = 3.0; + hdrl_mime_gmix1(x, params, &y); + cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15); + + hdrl_mime_gmix_derivs1(x, params, result); + cpl_test_leq(fabs(result[0] - 3.678794411714423e-01), 1e-15); + cpl_test_leq(fabs(result[1] - 7.357588823428847e-01), 1e-15); + cpl_test_leq(fabs(result[2] - 1.040520190045778e+00), 1e-15); + cpl_test_leq(fabs(result[3] - 3.678794411714423e-01), 1e-15); + cpl_test_zero(result[4]); + cpl_test_zero(result[5]); + +/* setting another set of parameters */ + params[0] = 0.0; + params[1] = 2.0; + params[2] = sqrt(0.5); + + params[3] = 1.0; + params[4] = 2.0; + params[5] = sqrt(0.5); + +/* testing the values */ + x[0] = 1.0; + hdrl_mime_gmix1(x, params, &y); + cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15); + + x[0] = 2.0; + hdrl_mime_gmix1(x, params, &y); + cpl_test_leq(fabs(y - 1.0), 1e-15); + + x[0] = 3.0; + hdrl_mime_gmix1(x, params, &y); + cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15); + + hdrl_mime_gmix_derivs1(x, params, result); + cpl_test_leq(fabs(result[0] - 3.678794411714423e-01), 1e-15); + cpl_test_zero(result[1]); + cpl_test_zero(result[2]); + cpl_test_leq(fabs(result[3] - 3.678794411714423e-01), 1e-15); + cpl_test_leq(fabs(result[4] - 7.357588823428847e-01), 1e-15); + cpl_test_leq(fabs(result[5] - 1.040520190045778e+00), 1e-15); + +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Create the Hermite functions. + * + * @param n Number of functions, + * @param center Center, + * @param scale Scale factor, + * @param x Nodes, at which the functions are evaluated. + * + * @return A matrix with the values of the functions. + * + * The i-th column contains the values of the i-th function at the + * given nodes. The functions have degrees 0, 1, ..., @a n-1. The + * specific dimensions of the matrix @a x are not used, only its size. + * The functions are normalized in the L2-sense. + * + * The returned matrix must be deallocated using cpl_matrix_delete(). + */ +/*---------------------------------------------------------------------------*/ +static cpl_matrix * hdrl_mime_hermite_functions_create(int n, double center, + double scale, const cpl_matrix * x) +{ + cpl_matrix *funs; + double *m; + const double *mx; + double rt, xi; + int i, j, nr; + + + /* testing input */ + cpl_ensure(x, CPL_ERROR_NULL_INPUT, NULL); + + if (n < 1 || scale <= 0.0) + { + cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return NULL; + } + +/* The specific dimensions of the matrix x are not used, only its size. */ + nr = cpl_matrix_get_nrow(x) * cpl_matrix_get_ncol(x); + +/* allocating memory */ + funs = cpl_matrix_new(nr, n); + +/* computing the normalization constant */ + rt = 1.0 / sqrt(sqrt(CPL_MATH_PI)); + +/* filling the first column */ + m = cpl_matrix_get_data(funs); + mx = cpl_matrix_get_data_const(x); + for (i = 0; i < nr; i++, m += n) + { + xi = (mx[i] - center) / scale; + m[0] = rt * exp(-0.5 * xi * xi); + } + +/* filling the second column */ + m = cpl_matrix_get_data(funs); + mx = cpl_matrix_get_data_const(x); + + for (i = 0; i < nr; i++, m += n) + { + xi = (mx[i] - center) / scale; + m[1] = rt * sqrt(2.0) * xi * exp(-0.5 * xi * xi); + } + +/* filling the remaining columns by recursion */ + m = cpl_matrix_get_data(funs); + for (i = 0; i < nr; i++, m += n) + { + xi = (mx[i] - center) / scale; + for (j = 2; j < n; j++) + { + m[j] = sqrt(2.0) * xi * m[j - 1] - sqrt(j - 1) * m[j - 2]; + m[j] = m[j] / sqrt(j); + } + } + +/* normalizing */ + cpl_matrix_multiply_scalar(funs, 1 / sqrt(scale)); + + return funs; +} + + +void test_hermite_sum(void) +{ + cpl_matrix *x; + cpl_matrix *sums; + + double a, b; + double center, scale; + int n, nfun; + + /* setting parameters: + n number of equispaced nodes + a, b endpoints of the sampled interval + nfun number of the Hermite functions + center center of the Hermite functions + scale scaling of the Hermite functions + */ + n = 6; + a = 0.0; + b = 5.0; + + nfun = 5; + center = 0.5; + scale = 1.3; + + /* creating the equispaced nodes and weights */ + x = hdrl_mime_matrix_linspace_create(n, a, b); + cpl_test_nonnull(x); + + /* Test error handling. */ + sums = hdrl_mime_hermite_functions_sums_create(nfun, center, scale, NULL); + cpl_test_null(sums); + cpl_test_error(CPL_ERROR_NULL_INPUT); + sums = hdrl_mime_hermite_functions_sums_create(0, center, scale, x); + cpl_test_null(sums); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + sums = hdrl_mime_hermite_functions_sums_create(nfun, center, 0.0, x); + cpl_test_null(sums); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + sums = hdrl_mime_hermite_functions_sums_create(nfun, center, -1.0, x); + cpl_test_null(sums); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* creating sums of the Hermite functions */ + sums = hdrl_mime_hermite_functions_sums_create(nfun, center, scale, x); + cpl_test_nonnull(sums); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_leq(fabs(cpl_matrix_get(sums, 0, 0) - 1.685081590066050e+00), + 1e-15); + cpl_test_leq(fabs(cpl_matrix_get(sums, 1, 0) - 9.093843925414908e-01), + 1e-15); + cpl_test_leq(fabs(cpl_matrix_get(sums, 2, 0) - 4.521636055506448e-01), + 1e-15); + cpl_test_leq(fabs(cpl_matrix_get(sums, 3, 0) - 8.130124958110769e-01), + 1e-15); + cpl_test_leq(fabs(cpl_matrix_get(sums, 4, 0) - 8.013868548156017e-01), + 1e-15); + + /* cleaning up */ + cpl_matrix_delete(x); + cpl_matrix_delete(sums); + + +} + + +void hdrl_fringe_compute_test_input(void) +{ + cpl_size nx = 21; + cpl_size ny= 32; + hdrl_parameter * collapse_params; + collapse_params = hdrl_collapse_mean_parameter_create(); + + hdrl_imagelist * ilist_fringe = hdrl_imagelist_new(); + cpl_imagelist * ilist_obj = cpl_imagelist_new(); + cpl_mask * stat_mask = cpl_mask_new(nx, ny); + + hdrl_image * master; + cpl_image * contrib_map; + + hdrl_image * hima1 = hdrl_image_new(nx, ny); + hdrl_image * hima2 = hdrl_image_new(nx, ny); + hdrl_image * hima_dimen1 = hdrl_image_new(nx+5, ny+10); + hdrl_image * hima_dimen2 = hdrl_image_new(nx+5, ny+10); + + cpl_image * cima1 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + cpl_image * cima2 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + + hdrl_image_add_scalar(hima1, (hdrl_value){1., 0.1}); + hdrl_image_add_scalar(hima2, (hdrl_value){10., 1.}); + cpl_image_add_scalar(cima1, 1.); + cpl_image_add_scalar(cima2, 10.); + + + hdrl_fringe_compute(NULL, ilist_obj, stat_mask, collapse_params, + &master, &contrib_map, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(master); + cpl_test_null(contrib_map); + + cpl_table *qctable = (cpl_table*)0xbadbeef; + hdrl_fringe_compute(NULL, ilist_obj, stat_mask, collapse_params, + &master, &contrib_map, &qctable); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(master); + cpl_test_null(contrib_map); + + hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, NULL, + &master, &contrib_map, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(master); + cpl_test_null(contrib_map); + + hdrl_imagelist_set(ilist_fringe, hima1, 0); + hdrl_imagelist_set(ilist_fringe, hima2, 1); + cpl_imagelist_set(ilist_obj, cima1, 0); + hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params, + &master, &contrib_map, NULL); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(master); + cpl_test_null(contrib_map); + cpl_imagelist_set(ilist_obj, cima2, 1); + + + hima2 = hdrl_imagelist_unset(ilist_fringe, 1); + hima1 = hdrl_imagelist_unset(ilist_fringe, 0); + hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params, + &master, &contrib_map, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(master); + cpl_test_null(contrib_map); + + /* Images in ilist_fringe and ilist_obj have now different dimensions */ + hdrl_imagelist_set(ilist_fringe, hima_dimen1, 0); + hdrl_imagelist_set(ilist_fringe, hima_dimen2, 1); + + hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params, + &master, &contrib_map, NULL); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(master); + cpl_test_null(contrib_map); + + hima_dimen2 = hdrl_imagelist_unset(ilist_fringe, 1); + hima_dimen1 = hdrl_imagelist_unset(ilist_fringe, 0); + + /* + cpl_msg_warning(cpl_func,"ilist_fringe=%p",ilist_fringe); + cpl_msg_warning(cpl_func,"ilist_obj=%p",ilist_obj); + cpl_msg_warning(cpl_func,"stat mask=%p",stat_mask); + cpl_msg_warning(cpl_func,"collapse params=%p",collapse_params); + cpl_msg_warning(cpl_func,"master=%p",master); + cpl_msg_warning(cpl_func,"contrib map=%p",contrib_map); + hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params, + &master, &contrib_map); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(master); + cpl_test_nonnull(contrib_map); + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + */ + + /* Test for success when computing a master fringe just from two frames + without any object or static masks. */ + hdrl_imagelist_set(ilist_fringe, hima1, 0); + hdrl_imagelist_set(ilist_fringe, hima2, 1); + hdrl_fringe_compute(ilist_fringe, NULL, NULL, collapse_params, + &master, &contrib_map, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(master); + cpl_test_nonnull(contrib_map); + hdrl_image_delete(master); + cpl_image_delete(contrib_map); + + /* Final cleanup */ + hdrl_image_delete(hima_dimen1); + hdrl_image_delete(hima_dimen2); + hdrl_imagelist_delete(ilist_fringe); + cpl_imagelist_delete(ilist_obj); + hdrl_parameter_delete(collapse_params); + cpl_mask_delete(stat_mask); +} + + +void hdrl_fringe_correct_test_input(void) +{ + cpl_size nx = 21; + cpl_size ny= 32; + + hdrl_imagelist * ilist_fringe = hdrl_imagelist_new(); + cpl_imagelist * ilist_obj = cpl_imagelist_new(); + cpl_mask * stat_mask = cpl_mask_new(nx, ny); + + hdrl_image * masterfringe = hdrl_image_new(nx, ny);; + + + hdrl_image * hima1 = hdrl_image_new(nx, ny); + hdrl_image * hima2 = hdrl_image_new(nx, ny); + + hdrl_image * hima_dimen1 = hdrl_image_new(nx+5, ny+10); + hdrl_image * hima_dimen2 = hdrl_image_new(nx+5, ny+10); + + cpl_image * cima1 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + cpl_image * cima2 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + + hdrl_image_add_scalar(hima1, (hdrl_value){1., 0.1}); + hdrl_image_add_scalar(hima2, (hdrl_value){10., 1.}); + cpl_image_add_scalar(cima1, 1.); + cpl_image_add_scalar(cima2, 10.); + + + hdrl_fringe_correct(NULL, ilist_obj, stat_mask, masterfringe, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_imagelist_set(ilist_fringe, hima1, 0); + hdrl_imagelist_set(ilist_fringe, hima2, 1); + cpl_imagelist_set(ilist_obj, cima1, 0); + hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_imagelist_set(ilist_obj, cima2, 1); + + + hima2 = hdrl_imagelist_unset(ilist_fringe, 1); + hima1 = hdrl_imagelist_unset(ilist_fringe, 0); + hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* Images in ilist_fringe and ilist_obj have now different dimensions */ + hdrl_imagelist_set(ilist_fringe, hima_dimen1, 0); + hdrl_imagelist_set(ilist_fringe, hima_dimen2, 1); + + hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hima_dimen2 = hdrl_imagelist_unset(ilist_fringe, 1); + hima_dimen1 = hdrl_imagelist_unset(ilist_fringe, 0); + + hdrl_imagelist_set(ilist_fringe, hima1, 0); + hdrl_imagelist_set(ilist_fringe, hima2, 1); + + hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_fringe_correct(ilist_fringe, ilist_obj, NULL, masterfringe, NULL); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_fringe_correct(ilist_fringe, NULL, NULL, masterfringe, NULL); + cpl_test_error(CPL_ERROR_NONE); + + + /* now we add real data: two frames with Poisson noise centred + * at different levels + */ + double* pdata = cpl_image_get_data_double(hdrl_image_get_image(hima1)); + int size = hdrl_image_get_size_x( hima1 ) * hdrl_image_get_size_y( hima1 ); + hdrl_random_state * rng = hdrl_random_state_new(1, NULL); + for(int i=0;i +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include "hdrl_test.h" + +#include + +#include +#include +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif +#define IMAGESZ 265 +#define IMAGENB 10 + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_imagelist_basic_test + Testing of hdrl_imagelist_basic module + */ +/*----------------------------------------------------------------------------*/ + +void test_image_basic_operations(void) +{ + /* Initialize values */ + hdrl_value value = {100., 10.}; + hdrl_value scalar = {1000., 100.}; + hdrl_value exponent = {2., 1.}; + + + /* Initialize images */ + hdrl_image *himg1 = hdrl_image_new(IMAGESZ, IMAGESZ); + hdrl_image *himg2 = hdrl_image_new(IMAGESZ, IMAGESZ); + hdrl_image *himg3 = hdrl_image_new(IMAGESZ, IMAGESZ); + + + /* Operations with images */ + hdrl_image_add_scalar(himg1, scalar); + hdrl_image_sub_scalar(himg1, value); + cpl_test_error(CPL_ERROR_NONE); + + + /* Initialize imageLists and add images */ + hdrl_imagelist *himlist1 = hdrl_imagelist_new(); + hdrl_imagelist_add_image(himlist1, himg1); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_imagelist *himlist2 = hdrl_imagelist_new(); + hdrl_imagelist_add_image(himlist2, himg2); + hdrl_imagelist_sub_image(himlist2, himg2); + hdrl_imagelist_add_image(himlist2, himg2); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_imagelist_add_imagelist(himlist1, himlist2); + hdrl_imagelist_sub_imagelist(himlist1, himlist2); + hdrl_imagelist_add_imagelist(himlist1, himlist2); + cpl_test_error(CPL_ERROR_NONE); + + + /* Complex operations with imageList: Div, Mul, Pow */ + hdrl_imagelist_div_scalar(himlist1, scalar); + hdrl_imagelist_div_image(himlist1, himg1); + hdrl_imagelist_div_imagelist(himlist1, himlist2); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_imagelist_mul_scalar(himlist1, scalar); + hdrl_imagelist_mul_image(himlist1, himg1); + hdrl_imagelist_mul_imagelist(himlist1, himlist2); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_imagelist_pow_scalar(himlist1, exponent); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_imagelist_add_image(himlist2, himg3); + hdrl_imagelist_add_imagelist(himlist1, himlist2); + hdrl_imagelist_pow_scalar(himlist1, exponent); + cpl_test_error(CPL_ERROR_NONE); + + + /* Clean up */ + hdrl_image_delete(himg1); + hdrl_image_delete(himg2); + hdrl_image_delete(himg3); + hdrl_imagelist_delete(himlist1) ; + hdrl_imagelist_delete(himlist2) ; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image_basic + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_image_basic_operations(); + + hdrl_imagelist * himlist ; + hdrl_image * himg ; + hdrl_image * himg2 ; + cpl_image * contrib ; + cpl_image * contrib2 ; + cpl_size nimages = IMAGENB ; + + /* Create an image list */ + himlist = hdrl_imagelist_new() ; + for (cpl_size i = 0 ; i < nimages ; i++) { + /* + What about having an + + hdrl_image_load_image(hdrl_image * hdrlimage + const char * filename, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum); + + hdrl_image_load_error(hdrl_image * hdrlimage + const char * filename, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum); + + with the same API like cpl? + two functions are better in the case the error is in another fitsfile + */ + + himg = hdrl_image_new(IMAGESZ, IMAGESZ); + if (i == nimages / 2) + hdrl_image_add_scalar(himg, (hdrl_value){1000, 100}); + else + hdrl_image_add_scalar(himg, (hdrl_value){i, 1}); + hdrl_imagelist_set(himlist, himg, i); + } + + /* Mean collapse */ + hdrl_imagelist_collapse_mean(himlist, &himg, &contrib); + hdrl_imagelist_collapse(himlist, HDRL_COLLAPSE_MEAN, &himg2, &contrib2); + hdrl_test_image_abs(himg, himg2, 0); + cpl_test_image_abs(contrib, contrib2, 0); + cpl_image_delete(contrib) ; + hdrl_image_delete(himg) ; + cpl_image_delete(contrib2) ; + hdrl_image_delete(himg2) ; + + /* Weighted Mean collapse */ + hdrl_imagelist_collapse_weighted_mean(himlist, &himg, &contrib); + hdrl_imagelist_collapse(himlist, HDRL_COLLAPSE_WEIGHTED_MEAN, &himg2, &contrib2); + hdrl_test_image_abs(himg, himg2, 0); + cpl_test_image_abs(contrib, contrib2, 0); + cpl_image_delete(contrib) ; + hdrl_image_delete(himg) ; + cpl_image_delete(contrib2) ; + hdrl_image_delete(himg2) ; + + /* Median collapse */ + hdrl_imagelist_collapse_median(himlist, &himg, &contrib); + hdrl_imagelist_collapse(himlist, HDRL_COLLAPSE_MEDIAN, &himg2, &contrib2); + hdrl_test_image_abs(himg, himg2, 0); + cpl_test_image_abs(contrib, contrib2, 0); + cpl_image_delete(contrib) ; + hdrl_image_delete(himg) ; + cpl_image_delete(contrib2) ; + hdrl_image_delete(himg2) ; + + /* Sigclip collapse */ + hdrl_parameter *psc = hdrl_collapse_sigclip_parameter_create(1., 3., 10); + hdrl_imagelist_collapse_median(himlist, &himg, &contrib); + hdrl_imagelist_collapse(himlist, psc, &himg2, &contrib2); + cpl_image_delete(contrib); + hdrl_image_delete(himg); + cpl_image_delete(contrib2); + hdrl_image_delete(himg2); + hdrl_parameter_delete(psc); + + /* MinMax collapse */ + hdrl_parameter *pmm = hdrl_collapse_minmax_parameter_create(1., 3.); + hdrl_imagelist_collapse_median(himlist, &himg, &contrib); + hdrl_imagelist_collapse(himlist, pmm, &himg2, &contrib2); + cpl_image_delete(contrib) ; + hdrl_image_delete(himg) ; + cpl_image_delete(contrib2) ; + hdrl_image_delete(himg2) ; + hdrl_parameter_delete(pmm); + + /* Unknown collapse mode */ + typedef hdrl_parameter_empty hdrl_collapse_unknown_parameter; + static hdrl_parameter_typeobj hdrl_collapse_unknown_parameter_type = { + -1, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_collapse_unknown_parameter), /* obj_size */ + }; + hdrl_collapse_unknown_parameter *unk = (hdrl_collapse_unknown_parameter *) + hdrl_parameter_new(&hdrl_collapse_unknown_parameter_type); + hdrl_parameter *punk = (hdrl_parameter *)unk; + hdrl_imagelist_collapse(himlist, punk, &himg2, &contrib2); + hdrl_parameter_delete(punk); + + + /* Collapse Direct */ + cpl_image *rej_low; + cpl_image *rej_high; + + /* Sigclip */ + hdrl_imagelist_collapse_sigclip(NULL, 1.0, 3.0, 10, &himg, &contrib, &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_imagelist_collapse_sigclip(himlist, 1.0, 3.0, 10, &himg, &contrib, NULL, NULL ); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + hdrl_image_delete(himg); + + hdrl_imagelist_collapse_sigclip(himlist, 1.0, 3.0, 10, &himg, &contrib, &rej_low, NULL ); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + cpl_image_delete(rej_low ); + hdrl_image_delete(himg); + + hdrl_imagelist_collapse_sigclip(himlist, 1.0, 3.0, 10, &himg, &contrib, NULL, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + cpl_image_delete(rej_high); + hdrl_image_delete(himg); + + hdrl_imagelist_collapse_sigclip(himlist, 1.0, 3.0, 10, &himg, &contrib, &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + cpl_image_delete(rej_low ); + cpl_image_delete(rej_high); + hdrl_image_delete(himg); + + /* MinMax */ + hdrl_imagelist_collapse_minmax(NULL, 1.0, 3.0, &himg, &contrib, &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_imagelist_collapse_minmax(himlist, 1.0, 3.0, &himg, &contrib, NULL, NULL ); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + hdrl_image_delete(himg); + + hdrl_imagelist_collapse_minmax(himlist, 1.0, 3.0, &himg, &contrib, &rej_low, NULL ); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + cpl_image_delete(rej_low ); + hdrl_image_delete(himg); + + hdrl_imagelist_collapse_minmax(himlist, 1.0, 3.0, &himg, &contrib, NULL, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + cpl_image_delete(rej_high); + hdrl_image_delete(himg); + + hdrl_imagelist_collapse_minmax(himlist, 1.0, 3.0, &himg, &contrib, &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(contrib ); + cpl_image_delete(rej_low ); + cpl_image_delete(rej_high); + hdrl_image_delete(himg); + + + /* Clean up */ + hdrl_imagelist_delete(himlist); + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_imagelist_io-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_imagelist_io-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_imagelist_io-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_imagelist_io-test.c 2017-09-14 14:20:05.000000000 +0000 @@ -0,0 +1,298 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013,2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include "hdrl_utils.h" +#include "hdrl_image.h" +#include "hdrl_test.h" + + +#include + +#include +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_imagelist_io-test + Testing of functions working on hdrl_imagelist + */ +/*----------------------------------------------------------------------------*/ + +void test_create(void) +{ + + /* create data initial data */ + cpl_imagelist * data = cpl_imagelist_new(); + cpl_imagelist * errs = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(64, 64, CPL_TYPE_DOUBLE); + cpl_image * err = cpl_image_new(64, 64, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img, 1. ); + cpl_image_add_scalar(err, 0.05); + + /* create expected results (err / sqrt(nz) for mean) */ + size_t n = 5; + for (size_t i = 0; i < n; i++) { + cpl_imagelist_set(data, cpl_image_duplicate(img), cpl_imagelist_get_size(data)); + cpl_imagelist_set(errs, cpl_image_duplicate(err), cpl_imagelist_get_size(errs)); + } + + /* new hdrl_imagelist */ + hdrl_imagelist * hl = hdrl_imagelist_create(data, errs); + cpl_test_eq(hdrl_imagelist_get_size(hl), n); + cpl_test_error(CPL_ERROR_NONE); + + /* Clean up */ + cpl_image_delete(img); + cpl_image_delete(err); + cpl_imagelist_delete(data); + cpl_imagelist_delete(errs); + hdrl_imagelist_delete(hl); +} + +void test_get(void) +{ + hdrl_imagelist * hl = NULL; + cpl_test_eq(hdrl_imagelist_get_size_x(hl), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_imagelist_get_size_y(hl), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_imagelist_get_size(hl), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hl = hdrl_imagelist_new(); + cpl_test_eq(hdrl_imagelist_get_size(hl), 0); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(hdrl_imagelist_get_size_x(hl), -1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_eq(hdrl_imagelist_get_size_y(hl), -1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_imagelist_set(hl, hdrl_image_new(5, 6), 0); + cpl_test_eq(hdrl_imagelist_get_size(hl), 1); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(hdrl_imagelist_get_size_x(hl), 5); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(hdrl_imagelist_get_size_y(hl), 6); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_imagelist_delete(hl); +} + +cpl_error_code test_interface(void) +{ + hdrl_imagelist * hl = hdrl_imagelist_new(); + hdrl_imagelist * h; + int c = 0; + hdrl_iter * it = hdrl_imagelist_get_iter_row_slices(hl, 1, 0, + HDRL_ITER_OWNS_DATA); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(it); + + it = hdrl_imagelist_get_iter_row_slices(NULL, 1, 0, HDRL_ITER_OWNS_DATA); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(it); + + hdrl_imagelist_set(hl, hdrl_image_new(5, 5), 0); + it = hdrl_imagelist_get_iter_row_slices(hl, 0, 0, HDRL_ITER_OWNS_DATA); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(it); + for (h = hdrl_iter_next(it); h != NULL; h = hdrl_iter_next(it)) { + c++; + } + cpl_test_eq(c, 5); + hdrl_iter_delete(it); + + hdrl_imagelist_set(hl, hdrl_image_new(5, 5), 0); + it = hdrl_imagelist_get_iter_row_slices(hl, 3, 0, 0); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(it); + c = 0; + for (h = hdrl_iter_next(it); h != NULL; h = hdrl_iter_next(it)) { + c++; + hdrl_imagelist_delete(h); + } + cpl_test_eq(c, 2); + hdrl_iter_delete(it); + + hdrl_imagelist_set(hl, hdrl_image_new(5, 5), 0); + it = hdrl_imagelist_get_iter_row_slices(hl, 3000, 0, HDRL_ITER_OWNS_DATA); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(it); + c = 0; + for (h = hdrl_iter_next(it); h != NULL; h = hdrl_iter_next(it)) { + c++; + } + cpl_test_eq(c, 1); + hdrl_iter_delete(it); + + hdrl_imagelist_delete(hl); + + return cpl_error_get_code(); +} + + +cpl_error_code test_iter(void) +{ + const cpl_size nx = 500; + const cpl_size ny = 571; + const cpl_size nz = 121; + const cpl_size yslice = 23; + hdrl_imagelist * hl = hdrl_imagelist_new(); + for (cpl_size i = 0; i < nz; i++) { + hdrl_image * img = hdrl_image_new(nx, ny); + hdrl_image_add_scalar(img, (hdrl_value){i, i}); + hdrl_image_reject(img, 1, 5); + if ((i % 5) == 0) { + hdrl_image_reject(img, 2, 5); + } + hdrl_imagelist_set(hl, img, i); + } + + for (cpl_size y = 1; y < ny + 1; y++) { + + hdrl_imagelist * lview = hdrl_imagelist_row_view(hl, y, y); + + hdrl_imagelist_add_scalar(lview, (hdrl_value){y, y}); + hdrl_imagelist_sub_scalar(lview, (hdrl_value){y, y}); + + int isConsistent = hdrl_imagelist_is_consistent(lview); + cpl_msg_debug(cpl_func, "Imagelist consistent? %d", isConsistent); + + /* Show the structure, the first time */ + if(y == 1){ + + hdrl_imagelist_dump_structure(lview, stdout); + + cpl_size llx = 1; + cpl_size lly = 1; + cpl_size urx = y; + cpl_size ury = y; + hdrl_imagelist_dump_window(lview, llx, lly, urx, ury, stdout); + } + + hdrl_imagelist_delete(lview); + } + + cpl_size ysum = 1; + hdrl_image * mean; + cpl_image * contrib; + hdrl_imagelist_collapse_mean(hl, &mean, &contrib); + hdrl_image * slicemean = hdrl_image_new(nx, ny); + cpl_image * slicecontrib = cpl_image_new(nx, ny, CPL_TYPE_INT); + + hdrl_iter * it = hdrl_imagelist_get_iter_row_slices(hl, yslice, 0, + HDRL_ITER_OWNS_DATA); + for (hdrl_imagelist * h = hdrl_iter_next(it); h != NULL; + h = hdrl_iter_next(it)) { + cpl_test_eq(hdrl_imagelist_get_size(h), nz); + hdrl_image * img = hdrl_imagelist_get(h, 0); + cpl_test_eq(hdrl_image_get_size_x(img), nx); + cpl_test_leq(hdrl_image_get_size_y(img), yslice); + hdrl_image * m; + cpl_image * c; + hdrl_imagelist_collapse_mean(h, &m, &c); + hdrl_image_copy(slicemean, m, 1, ysum); + cpl_image_copy(slicecontrib, c, 1, ysum); + hdrl_image_delete(m); + cpl_image_delete(c); + ysum += hdrl_image_get_size_y(img); + } + + cpl_test_eq(ysum - 1, ny); + hdrl_test_image_abs(slicemean, mean, nx * ny * DBL_EPSILON); + cpl_test_image_abs(slicecontrib, contrib, 0); + hdrl_iter_delete(it); + + /* test overlap iterator */ + ysum = 1; + cpl_size overlap = 5; + cpl_image_multiply_scalar(slicecontrib, 0); + hdrl_image_mul_scalar(slicemean, (hdrl_value){0., 0.}); + it = hdrl_imagelist_get_iter_row_slices(hl, yslice, overlap, + HDRL_ITER_OWNS_DATA); + for (hdrl_imagelist * h = hdrl_iter_next(it); h != NULL; + h = hdrl_iter_next(it)) { + cpl_test_eq(hdrl_imagelist_get_size(h), nz); + hdrl_image * img = hdrl_imagelist_get(h, 0); + cpl_test_eq(hdrl_image_get_size_x(img), nx); + + if (ysum == 1) { + cpl_test_leq(hdrl_image_get_size_y(img), yslice + overlap); + } else { + cpl_test_leq(hdrl_image_get_size_y(img), yslice + overlap * 2); + } + + hdrl_image * m; + cpl_image * c; + hdrl_imagelist_collapse_mean(h, &m, &c); + hdrl_il_rowsliceiter_data pdata = + hdrl_imagelist_iter_row_slices_get_data(it); + + hdrl_image * rm = hdrl_image_extract(m, 1, pdata.ly, nx, pdata.uy); + cpl_image * rc = cpl_image_extract(c, 1, pdata.ly, nx, pdata.uy); + hdrl_image_delete(m); + + hdrl_image_copy(slicemean, rm, 1, ysum); + cpl_image_copy(slicecontrib, rc, 1, ysum); + ysum += hdrl_image_get_size_y(rm); + hdrl_image_delete(rm); + cpl_image_delete(rc); + cpl_image_delete(c); + } + + cpl_test_eq(ysum - 1, ny); + hdrl_test_image_abs(slicemean, mean, nx * ny * DBL_EPSILON); + cpl_test_image_abs(slicecontrib, contrib, 0); + + hdrl_iter_delete(it); + hdrl_imagelist_delete(hl); + hdrl_image_delete(slicemean); + cpl_image_delete(slicecontrib); + hdrl_image_delete(mean); + cpl_image_delete(contrib); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_create(); + test_get(); + test_interface(); + test_iter(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_imagelist_view-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_imagelist_view-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_imagelist_view-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_imagelist_view-test.c 2017-08-28 07:23:35.000000000 +0000 @@ -0,0 +1,514 @@ +/* $Id: hdrl_imagelist_view-test.c,v 1.3 2013-10-22 08:26:11 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-22 08:26:11 $ + * $Revision: 1.3 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_imagelist.h" +#include "hdrl_test.h" +#include "hdrl_imagelist_view.h" /* TODO put in public api? */ + +#include + +#define IMG_PTR(a) \ + cpl_image_get_data(hdrl_image_get_image(a)) +#define ERR_PTR(a) \ + cpl_image_get_data(hdrl_image_get_image(a)) +#define MSK_PTR(a) \ + cpl_mask_get_data(hdrl_image_get_mask(a)) +#define CIMG_PTR(a) \ + cpl_image_get_data_const(hdrl_image_get_image_const(a)) +#define CERR_PTR(a) \ + cpl_image_get_data_const(hdrl_image_get_image_const(a)) +#define CMSK_PTR(a) \ + cpl_mask_get_data_const(hdrl_image_get_mask_const(a)) + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_imagelist_view_test + Testing of hdrl_imagelist_view module + */ +/*----------------------------------------------------------------------------*/ + +#define YSIZE 73 +#define XSIZE 50 + +cpl_error_code test_row_view(void) +{ + hdrl_imagelist * hlist; + hdrl_image * himg; + hdrl_image * himg2; + cpl_image * contrib; + cpl_image * contrib2; + + cpl_size nimages = 20; + hdrl_imagelist * view; + const hdrl_imagelist * cview; + cpl_imagelist * clist; + + /* Create an image list */ + hlist = hdrl_imagelist_new() ; + clist = cpl_imagelist_new() ; + for (cpl_size i = 0 ; i < nimages ; i++) { + + cpl_image *ima = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_DATA); + cpl_image *ima_err = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_ERROR); + + cpl_image_add_scalar(ima_err, 1.); + cpl_image_reject(ima, 1, 5); + if ((i % 5) == 0) { + cpl_image_reject(ima, 2, 5); + } + himg = hdrl_image_create(ima, ima_err); + cpl_image_delete(ima_err); + hdrl_imagelist_set(hlist, himg, i); + cpl_imagelist_set(clist, ima, i); + } + + view = hdrl_imagelist_row_view(NULL, 10, 20); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_NULL_INPUT); + view = hdrl_imagelist_row_view(hlist, 20, 10); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + view = hdrl_imagelist_row_view(hlist, 0, 10); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + view = hdrl_imagelist_row_view(hlist, 1, YSIZE + 11); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + + /* const variant */ + cview = hdrl_imagelist_const_row_view(NULL, 10, 20); + cpl_test_null(cview); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cview = hdrl_imagelist_const_row_view(hlist, 20, 10); + cpl_test_null(cview); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cview = hdrl_imagelist_const_row_view(hlist, 0, 10); + cpl_test_null(cview); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cview = hdrl_imagelist_const_row_view(hlist, 1, YSIZE + 11); + cpl_test_null(cview); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + + // Mean collapse + hdrl_imagelist_collapse_mean(hlist, &himg, &contrib); + + view = hdrl_imagelist_row_view(hlist, 1, YSIZE); + hdrl_imagelist_collapse_mean(view, &himg2, &contrib2); + + hdrl_test_image_abs(himg, himg2, 0); + cpl_test_image_abs(contrib, contrib2, 0); + cpl_image * ccontrib = cpl_image_new_from_accepted(clist); + cpl_test_image_abs(ccontrib, contrib2, 0); + cpl_image * cerror = cpl_image_cast(ccontrib, HDRL_TYPE_ERROR); + cpl_image_power(cerror, -0.5); + cpl_test_image_abs(hdrl_image_get_error(himg), cerror, HDRL_EPS_ERROR); + cpl_image_delete(contrib2); + hdrl_image_delete(himg2); + cpl_image_delete(cerror); + + /* const variant */ + cview = hdrl_imagelist_const_row_view(hlist, 1, YSIZE); + hdrl_imagelist_collapse_mean(view, &himg2, &contrib2); + + hdrl_test_image_abs(himg, himg2, 0); + cpl_test_image_abs(contrib, contrib2, 0); + cpl_test_image_abs(ccontrib, contrib2, 0); + cerror = cpl_image_cast(ccontrib, HDRL_TYPE_ERROR); + cpl_image_power(cerror, -0.5); + cpl_test_image_abs(hdrl_image_get_error(himg), cerror, HDRL_EPS_ERROR); + hdrl_image_delete(himg); + cpl_image_delete(contrib2); + hdrl_image_delete(himg2); + cpl_image_delete(ccontrib); + cpl_image_delete(cerror); + cpl_image_delete(contrib); + + /* one has no bpm */ + hdrl_image * iorig = hdrl_imagelist_get(hlist, 1); + hdrl_image * iview = hdrl_imagelist_get(view, 1); + cpl_test_eq_ptr(IMG_PTR(iorig), IMG_PTR(iview)); + cpl_test_eq_ptr(ERR_PTR(iorig), ERR_PTR(iview)); + cpl_test_eq_ptr(MSK_PTR(iorig), MSK_PTR(iview)); + + hdrl_image * ciview = hdrl_imagelist_get(cview, 1); + cpl_test_eq_ptr(IMG_PTR(iorig), CIMG_PTR(ciview)); + cpl_test_eq_ptr(ERR_PTR(iorig), CERR_PTR(ciview)); + cpl_test_eq_ptr(MSK_PTR(iorig), CMSK_PTR(ciview)); + + /* zero has bpm */ + iorig = hdrl_imagelist_get(hlist, 0); + iview = hdrl_imagelist_get(view, 0); + cpl_test_eq_ptr(IMG_PTR(iorig), IMG_PTR(iview)); + cpl_test_eq_ptr(ERR_PTR(iorig), ERR_PTR(iview)); + cpl_test_eq_ptr(MSK_PTR(iorig), MSK_PTR(iview)); + + ciview = hdrl_imagelist_get(cview, 0); + cpl_test_eq_ptr(IMG_PTR(iorig), CIMG_PTR(ciview)); + cpl_test_eq_ptr(ERR_PTR(iorig), CERR_PTR(ciview)); + cpl_test_eq_ptr(MSK_PTR(iorig), CMSK_PTR(ciview)); + + hdrl_image * icopy = hdrl_image_duplicate(iview); + cpl_test_eq(hdrl_image_get_size_y(icopy), YSIZE); + cpl_test_noneq_ptr(IMG_PTR(icopy), IMG_PTR(iview)); + cpl_test_noneq_ptr(ERR_PTR(icopy), ERR_PTR(iview)); + cpl_test_noneq_ptr(MSK_PTR(icopy), MSK_PTR(iview)); + hdrl_image_delete(icopy); + + hdrl_imagelist * lcopy = hdrl_imagelist_duplicate(view); + hdrl_imagelist_delete(view); + cpl_test_eq(hdrl_imagelist_get_size(lcopy), nimages); + cpl_test_eq(hdrl_image_get_size_y(hdrl_imagelist_get(lcopy, 0)), YSIZE); + hdrl_imagelist_delete(lcopy); + + cpl_size nsizey = YSIZE - 17 - 5 + 1; + view = hdrl_imagelist_row_view(hlist, 5, YSIZE - 17); + hdrl_image * vimg = hdrl_imagelist_get(view, 0); + hdrl_image_add_scalar(vimg, (hdrl_value){5, 1}); + + cpl_test_eq(hdrl_image_get_size_x(vimg), XSIZE); + cpl_test_eq(hdrl_image_get_size_y(vimg), nsizey); + + hdrl_image * orig = hdrl_imagelist_get(hlist, 0); + /* mean of original image (mix of 5s and zeros) */ + cpl_test_noneq(hdrl_image_get_mean(orig).data, 5); + + vimg = hdrl_imagelist_get(view, 0); + cpl_test_rel(hdrl_image_get_mean(vimg).data, 5, + HDRL_EPS_DATA * XSIZE * YSIZE); + + hdrl_imagelist_delete(view); + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + hdrl_imagelist_delete((hdrl_imagelist*)cview); + CPL_DIAG_PRAGMA_POP; + + hdrl_imagelist_delete(hlist); + cpl_imagelist_delete(clist); + + return cpl_error_get_code(); +} + +cpl_error_code test_cpl_row_view_invalid(void) +{ + cpl_imagelist * imglist = cpl_imagelist_new(); + cpl_imagelist * errlist = cpl_imagelist_new(); + const hdrl_imagelist * view; + + view = hdrl_imagelist_const_cpl_row_view(NULL, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 0); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + + cpl_image * img = cpl_image_new(5, 5, HDRL_TYPE_DATA); + cpl_imagelist_set(imglist, img, 0); + cpl_image * err = cpl_image_new(6, 5, HDRL_TYPE_ERROR); + cpl_imagelist_set(errlist, err, 0); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_image_delete(cpl_imagelist_unset(imglist, 0)); + cpl_image_delete(cpl_imagelist_unset(errlist, 0)); + + img = cpl_image_new(5, 5, CPL_TYPE_INT); + cpl_imagelist_set(imglist, img, 0); + err = cpl_image_new(5, 5, CPL_TYPE_INT); + cpl_imagelist_set(errlist, err, 0); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_image_delete(cpl_imagelist_unset(imglist, 0)); + cpl_image_delete(cpl_imagelist_unset(errlist, 0)); + + img = cpl_image_new(5, 5, HDRL_TYPE_DATA); + cpl_imagelist_set(imglist, img, 0); + err = cpl_image_new(5, 5, HDRL_TYPE_ERROR); + cpl_imagelist_set(errlist, err, 0); + cpl_image_reject(img, 1, 1); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_image_reject(img, 1, 1); + cpl_image_reject(err, 1, 2); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_image_accept_all(img); + + view = hdrl_imagelist_const_cpl_row_view(imglist, errlist, 1, 2); + cpl_test_null(view); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_imagelist_delete(imglist); + cpl_imagelist_delete(errlist); + + return cpl_error_get_code(); +} + +cpl_error_code test_cpl_row_view(void) +{ + hdrl_imagelist * hlist; + hdrl_imagelist * hlist_noerr; + hdrl_image * himg; + hdrl_image * vhimg; + cpl_image * contrib; + cpl_image * vcontrib; + + cpl_size nimages = 20; + const hdrl_imagelist * cview; + cpl_imagelist * cimglist, * cerrlist; + + /* Create an image list */ + hlist = hdrl_imagelist_new() ; + hlist_noerr = hdrl_imagelist_new() ; + cimglist = cpl_imagelist_new() ; + cerrlist = cpl_imagelist_new() ; + for (cpl_size i = 0 ; i < nimages ; i++) { + + cpl_image *ima = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_DATA); + cpl_image *ima_err = cpl_image_new(XSIZE, YSIZE, HDRL_TYPE_ERROR); + + cpl_image_add_scalar(ima_err, 1.); + cpl_image_reject(ima, 1, 5); + cpl_image_reject(ima_err, 1, 5); + if ((i % 5) == 0) { + cpl_image_reject(ima, 2, 5); + cpl_image_reject(ima_err, 2, 5); + } + himg = hdrl_image_create(ima, ima_err); + hdrl_imagelist_set(hlist, himg, i); + hdrl_imagelist_set(hlist_noerr, hdrl_image_create(ima, NULL), i); + cpl_imagelist_set(cimglist, ima, i); + cpl_imagelist_set(cerrlist, ima_err, i); + } + + cview = hdrl_imagelist_const_cpl_row_view(cimglist, cerrlist, 1, YSIZE); + cpl_test_nonnull(cview); + cpl_test_error(CPL_ERROR_NONE); + hdrl_imagelist_collapse_weighted_mean(hlist, &himg, &contrib); + hdrl_imagelist_collapse_weighted_mean(cview, &vhimg, &vcontrib); + hdrl_test_image_abs(himg, vhimg, 0); + cpl_test_image_abs(contrib, vcontrib, 0); + hdrl_image_delete(himg); + hdrl_image_delete(vhimg); + cpl_image_delete(contrib); + cpl_image_delete(vcontrib); + + hdrl_imagelist_collapse_mean(hlist, &himg, &contrib); + hdrl_imagelist_collapse_mean(cview, &vhimg, &vcontrib); + hdrl_test_image_abs(himg, vhimg, 0); + cpl_test_image_abs(contrib, vcontrib, 0); + hdrl_image_delete(himg); + hdrl_image_delete(vhimg); + cpl_image_delete(contrib); + cpl_image_delete(vcontrib); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + hdrl_imagelist_delete((hdrl_imagelist*)cview); + CPL_DIAG_PRAGMA_POP; + + /* no error test */ + cview = hdrl_imagelist_const_cpl_row_view(cimglist, NULL, 1, YSIZE); + hdrl_imagelist_collapse_mean(hlist_noerr, &himg, &contrib); + hdrl_imagelist_collapse_mean(cview, &vhimg, &vcontrib); + hdrl_test_image_abs(himg, vhimg, 0); + cpl_test_image_abs(contrib, vcontrib, 0); + hdrl_image_delete(himg); + hdrl_image_delete(vhimg); + cpl_image_delete(contrib); + cpl_image_delete(vcontrib); + + hdrl_imagelist_collapse_median(hlist_noerr, &himg, &contrib); + hdrl_imagelist_collapse_median(cview, &vhimg, &vcontrib); + hdrl_test_image_abs(himg, vhimg, 0); + cpl_test_image_abs(contrib, vcontrib, 0); + hdrl_image_delete(himg); + hdrl_image_delete(vhimg); + cpl_image_delete(contrib); + cpl_image_delete(vcontrib); + + hdrl_imagelist_collapse_sigclip(hlist_noerr, 3., 3., 3, &himg, &contrib, + NULL, NULL); + hdrl_imagelist_collapse_sigclip(cview, 3., 3., 3, &vhimg, &vcontrib, + NULL, NULL); + hdrl_test_image_abs(himg, vhimg, 0); + cpl_test_image_abs(contrib, vcontrib, 0); + hdrl_image_delete(himg); + hdrl_image_delete(vhimg); + cpl_image_delete(contrib); + cpl_image_delete(vcontrib); + + hdrl_imagelist_collapse_minmax(hlist_noerr, 3., 3., &himg, &contrib, + NULL, NULL); + hdrl_imagelist_collapse_minmax(cview, 3., 3., &vhimg, &vcontrib, + NULL, NULL); + hdrl_test_image_abs(himg, vhimg, 0); + cpl_test_image_abs(contrib, vcontrib, 0); + hdrl_image_delete(himg); + hdrl_image_delete(vhimg); + cpl_image_delete(contrib); + cpl_image_delete(vcontrib); + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + hdrl_imagelist_delete((hdrl_imagelist*)cview); + CPL_DIAG_PRAGMA_POP; + + hdrl_imagelist_delete(hlist); + hdrl_imagelist_delete(hlist_noerr); + cpl_imagelist_delete(cimglist); + cpl_imagelist_delete(cerrlist); + + return cpl_error_get_code(); +} + + +cpl_error_code test_image_view(void) +{ + hdrl_imagelist * hl = hdrl_imagelist_new(); + hdrl_imagelist * view; + + view = hdrl_imagelist_image_view(hl, 5, 1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(view); + + view = hdrl_imagelist_image_view(hl, 1, 1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(view); + + view = hdrl_imagelist_image_view(hl, 0, 1); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(view); + + hdrl_imagelist_set(hl, hdrl_image_new(5, 7), 0); + + view = hdrl_imagelist_image_view(hl, 1, 2); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(view); + + view = hdrl_imagelist_image_view(hl, -1, 1); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(view); + + view = hdrl_imagelist_image_view(hl, 0, 1); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(view); + + cpl_test_eq(hdrl_imagelist_get_size(view), hdrl_imagelist_get_size(hl)); + + hdrl_imagelist_add_scalar(hl, (hdrl_value){1, 1}); + + hdrl_test_image_abs(hdrl_imagelist_get(view, 0), + hdrl_imagelist_get(hl, 0), 0); + + hdrl_image * n = hdrl_image_new(5, 7); + hdrl_imagelist_set(hl, hdrl_image_new(5, 7), 1); + + hdrl_test_image_abs(hdrl_imagelist_get(view, 0), + hdrl_imagelist_get(hl, 0), 0); + hdrl_test_image_abs(hdrl_imagelist_get(hl, 1), n, 0); + hdrl_imagelist_delete(view); + hdrl_image_delete(n); + + hdrl_imagelist_set(hl, hdrl_image_new(5, 7), 2); + hdrl_imagelist_set(hl, hdrl_image_new(5, 7), 3); + view = hdrl_imagelist_image_view(hl, 1, 2); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(hdrl_imagelist_get_size(view), 1); + cpl_test_eq_ptr(IMG_PTR(hdrl_imagelist_get(view, 0)), + IMG_PTR(hdrl_imagelist_get(hl, 1))); + cpl_test_eq_ptr(ERR_PTR(hdrl_imagelist_get(view, 0)), + ERR_PTR(hdrl_imagelist_get(hl, 1))); + cpl_test_eq_ptr(MSK_PTR(hdrl_imagelist_get(view, 0)), + MSK_PTR(hdrl_imagelist_get(hl, 1))); + hdrl_imagelist_delete(view); + + view = hdrl_imagelist_image_view(hl, 1, 3); + cpl_test_eq(hdrl_imagelist_get_size(view), 2); + cpl_test_eq_ptr(IMG_PTR(hdrl_imagelist_get(view, 0)), + IMG_PTR(hdrl_imagelist_get(hl, 1))); + cpl_test_eq_ptr(ERR_PTR(hdrl_imagelist_get(view, 0)), + ERR_PTR(hdrl_imagelist_get(hl, 1))); + cpl_test_eq_ptr(MSK_PTR(hdrl_imagelist_get(view, 0)), + MSK_PTR(hdrl_imagelist_get(hl, 1))); + cpl_test_eq_ptr(IMG_PTR(hdrl_imagelist_get(view, 1)), + IMG_PTR(hdrl_imagelist_get(hl, 2))); + cpl_test_eq_ptr(ERR_PTR(hdrl_imagelist_get(view, 1)), + ERR_PTR(hdrl_imagelist_get(hl, 2))); + cpl_test_eq_ptr(MSK_PTR(hdrl_imagelist_get(view, 1)), + MSK_PTR(hdrl_imagelist_get(hl, 2))); + + /* test view of view */ + hdrl_imagelist * rview = hdrl_imagelist_row_view(view, 2, 7); + cpl_test_eq(hdrl_imagelist_get_size(rview), hdrl_imagelist_get_size(view)); + hdrl_image * tmp = hdrl_imagelist_get(rview, 0); + cpl_test_eq(hdrl_image_get_size_x(tmp), 5); + cpl_test_eq(hdrl_image_get_size_y(tmp), 6); + hdrl_imagelist_delete(rview); + + hdrl_imagelist_delete(hl); + hdrl_imagelist_delete(view); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image_view + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_row_view(); + test_image_view(); + test_cpl_row_view_invalid(); + test_cpl_row_view(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_image-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_image-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_image-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_image-test.c 2017-09-20 13:52:02.000000000 +0000 @@ -0,0 +1,649 @@ +/* $Id: hdrl_image-test.c,v 1.5 2013-10-23 09:13:56 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-23 09:13:56 $ + * $Revision: 1.5 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_image.h" +#include "hdrl_test.h" +#include "hdrl_imagelist.h" +#include "hdrl_buffer.h" +#include "hdrl_types.h" + +#include + +#include +#include +#include +#include + +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_image_test + Testing of hdrl_image module + */ +/*----------------------------------------------------------------------------*/ + +static void test_basic(void) +{ + hdrl_image * img; + cpl_image * cimg, * cerr; + cpl_error_code error; + + hdrl_image_delete(NULL); + + /* empty creation */ + + img = hdrl_image_new(5, 5); + cpl_test_nonnull(img); + cpl_test_error(CPL_ERROR_NONE); + hdrl_image_delete(img); + + img = hdrl_image_new(0, 5); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + img = hdrl_image_new(5, 0); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + img = hdrl_image_new(0, 0); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + img = hdrl_image_create(NULL, NULL); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* creation with cpl image */ + + cimg = cpl_image_new(5, 6, CPL_TYPE_DOUBLE); + cerr = cpl_image_new(5, 6, CPL_TYPE_DOUBLE); + + img = hdrl_image_create(NULL, cerr); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + img = hdrl_image_create(cimg, NULL); + cpl_test_nonnull(img); + hdrl_image_delete(img); + + img = hdrl_image_create(cimg, cerr); + cpl_test_nonnull(img); + + /* dump the structure */ + error = hdrl_image_dump_structure(img, stderr); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + error = hdrl_image_dump_window(img, 1, 1, 3, 3, stderr); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + hdrl_image_delete(img); + + /* with bpm */ + + cpl_image_reject(cimg, 2, 3); + img = hdrl_image_create(cimg, cerr); + cpl_test_nonnull(img); + cpl_test_eq(hdrl_image_count_rejected(img), 1); + hdrl_image_delete(img); + + cpl_image_reject(cerr, 2, 3); + img = hdrl_image_create(cimg, cerr); + cpl_test_eq(hdrl_image_count_rejected(img), 1); + cpl_test_nonnull(img); + hdrl_image_delete(img); + + /* incompatible bpm (emits warning) */ + cpl_image_reject(cerr, 2, 4); + img = hdrl_image_create(cimg, cerr); + cpl_test_eq(hdrl_image_count_rejected(img), 1); + cpl_test_nonnull(img); + hdrl_image_delete(img); + + cpl_image_accept_all(cimg); + img = hdrl_image_create(cimg, cerr); + cpl_test_eq(hdrl_image_count_rejected(img), 0); + cpl_test_nonnull(img); + hdrl_image_delete(img); + + cpl_image_delete(cerr); + cerr = cpl_image_new(2, 6, CPL_TYPE_DOUBLE); + img = hdrl_image_create(cimg, cerr); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_image_delete(cerr); + cerr = cpl_image_new(5, 2, CPL_TYPE_DOUBLE); + img = hdrl_image_create(cimg, cerr); + cpl_test_null(img); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + /* reject/accept */ + img = hdrl_image_new(5, 5); + hdrl_image_reject(img, 4, 5); + cpl_test(hdrl_image_is_rejected(img, 4, 5)); + hdrl_image_accept(img, 4, 5); + cpl_test(!hdrl_image_is_rejected(img, 4, 5)); + + hdrl_image_reject(img, 5, 6); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + hdrl_image_reject(img, 0, 6); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + hdrl_image_accept(img, 6, 5); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + hdrl_image_accept(img, 0, 5); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + + hdrl_image_reject(img, 4, 5); + hdrl_image_accept_all(img); + cpl_test(!hdrl_image_is_rejected(img, 4, 5)); + hdrl_image_delete(img); + + cpl_image_delete(cimg); + cpl_image_delete(cerr); +} + +static void test_extract(void) +{ + cpl_size nx = 5; + cpl_size ny = 13; + hdrl_image * himg = hdrl_image_new(nx, ny); + hdrl_image * ex; + hdrl_image_add_scalar(himg, (hdrl_value){1., 1.}); + + ex = hdrl_image_extract(himg, 1, 1, nx, ny); + cpl_test_nonnull(ex); + hdrl_test_image_abs(himg, ex, 0); + hdrl_image_delete(ex); + + ex = hdrl_image_extract(himg, 1, 1, 0, 0); + cpl_test_nonnull(ex); + hdrl_test_image_abs(himg, ex, 0); + hdrl_image_delete(ex); + + ex = hdrl_image_extract(himg, 0, 0, 0, 0); + cpl_test_nonnull(ex); + cpl_test_eq(hdrl_image_get_size_x(ex), 1); + cpl_test_eq(hdrl_image_get_size_y(ex), 1); + hdrl_image_delete(ex); + + ex = hdrl_image_extract(himg, 2, 2, -1, -1); + cpl_test_nonnull(ex); + cpl_test_eq(hdrl_image_get_size_x(ex), nx - 2); + cpl_test_eq(hdrl_image_get_size_y(ex), ny - 2); + hdrl_image_delete(ex); + + ex = hdrl_image_extract(himg, 2, 2, -1, 2 * ny); + cpl_test_null(ex); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + ex = hdrl_image_extract(himg, 2, 2, -1, -2 * ny); + cpl_test_null(ex); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + ex = hdrl_image_extract(himg, 2, 2, -2 * nx, -2); + cpl_test_null(ex); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + ex = hdrl_image_extract(himg, 2, -2 * ny, -2, -2); + cpl_test_null(ex); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + ex = hdrl_image_extract(himg, -2 * nx, -2, -2, -2); + cpl_test_null(ex); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_image_delete(himg); +} + +static void test_power(void) +{ + hdrl_value v; + hdrl_image * himg = hdrl_image_new(1, 1); + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5}); + hdrl_image_pow_scalar(himg, (hdrl_value){2., 0.}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 4., DBL_EPSILON); + cpl_test_rel(v.error, 2.0, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5}); + hdrl_image_pow_scalar(himg, (hdrl_value){4., 0.}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 16, DBL_EPSILON); + cpl_test_rel(v.error, 16, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5}); + hdrl_image_pow_scalar(himg, (hdrl_value){-1., 0.}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 0.5, DBL_EPSILON); + cpl_test_rel(v.error, 0.125, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5}); + hdrl_image_pow_scalar(himg, (hdrl_value){-2., 0.}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 0.25, DBL_EPSILON); + cpl_test_rel(v.error, 0.125, DBL_EPSILON); /* yes the same as ^-1 */ + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5}); + hdrl_image_pow_scalar(himg, (hdrl_value){-4., 0.}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 0.0625, DBL_EPSILON); + cpl_test_rel(v.error, 0.0625, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.3}); + hdrl_image_pow_scalar(himg, (hdrl_value){-3., 0.0}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 1.0/8.0, DBL_EPSILON); + cpl_test_rel(v.error, 0.05625, DBL_EPSILON); + + hdrl_image_delete(himg); +} + +static void test_exp(void) +{ + hdrl_value v; + hdrl_image * himg = hdrl_image_new(1, 1); + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.0}); + hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 4., DBL_EPSILON); + cpl_test_rel(v.error, 2.0, DBL_EPSILON); + + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){4., 0.}); + hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 16, DBL_EPSILON); + cpl_test_rel(v.error, 16, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){-1., 0.}); + hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 0.5, DBL_EPSILON); + cpl_test_rel(v.error, 0.125, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){-2., 0.}); + hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 0.25, DBL_EPSILON); + cpl_test_rel(v.error, 0.125, DBL_EPSILON); + + hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){-4., 0.}); + hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5}); + v = hdrl_image_get_pixel(himg, 1, 1, NULL); + cpl_test_rel(v.data, 0.0625, DBL_EPSILON); + cpl_test_rel(v.error, 0.0625, DBL_EPSILON); + + hdrl_image_delete(himg); +} + + +static void test_copy(void) +{ + hdrl_image * dst = hdrl_image_new(50, 50); + hdrl_image * src = hdrl_image_new(30, 30); + hdrl_image * expected = hdrl_image_new(50, 50); + + hdrl_image_copy(dst, src, 10, 10); + hdrl_test_image_abs(dst, expected, 0); + + hdrl_image_reject(expected, 1, 1); + /* bypass hdrl_image functions */ + cpl_image_reject(hdrl_image_get_image(src), 1, 1); + + hdrl_image_copy(dst, src, 10, 10); + hdrl_test_image_abs(dst, expected, 0); + + hdrl_image_delete(dst); + hdrl_image_delete(src); + hdrl_image_delete(expected); +} + +static void test_insert(void) +{ + hdrl_image * dst = hdrl_image_new(50, 50); + hdrl_image * dst2 = hdrl_image_new(50, 50); + cpl_image * im1 = cpl_image_new(50, 50, HDRL_TYPE_DATA); + cpl_image * im2 = cpl_image_new(50, 50, HDRL_TYPE_ERROR); + hdrl_image * him = hdrl_image_create(im1, im2); + cpl_image_reject(im1, 1, 1); + hdrl_image_reject(him, 1, 1); + + hdrl_image_copy(dst2, him, 1, 1); + hdrl_image_insert(dst, im1, im2, 1, 1); + hdrl_test_image_abs(dst, dst2, 0); + + hdrl_image_insert(dst, im1, NULL, 1, 1); + hdrl_test_image_abs(dst, dst2, 0); + + hdrl_image_delete(dst); + hdrl_image_delete(dst2); + hdrl_image_delete(him); + cpl_image_delete(im1); + cpl_image_delete(im2); +} + +static void test_reduce(void) +{ + { + size_t nx = 53, ny = 2310; + hdrl_value m; + hdrl_image * a = hdrl_image_new(nx, ny); + hdrl_image * b = hdrl_image_new(nx, ny); + hdrl_image * c = hdrl_image_new(nx, ny); + hdrl_imagelist * hl = hdrl_imagelist_new(); + hdrl_image_add_scalar(a, (hdrl_value){5., 3.2}); + hdrl_image_add_scalar(b, (hdrl_value){7., 1.2}); + hdrl_image_add_scalar(b, (hdrl_value){-3., .2}); + + m = hdrl_image_get_mean(a); + cpl_test_abs(m.data, 5., HDRL_EPS_DATA); + cpl_test_abs(m.error, 3.2 / sqrt(nx * ny), HDRL_EPS_ERROR * nx * ny); + + m = hdrl_image_get_weighted_mean(a); + cpl_test_abs(m.data, 5., HDRL_EPS_DATA); + cpl_test_abs(m.error, 3.2 / sqrt(nx * ny), HDRL_EPS_ERROR * nx * ny); + + m = hdrl_image_get_sigclip_mean(a, 3., 3., 100); + cpl_test_abs(m.data, 5., HDRL_EPS_DATA); + cpl_test_abs(m.error, 3.2 / sqrt(nx * ny), HDRL_EPS_ERROR * nx * ny); + + hdrl_imagelist_set(hl, a, 0); + hdrl_imagelist_set(hl, b, 1); + hdrl_imagelist_set(hl, c, 2); + hdrl_image * r; + cpl_image * con; + + /* must be equivalent */ + hdrl_imagelist_collapse_mean(hl, &r, &con); + hdrl_image_add_image(a, b); + hdrl_image_add_image(a, c); + hdrl_image_div_scalar(a, (hdrl_value){3., 0.}); + hdrl_test_image_abs(a, r, HDRL_EPS_DATA); + + hdrl_image_delete(r); + cpl_image_delete(con); + hdrl_imagelist_delete(hl); + } + { /* Test sigmaclipped mean */ + hdrl_value m; + /* gauss mean 100 sigma 3.5 and 2 outliers */ + double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 500, 600 }; + + cpl_image * data = cpl_image_wrap(7, 7, CPL_TYPE_DOUBLE, values); + cpl_image * errors = cpl_image_new(7, 7, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(errors, 1); + + cpl_image_set(errors, 7, 7, 100000.); + cpl_image_set(errors, 6, 7, 10000.); + + hdrl_image * sigimage = hdrl_image_create(data, errors); + + m = hdrl_image_get_sigclip_mean(sigimage, 3., 3., 100); + cpl_test_rel(m.data, 100., HDRL_EPS_DATA * 49); + cpl_test_rel(m.error, 1 / sqrt(7 * 7 - 2), HDRL_EPS_ERROR * 49); + cpl_image_unwrap(data); + cpl_image_delete(errors); + hdrl_image_delete(sigimage); + } + { /* Test minmax rejected mean */ + hdrl_value m; + /* gauss mean 100 sigma 3.5 and 2 outliers */ + double values[] = {-100000, 93, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 100000, 500000 }; + + cpl_image * data = cpl_image_wrap(7, 7, CPL_TYPE_DOUBLE, values); + cpl_image * errors = cpl_image_new(7, 7, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(errors, 1); + + cpl_image_set(errors, 7, 7,100000.); + cpl_image_set(errors, 6, 7,10000.); + cpl_image_set(errors, 1, 1,1000.); + + /*cpl_image_save(data,"data.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_CREATE); + cpl_image_save(errors,"errors.fits", CPL_TYPE_FLOAT, NULL, + CPL_IO_CREATE);*/ + + hdrl_image * minmaximage = hdrl_image_create(data, errors); + + m = hdrl_image_get_minmax_mean(minmaximage, 0, 0); + cpl_test_rel(m.data, 10298.122448979591, HDRL_EPS_DATA * 49); + m = hdrl_image_get_minmax_mean(minmaximage, 0, 1); + cpl_test_rel(m.data, 96.0, 0.005); + m = hdrl_image_get_minmax_mean(minmaximage, 0, 2); + cpl_test_rel(m.data, -2029.6170212765958, HDRL_EPS_DATA * 49); + m = hdrl_image_get_minmax_mean(minmaximage, 1, 2); + cpl_test_rel(m.data, 100.17391304347827, HDRL_EPS_DATA * 49); + + hdrl_image_delete(minmaximage); + cpl_image_delete(errors); + cpl_image_unwrap(data); + } + /* test sum, sqsum */ + { + size_t nx = 3, ny = 1; + hdrl_value m; + hdrl_image * a = hdrl_image_new(nx, ny); + hdrl_image_set_pixel(a, 1, 1, (hdrl_value){1 , 0.5}); + hdrl_image_set_pixel(a, 2, 1, (hdrl_value){2., 1.5}); + hdrl_image_set_pixel(a, 3, 1, (hdrl_value){3., 2.5}); + hdrl_image_reject(a, 1, 1); + + m = hdrl_image_get_sum(NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(isnan(m.data) && isnan(m.error)); + + m = hdrl_image_get_sum(a); + cpl_test_error(CPL_ERROR_NONE); + cpl_test(!isnan(m.data) && !isnan(m.error)); + + cpl_test_abs(m.data, 5., HDRL_EPS_DATA); + cpl_test_abs(m.error, sqrt(1.5 * 1.5 + 2.5 * 2.5), HDRL_EPS_ERROR * 3); + + m = hdrl_image_get_sqsum(a); + cpl_test_abs(m.data, 4. + 9., HDRL_EPS_DATA); + cpl_test_abs(m.error, 16.15549442140351, HDRL_EPS_ERROR * 6); + hdrl_image_delete(a); + } +} + +static inline void test_buffer(void) +{ + hdrl_buffer *buf = hdrl_buffer_new(); + hdrl_imagelist *hl = hdrl_imagelist_new(); + +#if (__WORDSIZE == 64) + + cpl_size iMax = 100; /* Previously = 900 */ + cpl_size sizeImg = 64; /* Previously = 500 */ + + for (cpl_size i = 0; i < iMax; i++) { + hdrl_image * img = hdrl_image_new_from_buffer(sizeImg, sizeImg, buf); + hdrl_imagelist_set(hl, img, i); + hdrl_image_add_scalar(img, (hdrl_value){1, 1}); + } + cpl_msg_warning(cpl_func, "alloc done"); + + hdrl_image *m; + cpl_image *c; + hdrl_imagelist_collapse_mean(hl, &m, &c); + hdrl_image_delete(m); + cpl_image_delete(c); + cpl_msg_warning(cpl_func, "collapse done"); + + +#endif + + + hdrl_imagelist_delete(hl); + + hdrl_buffer_delete(buf); +} + +static void test_create(void) +{ + /* Create reference images */ + size_t nx = 10; + size_t ny = 100; + hdrl_image *a = hdrl_image_new(nx, ny); + hdrl_image *b = hdrl_image_new(nx, ny); + + /* Reject value */ + hdrl_image_reject_value(a, CPL_VALUE_NAN); + hdrl_image_reject_value(b, CPL_VALUE_NAN); + + /* Add information */ + hdrl_value hValue = {2., 0.5}; + hdrl_image_add_scalar(a, hValue); + hdrl_image_add_scalar(b, hValue); + + hdrl_image *new1; + hdrl_image *new2; + hdrl_image *new3; + hdrl_image *new4; + hdrl_image *new5; + hdrl_image *new6; + + /* Basic operations */ + + new1 = hdrl_image_add_image_create(NULL, b); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new1); + new1 = hdrl_image_add_image_create(a, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new1); + new1 = hdrl_image_add_image_create(a, b); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(new1); + + new2 = hdrl_image_sub_image_create(NULL, b); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new2); + new2 = hdrl_image_sub_image_create(a, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new2); + new2 = hdrl_image_sub_image_create(a, b); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(new2); + + + new3 = hdrl_image_mul_image_create(NULL, b); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new3); + new3 = hdrl_image_mul_image_create(a, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new3); + new3 = hdrl_image_mul_image_create(a, b); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(new3); + + + new4 = hdrl_image_div_image_create(NULL, b); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new4); + new4 = hdrl_image_div_image_create(a, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new4); + new4 = hdrl_image_div_image_create(a, b); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(new4); + + + /* Pow and Exp operations */ + + new5 = hdrl_image_pow_scalar_create(NULL, hValue); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new5); + new5 = hdrl_image_pow_scalar_create(a, hValue); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(new5); + + new6 = hdrl_image_exp_scalar_create(NULL, hValue); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(new6); + new6 = hdrl_image_exp_scalar_create(a, hValue); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(new6); + + + /* Clean up */ + hdrl_image_delete(a); + hdrl_image_delete(b); + + hdrl_image_delete(new1); + hdrl_image_delete(new2); + hdrl_image_delete(new3); + hdrl_image_delete(new4); + + hdrl_image_delete(new5); + hdrl_image_delete(new6); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_basic(); + test_power(); + test_exp(); + test_copy(); + test_insert(); + test_extract(); + test_reduce(); + + test_create(); + + test_buffer(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_lacosmics-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_lacosmics-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_lacosmics-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_lacosmics-test.c 2017-09-28 14:27:39.000000000 +0000 @@ -0,0 +1,349 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_lacosmics.h" +#include "hdrl_bpm_2d.h" + +#include + +#include + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_lacosmics_test Testing of the HDRL cosmic ray rejection + */ +/*----------------------------------------------------------------------------*/ + +cpl_error_code test_lacosmic_inputs(void) +{ + /* Create parameters */ + hdrl_parameter *pFake = hdrl_bpm_2d_parameter_create_legendresmooth( + 4., 5., 6, 20, 21, 11, 12, 2, 10); + hdrl_parameter *pErr1 = hdrl_lacosmic_parameter_create( 0, 0, 0); + hdrl_parameter *pErr2 = hdrl_lacosmic_parameter_create( 0, -1., 1); + hdrl_parameter *pErr3 = hdrl_lacosmic_parameter_create(-1., 0, 1); + hdrl_parameter *params = hdrl_lacosmic_parameter_create(5, 2., 5); + cpl_test_error(CPL_ERROR_NONE); + + + /* Check parameter */ + cpl_test(!hdrl_lacosmic_parameter_check(pFake )); + cpl_test( hdrl_lacosmic_parameter_check(params)); + + + /* Verify parameter */ + hdrl_lacosmic_parameter_verify(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_lacosmic_parameter_verify(pFake); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_lacosmic_parameter_verify(pErr1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_lacosmic_parameter_verify(pErr2); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_lacosmic_parameter_verify(pErr3); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_lacosmic_parameter_verify(params); + cpl_test_error(CPL_ERROR_NONE); + + + /* Gets */ + + cpl_test_eq(hdrl_lacosmic_parameter_get_sigma_lim(NULL), -1.); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_lacosmic_parameter_get_sigma_lim(params), 5); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_lacosmic_parameter_get_f_lim(NULL), -1.); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_lacosmic_parameter_get_f_lim(params), 2.); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_lacosmic_parameter_get_max_iter(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_lacosmic_parameter_get_max_iter(params), 5); + cpl_test_error(CPL_ERROR_NONE); + + + /* Create ParameterList */ + cpl_parameterlist *pl; + + pl = hdrl_lacosmic_parameter_create_parlist(NULL, "lacosmic", params); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(pl); + + pl = hdrl_lacosmic_parameter_create_parlist("test", NULL, params); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(pl); + + pl = hdrl_lacosmic_parameter_create_parlist("test", "lacosmic", NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(pl); + + cpl_parameterlist *plFake; + plFake = hdrl_lacosmic_parameter_create_parlist("test", "lacosmic", pFake); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(plFake); + + pl = hdrl_lacosmic_parameter_create_parlist("test", "lacosmic", params); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(pl); + + + /* Parse ParameterList */ + hdrl_parameter *check; + + check = hdrl_lacosmic_parameter_parse_parlist(NULL, "test.lacosmic"); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(check); + + check = hdrl_lacosmic_parameter_parse_parlist(pl, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(check); + + check = hdrl_lacosmic_parameter_parse_parlist(pl, "test.lacosmic"); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(check); + + + /* image smaller than 7x7 kernel */ + hdrl_image *img1 = hdrl_image_new(6, 1000); + cpl_mask *res1 = hdrl_lacosmic_edgedetect(img1, params); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(res1); + hdrl_image_delete(img1); + + + /* image larger */ + hdrl_image *img2 = hdrl_image_new(1200, 4); + cpl_mask *res2 = hdrl_lacosmic_edgedetect(img2, params); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(res2); + hdrl_image_delete(img2); + + + /* Clean up */ + cpl_parameterlist_delete(pl); + hdrl_parameter_delete(pFake); + hdrl_parameter_delete(pErr1); + hdrl_parameter_delete(pErr2); + hdrl_parameter_delete(pErr3); + hdrl_parameter_delete(params); + hdrl_parameter_delete(check); + + return cpl_error_get_code(); +} + +cpl_error_code test_lacosmic_edgedetect(void) +{ + cpl_image * img_data = NULL; + cpl_mask * img_mask = NULL; + cpl_image * img_error = NULL; + cpl_mask * result_mask = NULL; + /* detect single pixel cosmics */ + { + img_data = cpl_image_new(200, 300, CPL_TYPE_DOUBLE); + img_mask = cpl_mask_new(200, 300); + cpl_image_fill_noise_uniform(img_data, 90, 110); + double error = (110 - 90) / sqrt(12); + cpl_image_set(img_data, 50, 50, 300.); + cpl_image_set(img_data, 100, 100, 300.); + cpl_image_set(img_data, 150, 150, 300.); + cpl_image_set(img_data, 100, 250, 300.); + + img_error = cpl_image_new(cpl_image_get_size_x(img_data), + cpl_image_get_size_y(img_data), + CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img_error, error); + + cpl_mask_set(img_mask, 120,120, CPL_BINARY_1); + cpl_mask_set(img_mask, 120,121, CPL_BINARY_1); + cpl_mask_set(img_mask, 120,122, CPL_BINARY_1); + cpl_mask_set(img_mask, 121,120, CPL_BINARY_1); + cpl_mask_set(img_mask, 121,121, CPL_BINARY_1); + cpl_mask_set(img_mask, 121,122, CPL_BINARY_1); + cpl_mask_set(img_mask, 122,120, CPL_BINARY_1); + cpl_mask_set(img_mask, 122,121, CPL_BINARY_1); + cpl_mask_set(img_mask, 122,122, CPL_BINARY_1); + /*set one outlier on a bad pixel*/ + cpl_image_set(img_data, 122, 122, 300.); + + cpl_image_reject_from_mask(img_data, img_mask); + hdrl_image * image = hdrl_image_create(img_data, img_error); + hdrl_parameter * params = + hdrl_lacosmic_parameter_create(error * 2, 2.0, 5); + result_mask = hdrl_lacosmic_edgedetect(image, params); + hdrl_parameter_delete(params) ; + + /* + cpl_image_save(data, "test_image.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); + cpl_image_save(data_error, "test_error.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); + cpl_mask_save(data_result, "test_cr.fits", NULL, CPL_IO_CREATE); + */ + + cpl_test_eq(cpl_mask_get(result_mask, 50, 50), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(result_mask, 100, 100), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(result_mask, 150, 150), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(result_mask, 100, 250), CPL_BINARY_1); + cpl_test_eq(cpl_mask_get(result_mask, 122, 122), CPL_BINARY_0); + + cpl_test_eq(cpl_mask_get(result_mask, 110, 260), CPL_BINARY_0); + + /* free the memory */ + cpl_image_delete(img_data); + cpl_mask_delete(img_mask); + cpl_image_delete(img_error); + cpl_mask_delete(result_mask); + hdrl_image_delete(image); + } + + /* detect a very big rectangular cosmic */ + { + img_data = cpl_image_new(150, 200, CPL_TYPE_DOUBLE); + img_mask = cpl_mask_new(150, 200); + cpl_image_fill_noise_uniform(img_data, 90, 110); + double error = (110 - 90) / sqrt(12); + + for (int varx = 50; varx < 75; ++varx) { + for (int vary = 60; vary < 130; ++vary) { + cpl_image_set(img_data, varx, vary, 5000); + } + } + for (int varx = 20; varx < 120; ++varx) { + for (int vary = 20; vary < 40; ++vary) { + cpl_image_set(img_data, varx, vary, 5000); + } + } + img_error = cpl_image_new(cpl_image_get_size_x(img_data), + cpl_image_get_size_y(img_data), + CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img_error, error); + + hdrl_image * image = hdrl_image_create(img_data, img_error); + /* In order to detect the full rectangle, f_lim has to be set to a low + * value - if not, the central part is not detected */ + hdrl_parameter * params = + hdrl_lacosmic_parameter_create(error * 2, 0.5, 65); + result_mask = hdrl_lacosmic_edgedetect(image, params); + hdrl_parameter_delete(params) ; + + /* + cpl_image_save(data, "input_data.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); + cpl_image_save(data_error, "input_error.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); + cpl_mask_save(data_result, "output_mask.fits", NULL, CPL_IO_CREATE); + */ + + cpl_test_eq(cpl_mask_count(result_mask), 100*20+25*70); + /* free the memory */ + cpl_image_delete(img_data); + cpl_mask_delete(img_mask); + cpl_image_delete(img_error); + cpl_mask_delete(result_mask); + hdrl_image_delete(image); + } + /* detect a very big rectangular cosmic with bad pixels */ + { + img_data = cpl_image_new(150, 200, CPL_TYPE_DOUBLE); + img_mask = cpl_mask_new(150, 200); + cpl_image_fill_noise_uniform(img_data, 90, 110); + double error = (110 - 90) / sqrt(12); + + for (int varx = 50; varx < 75; ++varx) { + for (int vary = 60; vary < 130; ++vary) { + cpl_image_set(img_data, varx, vary, 5000); + } + } + for (int varx = 20; varx < 120; ++varx) { + for (int vary = 20; vary < 40; ++vary) { + cpl_image_set(img_data, varx, vary, 5000); + } + } + + /*mark bad pixels*/ + for (int varx = 65; varx < 68; ++varx) { + for (int vary = 1; vary < 150; ++vary) { + cpl_mask_set(img_mask, varx, vary, CPL_BINARY_1); + } + } + img_error = cpl_image_new(cpl_image_get_size_x(img_data), + cpl_image_get_size_y(img_data), + CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img_error, error); + cpl_image_reject_from_mask(img_data, img_mask); + + hdrl_image * image = hdrl_image_create(img_data, img_error); + + /* In order to detect the full rectangle, f_lim has to be set to a low + * value - if not, the central part is not detected */ + hdrl_parameter * params = + hdrl_lacosmic_parameter_create(error * 2, 0.5, 80); + result_mask = hdrl_lacosmic_edgedetect(image, params); + hdrl_parameter_delete(params) ; + /* + cpl_image_save(data, "input_data.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); + cpl_image_save(data_error, "input_error.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); + cpl_mask_save(data_bpm, "input_mask.fits", NULL, CPL_IO_CREATE); + + cpl_mask_save(data_result, "output_mask.fits", NULL, CPL_IO_CREATE); + */ + + cpl_test_eq(cpl_mask_count(result_mask), 100*20 + 25*70 - 3*70 - 3*20); + /* free the memory */ + cpl_image_delete(img_data); + cpl_mask_delete(img_mask); + cpl_image_delete(img_error); + cpl_mask_delete(result_mask); + hdrl_image_delete(image); + } + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of Cosmic module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_lacosmic_inputs(); + + test_lacosmic_edgedetect(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_multiiter-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_multiiter-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_multiiter-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_multiiter-test.c 2017-09-20 10:47:58.000000000 +0000 @@ -0,0 +1,239 @@ +/* $Id: hdrl_multiiter-test.c,v 1.0 2017 Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_multiiter.h" +#include "hdrl_frameiter.h" + +#include + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_buffer_test + Testing of hdrl_buffer module + */ +/*----------------------------------------------------------------------------*/ + +cpl_frameset * create_frames(void){ + + size_t nframes = 5; + size_t next = 4; + cpl_frameset * frames = cpl_frameset_new(); + for (size_t i = 0; i < nframes; i++) { + char * fn = cpl_sprintf("frameiter%zu_%zd.fits", i, (intptr_t)getpid()); + cpl_propertylist * plist = cpl_propertylist_new(); + cpl_propertylist_update_string(plist, "TAG", fn); + cpl_propertylist_save(plist, fn, CPL_IO_CREATE); + cpl_propertylist_delete(plist); + for (size_t j = 1; j < next + 1; j++) { + cpl_image * img = cpl_image_new(50, 70, CPL_TYPE_INT); + cpl_image_add_scalar(img, i * next + j); + cpl_image_save(img, fn, CPL_TYPE_INT, NULL, CPL_IO_EXTEND); + cpl_image_delete(img); + } + cpl_frame * frm = cpl_frame_new(); + cpl_frame_set_filename(frm, fn); + cpl_frame_set_tag(frm, "RAW"); + cpl_frameset_insert(frames, frm); + cpl_free(fn); + } + + return frames; +} + +void test_invalid(cpl_frameset *frames){ + + hdrl_iter *subiters[] = { + hdrl_frameiter_new( + frames, 0, 2, + (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){0, 1}, + (intptr_t[]){1, 2}, + NULL), + hdrl_frameiter_new( + frames, 0, 2, + (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){0, 2}, + (intptr_t[]){1, 2}, + NULL), + }; + cpl_test_error(CPL_ERROR_NONE); + + /* empty and fail tests */ + hdrl_iter *it; + + it = hdrl_multiiter_new(0, subiters, HDRL_ITER_ALLOW_EMPTY); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(it); + + it = hdrl_multiiter_new(2, NULL, HDRL_ITER_ALLOW_EMPTY); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(it); +/* + it = hdrl_multiiter_new(2, subiters, HDRL_ITER_IMAGELIST); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(it); +*/ + it = hdrl_multiiter_new(2, subiters, HDRL_ITER_ALLOW_EMPTY); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(it); + + cpl_size size = hdrl_iter_length(it); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(size, 10); + + + hdrl_iter_delete(it); +} + +void test_basic(cpl_frameset *frames) +{ + hdrl_iter *subiters[] = { + hdrl_frameiter_new( + frames, 0, 2, + (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){0, 1}, + (intptr_t[]){1, 2}, + NULL), + hdrl_frameiter_new( + frames, 0, 2, + (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){0, 2}, + (intptr_t[]){1, 2}, + NULL), + NULL, + }; + cpl_test_error(CPL_ERROR_NONE); + + /* ugly need to know length of other iterators + * TODO add broadcasting do avoid need for dim override */ + subiters[2] = + hdrl_frameiter_new(frames, 0, 2, + (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){0, 1}, + (intptr_t[]){0, 0}, + (intptr_t[]){1, hdrl_iter_length(subiters[0])} + ); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_iter *it = hdrl_multiiter_new(3, subiters, 0); + cpl_test_nonnull(it); + + int cnt = 0; + for (hdrl_frameiter_data ** h = hdrl_iter_next(it); h != NULL; + h = hdrl_iter_next(it)) { + for (size_t i = 0; i < 3; i++) { + int d; + cpl_test_eq(cpl_image_get_size_x(h[i]->image), 50); + if (i < 2) { + cpl_test_eq(cpl_image_get(h[i]->image, 1, 1, &d), cnt + 1); + cnt++; + } + else { + cpl_test_eq(cpl_image_get(h[i]->image, 1, 1, &d), 1); + } + cpl_image_delete(h[i]->image); + cpl_propertylist_delete(h[i]->plist); + } + } + + hdrl_iter_delete(it); +} + + +void test_empty(cpl_frameset *frames) +{ + hdrl_iter *subiters[] = { + hdrl_frameiter_new( + frames, HDRL_ITER_OWNS_DATA, 2, + (intptr_t[]){HDRL_FRAMEITER_AXIS_FRAME, HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){0, 1}, + (intptr_t[]){1, 1}, + NULL), + hdrl_frameiter_new( + frames, HDRL_ITER_OWNS_DATA, 1, + (intptr_t[]){HDRL_FRAMEITER_AXIS_EXT}, + (intptr_t[]){1}, + NULL, + NULL) + }; + cpl_test_error(CPL_ERROR_NONE); + + hdrl_iter *it = hdrl_multiiter_new(2, subiters, HDRL_ITER_ALLOW_EMPTY); + cpl_test_nonnull(it); + + int cnt = 0; + for (hdrl_frameiter_data ** h = hdrl_iter_next(it); h != NULL; + h = hdrl_iter_next(it)) { + int d; + cpl_test_eq(cpl_image_get_size_x(h[0]->image), 50); + cpl_test_eq(cpl_image_get(h[0]->image, 1, 1, &d), cnt + 1); + if (cnt < hdrl_iter_length(subiters[1])) { + cpl_test_eq(cpl_image_get(h[1]->image, 1, 1, &d), cnt + 1); + /* take ownership test */ + cpl_image_delete(h[1]->image); + h[1]->image = NULL; + } + else { + cpl_test_null(h[1]); + } + cnt++; + } + + cpl_test_eq(hdrl_iter_length(subiters[0]), cnt); + + hdrl_iter_delete(it); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_multiiter + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + cpl_frameset *frames = create_frames(); + + test_invalid(frames); + cpl_test_error(CPL_ERROR_NONE); + + test_basic( frames); + cpl_test_error(CPL_ERROR_NONE); + + test_empty( frames); + cpl_test_error(CPL_ERROR_NONE); + + cpl_frameset_delete(frames); + if (system("rm -f frameiter*fits")) {} + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_overscan-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_overscan-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_overscan-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_overscan-test.c 2017-10-13 09:59:32.000000000 +0000 @@ -0,0 +1,1000 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl.h" +#include "hdrl_utils.h" +#include "hdrl_test.h" +#include "hdrl_overscan_defs.h" + +#include "hdrl_collapse.h" //TMP +#include + +#include +#include + +/*----------------------------------------------------------------------------- + Define + -----------------------------------------------------------------------------*/ + +typedef enum { + HDRL_OSCAN_COLLAPSE_TEST_MEAN, + HDRL_OSCAN_COLLAPSE_TEST_MEDIAN, + HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN, + HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP, + HDRL_OSCAN_COLLAPSE_TEST_MINMAX +} hdrl_oscan_collapse_test ; + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_overscan_test Testing of the HDRL Overscan module + */ +/*----------------------------------------------------------------------------*/ + +void test_parlist(void) +{ + /* parameter parsing smoketest */ + hdrl_parameter * hpar; + hdrl_parameter * rect_region_def = + hdrl_rect_region_parameter_create(1, 1, 20, 20); + hdrl_parameter * sigclip_def = + hdrl_collapse_sigclip_parameter_create(3., 3., 5); + hdrl_parameter * minmax_def = + hdrl_collapse_minmax_parameter_create(2., 3.); + cpl_parameterlist * pos = hdrl_overscan_parameter_create_parlist( + "RECIPE", "oscan", "alongX", 10, 10., rect_region_def, + "MINMAX", sigclip_def, minmax_def); + hdrl_parameter_delete(sigclip_def); + hdrl_parameter_delete(minmax_def); + hdrl_parameter_delete(rect_region_def); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_parameterlist_get_size(pos), 13); + + hpar = hdrl_overscan_parameter_parse_parlist(pos, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hpar = hdrl_overscan_parameter_parse_parlist(pos, "RECIPE.oscan"); + cpl_parameterlist_delete(pos); + cpl_test_error(CPL_ERROR_NONE); + { + hdrl_parameter * rect = hdrl_overscan_parameter_get_rect_region(hpar); + cpl_test_eq(hdrl_rect_region_get_llx(rect), 1); + cpl_test_eq(hdrl_rect_region_get_lly(rect), 1); + cpl_test_eq(hdrl_rect_region_get_urx(rect), 20); + cpl_test_eq(hdrl_rect_region_get_ury(rect), 20); + } + cpl_test_eq(hdrl_overscan_parameter_get_box_hsize(hpar), 10); + cpl_test_eq(hdrl_overscan_parameter_get_ccd_ron(hpar), 10.); + cpl_test_eq(hdrl_overscan_parameter_get_correction_direction(hpar), + HDRL_X_AXIS); + { + hdrl_parameter * col = hdrl_overscan_parameter_get_collapse(hpar); + cpl_test(hdrl_collapse_parameter_is_minmax(col)); + cpl_test(!hdrl_collapse_parameter_is_mean(col)); + cpl_test_eq(hdrl_collapse_minmax_parameter_get_nlow(col), 2); + cpl_test_eq(hdrl_collapse_minmax_parameter_get_nhigh(col), 3); + } + + hdrl_parameter_destroy(hpar); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_overscan_compute proper error on null input images + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_null_input(void) +{ + hdrl_parameter * os_region; + hdrl_parameter * os_collapse; + hdrl_parameter * os_param; + hdrl_overscan_compute_result * overscan_computation; + + /* Overscan Parameters */ + os_region = hdrl_rect_region_parameter_create(1, 1, 1, 1) ; + os_collapse = hdrl_collapse_mean_parameter_create() ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, 1., 1, + os_collapse, os_region) ; + cpl_test(hdrl_overscan_parameter_check(os_param)); + + /* test functionality */ + overscan_computation = hdrl_overscan_compute(NULL, os_param) ; + hdrl_parameter_delete(os_region) ; + hdrl_parameter_delete(os_collapse) ; + hdrl_parameter_delete(os_param) ; + + cpl_test_null(overscan_computation); + + hdrl_overscan_compute_result_delete(overscan_computation); + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_overscan_compute proper error on null input region + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_null_region(void) +{ + cpl_image * image_data; + hdrl_parameter * os_region = NULL; + hdrl_parameter * os_collapse; + hdrl_parameter * os_param; + hdrl_overscan_compute_result * overscan_computation; + + /* create input structures (on purpose not the input region) */ + image_data = cpl_image_new(1, 1, CPL_TYPE_DOUBLE); + + /* Overscan Parameters */ + os_collapse = hdrl_collapse_mean_parameter_create() ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, 1., 1, + os_collapse, os_region) ; + + /* test functionality */ + overscan_computation = hdrl_overscan_compute(image_data, os_param); + cpl_image_delete(image_data); + hdrl_parameter_delete(os_collapse) ; + hdrl_parameter_delete(os_param) ; + cpl_test_null(overscan_computation); + + hdrl_overscan_compute_result_delete(overscan_computation); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_overscan_compute proper error on null input sigclip + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_null_sigclip(void) +{ + cpl_image * image_data; + hdrl_parameter * os_region; + hdrl_parameter * os_collapse = NULL; + hdrl_parameter * os_param; + hdrl_overscan_compute_result * overscan_computation; + + /* create input structures (on purpose not the input region) */ + image_data = cpl_image_new(1, 1, CPL_TYPE_DOUBLE); + + /* Overscan Parameters */ + os_region = hdrl_rect_region_parameter_create(1, 1, 1, 1) ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, 1., 1, + os_collapse, os_region) ; + + /* test functionality */ + overscan_computation = hdrl_overscan_compute(image_data, os_param); + cpl_image_delete(image_data); + hdrl_parameter_delete(os_region) ; + hdrl_parameter_delete(os_param) ; + cpl_test_null(overscan_computation); + + hdrl_overscan_compute_result_delete(overscan_computation); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_overscan_compute proper error on null input compute control + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_null_params(void) +{ + cpl_image* image_data = cpl_image_new(1, 1, CPL_TYPE_DOUBLE); + hdrl_overscan_compute_result * overscan_computation; + + /* test functionality */ + overscan_computation = hdrl_overscan_compute(image_data, NULL); + cpl_test_null(overscan_computation); + + hdrl_overscan_compute_result_delete(overscan_computation); + cpl_image_delete(image_data); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_overscan_compute proper error on wrong input region + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_wrong_region(void) +{ + hdrl_parameter * os_region; + hdrl_parameter * os_collapse; + hdrl_parameter * os_param; + cpl_image * image_data; + hdrl_overscan_compute_result * computation; + + /* create input image */ + image_data = cpl_image_new(5, 10, CPL_TYPE_DOUBLE); + + /* Overscan Parameters */ + /* Initialize a region outside the bounds of the image */ + os_region = hdrl_rect_region_parameter_create(1, 1, 5, 10) ; + os_collapse = hdrl_collapse_mean_parameter_create() ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, 1., 1, + os_collapse, os_region) ; + + /* Run it and check */ + hdrl_rect_region_parameter_update(os_region, 0, 2, 4, 2) ; + + computation = hdrl_overscan_compute(image_data, os_param) ; + cpl_test_null(computation); + cpl_test_eq_error(cpl_error_get_code(), CPL_ERROR_ILLEGAL_INPUT); + + /* Initialize a region with size exceeding the X size of the image */ + hdrl_rect_region_parameter_update(os_region, 1, 5, 6, 10) ; + + // TODO yves fix and reenable + //computation = hdrl_overscan_compute(image_data, os_param) ; + //cpl_test_null(computation); + //cpl_test_eq_error(cpl_error_get_code(), CPL_ERROR_ILLEGAL_INPUT); + + /* Destroy and return */ + hdrl_parameter_delete(os_region) ; + hdrl_parameter_delete(os_collapse) ; + hdrl_parameter_delete(os_param) ; + cpl_image_delete(image_data); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_overscan_compute proper error on wrong input region + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static double hdrl_overscan_test_uniform_image(const double inp_value) +{ + double out_value = 0; + cpl_image * image_data; + cpl_image * image_errs; + hdrl_image * image; + hdrl_overscan_compute_result * comp_res; + hdrl_overscan_correct_result * overscan_correction; + hdrl_parameter * os_region; + hdrl_parameter * os_collapse; + hdrl_parameter * os_param; + + /* Create input structures (on purpose not the input region) */ + image_data = cpl_image_new(100, 100, HDRL_TYPE_DATA); + cpl_image_add_scalar(image_data, inp_value); + image_errs = cpl_image_new(100, 100, HDRL_TYPE_ERROR); + cpl_image_add_scalar(image_errs, inp_value); + cpl_image_power(image_errs, 0.5); + image = hdrl_image_wrap(image_data, image_errs, NULL, CPL_FALSE); + + /* Overscan Parameters */ + os_region = hdrl_rect_region_parameter_create(1, 1, 100, 100) ; + os_collapse = hdrl_collapse_median_parameter_create() ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, 1., 5, + os_collapse, os_region) ; + + /* Compute the Overscan correction */ + comp_res = hdrl_overscan_compute(image_data, os_param); + cpl_test_nonnull(comp_res); + + hdrl_parameter_delete(os_region) ; + hdrl_parameter_delete(os_collapse) ; + hdrl_parameter_delete(os_param) ; + + out_value = cpl_image_get_mean( + hdrl_image_get_image(comp_res->correction)); + cpl_test_abs(out_value, inp_value, HDRL_EPS_DATA); + + overscan_correction = hdrl_overscan_correct(image, NULL, comp_res); + cpl_test_nonnull(overscan_correction); + + hdrl_overscan_compute_result_delete(comp_res); + hdrl_overscan_correct_result_delete(overscan_correction); + hdrl_image_delete(image); + return out_value; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check overscan directions and shrinking window + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_dir(cpl_size Nx, cpl_size Ny, int hbox) +{ + const double error = 10; + hdrl_image * image = hdrl_image_new(Nx, Ny); + cpl_image * image_data = hdrl_image_get_image(image); + cpl_image * image_errs = hdrl_image_get_error(image); + hdrl_parameter * os_region = NULL; + hdrl_parameter * os_collapse = NULL; + hdrl_parameter * os_param = NULL; + hdrl_overscan_compute_result * res_os_comp = NULL; + hdrl_overscan_compute_result * res_os_comp_turn = NULL; + hdrl_overscan_correct_result * res_os_cor = NULL; + hdrl_overscan_correct_result * res_os_cor_turn = NULL; + int rej; + + cpl_msg_info(cpl_func, "check mean hbox %d, Nx %ld, Ny %ld", + hbox, (long)Nx, (long)Ny); + + /* create image incrementing in x axis, constant in y axis */ + for (cpl_size x = 0; x < Nx; x++) { + for (cpl_size y = 0; y < Ny; y++) { + cpl_image_set(image_data, x + 1, y + 1, x); + cpl_image_set(image_errs, x + 1, y + 1, x); + } + } + cpl_image_power(image_errs, 0.5); + + /* Overscan Parameters */ + os_region = hdrl_rect_region_parameter_create(1, 1, Nx, Ny) ; + os_collapse = hdrl_collapse_mean_parameter_create() ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, + error * sqrt(Ny * (1 + 2 * hbox)), hbox, os_collapse, os_region) ; + + /* test compute y direction */ + res_os_comp = hdrl_overscan_compute(image_data, os_param); + cpl_test_error(CPL_ERROR_NONE); + + { + /* in y direction overscan has same incremental pattern as input */ + cpl_image * ex = cpl_image_extract(image_data, 1, 1, Nx, 1); + /* cpl mean implementation has a rather large error */ + cpl_test_image_abs(ex, hdrl_image_get_image(res_os_comp->correction), + 2 * (1 + 2 * hbox) * Ny * HDRL_EPS_DATA); + + /* perfect match => zero chi2 = 0*/ + if (hbox == 0) { + cpl_image_subtract(ex, ex); + cpl_test_image_abs(ex, res_os_comp->red_chi2, + 2 * (1 + 2 * hbox) * Ny * HDRL_EPS_DATA); + } + + /* error constant in middle */ + cpl_image_subtract(ex, ex); + cpl_image_add_scalar(ex, error); + /* error larger on boundary */ + for (int i = 0; i < hbox; i++) { + double cor = sqrt((1 + 2. * (hbox)) / (1 + 2 * i)); + cpl_image_set(ex, 1 + i, 1, error * cor); + cpl_image_set(ex, Nx - i, 1, error * cor); + } + cpl_test_image_abs(ex, hdrl_image_get_error(res_os_comp->correction), + Ny * HDRL_EPS_ERROR); + + cpl_image_delete(ex); + } + + /* test compute x direction */ + + hdrl_parameter_delete(os_param) ; + os_param = hdrl_overscan_parameter_create(HDRL_X_AXIS, + error * sqrt(Nx * (1 + 2 * hbox)), hbox, os_collapse, os_region) ; + res_os_comp_turn = hdrl_overscan_compute(image_data, os_param); + + hdrl_parameter_delete(os_region) ; + hdrl_parameter_delete(os_collapse) ; + hdrl_parameter_delete(os_param) ; + + cpl_test_error(CPL_ERROR_NONE); + + { + /* in x direction overscan is the mean of the sum */ + cpl_image * ex = cpl_image_new(1, Ny, HDRL_TYPE_DATA); + cpl_image_add_scalar(ex, (Nx - 1.) / 2.); + cpl_test_image_abs(ex, + hdrl_image_get_image(res_os_comp_turn->correction), + 2 * (1 + 2 * hbox) * Nx * HDRL_EPS_DATA); + + /* reduced chi2 so it should be constant with this pattern */ + cpl_image_subtract(ex, ex); + cpl_image_add_scalar(ex, cpl_image_get(res_os_comp_turn->red_chi2, + 1, 1, &rej)); + cpl_test_image_abs(ex, res_os_comp_turn->red_chi2, + 2 * (1 + 2 * hbox) * Nx * HDRL_EPS_DATA); + + /* error constant in middle */ + cpl_image_subtract(ex, ex); + cpl_image_add_scalar(ex, error); + /* error larger on boundary */ + for (int i = 0; i < hbox; i++) { + double cor = sqrt((1 + 2. * (hbox)) / (1 + 2 * i)); + cpl_image_set(ex, 1, 1 + i, error * cor); + cpl_image_set(ex, 1, Ny - i, error * cor); + } + cpl_test_image_abs(ex, + hdrl_image_get_error(res_os_comp_turn->correction), + 3 * Nx * HDRL_EPS_ERROR); + + cpl_image_delete(ex); + } + + + /* test correct y direction */ + res_os_cor = hdrl_overscan_correct(image, NULL, res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + + { + /* corrected y direction is just a zero image */ + cpl_image * ex = cpl_image_new(Nx, Ny, HDRL_TYPE_DATA); + + cpl_test_image_abs(ex, hdrl_image_get_image(res_os_cor->corrected), + 2 * (1 + 2 * hbox) * Ny * HDRL_EPS_DATA); + + /* gaussian error */ + for (cpl_size y = 0; y < Ny; y++) { + for (cpl_size x = 0; x < Nx; x++) { + double val = cpl_image_get(image_errs, x + 1, y + 1, &rej); + cpl_image_set(ex, x + 1, y + 1, hypot(error, val)); + } + /* larger on boundaries */ + for (int i = 0; i < hbox; i++) { + double cor = sqrt((1 + 2. * (hbox)) / (1 + 2 * i)); + double val = cpl_image_get(image_errs, 1 + i, y + 1, &rej); + cpl_image_set(ex, 1 + i, y + 1, hypot(error * cor, val)); + val = cpl_image_get(image_errs, Nx - i, y + 1, &rej); + cpl_image_set(ex, Nx - i, y + 1, hypot(error * cor, val)); + } + } + + cpl_test_image_abs(ex, hdrl_image_get_error(res_os_cor->corrected), + Ny * HDRL_EPS_ERROR); + + cpl_image_delete(ex); + } + + res_os_cor_turn = hdrl_overscan_correct(image, NULL, res_os_comp_turn); + cpl_test_error(CPL_ERROR_NONE); + + { + /* overscan in x direction constant over whole axis */ + cpl_image * ex = cpl_image_duplicate(image_data); + cpl_image_subtract_scalar(ex, + hdrl_image_get_pixel(res_os_comp_turn->correction, 1, 1, + &rej).data); + cpl_test_image_abs(ex, hdrl_image_get_image(res_os_cor_turn->corrected), + 2 * (1 + 2 * hbox) * Nx * HDRL_EPS_DATA); + + /* gaussian error */ + for (cpl_size x = 0; x < Nx; x++) { + for (cpl_size y = 0; y < Ny; y++) { + double val = cpl_image_get(image_errs, x + 1, y + 1, &rej); + cpl_image_set(ex, x + 1, y + 1, hypot(error, val)); + } + /* larger on boundaries */ + for (int i = 0; i < hbox; i++) { + double cor = sqrt((1 + 2. * (hbox)) / (1 + 2 * i)); + double val = cpl_image_get(image_errs, 1 + x, 1 + i, &rej); + cpl_image_set(ex, x + 1, 1 + i, hypot(error * cor, val)); + val = cpl_image_get(image_errs, x + 1, Ny - i, &rej); + cpl_image_set(ex, x + 1, Ny - i, hypot(error * cor, val)); + } + } + + cpl_test_image_abs(ex, + hdrl_image_get_error(res_os_cor_turn->corrected), + 3 * Nx * HDRL_EPS_ERROR); + + cpl_image_delete(ex); + } + + hdrl_overscan_compute_result_delete(res_os_comp); + hdrl_overscan_compute_result_delete(res_os_comp_turn); + hdrl_overscan_correct_result_delete(res_os_cor); + hdrl_overscan_correct_result_delete(res_os_cor_turn); + hdrl_image_delete(image); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check single pixel overscan + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_full_hbox( + cpl_size Nx, + cpl_size Ny) +{ + const double error = 10; + hdrl_image * image = hdrl_image_new(Nx, Ny); + cpl_image * image_data = hdrl_image_get_image(image); + cpl_image * image_errs = hdrl_image_get_error(image); + hdrl_parameter * os_region = NULL; + hdrl_parameter * os_collapse = NULL; + hdrl_parameter * os_param = NULL; + hdrl_overscan_compute_result * res_os_comp; + hdrl_overscan_correct_result * res_os_cor = NULL; + + /* sets overscan to use full region and emit single pixel value */ + cpl_msg_info(cpl_func, "check mean full box, Nx %ld, Ny %ld", + (long)Nx, (long)Ny); + + /* create image incrementing in x axis, constant in y axis */ + for (cpl_size x = 0; x < Nx; x++) { + for (cpl_size y = 0; y < Ny; y++) { + cpl_image_set(image_data, x + 1, y + 1, x); + cpl_image_set(image_errs, x + 1, y + 1, x); + } + } + cpl_image_power(image_errs, 0.5); + + /* Overscan Parameters */ + os_region = hdrl_rect_region_parameter_create(1, 1, Nx, Ny); + os_collapse = hdrl_collapse_mean_parameter_create(); + + /* invalid boxsize */ + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, + error * sqrt(Nx * Ny), -2, os_collapse, os_region); + + hdrl_overscan_compute(image_data, os_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* test compute y direction */ + hdrl_parameter_delete(os_param); + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, + error * sqrt(Nx * Ny), + HDRL_OVERSCAN_FULL_BOX, + os_collapse, os_region); + res_os_comp = hdrl_overscan_compute(image_data, os_param); + + hdrl_parameter_delete(os_region); + hdrl_parameter_delete(os_collapse); + hdrl_parameter_delete(os_param); + + cpl_test_error(CPL_ERROR_NONE); + + { + /* we expect a row with all the same overscan value */ + hdrl_image * ex = hdrl_image_new(Nx, 1); + + hdrl_image_add_scalar(ex, (hdrl_value){(Nx - 1.) / 2., error}); + + /* cpl mean implementation has a rather large error */ + hdrl_test_image_abs(ex, res_os_comp->correction, + 2 * Nx * Ny * HDRL_EPS_DATA); + hdrl_test_image_abs(ex, res_os_comp->correction, + Nx * Ny * HDRL_EPS_DATA); + + hdrl_image_delete(ex); + } + + hdrl_overscan_compute_result_delete(res_os_comp); + hdrl_overscan_correct_result_delete(res_os_cor); + + hdrl_image_delete(image); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check result of turned image when changing direction + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_turn_eq( + cpl_size Nx, + cpl_size Ny, + int hbox, + hdrl_oscan_collapse_test method) +{ + cpl_ensure_code(method == HDRL_OSCAN_COLLAPSE_TEST_MEAN || + method == HDRL_OSCAN_COLLAPSE_TEST_MEDIAN || + method == HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN || + method == HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP || + method == HDRL_OSCAN_COLLAPSE_TEST_MINMAX, + CPL_ERROR_ILLEGAL_INPUT); + + hdrl_parameter *os_collapse; + if (method == HDRL_OSCAN_COLLAPSE_TEST_MEAN) { + cpl_msg_info(cpl_func, "Mean method hbox %d, Nx %ld, Ny %ld", + hbox, (long)Nx, (long)Ny); + os_collapse = hdrl_collapse_mean_parameter_create(); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_MEDIAN) { + cpl_msg_info(cpl_func, "Median method hbox %d, Nx %ld, Ny %ld", + hbox, (long)Nx, (long)Ny); + os_collapse = hdrl_collapse_median_parameter_create(); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN) { + cpl_msg_info(cpl_func, "Weighted Median method hbox %d, Nx %ld, Ny %ld", + hbox, (long)Nx, (long)Ny); + os_collapse = hdrl_collapse_weighted_mean_parameter_create(); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP) { + cpl_msg_info(cpl_func, "Sigma-Clipping method hbox %d, Nx %ld, Ny %ld", + hbox, (long)Nx, (long)Ny); + os_collapse = hdrl_collapse_sigclip_parameter_create(3., 3., 3) ; + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_MINMAX) { + cpl_msg_info(cpl_func, "MinMax method hbox %d, Nx %ld, Ny %ld", + hbox, (long)Nx, (long)Ny); + os_collapse = hdrl_collapse_minmax_parameter_create(3, 3); + } + + + const double error = 10; + + hdrl_image *image = hdrl_image_new(Nx, Ny); + hdrl_image *image_t; + + cpl_image * image_data = hdrl_image_get_image(image); + cpl_image * image_errs = hdrl_image_get_error(image); + + hdrl_parameter *os_region = NULL; + hdrl_parameter *os_param = NULL; + + hdrl_overscan_compute_result *res_os_comp = NULL; + hdrl_overscan_compute_result *res_os_comp_turn = NULL; + hdrl_overscan_correct_result *res_os_cor = NULL; + hdrl_overscan_correct_result *res_os_cor_turn = NULL; + + for (cpl_size x = 0; x < Nx; x++) { + for (cpl_size y = 0; y < Ny; y++) { + /* small range due to missing cpl_test_img_rel */ + double v = (50 - rand() % 100) / (double)((rand() % 50) + 1); + cpl_image_set(image_data, x + 1, y + 1, v); + cpl_image_set(image_errs, x + 1, y + 1, fabs(v)); + } + } + cpl_image_power(image_errs, 0.5); + image_t = hdrl_image_duplicate(image); + hdrl_image_turn(image_t, +1); + + + + /* Overscan Parameters */ + os_region = hdrl_rect_region_parameter_create(1, 1, Nx, Ny) ; + os_param = hdrl_overscan_parameter_create(HDRL_Y_AXIS, + error * sqrt(Ny * (1 + 2 * hbox)), hbox, os_collapse, os_region) ; + + /* test compute y direction */ + res_os_comp = hdrl_overscan_compute(image_data, os_param); + cpl_test_error(CPL_ERROR_NONE); + + /* test compute x direction */ + hdrl_rect_region_parameter_update(os_region, 1, 1, Ny, Nx) ; + hdrl_parameter_delete(os_param) ; + os_param = hdrl_overscan_parameter_create(HDRL_X_AXIS, + error * sqrt(Ny * (1 + 2 * hbox)), hbox, os_collapse, os_region) ; + res_os_comp_turn = hdrl_overscan_compute(hdrl_image_get_image(image_t), + os_param); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_parameter_delete(os_region) ; + hdrl_parameter_delete(os_collapse) ; + hdrl_parameter_delete(os_param) ; + + { + hdrl_image * cor_t = hdrl_image_duplicate(res_os_comp_turn->correction); + cpl_image * con_t = cpl_image_duplicate(res_os_comp_turn->contribution); + cpl_image * chi_t = cpl_image_duplicate(res_os_comp_turn->red_chi2); + hdrl_image_turn(cor_t, -1); + cpl_image_turn(con_t, -1); + cpl_image_turn(chi_t, -1); + hdrl_test_image_abs(res_os_comp->correction, + cor_t, (1 + hbox) * Ny * HDRL_EPS_DATA); + cpl_test_image_abs(res_os_comp->red_chi2, chi_t, + (1 + hbox) * Ny * HDRL_EPS_DATA); + cpl_test_image_abs(res_os_comp->contribution, con_t, 0); + hdrl_image_delete(cor_t); + cpl_image_delete(con_t); + cpl_image_delete(chi_t); + } + + /* test correct y direction */ + res_os_cor = hdrl_overscan_correct(image, NULL, res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + + res_os_cor_turn = hdrl_overscan_correct(image_t, NULL, res_os_comp_turn); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_image_turn(res_os_cor_turn->corrected, -1); + hdrl_test_image_abs(res_os_cor->corrected, res_os_cor_turn->corrected, + (1 + hbox) * Ny * HDRL_EPS_DATA); + + /* Get corrected */ + hdrl_image *imgCorrected1 = hdrl_overscan_correct_result_get_corrected(res_os_cor); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(imgCorrected1); + hdrl_image *imgCorrected2 = hdrl_overscan_correct_result_unset_corrected(res_os_cor); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(imgCorrected2); + hdrl_image_delete(imgCorrected2); + + /* Get badmask */ + cpl_image *cpImgBadMask_1 = hdrl_overscan_correct_result_get_badmask(res_os_cor); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgBadMask_1); + cpl_image *cpImgBadMask_2 = hdrl_overscan_correct_result_unset_badmask(res_os_cor); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgBadMask_2); + cpl_image_delete(cpImgBadMask_2); + + + hdrl_overscan_compute_result_delete(res_os_comp); + hdrl_overscan_compute_result_delete(res_os_comp_turn); + hdrl_overscan_correct_result_delete(res_os_cor); + hdrl_overscan_correct_result_delete(res_os_cor_turn); + hdrl_image_delete(image); + hdrl_image_delete(image_t); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check case where a overscan box only contains bad pixels + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_overscan_test_empty_box( + hdrl_oscan_collapse_test method) +{ + + cpl_ensure_code(method == HDRL_OSCAN_COLLAPSE_TEST_MEAN || + method == HDRL_OSCAN_COLLAPSE_TEST_MEDIAN || + method == HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN || + method == HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP || + method == HDRL_OSCAN_COLLAPSE_TEST_MINMAX, + CPL_ERROR_ILLEGAL_INPUT); + + /* Overscan Parameters */ + hdrl_parameter *os_collapse = NULL; + if(method == HDRL_OSCAN_COLLAPSE_TEST_MEAN) { + cpl_msg_info(cpl_func, "check empty box MEAN"); + os_collapse = hdrl_collapse_mean_parameter_create(); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_MEDIAN) { + cpl_msg_info(cpl_func, "check empty box MEDIAN"); + os_collapse = hdrl_collapse_median_parameter_create(); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN) { + cpl_msg_info(cpl_func, "check empty box WEIGHTED_MEAN"); + os_collapse = hdrl_collapse_weighted_mean_parameter_create(); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP) { + cpl_msg_info(cpl_func, "check empty box SIGCLIP"); + os_collapse = hdrl_collapse_sigclip_parameter_create(3., 3., 3); + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_MINMAX) { + cpl_msg_info(cpl_func, "check empty box MINMAX"); + os_collapse = hdrl_collapse_minmax_parameter_create(3, 3); + } + + cpl_size Nx = 10; + cpl_size Ny = 10; + cpl_image *image_data = cpl_image_new(Nx, Ny, HDRL_TYPE_DATA); + + hdrl_parameter *os_region = hdrl_rect_region_parameter_create(1, 1, Nx, Ny); + hdrl_parameter *os_param = hdrl_overscan_parameter_create( + HDRL_Y_AXIS, 1., 0, os_collapse, os_region); + + /* reject one row (= one box */ + for (cpl_size i = 0; i < Ny; i++) cpl_image_reject(image_data, 2, i + 1); + + /* test compute y direction */ + hdrl_overscan_compute_result *res_os_comp; + res_os_comp = hdrl_overscan_compute(image_data, os_param); + cpl_test_error(CPL_ERROR_NONE); + + + hdrl_parameter_delete(os_region); + hdrl_parameter_delete(os_collapse); + hdrl_parameter_delete(os_param); + + + int rej; + cpl_test_eq(cpl_image_get(res_os_comp->contribution, 2, 1, &rej), 0); + cpl_test(hdrl_image_is_rejected(res_os_comp->correction, 2, 1)); + cpl_test(cpl_image_is_rejected(res_os_comp->red_chi2, 2, 1)); + + /* Get correction */ + hdrl_image *img1 = hdrl_overscan_compute_result_get_correction(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(img1); + hdrl_image *img2 = hdrl_overscan_compute_result_unset_correction(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(img2); + hdrl_image_delete(img2); + + /* Get contribution */ + cpl_image *cpImg1 = hdrl_overscan_compute_result_get_contribution(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImg1); + cpl_image *cpImg2 = hdrl_overscan_compute_result_unset_contribution(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImg2); + cpl_image_delete(cpImg2); + + /* Get chi2 */ + cpl_image *cpImgCh2_1 = hdrl_overscan_compute_result_get_chi2(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgCh2_1); + cpl_image *cpImgCh2_2 = hdrl_overscan_compute_result_unset_chi2(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgCh2_2); + cpl_image_delete(cpImgCh2_2); + + /* Get red chi2 */ + cpl_image *cpImgRedCh2_1 = hdrl_overscan_compute_result_get_red_chi2(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgRedCh2_1); + cpl_image *cpImgRedCh2_2 = hdrl_overscan_compute_result_unset_red_chi2(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgRedCh2_2); + cpl_image_delete(cpImgRedCh2_2); + + + /* Overscan Parameters - SigClip and MinMax*/ + + if (method == HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP) { + + /* Get overscan SigClip Low */ + cpl_image *cpImgSGLow_1 = hdrl_overscan_compute_result_get_sigclip_reject_low(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgSGLow_1); + cpl_image *cpImgSGLow_2 = hdrl_overscan_compute_result_unset_sigclip_reject_low(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgSGLow_2); + cpl_image_delete(cpImgSGLow_2); + + /* Get overscan SigClip High */ + cpl_image *cpImgSGHigh_1 = hdrl_overscan_compute_result_get_sigclip_reject_high(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgSGHigh_1); + cpl_image *cpImgSGHigh_2 = hdrl_overscan_compute_result_unset_sigclip_reject_high(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgSGHigh_2); + cpl_image_delete(cpImgSGHigh_2); + + } else if (method == HDRL_OSCAN_COLLAPSE_TEST_MINMAX) { + + /* Get overscan MinMax Low */ + cpl_image *cpImgMMLow_1 = hdrl_overscan_compute_result_get_minmax_reject_low(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgMMLow_1); + cpl_image *cpImgMMLow_2 = hdrl_overscan_compute_result_unset_minmax_reject_low(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgMMLow_2); + cpl_image_delete(cpImgMMLow_2); + + /* Get overscan MinMax High */ + cpl_image *cpImgMMHigh_1 = hdrl_overscan_compute_result_get_minmax_reject_high(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgMMHigh_1); + cpl_image *cpImgMMHigh_2 = hdrl_overscan_compute_result_unset_minmax_reject_high(res_os_comp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(cpImgMMHigh_2); + cpl_image_delete(cpImgMMHigh_2); + } + + hdrl_overscan_compute_result_delete(res_os_comp); + + cpl_image_delete(image_data); + + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of overscan functions module + */ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + cpl_error_code code; + double inp_value = 0; + + /* parameter parsing tests */ + test_parlist(); + + /* Overscan with NULL input images */ + code = hdrl_overscan_test_null_input(); + cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); + + /* Overscan with NULL region */ + code = hdrl_overscan_test_null_region(); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* Overscan with NULL sigclip */ + code = hdrl_overscan_test_null_sigclip(); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* Overscan with NULL control */ + code = hdrl_overscan_test_null_params(); + cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); + + /* Overscan with wrong region */ + code = hdrl_overscan_test_wrong_region(); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + /* Check expected results with uniform frame */ + hdrl_overscan_test_uniform_image(inp_value); + + cpl_size anx[] = {97, 45, 200}; + cpl_size any[] = {575, 34, 200}; + + hdrl_overscan_test_turn_eq(0, 0, 0, -1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + for (size_t i = 0; i < sizeof(anx) / sizeof(anx[0]); i++) { + cpl_size nx = anx[i]; + cpl_size ny = any[i]; + + for (int hbox = 0; hbox < 12; hbox++) { + hdrl_overscan_test_dir(nx, ny, hbox); + } + + for (int hbox = 0; hbox < 6; hbox+=2) { + + hdrl_overscan_test_turn_eq(nx, ny, hbox, + HDRL_OSCAN_COLLAPSE_TEST_MEAN); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_turn_eq(nx, ny, hbox, + HDRL_OSCAN_COLLAPSE_TEST_MEDIAN); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_turn_eq(nx, ny, hbox, + HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_turn_eq(nx, ny, hbox, + HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_turn_eq(nx, ny, hbox, + HDRL_OSCAN_COLLAPSE_TEST_MINMAX); + cpl_test_error(CPL_ERROR_NONE); + } + + hdrl_overscan_test_full_hbox(nx, ny); + } + + hdrl_overscan_test_empty_box(-1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_overscan_test_empty_box(HDRL_OSCAN_COLLAPSE_TEST_MEAN); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_empty_box(HDRL_OSCAN_COLLAPSE_TEST_MEDIAN); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_empty_box(HDRL_OSCAN_COLLAPSE_TEST_WEIGHTED_MEAN); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_empty_box(HDRL_OSCAN_COLLAPSE_TEST_SIGCLIP); + cpl_test_error(CPL_ERROR_NONE); + hdrl_overscan_test_empty_box(HDRL_OSCAN_COLLAPSE_TEST_MINMAX); + cpl_test_error(CPL_ERROR_NONE); + + + + /** \todo Test expected results with uniform frame + spikes */ + //cpl_test(hdrl_overscan_test_uniform_image_and_outliers(),value); + + /** \todo Test expected results with uniform frame + noise */ + //cpl_test(hdrl_overscan_test_uniform_image_and_noise(),value); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_parameter-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_parameter-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_parameter-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_parameter-test.c 2017-09-15 08:49:15.000000000 +0000 @@ -0,0 +1,221 @@ +/* $Id: hdrl_parameter-test.c,v 1.1 2013-10-01 13:26:32 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-01 13:26:32 $ + * $Revision: 1.1 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_parameter.h" + +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_parameter-test Testing of the HDRL parameter + */ +/*----------------------------------------------------------------------------*/ + + +/* define sigma clipping parameter object */ +typedef struct { + HDRL_PARAMETER_HEAD; + double kappa_low; + double kappa_high; + int niter; +} hdrl_parameter_sigclip; + +/* define type metadata */ +static hdrl_parameter_typeobj hdrl_parameter_sigclip_type = { + HDRL_PARAMETER_COLLAPSE_SIGCLIP,/* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + NULL, /* fp_destroy */ + sizeof(hdrl_parameter_sigclip), /* obj_size */ +}; + +/* define initializing constructor */ +static hdrl_parameter * hdrl_parameter_sigclip_create(double kappa, int niter) +{ + hdrl_parameter_sigclip * p = (hdrl_parameter_sigclip *) + hdrl_parameter_new(&hdrl_parameter_sigclip_type); + p->kappa_low = kappa; + p->kappa_high = kappa; + p->niter = niter; + return (hdrl_parameter *)p; +} + +static int hdrl_parameter_is_sigclip(hdrl_parameter *self) +{ + return hdrl_parameter_check_type(self, &hdrl_parameter_sigclip_type); +} + +/* public */ +static double hdrl_parameter_sigclip_get_kappa(hdrl_parameter *p) +{ + cpl_test(hdrl_parameter_is_sigclip(p)); + + hdrl_parameter_sigclip * sp = (hdrl_parameter_sigclip *)p; + return sp->kappa_low; +} + + + +typedef struct { + HDRL_PARAMETER_HEAD; + int hbox_size; + hdrl_parameter * collapse; +} hdrl_parameter_overscan; + +static void hdrl_parameter_overscan_destroy(hdrl_parameter *); + +static hdrl_parameter_typeobj hdrl_parameter_overscan_type = { + HDRL_PARAMETER_OVERSCAN, /* type */ + (hdrl_alloc *)&cpl_malloc, /* fp_alloc */ + (hdrl_free *)&cpl_free, /* fp_free */ + (hdrl_free *)&hdrl_parameter_overscan_destroy, /* fp_destroy */ + sizeof(hdrl_parameter_overscan), /* obj_size */ +}; + +static hdrl_parameter * +hdrl_parameter_overscan_create(int hbox_size, hdrl_parameter *collapse) +{ + hdrl_parameter_overscan * p = + (hdrl_parameter_overscan *)hdrl_parameter_new(&hdrl_parameter_overscan_type); + p->hbox_size = hbox_size; + p->collapse = collapse; + return (hdrl_parameter *)p; +} + +static int hdrl_parameter_is_overscan(hdrl_parameter *p) +{ + return hdrl_parameter_check_type(p, &hdrl_parameter_overscan_type); +} + +static void hdrl_parameter_overscan_destroy(hdrl_parameter *p) +{ + cpl_test(hdrl_parameter_is_overscan(p)); + hdrl_parameter_destroy(((hdrl_parameter_overscan*)p)->collapse); + hdrl_parameter_get_type(p)->fp_free(p); +} + +static double hdrl_parameter_overscan_get_hbox_size(hdrl_parameter *p) +{ + cpl_test(hdrl_parameter_is_overscan(p)); + + hdrl_parameter_overscan * sp = (hdrl_parameter_overscan *)p; + return sp->hbox_size; +} + +static hdrl_parameter * hdrl_parameter_overscan_get_collapse(hdrl_parameter *p) +{ + cpl_test(hdrl_parameter_is_overscan(p)); + + hdrl_parameter_overscan * sp = (hdrl_parameter_overscan *)p; + return sp->collapse; +} + +static void test_parameters(hdrl_parameter *p) +{ + hdrl_parameter * collapse = hdrl_parameter_overscan_get_collapse(p); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(collapse); + + cpl_test(hdrl_parameter_is_sigclip(collapse)); + cpl_test(!hdrl_parameter_is_overscan(collapse)); + + cpl_test(!hdrl_parameter_is_sigclip(p)); + cpl_test(hdrl_parameter_is_overscan(p)); + + cpl_test_eq(0, hdrl_parameter_overscan_get_hbox_size(p)); + + cpl_test_eq(2, hdrl_parameter_sigclip_get_kappa(collapse)); + cpl_test_eq(2, ((hdrl_parameter_sigclip*)collapse)->kappa_low); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of parameter module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + /* Test null */ + hdrl_parameter_delete(NULL); + hdrl_parameter_destroy(NULL); + cpl_test_error(CPL_ERROR_NONE); + + /* Test sigclip_create */ + hdrl_parameter *collapse = hdrl_parameter_sigclip_create(2, 3); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(collapse); + + /* Test get kappa */ + double kappa = hdrl_parameter_sigclip_get_kappa(collapse); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(kappa, 2); + + /* Test create overscan */ + hdrl_parameter *osp = hdrl_parameter_overscan_create(0, collapse); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(osp); + + /* More tests over the parameters */ + test_parameters(osp); + cpl_test_error(CPL_ERROR_NONE); + + /* Test get size */ + double size = hdrl_parameter_overscan_get_hbox_size(osp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(size, 0); + + /* Test get collapse */ + hdrl_parameter *test = hdrl_parameter_overscan_get_collapse(osp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(test); + + /* Test destroy existing parameter */ + hdrl_parameter_destroy(osp); + cpl_test_error(CPL_ERROR_NONE); + + /* Test delete parameter */ + collapse = hdrl_parameter_sigclip_create(2, 3); + osp = hdrl_parameter_overscan_create(0, collapse); + hdrl_parameter_delete(osp); + hdrl_parameter_delete(collapse); + cpl_test_error(CPL_ERROR_NONE); + + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_prototyping-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_prototyping-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_prototyping-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_prototyping-test.c 2017-09-18 14:35:28.000000000 +0000 @@ -0,0 +1,620 @@ +/* $Id: hdrl_prototyping-test.c,v 1.0 2017-09-18 Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_prototyping.h" + +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_prototyping-test Testing of the HDRL prototyping + */ +/*----------------------------------------------------------------------------*/ + +void test_prototyping_spatial_freq(void) +{ + int dim_X = 64; + int dim_Y = 64; + cpl_image *image = cpl_image_new(dim_X, dim_Y, CPL_TYPE_DOUBLE); + + + double gausfilt = 1.0; + int mirrorx = 10; + int mirrory = 10; + + + /* Function to calculate the low spatial frequency */ + cpl_image *out1 = hdrl_get_spatial_freq(image, gausfilt, mirrorx, mirrory); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(out1); + cpl_image_delete(image); + + image = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_image *out2 = hdrl_get_spatial_freq(image, gausfilt, 0, 0); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(image); + cpl_image_delete(out2); +} + + +void test_mime_image_polynomial_bkg(void) +{ + int dim_X = 10; + int dim_Y = 10; + cpl_image *image = NULL; + cpl_matrix *coeffs = NULL; + cpl_image *out = hdrl_mime_image_polynomial_bkg(image, dim_X, dim_Y, &coeffs); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + image = cpl_image_new(dim_X, dim_Y, CPL_TYPE_DOUBLE); + out = hdrl_mime_image_polynomial_bkg(image, dim_X, dim_Y, &coeffs); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_test_nonnull(coeffs); + + cpl_image_delete(image); + cpl_image_delete(out); + cpl_matrix_delete(coeffs); +} + +void test_mime_compute_polynomial_bkg(void){ + + cpl_imagelist *images = NULL; + cpl_imagelist *bkg_images = NULL; + int dim_X = 10; + int dim_Y = 10; + cpl_matrix *coeffs = NULL; + + + /* Test input wrong */ + + hdrl_mime_compute_polynomial_bkg(NULL, bkg_images, dim_X, dim_Y, &coeffs); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hdrl_mime_compute_polynomial_bkg(images, bkg_images, dim_X, dim_Y, &coeffs); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + /* Normal execution */ + cpl_image *image = cpl_image_new(dim_X, dim_Y, CPL_TYPE_DOUBLE); + images = cpl_imagelist_new(); + cpl_imagelist_set(images, cpl_image_duplicate(image), 0); + cpl_imagelist_set(images, cpl_image_duplicate(image), 1); + /* hdrl_mime_compute_polynomial_bkg(images, bkg_images, dim_X, dim_Y, &coeffs); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_matrix_delete(coeffs); +*/ + bkg_images = cpl_imagelist_new(); + cpl_imagelist_set(bkg_images, cpl_image_duplicate(image), 0); + cpl_imagelist_set(bkg_images, cpl_image_duplicate(image), 1); +/* hdrl_mime_compute_polynomial_bkg(images, bkg_images, dim_X, dim_Y, &coeffs); + cpl_test_error(CPL_ERROR_TYPE_MISMATCH); + cpl_matrix_delete(coeffs); +*/ + /* Clean up */ + cpl_image_delete(image); + cpl_imagelist_delete(images); + cpl_imagelist_delete(bkg_images); +} + +void test_mime_legendre_polynomials_create(void){ + + int npoly = 0; + double a = 2; + double b = 2; + cpl_matrix *x = NULL; + cpl_matrix *legendre; + + + /* Test null inputs */ + + legendre = hdrl_mime_legendre_polynomials_create(npoly, a, b, x); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(legendre); + + x = cpl_matrix_new(a, b); + legendre = hdrl_mime_legendre_polynomials_create(npoly, a, b, x); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(legendre); + cpl_matrix_delete(x); + + + /* Normal execution */ + npoly = 2; + a = 3; + b = 5; + x = cpl_matrix_new(a, b); + legendre = hdrl_mime_legendre_polynomials_create(npoly, a, b, x); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(legendre); + cpl_matrix_delete(legendre); + cpl_matrix_delete(x); + +} + + +void test_mime_legendre_tensors_create(void) +{ + int nx = 2; + int ny = 2; + int npx = 1; + int npy = 1; + + cpl_matrix *out; + + /* Test wrong input */ + + out = hdrl_mime_legendre_tensors_create(0, ny, npx, npy); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_legendre_tensors_create(nx, 0, npx, npy); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_legendre_tensors_create(nx, ny, 0, npy); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_legendre_tensors_create(nx, ny, npx, 0 ); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + + /* Normal work */ + out = hdrl_mime_legendre_tensors_create(nx, ny, npx, npy); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); +} + +void test_mime_matrix_linspace_create(void) +{ + int n = 1; + double a = 2; + double b = 4; + + /* Test wrong input */ + cpl_matrix *out = hdrl_mime_matrix_linspace_create(n, a, b); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + /* Normal work */ + n = 2; + out = hdrl_mime_matrix_linspace_create(n, a, b); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); +} + +void test_mime_matrix_copy_column(void) +{ + int j_1 = 1; + int j_2 = 1; + int nx = 2; + int ny = 4; + cpl_matrix *mat1 = cpl_matrix_new(nx, ny); + cpl_matrix *mat2 = cpl_matrix_new(nx, ny); + + cpl_matrix *mat = cpl_matrix_new(ny, nx); + + + /* Test wrong input */ + + hdrl_mime_matrix_copy_column(NULL, j_1, mat2, j_2); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_copy_column(mat1, j_1, NULL, j_2); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_copy_column(mat1, j_1, mat, j_2); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_mime_matrix_copy_column(mat1, -1, mat2, j_2); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_mime_matrix_copy_column(mat1, 10, mat2, j_2); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_mime_matrix_copy_column(mat1, -1, mat2, j_2); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_mime_matrix_copy_column(mat1, j_1, mat2, -1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_mime_matrix_copy_column(mat1, j_1, mat2, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + + /* Normal work */ + hdrl_mime_matrix_copy_column(mat1, j_1, mat2, j_2); + cpl_test_error(CPL_ERROR_NONE); + + + cpl_matrix_delete(mat ); + cpl_matrix_delete(mat1); + cpl_matrix_delete(mat2); +} + + +void test_mime_linalg_pairwise_column_tensor_products_create(void) +{ + int nx = 4; + int ny = 4; + + cpl_matrix *mat1 = NULL; + cpl_matrix *mat2 = NULL; + + cpl_matrix *out; + + /* Test wrong inputs */ + out = hdrl_mime_linalg_pairwise_column_tensor_products_create(mat1, mat2); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + mat1 = cpl_matrix_new(nx, ny); + out = hdrl_mime_linalg_pairwise_column_tensor_products_create(mat1, mat2); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + /* Normal work */ + + mat2 = cpl_matrix_new(nx, ny); + out = hdrl_mime_linalg_pairwise_column_tensor_products_create(mat1, mat2); + cpl_test_nonnull(out); + cpl_matrix_delete(out); + + /* Clean up */ + cpl_matrix_delete(mat1); + cpl_matrix_delete(mat2); +} + +void test_mime_linalg_tensor_products_columns_create(void) +{ + int nx = 2; + int ny = 4; + cpl_matrix *mat1 = cpl_matrix_new(nx, ny); + cpl_matrix *mat2 = cpl_matrix_new(nx, ny); + + cpl_matrix *mat = cpl_matrix_new(ny, nx); + + + cpl_matrix *out; + + + /* Test wrong input */ + + out = hdrl_mime_linalg_tensor_products_columns_create(NULL, mat2); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_linalg_tensor_products_columns_create(mat1, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_linalg_tensor_products_columns_create(mat1, mat); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(out); + + + /* Normal work */ + out = hdrl_mime_linalg_tensor_products_columns_create(mat1, mat2); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); + + + /* Clean up */ + cpl_matrix_delete(mat ); + cpl_matrix_delete(mat1); + cpl_matrix_delete(mat2); +} + +void test_mime_tensor_weights_create(void) +{ + int nx = 2; + int ny = 2; + + cpl_matrix *out; + + + /* Test wrong input */ + + out = hdrl_mime_tensor_weights_create(1, ny); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_tensor_weights_create(nx, 1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + + /* Normal work */ + out = hdrl_mime_tensor_weights_create(nx, ny); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); +} + +void test_mime_matrix_mask_rows(void){ + + int nx = 2; + int ny = 8; + cpl_matrix *mat = cpl_matrix_new(nx, ny); + cpl_mask *mask = cpl_mask_new( nx, ny); + cpl_mask *mask1 = cpl_mask_new( ny, nx); + + + /* Test wrong input */ + + hdrl_mime_matrix_mask_rows(NULL, mask); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_mask_rows(mat, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_mask_rows(mat, mask1); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + + /* Normal work */ + hdrl_mime_matrix_mask_rows(mat, mask); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + + /* Clean up */ + cpl_matrix_delete(mat); + cpl_mask_delete(mask); + cpl_mask_delete(mask1); +} + +void test_mime_matrix_rescale_rows(void){ + + cpl_matrix *mat = cpl_matrix_new(2, 1); + cpl_matrix *d = cpl_matrix_new(2, 1); + cpl_matrix *dmat = cpl_matrix_new(2, 1); + cpl_matrix *d1 = cpl_matrix_new(2, 2); + cpl_matrix *dmat1 = cpl_matrix_new(1, 2); + + + /* Test wrong input */ + + hdrl_mime_matrix_rescale_rows(NULL, d, dmat); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_rescale_rows(mat, NULL, dmat); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_rescale_rows(mat, d, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_rescale_rows(mat, d1, dmat); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_mime_matrix_rescale_rows(mat, d, dmat1); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + + /* Normal work */ + hdrl_mime_matrix_rescale_rows(mat, d, dmat); + cpl_test_error(CPL_ERROR_NONE); + + cpl_matrix_delete(mat); + cpl_matrix_delete(d); + cpl_matrix_delete(d1); + cpl_matrix_delete(dmat); + cpl_matrix_delete(dmat1); +} + +void test_mime_linalg_solve_tikhonov(void) +{ + cpl_matrix *mat = cpl_matrix_new(1,2); + cpl_matrix *rhs = cpl_matrix_new(1,2); + cpl_matrix *rhs1 = cpl_matrix_new(2,2); + double alpha = 2.; + + cpl_matrix *out; + + /* Test wrong input */ + + out = hdrl_mime_linalg_solve_tikhonov(NULL, rhs, alpha); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_linalg_solve_tikhonov(mat, NULL, alpha); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_linalg_solve_tikhonov(mat, rhs1, alpha); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(out); + + + /* Normal work */ + out = hdrl_mime_linalg_solve_tikhonov(mat, rhs, alpha); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); + + + /* Clean up */ + cpl_matrix_delete(mat); + cpl_matrix_delete(rhs); + cpl_matrix_delete(rhs1); +} + +void test_mime_linalg_normal_equations_create(void) +{ + cpl_matrix *mat = cpl_matrix_new(1,2); + double alpha = 2.; + + cpl_matrix *out; + + /* Test wrong input */ + + out = hdrl_mime_linalg_normal_equations_create(NULL, alpha); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_linalg_normal_equations_create(mat, -1.); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(out); + + + /* Normal work */ + out = hdrl_mime_linalg_normal_equations_create(mat, alpha); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); + + + /* Clean up */ + cpl_matrix_delete(mat); +} + +void test_mime_matrix_product_left_transpose_create(void) +{ + int nx = 2; + int ny = 4; + cpl_matrix *mat1 = cpl_matrix_new(nx, ny); + cpl_matrix *mat2 = cpl_matrix_new(nx, ny); + + cpl_matrix *mat = cpl_matrix_new(ny, nx); + + + cpl_matrix *out; + + + /* Test wrong input */ + + out = hdrl_mime_matrix_product_left_transpose_create(NULL, mat2); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_matrix_product_left_transpose_create(mat1, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out); + + out = hdrl_mime_matrix_product_left_transpose_create(mat1, mat); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(out); + + + /* Normal work */ + out = hdrl_mime_matrix_product_left_transpose_create(mat1, mat2); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out); + cpl_matrix_delete(out); + + + /* Clean up */ + cpl_matrix_delete(mat ); + cpl_matrix_delete(mat1); + cpl_matrix_delete(mat2); +} + +void test_mime_matrix_product(void) +{ + cpl_matrix *mat1 = cpl_matrix_new(2, 3); + cpl_matrix *mat2 = cpl_matrix_new(3, 2); + cpl_matrix *mat = cpl_matrix_new(2, 3); + + cpl_matrix *product = cpl_matrix_new(2, 2); + cpl_matrix *product_1 = cpl_matrix_new(3, 2); + cpl_matrix *product_2 = cpl_matrix_new(3, 2); + + + /* Test wrong input */ + + hdrl_mime_matrix_product(NULL, mat2, product); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_product(mat1, NULL, product); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_product(mat1, mat2, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_mime_matrix_product(mat1, mat, product); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_mime_matrix_product(mat1, mat2, product_1); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + hdrl_mime_matrix_product(mat1, mat2, product_2); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + /* Normal work */ + hdrl_mime_matrix_product(mat1, mat2, product); + cpl_test_error(CPL_ERROR_NONE); + + + /* Clean up */ + cpl_matrix_delete(mat1); + cpl_matrix_delete(mat2); + cpl_matrix_delete(mat); + cpl_matrix_delete(product); + cpl_matrix_delete(product_1); + cpl_matrix_delete(product_2); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of parameter module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_prototyping_spatial_freq(); + + test_mime_image_polynomial_bkg(); + test_mime_compute_polynomial_bkg(); + + test_mime_legendre_polynomials_create(); + test_mime_legendre_tensors_create(); + test_mime_matrix_linspace_create(); + test_mime_matrix_copy_column(); + test_mime_linalg_pairwise_column_tensor_products_create(); + test_mime_linalg_tensor_products_columns_create(); + test_mime_tensor_weights_create(); + + test_mime_matrix_mask_rows(); + test_mime_matrix_rescale_rows(); + + test_mime_linalg_solve_tikhonov(); + test_mime_linalg_normal_equations_create(); + + test_mime_matrix_product_left_transpose_create(); + test_mime_matrix_product(); + + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_random-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_random-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_random-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_random-test.c 2016-06-30 14:14:34.000000000 +0000 @@ -0,0 +1,106 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2016 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 + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_random.h" + +#include +#include +#include + + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_random_test + Testing of hdrl_random module + */ +/*----------------------------------------------------------------------------*/ + +cpl_error_code test_basic(void) +{ + hdrl_random_state * state = hdrl_random_state_new(1, NULL); + const size_t N = 10000; + + for (size_t i = 0; i < N; i++) { + int64_t r = hdrl_random_uniform_int64(state, 0, 100); + cpl_test_lt(r, 101); + r = hdrl_random_uniform_int64(state, 1000, 2000); + cpl_test_lt(r, 2001); + cpl_test_lt(999, r); + + r = hdrl_random_uniform_int64(state, -(1ll<<55ll), 1ll<<55ll); + cpl_test_lt(r, (1ll<<55ll) + 1); + cpl_test_lt(-(1ll<<55ll) + 1ll, r); + + r = hdrl_random_uniform_int64(state, -(1ll<<55ll), 0); + cpl_test_lt(r, 1); + cpl_test_lt(-(1ll<<55ll) + 1ll, r); + + double rd = hdrl_random_uniform_double(state, -5., 2.); + cpl_test_lt(rd, nextafter(2., 1)); + cpl_test_lt(nextafter(-5., -1), rd); + } + + int buf[N]; + double bufd[N]; + for (size_t i = 0; i < N; i++) { + buf[i] = (int)hdrl_random_poisson(state, 300.); + bufd[i] = hdrl_random_normal(state, 3.5, 1.5); + } + cpl_image * iimg = cpl_image_wrap_int(N, 1, buf); + cpl_image * dimg = cpl_image_wrap_double(N, 1, bufd); + cpl_test_abs(cpl_image_get_mean(iimg), 300, 1); + cpl_test_abs(cpl_image_get_stdev(iimg), sqrt(300), 0.5); + cpl_test_abs(cpl_image_get_mean(dimg), 3.5, 0.1); + cpl_test_abs(cpl_image_get_stdev(dimg), 1.5, 0.1); + + cpl_image_unwrap(iimg); + cpl_image_unwrap(dimg); + hdrl_random_state_delete(state); + + uint64_t seed[2] = {1342, 232}; + state = hdrl_random_state_new(1, seed); + hdrl_random_state_delete(state); + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_basic(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_response-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_response-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_response-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_response-test.c 2018-01-22 10:21:47.000000000 +0000 @@ -0,0 +1,543 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl.h" + +#include +#include + +const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + +hdrl_spectrum1D * create_spectrum(double * wavs, + double * flux, double * flux_e, const cpl_size sz){ + cpl_image * flx = cpl_image_wrap_double(sz, 1, flux); + cpl_image * flx_e = cpl_image_wrap_double(sz, 1, flux_e); + cpl_array * wav = cpl_array_wrap_double(wavs, sz); + + hdrl_spectrum1D * s = hdrl_spectrum1D_create(flx, flx_e, wav, scale); + + cpl_image_unwrap(flx); + cpl_image_unwrap(flx_e); + cpl_array_unwrap(wav); + + return s; +} + +cpl_bivector * create_windows(const double * w1, const double * w2, + const cpl_size sz){ + + cpl_bivector * ret = cpl_bivector_new(sz); + cpl_vector * v1 = cpl_bivector_get_x(ret); + cpl_vector * v2 = cpl_bivector_get_y(ret); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_vector_set(v1, i, w1[i]); + cpl_vector_set(v2, i, w2[i]); + } + + return ret; +} + +cpl_array * create_array(const double * els, const cpl_size sz){ + cpl_array * to_ret = cpl_array_new(sz, HDRL_TYPE_DATA); + for(cpl_size i = 0; i < sz; ++i){ + cpl_array_set(to_ret, i, els[i]); + } + return to_ret; +} + +static cpl_error_code get_error_and_reset(void){ + cpl_error_code r = cpl_error_get_code(); + cpl_error_reset(); + return r; +} + +#define cpl_ensure_no_error cpl_test_eq(get_error_and_reset(), CPL_ERROR_NONE); + +#define cpl_ensure_error cpl_test_noneq(get_error_and_reset(), CPL_ERROR_NONE); + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_response_test + */ +/*----------------------------------------------------------------------------*/ +void test_response_basic(void) +{ + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + hdrl_spectrum1D * s = create_spectrum(wlen, flx, flx_e, 5); + + hdrl_response_result * r = + hdrl_response_compute(NULL, NULL, NULL, NULL, NULL, NULL, NULL); + cpl_ensure_error; + cpl_test_null(r); + + r = hdrl_response_compute(s, NULL, NULL, NULL, NULL, NULL, NULL); + cpl_ensure_error; + cpl_test_null(r); + + r = hdrl_response_compute(s, s, s, NULL, NULL, NULL, NULL); + cpl_ensure_error; + cpl_test_null(r); + + hdrl_parameter * calc_par = + hdrl_response_parameter_create((hdrl_value){1,.2}, + (hdrl_value){2,.3}, + (hdrl_value){5,.2}, + (hdrl_value){7,.1}); + + double aPoints[5] = {3.1, 3.2, 3.3, 6.9, 7.0}; + cpl_array * fit_points = create_array(aPoints, 5); + + hdrl_parameter * fit_par = + hdrl_response_fit_parameter_create(11, fit_points, 1.0, NULL); + + r = hdrl_response_compute(s, s, s, NULL, NULL, NULL, NULL); + cpl_ensure_error; + cpl_test_null(r); + hdrl_response_result_delete(r); + + r = hdrl_response_compute(s, s, s, NULL, NULL, calc_par, NULL); + cpl_ensure_error; + cpl_test_null(r); + hdrl_response_result_delete(r); + + r = hdrl_response_compute(s, s, s, NULL, NULL, NULL, fit_par); + cpl_ensure_error; + cpl_test_null(r); + hdrl_response_result_delete(r); + + r = hdrl_response_compute(s, s, s, NULL, NULL, fit_par, calc_par); + cpl_ensure_error; + cpl_test_null(r); + hdrl_response_result_delete(r); + + r = hdrl_response_compute(s, s, s, NULL, NULL, calc_par, fit_par); + cpl_ensure_no_error; + cpl_test_nonnull(r); + + const hdrl_spectrum1D * raw_resp = hdrl_response_result_get_raw_response(r); + + int rej = 0; + hdrl_value val = hdrl_spectrum1D_get_flux_value(raw_resp, 1, &rej); + + cpl_test_eq(rej, 0); + cpl_test_eq(val.data, 5); + cpl_test_eq(val.error, 4); + + const hdrl_spectrum1D * sel_resp = hdrl_response_result_get_selected_response(r); + + rej = 0; + val = hdrl_spectrum1D_get_flux_value(sel_resp, 1, &rej); + + cpl_test_eq(rej, 0); + cpl_test_eq(val.data, 2); + cpl_test_eq(val.error, 1); + + const hdrl_spectrum1D * resp = hdrl_response_result_get_final_response(r); + + rej = 0; + val = hdrl_spectrum1D_get_flux_value(resp, 1, &rej); + + cpl_test_eq(rej, 0); + cpl_test_eq(val.data, 2); + cpl_test_eq(val.error, 1); + + + hdrl_response_result_delete(r); + + hdrl_parameter_delete(fit_par); + hdrl_parameter_delete(calc_par); + cpl_array_delete(fit_points); + hdrl_spectrum1D_delete(&s); +} + + +void test_truncation(void){ + + hdrl_spectrum1D * obs_s = NULL; + hdrl_spectrum1D * ref_s = NULL; + hdrl_spectrum1D * E_x = NULL; + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + obs_s = create_spectrum(wlen, flx, flx_e, 5); + } + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3.5,5,7,9,11}; + ref_s = create_spectrum(wlen, flx, flx_e, 5); + } + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,10.5}; + E_x = create_spectrum(wlen, flx, flx_e, 5); + } + + hdrl_parameter * calc_par = + hdrl_response_parameter_create((hdrl_value){1,.2}, + (hdrl_value){2,.3}, + (hdrl_value){5,.2}, + (hdrl_value){7,.1}); + + cpl_array * fit_points = create_array((double[]){3.1, 6.8, 6.9, 7.0, 7.5, 9.0, 11.0}, 7); + cpl_bivector * high_abs_regions = NULL; + + hdrl_parameter * fit_par = + hdrl_response_fit_parameter_create(11, fit_points, 1.0, high_abs_regions); + + hdrl_response_result * r = hdrl_response_compute(obs_s, + ref_s, E_x, NULL, NULL, calc_par, fit_par); + cpl_ensure_no_error; + cpl_test_nonnull(r); + + const hdrl_spectrum1D * sel_resp = + hdrl_response_result_get_selected_response(r); + const hdrl_spectrum1D * final_resp = hdrl_response_result_get_final_response(r); + + const cpl_array * wlens_dest = hdrl_spectrum1D_get_wavelength(final_resp).wavelength; + + const double wmin = cpl_array_get_min(wlens_dest); + const double wmax = cpl_array_get_max(wlens_dest); + + cpl_test_rel(wmin, 5, 1e-10); + cpl_test_rel(wmax, 9, 1e-10); + + cpl_test_eq(hdrl_spectrum1D_get_size(sel_resp), 5); + + const cpl_array * wlens_sel = hdrl_spectrum1D_get_wavelength(sel_resp).wavelength; + cpl_test_rel(cpl_array_get(wlens_sel, 0, NULL), 6.8, 1e-10); + cpl_test_rel(cpl_array_get(wlens_sel, 1, NULL), 6.9, 1e-10); + cpl_test_rel(cpl_array_get(wlens_sel, 2, NULL), 7.0, 1e-10); + cpl_test_rel(cpl_array_get(wlens_sel, 3, NULL), 7.5, 1e-10); + cpl_test_rel(cpl_array_get(wlens_sel, 4, NULL), 9.0, 1e-10); + + hdrl_spectrum1D_delete(&obs_s); + hdrl_spectrum1D_delete(&ref_s); + hdrl_spectrum1D_delete(&E_x); + hdrl_response_result_delete(r); + hdrl_parameter_delete(calc_par); + hdrl_parameter_delete(fit_par); + cpl_array_delete(fit_points); + cpl_bivector_delete(high_abs_regions); +} + + +void test_edges_of_response_outside_fit_points(void){ + + hdrl_spectrum1D * obs_s = NULL; + hdrl_spectrum1D * ref_s = NULL; + hdrl_spectrum1D * E_x = NULL; + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + obs_s = create_spectrum(wlen, flx, flx_e, 5); + } + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + ref_s = create_spectrum(wlen, flx, flx_e, 5); + } + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + E_x = create_spectrum(wlen, flx, flx_e, 5); + } + + hdrl_parameter * calc_par = + hdrl_response_parameter_create((hdrl_value){1,.2}, + (hdrl_value){2,.3}, + (hdrl_value){5,.2}, + (hdrl_value){7,.1}); + + cpl_array * fit_points = create_array((double[]){3.1, 6.8, 6.9, 7.0, 7.5, 9.0, 11.0}, 7); + cpl_bivector * high_abs_regions = NULL; + + hdrl_parameter * fit_par = + hdrl_response_fit_parameter_create(11, fit_points, 1.0, high_abs_regions); + + hdrl_response_result * r = hdrl_response_compute(obs_s, + ref_s, E_x, NULL, NULL, calc_par, fit_par); + cpl_ensure_no_error; + cpl_test_nonnull(r); + + const hdrl_spectrum1D * sel_resp = + hdrl_response_result_get_selected_response(r); + + const cpl_array * wlens_selected = hdrl_spectrum1D_get_wavelength(sel_resp).wavelength; + + cpl_test_eq(cpl_array_get_size(wlens_selected), 7); + + cpl_test_rel(cpl_array_get(wlens_selected, 0, NULL), 3.1, 1e-10); + cpl_test_rel(cpl_array_get(wlens_selected, 1, NULL), 6.8, 1e-10); + cpl_test_rel(cpl_array_get(wlens_selected, 2, NULL), 6.9, 1e-10); + cpl_test_rel(cpl_array_get(wlens_selected, 3, NULL), 7.0, 1e-10); + cpl_test_rel(cpl_array_get(wlens_selected, 4, NULL), 7.5, 1e-10); + cpl_test_rel(cpl_array_get(wlens_selected, 5, NULL), 9.0, 1e-10); + cpl_test_rel(cpl_array_get(wlens_selected, 6, NULL), 11.0, 1e-10); + + const hdrl_spectrum1D * final_resp = hdrl_response_result_get_final_response(r); + + const cpl_array * wlens_dest = hdrl_spectrum1D_get_wavelength(final_resp).wavelength; + const cpl_array * wlens_obs = hdrl_spectrum1D_get_wavelength(obs_s).wavelength; + + cpl_test_eq(cpl_array_get_size(wlens_dest), cpl_array_get_size(wlens_obs)); + /*Must be defined on all the wavelengths (unless the models do not overlap, see test_truncation)*/ + for(cpl_size i = 0; i < cpl_array_get_size(wlens_dest); ++i){ + const double w_d = cpl_array_get(wlens_dest, i, NULL); + const double w_o = cpl_array_get(wlens_obs, i, NULL); + cpl_test_rel(w_d, w_o, 1e-10); + } + + int rej = 0; + /*wlen = 3.0 outside the fit points, rejected*/ + hdrl_spectrum1D_get_flux_value(final_resp, 0, & rej); + cpl_test_eq(rej, 1); + + /*wlen = 7.0 is also the last fit point, NOT rejected*/ + hdrl_spectrum1D_get_flux_value(final_resp, cpl_array_get_size(wlens_dest) - 1, & rej); + cpl_test_eq(rej, 0); + + hdrl_spectrum1D_delete(&obs_s); + hdrl_spectrum1D_delete(&ref_s); + hdrl_spectrum1D_delete(&E_x); + hdrl_response_result_delete(r); + hdrl_parameter_delete(calc_par); + hdrl_parameter_delete(fit_par); + cpl_array_delete(fit_points); + cpl_bivector_delete(high_abs_regions); + +} + +void test_telluric(void){ + + hdrl_spectrum1D * t1 = NULL; + hdrl_spectrum1D * t2 = NULL; + + { + double flx[] = {1, 2, 3, 4, 0, 1}; + double flx_e[] = {.1, .2, .1, .1, .05, .3, .83}; + double wlen[] = {3.1,5,7,9,10.9, 10.95}; + t1 = create_spectrum(wlen, flx, flx_e, 6); + } + + { + double flx[] = {2, 4, 6, 8, 0, 1}; + double flx_e[] = {.1, .2, .1, .1, .05, 3.3}; + double wlen[] = {3.1, 5, 7, 9, 10.9, 10.95}; + t2 = create_spectrum(wlen, flx, flx_e, 6); + } + + hdrl_spectrum1Dlist * ts = hdrl_spectrum1Dlist_new(); + + hdrl_spectrum1Dlist_set(ts, t2, 0); + hdrl_spectrum1Dlist_set(ts, t1, 1); + + cpl_bivector * areas = cpl_bivector_new(3); + + cpl_vector_set(cpl_bivector_get_x(areas), 0, 3); + cpl_vector_set(cpl_bivector_get_y(areas), 0, 5.1); + + cpl_vector_set(cpl_bivector_get_x(areas), 1, 6.9); + cpl_vector_set(cpl_bivector_get_y(areas), 1, 7.1); + + cpl_vector_set(cpl_bivector_get_x(areas), 2, 10.0); + cpl_vector_set(cpl_bivector_get_y(areas), 2, 11.0); + + hdrl_parameter * tell_par = + hdrl_response_telluric_evaluation_parameter_create(ts, 1, 15, CPL_FALSE, + CPL_FALSE, areas , areas, 3, 11); + + hdrl_parameter * calc_par = + hdrl_response_parameter_create((hdrl_value){1,.2}, + (hdrl_value){2,.3}, + (hdrl_value){5,.2}, + (hdrl_value){7,.1}); + + cpl_array * fit_points = create_array((double[]){3.1, 6.8, 6.9, 7.0, 7.5, 9.0, 11.0}, 7); + cpl_bivector * high_abs_regions = create_windows((double[]){8.9}, (double[]){9.1}, 1); + + hdrl_parameter * fit_par = + hdrl_response_fit_parameter_create(11, fit_points, 1.0, high_abs_regions); + + hdrl_response_result * r = hdrl_response_compute(t1, + t1, t1, tell_par, NULL, calc_par, fit_par); + + cpl_size idx = hdrl_response_result_get_best_telluric_model_idx(r); + cpl_test_eq(idx, 1); + + double mean = hdrl_response_result_get_avg_diff_from_1(r); + double stddev = hdrl_response_result_get_stddev(r); + double shift = hdrl_response_result_get_telluric_shift(r); + double doppler = hdrl_response_result_get_doppler_shift(r); + + cpl_test_rel(mean, 0.0041, 1e-2); + cpl_test_rel(stddev, 0.707, 1e-2); + cpl_test((fabs(shift) < 1e-10)); + cpl_test(doppler >= 0.); + + const hdrl_spectrum1D * obs_corr = + hdrl_response_result_get_corrected_obs_spectrum(r); + + cpl_test_eq(hdrl_spectrum1D_get_size(obs_corr), hdrl_spectrum1D_get_size(t1)); + + hdrl_value v = hdrl_spectrum1D_get_flux_value(obs_corr, 2, NULL); + cpl_test_rel(v.data, 1, 1e-5); + + cpl_ensure_no_error; + cpl_test_nonnull(r); + cpl_bivector_delete(areas); + hdrl_spectrum1Dlist_delete(ts); + hdrl_response_result_delete(r); + hdrl_parameter_delete(calc_par); + hdrl_parameter_delete(fit_par); + hdrl_parameter_delete(tell_par); + cpl_array_delete(fit_points); + cpl_bivector_delete(high_abs_regions); +} + +void test_ignore_abs_regions(void){ + + hdrl_spectrum1D * obs_s = NULL; + hdrl_spectrum1D * ref_s = NULL; + hdrl_spectrum1D * E_x = NULL; + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + obs_s = create_spectrum(wlen, flx, flx_e, 5); + } + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + ref_s = create_spectrum(wlen, flx, flx_e, 5); + } + + { + double flx[] = {1,2,3,4,5}; + double flx_e[] = {.1, .2, .1, .1, .05}; + double wlen[] = {3,5,7,9,11}; + E_x = create_spectrum(wlen, flx, flx_e, 5); + } + + hdrl_parameter * calc_par = + hdrl_response_parameter_create((hdrl_value){1,.2}, + (hdrl_value){2,.3}, + (hdrl_value){5,.2}, + (hdrl_value){7,.1}); + + cpl_array * fit_points = create_array((double[]){3.1, 6.8, 6.9, 7.0, 7.5, 9.0, 11.0}, 7); + cpl_bivector * high_abs_regions = create_windows((double[]){8.9}, (double[]){9.1}, 1); + + + hdrl_parameter * fit_par_no_abs = + hdrl_response_fit_parameter_create(11, fit_points, 1.0, NULL); + + hdrl_parameter * fit_par_abs = + hdrl_response_fit_parameter_create(11, fit_points, 1.0, high_abs_regions); + + hdrl_response_result * r_no_abs = hdrl_response_compute(obs_s, + ref_s, E_x, NULL, NULL, calc_par, fit_par_no_abs); + cpl_ensure_no_error; + cpl_test_nonnull(r_no_abs); + + hdrl_response_result * r_abs = hdrl_response_compute(obs_s, + ref_s, E_x, NULL, NULL, calc_par, fit_par_abs); + cpl_ensure_no_error; + cpl_test_nonnull(r_abs); + + const hdrl_spectrum1D * resp_selected_abs = hdrl_response_result_get_selected_response(r_abs); + const hdrl_spectrum1D * resp_selected_no_abs = hdrl_response_result_get_selected_response(r_no_abs); + + cpl_test_eq(hdrl_spectrum1D_get_size(resp_selected_abs), hdrl_spectrum1D_get_size(resp_selected_no_abs) - 1); + + int rej = 0; + cpl_test_rel(hdrl_spectrum1D_get_wavelength_value(resp_selected_abs, 0, &rej), + hdrl_spectrum1D_get_wavelength_value(resp_selected_no_abs, 0, &rej), 1e-10); + cpl_test_rel(hdrl_spectrum1D_get_wavelength_value(resp_selected_abs, 1, &rej), + hdrl_spectrum1D_get_wavelength_value(resp_selected_no_abs, 1, &rej), 1e-10); + cpl_test_rel(hdrl_spectrum1D_get_wavelength_value(resp_selected_abs, 2, &rej), + hdrl_spectrum1D_get_wavelength_value(resp_selected_no_abs, 2, &rej), 1e-10); + cpl_test_rel(hdrl_spectrum1D_get_wavelength_value(resp_selected_abs, 3, &rej), + hdrl_spectrum1D_get_wavelength_value(resp_selected_no_abs, 3, &rej), 1e-10); + cpl_test_rel(hdrl_spectrum1D_get_wavelength_value(resp_selected_abs, 4, &rej), + hdrl_spectrum1D_get_wavelength_value(resp_selected_no_abs, 4, &rej), 1e-10); + cpl_test_rel(hdrl_spectrum1D_get_wavelength_value(resp_selected_abs, 5, &rej), + hdrl_spectrum1D_get_wavelength_value(resp_selected_no_abs, 6, &rej), 1e-10); + + hdrl_spectrum1D_delete(&obs_s); + hdrl_spectrum1D_delete(&ref_s); + hdrl_spectrum1D_delete(&E_x); + hdrl_response_result_delete(r_no_abs); + hdrl_response_result_delete(r_abs); + hdrl_parameter_delete(calc_par); + hdrl_parameter_delete(fit_par_no_abs); + hdrl_parameter_delete(fit_par_abs); + cpl_array_delete(fit_points); + cpl_bivector_delete(high_abs_regions); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of efficiency calculation module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_response_basic(); + + test_truncation(); + + test_edges_of_response_outside_fit_points(); + + test_ignore_abs_regions(); + + test_telluric(); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_sigclip-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_sigclip-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_sigclip-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_sigclip-test.c 2015-03-18 09:23:58.000000000 +0000 @@ -0,0 +1,705 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2012,2013 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_sigclip.h" +#include "hdrl_utils.h" +#include + +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + +#ifndef SQR +#define SQR(a) ((a) * (a)) +#endif + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_sigclip_test Testing of the HDRL Sigma Clipping module + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_clip_kappa_sigma_test(void) +{ + double omean, omean_err, rej_low, rej_high; + cpl_size naccepted; + + { + double * dpixels = cpl_calloc(9, sizeof(double)); + + cpl_vector * data = cpl_vector_wrap(9, dpixels); + cpl_vector * errors = cpl_vector_new(9); + cpl_vector_fill(errors, 1); + + /* null optional out params */ + hdrl_kappa_sigma_clip(data, errors, 3, 3, 3, CPL_FALSE, + &omean, NULL, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(omean, 0.); + + /* all out params NULL makes no sense */ + hdrl_kappa_sigma_clip(data, errors, 3, 3, 3, CPL_FALSE, + NULL, NULL, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* NULL data */ + hdrl_kappa_sigma_clip(NULL, errors, 3, 3, 3, CPL_FALSE, + &omean, NULL, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* wrong iter */ + hdrl_kappa_sigma_clip(data, errors, 3, 3, 0, CPL_TRUE, + &omean, NULL, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + cpl_vector_delete(data); + cpl_vector_delete(errors); + } + + { + double * dpixels = cpl_calloc(9, sizeof(double)); + + cpl_vector * data = cpl_vector_wrap(9, dpixels); + cpl_vector * errors = cpl_vector_new(9); + cpl_vector_fill(errors, 1); + + hdrl_kappa_sigma_clip(data, errors, 3, 3, 3, CPL_FALSE, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(omean, 0.); + cpl_test_rel(omean_err, 1 / sqrt(9), 0.001); + cpl_test_eq(naccepted, 9); + + cpl_vector_delete(data); + cpl_vector_delete(errors); + } + + { + /* MAD sigma ~3 median 6, check that 1.5 and 10.5 which are closer to + * 6 -+ 3 * 1.5 than 4 and 6 but beyond the k*sig limit are not included */ + double values[] = {1.5, 6., 4., 6., 4., 6., 4., 6., 10.5}; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + + hdrl_kappa_sigma_clip(data, errors, 1.5, 1.5, 1, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, (4. * 3 + 6 * 4.) / 7., 0.001); + cpl_test_rel(omean_err, 1 / sqrt(n - 2), 0.001); + cpl_test_rel(rej_low, 1.55, 0.02); + cpl_test_rel(rej_high, 10.44, 0.02); + cpl_test_eq(naccepted, n - 2); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + { + /* special case of one remaining pixels */ + double values[] = {10.}; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + + hdrl_kappa_sigma_clip(data, errors, 2., 2., 1, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, values[0], 0.001); + cpl_test_rel(omean_err, 1, 0.001); + cpl_test_rel(rej_low, values[0], 0.02); + cpl_test_rel(rej_high, values[0], 0.02); + cpl_test_eq(naccepted, n); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + { + /* gaus mean 100 sigma 3.5 */ + double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108 }; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + + /* kappa 2 included by iqr 92 and 108 */ + hdrl_kappa_sigma_clip(data, errors, 2., 2., 3, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.001); + cpl_test_rel(omean_err, 1 / sqrt(n), 0.001); + /* sigma overestimated by iqr */ + cpl_test_rel(rej_low, 91., 0.005); + cpl_test_rel(rej_high, 109, 0.005); + cpl_test_eq(naccepted, n); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + { + /* gaus mean 100 sigma 3.5, 2 sigma range, 2 outliers */ + double values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108 }; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + + hdrl_kappa_sigma_clip(data, errors, 3, 3, 3, CPL_FALSE, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.005); + cpl_test_rel(omean_err, 1 / sqrt(n - 2), 0.001); + cpl_test_eq(naccepted, n - 2); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + /* test inputs are not modified */ + { + double values[] = {54, 234. ,5,2, 343, 23 , 2, 0.21, 0.1232 , 1.2e3}; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_duplicate(data); + cpl_vector * odata = cpl_vector_duplicate(data); + cpl_vector * oerrors = cpl_vector_duplicate(errors); + + hdrl_kappa_sigma_clip(data, errors, 3, 3, 3, CPL_FALSE, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_vector_abs(data, odata, FLT_EPSILON); + cpl_test_vector_abs(errors, oerrors, FLT_EPSILON); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + cpl_vector_delete(odata); + cpl_vector_delete(oerrors); + } + + + /* image test */ + { + /* gaus mean 100 sigma 3.5, 2 sigma range, 2 outliers */ + double values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 100, 100}; + const int n = ARRAY_LEN(values); + + cpl_image * data = cpl_image_wrap(sqrt(n), sqrt(n), CPL_TYPE_DOUBLE, + values); + cpl_image * errors = cpl_image_new(sqrt(n), sqrt(n), CPL_TYPE_DOUBLE); + cpl_image_add_scalar(errors, 1); + + hdrl_kappa_sigma_clip_image(data, errors, 3, 3, 3, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.005); + cpl_test_rel(omean_err, 1 / sqrt(n - 2), 0.001); + cpl_test_eq(naccepted, n - 2); + + cpl_image_unwrap(data); + cpl_image_delete(errors); + } + + /* image test with bad pixels */ + { + /* gaus mean 100 sigma 3.5, 2 sigma range, 2 outliers */ + float values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 100, 100}; + const int n = sqrt(ARRAY_LEN(values)); + + cpl_image * data = cpl_image_wrap(n, n, CPL_TYPE_FLOAT, values); + cpl_image * errors = cpl_image_new(n, n, CPL_TYPE_FLOAT); + cpl_image_add_scalar(errors, 1); + /* set two bad pixels with really high error */ + cpl_image_reject(data, n, n); + cpl_image_reject(data, n, n - 1); + cpl_image_set(errors, n, n, 2343.e30); + cpl_image_set(errors, n, n - 1, 2343.e30); + cpl_image_reject_from_mask(errors, cpl_image_get_bpm(data)); + + hdrl_kappa_sigma_clip_image(data, errors, 3, 3, 3, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.005); + cpl_test_rel(omean_err, 1 / sqrt(n * n - 4), 0.001); + cpl_test_eq(naccepted, (n * n) - 4); + + cpl_image_unwrap(data); + cpl_image_delete(errors); + } + + /* test unequal bpms */ + { + const int n = 5; + cpl_image * data = cpl_image_new(n, n, CPL_TYPE_FLOAT); + cpl_image * errors = cpl_image_new(n, n, CPL_TYPE_FLOAT); + cpl_image_reject(data, n, n); + cpl_image_reject(data, n, n - 1); + + hdrl_kappa_sigma_clip_image(data, errors, 3, 3, 3, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(data); + cpl_image_delete(errors); + } + + return cpl_error_get_code(); +} + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_minmax_test Testing of the HDRL MINMAX Clipping module + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_clip_minmax_test(void) +{ + double omean, omean_err, nlow, nhigh, rej_low, rej_high; + + cpl_size naccepted; + + { + double * dpixels = cpl_calloc(9, sizeof(double)); + + cpl_vector * data = cpl_vector_wrap(9, dpixels); + cpl_vector * errors = cpl_vector_new(9); + cpl_vector_fill(errors, 1); + + /* null optional out params */ + hdrl_minmax_clip(data, errors, 3, 3, CPL_FALSE, + &omean, NULL, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(omean, 0.); + + /* all out params NULL makes no sense */ + hdrl_minmax_clip(data, errors, 3, 3, CPL_FALSE, + NULL, NULL, NULL, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* NULL data */ + hdrl_minmax_clip(NULL, errors, 3, 3, CPL_TRUE, + &omean, NULL, NULL, NULL, &rej_high); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + + cpl_vector_delete(data); + cpl_vector_delete(errors); + } + + { + double * dpixels = cpl_calloc(9, sizeof(double)); + cpl_vector * data = cpl_vector_wrap(9, dpixels); + cpl_vector * errors = cpl_vector_new(9); + cpl_vector_fill(errors, 1); + nlow = 3; + nhigh = 3; + hdrl_minmax_clip(data, errors, nlow, nhigh, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(omean, 0.); + cpl_test_rel(omean_err, 1 / sqrt(9 - (nlow + nhigh)), 0.001); + cpl_test_eq(naccepted, 9 - (nlow + nhigh)); + cpl_test_eq(rej_low, 0.); + cpl_test_eq(rej_high, 0.); + + cpl_vector_delete(data); + cpl_vector_delete(errors); + } + + + { + /* special case of one remaining pixels */ + double values[] = {10.}; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + nlow = 1; + nhigh = 1; + hdrl_minmax_clip(data, errors, nlow, nhigh, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test(isnan(omean)); + cpl_test(isnan(omean_err)); + cpl_test_eq(naccepted, 0); + cpl_test_eq(rej_low, 0); /* invalid */ + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + { + /* gaus mean 100 sigma 3.5 - special case - don't reject anything */ + double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108 }; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + nlow = 0; + nhigh = 0; + + hdrl_minmax_clip(data, errors, nlow, nhigh, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., n * HDRL_EPS_DATA); + cpl_test_rel(omean_err, 1 / sqrt(n -(nlow + nhigh)), 0.001); + cpl_test_eq(rej_low, 92.); + cpl_test_eq(rej_high, 108); + cpl_test_eq(naccepted, n - (nlow + nhigh)); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + { + /* gaus mean 100 sigma 3.5 */ + double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108 }; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + nlow = 2; + nhigh = 2; + + hdrl_minmax_clip(data, errors, nlow, nhigh, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.001); + cpl_test_rel(omean_err, 1 / sqrt(n -(nlow + nhigh)), 0.001); + /* sigma overestimated by iqr */ + cpl_test_eq(rej_low, 94.); + cpl_test_eq(rej_high, 106); + cpl_test_eq(naccepted, n - (nlow + nhigh)); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + { + /* gaus mean 100 sigma 3.5, 2 sigma range, 2 outliers */ + double values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108 }; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_new(n); + cpl_vector_fill(errors, 1); + nlow = 3; + nhigh = 3; + hdrl_minmax_clip(data, errors, nlow, nhigh, CPL_FALSE, + &omean, &omean_err, &naccepted, + NULL, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.005); + cpl_test_rel(omean_err, 1 / sqrt(n - (nlow + nhigh)), 0.001); + cpl_test_eq(naccepted, n - (nlow + nhigh)); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + } + + /* test inputs are not modified */ + { + double values[] = {54, 234. ,5,2, 343, 23 , 2, 0.21, 0.1232 , 1.2e3}; + const int n = ARRAY_LEN(values); + + cpl_vector * data = cpl_vector_wrap(n, values); + cpl_vector * errors = cpl_vector_duplicate(data); + cpl_vector * odata = cpl_vector_duplicate(data); + cpl_vector * oerrors = cpl_vector_duplicate(errors); + nlow = 3; + nhigh = 3; + + hdrl_minmax_clip(data, errors, nlow, nhigh, CPL_FALSE, + &omean, &omean_err, &naccepted, + &rej_low, &rej_high); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(rej_low, 2.); + cpl_test_eq(rej_high, 54.); + + cpl_test_vector_abs(data, odata, 0.); + cpl_test_vector_abs(errors, oerrors, 0.); + + cpl_vector_unwrap(data); + cpl_vector_delete(errors); + cpl_vector_delete(odata); + cpl_vector_delete(oerrors); + } + + + /* image test */ + { + /* gaus mean 100 sigma 3.5, 2 sigma range, 3 outliers */ + double values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 100, -1000}; + const int n = ARRAY_LEN(values); + + cpl_image * data = cpl_image_wrap(sqrt(n), sqrt(n), CPL_TYPE_DOUBLE, + values); + cpl_image * errors = cpl_image_new(sqrt(n), sqrt(n), CPL_TYPE_DOUBLE); + cpl_image_add_scalar(errors, 1); + nlow = 2; + nhigh = 1; + + hdrl_minmax_clip_image(data, errors, nlow, nhigh, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 100., 0.005); + cpl_test_rel(omean_err, 1 / sqrt(n - (nlow + nhigh)), 0.001); + cpl_test_eq(naccepted, n - (nlow + nhigh)); + + cpl_image_unwrap(data); + cpl_image_delete(errors); + } + + /* image test with bad pixels */ + { + /* gaus mean 100 sigma 3.5, 2 sigma range, 2 outliers */ + float values[] = {1, 150, 94, 94, 95, 95, 96, 96, 96, 97, + 97, 97, 97, 98, 98, 98, 98, 99, 99, 99, + 99, 100, 100, 100, 100, 100, 101, 101, 101, 101, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, + 104, 105, 105, 106, 106, 107, 108, 100, 100}; + const int n = sqrt(ARRAY_LEN(values)); + + cpl_image * data = cpl_image_wrap(n, n, CPL_TYPE_FLOAT, values); + cpl_image * errors = cpl_image_new(n, n, CPL_TYPE_FLOAT); + cpl_image_add_scalar(errors, 1); + nlow = 1; + nhigh = 1; + + /* set two bad pixels with really high error */ + cpl_image_reject(data, n, n); + cpl_image_reject(data, n, n - 1); + cpl_image_set(errors, n, n, 2343.e30); + cpl_image_set(errors, n, n - 1, 2343.e30); + cpl_image_reject_from_mask(errors, cpl_image_get_bpm(data)); + + hdrl_minmax_clip_image(data, errors, nlow, nhigh, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + + cpl_test_rel(omean, 100., 0.005); + cpl_test_rel(omean_err, 1 / sqrt(n * n - (nlow + nhigh + 2)), 0.001); + cpl_test_eq(naccepted, (n * n) - (nlow + nhigh + 2)); + + cpl_image_unwrap(data); + cpl_image_delete(errors); + } + + /* test unequal bpms */ + { + const int n = 5; + cpl_image * data = cpl_image_new(n, n, CPL_TYPE_FLOAT); + cpl_image * errors = cpl_image_new(n, n, CPL_TYPE_FLOAT); + cpl_image_reject(data, n, n); + cpl_image_reject(data, n, n - 1); + nlow = 3; + nhigh = 3; + + hdrl_minmax_clip_image(data, errors, nlow, nhigh, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_image_delete(data); + cpl_image_delete(errors); + } + /* image test equal range of rejected values */ + { + float values[] = {-5., -5., -5., 1., 5., 1., 5., 1., 5., 5.}; + float errors[] = {50., 500., 100., 1., 5., 1., 500., 1., 200.}; + const int n = sqrt(ARRAY_LEN(values)); + + cpl_image * data = cpl_image_wrap(n, n, CPL_TYPE_FLOAT, values); + cpl_image * errs = cpl_image_wrap(n, n, CPL_TYPE_FLOAT, errors); + cpl_image * odata = cpl_image_duplicate(data); + cpl_image * oerrs = cpl_image_duplicate(errs); + + hdrl_minmax_clip_image(data, errs, 2, 2, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + + cpl_test_rel(omean, 0.6, 10 * HDRL_EPS_DATA); + cpl_test_rel(omean_err, sqrt((SQR(50.) + 1. * 3. + SQR(5.)) / + SQR(n * n - 4)), + 20 * HDRL_EPS_ERROR); + cpl_test_eq(naccepted, (n * n) - (4)); + + /* select multiple smallest errors, low*/ + hdrl_minmax_clip_image(data, errs, 1, 2, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + /* select multiple smallest errors, high */ + hdrl_minmax_clip_image(data, errs, 2, 1, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 8. / 6., 10 * HDRL_EPS_DATA); + cpl_test_rel(omean_err, + sqrt((SQR(50.) + SQR(200.) + 1. * 3. + SQR(5.)) / + SQR(n * n - (3))), + 20 * HDRL_EPS_ERROR); + cpl_test_eq(naccepted, (n * n) - (3)); + + /* select multiple smallest errors, low + high */ + hdrl_minmax_clip_image(data, errs, 1, 1, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 3. / 7., 10 * HDRL_EPS_DATA); + cpl_test_rel(omean_err, + sqrt((SQR(50.) + SQR(100.) + SQR(200.) + 3. + SQR(5.)) / + SQR(n * n - 2)), + 20 * HDRL_EPS_ERROR); + cpl_test_eq(naccepted, (n * n) - (2)); + + /* 50 error not in equal range so we should get the 100. error */ + values[0] = -5.0001; + cpl_image_set(odata, 1, 1, values[0]); + hdrl_minmax_clip_image(data, errs, 2, 2, + &omean, &omean_err, &naccepted, + NULL, NULL); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_rel(omean, 0.6, 10 * HDRL_EPS_DATA); + cpl_test_rel(omean_err, sqrt((SQR(100.) + 1. * 3. + SQR(5.)) / + SQR(n * n - 4)), + 20 * HDRL_EPS_ERROR); + cpl_test_eq(naccepted, (n * n) - (4)); + + /* check original have not been overwritten */ + cpl_test_image_abs(data, odata, 0); + cpl_test_image_abs(errs, oerrs, 0); + + cpl_image_delete(odata); + cpl_image_delete(oerrs); + cpl_image_unwrap(data); + cpl_image_unwrap(errs); + } + + return cpl_error_get_code(); +} + + + + + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of clipping + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_clip_kappa_sigma_test(); + hdrl_clip_minmax_test(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_spectrum1dlist-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_spectrum1dlist-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_spectrum1dlist-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_spectrum1dlist-test.c 2017-09-07 08:33:56.000000000 +0000 @@ -0,0 +1,487 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl.h" +#include "hdrl_spectrum_resample.h" + +#include + + +hdrl_spectrum1D * create_spectrum(double fx){ + cpl_image * flx = cpl_image_new(1, 1, HDRL_TYPE_DATA); + cpl_array * wln = cpl_array_new(1, HDRL_TYPE_DATA); + cpl_image_set(flx, 1, 1 , fx); + cpl_array_set(wln, 0, 100); + hdrl_spectrum1D * s = hdrl_spectrum1D_create_error_free(flx, wln, + hdrl_spectrum1D_wave_scale_linear); + + cpl_array_delete(wln); + cpl_image_delete(flx); + + return s; +} + +void check_equal(const hdrl_spectrum1D * s1, const hdrl_spectrum1D * s2){ + + const cpl_size sz = hdrl_spectrum1D_get_size(s1); + cpl_test_eq(sz, hdrl_spectrum1D_get_size(s2)); + + for(cpl_size i = 0; i < sz; ++i){ + int rej1 = 0, rej2 = 0; + hdrl_value v1 = hdrl_spectrum1D_get_flux_value(s1, i, &rej1); + hdrl_value v2 = hdrl_spectrum1D_get_flux_value(s2, i, &rej2); + + cpl_test_eq(rej1, rej2); + cpl_test_rel(v1.data, v2.data, 1e-5); + cpl_test_rel(v1.error, v2.error, 1e-5); + } +} + +void check_list_sequential(const hdrl_spectrum1Dlist * list, + cpl_size idx, double mlx){ + + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(list); ++i){ + const hdrl_spectrum1D * s = hdrl_spectrum1Dlist_get_const(list, i); + hdrl_value v = hdrl_spectrum1D_get_flux_value(s, 0, NULL); + cpl_test_rel(v.data, idx * mlx, 1e-10); + idx++; + } + +} + +void test_spectrum1dlist_wrap(void){ + hdrl_spectrum1D ** sl = cpl_calloc(6, sizeof(hdrl_spectrum1D*)); + + sl[0] = create_spectrum(1); + sl[1] = create_spectrum(2); + sl[2] = create_spectrum(3); + sl[3] = create_spectrum(4); + sl[4] = create_spectrum(5); + sl[5] = create_spectrum(6); + + hdrl_spectrum1Dlist * list = hdrl_spectrum1Dlist_wrap(sl, 6); + + cpl_test_eq(hdrl_spectrum1Dlist_get_size(list), 6); + + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(list); ++i){ + const hdrl_spectrum1D * s = hdrl_spectrum1Dlist_get_const(list, i); + cpl_test_eq_ptr(s, sl[i]); + } + + hdrl_spectrum1Dlist_delete(list); +} + +void test_spectrum1dlist(void){ + + hdrl_spectrum1Dlist * list1 = hdrl_spectrum1Dlist_new(); + + cpl_test_eq(0, hdrl_spectrum1Dlist_get_size(list1)); + + hdrl_spectrum1D * s4 = create_spectrum(4); + + { + hdrl_spectrum1D * s1 = create_spectrum(1); + hdrl_spectrum1D * s11 = create_spectrum(1); + hdrl_spectrum1D * s2 = create_spectrum(2); + hdrl_spectrum1D * s3 = create_spectrum(3); + hdrl_spectrum1D * s5 = create_spectrum(5); + hdrl_spectrum1D * s6 = create_spectrum(6); + + hdrl_spectrum1Dlist_set(list1, s1, 0); + /*Removed s1 when setting*/ + hdrl_spectrum1Dlist_set(list1, s11, 0); + hdrl_spectrum1Dlist_set(list1, s2, 1); + hdrl_spectrum1Dlist_set(list1, s3, 2); + hdrl_spectrum1Dlist_set(list1, s4, 3); + hdrl_spectrum1Dlist_set(list1, s5, 4); + hdrl_spectrum1Dlist_set(list1, s6, 5); + } + + cpl_test_eq(6, hdrl_spectrum1Dlist_get_size(list1)); + + /* Check duplication */ + hdrl_spectrum1Dlist * list2 = hdrl_spectrum1Dlist_duplicate(list1); + + cpl_test_eq(hdrl_spectrum1Dlist_get_size(list1), + hdrl_spectrum1Dlist_get_size(list2)); + + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(list1); ++i){ + const hdrl_spectrum1D * s1 = hdrl_spectrum1Dlist_get_const(list1, i); + const hdrl_spectrum1D * s2 = hdrl_spectrum1Dlist_get_const(list2, i); + + check_equal(s1, s2); + + /*check that list1 and list2 point to different memory spaces*/ + cpl_test_noneq_ptr(s1, s2); + } + + /*Check getters (mutability)*/ + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(list1); ++i){ + hdrl_spectrum1D * s = hdrl_spectrum1Dlist_get(list2, i); + hdrl_value v = hdrl_spectrum1D_get_flux_value(s, 0, NULL); + cpl_test_rel(v.data, (double)i + 1.0 , 1e-5); + hdrl_spectrum1D_mul_scalar(s, (hdrl_value){5.0, 0.0}); + } + + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(list1); ++i){ + hdrl_spectrum1D * s = hdrl_spectrum1Dlist_get(list2, i); + hdrl_value v = hdrl_spectrum1D_get_flux_value(s, 0, NULL); + cpl_test_rel(v.data, ((double)i + 1.0) * 5.0 , 1e-5); + } + + hdrl_spectrum1D * new_s4 = hdrl_spectrum1Dlist_unset(list1, 3); + + cpl_test_eq_ptr(new_s4, s4); + + cpl_test_eq(hdrl_spectrum1Dlist_get_size(list1), 5); + + const double flx_value[] = {1, 2, 3, 5, 6}; + for(cpl_size i = 0; i < hdrl_spectrum1Dlist_get_size(list1); ++i){ + + const hdrl_spectrum1D * s = hdrl_spectrum1Dlist_get_const(list1, i); + hdrl_value v = hdrl_spectrum1D_get_flux_value(s, 0, NULL); + cpl_test_rel(v.data, flx_value[i], 1e-5); + } + + cpl_size i = 1; + while(hdrl_spectrum1Dlist_get_size(list2)){ + hdrl_spectrum1D * s = hdrl_spectrum1Dlist_unset(list2, 0); + check_list_sequential(list2, i + 1, 5.0); + hdrl_value v = hdrl_spectrum1D_get_flux_value(s, 0, NULL); + cpl_test_rel(v.data, i * 5.0, 1e-5); + hdrl_spectrum1D_delete(&s); + i++; + } + + hdrl_spectrum1Dlist_delete(list2); + hdrl_spectrum1Dlist_delete(list1); + hdrl_spectrum1D_delete(&s4); +} + /*data[i] is both wavelength and flux. if data[i] the i-th pixel is rejected*/ +hdrl_spectrum1D * +create_spectrum_long(const double * data, const cpl_size length){ + cpl_array * wlens = cpl_array_new(length, HDRL_TYPE_DATA); + cpl_image * flx = cpl_image_new(length, 1, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < length; ++i){ + cpl_array_set(wlens, i, fabs(data[i])); + + if(data[i] >= 0) + cpl_image_set(flx, i + 1, 1, data[i]); + else + cpl_image_reject(flx, i + 1, 1); + } + + hdrl_spectrum1D * s = hdrl_spectrum1D_create_error_free(flx, wlens, + hdrl_spectrum1D_wave_scale_linear); + + cpl_image_delete(flx); + cpl_array_delete(wlens); + return s; +} + +/*check that bad pixels at the beginning or at the end of spectrum + * do not contribute to the collapsed spectrum*/ +void test_spectrum1dlist_collapse_badpix(void){ + + hdrl_spectrum1Dlist * l = hdrl_spectrum1Dlist_new(); + + double aValues1[4] = {1, 2, 3, 4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues1, 4), 0); + + double aValues2[3] = {-1, 2, 4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues2, 3), 1); + + double aValues3[3] = {1, 3, -4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues3, 3), 2); + + cpl_array * wlenghts = cpl_array_new(6, HDRL_TYPE_DATA); + for(cpl_size i = 0; i < cpl_array_get_size(wlenghts); ++i){ + cpl_array_set(wlenghts, i, i); + } + + hdrl_parameter * stacking_par = hdrl_collapse_mean_parameter_create(); + hdrl_parameter * resampling_par = + hdrl_spectrum1D_resample_interpolate_parameter_create(hdrl_spectrum1D_interp_linear); + + hdrl_spectrum1D * res = NULL; + cpl_image * contrib = NULL; + hdrl_imagelist * aligned_fluxes = NULL; + + hdrl_spectrum1Dlist_collapse(l, stacking_par, wlenghts, resampling_par, CPL_FALSE, + &res, &contrib, &aligned_fluxes); + + int contribs[] = {2, 3, 3, 2}; + for(cpl_size i = 1; i < 5; ++i){ + int rej = 0; + const double el = cpl_image_get(contrib, i + 1, 1, &rej); + cpl_test_eq(rej, 0); + cpl_test_eq(el, contribs[i - 1]); + } + + int reject = 0; + double el = cpl_image_get(contrib, 6, 1, &reject); + cpl_test_eq(reject, 0); + cpl_test_eq(el, 0); + + reject = 0; + el = cpl_image_get(contrib, 1, 1, &reject); + cpl_test_eq(reject, 0); + cpl_test_eq(el, 0); + + const cpl_size sz = hdrl_spectrum1D_get_size(res); + cpl_test_eq(cpl_array_get_size(wlenghts), sz); + + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + const hdrl_value v = hdrl_spectrum1D_get_flux_value(res, i, &rej); + if(i == 0 || i == (sz - 1)){ + cpl_test_eq(rej, 1); + continue; + } + cpl_test_rel(v.data, i, 1e-5); + cpl_test_eq(rej, 0); + } + + hdrl_spectrum1Dlist_delete(l); + hdrl_spectrum1D_delete(&res); + cpl_image_delete(contrib); + hdrl_parameter_delete(stacking_par); + hdrl_parameter_delete(resampling_par); + hdrl_imagelist_delete(aligned_fluxes); + cpl_array_delete(wlenghts); +} + +/*Check that resamplking pixels having rejected neighbors in the original spectrum + * do not contribute to the stacking*/ +void test_spectrum1dlist_collapse_mark_rej_in_interpolation(void){ + + hdrl_spectrum1Dlist * l = hdrl_spectrum1Dlist_new(); + + double aValues1[4] = {1, 2, 3, 4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues1, 4), 0); + + double aValues2[4] = {-1, 2, -3, 4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues2, 4), 1); + + double aValues3[4] = {1,-2, 3, -4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues3, 4), 2); + + cpl_array * wlenghts = cpl_array_new(6, HDRL_TYPE_DATA); + for(cpl_size i = 0; i < cpl_array_get_size(wlenghts); ++i){ + cpl_array_set(wlenghts, i, i); + } + + hdrl_parameter * stacking_par = hdrl_collapse_mean_parameter_create(); + hdrl_parameter * resampling_par = + hdrl_spectrum1D_resample_interpolate_parameter_create(hdrl_spectrum1D_interp_linear); + + hdrl_spectrum1D * res = NULL; + cpl_image * contrib = NULL; + hdrl_imagelist * aligned_fluxes = NULL; + + hdrl_spectrum1Dlist_collapse(l, stacking_par, wlenghts, resampling_par, CPL_TRUE, + &res, &contrib, &aligned_fluxes); + + int contribs[] = {2, 2, 2, 2}; + for(cpl_size i = 1; i < 5; ++i){ + int reject = 0; + const double el = cpl_image_get(contrib, i + 1, 1, &reject); + cpl_test_eq(reject, 0); + cpl_test_eq(el, contribs[i - 1]); + } + + int rej_contr = 0; + double el = cpl_image_get(contrib, 6, 1, &rej_contr); + cpl_test_eq(rej_contr, 0); + cpl_test_eq(el, 0); + + rej_contr = 0; + el = cpl_image_get(contrib, 1, 1, &rej_contr); + cpl_test_eq(rej_contr, 0); + cpl_test_eq(el, 0); + + const cpl_size sz = hdrl_spectrum1D_get_size(res); + cpl_test_eq(cpl_array_get_size(wlenghts), sz); + + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + const hdrl_value v = hdrl_spectrum1D_get_flux_value(res, i, &rej); + if(i == 0 || i == (sz - 1)){ + cpl_test_eq(rej, 1); + continue; + } + cpl_test_rel(v.data, i, 1e-5); + cpl_test_eq(rej, 0); + } + + hdrl_spectrum1Dlist_delete(l); + hdrl_spectrum1D_delete(&res); + cpl_image_delete(contrib); + hdrl_parameter_delete(stacking_par); + hdrl_parameter_delete(resampling_par); + hdrl_imagelist_delete(aligned_fluxes); + cpl_array_delete(wlenghts); +} + +/*check that shorted spectra are handled correctly*/ +void test_spectrum1dlist_collapse_holes(void){ + + hdrl_spectrum1Dlist * l = hdrl_spectrum1Dlist_new(); + + double aValues1[4] = {1, 2, 3, 4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues1, 4), 0); + + double aValues2[2] = {2, 4}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues2, 2), 1); + + double aValues3[2] = {1, 3}; + hdrl_spectrum1Dlist_set(l, create_spectrum_long(aValues3, 2), 2); + + cpl_array * wlenghts = cpl_array_new(6, HDRL_TYPE_DATA); + for(cpl_size i = 0; i < cpl_array_get_size(wlenghts); ++i){ + cpl_array_set(wlenghts, i, i); + } + + hdrl_parameter * stacking_par = hdrl_collapse_mean_parameter_create(); + hdrl_parameter * resampling_par = + hdrl_spectrum1D_resample_interpolate_parameter_create(hdrl_spectrum1D_interp_linear); + + hdrl_spectrum1D * res = NULL; + cpl_image * contrib = NULL; + hdrl_imagelist * aligned_fluxes = NULL; + hdrl_spectrum1Dlist_collapse(l, stacking_par, wlenghts, resampling_par, + CPL_FALSE, &res, &contrib, &aligned_fluxes); + + int contribs[] = {2, 3, 3, 2}; + for(cpl_size i = 1; i < 5; ++i){ + int rej_contr = 0; + const double el = cpl_image_get(contrib, i + 1, 1, &rej_contr); + cpl_test_eq(rej_contr, 0); + cpl_test_eq(el, contribs[i - 1]); + } + + int rej_contrib = 0; + double el = cpl_image_get(contrib, 6, 1, &rej_contrib); + cpl_test_eq(rej_contrib, 0); + cpl_test_eq(el, 0); + + rej_contrib = 0; + el = cpl_image_get(contrib, 1, 1, &rej_contrib); + cpl_test_eq(rej_contrib, 0); + cpl_test_eq(el, 0); + + const cpl_size sz = hdrl_spectrum1D_get_size(res); + cpl_test_eq(cpl_array_get_size(wlenghts), sz); + + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + const hdrl_value v = hdrl_spectrum1D_get_flux_value(res, i, &rej); + if(i == 0 || i == (sz - 1)){ + cpl_test_eq(rej, 1); + continue; + } + cpl_test_rel(v.data, i, 1e-5); + cpl_test_eq(rej, 0); + } + + hdrl_spectrum1Dlist_delete(l); + hdrl_spectrum1D_delete(&res); + cpl_image_delete(contrib); + hdrl_imagelist_delete(aligned_fluxes); + hdrl_parameter_delete(stacking_par); + hdrl_parameter_delete(resampling_par); + cpl_array_delete(wlenghts); +} + +void test_error_and_reset(cpl_error_code expected){ + cpl_test_eq_error(expected, cpl_error_get_code()); + cpl_error_reset(); +} + +void test_spectrum1dlist_insert_duplication(void){ + + hdrl_spectrum1Dlist * list1 = hdrl_spectrum1Dlist_new(); + + cpl_test_eq(0, hdrl_spectrum1Dlist_get_size(list1)); + + hdrl_spectrum1D * s1 = create_spectrum(1); + hdrl_spectrum1D * s2 = create_spectrum(2); + hdrl_spectrum1D * s3 = create_spectrum(3); + hdrl_spectrum1D * s4 = create_spectrum(4); + hdrl_spectrum1D * s5 = create_spectrum(5); + hdrl_spectrum1D * s6 = create_spectrum(6); + + hdrl_spectrum1Dlist_set(list1, s1, 0); + hdrl_spectrum1Dlist_set(list1, s2, 1); + hdrl_spectrum1Dlist_set(list1, s3, 2); + hdrl_spectrum1Dlist_set(list1, s4, 3); + hdrl_spectrum1Dlist_set(list1, s5, 4); + hdrl_spectrum1Dlist_set(list1, s6, 5); + + hdrl_spectrum1Dlist_set(list1, s1, 4); + test_error_and_reset(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_spectrum1Dlist_set(list1, s2, 3); + test_error_and_reset(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_spectrum1Dlist_set(list1, s3, 4); + test_error_and_reset(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_spectrum1Dlist_set(list1, s4, 5); + test_error_and_reset(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_spectrum1Dlist_set(list1, s5, 0); + test_error_and_reset(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_spectrum1Dlist_set(list1, s6, 2); + test_error_and_reset(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_spectrum1Dlist_delete(list1); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of efficiency calculation module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_spectrum1dlist(); + test_spectrum1dlist_wrap(); + test_spectrum1dlist_collapse_holes(); + test_spectrum1dlist_collapse_badpix(); + test_spectrum1dlist_collapse_mark_rej_in_interpolation(); + test_spectrum1dlist_insert_duplication(); + + cpl_test_error(CPL_ERROR_NONE); + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_spectrum1d_shift-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_spectrum1d_shift-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_spectrum1d_shift-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_spectrum1d_shift-test.c 2017-09-18 14:35:28.000000000 +0000 @@ -0,0 +1,198 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum_shift.h" + +#include +#include + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_spectrum1d_shift test, the xcorrelation methods are already + * covered by the correlation tests. + */ +/*----------------------------------------------------------------------------*/ + +double calc_gauss(double mean, double sigma, double x){ + + double exponent = - pow((x- mean), 2.0) / (2.0 * sigma * sigma); + double v = 1.0/(2.0 * CPL_MATH_PI * sigma * sigma) * exp(exponent); + return v; +} + +hdrl_value gauss_func(hdrl_data_t lambda){ + + hdrl_data_t mean = 1500; + hdrl_data_t sigma = 250; + + double v = calc_gauss(mean, sigma, lambda); + + return (hdrl_value){v, 0.0}; +} + +hdrl_value absorption1_func(hdrl_data_t lambda){ + + hdrl_data_t mean = 1754; + hdrl_data_t sigma = .75; + + double v = calc_gauss(mean, sigma, lambda); + + return (hdrl_value){ exp(-v), 0.0}; +} + +hdrl_value absorption2_func(hdrl_data_t lambda){ + + hdrl_data_t mean = 1504; + hdrl_data_t sigma = .75; + + double v = calc_gauss(mean, sigma, lambda); + + return (hdrl_value){ exp(-v), 0.0}; +} + +cpl_array * get_wlengths(double start, double stop, double step){ + + cpl_size sz = (cpl_size)floor((stop - start) / step); + cpl_array * arr = cpl_array_new(sz, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < sz; i++){ + cpl_array_set(arr, i, start); + start += step; + } + + return arr; +} + +void test_on_slope(void){ + cpl_array * wlenghts = get_wlengths(1e3, 2e3, 1.0); + + hdrl_spectrum1D * gaussian = + hdrl_spectrum1D_create_analytic(gauss_func, wlenghts, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * absorption = + hdrl_spectrum1D_create_analytic(absorption1_func, wlenghts, hdrl_spectrum1D_wave_scale_linear); + + + hdrl_spectrum1D * gaussian_with_abs = + hdrl_spectrum1D_mul_spectrum_create(gaussian, absorption); + + hdrl_parameter * par = + hdrl_spectrum1D_shift_fit_parameter_create(1750, 1730, 1770, 1740, 1760, 20); + + hdrl_data_t offset = hdrl_spectrum1D_compute_shift_fit(gaussian_with_abs, par); + + cpl_test_rel((1.0 + offset) * 1750., 1754., 1e-3); + + hdrl_spectrum1D_delete(&gaussian); + hdrl_spectrum1D_delete(&absorption); + hdrl_spectrum1D_delete(&gaussian_with_abs); + cpl_array_delete(wlenghts); + hdrl_parameter_delete(par); +} + +void test_on_peak(void){ + + cpl_array * wlenghts = get_wlengths(1e3, 2e3, 1.0); + + hdrl_spectrum1D * gaussian = + hdrl_spectrum1D_create_analytic(gauss_func, wlenghts, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * absorption = + hdrl_spectrum1D_create_analytic(absorption2_func, wlenghts, hdrl_spectrum1D_wave_scale_linear); + + + hdrl_spectrum1D * gaussian_with_abs = + hdrl_spectrum1D_mul_spectrum_create(gaussian, absorption); + + hdrl_parameter * par = + hdrl_spectrum1D_shift_fit_parameter_create(1500, 1480, 1520, 1490, 1510, 20); + + hdrl_data_t offset = hdrl_spectrum1D_compute_shift_fit(gaussian_with_abs, par); + + cpl_test_rel((1.0 + offset) * 1500., 1504., 1e-3); + + hdrl_spectrum1D_delete(&gaussian); + hdrl_spectrum1D_delete(&absorption); + hdrl_spectrum1D_delete(&gaussian_with_abs); + cpl_array_delete(wlenghts); + hdrl_parameter_delete(par); +} + + +void test_compute_shift_xcorrelation(void) +{ + cpl_array * wlenghts = get_wlengths(1e3, 2e3, 1.0); + + hdrl_spectrum1D * gaussian = hdrl_spectrum1D_create_analytic( + gauss_func, wlenghts, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * absorption = hdrl_spectrum1D_create_analytic( + absorption2_func, wlenghts, hdrl_spectrum1D_wave_scale_linear); + + cpl_size half_win = 1; + + /* Test nulls */ + + hdrl_spectrum1D_compute_shift_xcorrelation( + NULL, NULL, half_win, CPL_FALSE); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D_compute_shift_xcorrelation( + NULL, absorption, half_win, CPL_FALSE); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D_compute_shift_xcorrelation( + gaussian, NULL, half_win, CPL_FALSE); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D_compute_shift_xcorrelation( + gaussian, absorption, half_win, CPL_FALSE); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + + hdrl_spectrum1D_delete(&gaussian); + hdrl_spectrum1D_delete(&absorption); + cpl_array_delete(wlenghts); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of spectrum shift estimation module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + test_on_slope(); + test_on_peak(); + + test_compute_shift_xcorrelation(); + + return cpl_test_end(0); +} + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_spectrum1d-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_spectrum1d-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_spectrum1d-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_spectrum1d-test.c 2017-09-14 11:57:22.000000000 +0000 @@ -0,0 +1,3410 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2017 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_spectrum.h" +#include "hdrl_spectrumlist.h" +#include "hdrl_spectrum_resample.h" +#include "hdrl_DER_SNR.h" + +#include +#include +#include +#include + +#define LENGTH_ARRAY(a) ((cpl_size)(sizeof((a))/sizeof((a[0])))) + +static inline cpl_image * get_random_1d_img(cpl_size length, + double min, double max, cpl_type type); + +static inline void set_1d_bpm(cpl_image * img); + +static inline cpl_array * get_wavelength(cpl_size length, cpl_type type); + +static inline cpl_boolean are_hdrl_eq(const hdrl_image* flux_compound, + const cpl_image * flux, const cpl_image * flux_e); + +static inline cpl_error_code get_error_code_and_reset(); + +static inline double rand_0_to_1(); + +static inline hdrl_spectrum1D * +get_random_spectrum(int length, hdrl_spectrum1D_wave_scale scale); + +typedef hdrl_spectrum1D * (* operate_spectra_create) + (const hdrl_spectrum1D * self, + const hdrl_spectrum1D * other); + +typedef cpl_error_code (* operate_spectra)(hdrl_spectrum1D * self, + const hdrl_spectrum1D * other); + +static inline void test_error_create_func(const hdrl_spectrum1D * s1, + const hdrl_spectrum1D * s2, operate_spectra_create f); + +static inline void +test_calc_creat_error(operate_spectra_create f); + +static inline void test_calc_error(operate_spectra f); + +static inline hdrl_spectrum1D * get_spectrum1D_sin_shuffled +(cpl_size sz, int start, cpl_boolean add_peak, cpl_array ** unshuffled_lambda); + +typedef struct{ + double lambda_min; + double lambda_max; + cpl_boolean is_internal; +}sel_window; + +hdrl_spectrum1D * select_window(hdrl_spectrum1D * s, const sel_window w){ + + cpl_bivector * vec = cpl_bivector_new(1); + + cpl_vector_set(cpl_bivector_get_x(vec), 0, w.lambda_min); + cpl_vector_set(cpl_bivector_get_y(vec), 0, w.lambda_max); + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_select_wavelengths(s, vec, w.is_internal); + cpl_bivector_delete(vec); + + return to_ret; +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D constructors + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_constructor(cpl_type type){ + + const cpl_size sz = 40; + cpl_image * spectrum1d = get_random_1d_img(sz, 0.0f, 128.0f, type); + cpl_image * spectrum1d_error = get_random_1d_img(sz, 0.0f, 1.0f,type); + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(sz,type); + + /* test when passing error array */ + hdrl_spectrum1D * spec; + + spec = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_eq(hdrl_spectrum1D_get_size(spec), 40); + cpl_boolean are_equal = are_hdrl_eq( + hdrl_spectrum1D_get_flux(spec), spectrum1d, spectrum1d_error + ); + cpl_test_eq(are_equal, CPL_TRUE); + + hdrl_spectrum1D_delete(&spec); + cpl_test_null(spec); + + const cpl_size wn = 10; + + /* test when using DER SNR error*/ + spec = hdrl_spectrum1D_create_error_DER_SNR( + spectrum1d, wn, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + cpl_test_nonnull(spec); + + /*some casting to make sure that we are always using hdrl_data_t types*/ + cpl_image * flux_casted = cpl_image_cast(spectrum1d, HDRL_TYPE_DATA); + const hdrl_data_t * flux = + (const hdrl_data_t *) cpl_image_get_data_const(flux_casted); + const cpl_mask *msk_in = cpl_image_get_bpm_const(flux_casted); + const cpl_binary *msk_bn = cpl_mask_get_data_const(msk_in); + + cpl_image * noise = estimate_noise_DER_SNR(flux, msk_bn, wavelengths, + sz, wn); + + cpl_image_delete(flux_casted); + + cpl_mask * msk = cpl_image_unset_bpm(noise); + cpl_mask_delete(cpl_image_set_bpm(spectrum1d, msk)); + + { + hdrl_spectrum1D * spec2 = hdrl_spectrum1D_create( + spectrum1d, noise, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + const cpl_image * flux2 = + hdrl_image_get_image_const(hdrl_spectrum1D_get_flux(spec2)); + + const cpl_image * flux2_e = + hdrl_image_get_error_const(hdrl_spectrum1D_get_flux(spec2)); + + cpl_boolean are_equal2 = + are_hdrl_eq(hdrl_spectrum1D_get_flux(spec), flux2, flux2_e); + cpl_test_eq(are_equal2, CPL_TRUE); + + hdrl_spectrum1D_delete(&spec2); + cpl_test_null(spec2); + } + + hdrl_spectrum1D_delete(&spec); + cpl_test_null(spec); + + spec = hdrl_spectrum1D_create_error_free( + spectrum1d, wavelengths, hdrl_spectrum1D_wave_scale_linear); + cpl_test_nonnull(spec); + + cpl_size not_rej = 0; + for(cpl_size i = 0; i < sz; ++i){ + int rej; + const hdrl_value v = hdrl_spectrum1D_get_flux_value(spec, i, &rej); + if(rej) continue; + cpl_test_eq(v.error, 0.0); + not_rej ++; + } + cpl_test(not_rej > 0); + + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d); + cpl_image_delete(noise); + cpl_image_delete(spectrum1d_error); + + hdrl_spectrum1D_delete(&spec); + cpl_test_null(spec); + + /* deleting a nullptr should be NOOP */ + hdrl_spectrum1D_delete(&spec); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D analytical + constructors + */ +/*----------------------------------------------------------------------------*/ + +hdrl_value test_val(hdrl_data_t lambda){ + return (hdrl_value){lambda * 2.0, lambda *3.0}; +} + +void test_spectrum1D_constructor_analytical(void){ + + cpl_size sz = 10; + cpl_array * wav = cpl_array_new(sz, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < sz; i++){ + cpl_array_set(wav, i, (1 + i) * 10.0); + } + + hdrl_spectrum1D * spec = hdrl_spectrum1D_create_analytic + (test_val, wav, hdrl_spectrum1D_wave_scale_linear); + + for(cpl_size i = 0; i < sz; i++){ + + hdrl_value v = hdrl_spectrum1D_get_flux_value(spec, i, NULL); + + cpl_test_abs(v.data, (1 + i) * 20.0, 1e-3); + cpl_test_abs(v.error, (1 + i) * 30.0, 1e-3); + + hdrl_data_t ws = hdrl_spectrum1D_get_wavelength_value(spec, i, NULL); + hdrl_data_t ww = cpl_array_get(wav, i, NULL); + cpl_test_abs(ws, ww, 1e-3); + } + + cpl_test_eq(hdrl_spectrum1D_wave_scale_linear, + hdrl_spectrum1D_get_scale(spec)); + + cpl_array_delete(wav); + hdrl_spectrum1D_delete(&spec); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D constructors + errors + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_constructor_error(void){ + + cpl_image * spectrum1d_40 = + get_random_1d_img(40, 0.0f, 128.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d_error_40 = + get_random_1d_img(40, 0.0f, 1.0f,CPL_TYPE_DOUBLE); + set_1d_bpm(spectrum1d_40); + cpl_array * wavelengths_40 = get_wavelength(40,CPL_TYPE_DOUBLE); + + cpl_image * spectrum1d_42 = + get_random_1d_img(42, 0.0f, 128.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d_error_42 = + get_random_1d_img(42, 0.0f, 1.0f,CPL_TYPE_DOUBLE); + set_1d_bpm(spectrum1d_42); + cpl_array * wavelengths_42 = get_wavelength(42,CPL_TYPE_DOUBLE); + + hdrl_spectrum1D * spec = hdrl_spectrum1D_create(NULL, NULL, + wavelengths_40, + hdrl_spectrum1D_wave_scale_linear); + + cpl_test_null(spec); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D_delete(&spec); + + spec = hdrl_spectrum1D_create(spectrum1d_40, NULL, + NULL, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_null(spec); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D_delete(&spec); + + spec = hdrl_spectrum1D_create(spectrum1d_40, spectrum1d_error_42, + wavelengths_40, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_null(spec); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_INCOMPATIBLE_INPUT); + + spec = hdrl_spectrum1D_create(spectrum1d_42, spectrum1d_error_40, + wavelengths_40, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_null(spec); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_INCOMPATIBLE_INPUT); + + spec = hdrl_spectrum1D_create(spectrum1d_40, spectrum1d_error_40, + wavelengths_42, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_null(spec); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_INCOMPATIBLE_INPUT); + + double el0 = cpl_array_get(wavelengths_40, 0, NULL); + cpl_array_set(wavelengths_40, 1, el0); + + spec = hdrl_spectrum1D_create(spectrum1d_40, spectrum1d_error_40, + wavelengths_40, hdrl_spectrum1D_wave_scale_linear); + cpl_test_nonnull(spec); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_NONE); + + hdrl_spectrum1D_delete(&spec); + + cpl_array_delete(wavelengths_40); + cpl_image_delete(spectrum1d_40); + cpl_image_delete(spectrum1d_error_40); + + cpl_array_delete(wavelengths_42); + cpl_image_delete(spectrum1d_42); + cpl_image_delete(spectrum1d_error_42); +} + + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D constructors + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_duplication(void){ + + cpl_image * spectrum1d = + get_random_1d_img(140, 0.0f, 128.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d_error = + get_random_1d_img(140, 0.0f, 1.0f,CPL_TYPE_DOUBLE); + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(140, CPL_TYPE_DOUBLE); + + hdrl_spectrum1D * spec = hdrl_spectrum1D_create( + spectrum1d, NULL, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * spec_copy = hdrl_spectrum1D_duplicate(spec); + + hdrl_spectrum1D_delete(&spec); + hdrl_spectrum1D_delete(&spec_copy); + + /*Issues with NULL?*/ + hdrl_spectrum1D * should_be_null = hdrl_spectrum1D_duplicate(NULL); + cpl_test_null(should_be_null); + + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d); + cpl_image_delete(spectrum1d_error); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D constructors + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_calculation_scalar(void){ + + cpl_image * spectrum1d = + get_random_1d_img(40, 0.0f, 128.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d_error = + get_random_1d_img(40, 0.0f, 1.0f, CPL_TYPE_DOUBLE); + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(40, CPL_TYPE_DOUBLE); + + cpl_image_set(spectrum1d, 3, 1, 5.0); + cpl_image_set(spectrum1d_error, 3, 1, 2.1); + + hdrl_spectrum1D * spec = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_value vs = {1.5, 0.3}; + + hdrl_spectrum1D * spec_copy = hdrl_spectrum1D_mul_scalar_create(spec, vs); + hdrl_spectrum1D_mul_scalar(spec, vs); + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).data, + 7.5, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).error, + 3.4889, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).data, + 7.5, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).error, + 3.4889, 1e-3); + hdrl_spectrum1D_delete(&spec_copy); + + spec_copy = hdrl_spectrum1D_div_scalar_create(spec, vs); + hdrl_spectrum1D_div_scalar(spec, vs); + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).data, + 5.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).error, + 2.53179, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy , 2, NULL).data, + 5.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy , 2, NULL).error, + 2.53179, 1e-3); + hdrl_spectrum1D_delete(&spec_copy); + + spec_copy = hdrl_spectrum1D_add_scalar_create(spec, vs); + hdrl_spectrum1D_add_scalar(spec, vs); + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).data, + 6.5, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).error, + 2.54951, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).data, + 6.5, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).error, + 2.54951, 1e-3); + hdrl_spectrum1D_delete(&spec_copy); + + spec_copy = hdrl_spectrum1D_sub_scalar_create(spec, vs); + hdrl_spectrum1D_sub_scalar(spec, vs); + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).data, + 5.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).error, + 2.5671, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).data, + 5.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).error, + 2.5671, 1e-3); + hdrl_spectrum1D_delete(&spec_copy); + + vs.data = 2.0; + spec_copy = hdrl_spectrum1D_pow_scalar_create(spec, vs); + hdrl_spectrum1D_pow_scalar(spec, vs); + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).data, + pow(5.0, 2.0), 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).error, + 28.3673, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).data, + pow(5.0, 2.0), 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).error, + 28.3673, 1e-3); + hdrl_spectrum1D_delete(&spec_copy); + + hdrl_spectrum1D_delete(&spec); + spec = hdrl_spectrum1D_create(spectrum1d, spectrum1d_error, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + vs.data = 2.0; + vs.error = 0.2; + spec_copy = hdrl_spectrum1D_exp_scalar_create(spec, vs); + hdrl_spectrum1D_exp_scalar(spec, vs); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).data, + pow(2.0, 5.0), 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec, 2, NULL).error, + 49.25087754, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).data, + pow(2.0, 5.0), 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(spec_copy, 2, NULL).error, + 49.25087754, 1e-3); + hdrl_spectrum1D_delete(&spec_copy); + + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d); + cpl_image_delete(spectrum1d_error); + hdrl_spectrum1D_delete(&spec); + + + /* Issues with NULL */ + hdrl_value v = {100.0, 5.0}; + cpl_test_null(hdrl_spectrum1D_sub_scalar_create(NULL, v)); + cpl_test_null(hdrl_spectrum1D_add_scalar_create(NULL, v)); + cpl_test_null(hdrl_spectrum1D_div_scalar_create(NULL, v)); + cpl_test_null(hdrl_spectrum1D_mul_scalar_create(NULL, v)); + cpl_test_null(hdrl_spectrum1D_pow_scalar_create(NULL, v)); + cpl_test_null(hdrl_spectrum1D_exp_scalar_create(NULL, v)); + + cpl_test_eq(hdrl_spectrum1D_sub_scalar(NULL, v), CPL_ERROR_NONE); + cpl_test_eq(hdrl_spectrum1D_add_scalar(NULL, v), CPL_ERROR_NONE); + cpl_test_eq(hdrl_spectrum1D_div_scalar(NULL, v), CPL_ERROR_NONE); + cpl_test_eq(hdrl_spectrum1D_mul_scalar(NULL, v), CPL_ERROR_NONE); + cpl_test_eq(hdrl_spectrum1D_pow_scalar(NULL, v), CPL_ERROR_NONE); + cpl_test_eq(hdrl_spectrum1D_exp_scalar(NULL, v), CPL_ERROR_NONE); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D calculation + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_calculation(void){ + + cpl_image * spectrum1d1 = + get_random_1d_img(40, 1.0f, 128.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d2 = + get_random_1d_img(40, 1.0f, 128.0f, CPL_TYPE_DOUBLE); + + cpl_image * spectrum1d_error1 = + get_random_1d_img(40, 0.5f, 2.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d_error2 = + get_random_1d_img(40, 0.5f, 2.0f, CPL_TYPE_DOUBLE); + set_1d_bpm(spectrum1d1); + cpl_array * wavelengths = get_wavelength(40, CPL_TYPE_DOUBLE); + + cpl_image_set(spectrum1d1, 15, 1, 8.0); + cpl_image_set(spectrum1d2, 15, 1, 4.0); + cpl_image_set(spectrum1d_error1, 15, 1, 2.0); + cpl_image_set(spectrum1d_error2, 15, 1, 1.0); + + hdrl_spectrum1D * s1 = hdrl_spectrum1D_create( + spectrum1d1, spectrum1d_error1, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * s2 = hdrl_spectrum1D_create( + spectrum1d2, spectrum1d_error2, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s1, 14, NULL).data, 8.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s2, 14, NULL).data, 4.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s1, 14, NULL).error, 2.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s2, 14, NULL).error, 1.0, 1e-3); + + hdrl_spectrum1D * s3 = hdrl_spectrum1D_div_spectrum_create(s1, s2); + hdrl_spectrum1D * s4 = hdrl_spectrum1D_duplicate(s1); + hdrl_spectrum1D_div_spectrum(s4, s2); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).data, 2.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).error, + 0.707107, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).data, 2.0,1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).error, + 0.707107, 1e-3); + hdrl_spectrum1D_delete(&s3); + hdrl_spectrum1D_delete(&s4); + + s3 = hdrl_spectrum1D_mul_spectrum_create(s1, s2); + s4 = hdrl_spectrum1D_duplicate(s1); + hdrl_spectrum1D_mul_spectrum(s4, s2); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).data, + 32.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).error, + 11.3137, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).data, + 32.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).error, + 11.3137, 1e-3); + hdrl_spectrum1D_delete(&s3); + hdrl_spectrum1D_delete(&s4); + + + s3 = hdrl_spectrum1D_sub_spectrum_create(s1, s2); + s4 = hdrl_spectrum1D_duplicate(s1); + hdrl_spectrum1D_sub_spectrum(s4, s2); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).data, 4.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).error, 2.23607, + 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).data, 4.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).error, 2.23607, + 1e-3); + hdrl_spectrum1D_delete(&s3); + hdrl_spectrum1D_delete(&s4); + + s3 = hdrl_spectrum1D_add_spectrum_create(s1, s2); + s4 = hdrl_spectrum1D_duplicate(s1); + hdrl_spectrum1D_add_spectrum(s4, s2); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).data, 12.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s3, 14, NULL).error, 2.23607, + 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).data, 12.0, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(s4, 14, NULL).error, 2.23607, + 1e-3); + hdrl_spectrum1D_delete(&s3); + hdrl_spectrum1D_delete(&s4); + + hdrl_spectrum1D_delete(&s1); + hdrl_spectrum1D_delete(&s2); + + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d1); + cpl_image_delete(spectrum1d2); + cpl_image_delete(spectrum1d_error1); + cpl_image_delete(spectrum1d_error2); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D calculation + error conditions + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_calculation_error(void){ + + test_calc_creat_error(hdrl_spectrum1D_div_spectrum_create); + test_calc_creat_error(hdrl_spectrum1D_add_spectrum_create); + test_calc_creat_error(hdrl_spectrum1D_sub_spectrum_create); + test_calc_creat_error(hdrl_spectrum1D_mul_spectrum_create); + + test_calc_error(hdrl_spectrum1D_div_spectrum); + test_calc_error(hdrl_spectrum1D_add_spectrum); + test_calc_error(hdrl_spectrum1D_sub_spectrum); + test_calc_error(hdrl_spectrum1D_mul_spectrum); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D wavelength + calculation + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_conversion_wavelength_scale(void){ + + cpl_image * spectrum1d = + get_random_1d_img(40, 1.0f, 128.0f, CPL_TYPE_DOUBLE); + + cpl_image * spectrum1d_error1 = + get_random_1d_img(40, 0.5f, 2.0f, CPL_TYPE_DOUBLE); + + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(40, CPL_TYPE_DOUBLE); + + hdrl_spectrum1D * sp = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error1, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_data_t w1 = cpl_array_get(wavelengths, 4, NULL); + hdrl_data_t w2 = cpl_array_get(wavelengths, 6, NULL); + + hdrl_spectrum1D * s_lg = + hdrl_spectrum1D_wavelength_convert_to_log_create(sp); + hdrl_spectrum1D_wavelength w_lg = + hdrl_spectrum1D_get_wavelength(s_lg); + + cpl_test_eq(w_lg.scale, hdrl_spectrum1D_wave_scale_log); + + cpl_test_abs(log(w1), cpl_array_get(w_lg.wavelength, 4, NULL), 1e-3); + cpl_test_abs(log(w2), cpl_array_get(w_lg.wavelength, 6, NULL), 1e-3); + + hdrl_spectrum1D * s_lin = + hdrl_spectrum1D_wavelength_convert_to_linear_create(s_lg); + hdrl_spectrum1D_wavelength w_lin = hdrl_spectrum1D_get_wavelength(s_lin); + cpl_test_eq(w_lin.scale, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_abs(w1, cpl_array_get(w_lin.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2, cpl_array_get(w_lin.wavelength, 6, NULL), 1e-3); + + /*conversions on functions already in the right scale should behave like a + * duplicate*/ + + hdrl_spectrum1D * s_lg2 = + hdrl_spectrum1D_wavelength_convert_to_log_create(s_lg); + hdrl_spectrum1D_wavelength w_lg2 = hdrl_spectrum1D_get_wavelength(s_lg); + cpl_test_eq(w_lg2.scale, hdrl_spectrum1D_wave_scale_log); + cpl_test_noneq_ptr(s_lg2, s_lg); + + hdrl_spectrum1D * s_lin2 = + hdrl_spectrum1D_wavelength_convert_to_log_create(s_lin); + hdrl_spectrum1D_wavelength w_lin2 = hdrl_spectrum1D_get_wavelength(s_lin); + cpl_test_eq(w_lin2.scale, hdrl_spectrum1D_wave_scale_linear); + cpl_test_noneq_ptr(s_lin2, s_lin); + + hdrl_spectrum1D_delete(&s_lg); + hdrl_spectrum1D_delete(&s_lg2); + hdrl_spectrum1D_delete(&s_lin); + hdrl_spectrum1D_delete(&s_lin2); + + /* Mutator functions */ + + /* linear -> log */ + cpl_error_code e = hdrl_spectrum1D_wavelength_convert_to_log(sp); + cpl_test_eq(e, CPL_ERROR_NONE); + + hdrl_spectrum1D_wavelength sp_w_lg = hdrl_spectrum1D_get_wavelength(sp); + + cpl_test_eq(sp_w_lg.scale, hdrl_spectrum1D_wave_scale_log); + cpl_test_abs(log(w1), cpl_array_get(sp_w_lg.wavelength, 4, NULL), 1e-3); + cpl_test_abs(log(w2), cpl_array_get(sp_w_lg.wavelength, 6, NULL), 1e-3); + + /* log -> log NOOP*/ + e = hdrl_spectrum1D_wavelength_convert_to_log(sp); + cpl_test_eq(e, CPL_ERROR_NONE); + + sp_w_lg = hdrl_spectrum1D_get_wavelength(sp); + + cpl_test_eq(sp_w_lg.scale, hdrl_spectrum1D_wave_scale_log); + cpl_test_abs(log(w1), cpl_array_get(sp_w_lg.wavelength, 4, NULL), 1e-3); + cpl_test_abs(log(w2), cpl_array_get(sp_w_lg.wavelength, 6, NULL), 1e-3); + + /* log -> linear */ + e = hdrl_spectrum1D_wavelength_convert_to_linear(sp); + cpl_test_eq(e, CPL_ERROR_NONE); + + hdrl_spectrum1D_wavelength sp_w_lin = hdrl_spectrum1D_get_wavelength(sp); + cpl_test_eq(sp_w_lin.scale, hdrl_spectrum1D_wave_scale_linear); + cpl_test_abs(w1, cpl_array_get(sp_w_lin.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2, cpl_array_get(sp_w_lin.wavelength, 6, NULL), 1e-3); + + /* linear -> linear NOOP*/ + e = hdrl_spectrum1D_wavelength_convert_to_linear(sp); + cpl_test_eq(e, CPL_ERROR_NONE); + + sp_w_lin = hdrl_spectrum1D_get_wavelength(sp); + cpl_test_eq(sp_w_lin.scale, hdrl_spectrum1D_wave_scale_linear); + cpl_test_abs(w1, cpl_array_get(sp_w_lin.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2, cpl_array_get(sp_w_lin.wavelength, 6, NULL), 1e-3); + + hdrl_spectrum1D_delete(&sp); + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d_error1); + cpl_image_delete(spectrum1d); + + /* Test for null */ + + cpl_test_eq(hdrl_spectrum1D_wavelength_convert_to_linear(NULL), + CPL_ERROR_NONE); + cpl_test_eq(hdrl_spectrum1D_wavelength_convert_to_log(NULL), + CPL_ERROR_NONE); + + cpl_test_null(hdrl_spectrum1D_wavelength_convert_to_linear_create(NULL)); + cpl_test_null(hdrl_spectrum1D_wavelength_convert_to_log_create(NULL)); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D wavelength + calculation + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_mul_wavelength(void){ + + cpl_image * spectrum1d = + get_random_1d_img(40, 1.0f, 128.0f, CPL_TYPE_DOUBLE); + + cpl_image * spectrum1d_error1 = + get_random_1d_img(40, 0.5f, 2.0f, CPL_TYPE_DOUBLE); + + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(40, CPL_TYPE_DOUBLE); + + hdrl_spectrum1D * sp = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error1, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_data_t w1 = cpl_array_get(wavelengths, 4, NULL); + hdrl_data_t w2 = cpl_array_get(wavelengths, 6, NULL); + + /* mutator functions */ + + cpl_error_code e = hdrl_spectrum1D_wavelength_mult_scalar_linear(sp, 1e3); + cpl_test_eq(e, CPL_ERROR_NONE); + + hdrl_spectrum1D_wavelength sp_mul_1e3 = hdrl_spectrum1D_get_wavelength(sp); + + cpl_test_abs(w1 * 1e3, cpl_array_get(sp_mul_1e3.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2 * 1e3, cpl_array_get(sp_mul_1e3.wavelength, 6, NULL), 1e-3); + + e = hdrl_spectrum1D_wavelength_mult_scalar_linear(sp, 1e-3); + cpl_test_eq(e, CPL_ERROR_NONE); + + hdrl_spectrum1D_wavelength_convert_to_log(sp); + + e = hdrl_spectrum1D_wavelength_mult_scalar_linear(sp, 1e3); + cpl_test_eq(e, CPL_ERROR_NONE); + + hdrl_spectrum1D_wavelength sp_mul_log = hdrl_spectrum1D_get_wavelength(sp); + + cpl_test_abs(log(w1 * 1e3), cpl_array_get(sp_mul_log.wavelength, 4, NULL), + 1e-3); + cpl_test_abs(log(w2 * 1e3), cpl_array_get(sp_mul_log.wavelength, 6, NULL), + 1e-3); + + /* non mutator functions */ + hdrl_spectrum1D_delete(&sp); + + sp = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error1, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * sp_lin = + hdrl_spectrum1D_wavelength_mult_scalar_linear_create(sp, 1e-4); + hdrl_spectrum1D_wavelength_convert_to_log(sp); + hdrl_spectrum1D * sp_log = + hdrl_spectrum1D_wavelength_mult_scalar_linear_create(sp, 1e-4); + hdrl_spectrum1D_delete(&sp); + + sp_mul_1e3 = hdrl_spectrum1D_get_wavelength(sp_lin); + sp_mul_log = hdrl_spectrum1D_get_wavelength(sp_log); + + cpl_test_abs(w1 * 1e-4, cpl_array_get(sp_mul_1e3.wavelength, 4, NULL), 1e-6); + cpl_test_abs(w2 * 1e-4, cpl_array_get(sp_mul_1e3.wavelength, 6, NULL), 1e-6); + + cpl_test_abs( + log(w1 * 1e-4), cpl_array_get(sp_mul_log.wavelength, 4, NULL), 1e-6); + cpl_test_abs( + log(w2 * 1e-4), cpl_array_get(sp_mul_log.wavelength, 6, NULL), 1e-6); + + cpl_test_noneq(hdrl_spectrum1D_wavelength_mult_scalar_linear(sp_log, -2.0), + CPL_ERROR_NONE); + cpl_test_noneq(get_error_code_and_reset(), CPL_ERROR_NONE); + + cpl_test_null( + hdrl_spectrum1D_wavelength_mult_scalar_linear_create(sp_log, -2.0)); + cpl_test_noneq(get_error_code_and_reset(), CPL_ERROR_NONE); + + hdrl_spectrum1D_delete(&sp_log); + hdrl_spectrum1D_delete(&sp_lin); + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d_error1); + cpl_image_delete(spectrum1d); + + cpl_test_eq(hdrl_spectrum1D_wavelength_mult_scalar_linear(NULL, 3.0), + CPL_ERROR_NONE); + cpl_test_null(hdrl_spectrum1D_wavelength_mult_scalar_linear_create(NULL, + 3.0)); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D wavelength shift + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_shift_wavelength(void){ + + cpl_image * spectrum1d = + get_random_1d_img(40, 1.0f, 128.0f, CPL_TYPE_DOUBLE); + + cpl_image * spectrum1d_error1 = + get_random_1d_img(40, 0.5f, 2.0f, CPL_TYPE_DOUBLE); + + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(40, CPL_TYPE_DOUBLE); + + hdrl_data_t w1 = cpl_array_get(wavelengths, 4, NULL); + hdrl_data_t w2 = cpl_array_get(wavelengths, 6, NULL); + + hdrl_spectrum1D * sp1 = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error1, + wavelengths, hdrl_spectrum1D_wave_scale_linear); + + hdrl_spectrum1D * sp2 = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error1, + wavelengths, hdrl_spectrum1D_wave_scale_log); + + /* shift works in the same way both for linear and log scale */ + cpl_error_code err = hdrl_spectrum1D_wavelength_shift(sp1, 3.0); + cpl_test_eq(err, CPL_ERROR_NONE); + + err = hdrl_spectrum1D_wavelength_shift(sp2, -3.0); + cpl_test_eq(err, CPL_ERROR_NONE); + + hdrl_spectrum1D_wavelength sp_p_3 = hdrl_spectrum1D_get_wavelength(sp1); + hdrl_spectrum1D_wavelength sp_m_3 = hdrl_spectrum1D_get_wavelength(sp2); + + cpl_test_abs(w1 + 3.0, cpl_array_get(sp_p_3.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2 + 3.0, cpl_array_get(sp_p_3.wavelength, 6, NULL), 1e-3); + + cpl_test_abs(w1 - 3.0, cpl_array_get(sp_m_3.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2 - 3.0, cpl_array_get(sp_m_3.wavelength, 6, NULL), 1e-3); + + hdrl_spectrum1D* sp_new_1 = + hdrl_spectrum1D_wavelength_shift_create(sp1, -3.0); + hdrl_spectrum1D* sp_new_2 = + hdrl_spectrum1D_wavelength_shift_create(sp2, 3.0); + + hdrl_spectrum1D_delete(&sp1); + hdrl_spectrum1D_delete(&sp2); + + hdrl_spectrum1D_wavelength sp_n_1_w = + hdrl_spectrum1D_get_wavelength(sp_new_1); + hdrl_spectrum1D_wavelength sp_n_2_w = + hdrl_spectrum1D_get_wavelength(sp_new_2); + + cpl_test_abs(w1, cpl_array_get(sp_n_1_w.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2, cpl_array_get(sp_n_1_w.wavelength, 6, NULL), 1e-3); + cpl_test_abs(w1, cpl_array_get(sp_n_2_w.wavelength, 4, NULL), 1e-3); + cpl_test_abs(w2, cpl_array_get(sp_n_2_w.wavelength, 6, NULL), 1e-3); + + hdrl_spectrum1D_delete(&sp_new_1); + hdrl_spectrum1D_delete(&sp_new_2); + + /* Issues with NULL? */ + err = hdrl_spectrum1D_wavelength_shift(NULL, 3.0); + cpl_test_eq(err, CPL_ERROR_NONE); + hdrl_spectrum1D * should_be_null = + hdrl_spectrum1D_wavelength_shift_create(NULL, 3.0); + cpl_test_null(should_be_null); + + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d_error1); + cpl_image_delete(spectrum1d); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D table conversions + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_table_conversion(void){ + + const cpl_size sz_ori = 17; + cpl_array * unshuffled_lambda = NULL; + hdrl_spectrum1D * sp1 = get_spectrum1D_sin_shuffled(sz_ori, 2, CPL_TRUE, + &unshuffled_lambda); + cpl_array_delete(unshuffled_lambda); + + cpl_table * tab = hdrl_spectrum1D_convert_to_table(sp1, "flux", + "lambdas", "flux_e", "flux_bpm"); + + /*ad rejected pixels*/ + cpl_table_set_int(tab, "flux_bpm", 0, 1); + cpl_table_set_int(tab, "flux_bpm", sz_ori - 1, 1); + + hdrl_spectrum1D * sp2 = hdrl_spectrum1D_convert_from_table + (tab, "flux", "lambdas", "flux_e", "flux_bpm", + hdrl_spectrum1D_wave_scale_linear); + + const cpl_image * flux1 = + hdrl_image_get_image_const(hdrl_spectrum1D_get_flux(sp1)); + const cpl_image * flux1_e = + hdrl_image_get_error_const(hdrl_spectrum1D_get_flux(sp1)); + + const cpl_array * lambdas1 = hdrl_spectrum1D_get_wavelength(sp1).wavelength; + + const cpl_image * flux2 = + hdrl_image_get_image_const(hdrl_spectrum1D_get_flux(sp2)); + const cpl_image * flux2_e = + hdrl_image_get_error_const(hdrl_spectrum1D_get_flux(sp2)); + const cpl_array * lambdas2 = hdrl_spectrum1D_get_wavelength(sp2).wavelength; + + const cpl_size sz_x = cpl_image_get_size_x(flux1); + const cpl_size sz_y = cpl_image_get_size_y(flux1); + const cpl_size sz = cpl_array_get_size(lambdas1); + + cpl_test_eq(sz_x, cpl_image_get_size_x(flux2)); + cpl_test_eq(sz_y, cpl_image_get_size_y(flux2)); + cpl_test_eq(sz, cpl_array_get_size(lambdas2)); + + for(cpl_size i = 1; i < sz - 1; i++){ + + int rej1 = 0; + int rej2 = 0; + const double flx1 = cpl_image_get(flux1, i + 1, 1, &rej1); + const double flx2 = cpl_image_get(flux2, i + 1, 1, &rej2); + + + cpl_test_abs(flx1, flx2, 1e-3); + cpl_test_eq(rej1, rej2); + rej1 = rej2 = 0; + + const double flx1_e = cpl_image_get(flux1_e, i + 1, 1, &rej1); + const double flx2_e = cpl_image_get(flux2_e, i + 1, 1, &rej2); + + cpl_test_abs(flx1_e, flx2_e, 1e-3); + cpl_test_eq(rej1, rej2); + rej1 = rej2 = 0; + + + const double l1 = cpl_array_get(lambdas1, i, &rej1); + const double l2 = cpl_array_get(lambdas2, i, &rej2); + + cpl_test_abs(l1, l2, 1e-3); + cpl_test_eq(rej1, rej2); + } + + cpl_test(cpl_image_is_rejected(flux2, 1, 1)); + cpl_test(cpl_image_is_rejected(flux2, sz_ori, 1)); + + + hdrl_spectrum1D_append_to_table(sp2, tab, + "flux2", "lambdas2", NULL, "flux2_bpm"); + + for(cpl_size i = 0; i < sz; i++){ + + int rej = 0; + + const int bpm1 = cpl_table_get_int(tab, "flux_bpm", i, &rej); + const int bpm2 = cpl_table_get_int(tab, "flux2_bpm", i, &rej); + cpl_test_eq(bpm1, bpm2); + + if(bpm1) continue; + + const double flx1 = cpl_table_get(tab, "flux", i, &rej); + const double flx2 = cpl_table_get(tab, "flux2", i, &rej); + cpl_test_abs(flx1, flx2, 1e-3); + + const double l1 = cpl_table_get(tab, "lambdas", i, &rej); + const double l2 = cpl_table_get(tab, "lambdas2", i, &rej); + cpl_test_abs(l1, l2, 1e-3); + } + + hdrl_spectrum1D_delete(&sp2); + sp2 = hdrl_spectrum1D_convert_from_table + (tab, "flux", "lambdas", NULL, NULL, + hdrl_spectrum1D_wave_scale_linear); + + /* Check save */ + const char* filename = "check_spectrum1D.fits"; + hdrl_spectrum1D_save(sp2, filename); + remove(filename); + + for(cpl_size i = 0; i < hdrl_spectrum1D_get_size(sp2); ++i){ + int rej; + + const double fx1 = hdrl_spectrum1D_get_flux_value(sp1, i, &rej).data; + + const double fx2 = hdrl_spectrum1D_get_flux_value(sp2, i, &rej).data; + const double fx2_e = hdrl_spectrum1D_get_flux_value(sp2, i, &rej).error; + + cpl_test_eq(fx2_e, 0.0); + cpl_test_abs(fx1, fx2, 1e-3); + } + + hdrl_spectrum1D_delete(&sp2); + cpl_table_delete(tab); + + cpl_table * f_only = + hdrl_spectrum1D_convert_to_table(sp1, "flux", NULL, NULL, NULL); + cpl_table * l_only = + hdrl_spectrum1D_convert_to_table(sp1, NULL, "wav", NULL, NULL); + cpl_table * f_and_e = + hdrl_spectrum1D_convert_to_table(sp1, "flux", NULL, "error", NULL); + + for(cpl_size i = 0; i < hdrl_spectrum1D_get_size(sp1); ++i){ + const double f = hdrl_spectrum1D_get_flux_value(sp1, i, NULL).data; + const double e = hdrl_spectrum1D_get_flux_value(sp1, i, NULL).error; + const double w = hdrl_spectrum1D_get_wavelength_value(sp1, i, NULL); + + const double f1 = cpl_table_get(f_only, "flux", i, NULL); + const double f2 = cpl_table_get(f_and_e, "flux", i, NULL); + cpl_test_eq(f, f1); + cpl_test_eq(f, f2); + + const double w1 = cpl_table_get(l_only, "wav", i, NULL); + cpl_test_eq(w, w1); + + const double e1 = cpl_table_get(f_and_e, "error", i, NULL); + cpl_test_eq(e, e1); + } + + + hdrl_spectrum1D_delete(&sp1); + cpl_table_delete(f_only); + cpl_table_delete(l_only); + cpl_table_delete(f_and_e); +} +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D resample + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_resample_spectrum(cpl_boolean add_peak){ + + /* Initialize variables */ + cpl_array * unshuffled_lambda = NULL; + hdrl_spectrum1D * sp = get_spectrum1D_sin_shuffled(17, 2, add_peak, &unshuffled_lambda); + + hdrl_spectrum1D_wavelength wl = hdrl_spectrum1D_get_wavelength(sp); + cpl_size sz = hdrl_spectrum1D_get_size(sp); + cpl_array * new_lambda = cpl_array_new(sz, HDRL_TYPE_DATA); + for(cpl_size i = 0; i < sz; i++){ + double d = cpl_array_get(unshuffled_lambda, i, NULL) + + cpl_array_get(unshuffled_lambda, CPL_MIN(sz - 1, i + 1), NULL); + cpl_array_set(new_lambda, i, d/2); + } + + wl.wavelength = new_lambda; + + + /* Tests variables */ + int rej; + hdrl_parameter *pars; + hdrl_spectrum1D *resampled_lambda; + + + /* Test 1 */ + pars = hdrl_spectrum1D_resample_fit_parameter_create(4, 17); + resampled_lambda = hdrl_spectrum1D_resample(sp, &wl, pars); + + const double data2_fit = add_peak ? 116.368 : 209.577; + const double data3_fit = add_peak ? 303.376 : 199.524; + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(resampled_lambda, 2, &rej).data, data2_fit, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(resampled_lambda, 3, &rej).data, data3_fit, 1e-3); + + hdrl_parameter_delete(pars); + hdrl_spectrum1D_delete(&resampled_lambda); + + + /* Test 2 */ + pars = hdrl_spectrum1D_resample_interpolate_parameter_create(hdrl_spectrum1D_interp_akima); + resampled_lambda = hdrl_spectrum1D_resample(sp, &wl, pars); + + const double data2_interp = add_peak ? 208.699 : 209.65; + const double data3_interp = add_peak ? 247.949 : 199.585; + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(resampled_lambda, 2, &rej).data, data2_interp, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(resampled_lambda, 3, &rej).data, data3_interp, 1e-3); + + hdrl_parameter_delete(pars); + hdrl_spectrum1D_delete(&resampled_lambda); + + + /* Test 3 */ + pars = hdrl_spectrum1D_resample_integrate_parameter_create(); + resampled_lambda = hdrl_spectrum1D_resample(sp, &wl, pars); + + const double data2_integrate = 207.878; + const double data3_integrate = add_peak ? 245.443 : 197.992; + + cpl_test_abs(hdrl_spectrum1D_get_flux_value(resampled_lambda, 2, &rej).data, data2_integrate, 1e-3); + cpl_test_abs(hdrl_spectrum1D_get_flux_value(resampled_lambda, 3, &rej).data, data3_integrate, 1e-3); + + hdrl_parameter_delete(pars); + hdrl_spectrum1D_delete(&resampled_lambda); + + + /* Clean up */ + hdrl_spectrum1D_delete(&sp); + cpl_array_delete(new_lambda); + cpl_array_delete(unshuffled_lambda); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Testing of the HDRL spectrum1D resample private + * functions + */ +/*----------------------------------------------------------------------------*/ + +void test_spectrum1D_resample_spectrum_private_funcs(void){ + + double testValue1 = 2.1; + double testValue2 = 3.5; + double testValue3 = 5.5; + + { + double x[] = {3, 2.1, 5.5, 8.7, 3.3, 5.6, 2.1}; + double y1[] = {11, 88, -22, 56, 4, 22, 23}; + double y2[] = { 2, 55, 2, 27, 23, 1, 5}; + + double x_sorted[] = {2.1, 2.1, 3, 3.3, 5.5, 5.6, 8.7}; + double y1_sorted[] = {88, 23, 11, 4, -22, 22, 56}; + double y2_sorted[] = {55, 5, 2, 23, 2, 1, 27}; + + const cpl_size l = LENGTH_ARRAY(x); + + hdrl_sort_on_x(x, y1, y2, l, CPL_FALSE); + + cpl_test_eq(x[0], testValue1); + cpl_test_eq(x[1], testValue1); + + /*test the case were x is duplicated.*/ + cpl_test(y1[1] != y1[0]); + cpl_test(y2[1] != y2[0]); + + for(cpl_size i = 2; i < l; ++i){ + cpl_test_eq(x[i], x_sorted[i]); + cpl_test_eq(y1[i], y1_sorted[i]); + cpl_test_eq(y2[i], y2_sorted[i]); + } + } + + { + double x[] = {3, 2.1, 5.5, 8.7, 3.3, 5.6, 2.1}; + double y2[] = { 2, 55, 2, 27, 23, 1, 5}; + + double x_sorted[] = {2.1, 2.1, 3, 3.3, 5.5, 5.6, 8.7}; + double y2_sorted[] = {55, 5, 2, 23, 2, 1, 27}; + + const cpl_size l = LENGTH_ARRAY(x); + + hdrl_sort_on_x(x, NULL, y2, l, CPL_FALSE); + + cpl_test_eq(x[0], testValue1); + cpl_test_eq(x[1], testValue1); + + cpl_test(y2[1] != y2[0]); + + for(cpl_size i = 2; i < l; ++i){ + cpl_test_eq(x[i], x_sorted[i]); + cpl_test_eq(y2[i], y2_sorted[i]); + } + } + + { + double x[] = {3, 2.1, 5.5, 8.7, 3.3, 5.6, 2.1}; + double y1[] = {11, 88, -22, 56, 4, 22, 23}; + + double x_sorted[] = {2.1, 2.1, 3, 3.3, 5.5, 5.6, 8.7}; + double y1_sorted[] = {88, 23, 11, 4, -22, 22, 56}; + + const cpl_size l = LENGTH_ARRAY(x); + + hdrl_sort_on_x(x, y1, NULL, l, CPL_FALSE); + + cpl_test_eq(x[0], testValue1); + cpl_test_eq(x[1], testValue1); + + /*test the case were x is duplicated.*/ + cpl_test(y1[1] != y1[0]); + + for(cpl_size i = 2; i < l; ++i){ + cpl_test_eq(x[i], x_sorted[i]); + cpl_test_eq(y1[i], y1_sorted[i]); + } + } + + /* test duplicates search and median */ + { + /* edge case, all x are equal, even number of samples*/ + double x[] = {1,1,1,1,1}; + double y1[] = {5,4,3,2,5}; + double y2[] = {8,7,5,2,6}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 1); + cpl_test_eq(x[0], 1); + cpl_test_eq(y1[0], 4); + cpl_test_eq(y2[0], 6); + } + + { + /* edge case, all x are equal, odd number of samples*/ + double x[] = {1,1,1,1,1,1}; + double y1[] = {5,4,3,2,5,2.5}; + double y2[] = {8,7,5,2,6,4.6}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 1); + cpl_test_eq(x[0], 1); + cpl_test_eq(y1[0], testValue2); + cpl_test_eq(y2[0], testValue3); + } + + /* test duplicates search and median */ + { + /* edge case, all x are equal, except the first, even number of samples*/ + double x[] = {1,2,2,2,2,2}; + double y1[] = {55,5,4,3,2,5}; + double y2[] = {88,8,7,5,2,6}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 2); + cpl_test_eq(x[1], 2); + cpl_test_eq(y1[1], 4); + cpl_test_eq(y2[1], 6); + cpl_test_eq(x[0], 1); + cpl_test_eq(y1[0], 55); + cpl_test_eq(y2[0], 88); + } + + { + /* edge case, all x are equal, except the last, odd number of samples*/ + double x[] = {1, 1, 1, 1, 1, 1, 8}; + double y1[] = {5, 4, 3, 2, 5, 2.5, 77}; + double y2[] = {8, 7, 5, 2, 6, 4.6, 96}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 2); + cpl_test_eq(x[0] , 1); + cpl_test_eq(y1[0], testValue2); + cpl_test_eq(y2[0], testValue3); + + cpl_test_eq(x[1] , 8); + cpl_test_eq(y1[1], 77); + cpl_test_eq(y2[1], 96); + } + + /*more realist case with hunks of equal elements*/ + { + { + double x[] = {1, 2, 2, 3, 3, 3, 5, 6, 7, 7, 8, 9, 10, 10, 10, 11}; + double y1[] = {4, 3, 7, 8, 9, 4, 3, 7, 2, 4, 5, 2, 8, 7, 1, 12}; + double y2[] = {3, 6, 7, 8, 4, 5, 8, 3, 5, 1, 3, 8, 44, 33, 55, 45}; + + double x_f[] = {1, 2, 3, 5, 6, 7, 8, 9, 10, 11}; + double y1_f[] = {4, 5, 8, 3, 7, 3, 5, 2, 7, 12}; + double y2_f[] = {3, 6.5, 5, 8, 3, 3, 3, 8, 44, 45}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 10); + + for(cpl_size i = 0; i < l; ++i){ + cpl_test_eq(x[i], x_f[i]); + cpl_test_eq(y1[i], y1_f[i]); + cpl_test_eq(y2[i], y2_f[i]); + } + } + } + + /*more realist case with hunks of equal elements, one hunk at the end*/ + { + { + double x[] = {1, 2, 2, 3, 3, 3, 5, 6, 7, 7, 8, 9, 10, 10, 10, 11, 11}; + double y1[] = {4, 3, 7, 8, 9, 4, 3, 7, 2, 4, 5, 2, 8, 7, 1, 12, 2}; + double y2[] = {3, 6, 7, 8, 4, 5, 8, 3, 5, 1, 3, 8, 44, 33, 55, 45, 5}; + + double x_f[] = {1, 2, 3, 5, 6, 7, 8, 9, 10, 11}; + double y1_f[] = {4, 5, 8, 3, 7, 3, 5, 2, 7, 7}; + double y2_f[] = {3, 6.5, 5, 8, 3, 3, 3, 8, 44, 25}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 10); + + for(cpl_size i = 0; i < l; ++i){ + cpl_test_eq(x[i], x_f[i]); + cpl_test_eq(y1[i], y1_f[i]); + cpl_test_eq(y2[i], y2_f[i]); + } + } + } + + /*more realist case with hunks of equal elements, one hunk at the beginning*/ + { + { + double x[] = {1, 1, 2, 2, 3, 3, 3, 5, 6, 7, 7, 8, 9, 10, 10, 10, 11}; + double y1[] = {5, 7, 3, 7, 8, 9, 4, 3, 7, 2, 4, 5, 2, 8, 7, 1, 12}; + double y2[] = {1, 3, 6, 7, 8, 4, 5, 8, 3, 5, 1, 3, 8, 44, 33, 55, 45}; + + double x_f[] = {1, 2, 3, 5, 6, 7, 8, 9, 10, 11}; + double y1_f[] = {6, 5, 8, 3, 7, 3, 5, 2, 7, 12}; + double y2_f[] = {2, 6.5, 5, 8, 3, 3, 3, 8, 44, 45}; + + cpl_size l = LENGTH_ARRAY(x); + + l = hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median + (x, y1, y2, l); + + cpl_test_eq(l, 10); + + for(cpl_size i = 0; i < l; ++i){ + cpl_test_eq(x[i], x_f[i]); + cpl_test_eq(y1[i], y1_f[i]); + cpl_test_eq(y2[i], y2_f[i]); + } + } + } +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test error calculation for resample based on + * interpolation + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_resample_spectrum_interpolation_error_test(void){ + + double y[] = { 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1}; + double y_e[] = {.1, .2, .3, .4, .5, .6, .7, .8, .9, 1, 1.1, 1.2, 1.3, 1.4}; + double x[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + + double x_r[] = + {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.9, 11.1, 12.2, 13.9}; + + cpl_size closer_idx[] = + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + + const cpl_size l = LENGTH_ARRAY(y); + const cpl_size l2 = LENGTH_ARRAY(x_r); + cpl_test_eq(LENGTH_ARRAY(y), LENGTH_ARRAY(y_e)); + cpl_test_eq(LENGTH_ARRAY(y), LENGTH_ARRAY(x)); + + cpl_image * flux = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_image * flux_e = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_array * wavelengths = cpl_array_new(l, CPL_TYPE_DOUBLE); + cpl_array * wavelengths_resamp = cpl_array_new(l2, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < l; ++i){ + cpl_image_set(flux, i + 1, 1, y[i]); + cpl_image_set(flux_e, i + 1, 1, y_e[i]); + cpl_array_set(wavelengths, i, x[i]); + } + + for(cpl_size i = 0; i < l2; ++i){ + cpl_array_set(wavelengths_resamp, i, x_r[i]); + } + + hdrl_spectrum1D * sp1 = hdrl_spectrum1D_create(flux, flux_e, wavelengths, + hdrl_spectrum1D_wave_scale_linear); + + cpl_array_delete(wavelengths); + cpl_image_delete(flux); + cpl_image_delete(flux_e); + + hdrl_spectrum1D_wavelength wl = hdrl_spectrum1D_get_wavelength(sp1); + + wl.wavelength = wavelengths_resamp; + wl.bpm = NULL; + + hdrl_parameter * pars = hdrl_spectrum1D_resample_interpolate_parameter_create + (hdrl_spectrum1D_interp_akima); + + hdrl_spectrum1D * sp2 = hdrl_spectrum1D_resample(sp1, &wl, pars); + + hdrl_parameter_delete(pars); pars = NULL; + + /*check that for each position in x_r[i] we linearly interpolate the noise*/ + for(cpl_size i = 0; i < l2; ++i){ + + hdrl_error_t err = hdrl_spectrum1D_get_flux_value(sp2, i, NULL).error; + const cpl_size idx = closer_idx[i]; + hdrl_error_t err_ori = pow(y_e[idx], 2.0) * fabs(x[idx + 1] - x_r[i]) + + pow(y_e[idx + 1], 2.0) * fabs(x[idx] - x_r[i]); + + err_ori = sqrt(err_ori); + + cpl_test_abs(err, err_ori, 1e-16); + hdrl_data_t w = hdrl_spectrum1D_get_wavelength_value(sp2, i, NULL); + cpl_test_abs(w, x_r[i], 1e-16); + } + + hdrl_spectrum1D_delete(&sp1); + hdrl_spectrum1D_delete(&sp2); + cpl_array_delete(wavelengths_resamp); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test error calculation for resample based on + * interpolation + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_resample_spectrum_fit_error_test_error_interpol(void){ + + double y[] = { 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1}; + double y_e[] = {.1, .2, .3, .4, .5, .6, .7, .8, .9, 1, 1.1, 1.2, 1.3, 1.4}; + double x[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + + double x_r[] = + {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.9, 11.1, 12.2, 13.9}; + + cpl_size closer_idx[] = + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + + const cpl_size l = LENGTH_ARRAY(y); + const cpl_size l2 = LENGTH_ARRAY(x_r); + cpl_test_eq(LENGTH_ARRAY(y), LENGTH_ARRAY(y_e)); + cpl_test_eq(LENGTH_ARRAY(y), LENGTH_ARRAY(x)); + + cpl_image * flux = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_image * flux_e = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_array * wavelengths = cpl_array_new(l, CPL_TYPE_DOUBLE); + cpl_array * wavelengths_resamp = cpl_array_new(l2, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < l; ++i){ + cpl_image_set(flux, i + 1, 1, y[i]); + cpl_image_set(flux_e, i + 1, 1, y_e[i]); + cpl_array_set(wavelengths, i, x[i]); + } + + for(cpl_size i = 0; i < l2; ++i){ + cpl_array_set(wavelengths_resamp, i, x_r[i]); + } + + hdrl_spectrum1D * sp1 = hdrl_spectrum1D_create(flux, flux_e, wavelengths, + hdrl_spectrum1D_wave_scale_linear); + + cpl_array_delete(wavelengths); + cpl_image_delete(flux); + cpl_image_delete(flux_e); + + hdrl_spectrum1D_wavelength wl = hdrl_spectrum1D_get_wavelength(sp1); + + wl.wavelength = wavelengths_resamp; + wl.bpm = NULL; + + hdrl_parameter * pars = hdrl_spectrum1D_resample_fit_parameter_create(2, 5); + + + hdrl_spectrum1D * sp2 = hdrl_spectrum1D_resample(sp1, &wl, pars); + + hdrl_parameter_delete(pars); pars = NULL; + + /*check that for each position in x_r[i] we linearly interpolate the noise*/ + for(cpl_size i = 0; i < l2; ++i){ + + hdrl_error_t err = hdrl_spectrum1D_get_flux_value(sp2, i, NULL).error; + const cpl_size idx = closer_idx[i]; + hdrl_error_t err_ori = pow(y_e[idx], 2.0) * fabs(x[idx + 1] - x_r[i]) + + pow(y_e[idx + 1], 2.0) * fabs(x[idx] - x_r[i]); + + err_ori = sqrt(err_ori); + + cpl_test_abs(err, err_ori, 1e-16); + hdrl_data_t w = hdrl_spectrum1D_get_wavelength_value(sp2, i, NULL); + cpl_test_abs(w, x_r[i], 1e-16); + } + + hdrl_spectrum1D_delete(&sp1); + hdrl_spectrum1D_delete(&sp2); + cpl_array_delete(wavelengths_resamp); +} + + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test that bad pixels are not taken into account + * for interpolation + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_resample_spectrum_bpm(cpl_boolean interpolate){ + + double x[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15}; + + double x_r[] = + {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.9, 11.1, 12.2, 13.9, 14.1}; + + const cpl_size l = LENGTH_ARRAY(x); + const cpl_size l2 = LENGTH_ARRAY(x_r); + + cpl_image * flux = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_array * wavelengths = cpl_array_new(l, CPL_TYPE_DOUBLE); + cpl_array * wavelengths_resamp = cpl_array_new(l2, CPL_TYPE_DOUBLE); + + /* set all the bad pixels to 10 and all the others to 0. */ + for(cpl_size i = 0; i < l; ++i){ + if(i % 2 == 0) + cpl_image_set(flux, i + 1, 1, 10); + cpl_array_set(wavelengths, i, x[i]); + } + + for(cpl_size i = 0; i < l; i+=2) + cpl_image_reject(flux, i + 1, 1); + + for(cpl_size i = 0; i < l2; ++i){ + cpl_array_set(wavelengths_resamp, i, x_r[i]); + } + + + hdrl_spectrum1D * sp1 = hdrl_spectrum1D_create_error_free(flux, wavelengths, + hdrl_spectrum1D_wave_scale_linear); + + cpl_array_delete(wavelengths); + cpl_image_delete(flux); + + hdrl_spectrum1D_wavelength wl = hdrl_spectrum1D_get_wavelength(sp1); + + wl.wavelength = wavelengths_resamp; + wl.bpm = NULL; + + hdrl_parameter * pars = NULL; + if(interpolate) + pars = hdrl_spectrum1D_resample_interpolate_parameter_create + (hdrl_spectrum1D_interp_akima); + else + pars = hdrl_spectrum1D_resample_fit_parameter_create(2, 5); + + hdrl_spectrum1D * sp2 = hdrl_spectrum1D_resample(sp1, &wl, pars); + + hdrl_parameter_delete(pars); pars = NULL; + + /* the first element in the interpolated must be rejected since the element + * a wlength 1 is bad and we mark as bad every pixel outside the interval of the + * source spectra. I.e. we truncate*/ + int rej = 0; + hdrl_spectrum1D_get_flux_value(sp2, 0, &rej); + cpl_test_eq(rej, 1); + + rej = 0; + hdrl_spectrum1D_get_flux_value(sp2, l2 - 1, &rej); + cpl_test_eq(rej, 1); + + /*check that all the pixels are zero, the non zero pixels of sp1 should have + * not contributed to the interpolation, because there were all bad*/ + for(cpl_size i = 1; i < l2 - 1; ++i){ + + hdrl_data_t data = hdrl_spectrum1D_get_flux_value(sp2, i, NULL).data; + + cpl_test_rel(data, 0.0, 1e-6); + } + + hdrl_spectrum1D_delete(&sp1); + hdrl_spectrum1D_delete(&sp2); + cpl_array_delete(wavelengths_resamp); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test error calculation for resample based on + * fitting. We first resample .2 forward and then + * resample .2 backward. We expect that the flux + * of this 2nd spectrum has very similar errors to the + * original one. + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_resample_spectrum_fit_error_test_shift(cpl_boolean is_error_free){ + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + double y[] = { 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1}; + double y_e[] = {.1, .2, .3, .2, .1, .2, .3, .2, .1, .2, .3, .2, .1, .2}; + double x[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + + const cpl_size l = LENGTH_ARRAY(x); + + cpl_image * flux = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_image * flux_e = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_array * wavelengths = cpl_array_new(l, CPL_TYPE_DOUBLE); + + + for(cpl_size i = 0; i < l; ++i){ + cpl_image_set(flux, i + 1, 1, y[i]); + if(!is_error_free) + cpl_image_set(flux_e, i + 1, 1, y_e[i]); + cpl_array_set(wavelengths, i, x[i]); + } + + cpl_array * wavelengths_resampled1 = cpl_array_new(l - 1, CPL_TYPE_DOUBLE); + cpl_array * wavelengths_resampled2 = cpl_array_new(l - 2, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < l - 1; ++i){ + const double d = cpl_array_get(wavelengths, i, NULL) + .2; + cpl_array_set(wavelengths_resampled1, i, d); + } + + for(cpl_size i = 1; i < l - 1; ++i){ + const double d = cpl_array_get(wavelengths, i, NULL); + cpl_array_set(wavelengths_resampled2, i - 1, d); + } + + hdrl_spectrum1D * sp1 = hdrl_spectrum1D_create(flux, flux_e, + wavelengths, scale); + cpl_test_nonnull(sp1); + + const hdrl_spectrum1D_wavelength wl1 = {wavelengths_resampled1, NULL, scale}; + const hdrl_spectrum1D_wavelength wl2 = {wavelengths_resampled2, NULL, scale}; + + hdrl_parameter * pars = + hdrl_spectrum1D_resample_fit_parameter_create(4, l - 3); + + hdrl_spectrum1D * sp2 = hdrl_spectrum1D_resample(sp1, &wl1, pars); + cpl_test_nonnull(sp2); + + hdrl_spectrum1D * sp3 = hdrl_spectrum1D_resample(sp2, &wl2, pars); + cpl_test_nonnull(sp3); + + for(cpl_size i = 1; i < l - 2; ++i){ + const hdrl_value v1 = + hdrl_spectrum1D_get_flux_value(sp1, i, NULL); + const hdrl_value v3 = + hdrl_spectrum1D_get_flux_value(sp3, i - 1, NULL); + + cpl_test_eq(v1.error, v3.error); + cpl_test_abs(v1.data, v3.data, .5); + } + + hdrl_parameter_delete(pars); + cpl_image_delete(flux); + cpl_image_delete(flux_e); + cpl_array_delete(wavelengths); + cpl_array_delete(wavelengths_resampled1); + cpl_array_delete(wavelengths_resampled2); + + hdrl_spectrum1D_delete(&sp1); + hdrl_spectrum1D_delete(&sp2); + hdrl_spectrum1D_delete(&sp3); +} + +static inline double +func(const double t) +{ + double x = sin(10.0 * t); + return exp(x*x*x); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test for fitting when using windows + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_resample_spectrum_fit_windowed(void){ + + const cpl_size nblocks = 5e2; + const cpl_size length = 100e3; + const cpl_size window = length / nblocks; + + const double dt = 1.0 / (length - 1); + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + + hdrl_parameter * pars_no_win = + hdrl_spectrum1D_resample_fit_parameter_create(4, 28); + + hdrl_parameter * pars_win = + hdrl_spectrum1D_resample_fit_windowed_parameter_create + (4, 6, window, 1.2); + + cpl_array * lambdas = cpl_array_new(length, CPL_TYPE_DOUBLE); + cpl_array * lambdas_resampled = cpl_array_new(length - 2, CPL_TYPE_DOUBLE); + + cpl_image * flux = cpl_image_new(length, 1, CPL_TYPE_DOUBLE); + cpl_image * flux_real = cpl_image_new(length - 2, 1, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < length; ++i){ + const double d = i * dt; + cpl_array_set(lambdas, i, d); + cpl_image_set(flux, i + 1, 1, func(d)); + } + + for(cpl_size i = 0; i < length - 2; ++i){ + const double d = (i + .5) * dt; + cpl_array_set(lambdas_resampled, i, d); + cpl_image_set(flux_real, i + 1, 1, func(d)); + } + + hdrl_spectrum1D_wavelength wav = {lambdas_resampled, NULL, scale}; + + hdrl_spectrum1D * sp_source = + hdrl_spectrum1D_create_error_free(flux, lambdas, scale); + + hdrl_spectrum1D * sp_ideal_resampled = + hdrl_spectrum1D_create_error_free + (flux_real, lambdas_resampled, scale); + + hdrl_spectrum1D * sp_win_resampled = hdrl_spectrum1D_resample + (sp_source, &wav, pars_win); + + hdrl_spectrum1D * sp_resampled = hdrl_spectrum1D_resample + (sp_source, &wav, pars_no_win); + + for(cpl_size i = 0; i < length - 2; ++i){ + hdrl_data_t v_ideal = hdrl_spectrum1D_get_flux_value + (sp_ideal_resampled, i, NULL).data; + hdrl_data_t v_win = hdrl_spectrum1D_get_flux_value + (sp_win_resampled, i, NULL).data; + hdrl_data_t v_no_win = hdrl_spectrum1D_get_flux_value + (sp_resampled, i, NULL).data; + + cpl_test_rel(v_ideal, v_win, 1.5e-1); + cpl_test_rel(v_ideal, v_no_win, 1.5e-1); + } + + hdrl_parameter_delete(pars_no_win); + hdrl_parameter_delete(pars_win); + + cpl_array_delete(lambdas); + cpl_array_delete(lambdas_resampled); + + cpl_image_delete(flux); + cpl_image_delete(flux_real); + hdrl_spectrum1D_delete(&sp_ideal_resampled); + hdrl_spectrum1D_delete(&sp_win_resampled); + hdrl_spectrum1D_delete(&sp_resampled); + hdrl_spectrum1D_delete(&sp_source); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test for the selection function. + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_wavelength_select(void){ + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + double y[] = { 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1}; + double y_e[] = {.1, .2, .3, .2, .1, .2, .3, .2, .1, .2, .3, .2, .1, .2}; + double x[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + + const cpl_size l = LENGTH_ARRAY(x); + + cpl_image * flux = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_image * flux_e = cpl_image_new(l, 1, CPL_TYPE_DOUBLE); + cpl_array * wavelengths = cpl_array_new(l, CPL_TYPE_DOUBLE); + + + for(cpl_size i = 0; i < l; ++i){ + cpl_image_set(flux, i + 1, 1, y[i]); + cpl_image_set(flux_e, i + 1, 1, y_e[i]); + cpl_array_set(wavelengths, i, x[i]); + } + + cpl_image_reject(flux, 5, 1); + + hdrl_spectrum1D * sp1 = + hdrl_spectrum1D_create(flux, flux_e, wavelengths, scale); + + hdrl_spectrum1D * sp2 = select_window(sp1, (sel_window){3, 10, CPL_TRUE}); + + cpl_test_eq(8, hdrl_spectrum1D_get_size(sp2)); + { + int rej = 0; + hdrl_spectrum1D_get_flux_value(sp2, 2, &rej); + cpl_test_eq(rej, 1); + } + const cpl_size l2 = hdrl_spectrum1D_get_size(sp2); + for(cpl_size i = 0; i < l2; ++i){ + + if(i == 2) continue; + + int rej1_1 = 0; + int rej2_1 = 0; + + const hdrl_data_t w1 = + hdrl_spectrum1D_get_wavelength_value(sp1, i + 2, &rej1_1); + const hdrl_data_t w2 = + hdrl_spectrum1D_get_wavelength_value(sp2, i, &rej2_1); + + cpl_test_eq(rej1_1, 0); + cpl_test_eq(rej2_1, 0); + + cpl_test_eq(w1, w2); + + int rej1_2 = 0; + int rej2_2 = 0; + const hdrl_value s1 = hdrl_spectrum1D_get_flux_value(sp1, i + 2, &rej1_2); + const hdrl_value s2 = hdrl_spectrum1D_get_flux_value(sp2, i, &rej2_2); + + cpl_test_eq(rej1_2, 0); + cpl_test_eq(rej2_2, 0); + + cpl_test_rel(s1.data, s2.data, 1e-16); + cpl_test_rel(s1.error, s2.error, 1e-16); + } + + hdrl_spectrum1D_delete(&sp2); + + hdrl_spectrum1D * sp3 = select_window(sp1, (sel_window){3, 10, CPL_FALSE}); + + cpl_test_eq(6, hdrl_spectrum1D_get_size(sp3)); + + cpl_size idxes[] = {0, 1, 10, 11, 12, 13}; + + for(cpl_size i = 0; i < 6; ++i){ + + int rej1_1 = 0; + int rej2_1 = 0; + + const hdrl_data_t w1 = + hdrl_spectrum1D_get_wavelength_value(sp1, idxes[i], &rej1_1); + const hdrl_data_t w2 = + hdrl_spectrum1D_get_wavelength_value(sp3, i, &rej2_1); + + cpl_test_eq(rej1_1, 0); + cpl_test_eq(rej2_1, 0); + + cpl_test_eq(w1, w2); + + int rej1_2 = 0; + int rej2_2 = 0; + const hdrl_value s1 = + hdrl_spectrum1D_get_flux_value(sp1, idxes[i], &rej1_2); + const hdrl_value s2 = hdrl_spectrum1D_get_flux_value(sp3, i, &rej2_2); + + cpl_test_eq(rej1_2, 0); + cpl_test_eq(rej2_2, 0); + + cpl_test_rel(s1.data, s2.data, 1e-16); + cpl_test_rel(s1.error, s2.error, 1e-16); + } + + hdrl_spectrum1D_delete(&sp1); + hdrl_spectrum1D_delete(&sp3); + cpl_image_delete(flux); + cpl_image_delete(flux_e); + cpl_array_delete(wavelengths); + + /* Check for the function that rejects some elements inside the spectrum */ + const cpl_size sz = 10; + + hdrl_spectrum1D * sp = + get_spectrum1D_sin_shuffled(sz, 3, CPL_FALSE, NULL); + + cpl_array * arr = cpl_array_new(sz, CPL_TYPE_INT); + + for(cpl_size i = 0; i < sz; i++){ + cpl_array_set(arr, i, i % 2); + } + + hdrl_spectrum1D * sp_r1 = + hdrl_spectrum1D_reject_pixels(sp, arr); + + for(cpl_size i = 0; i < sz; i++){ + int rej = 0; + hdrl_value d = hdrl_spectrum1D_get_flux_value(sp_r1, i, &rej); + + if(i % 2 == 1){ + cpl_test(rej); + } + else{ + hdrl_value d1 = hdrl_spectrum1D_get_flux_value(sp, i, NULL); + cpl_test_rel(d.data, d1.data, HDRL_EPS_DATA); + cpl_test_rel(d.error, d1.error, HDRL_EPS_DATA); + } + } + + cpl_array_delete(arr); + hdrl_spectrum1D_delete(&sp); + hdrl_spectrum1D_delete(&sp_r1); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test for the uniformly sampled function + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_test_uniformly_sampled(void){ + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + + const cpl_size sz = 100; + hdrl_spectrum1D * sp = + get_spectrum1D_sin_shuffled(sz, 3, CPL_FALSE, NULL); + + double delta = 0.0; + cpl_boolean is_OK = hdrl_spectrum1D_is_uniformly_sampled(sp, &delta); + + cpl_test(is_OK); + cpl_test_abs(delta, 2 * CPL_MATH_PI / sz, HDRL_EPS_DATA); + + hdrl_spectrum1D_delete(&sp); + + cpl_array * arr = cpl_array_new(sz, CPL_TYPE_DOUBLE); + cpl_image * flx = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + for(cpl_size i = 0; i < sz; ++i){ + cpl_array_set(arr, i, i + 1); + cpl_image_set(flx, i + 1, 1, .1); + } + + cpl_array_set(arr, 4, 5.1); + sp = hdrl_spectrum1D_create_error_free(flx, arr, scale); + is_OK = hdrl_spectrum1D_is_uniformly_sampled(sp, &delta); + cpl_test(!is_OK); + hdrl_spectrum1D_delete(&sp); + + cpl_array_set(arr, 4, 5); + sp = hdrl_spectrum1D_create_error_free(flx, arr, scale); + is_OK = hdrl_spectrum1D_is_uniformly_sampled(sp, &delta); + cpl_test(is_OK); + cpl_test_rel(delta, 1.0, HDRL_EPS_DATA); + hdrl_spectrum1D_delete(&sp); + + cpl_image_delete(flx); + cpl_array_delete(arr); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test for the hdrl_spectrum1Dlist + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1Dlist(void){ + + { + hdrl_spectrum1Dlist * list = hdrl_spectrum1Dlist_new(); + hdrl_spectrum1Dlist_delete(list); + } + + const cpl_size sz = 40; + { + hdrl_spectrum1Dlist * list = hdrl_spectrum1Dlist_new(); + + hdrl_spectrum1D * s1 = + get_spectrum1D_sin_shuffled(sz, 4, CPL_TRUE, NULL); + hdrl_spectrum1D * s2 = + get_spectrum1D_sin_shuffled(sz, 4, CPL_TRUE, NULL); + hdrl_spectrum1D * s3 = + get_spectrum1D_sin_shuffled(sz, 4, CPL_TRUE, NULL); + + hdrl_spectrum1Dlist_set(list, s1, 0); + hdrl_spectrum1Dlist_set(list, s2, 1); + hdrl_spectrum1Dlist_set(list, s3, 2); + + cpl_test_eq(hdrl_spectrum1Dlist_get_size(list), 3); + cpl_test_eq(list->capacity, 4); + + hdrl_spectrum1D * s22 = hdrl_spectrum1Dlist_get(list, 1); + const hdrl_spectrum1D * s22_c = hdrl_spectrum1Dlist_get_const(list, 1); + + cpl_test_eq_ptr(s2, s22); + cpl_test_eq_ptr(s2, s22_c); + + hdrl_spectrum1D * s22_u = hdrl_spectrum1Dlist_unset(list, 1); + cpl_test_eq_ptr(s22_u, s22_c); + + cpl_test_eq(hdrl_spectrum1Dlist_get_size(list), 2); + + hdrl_spectrum1D_delete(&s22_u); + + cpl_size i = 0; + while(hdrl_spectrum1Dlist_get_size(list) > 0) { + hdrl_spectrum1D * s = hdrl_spectrum1Dlist_unset(list, 0); + + if(i == 0) + cpl_test_eq_ptr(s, s1); + else + cpl_test_eq_ptr(s, s3); + + hdrl_spectrum1D_delete(&s); + i++; + } + + cpl_test_eq(hdrl_spectrum1Dlist_get_size(list), 0); + cpl_test_eq(list->capacity, 0); + cpl_test_eq_ptr(list->spectra, NULL); + + hdrl_spectrum1Dlist_delete(list); + } +} + +static inline cpl_array * +get_waves(double start_wave, cpl_size sz, double step){ + + cpl_array * to_ret = cpl_array_new(sz, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < sz; ++i){ + cpl_array_set(to_ret, i, start_wave + step * i); + } + + return to_ret; +} + +static inline hdrl_spectrum1D * +generate_stair_spectrum(int start, int stop, double start_wave, double step_wave){ + + const cpl_size sz = stop - start + 1; + cpl_array * wave = get_waves(start_wave, sz, step_wave); + cpl_image * flx = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + cpl_image * flx_e = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + + + for(cpl_size i = 0; i < sz; ++i){ + const double f = start + i; + cpl_image_set(flx, i + 1, 1, f); + cpl_image_set(flx_e, i + 1, 1, f / 10.0); + } + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create(flx, flx_e, wave, + hdrl_spectrum1D_wave_scale_linear); + + cpl_image_delete(flx); + cpl_image_delete(flx_e); + cpl_array_delete(wave); + + + return to_ret; +} + +cpl_boolean contains(const cpl_array * arr, cpl_size idx){ + for(cpl_size i = 0; i < cpl_array_get_size(arr); ++i){ + const cpl_size this_idx = (cpl_size)cpl_array_get(arr, i, NULL); + if(this_idx == idx) return CPL_TRUE; + } + return CPL_FALSE; +} + +static inline hdrl_spectrum1D * +generate_bad_stair_spectrum(int start, int stop, double start_wave, + double step_wave, cpl_array * bad_idxes){ + + const cpl_size sz = stop - start + 1; + cpl_array * wave = get_waves(start_wave, sz, step_wave); + cpl_image * flx = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + cpl_image * flx_e = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + + + for(cpl_size i = 0; i < sz; ++i){ + + if(contains(bad_idxes, i)) + { + cpl_image_reject(flx, i + 1, 1); + cpl_image_reject(flx_e, i + 1, 1); + continue; + } + + const double f = start + i; + cpl_image_set(flx, i + 1, 1, f); + cpl_image_set(flx_e, i + 1, 1, f / 10.0); + } + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create(flx, flx_e, wave, + hdrl_spectrum1D_wave_scale_linear); + + cpl_image_delete(flx); + cpl_image_delete(flx_e); + cpl_array_delete(wave); + + + return to_ret; +} + + +static inline hdrl_spectrum1D * +generate_stair_spectrum_shuffled(int start, int stop, double start_wave, + double step_wave, cpl_size * idxes){ + + const cpl_size sz = stop - start + 1; + cpl_array * wave = get_waves(start_wave, sz, step_wave); + cpl_array * wave_s = cpl_array_duplicate(wave); + + cpl_image * flx = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + cpl_image * flx_e = cpl_image_new(sz, 1, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < sz; ++i){ + const double f = start + i; + const cpl_size dest_idx = idxes[i]; + cpl_image_set(flx, dest_idx + 1, 1, f); + cpl_image_set(flx_e, dest_idx + 1, 1, f / 10.0); + + const double w = cpl_array_get(wave, i, NULL); + cpl_array_set(wave_s, dest_idx, w); + } + + hdrl_spectrum1D * to_ret = hdrl_spectrum1D_create(flx, flx_e, wave_s, + hdrl_spectrum1D_wave_scale_linear); + + cpl_image_delete(flx); + cpl_image_delete(flx_e); + cpl_array_delete(wave); + cpl_array_delete(wave_s); + + return to_ret; +} + +void test1(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 2.0); + + cpl_array * wavs_integrate = get_waves(21, 9, 1); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + /* first element: the initial bin is asimmetric, tested as + * special case*/ + { + int rej = 0; + hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, 0, &rej); + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, 2.0, 1e-10); + cpl_test_rel(f.error, f.data / 10.0, 1e-10); + } + + const cpl_size int_size = cpl_array_get_size(wavs_integrate); + + /* last element: the final bin is asimmetric, tested as + * special case*/ + { + int rej = 0; + hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, int_size - 1, &rej); + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, 5.0, 1e-10); + cpl_test_rel(f.error, f.data / 10.0, 1e-10); + } + + double src_flx = 2.0; + for(cpl_size i = 1; i < int_size - 1; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + + if((i % 2) == 1){ + /*odd elements: they are in the center of the source bin*/ + cpl_test_rel(f.data, src_flx, 1e-10); + cpl_test_rel(f.error, src_flx / 10.0, 1e-10); + + } + else{ + /*even elements: they are between bins*/ + const double el = src_flx + .5; + cpl_test_rel(f.data, el, 1e-10); + + const double el_e = pow(src_flx, 2.0) + pow((src_flx + 1.0), 2.0); + cpl_test_rel(f.error, sqrt(el_e) / (10.0 * sqrt(2.0)), 1e-10); + src_flx++; + } + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +void test2(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 2.0); + + cpl_array * wavs_integrate = get_waves(20, 15, 1); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + const cpl_size int_size = cpl_array_get_size(wavs_integrate); + + double src_flx = 1.0; + for(cpl_size i = 0; i < int_size; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + + if((i % 2) == 0){ + /*odd elements: they are in the center of the source bin*/ + cpl_test_rel(f.data, src_flx, 1e-10); + cpl_test_rel(f.error, src_flx / 10.0, 1e-10); + + } + else{ + /*even elements: they are between bins*/ + const double el = src_flx + .5; + cpl_test_rel(f.data, el, 1e-10); + + const double el_e = pow(src_flx, 2.0) + pow((src_flx + 1.0), 2.0); + cpl_test_rel(f.error, sqrt(el_e) / (10.0 * sqrt(2.0)), 1e-10); + src_flx++; + } + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +void test3(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 2.0); + + cpl_array * wavs_integrate = get_waves(19, 17, 1); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + const cpl_size int_size = cpl_array_get_size(wavs_integrate); + + /*2 bins are rejected, 1 because is completely outside, the other half outside*/ + for(cpl_size i = 0; i < 2; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + /*2 bins are rejected, 1 because is completely outside, the other half outside*/ + for(cpl_size i = int_size - 2; i < int_size; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double src_flx = 1.0; + for(cpl_size i = 2; i < int_size - 2; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + + if((i % 2) == 1){ + /*odd elements: they are in the center of the source bin*/ + cpl_test_rel(f.data, src_flx, 1e-10); + cpl_test_rel(f.error, src_flx / 10.0, 1e-10); + + } + else{ + /*even elements: they are between bins*/ + const double el = src_flx + .5; + cpl_test_rel(f.data, el, 1e-10); + + const double el_e = pow(src_flx, 2.0) + pow((src_flx + 1.0), 2.0); + cpl_test_rel(f.error, sqrt(el_e) / (10.0 * sqrt(2.0)), 1e-10); + src_flx++; + } + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +static inline cpl_array * +shuffle(const cpl_array * ori, const cpl_size * idxes){ + cpl_array * to_ret = cpl_array_duplicate(ori); + cpl_size sz = cpl_array_get_size(ori); + for(cpl_size i = 0; i < sz; ++i){ + const double w = cpl_array_get(ori, i, NULL); + cpl_array_set(to_ret, idxes[i], w); + } + return to_ret; +} + +void test4(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 2.0); + + hdrl_spectrum1D * ori_s_shuffled = generate_stair_spectrum_shuffled(1, 8, 20.0, 2.0, + (cpl_size[]){3, 2, 1, 4, 7, 6, 0, 5}); + + cpl_array * wavs_integrate = get_waves(21, 9, 1); + + cpl_size shuffles[] = {1, 3, 5, 0, 8, 7, 6, 2, 4}; + cpl_array * wavs_integrate_shuffle = shuffle(wavs_integrate, + shuffles); + + hdrl_spectrum1D * integrated_s_shuffled = + hdrl_spectrum1D_resample_on_array(ori_s_shuffled, wavs_integrate_shuffle, par); + + hdrl_spectrum1D * integrated_s= + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + const cpl_size sz = hdrl_spectrum1D_get_size(integrated_s_shuffled); + cpl_test_eq(sz, cpl_array_get_size(wavs_integrate)); + cpl_test_eq(sz, hdrl_spectrum1D_get_size(integrated_s)); + + for(cpl_size i = 0; i < sz; ++i){ + const double wav_s = hdrl_spectrum1D_get_wavelength_value(integrated_s, + i, NULL); + const double wav = cpl_array_get(wavs_integrate, i, NULL); + cpl_test_rel(wav_s, wav, 1e-10); + } + + for(cpl_size i = 0; i < sz; ++i){ + const double wav_s = hdrl_spectrum1D_get_wavelength_value(integrated_s_shuffled, + i, NULL); + const double wav = cpl_array_get(wavs_integrate_shuffle, i, NULL); + cpl_test_rel(wav_s, wav, 1e-10); + } + + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0, rej_shuffled = 0; + + const hdrl_value flx = hdrl_spectrum1D_get_flux_value(integrated_s, + i, &rej); + const hdrl_value flx_shuffled = hdrl_spectrum1D_get_flux_value(integrated_s_shuffled, + shuffles[i], &rej_shuffled); + + const hdrl_data_t wav = hdrl_spectrum1D_get_wavelength_value(integrated_s, + i, NULL); + + const hdrl_data_t wav_shuffled = hdrl_spectrum1D_get_wavelength_value(integrated_s_shuffled, + shuffles[i], NULL); + + cpl_test_rel(wav, wav_shuffled, 1e-10); + cpl_test_eq(rej, rej_shuffled); + cpl_test_rel(flx.data, flx_shuffled.data, 1e-10); + cpl_test_rel(flx.error, flx_shuffled.error, 1e-10); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&ori_s_shuffled); + hdrl_spectrum1D_delete(&integrated_s); + hdrl_spectrum1D_delete(&integrated_s_shuffled); + cpl_array_delete(wavs_integrate); + cpl_array_delete(wavs_integrate_shuffle); +} + +void test5(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + cpl_array * bad_idxes = cpl_array_new(4, CPL_TYPE_INT); + + cpl_array_set(bad_idxes, 0, 0); + cpl_array_set(bad_idxes, 1, 7); + cpl_array_set(bad_idxes, 2, 2); + cpl_array_set(bad_idxes, 3, 5); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 8, 20.0, 2.0 , bad_idxes); + + cpl_array * wavs_integrate = get_waves(19, 17, 1); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + const cpl_size int_size = cpl_array_get_size(wavs_integrate); + + /*3 bins are rejected, 1 because is completely outside, the other half outside, + * the third in a bad pixel*/ + for(cpl_size i = 0; i < 3; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + /*3 bins are rejected, 1 because is completely outside, the other half outside, + * the third in a bad pixel*/ + for(cpl_size i = int_size - 3; i < int_size; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double src_flx = 2.0; + for(cpl_size i = 3; i < int_size - 3; ++i){ + + /*rejected because inside a bad pixel*/ + if((i >=4 && i <= 6) || (i >= 10 && i <= 12)){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + + if((i % 2) == 0) src_flx++; + + continue; + } + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + + if((i % 2) == 1){ + /*odd elements: they are in the center of the source bin*/ + cpl_test_rel(f.data, src_flx, 1e-10); + cpl_test_rel(f.error, src_flx / 10.0, 1e-10); + + } + else{ + /*even elements: they are between bins*/ + const double el = src_flx + .5; + cpl_test_rel(f.data, el, 1e-10); + + const double el_e = pow(src_flx, 2.0) + pow((src_flx + 1.0), 2.0); + cpl_test_rel(f.error, sqrt(el_e) / (10.0 * sqrt(2.0)), 1e-10); + src_flx++; + } + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); + cpl_array_delete(bad_idxes); +} + +void test6(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 2.0); + + cpl_array * wavs_integrate = get_waves(20.5, 15, 1); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + double src_flx = 1.0; + + for(cpl_size i = 0; i < cpl_array_get_size(wavs_integrate) - 1; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, src_flx, 1e-10); + cpl_test_rel(f.error, src_flx / 10.0, 1e-10); + src_flx = src_flx + ((i+1) % 2); + } + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, + cpl_array_get_size(wavs_integrate) - 1, &rej); + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +void test7(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + cpl_array * bads = cpl_array_new(3, CPL_TYPE_INT); + + cpl_array_set(bads, 0, 0); + cpl_array_set(bads, 1, 7); + cpl_array_set(bads, 2, 4); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 8, 20.0, 2.0, bads); + + cpl_array * wavs_integrate = get_waves(20.5, 15, 1); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + double src_flx = 1.0; + + for(cpl_size i = 0; i < cpl_array_get_size(wavs_integrate); ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + if(i == 0 || i == 7 || i == 8 || i >= 13){ + cpl_test_eq(rej, 1); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + else{ + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, src_flx, 1e-10); + cpl_test_rel(f.error, src_flx / 10.0, 1e-10); + } + src_flx = src_flx + ((i+1) % 2); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); + cpl_array_delete(bads); +} + + +void test8(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 1.0); + + cpl_array * wavs_integrate = get_waves(21, 3, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + double res_flx[] = {2.5, 4, 5.5}; + double res_flx_e[] = {sqrt(6.5), sqrt(16.5), sqrt(30.5)}; + + for(cpl_size i = 0; i < 3; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i], 1e-10); + cpl_test_rel(f.error, res_flx_e[i] / 10.0, 1e-10); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +void test9(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 1.0); + + cpl_array * wavs_integrate = get_waves(19, 5, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + { + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, 0, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double res_flx[] = {2, 4, 6, 7.5}; + for(cpl_size i = 1; i <= 4; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i - 1], 1e-10); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + + +void test10(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 8, 20.0, 1.0); + + cpl_array * wavs_integrate = get_waves(19, 6, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + { + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, 0, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double res_flx[] = {2, 4, 6}; + for(cpl_size i = 1; i <= 3; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i - 1], 1e-10); + } + + for(cpl_size i = 4; i < 6; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + + +void test11(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + cpl_array * bads = cpl_array_new(1, CPL_TYPE_INT); + + cpl_array_set(bads, 0, 3); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 8, 20.0, 1.0, bads); + + cpl_array * wavs_integrate = get_waves(19, 6, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + { + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, 0, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double res_flx[] = {2, 4, 6}; + for(cpl_size i = 1; i <= 3; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + if(i == 2){ + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + continue; + } + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i - 1], 1e-10); + } + + for(cpl_size i = 4; i < 6; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); + cpl_array_delete(bads); +} + +void test12(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + cpl_array * bads = cpl_array_new(1, CPL_TYPE_INT); + + cpl_array_set(bads, 0, 4); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 8, 20.0, 1.0, bads); + + cpl_array * wavs_integrate = get_waves(19, 6, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + { + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, 0, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double res_flx[] = {2, 4, 6}; + for(cpl_size i = 1; i <= 3; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + if(i == 2 || i == 3){ + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + continue; + } + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i - 1], 1e-10); + } + + for(cpl_size i = 4; i < 6; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); + cpl_array_delete(bads); +} + + +void test13(void){ + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + cpl_array * bads = cpl_array_new(2, CPL_TYPE_INT); + + cpl_array_set(bads, 0, 0); + cpl_array_set(bads, 1, 7); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 8, 20.0, 1.0, bads); + + cpl_array * wavs_integrate = get_waves(19, 6, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + { + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, 0, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + double res_flx[] = {2, 4, 6}; + for(cpl_size i = 0; i <= 3; ++i){ + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + if(i == 0 || i == 1){ + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + continue; + } + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i - 1], 1e-10); + } + + for(cpl_size i = 4; i < 6; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); + cpl_array_delete(bads); +} + +void test14(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + cpl_array * bads = cpl_array_new(2, CPL_TYPE_INT); + + cpl_array_set(bads, 0, 0); + cpl_array_set(bads, 1, 4); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 9, 20.5, 1.0, bads); + + cpl_array * wavs_integrate = get_waves(21, 5, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + + double res_flx[] = {2, 3.5, 4.5, 7.5}; + + for(cpl_size i = 0; i < cpl_array_get_size(wavs_integrate) - 1; ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + + if(i == 2){ + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + continue; + } + + cpl_test_eq(rej, 0); + cpl_test_rel(f.data, res_flx[i], 1e-10); + } + + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, + cpl_array_get_size(wavs_integrate) - 1, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); + cpl_array_delete(bads); +} + +void test15(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 3, 20.5, 1.0); + + double wa_mx = hdrl_spectrum1D_get_wavelength_value(ori_s, 2, NULL); + cpl_test_rel(wa_mx, 22.5, 1e-10); + + cpl_array * wavs_integrate = get_waves(22.5, 5, 2); + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + for(cpl_size i = 0; i < cpl_array_get_size(wavs_integrate); ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +void test16(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 3, 20.5, 1.0); + + cpl_array * wavs_integrate = get_waves(14.5, 4, 2); + + double wa_mx = cpl_array_get(wavs_integrate, 3, NULL); + cpl_test_rel(wa_mx, 20.5, 1e-10); + + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + for(cpl_size i = 0; i < cpl_array_get_size(wavs_integrate); ++i){ + int rej = 0; + const hdrl_value f = hdrl_spectrum1D_get_flux_value(integrated_s, i, &rej); + cpl_test(rej); + cpl_test(isnan(f.data)); + cpl_test(isnan(f.error)); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +void test17(void){ + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + cpl_array * bads = cpl_array_new(3, CPL_TYPE_INT); + + cpl_array_set(bads, 0, 0); + cpl_array_set(bads, 1, 4); + cpl_array_set(bads, 2, 7); + + hdrl_spectrum1D * ori_s = generate_bad_stair_spectrum(1, 8, 20.5, 1.0, bads); + + const cpl_array * wavs_integrate = + hdrl_spectrum1D_get_wavelength(ori_s).wavelength; + + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + for(cpl_size i = 0; i < cpl_array_get_size(wavs_integrate); ++i){ + int ori_rej = 0; + const hdrl_value ori_flx = hdrl_spectrum1D_get_flux_value(ori_s, i, &ori_rej); + + int int_rej = 0; + const hdrl_value int_flx = hdrl_spectrum1D_get_flux_value(integrated_s, i, &int_rej); + + cpl_test_eq(ori_rej, int_rej); + if(ori_rej) continue; + + cpl_test_rel(ori_flx.data, int_flx.data, 1e-10); + cpl_test_rel(ori_flx.error, int_flx.error, 1e-10); + } + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(bads); +} + +double get_bin_size(const hdrl_spectrum1D * s, const cpl_size i){ + + if(i == 0){ + const double w0 = hdrl_spectrum1D_get_wavelength_value(s, i, NULL); + const double w1 = hdrl_spectrum1D_get_wavelength_value(s, i + 1, NULL); + return (w0 + w1) / 2 - w0; + } + + const cpl_size sz = hdrl_spectrum1D_get_size(s); + if(i == sz - 1){ + const double w0 = hdrl_spectrum1D_get_wavelength_value(s, i - 1, NULL); + const double w1 = hdrl_spectrum1D_get_wavelength_value(s, i, NULL); + return (w0 + w1) / 2 - w0; + } + + const double w0 = hdrl_spectrum1D_get_wavelength_value(s, i - 1, NULL); + const double w1 = hdrl_spectrum1D_get_wavelength_value(s, i + 1, NULL); + return (w0 + w1) / 2 - w0; +} + +double calc_total_flux(const hdrl_spectrum1D * s){ + double flux = 0; + const cpl_size sz = hdrl_spectrum1D_get_size(s); + for(cpl_size i = 0; i < sz; ++i) + flux += hdrl_spectrum1D_get_flux_value(s, i, NULL).data * get_bin_size(s, i); + + return flux; +} + +void test18(void){ + + + hdrl_parameter * par = hdrl_spectrum1D_resample_integrate_parameter_create(); + + hdrl_spectrum1D * ori_s = generate_stair_spectrum(1, 4, 20.0, 2.0); + + cpl_array * wavs_integrate = get_waves(20, 3, 3); + + hdrl_spectrum1D * integrated_s = + hdrl_spectrum1D_resample_on_array(ori_s, wavs_integrate, par); + + cpl_test_rel(calc_total_flux(ori_s), 15.0, 1e-10); + + cpl_test_rel(calc_total_flux(ori_s), calc_total_flux(integrated_s), 1e-10); + + hdrl_parameter_delete(par); + hdrl_spectrum1D_delete(&ori_s); + hdrl_spectrum1D_delete(&integrated_s); + cpl_array_delete(wavs_integrate); +} + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_spectrum1D Test for resampling done using integration + */ +/*----------------------------------------------------------------------------*/ +void test_spectrum1D_resample_spectrum_integrate(void){ + + /*tests 1 to 6 test the case of upsampling doing integration*/ + /*test when the destination spectrum starts after the source and ends before + * the source end.*/ + test1(); + + /*test when source and destination points start and stop at the same bin*/ + test2(); + + /*test when destination points cover a wider range of the source*/ + test3(); + + /*like test1 but the output and input values are shuffled*/ + test4(); + + /*like test3 but we have bad pixels inside (and the edges) of the spectrum*/ + test5(); + + /* Test for rebinning, the dest bins split exactly source bin in half, + * except the last one which is outside*/ + test6(); + + /*Test like test6 but with bad pixels*/ + test7(); + + /*The following test test the case of dest bins bigger than source*/ + + /*Test when the destination spectrum starts after the source and ends before + * the source end.*/ + test8(); + + /*test when source and destination points stop at the same bin*/ + test9(); + + /*test when destination points cover a wider range of the source*/ + test10(); + + /*like test 10 but we have a bad pixel*/ + test11(); + test12(); + test13(); + + /* Test for rebinning, the dest bins split exactly source bin in half, + * except the last one which is outside, with bad pixels*/ + test14(); + + /*Source and destination have empty intersections*/ + test15(); + test16(); + + /*Source and destination with same bins*/ + test17(); + + /*Flux conservation*/ + test18(); + + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); +} + +void test_parlist(void) +{ + /* parameter parsing smoketest */ + const char *base_context = "RECIPE"; + const char *prefix = "test"; + const char *method_def = "LINEAR"; + + cpl_parameterlist *pos; + pos = hdrl_spectrum1D_resample_interpolate_parameter_create_parlist(base_context, prefix, method_def); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_parameter *hpar; + hpar = hdrl_spectrum1D_resample_interpolate_parameter_parse_parlist( + pos, "RECIPE.test"); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_parameter_delete(hpar); + + cpl_parameterlist_delete(pos); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of Spectrum1D module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + srand(500); + + test_parlist(); + + test_spectrum1D_constructor(CPL_TYPE_DOUBLE); + test_spectrum1D_constructor(CPL_TYPE_FLOAT); + test_spectrum1D_constructor_error(); + test_spectrum1D_constructor_analytical(); + test_spectrum1D_duplication(); + + + test_spectrum1D_calculation_scalar(); + + test_spectrum1D_calculation(); + test_spectrum1D_calculation_error(); + + test_spectrum1D_conversion_wavelength_scale(); + test_spectrum1D_mul_wavelength(); + test_spectrum1D_shift_wavelength(); + + test_spectrum1D_wavelength_select(); + + test_spectrum1D_resample_spectrum(CPL_TRUE); + test_spectrum1D_resample_spectrum(CPL_FALSE); + test_spectrum1D_resample_spectrum_private_funcs(); + test_spectrum1D_resample_spectrum_bpm(CPL_TRUE); + test_spectrum1D_resample_spectrum_bpm(CPL_FALSE); + test_spectrum1D_resample_spectrum_interpolation_error_test(); + test_spectrum1D_resample_spectrum_fit_error_test_shift(CPL_TRUE); + test_spectrum1D_resample_spectrum_fit_error_test_shift(CPL_FALSE); + test_spectrum1D_resample_spectrum_fit_error_test_error_interpol(); + test_spectrum1D_resample_spectrum_fit_windowed(); + + test_spectrum1D_resample_spectrum_integrate(); + + test_spectrum1D_table_conversion(); + + test_spectrum1D_test_uniformly_sampled(); + + test_spectrum1Dlist(); + + return cpl_test_end(0); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Helper functions + **/ +/*----------------------------------------------------------------------------*/ + +static inline cpl_image * get_random_1d_img(cpl_size length, + double min, double max, cpl_type type){ + cpl_image * to_ret = cpl_image_new(length, 1, type); + + for(cpl_size i = 0; i < length; i++){ + double d = rand_0_to_1() * (max - min) + min; + cpl_image_set(to_ret, i + 1, 1, d); + } + return to_ret; +} + +static inline void set_1d_bpm(cpl_image * img){ + + int sz_x = cpl_image_get_size_x(img); + int sz_y = cpl_image_get_size_y(img); + + cpl_mask * msk = cpl_image_get_bpm(img); + + for(cpl_size x = 0; x < sz_x; x++){ + for(cpl_size y = 0; y < sz_y; y++){ + cpl_mask_set(msk, x + 1, y + 1, rand_0_to_1() > .5); + } + } + +} + +static inline cpl_array * get_wavelength(cpl_size length, cpl_type type){ + + cpl_array * to_ret = cpl_array_new(length, type); + double d = rand_0_to_1(); + + for(cpl_size i = 0; i < length; i++){ + cpl_array_set(to_ret, i, d); + d += 1.0 + rand_0_to_1(); + } + return to_ret; +} + +static inline cpl_boolean are_cpl_img_eq( + const cpl_image *im1, const cpl_image *im2){ + + if (cpl_image_get_size_x(im1) != cpl_image_get_size_x(im2) || + cpl_image_get_size_y(im1) != cpl_image_get_size_y(im2) ){ + return CPL_FALSE; + } + + cpl_size sz_x = cpl_image_get_size_x(im1); + cpl_size sz_y = cpl_image_get_size_y(im1); + + int rej1 = 0; + int rej2 = 0; + + for(cpl_size x = 0; x < sz_x; x++){ + for(cpl_size y = 0; y < sz_y; y++){ + double px1 = cpl_image_get(im1, x + 1, y + 1, &rej1); + double px2 = cpl_image_get(im2, x + 1, y + 1, &rej2); + + if(px1 != px2 || rej1 != rej2) { + return CPL_FALSE; + } + } + } + + return CPL_TRUE; +} + +static inline cpl_boolean are_hdrl_eq(const hdrl_image* flux_compound, + const cpl_image * flux, const cpl_image * flux_e){ + + if (cpl_image_get_size_x(flux) != cpl_image_get_size_x(flux_e) || + cpl_image_get_size_y(flux) != cpl_image_get_size_y(flux_e) || + hdrl_image_get_size_x(flux_compound) != cpl_image_get_size_x(flux) || + hdrl_image_get_size_y(flux_compound) != cpl_image_get_size_y(flux) ){ + return CPL_FALSE; + } + + const cpl_image * flux_hdrl = hdrl_image_get_image_const(flux_compound); + const cpl_image * flux_e_hdrl = hdrl_image_get_error_const(flux_compound); + + hdrl_image * hdrl_img = hdrl_image_create(flux, flux_e); + + cpl_boolean is_success = + are_cpl_img_eq(hdrl_image_get_image_const(hdrl_img), flux_hdrl); + + is_success &= are_cpl_img_eq(hdrl_image_get_error_const(hdrl_img), + flux_e_hdrl); + + hdrl_image_delete(hdrl_img); hdrl_img = NULL; + + return is_success; +} + +static inline cpl_error_code get_error_code_and_reset(void){ + + cpl_error_code err = cpl_error_get_code(); + cpl_error_reset(); + return err; +} + +static inline double rand_0_to_1(void){ + double r = rand(); + r /= RAND_MAX; + return r; +} + +static inline hdrl_spectrum1D * +get_random_spectrum(int length, hdrl_spectrum1D_wave_scale scale){ + + cpl_image * spectrum1d = + get_random_1d_img(length, 1.0f, 128.0f, CPL_TYPE_DOUBLE); + cpl_image * spectrum1d_error = + get_random_1d_img(length, 0.5f, 2.0f, CPL_TYPE_DOUBLE); + + set_1d_bpm(spectrum1d); + cpl_array * wavelengths = get_wavelength(length, CPL_TYPE_DOUBLE); + + hdrl_spectrum1D * s1 = hdrl_spectrum1D_create( + spectrum1d, spectrum1d_error, + wavelengths, scale); + + cpl_array_delete(wavelengths); + cpl_image_delete(spectrum1d); + cpl_image_delete(spectrum1d_error); + + return s1; +} + + +static inline void +test_error_create_func(const hdrl_spectrum1D * s1, const hdrl_spectrum1D * s2, + operate_spectra_create f){ + + hdrl_spectrum1D * res = f(s1, s2); + cpl_test_null(res); + const cpl_error_code cd = get_error_code_and_reset(); + cpl_test_noneq(cd, CPL_ERROR_NONE); +} + +static inline void +test_error_mutate_func(hdrl_spectrum1D * s1, const hdrl_spectrum1D * s2, + operate_spectra f){ + + const cpl_error_code res = f(s1, s2); + cpl_test_noneq(res, CPL_ERROR_NONE); + + const cpl_error_code cd = get_error_code_and_reset(); + cpl_test_noneq(cd, CPL_ERROR_NONE); +} + +static inline void +test_calc_creat_error(operate_spectra_create f){ + + hdrl_spectrum1D * spec_l40_linear = + get_random_spectrum(40, hdrl_spectrum1D_wave_scale_linear); + hdrl_spectrum1D * spec_l40_log = + get_random_spectrum(40, hdrl_spectrum1D_wave_scale_log); + + hdrl_spectrum1D * spec_l41_linear = + get_random_spectrum(41, hdrl_spectrum1D_wave_scale_linear); + hdrl_spectrum1D * spec_l41_log = + get_random_spectrum(41, hdrl_spectrum1D_wave_scale_log); + + test_error_create_func + (spec_l40_linear, spec_l40_log, f); + test_error_create_func + (spec_l41_linear, spec_l40_linear, f); + test_error_create_func + (spec_l40_log, spec_l40_linear, f); + test_error_create_func + (spec_l40_linear, spec_l41_linear, f); + + test_error_create_func + (NULL, spec_l40_log, f); + test_error_create_func + (spec_l41_linear, NULL, f); + test_error_create_func(NULL, NULL, f); + + + hdrl_spectrum1D_delete(&spec_l40_linear); + hdrl_spectrum1D_delete(&spec_l41_linear); + + hdrl_spectrum1D_delete(&spec_l40_log); + hdrl_spectrum1D_delete(&spec_l41_log); +} + + +static inline void test_calc_error(operate_spectra f){ + + hdrl_spectrum1D * spec_l40_linear = + get_random_spectrum(40, hdrl_spectrum1D_wave_scale_linear); + hdrl_spectrum1D * spec_l40_log = + get_random_spectrum(40, hdrl_spectrum1D_wave_scale_log); + + hdrl_spectrum1D * spec_l41_linear = + get_random_spectrum(41, hdrl_spectrum1D_wave_scale_linear); + hdrl_spectrum1D * spec_l41_log = + get_random_spectrum(41, hdrl_spectrum1D_wave_scale_log); + + test_error_mutate_func + (spec_l40_linear, spec_l40_log, f); + test_error_mutate_func + (spec_l41_linear, spec_l40_linear, f); + test_error_mutate_func + (spec_l40_log, spec_l40_linear, f); + test_error_mutate_func + (spec_l40_linear, spec_l41_linear, f); + + test_error_mutate_func + (NULL, spec_l40_log, f); + test_error_mutate_func + (spec_l41_linear, NULL, f); + test_error_mutate_func(NULL, NULL, f); + + hdrl_spectrum1D_delete(&spec_l40_linear); + hdrl_spectrum1D_delete(&spec_l41_linear); + + hdrl_spectrum1D_delete(&spec_l40_log); + hdrl_spectrum1D_delete(&spec_l41_log); +} + +static inline hdrl_spectrum1D * get_spectrum1D_sin_shuffled(cpl_size sz, int start, + cpl_boolean add_peak, cpl_array ** unshuffled_lambda){ + + static const double peak = 100.0; + const double delta = 2 * CPL_MATH_PI / sz; + + cpl_array * lambda = cpl_array_new(sz, HDRL_TYPE_DATA); + cpl_image * flux = cpl_image_new(sz, 1, HDRL_TYPE_DATA); + + for(cpl_size i = 0; i < sz; i++){ + double l = delta * (i + start); + double f = fabs(peak * (sin(l) + 1.1)); + + if(i == 4 && add_peak) f *= 1.5; + + cpl_array_set(lambda, i, l); + cpl_image_set(flux, i + 1, 1, f); + } + + if(unshuffled_lambda) + *unshuffled_lambda = cpl_array_duplicate(lambda); + + /* scramble array */ + for(cpl_size i1 = 0; i1 < sz; i1++){ + int rej; + double l1 = cpl_array_get(lambda, i1, &rej); + double f1 = cpl_image_get(flux, i1 + 1, 1, &rej); + + cpl_size i2 = (cpl_size)(rand_0_to_1() * (sz - 1)); + + double l2 = cpl_array_get(lambda, i2, &rej); + double f2 = cpl_image_get(flux, i2 + 1, 1, &rej); + + cpl_array_set(lambda, i1, l2); + cpl_image_set(flux, i1 + 1, 1, f2); + + cpl_array_set(lambda, i2, l1); + cpl_image_set(flux, i2 + 1, 1, f1); + } + + + hdrl_spectrum1D * sp = + hdrl_spectrum1D_create_error_DER_SNR + (flux, 10, lambda, hdrl_spectrum1D_wave_scale_linear); + + cpl_test_nonnull(sp); + cpl_test_eq(get_error_code_and_reset(), CPL_ERROR_NONE); + + + cpl_array_delete(lambda); + cpl_image_delete(flux); + + return sp; +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_strehl-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_strehl-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_strehl-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_strehl-test.c 2017-09-20 10:02:45.000000000 +0000 @@ -0,0 +1,647 @@ +/* + * This file is part of the HDRL + * Copyright (C) 2014 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 + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_strehl.c" +#include "hdrl_strehl.h" +#include "hdrl_test.h" + +#include + +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + + +/*----------------------------------------------------------------------------*/ +/** + @defgroup hdrl_strehl_test Testing of the HDRL Strehl module + */ +/*----------------------------------------------------------------------------*/ + +void hdrl_strehl_test_parlist(void) +{ + /* Test null parameters */ + hdrl_parameter *pFake1 = hdrl_strehl_parameter_create( + 0., 0., 0., 0., 0., 0., 0., 0.); + hdrl_strehl_parameter_verify(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_parameter_delete(pFake1); + + + /* parameter parsing smoketest */ + double wavelength = 1.635e-6; + double m1 = 5.08/2; + double m2 = 5.08/2*0.36; + double psx = 0.0331932/2.; + double psy = 0.0331932/2.; + double r1 = 1.5; + double r2 = 1.5; + double r3 = 2.0; + + + /* Create parameter */ + hdrl_parameter * hpar; + hdrl_parameter * strehl_def = + hdrl_strehl_parameter_create(wavelength, m1, m2, psx, psy, r1, r2, r3); + + + /* Check parameter */ + cpl_test(!hdrl_strehl_parameter_check(pFake1)); + cpl_test( hdrl_strehl_parameter_check(strehl_def)); + cpl_test_error(CPL_ERROR_NONE); + + + /* Gets */ + + cpl_test_eq(hdrl_strehl_parameter_get_wavelength(NULL), -1.); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_wavelength(strehl_def), wavelength); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_m1(NULL), -1.); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_m1(strehl_def), m1); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_m2(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_m2(strehl_def), m2); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_pixel_scale_x(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_pixel_scale_x(strehl_def), psx); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_pixel_scale_y(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_pixel_scale_y(strehl_def), psy); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_flux_radius(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_flux_radius(strehl_def), r1); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_bkg_radius_low(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_bkg_radius_low(strehl_def), r2); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(hdrl_strehl_parameter_get_bkg_radius_high(NULL), -1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(hdrl_strehl_parameter_get_bkg_radius_high(strehl_def), r3); + cpl_test_error(CPL_ERROR_NONE); + + + cpl_parameterlist * strehl = hdrl_strehl_parameter_create_parlist( + "RECIPE", "strehl", strehl_def); + + hdrl_parameter_delete(strehl_def); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(cpl_parameterlist_get_size(strehl), 8); + + hpar = hdrl_strehl_parameter_parse_parlist(strehl, "RECIPE.invalid"); + cpl_test_null(hpar); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hpar = hdrl_strehl_parameter_parse_parlist(strehl, "RECIPE.strehl"); + cpl_parameterlist_delete(strehl); + cpl_test_error(CPL_ERROR_NONE); + { + cpl_test_eq(hdrl_strehl_parameter_get_wavelength(hpar), wavelength); + cpl_test_eq(hdrl_strehl_parameter_get_m1(hpar), m1); + cpl_test_eq(hdrl_strehl_parameter_get_m2(hpar), m2); + cpl_test_eq(hdrl_strehl_parameter_get_pixel_scale_x(hpar), psx); + cpl_test_eq(hdrl_strehl_parameter_get_pixel_scale_y(hpar), psy); + cpl_test_eq(hdrl_strehl_parameter_get_flux_radius(hpar), r1); + cpl_test_eq(hdrl_strehl_parameter_get_bkg_radius_low(hpar), r2); + cpl_test_eq(hdrl_strehl_parameter_get_bkg_radius_high(hpar), r3); + } + + hdrl_parameter_destroy(hpar); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_strehl_compute proper error on null input images + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static hdrl_image* hdrl_strehl_test_gauss_create(void) +{ + + double sig_x = 3.; + double sig_y = 3.; + cpl_size n = 5; + double dmad; + hdrl_image* hgauss; + cpl_image * gauss_data; + cpl_image * gauss_error; + + gauss_data = cpl_image_new(2 * n + 1, 2 * n + 1, CPL_TYPE_DOUBLE); + cpl_image_fill_gaussian(gauss_data, n + 1, n + 1, (double)121.0, sig_x, sig_y); + gauss_error = cpl_image_duplicate(gauss_data); + cpl_image_multiply_scalar(gauss_error, 0); + cpl_image_get_mad(gauss_data, &dmad); + cpl_image_add_scalar(gauss_error, (dmad * CPL_MATH_STD_MAD)); + + hgauss = hdrl_image_create(gauss_data, gauss_error); + cpl_image_delete(gauss_data); + cpl_image_delete(gauss_error); + + return hgauss; +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_strehl_compute proper error on null input images + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_strehl_test_null_input(void) +{ + double w; + + double m1 = 5.08/2; + double m2 = 5.08/2*0.36; + double psx = 0.0331932/2.; + double psy = 0.0331932/2.; + double r1 = 1.5; + double r2 = 1.5; + double r3 = 2.0; + + hdrl_parameter *strehl_param; + hdrl_strehl_result strehl_result; + + /* test functionality - Image null*/ + hdrl_image *hima = NULL; + w = 1.635e-6; + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, psx, psy, r1, r2, r3); + cpl_test(hdrl_strehl_parameter_check(strehl_param)); + strehl_result = hdrl_strehl_compute(hima, strehl_param) ; + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_parameter_delete(strehl_param) ; + cpl_test(isnan(strehl_result.strehl_value.data)); + + /* Strehl Parameter wrong */ + hima = hdrl_image_new(10, 10); + w = -1.; + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, psx, psy, r1, r2, r3); + cpl_test(!hdrl_strehl_parameter_check(strehl_param)); + strehl_result = hdrl_strehl_compute(hima, strehl_param); + cpl_test_error(CPL_ERROR_NULL_INPUT); + hdrl_parameter_delete(strehl_param); + hdrl_image_delete(hima); + cpl_test(isnan(strehl_result.strehl_value.data)); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Check hdrl_strehl_compute proper error on illegal inputs + @return cpl_error_code + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_strehl_test_illegal_input(void) +{ + double w = 1.635e-6; + double m1 = 5.08/2; + double m2 = 5.08/2*0.36; + double psx = 0.0331932/2.; + double psy = 0.0331932/2.; + double r1 = 1.5; + double r2 = 1.5; + double r3 = 2.0; + + hdrl_image * hima = hdrl_strehl_test_gauss_create(); + hdrl_parameter * strehl_param; + + strehl_param = hdrl_strehl_parameter_create(-1, m1, m2, psx, psy, r1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + strehl_param = hdrl_strehl_parameter_create(w, -1, m2, psx, psy, r1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + strehl_param = hdrl_strehl_parameter_create(w, m1, -1, psx, psy, r1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, -1, psy, r1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, psx, -1, r1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, psx, psy, -1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, psx, psy, r1, -1, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + strehl_param = hdrl_strehl_parameter_create(w, m1, m2, psx, psy, r1, r2, -1); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + strehl_param = hdrl_strehl_parameter_create(w, m1, m1 + 1, psx, psy, r1, r2, r3); + cpl_test_null(strehl_param); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_image_delete(hima); + + return cpl_error_get_code(); +} + + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_strehl_test + Testing of hdrl_strehl module + */ +/*----------------------------------------------------------------------------*/ + +void test_psf(void) +{ + double m1 = 8.3 / 2; /* telescope mirror radii [m] */ + double m2 = 1.1 / 2; /* telescope obstruction radii [m] */ + size_t nx = 256; /* PSF image X size */ + size_t ny = 256; /* PSF image Y size */ + size_t hx = nx / 2; /* pixel position of peak (FITS) */ + size_t hy = ny / 2; /* pixel position of peak (FITS) */ + double peak; /* expected PSF peak value */ + int rej; + + + double wavelength = 7.7e-6; /* observing wavelength in [m] */ + double pscale_x = 0.075; /* pixel scale in x [as] */ + double pscale_y = 0.075; /* pixel scale in y [as] */ + + /* exactly centered psf (symmetric) */ + cpl_image * psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y, + hx, hy, + nx, ny); + peak = 0.670695; + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), 1., 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4); + cpl_image_delete(psf); + + /* exactly centered psf (symmetric) one pixel lower in x */ + psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y, + hx - 1, hy, + nx, ny); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), 1., 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 2, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy + 1, &rej), peak, 1e-4); + cpl_image_delete(psf); + + /* centered at origin of pixel -> square block */ + psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y, + hx - 0.5, hy - 0.5, + nx, ny); + peak = 0.821877; + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4); + cpl_image_delete(psf); + + /* + .75 / 0.25 */ + psf = compute_psf(wavelength, m1, m2, pscale_x, pscale_y, + hx + .75, hy + .25, + nx, ny); + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), 0.781698, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), 0.255305, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), 0.411749, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), 0.952739, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), 0.636695, 1e-4); + cpl_image_delete(psf); + + /* centered at origin of pixel -> square block + * asymmetric pixel scale */ + psf = compute_psf(wavelength, m1, m2, pscale_x, 0.025, + hx - 0.5, hy - 0.5, + nx, ny); + peak = 0.897496; + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4); + /* x direction tails */ + peak = 0.383906; + cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx + 1, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 2, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 2, hy - 1, &rej), peak, 1e-4); + /* y direction tails */ + peak = 0.821877; + cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy + 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 2, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 2, &rej), peak, 1e-4); + cpl_image_delete(psf); + + /* exactly centered psf (symmetric) double sampled*/ + hx = nx; /* fits */ + hy = ny; /* fits */ + psf = compute_psf(wavelength, m1, m2, pscale_x / 2., pscale_y / 2., + hx, hx, + nx * 2, ny * 2); + peak = 0.907339; + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), 1., 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4); + cpl_image_delete(psf); + + /* centered at origin of pixel -> square block + * asymmetric pixel scale and image size*/ + ny = 2 * nx; + hx = nx / 2; /* fits */ + hy = ny / 2; /* fits */ + psf = compute_psf(wavelength, m1, m2, pscale_x, 0.025, + hx - 0.5, hy - 0.5, + nx, ny); + peak = 0.897496; + cpl_test_abs(cpl_image_get(psf, hx, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy, &rej), peak, 1e-4); + /* x direction tails */ + peak = 0.383906; + cpl_test_abs(cpl_image_get(psf, hx + 1, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx + 1, hy - 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 2, hy, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 2, hy - 1, &rej), peak, 1e-4); + /* y direction tails */ + peak = 0.821877; + cpl_test_abs(cpl_image_get(psf, hx, hy + 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy + 1, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx, hy - 2, &rej), peak, 1e-4); + cpl_test_abs(cpl_image_get(psf, hx - 1, hy - 2, &rej), peak, 1e-4); + cpl_image_delete(psf); +} + + +void test_strehl_with_bkg(void) +{ + hdrl_image * himg; + cpl_image * img; + hdrl_strehl_result r; + /* TODO add more unit tests */ + double m1 = 8.3 / 2; + double m2 = 1.1 / 2; + size_t nx = 256; + size_t ny = 256; + double lam = 7.7e-6; + /* oversampled image, 0.075 would be about 2*nyquist */ + double pscale = 0.03; + + /* realistic bkg slope */ + double slope_x = 1. / nx * 100; + + img = compute_psf(lam, m1, m2, pscale, pscale, nx / 2., ny / 2., nx, ny); + + /* we multiply for a large factor to make sure that the psf has high S/N */ + cpl_image_multiply_scalar(img, 2000.); + + /* create a background image with a simple slope along X direction */ + cpl_image *bkg = cpl_image_duplicate(img); + cpl_image_multiply_scalar(bkg, 0); + double *pbkg=cpl_image_get_data_double(bkg); + + + for(size_t j = 0; j < ny; j++) { + for(size_t i = 0; i < nx; i++) { + pbkg[i+nx*j] = i * slope_x; + } + } + cpl_image_add(img, bkg); + /* + cpl_image_save(img, "data.fits", CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT); + cpl_image_save(bkg, "bkg.fits", CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT); + */ + + himg = hdrl_image_create(img, NULL); + + /* upsampling/downsampling introduces an error */ + double rel = 0.015; + + /* real test starts here: we need to subtract bkg from proper region */ + r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 2.5, 3.0); + cpl_test_abs(r.strehl_value.data, 1.0, rel); + + hdrl_image_delete(himg); + cpl_image_delete(img); + cpl_image_delete(bkg); + +} + +void test_strehl(void) +{ + hdrl_image * himg; + cpl_image * img; + hdrl_strehl_result r; + /* TODO add more unit tests */ + double m1 = 8.3 / 2; + double m2 = 1.1 / 2; + size_t nx = 256; + size_t ny = 256; + double lam = 7.7e-6; + /* oversampled image, 0.075 would be about 2*nyquist */ + double pscale = 0.03; + img = compute_psf(lam, m1, m2, pscale, pscale, + nx / 2, ny / 2, nx, ny); + himg = hdrl_image_create(img, NULL); + + /* add unmasked larger maximum */ + hdrl_image_set_pixel(himg, 28, 231, (hdrl_value){1.5, 1.5}); + + /* bad background */ + compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, -1, 4.); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, 4., -1); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + + compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, 5, 5); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_mask_not(hdrl_image_get_mask(himg)); + + compute_strehl(himg, lam, m1, m2, pscale, pscale, 1.5, 5, 6); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + cpl_mask_not(hdrl_image_get_mask(himg)); + + /* upsampling/downsampling introduces an error */ + double rel = 0.015; + + r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, -1, -1); + cpl_test_abs(r.strehl_value.data, 1.0, rel); + cpl_test_abs(r.star_x, nx / 2., rel); + cpl_test_abs(r.star_y, nx / 2., rel); + + /* test with background */ + hdrl_image_add_scalar(himg, (hdrl_value){5., 0.}); + r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 2, 3); + cpl_test_abs(r.strehl_value.data, 1.0, rel); + cpl_test_abs(r.star_background.data, 5.0, rel); + cpl_test_abs(r.star_background.error, 0., rel); + + /* test with bad pixel in background */ + hdrl_image_set_pixel(himg, 128, 161, (hdrl_value){1e20, 1e20}); + hdrl_image_reject(himg, 128, 161); + r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 2, 3); + cpl_test_abs(r.strehl_value.data, 1.0, rel); + cpl_test_abs(r.star_background.data, 5.0, rel); + cpl_test_abs(r.star_background.error, 0., rel); + + /* test zero background */ + compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, 50, 55); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_image_delete(himg); + cpl_image_delete(img); + + + /* test other psf offsets */ + for (size_t i = 0; i < 10; i++) { + img = compute_psf(lam, m1, m2, pscale, pscale, + nx / 2 + i / 10., ny / 2 + i / 10., nx, ny); + himg = hdrl_image_create(img, NULL); + r = compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, -1, -1); + cpl_test_abs(r.strehl_value.data, 1.0, rel); + hdrl_image_delete(himg); + cpl_image_delete(img); + } + + /* failing fit */ + himg = hdrl_image_new(nx, ny); + compute_strehl(himg, lam, m1, m2, pscale, pscale, .5, -1, -1); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + + hdrl_image_delete(himg); +} + +/* +void test_strehl_data(int argc, char * argv[]) +{ + for (size_t i = 2; i < (size_t)argc; i++) { + hdrl_image * himg; + cpl_image * img; + hdrl_strehl_result r; + cpl_frame * frm = cpl_frame_new(); + cpl_frame_set_filename(frm, argv[i]); + cpl_size next = cpl_frame_get_nextensions(frm); + cpl_frame_delete(frm); + img = cpl_image_load(argv[i], CPL_TYPE_DOUBLE, 0, 0); + double radius = atof(argv[1]); // arcsec + if (next == 0) { + + double dmad; + cpl_image_get_mad(img, &dmad); + // signal/noise + cpl_image * err = cpl_image_duplicate(img); + cpl_image_multiply_scalar(err, 0); + cpl_image_add_scalar(err, (dmad * CPL_MATH_STD_MAD)); + himg = hdrl_image_create(img, err); + cpl_msg_info(cpl_func, "image error %g", (dmad * CPL_MATH_STD_MAD)); + } + else { + cpl_image * err = cpl_image_load(argv[i], CPL_TYPE_DOUBLE, 0, 1); + himg = hdrl_image_create(img, err); + cpl_msg_info(cpl_func, "using ext 1 as error"); + } + if (strstr(argv[i], "_2.fits")) { + r = compute_strehl(himg, 1.635e-6, 5.08/2, 5.08/2*0.36, 0.0331932, + 0.0331932, radius, -1, -1); + } + else if (strstr(argv[i], "_4.fits")) { + r = compute_strehl(himg, 1.635e-6, 5.08/2, 5.08/2*0.36, + 0.0331932/2., 0.0331932/2., radius, -1, -1); + } + else if (strstr(argv[i], ".fits")) { + cpl_msg_warning(cpl_func,"case .fits"); + cpl_image_save(hdrl_image_get_image(himg), "data.fits", + CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT); + cpl_image_save(hdrl_image_get_error(himg), "errs.fits", + CPL_TYPE_FLOAT, NULL, CPL_IO_DEFAULT); + cpl_msg_info(cpl_func,"r1=%g r2=%g r3=%g",radius,-1.,-1.); + cpl_msg_info(cpl_func,"m1=%g m2=%g pscale_x=%g pscale_y=%g", + 8.0,1.12,0.01225,0.01225); + r = compute_strehl(himg, 1.6e-6, 8.0/2, 1.12/2, + 0.01225, 0.01225, radius, 1.5, 2.0); + } + else { + cpl_msg_error(cpl_func, "Unknown pixelscale for %s", argv[i]); + continue; + } + cpl_msg_info(cpl_func, "Strehl for %s: %g", argv[i], r.strehl_value.data); + cpl_test_abs(r.strehl_value.data, 1.0, 0); + cpl_image_delete(img); + } + + +} +*/ + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of hdrl_image + **/ +/*----------------------------------------------------------------------------*/ +int main(int argc, char * argv[]) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_strehl_test_parlist(); + hdrl_strehl_test_null_input(); + hdrl_strehl_test_illegal_input(); + + test_psf(); + test_strehl(); + test_strehl_with_bkg(); + + cpl_msg_debug(cpl_func, "test_strehl_data only for command line " + "(argc=%d, argv=%s). If you need to test images images " + "via command line uncomment the function.", argc, argv[0]); +/* + test_strehl_data(argc, argv); +*/ + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_utils-test.c cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_utils-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/hdrl_utils-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/hdrl_utils-test.c 2017-09-28 08:09:30.000000000 +0000 @@ -0,0 +1,1208 @@ +/* $Id: hdrl_utils-test.c,v 1.11 2013-10-23 10:49:28 jtaylor Exp $ + * + * This file is part of the HDRL + * Copyright (C) 2013 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: jtaylor $ + * $Date: 2013-10-23 10:49:28 $ + * $Revision: 1.11 $ + * $Name: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/*----------------------------------------------------------------------------- + Includes + -----------------------------------------------------------------------------*/ + +#include "hdrl_utils.h" +#include "hdrl_collapse.h" +#include "hdrl_bpm_utils.h" + +#include + +#include +#include +#include +#include + +#ifndef ARRAY_LEN +#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0]) +#endif + + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup hdrl_utils_test Testing of the HDRL utility module + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code hdrl_image_to_vector_test(void) +{ + + { + cpl_vector * v = hdrl_image_to_vector(NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(v); + v = hdrl_image_to_vector(NULL, (void*)1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(v); + } + { + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT); + cpl_vector * v = hdrl_image_to_vector(img, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 5 * 6); + cpl_image_delete(img); + cpl_vector_delete(v); + } + /* empty result */ + { + cpl_image * img = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_image_reject(img, 1, 1); + cpl_vector * v = hdrl_image_to_vector(img, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_null(v); + cpl_image_delete(img); + } + /* bad pixel in image bpm */ + { + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT); + cpl_image_set(img, 3, 5, 100); + cpl_image_reject(img, 3, 5); + cpl_vector * v = hdrl_image_to_vector(img, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 5 * 6 - 1); + cpl_test_eq(cpl_vector_get_sum(v), 0); + cpl_image_delete(img); + cpl_vector_delete(v); + } + /* bad pixel in external bpm */ + { + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT); + cpl_mask * m = cpl_mask_new(5, 6); + cpl_image_set(img, 2, 5, 100); + cpl_image_set(img, 3, 5, 100); + cpl_mask_set(m, 3, 5, CPL_BINARY_1); + cpl_vector * v = hdrl_image_to_vector(img, m); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 5 * 6 - 1); + cpl_test_eq(cpl_vector_get_sum(v), 100); + cpl_image_delete(img); + cpl_mask_delete(m); + cpl_vector_delete(v); + } + /* no cast bad pixel in external bpm */ + { + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_DOUBLE); + cpl_mask * m = cpl_mask_new(5, 6); + cpl_image_set(img, 2, 5, 100.); + cpl_image_set(img, 3, 5, 100.); + cpl_mask_set(m, 3, 5, CPL_BINARY_1); + cpl_vector * v = hdrl_image_to_vector(img, m); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 5 * 6 - 1); + cpl_test_eq(cpl_vector_get_sum(v), 100); + cpl_image_delete(img); + cpl_mask_delete(m); + cpl_vector_delete(v); + } + return cpl_error_get_code(); +} + + +static cpl_error_code hdrl_imagelist_to_vector_test(void) +{ + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_vector * v = hdrl_imagelist_to_vector(NULL, 1, 1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(v); + v = hdrl_imagelist_to_vector(list, 1, 1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(v); + cpl_imagelist_set(list, cpl_image_new(5, 5, CPL_TYPE_INT), 0); + v = hdrl_imagelist_to_vector(list, 0, 0); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(v); + v = hdrl_imagelist_to_vector(list, 0, 1); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(v); + v = hdrl_imagelist_to_vector(list, 1, 0); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(v); + v = hdrl_imagelist_to_vector(list, 10, 3); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(v); + v = hdrl_imagelist_to_vector(list, 3, 10); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(v); + v = hdrl_imagelist_to_vector(list, 10, 10); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(v); + cpl_imagelist_delete(list); + } + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 0); + cpl_vector * v = hdrl_imagelist_to_vector(list, 1, 1); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 1); + cpl_vector_delete(v); + cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 1); + v = hdrl_imagelist_to_vector(list, 1, 1); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 2); + cpl_imagelist_delete(list); + cpl_vector_delete(v); + } + /* empty result */ + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT); + cpl_image_reject(img, 2, 1); + cpl_imagelist_set(list, img, 0); + cpl_imagelist_set(list, cpl_image_duplicate(img), 1); + cpl_vector * v = hdrl_imagelist_to_vector(list, 2, 1); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_null(v); + cpl_imagelist_delete(list); + cpl_vector_delete(v); + } + /* bad pixel in image bpm */ + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT); + cpl_image_set(img, 2, 1, 100); + cpl_imagelist_set(list, cpl_image_duplicate(img), 0); + cpl_imagelist_set(list, cpl_image_duplicate(img), 1); + cpl_image_reject(img, 2, 1); + cpl_imagelist_set(list, img, 2); + /* add a good image so potential uninitialized memory is included */ + cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 3); + cpl_vector * v = hdrl_imagelist_to_vector(list, 2, 1); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 3); + cpl_test_eq(cpl_vector_get_sum(v), 200); + cpl_imagelist_delete(list); + cpl_vector_delete(v); + } + /* no cast bad pixel in image bpm */ + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img, 37); + cpl_image_set(img, 5, 6, 100); + cpl_imagelist_set(list, cpl_image_duplicate(img), 0); + cpl_imagelist_set(list, cpl_image_duplicate(img), 1); + cpl_image_reject(img, 5, 6); + cpl_imagelist_set(list, img, 2); + /* add a good image so potential uninitialized memory is included */ + cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_DOUBLE), 3); + cpl_vector * v = hdrl_imagelist_to_vector(list, 5, 6); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(v), 3); + cpl_test_eq(cpl_vector_get_sum(v), 200); + cpl_imagelist_delete(list); + cpl_vector_delete(v); + } + /* no cast bad pixel in image bpm, full row test */ + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_DOUBLE); + cpl_image_add_scalar(img, 37); + cpl_image_set(img, 5, 6, 100); + cpl_imagelist_set(list, cpl_image_duplicate(img), 0); + cpl_imagelist_set(list, cpl_image_duplicate(img), 1); + cpl_image_reject(img, 5, 6); + cpl_imagelist_set(list, img, 2); + /* add a good image so potential uninitialized memory is included */ + cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_DOUBLE), 3); + cpl_vector * o[5]; + hdrl_imagelist_to_vector_row(list, 6, o, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(o[4]), 3); + cpl_test_eq(cpl_vector_get_sum(o[4]), 200); + cpl_imagelist_delete(list); + for (size_t i = 0; i < 5; i++) { + cpl_vector_delete(o[i]); + } + } + /* no cast bad pixel in image bpm, full row test non-double */ + { + cpl_imagelist * list = cpl_imagelist_new(); + cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT); + cpl_image_add_scalar(img, 37); + cpl_image_set(img, 5, 6, 100); + cpl_imagelist_set(list, cpl_image_duplicate(img), 0); + cpl_imagelist_set(list, cpl_image_duplicate(img), 1); + cpl_image_reject(img, 5, 6); + cpl_imagelist_set(list, img, 2); + /* add a good image so potential uninitialized memory is included */ + cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 3); + cpl_vector * o[5]; + hdrl_imagelist_to_vector_row(list, 6, o, NULL); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_vector_get_size(o[4]), 3); + cpl_test_eq(cpl_vector_get_sum(o[4]), 200); + cpl_imagelist_delete(list); + for (size_t i = 0; i < 5; i++) { + cpl_vector_delete(o[i]); + } + } + return cpl_error_get_code(); +} + +static cpl_error_code hdrl_imagelist_cplwrap(void) +{ + hdrl_imagelist *list = NULL; + cpl_imagelist *data = NULL; + cpl_imagelist *errs = NULL; + + /* Test list null */ + hdrl_imagelist_to_cplwrap(list, &data, &errs); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + /* new list and new data and errs */ + list = hdrl_imagelist_new(); + hdrl_imagelist_to_cplwrap(list, &data, &errs); + cpl_test_error(CPL_ERROR_NONE); + cpl_imagelist_unwrap(data); + cpl_imagelist_unwrap(errs); + + /* Not create new data and errs */ + hdrl_imagelist_to_cplwrap(list, &data, &errs); + cpl_test_error(CPL_ERROR_NONE); + cpl_imagelist_unwrap(data); + cpl_imagelist_unwrap(errs); + + hdrl_imagelist_delete(list); + + + return cpl_error_get_code(); +} + +static cpl_error_code hdrl_normalize_test(void) +{ + cpl_imagelist * data = cpl_imagelist_new(); + cpl_imagelist * errs = cpl_imagelist_new(); + cpl_vector * vnorm_d, * vnorm_e; + cpl_array * acontrib; + + const size_t nz = 23; + const size_t nx = 41; + const size_t ny = 17; + for (size_t i = 0; i < nz; i++) { + cpl_image * img = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_add_scalar(img, i + 1); + cpl_image * err = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + cpl_image_add_scalar(err, i + 1); + cpl_image_divide_scalar(err, 3.); + cpl_imagelist_set(data, img, i); + cpl_imagelist_set(errs, err, i); + } + + + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_mean(); + hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs, + &vnorm_d, &vnorm_e, &acontrib, + NULL); + cpl_array_delete(acontrib); + + /* Unknown mode */ + { + cpl_imagelist * ndata = cpl_imagelist_duplicate(data); + cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs); + hdrl_normalize_imagelist_by_vector(vnorm_d, vnorm_e, + -1, ndata, nerrs); + cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); + cpl_imagelist_delete(ndata); + cpl_imagelist_delete(nerrs); + } + + /* additive */ + { + cpl_imagelist * ndata = cpl_imagelist_duplicate(data); + cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs); + hdrl_normalize_imagelist_by_vector(vnorm_d, vnorm_e, + HDRL_SCALE_ADDITIVE, + ndata, nerrs); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_image_abs(cpl_imagelist_get_const(data, 0), + cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA); + cpl_test_image_abs(cpl_imagelist_get_const(errs, 0), + cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR); + for (size_t i = 1; i < nz; i++) { + cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + double escale = hypot(((i + 1) / 3.) / sqrt(nx * ny), + (1. / 3.) / sqrt(nx * ny)); + cpl_image_add_scalar(expect_e, hypot(escale, (i + 1) / 3.)); + cpl_image_add_scalar(expect_d, 1); + cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i), + HDRL_EPS_DATA); + cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i), + HDRL_EPS_ERROR * 4); + cpl_image_delete(expect_d); + cpl_image_delete(expect_e); + } + cpl_imagelist_delete(ndata); + cpl_imagelist_delete(nerrs); + } + + /* multiplicative */ + { + cpl_imagelist *ndata = cpl_imagelist_duplicate(data); + cpl_imagelist *nerrs = cpl_imagelist_duplicate(errs); + + + /* Simulate scale error (emit warnings) */ + cpl_vector *fake1 = cpl_vector_duplicate(vnorm_d); + cpl_vector *fake2 = cpl_vector_duplicate(vnorm_e); + cpl_imagelist *fake3 = cpl_imagelist_duplicate(ndata); + cpl_imagelist *fake4 = cpl_imagelist_duplicate(nerrs); + cpl_vector_set(fake1, 1, 0.); + cpl_vector_set(fake2, 1, 0.); + hdrl_normalize_imagelist_by_vector(fake1, fake2, + HDRL_SCALE_MULTIPLICATIVE, fake3, fake4); + cpl_vector_delete(fake1); + cpl_vector_delete(fake2); + cpl_imagelist_delete(fake3); + cpl_imagelist_delete(fake4); + + + /* Normal work */ + hdrl_normalize_imagelist_by_vector(vnorm_d, vnorm_e, + HDRL_SCALE_MULTIPLICATIVE, + ndata, nerrs); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_image_abs(cpl_imagelist_get_const(data, 0), + cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA); + cpl_test_image_abs(cpl_imagelist_get_const(errs, 0), + cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR); + for (size_t i = 1; i < nz; i++) { + cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + /* off by about 10e-4 due to missing correlation */ + cpl_image_add_scalar(expect_e, 0.3338112308308246); + cpl_image_add_scalar(expect_d, 1.); + cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i), + HDRL_EPS_DATA); + cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i), + HDRL_EPS_ERROR * 4); + cpl_image_delete(expect_d); + cpl_image_delete(expect_e); + } + cpl_imagelist_delete(ndata); + cpl_imagelist_delete(nerrs); + } + + cpl_imagelist_delete(data); + cpl_imagelist_delete(errs); + cpl_vector_delete(vnorm_d); + cpl_vector_delete(vnorm_e); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + + return cpl_error_get_code(); +} + + +static cpl_error_code hdrl_normalize_image_test(void) +{ + cpl_imagelist * data = cpl_imagelist_new(); + cpl_imagelist * errs = cpl_imagelist_new(); + cpl_imagelist * vnorm_d = cpl_imagelist_new(); + cpl_imagelist * vnorm_e = cpl_imagelist_new(); + cpl_vector * vnorm_d_, * vnorm_e_; + cpl_array * acontrib; + + const size_t nz = 23; + const size_t nx = 41; + const size_t ny = 17; + for (size_t i = 0; i < nz; i++) { + cpl_image * img = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image_add_scalar(img, i + 1); + cpl_image * err = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + cpl_image_add_scalar(err, i + 1); + cpl_image_divide_scalar(err, 3.); + cpl_imagelist_set(data, img, i); + cpl_imagelist_set(errs, err, i); + } + + + hdrl_collapse_imagelist_to_vector_t * vmethod = + hdrl_collapse_imagelist_to_vector_mean(); + hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs, + &vnorm_d_, &vnorm_e_, &acontrib, + NULL); + cpl_array_delete(acontrib); + for (cpl_size i = 0; i < cpl_vector_get_size(vnorm_d_); i++) { + cpl_image * dimg = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image * eimg = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + cpl_image_add_scalar(dimg, cpl_vector_get(vnorm_d_, i)); + cpl_image_add_scalar(eimg, cpl_vector_get(vnorm_e_, i)); + cpl_imagelist_set(vnorm_d, dimg, i); + cpl_imagelist_set(vnorm_e, eimg, i); + } + cpl_vector_delete(vnorm_d_); + cpl_vector_delete(vnorm_e_); + + + /* Unknown mode */ + { + cpl_imagelist * ndata = cpl_imagelist_duplicate(data); + cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs); + hdrl_normalize_imagelist_by_imagelist(vnorm_d, vnorm_e, + -1, ndata, nerrs); + cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); + cpl_imagelist_delete(ndata); + cpl_imagelist_delete(nerrs); + } + + /* additive */ + { + cpl_imagelist * ndata = cpl_imagelist_duplicate(data); + cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs); + hdrl_normalize_imagelist_by_imagelist(vnorm_d, vnorm_e, + HDRL_SCALE_ADDITIVE, + ndata, nerrs); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_image_abs(cpl_imagelist_get_const(data, 0), + cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA); + cpl_test_image_abs(cpl_imagelist_get_const(errs, 0), + cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR); + for (size_t i = 1; i < nz; i++) { + cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + double escale = hypot(((i + 1) / 3.) / sqrt(nx * ny), + (1. / 3.) / sqrt(nx * ny)); + cpl_image_add_scalar(expect_e, hypot(escale, (i + 1) / 3.)); + cpl_image_add_scalar(expect_d, 1); + cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i), + HDRL_EPS_DATA); + cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i), + HDRL_EPS_ERROR * 4); + cpl_image_delete(expect_d); + cpl_image_delete(expect_e); + } + cpl_imagelist_delete(ndata); + cpl_imagelist_delete(nerrs); + } + + /* multiplicative */ + { + cpl_imagelist * ndata = cpl_imagelist_duplicate(data); + cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs); + hdrl_normalize_imagelist_by_imagelist(vnorm_d, vnorm_e, + HDRL_SCALE_MULTIPLICATIVE, + ndata, nerrs); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_image_abs(cpl_imagelist_get_const(data, 0), + cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA); + cpl_test_image_abs(cpl_imagelist_get_const(errs, 0), + cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR); + for (size_t i = 1; i < nz; i++) { + cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA); + cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR); + /* off by about 10e-4 due to missing correlation */ + cpl_image_add_scalar(expect_e, 0.3338112308308246); + cpl_image_add_scalar(expect_d, 1.); + cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i), + HDRL_EPS_DATA); + cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i), + HDRL_EPS_ERROR * 4); + cpl_image_delete(expect_d); + cpl_image_delete(expect_e); + } + cpl_imagelist_delete(ndata); + cpl_imagelist_delete(nerrs); + } + + cpl_imagelist_delete(data); + cpl_imagelist_delete(errs); + cpl_imagelist_delete(vnorm_d); + cpl_imagelist_delete(vnorm_e); + hdrl_collapse_imagelist_to_vector_delete(vmethod); + + return cpl_error_get_code(); +} + + + +/* path related smoke tests */ +void hdrl_path_test(void) +{ + char * cwd; + int fd; + + cwd = hdrl_get_cwd(); + cpl_test_nonnull(cwd); + + fd = hdrl_get_tempfile(NULL, CPL_TRUE); + cpl_test(fd >= 0); + close(fd); + +/* + fd = hdrl_get_tempfile(NULL, CPL_FALSE); + cpl_test(fd >= 0); +*/ + + fd = hdrl_get_tempfile(cwd, CPL_TRUE); + cpl_test(fd >= 0); + +/* + fd = hdrl_get_tempfile(cwd, CPL_FALSE); + cpl_test(fd >= 0); +*/ + + cpl_free(cwd); +} + +void hdrl_string_test(void) +{ + char * dummy = NULL; + char * s; + int result; + + s = hdrl_join_string(NULL, 0, "test"); + cpl_test_null(s); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + s = hdrl_join_string(NULL, 1, "test"); + result = strcmp(s, "test"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string(NULL, 2, "test", "bla"); + result = strcmp(s, "testbla"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string(".", 1, "test"); + result = strcmp(s, "test"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string(".", 2, "test", "bla"); + result = strcmp(s, "test.bla"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 3, "test", "bla", "val"); + result = strcmp(s, "test--bla--val"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 3, "", "bla", "val"); + result = strcmp(s, "bla--val"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 3, "test", "", "val"); + result = strcmp(s, "test--val"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string(",", 3, "test", dummy, "val"); + result = strcmp(s, "test,val"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 4, "", dummy, "val", "test"); + result = strcmp(s, "val--test"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 3, dummy, "bla", "val"); + result = strcmp(s, "bla--val"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 3, "test", "bla", ""); + result = strcmp(s, "test--bla"); + cpl_test_zero(result); + cpl_free(s); + + s = hdrl_join_string("--", 3, "test", "bla", dummy); + result = strcmp(s, "test--bla"); + cpl_test_zero(result); + cpl_free(s); +} + + +void hdrl_pfilter_test(void) +{ + cpl_imagelist * list1 = cpl_imagelist_new(); + cpl_imagelist_set(list1, cpl_image_new(5, 5, CPL_TYPE_INT), 0); + cpl_imagelist_set(list1, cpl_image_new(5, 5, CPL_TYPE_INT), 1); + + cpl_imagelist *list2; + + list2 = hdrl_bpm_filter_list(NULL, 5, 5, CPL_FILTER_MEDIAN); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(list2); + + list2 = hdrl_bpm_filter_list(list1, 5, 5, CPL_FILTER_MEDIAN); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(list2); + + cpl_imagelist_delete(list2); + cpl_imagelist_delete(list1); + + size_t nx = 100; + size_t any[] = {13, 22, 47, 100, 103, 104, 202, 203, 204, + 542, 1034, 1239}; + size_t amx[] = {1, 1, 3, 3, 5, 7, 13}; + size_t amy[] = {1, 3, 1, 3, 5, 7, 13}; + for (size_t j = 0; j < ARRAY_LEN(amx); j++) { + cpl_mask * m = cpl_mask_new(amx[j], amy[j]); + cpl_matrix * k = cpl_matrix_new(amx[j], amy[j]); + cpl_mask_not(m); + cpl_matrix_add_scalar(k, 1); + for (size_t i = 0; i < ARRAY_LEN(any); i++) { + size_t ny = any[i]; + cpl_msg_info(cpl_func, "Testing ny %zu mask %zu,%zu", ny, + amx[j], amy[j]); + cpl_image * img = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + double * d = cpl_image_get_data_double(img); + for (size_t kindex = 0; kindex < nx * ny; kindex++) { + d[kindex] = kindex + rand() % 100; + if (i % 2 == 0 && ((int)d[kindex] % 20) == 0) { + cpl_image_reject(img, (rand() % nx) + 1, (rand() % ny) + 1); + } + } + cpl_image * orig_inp = cpl_image_duplicate(img); + cpl_image * ro = cpl_image_duplicate(img); + cpl_image * rp; + + cpl_image_filter_mask(ro, img, m, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER); + rp = hdrl_parallel_filter_image(img, NULL, m, CPL_FILTER_MEDIAN); + cpl_test_image_abs(rp, ro, 0); + /* input unchanged */ + cpl_test_image_abs(img, orig_inp, 0); + cpl_image_delete(rp); + + cpl_image_filter(ro, img, k, CPL_FILTER_LINEAR, CPL_BORDER_FILTER); + rp = hdrl_parallel_filter_image(img, k, NULL, CPL_FILTER_LINEAR); + cpl_test_image_abs(rp, ro, 0); + /* input unchanged */ + cpl_test_image_abs(img, orig_inp, 0); + cpl_image_delete(rp); + + cpl_image_delete(ro); + cpl_image_delete(img); + cpl_image_delete(orig_inp); + } + cpl_mask_delete(m); + cpl_matrix_delete(k); + } +} + +void hdrl_pconvert_test(void) +{ + cpl_size nx = 223; + cpl_size ny = 223; + cpl_propertylist * plist = cpl_propertylist_new(); + cpl_propertylist_update_int(plist, "NAXIS", 2); + cpl_propertylist_update_int(plist, "NAXIS1", nx); + cpl_propertylist_update_int(plist, "NAXIS2", ny); + cpl_propertylist_update_string(plist, "CTYPE1", "RA---ZPN"); + cpl_propertylist_update_string(plist, "CTYPE2", "DEC--ZPN"); + cpl_propertylist_update_double(plist, "CRVAL1", 149.947); + cpl_propertylist_update_double(plist, "CRVAL2", 2.205); + cpl_propertylist_update_double(plist, "CRPIX1", 5401.42); + cpl_propertylist_update_double(plist, "CRPIX2", 6834.89); + cpl_propertylist_update_double(plist, "CD1_1", 1.8072e-07); + cpl_propertylist_update_double(plist, "CD1_2", 9.4796e-05); + cpl_propertylist_update_double(plist, "CD2_1", -9.4820e-05); + cpl_propertylist_update_double(plist, "CD2_2", 2.0167e-07); + cpl_propertylist_update_double(plist, "PV2_1", 1.); + cpl_propertylist_update_double(plist, "PV2_2", 0.); + cpl_propertylist_update_double(plist, "PV2_3", 44.); + cpl_propertylist_update_double(plist, "PV2_4", 0.); + cpl_propertylist_update_double(plist, "PV2_5", -10300.); + cpl_propertylist_update_string(plist, "CUNIT1", "deg"); + cpl_propertylist_update_string(plist, "CUNIT2", "deg"); + + cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist); + cpl_matrix * from = cpl_matrix_new(nx * ny, 2); + for (cpl_size y = 0; y < ny; y++) { + for (cpl_size x = 0; x < nx; x++) { + cpl_matrix_set(from, (y * nx) + x, 0, x); + cpl_matrix_set(from, (y * nx) + x, 1, y); + } + } + cpl_matrix * to, *to2, *toc, *toc2; + cpl_array * status, *statusc; + hdrl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD); + cpl_test_error(CPL_ERROR_NONE); + cpl_wcs_convert(wcs, from, &toc, &statusc, CPL_WCS_PHYS2WORLD); + + cpl_test_matrix_abs(to, toc, 0.); + cpl_test_array_abs(status, statusc, 0.); + cpl_array_delete(status); + cpl_array_delete(statusc); + + hdrl_wcs_convert(wcs, to, &to2, &status, CPL_WCS_WORLD2PHYS); + cpl_test_error(CPL_ERROR_NONE); + cpl_wcs_convert(wcs, to, &toc2, &statusc, CPL_WCS_WORLD2PHYS); + + cpl_test_matrix_abs(to2, toc2, 0.); + cpl_test_array_abs(status, statusc, 0.); + + cpl_matrix_delete(to); + cpl_matrix_delete(toc); + cpl_matrix_delete(to2); + cpl_matrix_delete(toc2); + cpl_array_delete(status); + cpl_array_delete(statusc); + + /* invalid phys as world input */ + hdrl_wcs_convert(wcs, from, &to, &status, CPL_WCS_WORLD2PHYS); + cpl_test_error(CPL_ERROR_UNSPECIFIED); + cpl_wcs_convert(wcs, from, &toc, &statusc, CPL_WCS_WORLD2PHYS); + cpl_test_array_abs(status, statusc, 0.); + + cpl_matrix_delete(to); + cpl_matrix_delete(toc); + cpl_array_delete(status); + cpl_array_delete(statusc); + + /* check error */ + hdrl_wcs_convert(NULL, NULL, NULL, NULL, CPL_WCS_PHYS2WORLD); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_wcs_convert(wcs, from, &to, &status, (cpl_wcs_trans_mode)1421); + cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); + + cpl_propertylist_erase(plist, "NAXIS2"); + cpl_wcs_delete(wcs); + wcs = cpl_wcs_new_from_propertylist(plist); + hdrl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD); + cpl_test_error(CPL_ERROR_UNSPECIFIED); + cpl_matrix_delete(to); + cpl_array_delete(status); + + cpl_propertylist_delete(plist); + cpl_wcs_delete(wcs); + cpl_matrix_delete(from); +} + +static cpl_error_code hdrl_airmass_test(void){ + + cpl_errorstate prestate = cpl_errorstate_get(); + + /* Temporary variables */ + hdrl_value airmass, airmass1, airmass2, airmass3; + + /* Aproximation methods */ + hdrl_airmass_approx typeAirmassAprox1 = HDRL_AIRMASS_APPROX_HARDIE; + hdrl_airmass_approx typeAirmassAprox2 = HDRL_AIRMASS_APPROX_YOUNG_IRVINE; + hdrl_airmass_approx typeAirmassAprox3 = HDRL_AIRMASS_APPROX_YOUNG; + + + /* Input parameters based in MUSE data */ + + hdrl_value ra1 = { 122.994945, 0.}; + hdrl_value dec1 = {74.95304, 0.}; + hdrl_value lst1 = {25407.072748, 0.}; + hdrl_value exptime1 = {120., 0.}; + hdrl_value geolat1 = {37.2236, 0.}; + + hdrl_value ra2 = {238.071555, 0.}; + hdrl_value dec2 = {32.92533, 0.}; + hdrl_value lst2 = {60515.584209, 0.}; + hdrl_value exptime2 = {300., 0.}; + hdrl_value geolat2 = {37.2236, 0.}; + + hdrl_value ra3 = {0.125, 0.}; + hdrl_value dec3 = {-30., 0.}; + hdrl_value lst3 = {69446.2765265328, 0.}; + hdrl_value exptime3 = {3600., 0.}; + hdrl_value geolat3 = {-24.625278, 0.}; + + + /******** Tests of failure cases (HARDIE approx method) ****************/ + + /* Not valid Ra */ + airmass = hdrl_utils_airmass((hdrl_value){-1.,0.}, dec1, lst1, exptime1, geolat1, typeAirmassAprox1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(airmass.data == -1.); + + /* Not valid Dec */ + airmass = hdrl_utils_airmass(ra1, (hdrl_value){180.,0.}, lst1, exptime1, geolat1, typeAirmassAprox1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(airmass.data == -1.); + + /* Not valid Lst */ + airmass = hdrl_utils_airmass(ra1, dec1, (hdrl_value){-1.,0.}, exptime1, geolat1, typeAirmassAprox1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(airmass.data == -1.); + + /* Not valid Exptime */ + airmass = hdrl_utils_airmass(ra1, dec1, lst1, (hdrl_value){-1.,0.}, geolat1, typeAirmassAprox1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(airmass.data == -1.); + + /* Not valid Geolat */ + airmass = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, (hdrl_value){180.,0.}, typeAirmassAprox1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(airmass.data == -1.); + + /* Not valid Airmass Approximation method */ + airmass = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, 0); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test(airmass.data == -1.); + + + /***** Test without error propagation (HARDIE approx method) ***********/ + + airmass1 = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + airmass2 = hdrl_utils_airmass(ra2, dec2, lst2, exptime2, geolat2, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + airmass3 = hdrl_utils_airmass(ra3, dec3, lst3, exptime3, geolat3, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + /* check the result without error propagation */ + + cpl_test(airmass1.data > 1.27803 - 0.001); + cpl_test(airmass1.data < 1.27803 + 0.001); + + cpl_test(airmass2.data > 1.02529 - 0.001); + cpl_test(airmass2.data < 1.02529 + 0.001); + + cpl_test(airmass3.data > 1.79364 - 0.001); + cpl_test(airmass3.data < 1.79364 + 0.001); + + + /****** Tests with error propagation (HARDIE approx method) ************/ + + double delta = 1e-2; + double deltaRa = delta; + double deltaDec = delta; + double deltaLst = delta; + double deltaExptime = delta; + double deltaGeolat = delta; + + ra1.error = deltaRa * fabs(ra1.data); + dec1.error = deltaDec * fabs(dec1.data); + lst1.error = deltaLst * fabs(lst1.data); + exptime1.error = deltaExptime * fabs(exptime1.data); + geolat1.error = deltaGeolat * fabs(geolat1.data); + + ra2.error = deltaRa * fabs(ra2.data); + dec2.error = deltaDec * fabs(dec2.data); + lst2.error = deltaLst * fabs(lst2.data); + exptime2.error = deltaExptime * fabs(exptime2.data); + geolat2.error = deltaGeolat * fabs(geolat2.data); + + ra3.error = deltaRa * fabs(ra3.data); + dec3.error = deltaDec * fabs(dec3.data); + lst3.error = deltaLst * fabs(lst3.data); + exptime3.error = deltaExptime * fabs(exptime3.data); + geolat3.error = deltaGeolat * fabs(geolat3.data); + + airmass1 = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + airmass2 = hdrl_utils_airmass(ra2, dec2, lst2, exptime2, geolat2, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + airmass3 = hdrl_utils_airmass(ra3, dec3, lst3, exptime3, geolat3, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + /* check the result with error propagation */ + + cpl_test(airmass1.data > 1.27803 - 0.001 ); + cpl_test(airmass1.data < 1.27803 + 0.001 ); + cpl_test(airmass1.error > 0.0136602 - 0.0001); + cpl_test(airmass1.error < 0.0136602 + 0.0001); + + cpl_test(airmass2.data > 1.02529 - 0.001 ); + cpl_test(airmass2.data < 1.02529 + 0.001 ); + cpl_test(airmass2.error > 0.0216347 - 0.0001); + cpl_test(airmass2.error < 0.0216347 + 0.0001); + + cpl_test(airmass3.data > 1.79364 - 0.001 ); + cpl_test(airmass3.data < 1.79364 + 0.001 ); + cpl_test(airmass3.error > 0.128632 - 0.0001); + cpl_test(airmass3.error < 0.128631 + 0.0001); + + + /*** Test with different kinds of approximation and error propagation ***/ + + airmass1 = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, typeAirmassAprox1); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + airmass2 = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, typeAirmassAprox2); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + airmass3 = hdrl_utils_airmass(ra1, dec1, lst1, exptime1, geolat1, typeAirmassAprox3); + cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE); + + + /* check the result with error propagation and different approximations */ + + cpl_test(airmass1.data > 1.27803 - 0.001 ); + cpl_test(airmass1.data < 1.27803 + 0.001 ); + cpl_test(airmass1.error > 0.0136602 - 0.0001); + cpl_test(airmass1.error < 0.0136602 + 0.0001); + + cpl_test(airmass2.data > 1.2778 - 0.001 ); + cpl_test(airmass2.data < 1.2778 + 0.001 ); + cpl_test(airmass2.error > 0.0135473 - 0.0001); + cpl_test(airmass2.error < 0.0135473 + 0.0001); + + cpl_test(airmass3.data > 1.27755 - 0.001 ); + cpl_test(airmass3.data < 1.27755 + 0.001 ); + cpl_test(airmass3.error > 0.0135339 - 0.0001); + cpl_test(airmass3.error < 0.0135339 + 0.0001); + + + return cpl_error_get_code(); +} + +static cpl_error_code hdrl_license_test(void) +{ + const char* str = hdrl_get_license(); + cpl_test_nonnull(str); + + return cpl_error_get_code(); +} + +static cpl_error_code hdrl_region_test(void) +{ + /* Test wrong hdrl_parameter */ + hdrl_parameter* pFake = hdrl_collapse_mean_parameter_create(); + hdrl_rect_region_parameter_verify(pFake, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + /* Test error verify */ + hdrl_parameter* pErr1 = hdrl_rect_region_parameter_create( 0, 1, 10, 10); + hdrl_parameter* pErr2 = hdrl_rect_region_parameter_create( 1, 0, 10, 10); + hdrl_parameter* pErr3 = hdrl_rect_region_parameter_create( 1, 1, 0, 10); + hdrl_parameter* pErr4 = hdrl_rect_region_parameter_create( 1, 1, 10, 0); + hdrl_parameter* pErr5 = hdrl_rect_region_parameter_create(10, 1, 1, 10); + hdrl_parameter* pErr6 = hdrl_rect_region_parameter_create( 1, 10, 10, 1); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_rect_region_parameter_verify(NULL, 10, 10); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_rect_region_parameter_verify(pErr1, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_parameter_verify(pErr2, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_parameter_verify(pErr3, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_parameter_verify(pErr4, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_parameter_verify(pErr5, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_parameter_verify(pErr6, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + + /* Correct verify */ + hdrl_parameter* p = hdrl_rect_region_parameter_create(1, 1, 10, 10); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(p); + + hdrl_rect_region_parameter_check(p); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_rect_region_parameter_update(p, 1, 1, 20, 20); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_rect_region_parameter_verify(p, 10, 20); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_parameter_verify(p, 20, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_get_llx(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_size llx = hdrl_rect_region_get_llx(p); + cpl_test_eq(llx, 1); + + hdrl_rect_region_get_lly(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_size lly = hdrl_rect_region_get_lly(p); + cpl_test_eq(lly, 1); + + hdrl_rect_region_get_urx(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_size urx = hdrl_rect_region_get_urx(p); + cpl_test_eq(urx, 20); + + hdrl_rect_region_get_ury(NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_size ury = hdrl_rect_region_get_ury(p); + cpl_test_eq(ury, 20); + + + + /* Test null parameters */ + + cpl_parameterlist *plist = hdrl_rect_region_parameter_create_parlist( + NULL, "test", "region-", p); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plist); + + plist = hdrl_rect_region_parameter_create_parlist( + "RECIPE", NULL, "region-", p); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plist); + + plist = hdrl_rect_region_parameter_create_parlist( + "RECIPE", "test", NULL, p); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plist); + + plist = hdrl_rect_region_parameter_create_parlist( + "RECIPE", "test", "region-", NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(plist); + + + /* Wrong parse */ + cpl_parameterlist *plFake = hdrl_rect_region_parameter_create_parlist( + "RECIPE", "test", "region-", pFake); + cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_null(plFake); + hdrl_parameter_delete(pFake); + + + cpl_parameterlist *plist1 = hdrl_rect_region_parameter_create_parlist( + "RECIPE", "test", "region-", p); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plist1); + + hdrl_parameter *out1 = hdrl_rect_region_parameter_parse_parlist( + NULL, "test", "region-"); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out1); + + out1 = hdrl_rect_region_parameter_parse_parlist( + plist1, NULL, "region-"); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(out1); + + out1 = hdrl_rect_region_parameter_parse_parlist( + plist1, "test", NULL); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + cpl_test_null(out1); + + out1 = hdrl_rect_region_parameter_parse_parlist( + plist1, "test", "region-"); + cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); + cpl_test_null(out1); + + + /* Right parse */ + cpl_parameterlist *plist2 = hdrl_rect_region_parameter_create_parlist( + "test", "", "region-", p); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plist2); + + hdrl_parameter *out2 = hdrl_rect_region_parameter_parse_parlist( + plist2, "test", "region-"); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(out2); + + + /* Region Fix negatives */ + + hdrl_rect_region_fix_negatives(NULL, 10, 10); + cpl_test_error(CPL_ERROR_NULL_INPUT); + + hdrl_parameter* pFake2 = hdrl_collapse_mean_parameter_create(); + hdrl_rect_region_fix_negatives(pFake2, 10, 10); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + hdrl_parameter_delete(pFake2); + + hdrl_rect_region_fix_negatives(p, 0, 0); + cpl_test_error(CPL_ERROR_NONE); + + hdrl_parameter* pErr = hdrl_rect_region_parameter_create(-1, -1, -1, -1); + + hdrl_rect_region_fix_negatives(pErr, 0, 0); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + + hdrl_rect_region_fix_negatives(pErr, 2, 2); + cpl_test_error(CPL_ERROR_NONE); + + + /* Clean up */ + cpl_parameterlist_delete(plist1); + cpl_parameterlist_delete(plist2); + + hdrl_parameter_delete(pErr1); + hdrl_parameter_delete(pErr2); + hdrl_parameter_delete(pErr3); + hdrl_parameter_delete(pErr4); + hdrl_parameter_delete(pErr5); + hdrl_parameter_delete(pErr6); + hdrl_parameter_delete(pErr); + + hdrl_parameter_delete(p); + hdrl_parameter_delete(out1); + hdrl_parameter_delete(out2); + + return cpl_error_get_code(); +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Unit tests of utility module + **/ +/*----------------------------------------------------------------------------*/ +int main(void) +{ + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + hdrl_image_to_vector_test(); + hdrl_imagelist_to_vector_test(); + hdrl_imagelist_cplwrap(); + hdrl_normalize_test(); + hdrl_normalize_image_test(); + hdrl_path_test(); + hdrl_string_test(); + hdrl_pfilter_test(); + hdrl_pconvert_test(); + hdrl_airmass_test(); + hdrl_license_test(); + hdrl_region_test(); + + return cpl_test_end(0); +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/Makefile.am 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/Makefile.am 2017-09-20 10:02:45.000000000 +0000 @@ -0,0 +1,121 @@ +## Process this file with automake to produce Makefile.in + +## This file is part of the ESO Common Pipeline Library +## Copyright (C) 2012,2013 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 + + +AUTOMAKE_OPTIONS = 1.8 foreign + +DISTCLEANFILES = *~ + +if MAINTAINER_MODE + +MAINTAINERCLEANFILES = $(srcdir)/Makefile.in + +endif + +AM_CPPFLAGS = $(CPL_INCLUDES) $(HDRL_INCLUDES) -DHDRL_USE_PRIVATE +AM_LDFLAGS = $(CPL_LDFLAGS) $(HDRL_LDFLAGS) + +LDADD = ../libhdrl.la $(LIBCPLCORE) $(LIBCPLDFS) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCEXT) -lgsl -lgslcblas -lm + +check_PROGRAMS = hdrl_buffer-test \ + hdrl_overscan-test \ + hdrl_sigclip-test \ + hdrl_utils-test \ + hdrl_combine-test \ + hdrl_bpm_2d-test \ + hdrl_bpm_3d-test \ + hdrl_bpm_fit-test \ + hdrl_bpm_utils-test \ + hdrl_collapse-test \ + hdrl_image-test \ + hdrl_imagelist_io-test \ + hdrl_imagelist_basic-test \ + hdrl_imagelist_view-test \ + hdrl_elemop-test \ + hdrl_parameter-test \ + hdrl_fit-test \ + hdrl_strehl-test \ + hdrl_lacosmics-test \ + hdrl_fringe-test \ + hdrl_catalogue-test \ + hdrl_random-test \ + hdrl_frameiter-test \ + hdrl_flat-test \ + hdrl_spectrum1d-test \ + hdrl_spectrum1d_shift-test \ + hdrl_spectrum1dlist-test \ + hdrl_efficiency-test \ + hdrl_response-test \ + hdrl_der_snr-test \ + hdrl_dar-test \ + hdrl_prototyping-test \ + hdrl_multiiter-test \ + hdrl_correlation-test + +hdrl_overscan_test_SOURCES = hdrl_overscan-test.c +hdrl_sigclip_test_SOURCES = hdrl_sigclip-test.c +hdrl_utils_test_SOURCES = hdrl_utils-test.c +hdrl_combine_test_SOURCES = hdrl_combine-test.c +hdrl_bpm_2d_test_SOURCES = hdrl_bpm_2d-test.c +hdrl_bpm_3d_test_SOURCES = hdrl_bpm_3d-test.c +hdrl_bpm_fit_test_SOURCES = hdrl_bpm_fit-test.c +hdrl_bpm_utils_test_SOURCES = hdrl_bpm_utils-test.c +hdrl_collapse_test_SOURCES = hdrl_collapse-test.c +hdrl_image_test_SOURCES = hdrl_image-test.c +hdrl_imagelist_io_test_SOURCES = hdrl_imagelist_io-test.c +hdrl_imagelist_basic_test_SOURCES = hdrl_imagelist_basic-test.c +hdrl_imagelist_view_test_SOURCES = hdrl_imagelist_view-test.c +hdrl_elemop_test_SOURCES = hdrl_elemop-test.c +hdrl_parameter_test_SOURCES = hdrl_parameter-test.c +hdrl_buffer_test_SOURCES = hdrl_buffer-test.c +hdrl_fit_test_SOURCES = hdrl_fit-test.c +hdrl_strehl_test_SOURCES = hdrl_strehl-test.c +hdrl_lacosmics_test_SOURCES = hdrl_lacosmics-test.c +hdrl_fringe_test_SOURCES = hdrl_fringe-test.c +hdrl_catalogue_test_SOURCES = hdrl_catalogue-test.c +hdrl_random_test_SOURCES = hdrl_random-test.c +hdrl_frameiter_test_SOURCES = hdrl_frameiter-test.c +hdrl_flat_test_SOURCES = hdrl_flat-test.c +hdrl_spectrum1d_test_SOURCES = hdrl_spectrum1d-test.c +hdrl_spectrum1dlist_test_SOURCES = hdrl_spectrum1dlist-test.c +hdrl_der_snr_test_SOURCES = hdrl_der_snr-test.c +hdrl_efficiency_test_SOURCES = hdrl_efficiency-test.c +hdrl_response_test_SOURCES = hdrl_response-test.c +hdrl_correlation_test_SOURCES = hdrl_correlation-test.c +hdrl_spectrum1d_shift_test_SOURCES = hdrl_spectrum1d_shift-test.c +hdrl_dar_test_SOURCES = hdrl_dar-test.c +hdrl_prototyping_test_SOURCES = hdrl_prototyping-test.c +hdrl_multiiter_test_SOURCES = hdrl_multiiter-test.c + +# Be sure to reexport important environment variables. +TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \ + LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \ + OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \ + MALLOC_PERTURB_=31 MALLOC_CHECK_=2 \ + GOMP_SPINCOUNT=10000 + +TESTS = $(check_PROGRAMS) + +# Expected failures +XFAIL_TESTS = + +# We need to remove any files that the above tests created. +clean-local: + $(RM) *.fits *.tfits *.log diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/hdrl/tests/Makefile.in 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/hdrl/tests/Makefile.in 2018-04-13 15:46:32.000000000 +0000 @@ -0,0 +1,1719 @@ +# Makefile.in generated by automake 1.15 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2014 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +check_PROGRAMS = hdrl_buffer-test$(EXEEXT) hdrl_overscan-test$(EXEEXT) \ + hdrl_sigclip-test$(EXEEXT) hdrl_utils-test$(EXEEXT) \ + hdrl_combine-test$(EXEEXT) hdrl_bpm_2d-test$(EXEEXT) \ + hdrl_bpm_3d-test$(EXEEXT) hdrl_bpm_fit-test$(EXEEXT) \ + hdrl_bpm_utils-test$(EXEEXT) hdrl_collapse-test$(EXEEXT) \ + hdrl_image-test$(EXEEXT) hdrl_imagelist_io-test$(EXEEXT) \ + hdrl_imagelist_basic-test$(EXEEXT) \ + hdrl_imagelist_view-test$(EXEEXT) hdrl_elemop-test$(EXEEXT) \ + hdrl_parameter-test$(EXEEXT) hdrl_fit-test$(EXEEXT) \ + hdrl_strehl-test$(EXEEXT) hdrl_lacosmics-test$(EXEEXT) \ + hdrl_fringe-test$(EXEEXT) hdrl_catalogue-test$(EXEEXT) \ + hdrl_random-test$(EXEEXT) hdrl_frameiter-test$(EXEEXT) \ + hdrl_flat-test$(EXEEXT) hdrl_spectrum1d-test$(EXEEXT) \ + hdrl_spectrum1d_shift-test$(EXEEXT) \ + hdrl_spectrum1dlist-test$(EXEEXT) \ + hdrl_efficiency-test$(EXEEXT) hdrl_response-test$(EXEEXT) \ + hdrl_der_snr-test$(EXEEXT) hdrl_dar-test$(EXEEXT) \ + hdrl_prototyping-test$(EXEEXT) hdrl_multiiter-test$(EXEEXT) \ + hdrl_correlation-test$(EXEEXT) +XFAIL_TESTS = +subdir = tests +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/libtool.m4 \ + $(top_srcdir)/m4macros/ltoptions.m4 \ + $(top_srcdir)/m4macros/ltsugar.m4 \ + $(top_srcdir)/m4macros/ltversion.m4 \ + $(top_srcdir)/m4macros/lt~obsolete.m4 \ + $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/m4macros/cpl-pipeline.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am_hdrl_bpm_2d_test_OBJECTS = hdrl_bpm_2d-test.$(OBJEXT) +hdrl_bpm_2d_test_OBJECTS = $(am_hdrl_bpm_2d_test_OBJECTS) +hdrl_bpm_2d_test_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +hdrl_bpm_2d_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +am_hdrl_bpm_3d_test_OBJECTS = hdrl_bpm_3d-test.$(OBJEXT) +hdrl_bpm_3d_test_OBJECTS = $(am_hdrl_bpm_3d_test_OBJECTS) +hdrl_bpm_3d_test_LDADD = $(LDADD) +hdrl_bpm_3d_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_bpm_fit_test_OBJECTS = hdrl_bpm_fit-test.$(OBJEXT) +hdrl_bpm_fit_test_OBJECTS = $(am_hdrl_bpm_fit_test_OBJECTS) +hdrl_bpm_fit_test_LDADD = $(LDADD) +hdrl_bpm_fit_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_bpm_utils_test_OBJECTS = hdrl_bpm_utils-test.$(OBJEXT) +hdrl_bpm_utils_test_OBJECTS = $(am_hdrl_bpm_utils_test_OBJECTS) +hdrl_bpm_utils_test_LDADD = $(LDADD) +hdrl_bpm_utils_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_buffer_test_OBJECTS = hdrl_buffer-test.$(OBJEXT) +hdrl_buffer_test_OBJECTS = $(am_hdrl_buffer_test_OBJECTS) +hdrl_buffer_test_LDADD = $(LDADD) +hdrl_buffer_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_catalogue_test_OBJECTS = hdrl_catalogue-test.$(OBJEXT) +hdrl_catalogue_test_OBJECTS = $(am_hdrl_catalogue_test_OBJECTS) +hdrl_catalogue_test_LDADD = $(LDADD) +hdrl_catalogue_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_collapse_test_OBJECTS = hdrl_collapse-test.$(OBJEXT) +hdrl_collapse_test_OBJECTS = $(am_hdrl_collapse_test_OBJECTS) +hdrl_collapse_test_LDADD = $(LDADD) +hdrl_collapse_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_combine_test_OBJECTS = hdrl_combine-test.$(OBJEXT) +hdrl_combine_test_OBJECTS = $(am_hdrl_combine_test_OBJECTS) +hdrl_combine_test_LDADD = $(LDADD) +hdrl_combine_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_correlation_test_OBJECTS = hdrl_correlation-test.$(OBJEXT) +hdrl_correlation_test_OBJECTS = $(am_hdrl_correlation_test_OBJECTS) +hdrl_correlation_test_LDADD = $(LDADD) +hdrl_correlation_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_dar_test_OBJECTS = hdrl_dar-test.$(OBJEXT) +hdrl_dar_test_OBJECTS = $(am_hdrl_dar_test_OBJECTS) +hdrl_dar_test_LDADD = $(LDADD) +hdrl_dar_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_der_snr_test_OBJECTS = hdrl_der_snr-test.$(OBJEXT) +hdrl_der_snr_test_OBJECTS = $(am_hdrl_der_snr_test_OBJECTS) +hdrl_der_snr_test_LDADD = $(LDADD) +hdrl_der_snr_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_efficiency_test_OBJECTS = hdrl_efficiency-test.$(OBJEXT) +hdrl_efficiency_test_OBJECTS = $(am_hdrl_efficiency_test_OBJECTS) +hdrl_efficiency_test_LDADD = $(LDADD) +hdrl_efficiency_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_elemop_test_OBJECTS = hdrl_elemop-test.$(OBJEXT) +hdrl_elemop_test_OBJECTS = $(am_hdrl_elemop_test_OBJECTS) +hdrl_elemop_test_LDADD = $(LDADD) +hdrl_elemop_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_fit_test_OBJECTS = hdrl_fit-test.$(OBJEXT) +hdrl_fit_test_OBJECTS = $(am_hdrl_fit_test_OBJECTS) +hdrl_fit_test_LDADD = $(LDADD) +hdrl_fit_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_flat_test_OBJECTS = hdrl_flat-test.$(OBJEXT) +hdrl_flat_test_OBJECTS = $(am_hdrl_flat_test_OBJECTS) +hdrl_flat_test_LDADD = $(LDADD) +hdrl_flat_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_frameiter_test_OBJECTS = hdrl_frameiter-test.$(OBJEXT) +hdrl_frameiter_test_OBJECTS = $(am_hdrl_frameiter_test_OBJECTS) +hdrl_frameiter_test_LDADD = $(LDADD) +hdrl_frameiter_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_fringe_test_OBJECTS = hdrl_fringe-test.$(OBJEXT) +hdrl_fringe_test_OBJECTS = $(am_hdrl_fringe_test_OBJECTS) +hdrl_fringe_test_LDADD = $(LDADD) +hdrl_fringe_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_image_test_OBJECTS = hdrl_image-test.$(OBJEXT) +hdrl_image_test_OBJECTS = $(am_hdrl_image_test_OBJECTS) +hdrl_image_test_LDADD = $(LDADD) +hdrl_image_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_imagelist_basic_test_OBJECTS = \ + hdrl_imagelist_basic-test.$(OBJEXT) +hdrl_imagelist_basic_test_OBJECTS = \ + $(am_hdrl_imagelist_basic_test_OBJECTS) +hdrl_imagelist_basic_test_LDADD = $(LDADD) +hdrl_imagelist_basic_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_imagelist_io_test_OBJECTS = hdrl_imagelist_io-test.$(OBJEXT) +hdrl_imagelist_io_test_OBJECTS = $(am_hdrl_imagelist_io_test_OBJECTS) +hdrl_imagelist_io_test_LDADD = $(LDADD) +hdrl_imagelist_io_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_imagelist_view_test_OBJECTS = \ + hdrl_imagelist_view-test.$(OBJEXT) +hdrl_imagelist_view_test_OBJECTS = \ + $(am_hdrl_imagelist_view_test_OBJECTS) +hdrl_imagelist_view_test_LDADD = $(LDADD) +hdrl_imagelist_view_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_lacosmics_test_OBJECTS = hdrl_lacosmics-test.$(OBJEXT) +hdrl_lacosmics_test_OBJECTS = $(am_hdrl_lacosmics_test_OBJECTS) +hdrl_lacosmics_test_LDADD = $(LDADD) +hdrl_lacosmics_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_multiiter_test_OBJECTS = hdrl_multiiter-test.$(OBJEXT) +hdrl_multiiter_test_OBJECTS = $(am_hdrl_multiiter_test_OBJECTS) +hdrl_multiiter_test_LDADD = $(LDADD) +hdrl_multiiter_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_overscan_test_OBJECTS = hdrl_overscan-test.$(OBJEXT) +hdrl_overscan_test_OBJECTS = $(am_hdrl_overscan_test_OBJECTS) +hdrl_overscan_test_LDADD = $(LDADD) +hdrl_overscan_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_parameter_test_OBJECTS = hdrl_parameter-test.$(OBJEXT) +hdrl_parameter_test_OBJECTS = $(am_hdrl_parameter_test_OBJECTS) +hdrl_parameter_test_LDADD = $(LDADD) +hdrl_parameter_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_prototyping_test_OBJECTS = hdrl_prototyping-test.$(OBJEXT) +hdrl_prototyping_test_OBJECTS = $(am_hdrl_prototyping_test_OBJECTS) +hdrl_prototyping_test_LDADD = $(LDADD) +hdrl_prototyping_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_random_test_OBJECTS = hdrl_random-test.$(OBJEXT) +hdrl_random_test_OBJECTS = $(am_hdrl_random_test_OBJECTS) +hdrl_random_test_LDADD = $(LDADD) +hdrl_random_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_response_test_OBJECTS = hdrl_response-test.$(OBJEXT) +hdrl_response_test_OBJECTS = $(am_hdrl_response_test_OBJECTS) +hdrl_response_test_LDADD = $(LDADD) +hdrl_response_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_sigclip_test_OBJECTS = hdrl_sigclip-test.$(OBJEXT) +hdrl_sigclip_test_OBJECTS = $(am_hdrl_sigclip_test_OBJECTS) +hdrl_sigclip_test_LDADD = $(LDADD) +hdrl_sigclip_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_spectrum1d_test_OBJECTS = hdrl_spectrum1d-test.$(OBJEXT) +hdrl_spectrum1d_test_OBJECTS = $(am_hdrl_spectrum1d_test_OBJECTS) +hdrl_spectrum1d_test_LDADD = $(LDADD) +hdrl_spectrum1d_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_spectrum1d_shift_test_OBJECTS = \ + hdrl_spectrum1d_shift-test.$(OBJEXT) +hdrl_spectrum1d_shift_test_OBJECTS = \ + $(am_hdrl_spectrum1d_shift_test_OBJECTS) +hdrl_spectrum1d_shift_test_LDADD = $(LDADD) +hdrl_spectrum1d_shift_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_spectrum1dlist_test_OBJECTS = \ + hdrl_spectrum1dlist-test.$(OBJEXT) +hdrl_spectrum1dlist_test_OBJECTS = \ + $(am_hdrl_spectrum1dlist_test_OBJECTS) +hdrl_spectrum1dlist_test_LDADD = $(LDADD) +hdrl_spectrum1dlist_test_DEPENDENCIES = ../libhdrl.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am_hdrl_strehl_test_OBJECTS = hdrl_strehl-test.$(OBJEXT) +hdrl_strehl_test_OBJECTS = $(am_hdrl_strehl_test_OBJECTS) +hdrl_strehl_test_LDADD = $(LDADD) +hdrl_strehl_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +am_hdrl_utils_test_OBJECTS = hdrl_utils-test.$(OBJEXT) +hdrl_utils_test_OBJECTS = $(am_hdrl_utils_test_OBJECTS) +hdrl_utils_test_LDADD = $(LDADD) +hdrl_utils_test_DEPENDENCIES = ../libhdrl.la $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/admin/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(hdrl_bpm_2d_test_SOURCES) $(hdrl_bpm_3d_test_SOURCES) \ + $(hdrl_bpm_fit_test_SOURCES) $(hdrl_bpm_utils_test_SOURCES) \ + $(hdrl_buffer_test_SOURCES) $(hdrl_catalogue_test_SOURCES) \ + $(hdrl_collapse_test_SOURCES) $(hdrl_combine_test_SOURCES) \ + $(hdrl_correlation_test_SOURCES) $(hdrl_dar_test_SOURCES) \ + $(hdrl_der_snr_test_SOURCES) $(hdrl_efficiency_test_SOURCES) \ + $(hdrl_elemop_test_SOURCES) $(hdrl_fit_test_SOURCES) \ + $(hdrl_flat_test_SOURCES) $(hdrl_frameiter_test_SOURCES) \ + $(hdrl_fringe_test_SOURCES) $(hdrl_image_test_SOURCES) \ + $(hdrl_imagelist_basic_test_SOURCES) \ + $(hdrl_imagelist_io_test_SOURCES) \ + $(hdrl_imagelist_view_test_SOURCES) \ + $(hdrl_lacosmics_test_SOURCES) $(hdrl_multiiter_test_SOURCES) \ + $(hdrl_overscan_test_SOURCES) $(hdrl_parameter_test_SOURCES) \ + $(hdrl_prototyping_test_SOURCES) $(hdrl_random_test_SOURCES) \ + $(hdrl_response_test_SOURCES) $(hdrl_sigclip_test_SOURCES) \ + $(hdrl_spectrum1d_test_SOURCES) \ + $(hdrl_spectrum1d_shift_test_SOURCES) \ + $(hdrl_spectrum1dlist_test_SOURCES) \ + $(hdrl_strehl_test_SOURCES) $(hdrl_utils_test_SOURCES) +DIST_SOURCES = $(hdrl_bpm_2d_test_SOURCES) $(hdrl_bpm_3d_test_SOURCES) \ + $(hdrl_bpm_fit_test_SOURCES) $(hdrl_bpm_utils_test_SOURCES) \ + $(hdrl_buffer_test_SOURCES) $(hdrl_catalogue_test_SOURCES) \ + $(hdrl_collapse_test_SOURCES) $(hdrl_combine_test_SOURCES) \ + $(hdrl_correlation_test_SOURCES) $(hdrl_dar_test_SOURCES) \ + $(hdrl_der_snr_test_SOURCES) $(hdrl_efficiency_test_SOURCES) \ + $(hdrl_elemop_test_SOURCES) $(hdrl_fit_test_SOURCES) \ + $(hdrl_flat_test_SOURCES) $(hdrl_frameiter_test_SOURCES) \ + $(hdrl_fringe_test_SOURCES) $(hdrl_image_test_SOURCES) \ + $(hdrl_imagelist_basic_test_SOURCES) \ + $(hdrl_imagelist_io_test_SOURCES) \ + $(hdrl_imagelist_view_test_SOURCES) \ + $(hdrl_lacosmics_test_SOURCES) $(hdrl_multiiter_test_SOURCES) \ + $(hdrl_overscan_test_SOURCES) $(hdrl_parameter_test_SOURCES) \ + $(hdrl_prototyping_test_SOURCES) $(hdrl_random_test_SOURCES) \ + $(hdrl_response_test_SOURCES) $(hdrl_sigclip_test_SOURCES) \ + $(hdrl_spectrum1d_test_SOURCES) \ + $(hdrl_spectrum1d_shift_test_SOURCES) \ + $(hdrl_spectrum1dlist_test_SOURCES) \ + $(hdrl_strehl_test_SOURCES) $(hdrl_utils_test_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__tty_colors_dummy = \ + mgn= red= grn= lgn= blu= brg= std=; \ + am__color_tests=no +am__tty_colors = { \ + $(am__tty_colors_dummy); \ + if test "X$(AM_COLOR_TESTS)" = Xno; then \ + am__color_tests=no; \ + elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ + am__color_tests=yes; \ + elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ + am__color_tests=yes; \ + fi; \ + if test $$am__color_tests = yes; then \ + red=''; \ + grn=''; \ + lgn=''; \ + blu=''; \ + mgn=''; \ + brg=''; \ + std=''; \ + fi; \ +} +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__recheck_rx = ^[ ]*:recheck:[ ]* +am__global_test_result_rx = ^[ ]*:global-test-result:[ ]* +am__copy_in_global_log_rx = ^[ ]*:copy-in-global-log:[ ]* +# A command that, given a newline-separated list of test names on the +# standard input, print the name of the tests that are to be re-run +# upon "make recheck". +am__list_recheck_tests = $(AWK) '{ \ + recheck = 1; \ + while ((rc = (getline line < ($$0 ".trs"))) != 0) \ + { \ + if (rc < 0) \ + { \ + if ((getline line2 < ($$0 ".log")) < 0) \ + recheck = 0; \ + break; \ + } \ + else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \ + { \ + recheck = 0; \ + break; \ + } \ + else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \ + { \ + break; \ + } \ + }; \ + if (recheck) \ + print $$0; \ + close ($$0 ".trs"); \ + close ($$0 ".log"); \ +}' +# A command that, given a newline-separated list of test names on the +# standard input, create the global log from their .trs and .log files. +am__create_global_log = $(AWK) ' \ +function fatal(msg) \ +{ \ + print "fatal: making $@: " msg | "cat >&2"; \ + exit 1; \ +} \ +function rst_section(header) \ +{ \ + print header; \ + len = length(header); \ + for (i = 1; i <= len; i = i + 1) \ + printf "="; \ + printf "\n\n"; \ +} \ +{ \ + copy_in_global_log = 1; \ + global_test_result = "RUN"; \ + while ((rc = (getline line < ($$0 ".trs"))) != 0) \ + { \ + if (rc < 0) \ + fatal("failed to read from " $$0 ".trs"); \ + if (line ~ /$(am__global_test_result_rx)/) \ + { \ + sub("$(am__global_test_result_rx)", "", line); \ + sub("[ ]*$$", "", line); \ + global_test_result = line; \ + } \ + else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \ + copy_in_global_log = 0; \ + }; \ + if (copy_in_global_log) \ + { \ + rst_section(global_test_result ": " $$0); \ + while ((rc = (getline line < ($$0 ".log"))) != 0) \ + { \ + if (rc < 0) \ + fatal("failed to read from " $$0 ".log"); \ + print line; \ + }; \ + printf "\n"; \ + }; \ + close ($$0 ".trs"); \ + close ($$0 ".log"); \ +}' +# Restructured Text title. +am__rst_title = { sed 's/.*/ & /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; } +# Solaris 10 'make', and several other traditional 'make' implementations, +# pass "-e" to $(SHELL), and POSIX 2008 even requires this. Work around it +# by disabling -e (using the XSI extension "set +e") if it's set. +am__sh_e_setup = case $$- in *e*) set +e;; esac +# Default flags passed to test drivers. +am__common_driver_flags = \ + --color-tests "$$am__color_tests" \ + --enable-hard-errors "$$am__enable_hard_errors" \ + --expect-failure "$$am__expect_failure" +# To be inserted before the command running the test. Creates the +# directory for the log if needed. Stores in $dir the directory +# containing $f, in $tst the test, in $log the log. Executes the +# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and +# passes TESTS_ENVIRONMENT. Set up options for the wrapper that +# will run the test scripts (or their associated LOG_COMPILER, if +# thy have one). +am__check_pre = \ +$(am__sh_e_setup); \ +$(am__vpath_adj_setup) $(am__vpath_adj) \ +$(am__tty_colors); \ +srcdir=$(srcdir); export srcdir; \ +case "$@" in \ + */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;; \ + *) am__odir=.;; \ +esac; \ +test "x$$am__odir" = x"." || test -d "$$am__odir" \ + || $(MKDIR_P) "$$am__odir" || exit $$?; \ +if test -f "./$$f"; then dir=./; \ +elif test -f "$$f"; then dir=; \ +else dir="$(srcdir)/"; fi; \ +tst=$$dir$$f; log='$@'; \ +if test -n '$(DISABLE_HARD_ERRORS)'; then \ + am__enable_hard_errors=no; \ +else \ + am__enable_hard_errors=yes; \ +fi; \ +case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$f[\ \ ]* | *[\ \ ]$$dir$$f[\ \ ]*) \ + am__expect_failure=yes;; \ + *) \ + am__expect_failure=no;; \ +esac; \ +$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT) +# A shell command to get the names of the tests scripts with any registered +# extension removed (i.e., equivalently, the names of the test logs, with +# the '.log' extension removed). The result is saved in the shell variable +# '$bases'. This honors runtime overriding of TESTS and TEST_LOGS. Sadly, +# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)", +# since that might cause problem with VPATH rewrites for suffix-less tests. +# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'. +am__set_TESTS_bases = \ + bases='$(TEST_LOGS)'; \ + bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ + bases=`echo $$bases` +RECHECK_LOGS = $(TEST_LOGS) +AM_RECURSIVE_TARGETS = check recheck +TEST_SUITE_LOG = test-suite.log +TEST_EXTENSIONS = @EXEEXT@ .test +LOG_DRIVER = $(SHELL) $(top_srcdir)/admin/test-driver +LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS) +am__set_b = \ + case '$@' in \ + */*) \ + case '$*' in \ + */*) b='$*';; \ + *) b=`echo '$@' | sed 's/\.log$$//'`; \ + esac;; \ + *) \ + b='$*';; \ + esac +am__test_logs1 = $(TESTS:=.log) +am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) +TEST_LOGS = $(am__test_logs2:.test.log=.log) +TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/admin/test-driver +TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ + $(TEST_LOG_FLAGS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/admin/depcomp \ + $(top_srcdir)/admin/test-driver +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPL_INCLUDES = @CPL_INCLUDES@ +CPL_LDFLAGS = @CPL_LDFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DOXYGEN = @DOXYGEN@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ESO_DEBUG_FLAGS = @ESO_DEBUG_FLAGS@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_BINARY_AGE = @HDRL_BINARY_AGE@ +HDRL_BINARY_VERSION = @HDRL_BINARY_VERSION@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERFACE_AGE = @HDRL_INTERFACE_AGE@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_MAJOR_VERSION = @HDRL_MAJOR_VERSION@ +HDRL_MICRO_VERSION = @HDRL_MICRO_VERSION@ +HDRL_MINOR_VERSION = @HDRL_MINOR_VERSION@ +HDRL_VERSION = @HDRL_VERSION@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LATEX = @LATEX@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBCEXT = @LIBCEXT@ +LIBCPLCORE = @LIBCPLCORE@ +LIBCPLDFS = @LIBCPLDFS@ +LIBCPLDRS = @LIBCPLDRS@ +LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_AGE = @LT_AGE@ +LT_CURRENT = @LT_CURRENT@ +LT_REVISION = @LT_REVISION@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +all_includes = @all_includes@ +all_ldflags = @all_ldflags@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AUTOMAKE_OPTIONS = 1.8 foreign +DISTCLEANFILES = *~ +@MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = $(srcdir)/Makefile.in +AM_CPPFLAGS = $(CPL_INCLUDES) $(HDRL_INCLUDES) -DHDRL_USE_PRIVATE +AM_LDFLAGS = $(CPL_LDFLAGS) $(HDRL_LDFLAGS) +LDADD = ../libhdrl.la $(LIBCPLCORE) $(LIBCPLDFS) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCEXT) -lgsl -lgslcblas -lm +hdrl_overscan_test_SOURCES = hdrl_overscan-test.c +hdrl_sigclip_test_SOURCES = hdrl_sigclip-test.c +hdrl_utils_test_SOURCES = hdrl_utils-test.c +hdrl_combine_test_SOURCES = hdrl_combine-test.c +hdrl_bpm_2d_test_SOURCES = hdrl_bpm_2d-test.c +hdrl_bpm_3d_test_SOURCES = hdrl_bpm_3d-test.c +hdrl_bpm_fit_test_SOURCES = hdrl_bpm_fit-test.c +hdrl_bpm_utils_test_SOURCES = hdrl_bpm_utils-test.c +hdrl_collapse_test_SOURCES = hdrl_collapse-test.c +hdrl_image_test_SOURCES = hdrl_image-test.c +hdrl_imagelist_io_test_SOURCES = hdrl_imagelist_io-test.c +hdrl_imagelist_basic_test_SOURCES = hdrl_imagelist_basic-test.c +hdrl_imagelist_view_test_SOURCES = hdrl_imagelist_view-test.c +hdrl_elemop_test_SOURCES = hdrl_elemop-test.c +hdrl_parameter_test_SOURCES = hdrl_parameter-test.c +hdrl_buffer_test_SOURCES = hdrl_buffer-test.c +hdrl_fit_test_SOURCES = hdrl_fit-test.c +hdrl_strehl_test_SOURCES = hdrl_strehl-test.c +hdrl_lacosmics_test_SOURCES = hdrl_lacosmics-test.c +hdrl_fringe_test_SOURCES = hdrl_fringe-test.c +hdrl_catalogue_test_SOURCES = hdrl_catalogue-test.c +hdrl_random_test_SOURCES = hdrl_random-test.c +hdrl_frameiter_test_SOURCES = hdrl_frameiter-test.c +hdrl_flat_test_SOURCES = hdrl_flat-test.c +hdrl_spectrum1d_test_SOURCES = hdrl_spectrum1d-test.c +hdrl_spectrum1dlist_test_SOURCES = hdrl_spectrum1dlist-test.c +hdrl_der_snr_test_SOURCES = hdrl_der_snr-test.c +hdrl_efficiency_test_SOURCES = hdrl_efficiency-test.c +hdrl_response_test_SOURCES = hdrl_response-test.c +hdrl_correlation_test_SOURCES = hdrl_correlation-test.c +hdrl_spectrum1d_shift_test_SOURCES = hdrl_spectrum1d_shift-test.c +hdrl_dar_test_SOURCES = hdrl_dar-test.c +hdrl_prototyping_test_SOURCES = hdrl_prototyping-test.c +hdrl_multiiter_test_SOURCES = hdrl_multiiter-test.c + +# Be sure to reexport important environment variables. +TESTS_ENVIRONMENT = MAKE="$(MAKE)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + CPPFLAGS="$(CPPFLAGS)" LD="$(LD)" LDFLAGS="$(LDFLAGS)" \ + LIBS="$(LIBS)" LN_S="$(LN_S)" NM="$(NM)" RANLIB="$(RANLIB)" \ + OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" \ + MALLOC_PERTURB_=31 MALLOC_CHECK_=2 \ + GOMP_SPINCOUNT=10000 + +TESTS = $(check_PROGRAMS) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign tests/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +hdrl_bpm_2d-test$(EXEEXT): $(hdrl_bpm_2d_test_OBJECTS) $(hdrl_bpm_2d_test_DEPENDENCIES) $(EXTRA_hdrl_bpm_2d_test_DEPENDENCIES) + @rm -f hdrl_bpm_2d-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_bpm_2d_test_OBJECTS) $(hdrl_bpm_2d_test_LDADD) $(LIBS) + +hdrl_bpm_3d-test$(EXEEXT): $(hdrl_bpm_3d_test_OBJECTS) $(hdrl_bpm_3d_test_DEPENDENCIES) $(EXTRA_hdrl_bpm_3d_test_DEPENDENCIES) + @rm -f hdrl_bpm_3d-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_bpm_3d_test_OBJECTS) $(hdrl_bpm_3d_test_LDADD) $(LIBS) + +hdrl_bpm_fit-test$(EXEEXT): $(hdrl_bpm_fit_test_OBJECTS) $(hdrl_bpm_fit_test_DEPENDENCIES) $(EXTRA_hdrl_bpm_fit_test_DEPENDENCIES) + @rm -f hdrl_bpm_fit-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_bpm_fit_test_OBJECTS) $(hdrl_bpm_fit_test_LDADD) $(LIBS) + +hdrl_bpm_utils-test$(EXEEXT): $(hdrl_bpm_utils_test_OBJECTS) $(hdrl_bpm_utils_test_DEPENDENCIES) $(EXTRA_hdrl_bpm_utils_test_DEPENDENCIES) + @rm -f hdrl_bpm_utils-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_bpm_utils_test_OBJECTS) $(hdrl_bpm_utils_test_LDADD) $(LIBS) + +hdrl_buffer-test$(EXEEXT): $(hdrl_buffer_test_OBJECTS) $(hdrl_buffer_test_DEPENDENCIES) $(EXTRA_hdrl_buffer_test_DEPENDENCIES) + @rm -f hdrl_buffer-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_buffer_test_OBJECTS) $(hdrl_buffer_test_LDADD) $(LIBS) + +hdrl_catalogue-test$(EXEEXT): $(hdrl_catalogue_test_OBJECTS) $(hdrl_catalogue_test_DEPENDENCIES) $(EXTRA_hdrl_catalogue_test_DEPENDENCIES) + @rm -f hdrl_catalogue-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_catalogue_test_OBJECTS) $(hdrl_catalogue_test_LDADD) $(LIBS) + +hdrl_collapse-test$(EXEEXT): $(hdrl_collapse_test_OBJECTS) $(hdrl_collapse_test_DEPENDENCIES) $(EXTRA_hdrl_collapse_test_DEPENDENCIES) + @rm -f hdrl_collapse-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_collapse_test_OBJECTS) $(hdrl_collapse_test_LDADD) $(LIBS) + +hdrl_combine-test$(EXEEXT): $(hdrl_combine_test_OBJECTS) $(hdrl_combine_test_DEPENDENCIES) $(EXTRA_hdrl_combine_test_DEPENDENCIES) + @rm -f hdrl_combine-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_combine_test_OBJECTS) $(hdrl_combine_test_LDADD) $(LIBS) + +hdrl_correlation-test$(EXEEXT): $(hdrl_correlation_test_OBJECTS) $(hdrl_correlation_test_DEPENDENCIES) $(EXTRA_hdrl_correlation_test_DEPENDENCIES) + @rm -f hdrl_correlation-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_correlation_test_OBJECTS) $(hdrl_correlation_test_LDADD) $(LIBS) + +hdrl_dar-test$(EXEEXT): $(hdrl_dar_test_OBJECTS) $(hdrl_dar_test_DEPENDENCIES) $(EXTRA_hdrl_dar_test_DEPENDENCIES) + @rm -f hdrl_dar-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_dar_test_OBJECTS) $(hdrl_dar_test_LDADD) $(LIBS) + +hdrl_der_snr-test$(EXEEXT): $(hdrl_der_snr_test_OBJECTS) $(hdrl_der_snr_test_DEPENDENCIES) $(EXTRA_hdrl_der_snr_test_DEPENDENCIES) + @rm -f hdrl_der_snr-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_der_snr_test_OBJECTS) $(hdrl_der_snr_test_LDADD) $(LIBS) + +hdrl_efficiency-test$(EXEEXT): $(hdrl_efficiency_test_OBJECTS) $(hdrl_efficiency_test_DEPENDENCIES) $(EXTRA_hdrl_efficiency_test_DEPENDENCIES) + @rm -f hdrl_efficiency-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_efficiency_test_OBJECTS) $(hdrl_efficiency_test_LDADD) $(LIBS) + +hdrl_elemop-test$(EXEEXT): $(hdrl_elemop_test_OBJECTS) $(hdrl_elemop_test_DEPENDENCIES) $(EXTRA_hdrl_elemop_test_DEPENDENCIES) + @rm -f hdrl_elemop-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_elemop_test_OBJECTS) $(hdrl_elemop_test_LDADD) $(LIBS) + +hdrl_fit-test$(EXEEXT): $(hdrl_fit_test_OBJECTS) $(hdrl_fit_test_DEPENDENCIES) $(EXTRA_hdrl_fit_test_DEPENDENCIES) + @rm -f hdrl_fit-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_fit_test_OBJECTS) $(hdrl_fit_test_LDADD) $(LIBS) + +hdrl_flat-test$(EXEEXT): $(hdrl_flat_test_OBJECTS) $(hdrl_flat_test_DEPENDENCIES) $(EXTRA_hdrl_flat_test_DEPENDENCIES) + @rm -f hdrl_flat-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_flat_test_OBJECTS) $(hdrl_flat_test_LDADD) $(LIBS) + +hdrl_frameiter-test$(EXEEXT): $(hdrl_frameiter_test_OBJECTS) $(hdrl_frameiter_test_DEPENDENCIES) $(EXTRA_hdrl_frameiter_test_DEPENDENCIES) + @rm -f hdrl_frameiter-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_frameiter_test_OBJECTS) $(hdrl_frameiter_test_LDADD) $(LIBS) + +hdrl_fringe-test$(EXEEXT): $(hdrl_fringe_test_OBJECTS) $(hdrl_fringe_test_DEPENDENCIES) $(EXTRA_hdrl_fringe_test_DEPENDENCIES) + @rm -f hdrl_fringe-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_fringe_test_OBJECTS) $(hdrl_fringe_test_LDADD) $(LIBS) + +hdrl_image-test$(EXEEXT): $(hdrl_image_test_OBJECTS) $(hdrl_image_test_DEPENDENCIES) $(EXTRA_hdrl_image_test_DEPENDENCIES) + @rm -f hdrl_image-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_image_test_OBJECTS) $(hdrl_image_test_LDADD) $(LIBS) + +hdrl_imagelist_basic-test$(EXEEXT): $(hdrl_imagelist_basic_test_OBJECTS) $(hdrl_imagelist_basic_test_DEPENDENCIES) $(EXTRA_hdrl_imagelist_basic_test_DEPENDENCIES) + @rm -f hdrl_imagelist_basic-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_imagelist_basic_test_OBJECTS) $(hdrl_imagelist_basic_test_LDADD) $(LIBS) + +hdrl_imagelist_io-test$(EXEEXT): $(hdrl_imagelist_io_test_OBJECTS) $(hdrl_imagelist_io_test_DEPENDENCIES) $(EXTRA_hdrl_imagelist_io_test_DEPENDENCIES) + @rm -f hdrl_imagelist_io-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_imagelist_io_test_OBJECTS) $(hdrl_imagelist_io_test_LDADD) $(LIBS) + +hdrl_imagelist_view-test$(EXEEXT): $(hdrl_imagelist_view_test_OBJECTS) $(hdrl_imagelist_view_test_DEPENDENCIES) $(EXTRA_hdrl_imagelist_view_test_DEPENDENCIES) + @rm -f hdrl_imagelist_view-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_imagelist_view_test_OBJECTS) $(hdrl_imagelist_view_test_LDADD) $(LIBS) + +hdrl_lacosmics-test$(EXEEXT): $(hdrl_lacosmics_test_OBJECTS) $(hdrl_lacosmics_test_DEPENDENCIES) $(EXTRA_hdrl_lacosmics_test_DEPENDENCIES) + @rm -f hdrl_lacosmics-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_lacosmics_test_OBJECTS) $(hdrl_lacosmics_test_LDADD) $(LIBS) + +hdrl_multiiter-test$(EXEEXT): $(hdrl_multiiter_test_OBJECTS) $(hdrl_multiiter_test_DEPENDENCIES) $(EXTRA_hdrl_multiiter_test_DEPENDENCIES) + @rm -f hdrl_multiiter-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_multiiter_test_OBJECTS) $(hdrl_multiiter_test_LDADD) $(LIBS) + +hdrl_overscan-test$(EXEEXT): $(hdrl_overscan_test_OBJECTS) $(hdrl_overscan_test_DEPENDENCIES) $(EXTRA_hdrl_overscan_test_DEPENDENCIES) + @rm -f hdrl_overscan-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_overscan_test_OBJECTS) $(hdrl_overscan_test_LDADD) $(LIBS) + +hdrl_parameter-test$(EXEEXT): $(hdrl_parameter_test_OBJECTS) $(hdrl_parameter_test_DEPENDENCIES) $(EXTRA_hdrl_parameter_test_DEPENDENCIES) + @rm -f hdrl_parameter-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_parameter_test_OBJECTS) $(hdrl_parameter_test_LDADD) $(LIBS) + +hdrl_prototyping-test$(EXEEXT): $(hdrl_prototyping_test_OBJECTS) $(hdrl_prototyping_test_DEPENDENCIES) $(EXTRA_hdrl_prototyping_test_DEPENDENCIES) + @rm -f hdrl_prototyping-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_prototyping_test_OBJECTS) $(hdrl_prototyping_test_LDADD) $(LIBS) + +hdrl_random-test$(EXEEXT): $(hdrl_random_test_OBJECTS) $(hdrl_random_test_DEPENDENCIES) $(EXTRA_hdrl_random_test_DEPENDENCIES) + @rm -f hdrl_random-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_random_test_OBJECTS) $(hdrl_random_test_LDADD) $(LIBS) + +hdrl_response-test$(EXEEXT): $(hdrl_response_test_OBJECTS) $(hdrl_response_test_DEPENDENCIES) $(EXTRA_hdrl_response_test_DEPENDENCIES) + @rm -f hdrl_response-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_response_test_OBJECTS) $(hdrl_response_test_LDADD) $(LIBS) + +hdrl_sigclip-test$(EXEEXT): $(hdrl_sigclip_test_OBJECTS) $(hdrl_sigclip_test_DEPENDENCIES) $(EXTRA_hdrl_sigclip_test_DEPENDENCIES) + @rm -f hdrl_sigclip-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_sigclip_test_OBJECTS) $(hdrl_sigclip_test_LDADD) $(LIBS) + +hdrl_spectrum1d-test$(EXEEXT): $(hdrl_spectrum1d_test_OBJECTS) $(hdrl_spectrum1d_test_DEPENDENCIES) $(EXTRA_hdrl_spectrum1d_test_DEPENDENCIES) + @rm -f hdrl_spectrum1d-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_spectrum1d_test_OBJECTS) $(hdrl_spectrum1d_test_LDADD) $(LIBS) + +hdrl_spectrum1d_shift-test$(EXEEXT): $(hdrl_spectrum1d_shift_test_OBJECTS) $(hdrl_spectrum1d_shift_test_DEPENDENCIES) $(EXTRA_hdrl_spectrum1d_shift_test_DEPENDENCIES) + @rm -f hdrl_spectrum1d_shift-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_spectrum1d_shift_test_OBJECTS) $(hdrl_spectrum1d_shift_test_LDADD) $(LIBS) + +hdrl_spectrum1dlist-test$(EXEEXT): $(hdrl_spectrum1dlist_test_OBJECTS) $(hdrl_spectrum1dlist_test_DEPENDENCIES) $(EXTRA_hdrl_spectrum1dlist_test_DEPENDENCIES) + @rm -f hdrl_spectrum1dlist-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_spectrum1dlist_test_OBJECTS) $(hdrl_spectrum1dlist_test_LDADD) $(LIBS) + +hdrl_strehl-test$(EXEEXT): $(hdrl_strehl_test_OBJECTS) $(hdrl_strehl_test_DEPENDENCIES) $(EXTRA_hdrl_strehl_test_DEPENDENCIES) + @rm -f hdrl_strehl-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_strehl_test_OBJECTS) $(hdrl_strehl_test_LDADD) $(LIBS) + +hdrl_utils-test$(EXEEXT): $(hdrl_utils_test_OBJECTS) $(hdrl_utils_test_DEPENDENCIES) $(EXTRA_hdrl_utils_test_DEPENDENCIES) + @rm -f hdrl_utils-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(hdrl_utils_test_OBJECTS) $(hdrl_utils_test_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_bpm_2d-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_bpm_3d-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_bpm_fit-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_bpm_utils-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_buffer-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_catalogue-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_collapse-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_combine-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_correlation-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_dar-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_der_snr-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_efficiency-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_elemop-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_fit-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_flat-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_frameiter-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_fringe-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_image-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_imagelist_basic-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_imagelist_io-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_imagelist_view-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_lacosmics-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_multiiter-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_overscan-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_parameter-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_prototyping-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_random-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_response-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_sigclip-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_spectrum1d-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_spectrum1d_shift-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_spectrum1dlist-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_strehl-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hdrl_utils-test.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +# Recover from deleted '.trs' file; this should ensure that +# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create +# both 'foo.log' and 'foo.trs'. Break the recipe in two subshells +# to avoid problems with "make -n". +.log.trs: + rm -f $< $@ + $(MAKE) $(AM_MAKEFLAGS) $< + +# Leading 'am--fnord' is there to ensure the list of targets does not +# expand to empty, as could happen e.g. with make check TESTS=''. +am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck) +am--force-recheck: + @: + +$(TEST_SUITE_LOG): $(TEST_LOGS) + @$(am__set_TESTS_bases); \ + am__f_ok () { test -f "$$1" && test -r "$$1"; }; \ + redo_bases=`for i in $$bases; do \ + am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \ + done`; \ + if test -n "$$redo_bases"; then \ + redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \ + redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \ + if $(am__make_dryrun); then :; else \ + rm -f $$redo_logs && rm -f $$redo_results || exit 1; \ + fi; \ + fi; \ + if test -n "$$am__remaking_logs"; then \ + echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ + "recursion detected" >&2; \ + elif test -n "$$redo_logs"; then \ + am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ + fi; \ + if $(am__make_dryrun); then :; else \ + st=0; \ + errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ + for i in $$redo_bases; do \ + test -f $$i.trs && test -r $$i.trs \ + || { echo "$$errmsg $$i.trs" >&2; st=1; }; \ + test -f $$i.log && test -r $$i.log \ + || { echo "$$errmsg $$i.log" >&2; st=1; }; \ + done; \ + test $$st -eq 0 || exit 1; \ + fi + @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \ + ws='[ ]'; \ + results=`for b in $$bases; do echo $$b.trs; done`; \ + test -n "$$results" || results=/dev/null; \ + all=` grep "^$$ws*:test-result:" $$results | wc -l`; \ + pass=` grep "^$$ws*:test-result:$$ws*PASS" $$results | wc -l`; \ + fail=` grep "^$$ws*:test-result:$$ws*FAIL" $$results | wc -l`; \ + skip=` grep "^$$ws*:test-result:$$ws*SKIP" $$results | wc -l`; \ + xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \ + xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \ + error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \ + if test `expr $$fail + $$xpass + $$error` -eq 0; then \ + success=true; \ + else \ + success=false; \ + fi; \ + br='==================='; br=$$br$$br$$br$$br; \ + result_count () \ + { \ + if test x"$$1" = x"--maybe-color"; then \ + maybe_colorize=yes; \ + elif test x"$$1" = x"--no-color"; then \ + maybe_colorize=no; \ + else \ + echo "$@: invalid 'result_count' usage" >&2; exit 4; \ + fi; \ + shift; \ + desc=$$1 count=$$2; \ + if test $$maybe_colorize = yes && test $$count -gt 0; then \ + color_start=$$3 color_end=$$std; \ + else \ + color_start= color_end=; \ + fi; \ + echo "$${color_start}# $$desc $$count$${color_end}"; \ + }; \ + create_testsuite_report () \ + { \ + result_count $$1 "TOTAL:" $$all "$$brg"; \ + result_count $$1 "PASS: " $$pass "$$grn"; \ + result_count $$1 "SKIP: " $$skip "$$blu"; \ + result_count $$1 "XFAIL:" $$xfail "$$lgn"; \ + result_count $$1 "FAIL: " $$fail "$$red"; \ + result_count $$1 "XPASS:" $$xpass "$$red"; \ + result_count $$1 "ERROR:" $$error "$$mgn"; \ + }; \ + { \ + echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \ + $(am__rst_title); \ + create_testsuite_report --no-color; \ + echo; \ + echo ".. contents:: :depth: 2"; \ + echo; \ + for b in $$bases; do echo $$b; done \ + | $(am__create_global_log); \ + } >$(TEST_SUITE_LOG).tmp || exit 1; \ + mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG); \ + if $$success; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ + fi; \ + echo "$${col}$$br$${std}"; \ + echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}$$br$${std}"; \ + create_testsuite_report --maybe-color; \ + echo "$$col$$br$$std"; \ + if $$success; then :; else \ + echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}"; \ + if test -n "$(PACKAGE_BUGREPORT)"; then \ + echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \ + fi; \ + echo "$$col$$br$$std"; \ + fi; \ + $$success || exit 1 + +check-TESTS: + @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list + @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list + @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + @set +e; $(am__set_TESTS_bases); \ + log_list=`for i in $$bases; do echo $$i.log; done`; \ + trs_list=`for i in $$bases; do echo $$i.trs; done`; \ + log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \ + $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \ + exit $$?; +recheck: all $(check_PROGRAMS) + @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + @set +e; $(am__set_TESTS_bases); \ + bases=`for i in $$bases; do echo $$i; done \ + | $(am__list_recheck_tests)` || exit 1; \ + log_list=`for i in $$bases; do echo $$i.log; done`; \ + log_list=`echo $$log_list`; \ + $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \ + am__force_recheck=am--force-recheck \ + TEST_LOGS="$$log_list"; \ + exit $$? +hdrl_buffer-test.log: hdrl_buffer-test$(EXEEXT) + @p='hdrl_buffer-test$(EXEEXT)'; \ + b='hdrl_buffer-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_overscan-test.log: hdrl_overscan-test$(EXEEXT) + @p='hdrl_overscan-test$(EXEEXT)'; \ + b='hdrl_overscan-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_sigclip-test.log: hdrl_sigclip-test$(EXEEXT) + @p='hdrl_sigclip-test$(EXEEXT)'; \ + b='hdrl_sigclip-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_utils-test.log: hdrl_utils-test$(EXEEXT) + @p='hdrl_utils-test$(EXEEXT)'; \ + b='hdrl_utils-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_combine-test.log: hdrl_combine-test$(EXEEXT) + @p='hdrl_combine-test$(EXEEXT)'; \ + b='hdrl_combine-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_bpm_2d-test.log: hdrl_bpm_2d-test$(EXEEXT) + @p='hdrl_bpm_2d-test$(EXEEXT)'; \ + b='hdrl_bpm_2d-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_bpm_3d-test.log: hdrl_bpm_3d-test$(EXEEXT) + @p='hdrl_bpm_3d-test$(EXEEXT)'; \ + b='hdrl_bpm_3d-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_bpm_fit-test.log: hdrl_bpm_fit-test$(EXEEXT) + @p='hdrl_bpm_fit-test$(EXEEXT)'; \ + b='hdrl_bpm_fit-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_bpm_utils-test.log: hdrl_bpm_utils-test$(EXEEXT) + @p='hdrl_bpm_utils-test$(EXEEXT)'; \ + b='hdrl_bpm_utils-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_collapse-test.log: hdrl_collapse-test$(EXEEXT) + @p='hdrl_collapse-test$(EXEEXT)'; \ + b='hdrl_collapse-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_image-test.log: hdrl_image-test$(EXEEXT) + @p='hdrl_image-test$(EXEEXT)'; \ + b='hdrl_image-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_imagelist_io-test.log: hdrl_imagelist_io-test$(EXEEXT) + @p='hdrl_imagelist_io-test$(EXEEXT)'; \ + b='hdrl_imagelist_io-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_imagelist_basic-test.log: hdrl_imagelist_basic-test$(EXEEXT) + @p='hdrl_imagelist_basic-test$(EXEEXT)'; \ + b='hdrl_imagelist_basic-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_imagelist_view-test.log: hdrl_imagelist_view-test$(EXEEXT) + @p='hdrl_imagelist_view-test$(EXEEXT)'; \ + b='hdrl_imagelist_view-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_elemop-test.log: hdrl_elemop-test$(EXEEXT) + @p='hdrl_elemop-test$(EXEEXT)'; \ + b='hdrl_elemop-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_parameter-test.log: hdrl_parameter-test$(EXEEXT) + @p='hdrl_parameter-test$(EXEEXT)'; \ + b='hdrl_parameter-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_fit-test.log: hdrl_fit-test$(EXEEXT) + @p='hdrl_fit-test$(EXEEXT)'; \ + b='hdrl_fit-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_strehl-test.log: hdrl_strehl-test$(EXEEXT) + @p='hdrl_strehl-test$(EXEEXT)'; \ + b='hdrl_strehl-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_lacosmics-test.log: hdrl_lacosmics-test$(EXEEXT) + @p='hdrl_lacosmics-test$(EXEEXT)'; \ + b='hdrl_lacosmics-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_fringe-test.log: hdrl_fringe-test$(EXEEXT) + @p='hdrl_fringe-test$(EXEEXT)'; \ + b='hdrl_fringe-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_catalogue-test.log: hdrl_catalogue-test$(EXEEXT) + @p='hdrl_catalogue-test$(EXEEXT)'; \ + b='hdrl_catalogue-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_random-test.log: hdrl_random-test$(EXEEXT) + @p='hdrl_random-test$(EXEEXT)'; \ + b='hdrl_random-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_frameiter-test.log: hdrl_frameiter-test$(EXEEXT) + @p='hdrl_frameiter-test$(EXEEXT)'; \ + b='hdrl_frameiter-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_flat-test.log: hdrl_flat-test$(EXEEXT) + @p='hdrl_flat-test$(EXEEXT)'; \ + b='hdrl_flat-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_spectrum1d-test.log: hdrl_spectrum1d-test$(EXEEXT) + @p='hdrl_spectrum1d-test$(EXEEXT)'; \ + b='hdrl_spectrum1d-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_spectrum1d_shift-test.log: hdrl_spectrum1d_shift-test$(EXEEXT) + @p='hdrl_spectrum1d_shift-test$(EXEEXT)'; \ + b='hdrl_spectrum1d_shift-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_spectrum1dlist-test.log: hdrl_spectrum1dlist-test$(EXEEXT) + @p='hdrl_spectrum1dlist-test$(EXEEXT)'; \ + b='hdrl_spectrum1dlist-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_efficiency-test.log: hdrl_efficiency-test$(EXEEXT) + @p='hdrl_efficiency-test$(EXEEXT)'; \ + b='hdrl_efficiency-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_response-test.log: hdrl_response-test$(EXEEXT) + @p='hdrl_response-test$(EXEEXT)'; \ + b='hdrl_response-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_der_snr-test.log: hdrl_der_snr-test$(EXEEXT) + @p='hdrl_der_snr-test$(EXEEXT)'; \ + b='hdrl_der_snr-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_dar-test.log: hdrl_dar-test$(EXEEXT) + @p='hdrl_dar-test$(EXEEXT)'; \ + b='hdrl_dar-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_prototyping-test.log: hdrl_prototyping-test$(EXEEXT) + @p='hdrl_prototyping-test$(EXEEXT)'; \ + b='hdrl_prototyping-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_multiiter-test.log: hdrl_multiiter-test$(EXEEXT) + @p='hdrl_multiiter-test$(EXEEXT)'; \ + b='hdrl_multiiter-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +hdrl_correlation-test.log: hdrl_correlation-test$(EXEEXT) + @p='hdrl_correlation-test$(EXEEXT)'; \ + b='hdrl_correlation-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +.test.log: + @p='$<'; \ + $(am__set_b); \ + $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +@am__EXEEXT_TRUE@.test$(EXEEXT).log: +@am__EXEEXT_TRUE@ @p='$<'; \ +@am__EXEEXT_TRUE@ $(am__set_b); \ +@am__EXEEXT_TRUE@ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ +@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ +@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ +@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + -test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS) + -test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs) + -test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libtool clean-local \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \ + clean-checkPROGRAMS clean-generic clean-libtool clean-local \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + recheck tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# We need to remove any files that the above tests created. +clean-local: + $(RM) *.fits *.tfits *.log + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_calib.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_calib.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_calib.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_calib.c 2018-01-18 08:56:57.000000000 +0000 @@ -33,10 +33,13 @@ Includes -----------------------------------------------------------------------------*/ +#include "irplib_calib.h" + #include -#include -#include "irplib_calib.h" +/*----------------------------------------------------------------------------- + Static Function Prototypes + -----------------------------------------------------------------------------*/ static int irplib_get_clean_mean_window(cpl_image* img, @@ -48,18 +51,6 @@ double* clean_mean, double* clean_stdev); -/*----------------------------------------------------------------------------- - Defines - -----------------------------------------------------------------------------*/ - -#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(6, 3, 0) -#define IRPLIB_FRAMESET_GET cpl_frameset_get_position -#else -/* Remove this branch once CPL versions less than 6.3 are no longer supported */ -#define IRPLIB_FRAMESET_GET cpl_frameset_get_frame -#endif - - static double irplib_pfits_get_dit(const cpl_propertylist * plist); static double irplib_pfits_get_exp_time(const cpl_propertylist* plist); /*----------------------------------------------------------------------------*/ @@ -231,7 +222,7 @@ for(i=0;i + +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + cpl_table* irplib_compute_gain( cpl_frameset* son, cpl_frameset* sof, int* zone1, const int kappa1, - const int nclip1); -cpl_table* irplib_compute_linearity(cpl_frameset* son, cpl_frameset* sof); + const int nclip1) CPL_ATTR_ALLOC; + +cpl_table* irplib_compute_linearity(cpl_frameset* son, cpl_frameset* sof) + CPL_ATTR_ALLOC; + int irplib_flat_dark_bpm_calib(cpl_imagelist *, const char *, const char *, const char *); int irplib_detlin_correct(cpl_imagelist *, const char *, const char *, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_cat.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_cat.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_cat.h 2009-12-16 14:49:52.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_cat.h 2017-09-18 08:05:11.000000000 +0000 @@ -34,6 +34,10 @@ #include +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + int irplib_2mass_get_catpars (const cpl_frame *master_index, char **catpath, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_distortion.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_distortion.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_distortion.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_distortion.c 2017-09-18 13:05:17.000000000 +0000 @@ -409,7 +409,7 @@ #else cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Not enough valid arcs, min=" - IRPLIB_STRINGIFY(ARC_MINNBARCS)); + CPL_STRINGIFY(ARC_MINNBARCS)); #endif cpl_image_delete(*label_im); *label_im = NULL; @@ -995,13 +995,13 @@ #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "image has %d lines, min=" - IRPLIB_STRINGIFY(IS_SKIPZONE) "*" - IRPLIB_STRINGIFY(IS_NB_TESTPOINTS), ny); + CPL_STRINGIFY(IS_SKIPZONE) "*" + CPL_STRINGIFY(IS_NB_TESTPOINTS), ny); #else cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "image has too few lines, min=" - IRPLIB_STRINGIFY(IS_SKIPZONE) "*" - IRPLIB_STRINGIFY(IS_NB_TESTPOINTS)); + CPL_STRINGIFY(IS_SKIPZONE) "*" + CPL_STRINGIFY(IS_NB_TESTPOINTS)); #endif return NULL; } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_distortion.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_distortion.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_distortion.h 2013-01-29 08:49:53.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_distortion.h 2017-09-18 08:05:11.000000000 +0000 @@ -29,13 +29,13 @@ #define IRPLIB_DISTORTION_H /*----------------------------------------------------------------------------- - Includes + Includes -----------------------------------------------------------------------------*/ #include /*----------------------------------------------------------------------------- - Prototypes + Function prototypes -----------------------------------------------------------------------------*/ cpl_polynomial * irplib_distortion_estimate(const cpl_image *, int, int, int, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_flat.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_flat.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_flat.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_flat.c 2017-09-18 08:05:11.000000000 +0000 @@ -33,10 +33,8 @@ Includes -----------------------------------------------------------------------------*/ -#include -#include - #include "irplib_flat.h" +#include /*----------------------------------------------------------------------------- Functions prototypes diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_framelist.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_framelist.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_framelist.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_framelist.c 2018-01-18 09:56:23.000000000 +0000 @@ -29,7 +29,6 @@ #include "irplib_framelist.h" #include "irplib_utils.h" -#include #include #include @@ -202,7 +201,6 @@ { irplib_framelist * self; - int i; cpl_ensure(frameset != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -210,13 +208,16 @@ /* The function cannot fail now */ self = irplib_framelist_new(); - for (i = 0; i < cpl_frameset_get_size(frameset); i++) + for (int i = 0; i < cpl_frameset_get_size(frameset); i++) { const cpl_frame * frame = cpl_frameset_get_position_const(frameset, i); cpl_frame * copy = cpl_frame_duplicate(frame); - const cpl_error_code error = irplib_framelist_set(self, copy, i); +#ifndef NDEBUG + const cpl_error_code error = +#endif + irplib_framelist_set(self, copy, i); assert(error == CPL_ERROR_NONE); @@ -243,16 +244,18 @@ { cpl_frameset * new; - int i; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); /* The function cannot fail now */ new = cpl_frameset_new(); - for (i = 0; i < self->size; i++) { + for (int i = 0; i < self->size; i++) { cpl_frame * frame = cpl_frame_duplicate(self->frame[i]); - const cpl_error_code error = cpl_frameset_insert(new, frame); +#ifndef NDEBUG + const cpl_error_code error = +#endif + cpl_frameset_insert(new, frame); assert(error == CPL_ERROR_NONE); @@ -296,20 +299,21 @@ const cpl_frame * frame = self->frame[i]; const char * ftag = cpl_frame_get_tag(frame); cpl_frame * copy; - cpl_error_code error; + cpl_error_code code; if (ftag == NULL) { /* The frame is ill-formed */ irplib_framelist_delete(new); - cpl_ensure(0, CPL_ERROR_ILLEGAL_INPUT, NULL); + (void)cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return NULL; } if (strcmp(tag, ftag)) continue; copy = cpl_frame_duplicate(frame); - error = irplib_framelist_set(new, copy, newsize); - assert(error == CPL_ERROR_NONE); + code = irplib_framelist_set(new, copy, newsize); + if (code != CPL_ERROR_NONE) break; /* Should not be possible */ if (self->propertylist[i] != NULL) new->propertylist[newsize] = cpl_propertylist_duplicate(self->propertylist[i]); @@ -902,8 +906,8 @@ cpl_boolean is_equal, double fp_tol) { - char * value_0; - char * value_i; + char * value_0 = NULL; + char * value_i = NULL; cpl_type type_0 = CPL_TYPE_INVALID; int i, ifirst = -1; /* First non-NULL propertylist */ @@ -1059,7 +1063,7 @@ for (i=0; i < self->size; i++, image = NULL) { const char * filename = cpl_frame_get_filename(self->frame[i]); - cpl_error_code error; + cpl_error_code code; if (filename == NULL) break; @@ -1077,8 +1081,8 @@ break; } - error = cpl_imagelist_set(list, image, i); - assert(error == CPL_ERROR_NONE); + code = cpl_imagelist_set(list, image, i); + if (code != CPL_ERROR_NONE) break; /* Should not be possible */ } cpl_image_delete(image); @@ -1086,7 +1090,7 @@ if (cpl_imagelist_get_size(list) != self->size) { cpl_imagelist_delete(list); list = NULL; - assert(cpl_error_get_code() != CPL_ERROR_NONE); + (void)cpl_error_set_where(cpl_func); } return list; @@ -1266,10 +1270,11 @@ } default: /* Unknown property type */ +#ifdef NDEBUG + equal = CPL_FALSE; +#endif assert( 0 ); - equal = CPL_FALSE; /* In case of -DNDEBUG */ - } if (!equal) { diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_match_cats.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_match_cats.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_match_cats.c 2009-12-18 10:44:48.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_match_cats.c 2018-01-18 08:59:02.000000000 +0000 @@ -33,16 +33,16 @@ Includes -----------------------------------------------------------------------------*/ +#include "irplib_match_cats.h" #include -#include -#include -#include "irplib_match_cats.h" +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ #define FILENAME_SZBUF 1024 - /*----------------------------------------------------------------------------*/ /* Private functions */ @@ -90,8 +90,8 @@ (int * cats_idx_set_ptr, int ncats); -int nCombinations; -int nFilter; +int irplib_nCombinations; +int irplib_nFilter; /*----------------------------------------------------------------------------*/ /** @@ -157,8 +157,8 @@ int icat1; int icat2; - nCombinations = 0; - nFilter = 0; + irplib_nCombinations = 0; + irplib_nFilter = 0; for(icat1 = 0; icat1 < ncats ; ++icat1) for(icat2 = icat1 + 1 ; icat2 < ncats ; ++icat2) @@ -174,7 +174,7 @@ for(iobj1 = 0; iobj1 < nobj1 ; ++iobj1) for(iobj2 = 0 ; iobj2 < nobj2 ; ++iobj2) { - ++nCombinations; + ++irplib_nCombinations; if(binary_match_condition(catalogues[icat1], catalogues[icat2], iobj1, iobj2)) @@ -182,7 +182,7 @@ cpl_array * cats_idx_set; int icat; - ++nFilter; + ++irplib_nFilter; cats_idx_set = cpl_array_new(ncats, CPL_TYPE_INT); for(icat = 0; icat < ncats; ++icat) { diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_match_cats.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_match_cats.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_match_cats.h 2009-12-18 10:44:48.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_match_cats.h 2018-01-18 08:57:36.000000000 +0000 @@ -34,6 +34,10 @@ #include +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + cpl_table * irplib_match_cat_pairs (cpl_table ** catalogues, int nCats, @@ -41,6 +45,6 @@ (cpl_table * catalogue1, cpl_table * catalogue2, int iobj1, - int iobj2) ); + int iobj2) ) CPL_ATTR_ALLOC; #endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_plugin.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_plugin.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_plugin.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_plugin.c 2017-09-18 13:05:17.000000000 +0000 @@ -33,15 +33,14 @@ #include #endif +#include "irplib_plugin.h" + +#include "irplib_utils.h" /* irplib_reset() */ + #include #include #include -#include - - -#include "irplib_plugin.h" - /*----------------------------------------------------------------------------*/ /** * @defgroup irplib_plugin Irplib plugin functionality @@ -60,9 +59,14 @@ /* Maximum line length in SOF-file */ #ifndef LINE_LEN_MAX -#define LINE_LEN_MAX 1024 +#define LINE_LEN_MAX 1023 #endif +#define LINE_SCAN_FMT \ + "%" CPL_STRINGIFY(LINE_LEN_MAX) "s " \ + "%" CPL_STRINGIFY(LINE_LEN_MAX) "s " \ + "%" CPL_STRINGIFY(LINE_LEN_MAX) "s" + /* This device provides quite-random data */ #define DEV_RANDOM "/dev/urandom" @@ -1023,8 +1027,8 @@ { FILE *fp; - char line[LINE_LEN_MAX]; - char path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX]; + char line[LINE_LEN_MAX + 1]; + char path[LINE_LEN_MAX + 1], group[LINE_LEN_MAX + 1], tag[LINE_LEN_MAX + 1]; int line_number; assert( set != NULL ); @@ -1037,18 +1041,15 @@ } /* Loop over all the lines in the set-of-frames file */ - for (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) { + for (line_number = 0; fgets(line, LINE_LEN_MAX, fp); line_number++) { - char scan_fmt[50]; cpl_frame_group grp; cpl_frame * frame; int n; if (line[0] == '#') continue; - snprintf(scan_fmt, 49, "%%%ds %%%ds %%%ds", LINE_LEN_MAX - 1, - LINE_LEN_MAX - 1, LINE_LEN_MAX - 1); - n = sscanf(line, scan_fmt, path, tag, group); + n = sscanf(line, LINE_SCAN_FMT, path, tag, group); if (n < 1) { cpl_msg_warning(cpl_func, "Spurious line no. %d in %s: %s", diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_plugin.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_plugin.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_plugin.h 2012-01-11 08:03:37.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_plugin.h 2017-09-18 08:31:18.000000000 +0000 @@ -32,19 +32,9 @@ Includes -----------------------------------------------------------------------------*/ -#include /* irplib_reset() */ - #include /*----------------------------------------------------------------------------- - Define - -----------------------------------------------------------------------------*/ - -/* Needed (by uves) to concatenate two macro arguments */ -#define IRPLIB_CONCAT(a,b) a ## _ ## b -#define IRPLIB_CONCAT2X(a,b) IRPLIB_CONCAT(a,b) - -/*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_polynomial.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_polynomial.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_polynomial.c 2017-02-03 09:54:27.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_polynomial.c 2017-09-18 08:52:16.000000000 +0000 @@ -34,6 +34,10 @@ #endif #include "irplib_polynomial.h" + +/* IRPLIB_SWAP_DOUBLE: */ +#include "irplib_utils.h" + #include #include /* DBL_MAX: */ @@ -49,18 +53,6 @@ /**@{*/ /*----------------------------------------------------------------------------- - Macro definitions - -----------------------------------------------------------------------------*/ - -#define IRPLIB_SWAP(a,b) { const double t=(a);(a)=(b);(b)=t; } - -#if 0 -#define irplib_trace() cpl_msg_info(cpl_func, "%d: Trace", __LINE__) -#else -#define irplib_trace() /* Trace */ -#endif - -/*----------------------------------------------------------------------------- Static functions -----------------------------------------------------------------------------*/ @@ -335,7 +327,7 @@ cpl_vector * reals = cpl_vector_wrap(*preal, cpl_vector_get_data(roots)); - cpl_vector_sort(reals, 1); + cpl_vector_sort(reals, CPL_SORT_ASCENDING); (void)cpl_vector_unwrap(reals); } } @@ -353,9 +345,11 @@ @param p2 The non-zero coefficient to x^2 @param p1 The coefficient to x @param p0 The constant term - @param px1 The 1st root or the real part of the complex roots - @param px2 The 2nd root or the imaginary part of the complex roots - @return CPL_TRUE iff the roots are complex + @param px1 The 1st real root or the real part of the complex, conjugate + roots + @param px2 The 2nd real root or the positive, imaginary part of the + complex roots + @return CPL_TRUE iff the roots are complex conjugate */ /*----------------------------------------------------------------------------*/ @@ -384,10 +378,8 @@ /* x1 is the root with largest absolute value */ if (p1 > 0.0) { x1 = -0.5 * (p1 + sqrtD); - irplib_trace(); /* OK */ } else { x1 = -0.5 * (p1 - sqrtD); - irplib_trace(); /* OK */ } /* Compute smaller root via division to avoid loss of precision due to cancellation */ @@ -401,11 +393,9 @@ if (x2 > x1) { *px1 = x1; *px2 = x2; - irplib_trace(); /* OK */ } else { *px1 = x2; *px2 = x1; - irplib_trace(); /* OK */ } } @@ -420,7 +410,6 @@ *px1 = x1; *px2 = x2; is_complex = CPL_TRUE; - irplib_trace(); /* OK */ } return is_complex; @@ -450,13 +439,11 @@ if (is_c) { res = fabs(p0 + x1 * (p1 + x1 * p2) - p2 * x2 * x2); - irplib_trace(); /* OK */ } else { const double r1 = fabs(p0 + x1 * (p1 + x1 * p2)); const double r2 = fabs(p0 + x2 * (p1 + x2 * p2)); res = r1 > r2 ? r1 : r2; - irplib_trace(); /* OK */ } return res; @@ -492,12 +479,10 @@ - x3 * x3 * ( 3.0 * p3 * x2 + p2)); res = r1 > r2 ? r1 : r2; - irplib_trace(); /* OK */ } else { const double r2 = fabs(p0 + x2 * (p1 + x2 * (p2 + x2 * p3))); const double r3 = fabs(p0 + x3 * (p1 + x3 * (p2 + x3 * p3))); res = r1 > r2 ? (r1 > r3 ? r1 : r3) : (r2 > r3 ? r2 : r3); - irplib_trace(); /* OK */ } /* cpl_msg_info(cpl_func, "%d: %g (%g)", __LINE__, res, r1); */ @@ -592,7 +577,6 @@ if (pdbl1 != NULL) *pdbl1 = CPL_FALSE; if (!is_c && pdbl2 != NULL) *pdbl2 = dbl2; is_complex = is_c; - irplib_trace(); /* OK */ } @@ -617,7 +601,6 @@ if (pdbl1 != NULL) *pdbl1 = CPL_FALSE; if (pdbl2 != NULL) *pdbl2 = CPL_FALSE; is_complex = CPL_FALSE; - irplib_trace(); /* OK */ } } @@ -643,7 +626,6 @@ if (pdbl1 != NULL) *pdbl1 = CPL_FALSE; if (pdbl2 != NULL) *pdbl2 = dbl2; is_complex = CPL_FALSE; - irplib_trace(); /* OK */ } @@ -664,7 +646,6 @@ if (pdbl1 != NULL) *pdbl1 = dbl1; if (pdbl2 != NULL) *pdbl2 = CPL_FALSE; is_complex = CPL_FALSE; - irplib_trace(); /* OK */ } } @@ -673,13 +654,10 @@ *px1 = x1; *px2 = x2; *px3 = x3; - irplib_trace(); /* OK */ } else if (is_complex) { *px1 = x1; - irplib_trace(); /* OK */ } else { *px1 = x3; - irplib_trace(); /* OK */ } return is_complex; @@ -717,7 +695,6 @@ *px2 = x2; *px3 = x3; - irplib_trace(); /* OK */ return; } @@ -755,18 +732,15 @@ end up here, with the sign lost for one of them */ x3 = x2 = -a < x1 ? -sqrt(fabs(c / x1)) : sqrt(fabs(c / x1)); if (pdbl2 != NULL) *pdbl2 = CPL_TRUE; - irplib_trace(); /* OK */ } else if (a < 0.0) { /* a and sqrt(Q) have opposite signs - or Q is zero */ x3 = x2 = sqrtQ - a / 3.0; x1 = -c / (x2 * x2); if (pdbl2 != NULL) *pdbl2 = CPL_TRUE; - irplib_trace(); /* OK */ } else { x1 = -2.0 * sqrtQ; x3 = x2 = sqrtQ; if (pdbl2 != NULL) *pdbl2 = CPL_TRUE; - irplib_trace(); /* OK */ } *px1 = x1; @@ -832,7 +806,6 @@ x3 = 0.5 * CPL_MATH_SQRT3 * fabs(A - B); x1 = -c / (x2 * x2 + x3 * x3); - irplib_trace(); /* OK */ } else { /* A+B and a have opposite signs - or exactly one is zero */ x1 = A + B - a / 3.0; @@ -842,24 +815,20 @@ if (x3 > 0.0) { /* Real part of complex conjugate */ x2 = -0.5 * (A + B) - a / 3.0; /* FIXME: Cancellation */ - irplib_trace(); /* OK */ } else { x2 = -a < x1 ? -sqrt(fabs(c / x1)) : sqrt(fabs(c / x1)); x3 = 0.0; - irplib_trace(); /* OK */ } } if (x3 > 0.0) { is_complex = CPL_TRUE; - irplib_trace(); /* OK */ } else { /* Whoaa, the imaginary part was truncated to zero - return a real, double root */ x3 = x2; if (pdbl2 != NULL) *pdbl2 = CPL_TRUE; - irplib_trace(); /* OK */ } *px1 = x1; @@ -920,7 +889,6 @@ /* FIXME: Cancellation may still effect x3 ? */ x3 = TR3 - a / 3.0; x2 = -c / ( x1 * x3 ); - irplib_trace(); /* OK */ } else { /* FIXME: Cancellation may still effect x2, especially if x2, x3 is (almost) a double root, i.e. @@ -928,24 +896,20 @@ x2 = TR2 - a / 3.0; x3 = -c / ( x1 * x2 ); - irplib_trace(); /* OK */ } } else if (a < 0.0) { x3 = TR3 - a / 3.0; if (TR2 < 0.0 && (TR1 + TR2) > 2.0 * a) { x1 = TR1 - a / 3.0; x2 = -c / ( x1 * x3 ); - irplib_trace(); /* OK */ } else { x2 = TR2 - a / 3.0; x1 = -c / ( x2 * x3 ); - irplib_trace(); /* OK */ } } else { x1 = TR1; x2 = TR2; x3 = TR3; - irplib_trace(); /* OK */ } assert(x1 < x3); @@ -959,7 +923,6 @@ theta is close to PI */ x1 = x2 = 0.5 * ( x1 + x2 ); - irplib_trace(); /* OK, tested only for x1 == x2 */ } else if (x2 > x3) { /* In absence of round-off: theta == 0: x2 == x3, @@ -969,7 +932,6 @@ Round-off can cause x2 to become greater than x3 */ x3 = x2 = 0.5 * ( x2 + x3 ); - irplib_trace(); /* OK */ } *px1 = x1; @@ -1047,7 +1009,7 @@ x4 -= 0.25 * p3 / p4; /* Need (only) a guarded swap of x2, x3 */ if (x2 > x3) { - IRPLIB_SWAP(x2, x3); + IRPLIB_SWAP_DOUBLE(x2, x3); } if (dbl1) { assert( x1 <= x2); /* The cubic may have 0 as triple root */ @@ -1064,7 +1026,7 @@ if (x1 > x2) { assert( x3 <= x2 ); /* Don't swap a complex root */ - IRPLIB_SWAP(x1, x2); + IRPLIB_SWAP_DOUBLE(x1, x2); } else { assert( x3 >= x2 ); } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_sdp_spectrum.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_sdp_spectrum.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_sdp_spectrum.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_sdp_spectrum.c 2018-01-10 08:22:39.000000000 +0000 @@ -1598,6 +1598,44 @@ GET_SET_METHODS_TYPE_DOUBLE(tdmax, KEY_TDMAX(1), KEY_TDMAX1_COMMENT) +#if 0 +/*----------------------------------------------------------------------------*/ +/** + * @brief Replace a keyword comment by a custom string. + * @param self The spectrum object to update. + * @param keyword The name of the keyword to update. + * @param comment The string to use as keyword comment. + * @return @c CPL_ERROR_NONE on success or an appropriate error code otherwise. + * + * This function will replace the comment of the keyword @c keyword with + * the string @c comment. The string @c keyword is the full keyword name. + * Both, the keyword @c keyword and the new comment @c comment must not + * be @a NULL. + * If any error occurs then a error code is set and returned, otherwise + * @c CPL_ERROR_NONE is returned on success. + */ +/*----------------------------------------------------------------------------*/ + +cpl_error_code +irplib_sdp_spectrum_replace_comment(irplib_sdp_spectrum *self, + const char *keyword, + const char *comment) +{ + cpl_ensure_code((self != NULL) && (keyword != NULL) && (comment != NULL), + CPL_ERROR_NULL_INPUT); + cpl_ensure_code((self->proplist != NULL), CPL_ERROR_ILLEGAL_INPUT); + + if (!cpl_propertylist_has(self->proplist, keyword)) { + return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Could not find '%s' keyword.", keyword); + } + + cpl_propertylist_set_comment(self->proplist, keyword, comment); + return CPL_ERROR_NONE; +} +#endif + + cpl_error_code irplib_sdp_spectrum_append_prov(irplib_sdp_spectrum *self, cpl_size firstindex, const cpl_frameset *frames) @@ -2496,6 +2534,57 @@ } +/*----------------------------------------------------------------------------*/ +/** + * @brief Replace the comment of a column description keyword. + * @param self The spectrum object to update. + * @param name The name of the column to update. + * @param keyword The name of the keyword to update. + * @param comment The string to use as keyword comment. + * @return @c CPL_ERROR_NONE on success or an appropriate error code otherwise. + * + * This function will replace the comment of the keyword @c keyword of + * the column @c name with the string @c comment. The string @c keyword + * is the keyword name without the column index appended. The latter is + * deduced from the column name @name. The new comment @c comment must not + * be @a NULL. + * If any error occurs then a error code is set and returned, otherwise + * @c CPL_ERROR_NONE is returned on success. + */ +/*----------------------------------------------------------------------------*/ + +cpl_error_code +irplib_sdp_spectrum_replace_column_comment(irplib_sdp_spectrum *self, + const char *name, + const char *keyword, + const char *comment) +{ + cpl_ensure_code((self != NULL), CPL_ERROR_NULL_INPUT); + cpl_ensure_code((self->proplist != NULL), CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((name != NULL) && (keyword != NULL) && (comment != NULL), + CPL_ERROR_NULL_INPUT); + + cpl_size index = _irplib_sdp_spectrum_get_column_index(self, name); + if (index == (cpl_size)-1) { + return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Could not find column '%s'.", name); + } + + char *propname = cpl_sprintf("%s%"CPL_SIZE_FORMAT, keyword, index + 1); + if (!cpl_propertylist_has(self->proplist, propname)) { + cpl_free(propname); + return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND, + "Could not find '%s' keyword for column '%s'.", keyword, + name); + } + + cpl_propertylist_set_comment(self->proplist, propname, comment); + cpl_free(propname); + + return CPL_ERROR_NONE; +} + + const cpl_array * irplib_sdp_spectrum_get_column_data(const irplib_sdp_spectrum *self, const char *name) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_sdp_spectrum.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_sdp_spectrum.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_sdp_spectrum.h 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_sdp_spectrum.h 2018-01-10 08:22:39.000000000 +0000 @@ -599,6 +599,16 @@ const char *name); /* + * Method to replace the default keyword comment with a custom comment + */ + +cpl_error_code +irplib_sdp_spectrum_replace_column_comment(irplib_sdp_spectrum *self, + const char *name, + const char *keyword, + const char *comment); + +/* * Column manipulation functions. */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_spectrum.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_spectrum.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_spectrum.h 2009-07-30 12:38:37.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_spectrum.h 2017-09-18 08:05:11.000000000 +0000 @@ -48,7 +48,7 @@ } spec_shadows ; /*----------------------------------------------------------------------------- - Prototypes + Function prototypes -----------------------------------------------------------------------------*/ int irplib_spectrum_find_brightest(const cpl_image *, int, spec_shadows, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_stdstar.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_stdstar.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_stdstar.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_stdstar.c 2018-01-18 08:55:56.000000000 +0000 @@ -42,18 +42,6 @@ #include #include -/*----------------------------------------------------------------------------- - Defines - -----------------------------------------------------------------------------*/ - -#if defined CPL_VERSION_CODE && CPL_VERSION_CODE >= CPL_VERSION(6, 3, 0) -#define IRPLIB_FRAMESET_GET_CONST cpl_frameset_get_position_const -#else -/* Remove this branch once CPL versions less than 6.3 are no longer supported */ -#define IRPLIB_FRAMESET_GET_CONST cpl_frameset_get_frame_const -#endif - - /*----------------------------------------------------------------------------*/ /** * @defgroup irplib_stdstar Functions for standard stars @@ -119,7 +107,8 @@ /* Process the catalogs */ for (i = 0; i < nb_catalogs; i++) { /* Get the catalog name */ - const cpl_frame * cur_frame = IRPLIB_FRAMESET_GET_CONST(set_raw, i); + const cpl_frame * cur_frame = cpl_frameset_get_position_const(set_raw, + i); const char * cat_name = cpl_frame_get_filename(cur_frame); cpl_table * out = convert_ascii_table(cat_name); @@ -335,15 +324,14 @@ /*----------------------------------------------------------------------------*/ /** - @brief Select the stars that are within a given distance - @param cat the catalog - @param ra RA pos - @param dec DEC pos - @param dist the distancw - @return 0 if ok, -1 in error case + @brief Deselect the stars that are beyond a given distance + @param cat The standard star catalog, with too distant stars to unselect + @param ra Right ascension [degrees] + @param dec Declination [degrees] + @param dist The distance [degrees] + @return 0 if ok, -1 in error case - The stars that are within not further than dist from ra,dec are - selected in the table. + The stars that are further than dist from ra,dec are unselected in the table. */ /*----------------------------------------------------------------------------*/ int irplib_stdstar_select_stars_dist( @@ -352,31 +340,34 @@ double dec, double dist) { - double distance; - int nrows; - int i; + cpl_size i, nrows; /* Check entries */ if (cat == NULL) return -1; /* Get the number of selected rows */ nrows = cpl_table_get_nrow(cat); - + /* Check if the columns are there */ if (!cpl_table_has_column(cat, IRPLIB_STDSTAR_RA_COL)) { - cpl_msg_error(cpl_func, "Missing %s column", IRPLIB_STDSTAR_RA_COL); + cpl_msg_error(cpl_func, "Missing column: " IRPLIB_STDSTAR_RA_COL); return -1; } if (!cpl_table_has_column(cat, IRPLIB_STDSTAR_DEC_COL)) { - cpl_msg_error(cpl_func, "Missing %s column", IRPLIB_STDSTAR_DEC_COL); + cpl_msg_error(cpl_func, "Missing column: " IRPLIB_STDSTAR_DEC_COL); + return -1; + } + + if (cpl_table_count_selected(cat) == 0) { + cpl_msg_error(cpl_func, "All %d row(s) already deselected", (int)nrows); return -1; } /* Compute distances of the selected rows */ - for (i=0; i dist) cpl_table_unselect_row(cat, i); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_strehl.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_strehl.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_strehl.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_strehl.c 2017-10-23 09:30:58.000000000 +0000 @@ -102,9 +102,15 @@ static cpl_error_code irplib_gaussian_maxpos(const cpl_image *, double, + double, + double, double *, double *, double *); + +static cpl_error_code +irplib_closeset_aperture(const cpl_apertures * self, + const double x, const double y, int * ind); #endif /*----------------------------------------------------------------------------- @@ -219,7 +225,7 @@ *psf_flux = 1.0; /* The psf flux, cpl_image_get_flux(psf), is always 1 */ #ifndef IRPLIB_NO_FIT_GAUSSIAN - code = irplib_gaussian_maxpos(im, IRPLIB_STREHL_DETECT_LEVEL, + code = irplib_gaussian_maxpos(im, IRPLIB_STREHL_DETECT_LEVEL, xpos, ypos, &xposfit, &yposfit, &peak); if (code) { cpl_errorstate_set(prestate); @@ -707,7 +713,9 @@ /*----------------------------------------------------------------------------*/ static double PSF_sinc_norm(double x) { - return sin(x * CPL_MATH_PI) / (x * CPL_MATH_PI); + /* This static function should not be called with zero, but handle it + anyway. */ + return x != 0.0 ? sin(x * CPL_MATH_PI) / (x * CPL_MATH_PI) : 1.0; } /*----------------------------------------------------------------------------* @@ -893,6 +901,33 @@ } +static cpl_error_code +irplib_closeset_aperture(const cpl_apertures * self, + const double x, const double y, int * ind){ + + double dist = INFINITY; + + const int nsize = cpl_apertures_get_size(self); + + cpl_ensure_code(nsize > 0, cpl_error_get_code()); + cpl_ensure_code(ind, CPL_ERROR_NULL_INPUT); + + *ind = -1; + + for(int i = 1; i <= nsize; ++i){ + const double this_x = cpl_apertures_get_centroid_x(self, i); + const double this_y = cpl_apertures_get_centroid_y(self, i); + const double this_d_sq = pow(this_x - x, 2.0) + pow(this_y - y, 2.0); + + if(this_d_sq < dist){ + dist = this_d_sq; + *ind = i; + } + + } + return CPL_ERROR_NONE; +} + /*----------------------------------------------------------------------------*/ /** @brief Find the peak flux, peak sum and position of a Gaussian @@ -907,7 +942,9 @@ /*----------------------------------------------------------------------------*/ static cpl_error_code irplib_gaussian_maxpos(const cpl_image * self, - double sigma, + double sigma, + double x_initial, + double y_initial, double * pxpos, double * pypos, double * ppeak) @@ -971,8 +1008,8 @@ aperts = cpl_apertures_new_from_image(self, labels); - /* Find the aperture with the greatest flux */ - code = irplib_apertures_find_max_flux(aperts, &ifluxapert, 1); + /* Find the aperture closest to the provided coordinates */ + code = irplib_closeset_aperture(aperts, x_initial, y_initial, &ifluxapert); if (code) { cpl_apertures_delete(aperts); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_strehl.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_strehl.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_strehl.h 2014-03-19 11:44:02.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_strehl.h 2017-09-18 08:05:11.000000000 +0000 @@ -104,7 +104,7 @@ } irplib_strehl_bg_method; /*----------------------------------------------------------------------------- - Functions prototypes + Function prototypes -----------------------------------------------------------------------------*/ cpl_error_code irplib_strehl_compute(const cpl_image *, double, double, double, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_utils.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_utils.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_utils.c 2017-02-06 12:49:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_utils.c 2017-09-18 08:05:11.000000000 +0000 @@ -32,9 +32,6 @@ #include #include -#include -#include - /*----------------------------------------------------------------------------- Defines -----------------------------------------------------------------------------*/ @@ -1726,3 +1723,82 @@ } return cpl_frameset_iterator_get_const(iterator); } + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Find the kth smallest value in a cpl_vector + @param self The vector to permute and search + @param k The requested value position in the sorted array, zero for 1st + + After a successful call, self is permuted so elements less than the kth have + lower indices, while elements greater than the kth have higher indices. If + the call fails, self is not modified. + + Reference: + + Author: Wirth, Niklaus + Title: Algorithms + data structures = programs + Publisher: Englewood Cliffs: Prentice-Hall, 1976 + Physical description: 366 p. + Series: Prentice-Hall Series in Automatic Computation + + See also: http://ndevilla.free.fr/median/median/ + + */ +/*----------------------------------------------------------------------------*/ + +void irplib_vector_get_kth(cpl_vector * self, cpl_size k) +{ + + cpl_size l = 0; + cpl_size m = cpl_vector_get_size(self) - 1; + cpl_size i = l; + cpl_size j = m; + double* pself = cpl_vector_get_data(self); + + if (pself == NULL) { + (void)cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return; + } else if (k < 0) { + (void)cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + return; + } else if (k > m) { + (void)cpl_error_set(cpl_func, CPL_ERROR_ACCESS_OUT_OF_RANGE); + return; + } + + while (l < m) { + const double x = pself[k]; + + do { + while (pself[i] < x) i++; + while (x < pself[j]) j--; + if (i <= j) { + IRPLIB_SWAP_DOUBLE(pself[i], pself[j]); + i++; j--; + } + } while (i <= j); + + assert( j < i ); + + /* The original implementation has two index comparisons and + two, three or four index assignments. This has been reduced + to one or two index comparisons and two index assignments. + */ + + if (k <= j) { + assert( k < i ); + m = j; + i = l; + } else { + if (k < i) { + m = j; + } else { + j = m; + } + l = i; + } + } +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_utils.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_utils.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_utils.h 2014-06-06 12:23:07.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_utils.h 2017-09-18 13:05:17.000000000 +0000 @@ -71,11 +71,29 @@ #include /*----------------------------------------------------------------------------- - Define + Defines -----------------------------------------------------------------------------*/ -#define IRPLIB_XSTRINGIFY(TOSTRING) #TOSTRING -#define IRPLIB_STRINGIFY(TOSTRING) IRPLIB_XSTRINGIFY(TOSTRING) +/* Concatenate two macro arguments */ +#define IRPLIB_CONCAT(a,b) a ## _ ## b +#define IRPLIB_CONCAT2X(a,b) IRPLIB_CONCAT(a,b) + +/*----------------------------------------------------------------------------*/ +/* + @brief Swap two double values + @param A The 1st double to swap + @param B The 2nd double to swap + @note A and B are evaluated twice, so side-effects should be avoided +*/ +/*----------------------------------------------------------------------------*/ +#define IRPLIB_SWAP_DOUBLE(A, B) do { \ + const double irplib_swap_double=(A); \ + (A)=(B); \ + (B)=irplib_swap_double; \ + } while (0) + +#define IRPLIB_XSTRINGIFY CPL_XSTRINGIFY +#define IRPLIB_STRINGIFY CPL_STRINGIFY #if !defined __GNUC__ && !defined __inline__ #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L @@ -85,31 +103,21 @@ #endif #endif -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#define IRPLIB_DIAG_PRAGMA_PUSH_IGN(x) \ - _Pragma("GCC diagnostic push") \ - _Pragma(IRPLIB_STRINGIFY(GCC diagnostic ignored #x)) -#define IRPLIB_DIAG_PRAGMA_PUSH_ERR(x) \ - _Pragma("GCC diagnostic push") \ - _Pragma(IRPLIB_STRINGIFY(GCC diagnostic error #x)) -#define IRPLIB_DIAG_PRAGMA_POP \ - _Pragma("GCC diagnostic pop") -#else -#define IRPLIB_DIAG_PRAGMA_PUSH_IGN(x) -#define IRPLIB_DIAG_PRAGMA_PUSH_ERR(x) -#define IRPLIB_DIAG_PRAGMA_POP -#endif - +#define IRPLIB_DIAG_PRAGMA_PUSH_IGN CPL_DIAG_PRAGMA_PUSH_IGN +#define IRPLIB_DIAG_PRAGMA_PUSH_ERR CPL_DIAG_PRAGMA_PUSH_ERR +#define IRPLIB_DIAG_PRAGMA_POP CPL_DIAG_PRAGMA_POP /* FIXME: Remove when no longer used by any irplib-based pipelines */ /* Useful for debugging */ -#define irplib_trace() do if (cpl_error_get_code()) { \ - cpl_msg_debug(cpl_func, __FILE__ " at line %d: ERROR '%s' at %s", \ - __LINE__, cpl_error_get_message(), cpl_error_get_where()); \ - } else { \ - cpl_msg_debug(cpl_func, __FILE__ " at line %d: OK", __LINE__); \ - } while (0) - +#define irplib_trace() do if (cpl_error_get_code()) { \ + cpl_msg_debug(cpl_func, __FILE__ " at line " \ + CPL_STRINGIFY(__LINE__) ": ERROR '%s' at %s", \ + cpl_error_get_message(), cpl_error_get_where()); \ + } else { \ + cpl_msg_debug(cpl_func, __FILE__ " at line " \ + CPL_STRINGIFY(__LINE__) ": OK"); \ + } while (0) + #define irplib_error_recover(ESTATE, ...) \ do if (!cpl_errorstate_is_equal(ESTATE)) { \ cpl_msg_warning(cpl_func, __VA_ARGS__); \ @@ -291,16 +299,16 @@ @note end_skip should be used exactly once in functions that use skip_if() etc */ /*----------------------------------------------------------------------------*/ -#define end_skip \ - do { \ - cleanup: \ - if (cpl_error_get_code()) \ - cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u with " \ - "error '%s' at %s", __LINE__, \ - cpl_error_get_message(), cpl_error_get_where()); \ - else \ - cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line %u", \ - __LINE__); \ +#define end_skip \ + do { \ + cleanup: \ + if (cpl_error_get_code()) \ + cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line " \ + CPL_STRINGIFY(__LINE__) " with error '%s' at %s", \ + cpl_error_get_message(), cpl_error_get_where()); \ + else \ + cpl_msg_debug(cpl_func, "Cleanup in " __FILE__ " line " \ + CPL_STRINGIFY(__LINE__)); \ } while (0) @@ -352,16 +360,16 @@ */ /*----------------------------------------------------------------------------*/ -#define irplib_check(COMMAND, ...) \ - do { \ - cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \ - skip_if(0); \ - COMMAND; \ - irplib_trace(); \ - irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \ - cpl_error_get_code(), __VA_ARGS__); \ - irplib_trace(); \ - } while (0) +#define irplib_check(COMMAND, ...) \ + do { \ + cpl_errorstate irplib_check_prestate = cpl_errorstate_get(); \ + skip_if(0); \ + COMMAND; \ + irplib_trace(); \ + irplib_ensure(cpl_errorstate_is_equal(irplib_check_prestate), \ + cpl_error_get_code(), __VA_ARGS__); \ + irplib_trace(); \ + } while (0) /*----------------------------------------------------------------------------- Function prototypes @@ -517,6 +525,9 @@ const cpl_frame * irplib_frameset_get_next_const(cpl_frameset_iterator *iterator); + +void irplib_vector_get_kth(cpl_vector *, cpl_size); + /*----------------------------------------------------------------------------- Function inlines -----------------------------------------------------------------------------*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wavecal.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wavecal.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wavecal.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wavecal.c 2018-01-25 09:32:20.000000000 +0000 @@ -30,8 +30,6 @@ /* Needed for irplib_errorstate_dump_debug() */ #include "irplib_utils.h" -#include - #include #include @@ -1013,19 +1011,20 @@ /*----------------------------------------------------------------------------*/ /** - @brief Generate a 1D spectrum from (arc) lines and a dispersion relation - @param self Vector to fill with spectrum - @param linepix Vector to update with best guess of line pixel position - @param disp 1D-Dispersion relation, at least of degree 1 - @param lines Catalogue of lines, with increasing wavelengths - @param wslit Positive width of the slit - @param wfwhm Positive FWHM of the transfer function - @param xtrunc Truncate the line profile beyond distance xtrunc, xtrunc > 0 - @param hsize The 1st intensity in self will be disp(1-hsize), hsize >= 0 - @param dofast Iff true compose profile from pairs of two integer-placed - @param dolog Iff true log(1+I) is used for the (positive) intensities - @param pulines Iff non-NULL, number of lines used, on success - @return CPL_ERROR_NONE on success, otherwise the relevant CPL error code + @brief Generate a 1D spectrum from (arc) lines and a dispersion relation + @param self Vector to fill with spectrum + @param linepix Vector to update with best guess of line pixel position + @param erftmp Vector with temporary buffer for erf() values + @param disp 1D-Dispersion relation, at least of degree 1 + @param lines Catalogue of lines, with increasing wavelengths + @param wslit Positive width of the slit + @param wfwhm Positive FWHM of the transfer function + @param xtrunc Truncate the line profile beyond distance xtrunc, xtrunc > 0 + @param hsize The 1st intensity in self will be disp(1-hsize), hsize >= 0 + @param dofast Iff true compose profile from pairs of two integer-placed + @param dolog Iff true log(1+I) is used for the (positive) intensities + @param pulines Iff non-NULL, number of lines used, on success + @return CPL_ERROR_NONE on success, otherwise the relevant CPL error code @see irplib_vector_fill_line_spectrum() @note This function is supposed to be called via irplib_vector_fill_line_spectrum(). diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wcs.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wcs.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wcs.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wcs.c 2017-05-23 15:09:28.000000000 +0000 @@ -25,19 +25,18 @@ * $Name: not supported by cvs2svn $ */ -#ifdef HAVE_CONFIG_H -#include -#endif - /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ -#include -#include +#ifdef HAVE_CONFIG_H +#include +#endif #include "irplib_wcs.h" +#include + /*----------------------------------------------------------------------------*/ /** * @defgroup irplib_wcs Functions related to WCS @@ -46,6 +45,9 @@ static cpl_error_code irplib_wcs_is_iso8601(int, int, int, int, int, double); +/* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */ +#define IRPLIB_ISO8601_FORMAT "%4d-%2d-%2dT%2d:%2d:%lf" + /**@{*/ /*----------------------------------------------------------------------------*/ @@ -237,8 +239,7 @@ const char * iso8601) { - /* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */ - const char * iso8601format = "%4d-%2d-%2dT%2d:%2d:%lf"; + int nret; cpl_ensure_code(pyear != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(pmonth != NULL, CPL_ERROR_NULL_INPUT); @@ -248,16 +249,18 @@ cpl_ensure_code(psecond != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(iso8601 != NULL, CPL_ERROR_NULL_INPUT); - cpl_error_ensure(sscanf(iso8601, iso8601format, pyear, pmonth, - pday, phour, pminute, psecond) == 6, - CPL_ERROR_ILLEGAL_INPUT, return cpl_error_get_code(), - "%s is not formatted as %s", iso8601, iso8601format); - - cpl_ensure_code(!irplib_wcs_is_iso8601(*pyear, *pmonth, *pday, *phour, - *pminute, *psecond), - cpl_error_get_code()); + nret = sscanf(iso8601, IRPLIB_ISO8601_FORMAT, pyear, pmonth, + pday, phour, pminute, psecond); - return CPL_ERROR_NONE; + if (nret != 6) { + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "Parsed" + " %d != 6: input %s is not in format %s", + nret, iso8601, IRPLIB_ISO8601_FORMAT); + } + + return irplib_wcs_is_iso8601(*pyear, *pmonth, *pday, *phour, *pminute, + *psecond) + ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE; } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wcs.h cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wcs.h --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wcs.h 2010-10-07 14:10:55.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wcs.h 2017-09-18 08:05:11.000000000 +0000 @@ -34,6 +34,10 @@ #include +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + cpl_error_code irplib_wcs_xytoradec(const cpl_wcs * wcs, double x, double y, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wlxcorr.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wlxcorr.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/irplib_wlxcorr.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/irplib_wlxcorr.c 2017-07-05 12:27:08.000000000 +0000 @@ -352,10 +352,10 @@ corr_poly, spec_sz, 1.0); cpl_error_code error; - cpl_msg_debug(cpl_func, "Tabel for guess dispersion polynomial (slitw=%g, " + cpl_msg_debug(cpl_func, "Table for guess dispersion polynomial (slitw=%g, " "fwhm=%g) with %d-point observed spectrum with%s catalog re" "sampling", slitw, fwhm, spec_sz, guess_resamp ? "out" : ""); - cpl_msg_debug(cpl_func, "Tabel for corr. dispersion polynomial (slitw=%g, " + cpl_msg_debug(cpl_func, "Table for corr. dispersion polynomial (slitw=%g, " "fwhm=%g) with %d-point observed spectrum with%s catalog re" "sampling", slitw, fwhm, spec_sz, corr_resamp ? "out" : ""); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/irplib/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/Makefile.in 2018-04-13 15:46:36.000000000 +0000 @@ -93,7 +93,8 @@ subdir = irplib ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -290,6 +291,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -304,6 +312,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -403,6 +412,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_plugin-test.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_plugin-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_plugin-test.c 2014-07-14 21:05:36.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_plugin-test.c 2017-09-18 08:05:11.000000000 +0000 @@ -26,6 +26,7 @@ -----------------------------------------------------------------------------*/ #include +#include #include #include diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_polynomial-test.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_polynomial-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_polynomial-test.c 2017-02-22 09:54:38.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_polynomial-test.c 2017-06-01 12:59:07.000000000 +0000 @@ -264,6 +264,13 @@ irplib_polynomial_test_root_all(xtrue, nreal, 1.0, 4.0*DBL_EPSILON, 30.0*DBL_EPSILON); + (void)cpl_vector_set(xtrue, 0, 1.0); + (void)cpl_vector_set(xtrue, 1, 2.0); + (void)cpl_vector_set(xtrue, 2, 1.0); + + irplib_polynomial_test_root_all(xtrue, nreal-2, 1.0, + 4.0*DBL_EPSILON, 30.0*DBL_EPSILON); + #if MAXDEGREE > 3 nreal = 4; @@ -552,9 +559,12 @@ code = irplib_polynomial_solve_1d_all(p1d, roots, &jreal); cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_msg_info(cpl_func, "1D-polynomial of degree %d:", (int)degree); + cpl_polynomial_dump(p1d, stderr); + cpl_test_eq(jreal, nreal); if (jreal != nreal) { - cpl_msg_info(cpl_func, "1D-polynomial:"); + cpl_msg_info(cpl_func, "1D-polynomial of degree %d:", (int)degree); cpl_polynomial_dump(p1d, stderr); cpl_msg_error(cpl_func, "True roots (%" CPL_SIZE_FORMAT " real): (line=%u)", nreal, line); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_strehl-test.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_strehl-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_strehl-test.c 2014-02-06 10:27:17.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_strehl-test.c 2017-09-18 13:05:17.000000000 +0000 @@ -178,12 +178,12 @@ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); cpl_msg_info("Strehl-testing with star with ", - IRPLIB_XSTRINGIFY(IRPLIB_STREHL_STAR_RADIUS) " = " - IRPLIB_STRINGIFY(IRPLIB_STREHL_STAR_RADIUS) ". " - IRPLIB_XSTRINGIFY(IRPLIB_STREHL_BACKGROUND_R1) " = " - IRPLIB_STRINGIFY(IRPLIB_STREHL_BACKGROUND_R1) ". " - IRPLIB_XSTRINGIFY(IRPLIB_STREHL_BACKGROUND_R2) " = " - IRPLIB_STRINGIFY(IRPLIB_STREHL_BACKGROUND_R2) "."); + CPL_XSTRINGIFY(IRPLIB_STREHL_STAR_RADIUS) " = " + CPL_STRINGIFY(IRPLIB_STREHL_STAR_RADIUS) ". " + CPL_XSTRINGIFY(IRPLIB_STREHL_BACKGROUND_R1) " = " + CPL_STRINGIFY(IRPLIB_STREHL_BACKGROUND_R1) ". " + CPL_XSTRINGIFY(IRPLIB_STREHL_BACKGROUND_R2) " = " + CPL_STRINGIFY(IRPLIB_STREHL_BACKGROUND_R2) "."); irplib_strehl_test_one(); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_utils-test.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_utils-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_utils-test.c 2014-12-02 16:37:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_utils-test.c 2017-09-18 12:47:32.000000000 +0000 @@ -63,6 +63,8 @@ /* Initialize CPL for unit testing */ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + irplib_trace(); + test_irplib_isnaninf(); test_irplib_dfs_table_convert(); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_wcs-test.c cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_wcs-test.c --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/irplib_wcs-test.c 2013-01-29 08:49:53.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/irplib_wcs-test.c 2018-03-06 10:23:52.000000000 +0000 @@ -35,6 +35,7 @@ #include #include "irplib_wcs.h" +#include "math.h" /*----------------------------------------------------------------------------- Static functions @@ -43,6 +44,7 @@ static void irplib_wcs_mjd_test(void); +static void irplib_wcs_great_circle_dist_test(void); /*----------------------------------------------------------------------------- Main @@ -56,6 +58,8 @@ irplib_wcs_mjd_test(); + irplib_wcs_great_circle_dist_test(); + return cpl_test_end(0); } @@ -305,3 +309,56 @@ cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); } + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test the function, using trivial cases + @return void + */ +/*----------------------------------------------------------------------------*/ +static void irplib_wcs_great_circle_dist_test(void) +{ + double dist1, dist2; + + /* Commutative */ + dist1 = irplib_wcs_great_circle_dist(12.0, 34.0, 56.0, 78.0); + dist2 = irplib_wcs_great_circle_dist(56.0, 78.0, 12.0, 34.0); + cpl_test_abs(dist1, dist2, 0.0); + + for (int j = 0; j <= 360; j += 4) { + const double ra2 = CPL_MATH_E + (double)j; + + for (int i = 0; i < 180; i++) { + const double ra1 = (double)i; + const double dec1 = (double)i; + + /* Poles Apart */ + dist1 = irplib_wcs_great_circle_dist(ra2, 90.0, ra2 + ra1, -90.0); + cpl_test_abs(dist1, 180.0, 0.0); + + /* Equatorial */ + dist1 = irplib_wcs_great_circle_dist(ra2, 0.0, ra2 + ra1, 0.0); + cpl_test_abs(dist1, ra1, 2560.0 * DBL_EPSILON); + + /* "I will go on the slightest errand now to the Antipodes..." */ + dist1 = irplib_wcs_great_circle_dist(ra2, dec1, ra2 + 180.0, -dec1); + cpl_test_abs(dist1, 180.0, 30.0 * FLT_EPSILON); + + } + /* Meridional */ + for (int i = -90; i <= 90; i += 3) { + const double dec1 = (double)i; + for (int k = 0; k <= 90; k += 3) { + const double dec2 = (double)k; + + dist1 = irplib_wcs_great_circle_dist(ra2, dec1, ra2, dec2); + cpl_test_abs(dist1, fabs(dec1 - dec2), 1024.0 * DBL_EPSILON); + } + + dist1 = irplib_wcs_great_circle_dist(ra2, dec1, ra2 + 180.0, + 90.0 - dec1); + cpl_test_abs(dist1, 90.0, 512.0 * DBL_EPSILON); + } + } +} diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/irplib/tests/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/irplib/tests/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -98,7 +98,8 @@ subdir = irplib/tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -504,6 +505,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -518,6 +526,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -617,6 +626,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/m4macros/cpl.m4 cpl-plugin-sinfo-3.1.0+dfsg/m4macros/cpl.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/m4macros/cpl.m4 2017-01-27 14:36:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/m4macros/cpl.m4 2017-09-05 11:58:51.000000000 +0000 @@ -14,24 +14,24 @@ AC_REQUIRE([ESO_CHECK_THREADS_POSIX]) AC_ARG_WITH(cfitsio, - AC_HELP_STRING([--with-cfitsio], + AS_HELP_STRING([--with-cfitsio], [location where cfitsio is installed]), [ cpl_with_cfitsio=$withval ]) AC_ARG_WITH(cfitsio-includes, - AC_HELP_STRING([--with-cfitsio-includes], + AS_HELP_STRING([--with-cfitsio-includes], [location of the cfitsio header files]), cpl_with_cfitsio_includes=$withval) AC_ARG_WITH(cfitsio-libs, - AC_HELP_STRING([--with-cfitsio-libs], + AS_HELP_STRING([--with-cfitsio-libs], [location of the cfitsio library]), cpl_with_cfitsio_libs=$withval) AC_ARG_ENABLE(cfitsio-test, - AC_HELP_STRING([--disable-cfitsio-test], + AS_HELP_STRING([--disable-cfitsio-test], [disables checks for the cfitsio library and headers]), cpl_enable_cfitsio_test=$enableval, cpl_enable_cfitsio_test=yes) @@ -378,24 +378,24 @@ AC_REQUIRE([ESO_PROG_PKGCONFIG]) AC_ARG_WITH(cext, - AC_HELP_STRING([--with-cext], + AS_HELP_STRING([--with-cext], [location where libcext is installed]), [ cpl_with_cext=$withval ]) AC_ARG_WITH(cext-includes, - AC_HELP_STRING([--with-cext-includes], + AS_HELP_STRING([--with-cext-includes], [location of the libcext header files]), cpl_with_cext_includes=$withval) AC_ARG_WITH(cext-libs, - AC_HELP_STRING([--with-cext-libs], + AS_HELP_STRING([--with-cext-libs], [location of the libcext library]), cpl_with_cext_libs=$withval) AC_ARG_ENABLE(cext-test, - AC_HELP_STRING([--disable-cext-test], + AS_HELP_STRING([--disable-cext-test], [disables checks for the libcext library and headers]), cpl_enable_cext_test=$enableval, cpl_enable_cext_test=yes) @@ -564,25 +564,25 @@ AC_REQUIRE([ESO_PROG_PKGCONFIG]) AC_ARG_WITH(wcslib, - AC_HELP_STRING([--with-wcslib], + AS_HELP_STRING([--with-wcslib], [location where wcslib is installed]), [ cpl_with_wcs=$withval ]) AC_ARG_WITH(wcslib-includes, - AC_HELP_STRING([--with-wcslib-includes], + AS_HELP_STRING([--with-wcslib-includes], [location of the wcslib header files]), cpl_with_wcs_includes=$withval) AC_ARG_WITH(wcslib-libs, - AC_HELP_STRING([--with-wcslib-libs], + AS_HELP_STRING([--with-wcslib-libs], [location of the wcslib library]), cpl_with_wcs_libs=$withval) AC_ARG_ENABLE(wcs, - AC_HELP_STRING([--disable-wcs], + AS_HELP_STRING([--disable-wcs], [disable WCS support.]), [cpl_enable_wcs=$enable_wcs], [cpl_enable_wcs="yes"]) @@ -851,24 +851,24 @@ AC_REQUIRE([ESO_PROG_PKGCONFIG]) AC_ARG_WITH(fftw, - AC_HELP_STRING([--with-fftw], + AS_HELP_STRING([--with-fftw], [location where fftw is installed]), [ cpl_with_fftw=$withval ]) AC_ARG_WITH(fftw-includes, - AC_HELP_STRING([--with-fftw-includes], + AS_HELP_STRING([--with-fftw-includes], [location of the fftw header files]), cpl_with_fftw_includes=$withval) AC_ARG_WITH(fftw-libs, - AC_HELP_STRING([--with-fftw-libs], + AS_HELP_STRING([--with-fftw-libs], [location of the fftw libraries]), cpl_with_fftw_libs=$withval) AC_ARG_ENABLE(fft, - AC_HELP_STRING([--disable-fft], + AS_HELP_STRING([--disable-fft], [disable FFt support.]), [cpl_enable_fft=$enable_fft], [cpl_enable_fft="yes"]) @@ -1421,24 +1421,24 @@ AC_ARG_WITH(cpl, - AC_HELP_STRING([--with-cpl], + AS_HELP_STRING([--with-cpl], [location where CPL is installed]), [ cpl_with_cpl=$withval ]) AC_ARG_WITH(cpl-includes, - AC_HELP_STRING([--with-cpl-includes], + AS_HELP_STRING([--with-cpl-includes], [location of the CPL header files]), cpl_with_cpl_includes=$withval) AC_ARG_WITH(cpl-libs, - AC_HELP_STRING([--with-cpl-libs], + AS_HELP_STRING([--with-cpl-libs], [location of the CPL library]), cpl_with_cpl_libs=$withval) AC_ARG_ENABLE(cpl-test, - AC_HELP_STRING([--disable-cpl-test], + AS_HELP_STRING([--disable-cpl-test], [disables checks for the CPL library and headers]), cpl_enable_cpl_test=$enableval, cpl_enable_cpl_test=yes) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/m4macros/eso.m4 cpl-plugin-sinfo-3.1.0+dfsg/m4macros/eso.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/m4macros/eso.m4 2016-10-25 09:25:42.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/m4macros/eso.m4 2017-09-05 11:58:51.000000000 +0000 @@ -83,7 +83,7 @@ AC_REQUIRE([AC_PROG_CC]) AC_ARG_ENABLE(debug, - AC_HELP_STRING([--enable-debug], + AS_HELP_STRING([--enable-debug], [creates debugging code [default=$1]]), eso_enable_debug=$enableval, eso_enable_debug=$1) @@ -174,7 +174,7 @@ AC_REQUIRE([AC_PROG_CC]) AC_ARG_ENABLE(strict, - AC_HELP_STRING([--enable-strict], + AS_HELP_STRING([--enable-strict], [compiles with strict compiler options (may not work!) [default=$1]]), eso_enable_strict=$enableval, eso_enable_strict=$1) @@ -211,7 +211,7 @@ AC_REQUIRE([AC_PROG_CC]) AC_ARG_ENABLE(profile, - AC_HELP_STRING([--enable-profile], + AS_HELP_STRING([--enable-profile], [compiles with compiler options necessary for profiling (may not work!) [default=$1]]), eso_enable_profile=$enableval, eso_enable_profile=$1) @@ -285,12 +285,12 @@ [ AC_ARG_WITH(extra-includes, - AC_HELP_STRING([--with-extra-includes=DIR], + AS_HELP_STRING([--with-extra-includes=DIR], [adds non standard include paths]), eso_with_extra_includes=$withval, eso_with_extra_includes=NONE) AC_ARG_WITH(extra-libs, - AC_HELP_STRING([--with-extra-libs=DIR], + AS_HELP_STRING([--with-extra-libs=DIR], [adds non standard library paths]), eso_with_extra_libs=$withval, eso_with_extra_libs=NONE) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/m4macros/gsl.m4 cpl-plugin-sinfo-3.1.0+dfsg/m4macros/gsl.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/m4macros/gsl.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/m4macros/gsl.m4 2017-09-05 11:58:51.000000000 +0000 @@ -0,0 +1,123 @@ +# LIB_CHECK_GSL +#------------------ +# Checks for the gsl library and header files. +AC_DEFUN([CPL_CHECK_GSL], +[ + + AC_MSG_CHECKING([for gsl]) + + AC_ARG_WITH(gsl, + AS_HELP_STRING([--with-gsl], + [location where gsl is installed]), + [ + cpl_gsl_dir=$withval + ]) + + export PKG_CONFIG_PATH="$cpl_gsl_dir/lib/pkgconfig:$cpl_gsl_dir/lib64/pkgconfig:$GSLDIR/lib/pkgconfig/:$GSLDIR/lib64/pkgconfig/:$PKG_CONFIG_PATH" + + AC_SUBST(PKG_CONFIG_PATH) + PKG_CHECK_MODULES([GSL], [gsl], + [AC_DEFINE([HAVE_LIBGSL], [1], [Define to 1 iff you have GSL]) + AC_DEFINE(HAVE_GSL, 1, [Define to 1 iff you have GSL])], + AC_MSG_WARN([No GSL available])) + +]) + +# GSL_CHECK_LIBS +#--------------- +# Checks for the GSL libraries and header files, does not require pkg-config +# If the first argument is "optional" the check is allowed to fail, otherwise +# missing GSL is a fatal error +# adds --with-gsl{,-libs,-includes}, --disable-gsl-test and sets +# GSL_INCLUDES +# GSL_LDFLAGS +# GSL_LIBS +# It defines HAVE_GSL and HAVE_LIBGSL in config.h +AC_DEFUN([GSL_CHECK_LIBS], +[ + + AC_MSG_CHECKING([for GSL]) + + gsl_check_gsl_lib="-lgsl -lgslcblas" + + gsl_includes="" + gsl_libraries="" + + AC_ARG_WITH(gsl, + AS_HELP_STRING([--with-gsl], + [location where GSL is installed]), + [ + gsl_with_gsl_includes=$withval/include + # opensuse defaults also non systems installations to lib64 ... + gsl_with_gsl_libs="-L$withval/lib -L$withval/lib64 -L$withval/lib32" + ]) + + AC_ARG_WITH(gsl-includes, + AS_HELP_STRING([--with-gsl-includes], + [location of the GSL header files]), + gsl_with_gsl_includes=$withval) + + AC_ARG_WITH(gsl-libs, + AS_HELP_STRING([--with-gsl-libs], + [location of the GSL library]), + gsl_with_gsl_libs=-L$withval) + + AC_ARG_ENABLE(gsl-test, + AS_HELP_STRING([--disable-gsl-test], + [disables checks for the GSL library and headers]), + gsl_enable_gsl_test=$enableval, + gsl_enable_gsl_test=yes) + + + if test "x$gsl_enable_gsl_test" = xyes; then + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + if test -n "$gsl_with_gsl_libs"; then + LDFLAGS="$gsl_with_gsl_libs" + elif test -n "$GSLDIR"; then + LDFLAGS="-L$GSLDIR/lib -L$GSLDIR/lib64 -L$GSLDIR/lib32" + else + LDFLAGS="" + fi + if test -n "$gsl_with_gsl_includes"; then + CFLAGS="-I$gsl_with_gsl_includes" + elif test -n "$GSLDIR"; then + CFLAGS="-I$GSLDIR/include" + else + CFLAGS="" + fi + LIBS=$gsl_check_gsl_lib + + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[gsl_sf_bessel_J0(5.);]])],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_GSL, 1, [Define to 1 iff you have GSL]) + AC_DEFINE(HAVE_LIBGSL, 1, [Define to 1 iff you have GSL]) + # Set up the symbols + GSL_INCLUDES="$CFLAGS" + GSL_LDFLAGS="$LDFLAGS" + GSL_LIBS="$gsl_check_gsl_lib" + ],[ + if test "x$1" = xoptional; then + AC_MSG_NOTICE([Optional GSL not found]) + else + AC_MSG_ERROR([GSL not found]) + fi + ]) + + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + else + AC_MSG_RESULT([disabled]) + AC_MSG_WARN([GSL checks have been disabled! This package may not build!]) + GSL_INCLUDES="" + GSL_LDFLAGS="" + GSL_LIBS="" + fi + + AC_SUBST(GSL_INCLUDES) + AC_SUBST(GSL_LDFLAGS) + AC_SUBST(GSL_LIBS) + +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/m4macros/hdrl.m4 cpl-plugin-sinfo-3.1.0+dfsg/m4macros/hdrl.m4 --- cpl-plugin-sinfo-3.0.0+dfsg/m4macros/hdrl.m4 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/m4macros/hdrl.m4 2017-11-21 13:36:01.000000000 +0000 @@ -0,0 +1,34 @@ +# HDRL_CHECK([location]) +# ---------------------- +# Sets build variables required to build and link hdrl +# the argument defines the relative location of the hdrl external in the source +# tree +# Note that this macro calls GSL_CHECK_LIBS([optional]) so additional calls to +# this macro with optional argument can be skipped in the pipeline. +AC_DEFUN([HDRL_CHECK], +[ + HDRL_LOCATION="$1" + + # check for optional GSL, needed in pipelines to correctly setup + # HDRL_LDFLAGS and HDRL_LIBS and in the case of no GSL being present to not + # declare functions using GSL in the hdrl headers as this requires a + # HAVE_GSL defined in the pipelines config.h + GSL_CHECK_LIBS([optional]) + + AC_MSG_CHECKING([HDRL in $HDRL_LOCATION]) + + # requires cpl and libm as it is a static library + HDRL_LIBS="-lhdrl -lcplcore -lcpldrs -lcplui -lcpldfs -lcext -lm $GSL_LIBS" + # la file to be added to DEPENDENCIES libtool doesn't track static libs + LIBHDRL="\$(top_builddir)/$HDRL_LOCATION/libhdrl.la" + HDRL_LDFLAGS="-L\$(top_builddir)/$HDRL_LOCATION $GSL_LDFLAGS" + HDRL_INCLUDES="-I\$(top_srcdir)/$HDRL_LOCATION" + + AC_SUBST(HDRL_LIBS) + AC_SUBST(LIBHDRL) + AC_SUBST(HDRL_LDFLAGS) + AC_SUBST(HDRL_INTERNAL_CFLAGS) + AC_SUBST(HDRL_INCLUDES) + + AC_MSG_RESULT([ok]) +]) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/Makefile.am 2013-06-20 14:54:30.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/Makefile.am 2017-05-05 14:18:29.000000000 +0000 @@ -28,7 +28,7 @@ COMPILE_FIRST = -TOPSUBDIRS = irplib sinfoni recipes regtests reflex +TOPSUBDIRS = hdrl irplib sinfoni recipes regtests reflex #COMPILE_LAST = sinfoni/tests COMPILE_LAST = diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/Makefile.in 2018-04-13 15:46:36.000000000 +0000 @@ -92,7 +92,8 @@ subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -277,6 +278,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -291,6 +299,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -390,6 +399,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -406,7 +416,7 @@ DISTCLEANFILES = *~ .logfile DISTCHECK_CONFIGURE_FLAGS = --enable-maintainer-mode COMPILE_FIRST = -TOPSUBDIRS = irplib sinfoni recipes regtests reflex +TOPSUBDIRS = hdrl irplib sinfoni recipes regtests reflex #COMPILE_LAST = sinfoni/tests COMPILE_LAST = diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/NEWS cpl-plugin-sinfo-3.1.0+dfsg/NEWS --- cpl-plugin-sinfo-3.0.0+dfsg/NEWS 2003-08-18 12:42:44.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/NEWS 2018-02-09 10:07:45.000000000 +0000 @@ -0,0 +1,9 @@ +v 3.1.0 (2018-04-01): + -Support of reduction data after 31/01/2018 upgrade (PIPE-7651) + -Updated of DFS for Paranal 2018 + -Updated reflex oca rules to support new esoreflex-2.9.0 + -Added efficiency compuation + -Added response computation + -Added flux calibration + -Fixed Reflex fv problem opening product files for inspection + -Fix minor bugs reported by QC diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/recipes/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/recipes/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/recipes/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/recipes/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -93,7 +93,8 @@ subdir = recipes ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -405,6 +406,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -419,6 +427,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -518,6 +527,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/recipes/sinfo_rec_distortion.c cpl-plugin-sinfo-3.1.0+dfsg/recipes/sinfo_rec_distortion.c --- cpl-plugin-sinfo-3.0.0+dfsg/recipes/sinfo_rec_distortion.c 2015-08-03 12:39:56.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/recipes/sinfo_rec_distortion.c 2018-02-19 10:13:40.000000000 +0000 @@ -76,7 +76,7 @@ #include #include #include - +#include /*----------------------------------------------------------------------------- @@ -314,11 +314,41 @@ if(line_cor==1) { check_nomsg(sinfo_ima_line_cor(config,set)); } + {/* special check in case of J band distortion data after 31/01/2018 */ + + cpl_frame* frm=cpl_frameset_find(set,"FIBRE_NS"); + const char* fname=cpl_frame_get_filename(frm); + cpl_propertylist* plist=cpl_propertylist_load(fname,0); + double mjd_obs=sinfo_pfits_get_mjdobs(plist); + char band[FILE_NAME_SZ]; + sinfo_get_band(frm,band); + //sinfo_msg("band=%s",band); + //sinfo_msg("mjd_obs=%g",mjd_obs); + if ( strcmp(band,"J") == 0 && mjd_obs > 58150.) { + p = cpl_parameterlist_find(config, "sinfoni.bp_dist.min_cut"); + if (cpl_parameter_get_double(p) == cpl_parameter_get_default_double(p)) { + sinfo_msg_warning("J band, data after 31/01/2018, use bp_dist-min_cut=0.05"); + cpl_parameter_set_double(p,0.05); + cpl_parameter_set_default_double(p,0.05); + + } + } + cpl_propertylist_delete(plist); + } - //cknull_nomsg(set_fibre_ns=sinfo_frameset_extract(set,RAW_FIBRE_NS)); + set_fibre_ns=sinfo_frameset_extract(set,RAW_FIBRE_NS); + if (cpl_frameset_get_size(set_fibre_ns) < 75 ) { + sinfo_msg_warning("For robustness it is strongly recommended to input 75 frames (if available) tagged as %s",RAW_FIBRE_NS); + } set_fibre_ns=cpl_frameset_duplicate(set); - cknull_nomsg(set_flat_ns=sinfo_frameset_extract(set,RAW_FLAT_NS)); + set_flat_ns=sinfo_frameset_extract(set,RAW_FLAT_NS); + if (cpl_frameset_get_size(set_flat_ns) < 2 ) { + sinfo_msg_warning("For robustness it is strongly recommended to input two frames tagged as %s one flat on one flat off",RAW_FLAT_NS); + } cknull_nomsg(set_wave_ns=sinfo_frameset_extract(set,RAW_WAVE_NS)); + if (cpl_frameset_get_size(set_wave_ns) < 2 ) { + sinfo_msg_warning("For robustness it is strongly recommended to input two frames tagged as %s one arc lamp on one arc lamp off",RAW_WAVE_NS); + } check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.bp.method")); check_nomsg(cpl_parameter_set_string(p,"Normal")); check_nomsg(raw_set=cpl_frameset_duplicate(set)); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/recipes/sinfo_rec_jitter.c cpl-plugin-sinfo-3.1.0+dfsg/recipes/sinfo_rec_jitter.c --- cpl-plugin-sinfo-3.0.0+dfsg/recipes/sinfo_rec_jitter.c 2014-01-01 11:48:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/recipes/sinfo_rec_jitter.c 2018-01-15 16:11:31.000000000 +0000 @@ -66,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -104,10 +105,23 @@ "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n" "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n" "A corresponding (band) distortion table with tag DISTORTION\n" - "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"; - + "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n" + "Optional Input: \n"; static char sinfo_rec_jitter_description3[] = + "FLUX_STD_CATALOG, the catalog of flux std stars \n" + "EXTCOEFF_TABLE, The Atmospheric Extinction correction table \n" + "EFFICIENCY_WINDOWS, the regions used to compute QC on efficiency \n" + "RESP_FIT_POINTS_CATALOG, the catalog indicating points to fit the response \n" + "RESPONSE_WINDOWS, the regions used to compute QC on the response \n" + "TEL_MOD_CATG, the Catalog of Telluric models \n" + "QUALITY_AREAS, the areas where the quality of \n" + "the Telluric fitting is calculated\n" + "FIT_AREAS, the areas used for Telluric model fitting \n" + "HIGH_ABS_REGIONS, the High absorption regions\n"; + + +static char sinfo_rec_jitter_description4[] = "The output is an image resulting from the IMA1 op IMA2 where op indicates\n" "A reference table with the position of the first " "column with tag FIRST_COLUMN\n" @@ -120,7 +134,7 @@ "(PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n" "\n"; -static char sinfo_rec_jitter_description[1400]; +static char sinfo_rec_jitter_description[1800]; /*----------------------------------------------------------------------------- Functions code @@ -152,6 +166,7 @@ strcpy(sinfo_rec_jitter_description,sinfo_rec_jitter_description1); strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description2); strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description3); + strcat(sinfo_rec_jitter_description,sinfo_rec_jitter_description4); cpl_plugin_init(plugin, CPL_PLUGIN_API, @@ -286,8 +301,11 @@ cpl_parameter* p=NULL; int psf_sw=0; int std_sw=0; - cpl_frameset* ref_set=NULL; + cpl_frameset* tmp_set=NULL; + cpl_frameset* eff_set=NULL; + cpl_frameset* store_set=NULL; int line_cor=0; + int flat_ind=0; sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d", SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION); @@ -303,69 +321,118 @@ check_nomsg(sinfo_ima_line_cor(config,set)); } - check_nomsg(ref_set=cpl_frameset_duplicate(set)); - /* =============================================================== - Defines several framesets each with a pair obj-sky, - stack each pair, put the results in set - =============================================================== */ - ck0(sinfo_cub_stk_frames(config,&set,cpl_func,&pro_ctg_cube), - "Cannot stack RAW frames") ; - - /* =============================================================== - SCI OBJNOD - =============================================================== */ - sinfo_msg("------------------------------") ; - sinfo_msg("COADDING CUBES"); - sinfo_msg("------------------------------") ; - ck0(sinfo_new_cubes_coadd(cpl_func,config, set, pro_ctg_cube), - "COADDING CUBES") ; - - sinfo_msg("------------------------------") ; - sinfo_msg("COADDED CUBES"); - sinfo_msg("------------------------------") ; - - /* =============================================================== - PSF - =============================================================== */ - - if((strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) || - (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) || - (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) { - - - p = cpl_parameterlist_find(config, "sinfoni.psf.switch"); - psf_sw = cpl_parameter_get_bool(p); - sinfo_msg("switch=%d",psf_sw); - if(psf_sw) { - sinfo_msg("------------------------------") ; - sinfo_msg("REDUCE PSF STD STAR FRAMES"); - sinfo_msg("------------------------------") ; - if ( -1 == sinfo_new_psf(cpl_func,config,set,set) ) { - sinfo_msg_error("REDUCING PSF STD STAR FRAMES") ; - cpl_error_reset(); + + int compute_efficiency = 0; + cpl_frame* frm_std = cpl_frameset_find(set, RAW_STD); + + int niter=1; + if(frm_std != NULL) { + p = cpl_parameterlist_find(config,"sinfoni.stacked.flat_index"); + flat_ind = cpl_parameter_get_bool(p); + cpl_frame* frm_std_cat = cpl_frameset_find(set, FLUX_STD_CATALOG); + cpl_frame* frm_atmext = cpl_frameset_find(set, EXTCOEFF_TABLE); + if ( frm_std_cat != NULL && frm_atmext != NULL ) { + check_nomsg(eff_set=cpl_frameset_duplicate(set)); + compute_efficiency = 1; + niter=2; + } + + } + + for(int i=0; i< niter; i++) { + if( compute_efficiency == 1 ) { + if( i == 0 ) { + p = cpl_parameterlist_find(config,"sinfoni.stacked.flat_index"); + cpl_parameter_set_bool(p,CPL_FALSE); + tmp_set=eff_set; } else { - sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ; + p = cpl_parameterlist_find(config,"sinfoni.stacked.flat_index"); + cpl_parameter_set_bool(p,flat_ind); + tmp_set=set; + compute_efficiency = 0; } + } else { + tmp_set=set; } - p = cpl_parameterlist_find(config, "sinfoni.std_star.switch"); - std_sw = cpl_parameter_get_bool(p); - sinfo_msg("switch=%d",std_sw); - if(std_sw) { - sinfo_msg("------------------------------") ; - sinfo_msg("STD STAR DATA REDUCTION"); - sinfo_msg("------------------------------") ; - if ( -1 == sinfo_new_stdstar(cpl_func,config, set,set ) ) { - sinfo_msg_error("REDUCING STD STAR DATA") ; - cpl_error_reset(); - } else { - sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ; + /* =============================================================== + Defines several framesets each with a pair obj-sky, + stack each pair, put the results in set + =============================================================== */ + ck0(sinfo_cub_stk_frames(config,&tmp_set,cpl_func,&pro_ctg_cube), + "Cannot stack RAW frames") ; + + /* =============================================================== + SCI OBJNOD + =============================================================== */ + sinfo_msg("------------------------------") ; + sinfo_msg("COADDING CUBES"); + sinfo_msg("------------------------------") ; + ck0(sinfo_new_cubes_coadd(cpl_func,config, tmp_set, pro_ctg_cube), + "COADDING CUBES") ; + + sinfo_msg("------------------------------") ; + sinfo_msg("COADDED CUBES"); + sinfo_msg("------------------------------") ; + + /* =============================================================== + PSF + =============================================================== */ + + if((strcmp(pro_ctg_cube,PRO_COADD_PSF) == 0) || + (strcmp(pro_ctg_cube,PRO_COADD_STD) == 0) || + (strcmp(pro_ctg_cube,PRO_COADD_PUPIL) == 0) ) { + + + p = cpl_parameterlist_find(config, "sinfoni.psf.switch"); + psf_sw = cpl_parameter_get_bool(p); + sinfo_msg("switch=%d",psf_sw); + if(psf_sw) { + sinfo_msg("------------------------------") ; + sinfo_msg("REDUCE PSF STD STAR FRAMES"); + sinfo_msg("------------------------------") ; + if ( -1 == sinfo_new_psf(cpl_func,config,tmp_set,tmp_set) ) { + sinfo_msg_error("REDUCING PSF STD STAR FRAMES") ; + cpl_error_reset(); + } else { + sinfo_msg("SUCCESS REDUCE PSF STD STAR FRAMES") ; + } + } + + p = cpl_parameterlist_find(config, "sinfoni.std_star.switch"); + std_sw = cpl_parameter_get_bool(p); + sinfo_msg("switch=%d",std_sw); + if(std_sw) { + sinfo_msg("------------------------------") ; + sinfo_msg("STD STAR DATA REDUCTION"); + sinfo_msg("------------------------------") ; + if ( -1 == sinfo_new_stdstar(cpl_func,config, tmp_set,tmp_set ) ) { + sinfo_msg_error("REDUCING STD STAR DATA") ; + cpl_error_reset(); + } else { + sinfo_msg("STD STAR DATA REDUCTION SUCCESS") ; + } } } - } + if( compute_efficiency == 1 ) { + + cpl_frame* frm_eff=cpl_frameset_find(tmp_set, PRO_EFFICIENCY); + if(frm_eff != NULL) { + cpl_frame* frm_tmp=cpl_frame_duplicate(frm_eff); + store_set=cpl_frameset_new(); + cpl_frameset_insert(store_set,frm_tmp); + } + sinfo_free_frameset(&eff_set); + + } else{ + cpl_frameset_join(set,store_set); + sinfo_free_frameset(&store_set); + } + + } cleanup: - sinfo_free_frameset(&ref_set); + if (cpl_error_get_code() != CPL_ERROR_NONE) { sinfo_check_rec_status(0); return -1; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/recipes/tests/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/recipes/tests/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/recipes/tests/Makefile.am 2017-01-04 17:11:09.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/recipes/tests/Makefile.am 2018-02-19 10:35:35.000000000 +0000 @@ -37,11 +37,11 @@ LDADD = $(LIBSINFO) check_PROGRAMS = sinfo_rec_detlin-test \ - sinfo_rec_distortion-test \ sinfo_rec_jitter-test \ sinfo_utl_cube2ima-test \ sinfo_utl_cube2spectrum-test \ sinfo_utl_spectrum_divide_by_blackbody-test +# sinfo_rec_distortion-test \ # sinfo_rec_mdark-test # sinfo_rec_mdark_detmon-test \ # sinfo_rec_lingain-test \ @@ -68,8 +68,8 @@ #sinfo_rec_lingain_test_LDADD = $(OBJDIR)/sinfo_rec_lingain.o $(LDADD) $(LIBALL) -sinfo_rec_distortion_test_SOURCES = recipe_main.c -sinfo_rec_distortion_test_LDADD = $(OBJDIR)/sinfo_rec_distortion.o $(LDADD) $(LIBALL) +#sinfo_rec_distortion_test_SOURCES = recipe_main.c +#sinfo_rec_distortion_test_LDADD = $(OBJDIR)/sinfo_rec_distortion.o $(LDADD) $(LIBALL) #sinfo_rec_mdark_test_SOURCES = recipe_main.c diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/recipes/tests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/recipes/tests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/recipes/tests/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/recipes/tests/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -89,7 +89,6 @@ host_triplet = @host@ target_triplet = @target@ check_PROGRAMS = sinfo_rec_detlin-test$(EXEEXT) \ - sinfo_rec_distortion-test$(EXEEXT) \ sinfo_rec_jitter-test$(EXEEXT) \ sinfo_utl_cube2ima-test$(EXEEXT) \ sinfo_utl_cube2spectrum-test$(EXEEXT) \ @@ -97,7 +96,8 @@ subdir = recipes/tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -119,11 +119,6 @@ am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -am_sinfo_rec_distortion_test_OBJECTS = recipe_main.$(OBJEXT) -sinfo_rec_distortion_test_OBJECTS = \ - $(am_sinfo_rec_distortion_test_OBJECTS) -sinfo_rec_distortion_test_DEPENDENCIES = \ - $(OBJDIR)/sinfo_rec_distortion.o $(LDADD) am_sinfo_rec_jitter_test_OBJECTS = recipe_main.$(OBJEXT) sinfo_rec_jitter_test_OBJECTS = $(am_sinfo_rec_jitter_test_OBJECTS) sinfo_rec_jitter_test_DEPENDENCIES = $(OBJDIR)/sinfo_rec_jitter.o \ @@ -179,13 +174,11 @@ am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(sinfo_rec_detlin_test_SOURCES) \ - $(sinfo_rec_distortion_test_SOURCES) \ $(sinfo_rec_jitter_test_SOURCES) \ $(sinfo_utl_cube2ima_test_SOURCES) \ $(sinfo_utl_cube2spectrum_test_SOURCES) \ $(sinfo_utl_spectrum_divide_by_blackbody_test_SOURCES) DIST_SOURCES = $(sinfo_rec_detlin_test_SOURCES) \ - $(sinfo_rec_distortion_test_SOURCES) \ $(sinfo_rec_jitter_test_SOURCES) \ $(sinfo_utl_cube2ima_test_SOURCES) \ $(sinfo_utl_cube2spectrum_test_SOURCES) \ @@ -452,6 +445,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -466,6 +466,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -565,6 +566,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -585,6 +587,7 @@ OBJDIR = $(top_builddir)/recipes/.libs AM_CPPFLAGS = $(all_includes) LDADD = $(LIBSINFO) +# sinfo_rec_distortion-test \ # sinfo_rec_mdark-test # sinfo_rec_mdark_detmon-test \ # sinfo_rec_lingain-test \ @@ -607,8 +610,9 @@ #sinfo_rec_lingain_test_SOURCES = recipe_main.c #sinfo_rec_lingain_test_LDADD = $(OBJDIR)/sinfo_rec_lingain.o $(LDADD) $(LIBALL) -sinfo_rec_distortion_test_SOURCES = recipe_main.c -sinfo_rec_distortion_test_LDADD = $(OBJDIR)/sinfo_rec_distortion.o $(LDADD) $(LIBALL) + +#sinfo_rec_distortion_test_SOURCES = recipe_main.c +#sinfo_rec_distortion_test_LDADD = $(OBJDIR)/sinfo_rec_distortion.o $(LDADD) $(LIBALL) #sinfo_rec_mdark_test_SOURCES = recipe_main.c #sinfo_rec_mdark_test_LDADD = $(OBJDIR)/sinfo_rec_mdark.o $(LDADD) $(LIBALL) @@ -722,10 +726,6 @@ @rm -f sinfo_rec_detlin-test$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sinfo_rec_detlin_test_OBJECTS) $(sinfo_rec_detlin_test_LDADD) $(LIBS) -sinfo_rec_distortion-test$(EXEEXT): $(sinfo_rec_distortion_test_OBJECTS) $(sinfo_rec_distortion_test_DEPENDENCIES) $(EXTRA_sinfo_rec_distortion_test_DEPENDENCIES) - @rm -f sinfo_rec_distortion-test$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(sinfo_rec_distortion_test_OBJECTS) $(sinfo_rec_distortion_test_LDADD) $(LIBS) - sinfo_rec_jitter-test$(EXEEXT): $(sinfo_rec_jitter_test_OBJECTS) $(sinfo_rec_jitter_test_DEPENDENCIES) $(EXTRA_sinfo_rec_jitter_test_DEPENDENCIES) @rm -f sinfo_rec_jitter-test$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sinfo_rec_jitter_test_OBJECTS) $(sinfo_rec_jitter_test_LDADD) $(LIBS) @@ -976,13 +976,6 @@ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ - "$$tst" $(AM_TESTS_FD_REDIRECT) -sinfo_rec_distortion-test.log: sinfo_rec_distortion-test$(EXEEXT) - @p='sinfo_rec_distortion-test$(EXEEXT)'; \ - b='sinfo_rec_distortion-test'; \ - $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ - --log-file $$b.log --trs-file $$b.trs \ - $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) sinfo_rec_jitter-test.log: sinfo_rec_jitter-test$(EXEEXT) @p='sinfo_rec_jitter-test$(EXEEXT)'; \ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/reflex/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/reflex/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/reflex/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/reflex/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -92,7 +92,8 @@ subdir = reflex ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -188,6 +189,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -202,6 +210,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -301,6 +310,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/reflex/sinfo_wkf.oca cpl-plugin-sinfo-3.1.0+dfsg/reflex/sinfo_wkf.oca --- cpl-plugin-sinfo-3.0.0+dfsg/reflex/sinfo_wkf.oca 2017-03-21 12:18:02.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/reflex/sinfo_wkf.oca 2018-02-20 09:02:16.000000000 +0000 @@ -160,6 +160,11 @@ REFLEX.CATG = "DRS_SETUP_WAVE"; } +if PRO.CATG=="DRS_SETUP_WAVE_OH" and INSTRUME=="SINFONI" then +{ + REFLEX.CATG = "DRS_SETUP_WAVE_OH"; +} + if PRO.CATG=="ATM_REF_CORR" and INSTRUME=="SINFONI" then { REFLEX.CATG = "ATM_REF_CORR"; @@ -186,6 +191,50 @@ REFLEX.CATG = "BP_MAP_NL"; } + + +if PRO.CATG == "EFFICIENCY_WINDOWS" then +{ + REFLEX.CATG = "EFFICIENCY_WINDOWS"; +} +if PRO.CATG == "RESPONSE_WINDOWS" then +{ + REFLEX.CATG = "RESPONSE_WINDOWS"; +} +if PRO.CATG == "EXTCOEFF_TABLE" then +{ + REFLEX.CATG = "EXTCOEFF_TABLE"; +} +if PRO.CATG == "FLUX_STD_CATALOG" then +{ + REFLEX.CATG = "FLUX_STD_CATALOG"; +} +if PRO.CATG == "FIT_AREAS" then +{ + REFLEX.CATG = "FIT_AREAS"; +} +if PRO.CATG == "QUALITY_AREAS" then +{ + REFLEX.CATG = "QUALITY_AREAS"; +} + +if PRO.CATG == "RESPONSE" then +{ + REFLEX.CATG = "RESPONSE"; +} +if PRO.CATG == "RESP_FIT_POINTS_CATALOG" then +{ + REFLEX.CATG = "RESP_FIT_POINTS_CATALOG"; +} +if PRO.CATG == "TELL_MOD_CATALOG" then +{ + REFLEX.CATG = "TELL_MOD_CATALOG"; +} + + + + + select execute(ACTION_DARK) from inputFiles where RAW.TYPE=="DARK" group by DET.DIT,TPL.START as (TPL_A,tpl); @@ -201,8 +250,6 @@ select execute(ACTION_FLAT) from inputFiles where RAW.TYPE=="FLAT" group by INS.SETUP.ID,INS.OPTI1.NAME,TPL.START as (TPL_A,tpl); -select execute(ACTION_TECH_FLUT) from inputFiles where RAW.TYPE=="TECH_FLUT" - group by INS.SETUP.ID,INS.OPTI1.NAME,TPL.START as (TPL_A,tpl); minRet = 2; select execute(ACTION_WAVE) from inputFiles where RAW.TYPE=="WAVE" @@ -317,6 +364,23 @@ minRet = 1; maxRet = 1; select file as SLIT_POS_WKF from calibFiles where PRO.CATG=="SLIT_POS_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME and inputFile.INSTRUME==INSTRUME ; + + + +minRet = 0; maxRet = 1; +select file as EXTCOEFF_TABLE from calibFiles where REFLEX.CATG == "EXTCOEFF_TABLE" + and inputFile.INSTRUME==INSTRUME; + + +minRet = 0; maxRet = 1; +select file as RESPONSE from calibFiles where REFLEX.CATG == "RESPONSE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME==INS.FILT1.NAME; + + + + + + recipe sinfo_rec_jitter; } @@ -391,39 +455,6 @@ product MASTER_PSF { PRO.CATG="MASTER_PSF"; PRO.EXT="tpl_0005.fits";} } -action ACTION_SMON -{ -// minRet = 0; maxRet = 1; -// select file as FIRST_COL from calibFiles where PRO.CATG=="FIRST_COL" and inputFile.INSTRUME==INSTRUME -// ; - minRet = 1; maxRet = 1; - select file as MASTER_BP_MAP_WKF from calibFiles where PRO.CATG=="MASTER_BP_MAP_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME and inputFile.INSTRUME==INSTRUME - ; - minRet = 1; maxRet = 1; - select file as MASTER_FLAT_LAMP_WKF from calibFiles where PRO.CATG=="MASTER_FLAT_LAMP_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME and inputFile.INSTRUME==INSTRUME - ; - minRet = 1; maxRet = 1; - select file as DISTORTION_WKF from calibFiles where PRO.CATG=="DISTORTION_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INSTRUME==INSTRUME - ; - minRet = 1; maxRet = 1; - select file as SLITLETS_DISTANCE_WKF from calibFiles where PRO.CATG=="SLITLETS_DISTANCE_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INSTRUME==INSTRUME - ; - minRet = 1; maxRet = 1; - select file as WAVE_MAP_WKF from calibFiles where PRO.CATG=="WAVE_MAP_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME and inputFile.INSTRUME==INSTRUME - ; - minRet = 1; maxRet = 1; - select file as SLIT_POS_WKF from calibFiles where PRO.CATG=="SLIT_POS_WKF" and inputFile.INS.SETUP.ID==INS.SETUP.ID and inputFile.INS.OPTI1.NAME==INS.OPTI1.NAME and inputFile.INSTRUME==INSTRUME - ; - minRet = 0; maxRet = 1; - select file as MASTER_DARK_WKF from calibFiles where PRO.CATG=="MASTER_DARK_WKF" and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME - ; - minRet = 0; maxRet = 1; - select file as BP_MAP_HP_WKF from calibFiles where PRO.CATG=="BP_MAP_HP_WKF" and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME - ; - recipe sinfo_rec_jitter; - product SMON_ { PRO.CATG="COADD_PSF"; PRO.EXT="tpl_0000.fits";} - product SMON_ { PRO.CATG="MASTER_PSF"; PRO.EXT="tpl_0005.fits";} -} action ACTION_STD { @@ -459,6 +490,49 @@ minRet = 0; maxRet = 1; select file as BP_MAP_HP_WKF from calibFiles where PRO.CATG=="BP_MAP_HP_WKF" and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME ; + + +minRet = 0; maxRet = 1; +select file as EFFICIENCY_WINDOWS from calibFiles where REFLEX.CATG == "EFFICIENCY_WINDOWS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as RESPONSE_WINDOWS from calibFiles where REFLEX.CATG == "RESPONSE_WINDOWS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as EXTCOEFF_TABLE from calibFiles where REFLEX.CATG == "EXTCOEFF_TABLE" + and inputFile.INSTRUME==INSTRUME; + +minRet = 0; maxRet = 1; +select file as FLUX_STD_CATALOG from calibFiles where REFLEX.CATG == "FLUX_STD_CATALOG" + and inputFile.INSTRUME==INSTRUME; + +minRet = 0; maxRet = 1; +select file as TELL_MOD_CATALOG from calibFiles where REFLEX.CATG == "TELL_MOD_CATALOG" + and inputFile.INSTRUME==INSTRUME; + + + +minRet = 0; maxRet = 1; +select file as FIT_AREAS from calibFiles where REFLEX.CATG == "FIT_AREAS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as QUALITY_AREAS from calibFiles where REFLEX.CATG == "QUALITY_AREAS" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + +minRet = 0; maxRet = 1; +select file as RESP_FIT_POINTS_CATALOG from calibFiles where REFLEX.CATG == "RESP_FIT_POINTS_CATALOG" + and inputFile.INSTRUME==INSTRUME; + +//minRet = 0; maxRet = 1; +//select file as RESPONSE from calibFiles where REFLEX.CATG == "RESPONSE" +// and inputFile.INSTRUME==INSTRUME and inputFile.INS.FILT1.NAME == INS.FILT1.NAME; + + + + recipe sinfo_rec_jitter; product COADD_STD { PRO.CATG="COADD_STD"; PRO.EXT="tpl_0000.fits";} product STD_STAR_SPECTRA { PRO.CATG="STD_STAR_SPECTRA"; PRO.EXT="tpl_0007.fits";} @@ -498,7 +572,21 @@ minRet = 0; maxRet = 1; select file as BP_MAP_HP_WKF from calibFiles where PRO.CATG=="BP_MAP_HP_WKF" and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME ; - recipe sinfo_rec_jitter; + + +minRet = 0; maxRet = 1; +select file as EXTCOEFF_TABLE from calibFiles where REFLEX.CATG == "EXTCOEFF_TABLE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + +minRet = 0; maxRet = 1; +select file as RESPONSE from calibFiles where REFLEX.CATG == "RESPONSE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + + + +recipe sinfo_rec_jitter; } action ACTION_OBSNOD @@ -536,5 +624,19 @@ minRet = 0; maxRet = 1; select file as BP_MAP_HP_WKF from calibFiles where PRO.CATG=="BP_MAP_HP_WKF" and inputFile.DET.DIT==DET.DIT and inputFile.INSTRUME==INSTRUME ; - recipe sinfo_rec_jitter; + + +minRet = 0; maxRet = 1; +select file as EXTCOEFF_TABLE from calibFiles where REFLEX.CATG == "EXTCOEFF_TABLE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + +minRet = 0; maxRet = 1; +select file as RESPONSE from calibFiles where REFLEX.CATG == "RESPONSE" + and inputFile.INSTRUME==INSTRUME and inputFile.INS.SETUP.ID==INS.SETUP.ID; + + + + +recipe sinfo_rec_jitter; } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/reflex/sinfo.xml.in cpl-plugin-sinfo-3.1.0+dfsg/reflex/sinfo.xml.in --- cpl-plugin-sinfo-3.0.0+dfsg/reflex/sinfo.xml.in 2016-06-17 15:22:46.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/reflex/sinfo.xml.in 2018-02-19 12:12:44.000000000 +0000 @@ -1,7 +1,7 @@ - + @@ -49,17 +49,17 @@ - + - + - + - + none yang zhao, edward lee @@ -98,7 +98,7 @@ - + @@ -173,7 +173,7 @@ - + @@ -220,7 +220,7 @@ - + @@ -267,7 +267,7 @@ - + @@ -314,7 +314,7 @@ - + @@ -371,17 +371,17 @@ - + - + - + - + - + - + @@ -453,7 +453,7 @@ - + null Edward A. Lee @@ -523,7 +523,7 @@ - + null Edward A. Lee @@ -602,7 +602,7 @@ - + @@ -754,7 +754,7 @@ - + @@ -1225,17 +1225,17 @@ - + - + - + - + - + - + @@ -1290,17 +1290,17 @@ - + - + - + - + - + - + @@ -1355,17 +1355,17 @@ - + - + - + - + - + - + @@ -1420,17 +1420,17 @@ - + - + - + - + - + - + @@ -1485,17 +1485,17 @@ - + - + - + - + - + - + @@ -1642,21 +1642,21 @@ - + - + - + - + - + - + - + @@ -1711,21 +1711,21 @@ - + - + - + - + - + - + - + @@ -1772,7 +1772,7 @@ - + @@ -2008,7 +2008,7 @@ - + null Edward A. Lee @@ -2097,17 +2097,17 @@ - + - + - + - + - + - + @@ -2166,17 +2166,17 @@ - + - + - + - + - + - + @@ -2235,17 +2235,17 @@ - + - + - + - + - + - + @@ -2304,17 +2304,17 @@ - + - + - + - + - + - + @@ -2373,17 +2373,17 @@ - + - + - + - + - + - + @@ -2442,17 +2442,17 @@ - + - + - + - + - + - + @@ -2511,17 +2511,17 @@ - + - + - + - + - + - + @@ -2580,17 +2580,17 @@ - + - + - + - + - + - + @@ -2649,17 +2649,17 @@ - + - + - + - + - + - + @@ -2718,17 +2718,17 @@ - + - + - + - + - + - + @@ -2787,17 +2787,17 @@ - + - + - + - + - + - + @@ -2856,17 +2856,17 @@ - + - + - + - + - + - + @@ -2925,17 +2925,17 @@ - + - + - + - + - + - + @@ -2994,17 +2994,17 @@ - + - + - + - + - + - + @@ -3063,17 +3063,17 @@ - + - + - + - + - + - + @@ -3132,17 +3132,17 @@ - + - + - + - + - + - + @@ -3201,17 +3201,17 @@ - + - + - + - + - + - + @@ -3270,17 +3270,17 @@ - + - + - + - + - + - + @@ -3339,17 +3339,17 @@ - + - + - + - + - + - + @@ -3529,17 +3529,17 @@ - + - + - + - + - + - + @@ -3647,17 +3647,17 @@ - + - + - + - + - + - + @@ -3716,17 +3716,17 @@ - + - + - + - + - + - + @@ -4003,7 +4003,7 @@ - + @@ -4165,7 +4165,87 @@ - + +null +null +null +<p>The RecipeExecuter executes one CPL recipe. The recipe can be chosen only when you instantiate the component: at the moment the user is presented with a list of the available recipes (the output of esorex --recipes). After the user selects the recipe the actor queries EsoRex for the recipe parameters and adds them to the actor. Each parameter is set to the default value: if the user wants to change any of the parameters then he can enter his own value or he can write the special value PORT, in which case the value is taken from the input port SoP.</p><p>The actor has three modes: Run, Skip and Disabled</p><p>Note: since this actor has very different behaviour depending on the pipeline recipe to which it is associated, it is not present in the left hand side actor list, and instead it must be instantiated from the menu.</p> +the recipe input parameters +the outputs not matching any of the output categories +the logs generated by EsoRex, empty if lazy mode is triggered +the inputs not matching any of the input categories +the warnings generated by EsoRex, empty if lazy mode is triggered +the input files +the output files +the errors generated by EsoRex, empty if lazy mode is triggered +the parameters used in the last execution of the recipe +if true then the actor will check whether the pipeline recipe has already been executed with the same input files and with the same recipe parameters. If this is the case then the recipe will not be executed, and instead the previously generated products (which are the same as those that would have been generated if the recipe were executed, except for a timestamp) will be broadcast to the output port. +additional parameters passed to EsoRex +the selected pipeline recipe (cannot be changed) +the directory where the products will be created +<p>how the purpose of the input files will be sent to the output:</p><p>Do nothing: leave the input purpose unmodified</p><p>Strip last: remove the last section of the input purpose, if there is only one section set the purpose to universal. This is the default mode, and it means that the actor has completed a reduction step and removes it from the purpose chain</p><p>Set to universal: set the output purpose to universal</p> +Parameter name: stack-qc_thresh_max. Default value:49000 +Parameter name: stack-qc_thresh_min. Default value:0 +Parameter name: stack-warpfix_kernel. Default value:tanh +if true then an empty sof on the input port will be broadcast to the output without executing the recipe +Parameter name: stack-warpfix_ind. Default value:true +<p>Run: the recipe will be executed (see lazy mode)</p><p>Skip: the inputs are broadcast to the output with the following modifications: input files will be filtered according to input and output tags and recipe parameters will be filtered based on the recipe and whether the parameter is set to PORT</p><p>Disabled: the recipe is not executed and an empty SoF is generated on the output port</p> +Parameter name: wcal-no_coeffs. Default value:3 +if true then the execution is paused after the execution of the recipe +Parameter name: stack-khw. Default value:2 +Parameter name: wcal-qc_thresh_max. Default value:49000 +Parameter name: stack-gauss_ind. Default value:false +Parameter name: wcal-qc_thresh_min. Default value:0 +Parameter name: stack-mask_rad. Default value:4 +Parameter name: wcal-diff_toll. Default value:2 +Parameter name: stack-ind_ind. Default value:false +Parameter name: wcal-y_box. Default value:5 +Parameter name: stack-mask_ind. Default value:1 +Parameter name: wcal-box_len. Default value:32 +Parameter name: stack-mflat_smooth_rad. Default value:16 +Parameter name: wcal-estimate_ind. Default value:false +Parameter name: wcal-fit_edge_ind. Default value:false +Parameter name: wcal-fit_boltz_ind. Default value:true +Parameter name: wcal-slit_pos_ind. Default value:true +if true then the execution is paused just before executing the recipe +Parameter name: wcal-mag_factor. Default value:8 +Parameter name: wcal-wave_map_ind. Default value:false +Parameter name: wcal-pixel_tol. Default value:5 +Parameter name: wcal-pixel_dist. Default value:15 +Parameter name: wcal-par_ind. Default value:true +Parameter name: wcal-wcoeff_ind. Default value:true +Parameter name: stack-mflat_norm_smooth. Default value:0 +Parameter name: wcal-sigma_factor. Default value:1.5 +Parameter name: stack-flat_ind. Default value:true +Parameter name: wcal-n_b_coeffs. Default value:2 +Parameter name: stack-hi_rej. Default value:0.1 +Parameter name: stack-lo_rej. Default value:0.1 +Parameter name: product-density. Default value:2 +Parameter name: lc_filt_rad. Default value:3 +Parameter name: lc_kappa. Default value:18 +Parameter name: lc_sw. Default value:false +Parameter name: gen-overpar. Default value:true +the directory where the EsoRex logs will be saved + +a list of file categories separated by a comma or a space: only input files belonging to one of these categories will be passed to the recipe +Parameter name: wcal-n_a_coeffs. Default value:4 +Parameter name: wcal-max_residual. Default value:0.5 +<p>it specifies the behavior of the actor if the recipe fails</p> <p>Stop: the actor produces an error message and the workflows stops. This is the default</p><p>Continue: the actor outputs an empty SoF</p><p>Ask: the actor pops up a window and asks the user whether he wants to continue or stop the execution</p> +Parameter name: wcal-min_amplitude. Default value:5 +Parameter name: wcal-fwhm. Default value:2.83 +a list of file categories separated by a comma or a space: only products belonging to one of these categories will be broadcast to the output port +Parameter name: wcal-sigma. Default value:2 +Parameter name: wcal-hw. Default value:7 +Parameter name: wcal-min_diff. Default value:1 +Parameter name: wcal-calib_indicator. Default value:true +Parameter name: wcal-slitpos_bootstrap. Default value:false +the directory the recipe will use as a working directory +Parameter name: stack-sub_raw_sky. Default value:true +if true, the temporary directories (where the logs, the final and the temporary products of the recipe are created) are cleaned before the execution + + + + @@ -4236,7 +4316,7 @@ <p>A Composite actor is an aggregation of actors. It may have a local director that is responsible for executing the contained actors. A Composite actor with a local director is called an opaque actor. Composite actors do not require a local director. Composite actors with no local director "inherit" the director from the containing workflow and are called non-opaque.</p> <p>To create a composite actor, drag and drop the Composite actor onto the Workflow canvas. Right-click the actor and select Open Actor from the drop-down menu. A new Kepler application window will open for designing the composite.</p> - + @@ -4298,18 +4378,120 @@ - + - + - + +null +null +null +<p>The RecipeExecuter executes one CPL recipe. The recipe can be chosen only when you instantiate the component: at the moment the user is presented with a list of the available recipes (the output of esorex --recipes). After the user selects the recipe the actor queries EsoRex for the recipe parameters and adds them to the actor. Each parameter is set to the default value: if the user wants to change any of the parameters then he can enter his own value or he can write the special value PORT, in which case the value is taken from the input port SoP.</p><p>The actor has three modes: Run, Skip and Disabled</p><p>Note: since this actor has very different behaviour depending on the pipeline recipe to which it is associated, it is not present in the left hand side actor list, and instead it must be instantiated from the menu.</p> +the recipe input parameters +the outputs not matching any of the output categories +the logs generated by EsoRex, empty if lazy mode is triggered +the inputs not matching any of the input categories +the warnings generated by EsoRex, empty if lazy mode is triggered +the input files +the output files +the errors generated by EsoRex, empty if lazy mode is triggered +the parameters used in the last execution of the recipe +Parameter name: std_star-switch. Default value:true +Parameter name: skycor-sub_thr_bkg_from_obj. Default value:false +Parameter name: skycor-ury. Default value:64 +Parameter name: skycor-urx. Default value:64 +Parameter name: skycor-lly. Default value:1 + +Parameter name: skycor-llx. Default value:1 +Parameter name: skycor-pshift. Default value:0 +Parameter name: skycor-niter. Default value:10 +Parameter name: skycor-fit_obj_noise. Default value:false +Parameter name: skycor-rot_cor. Default value:false +the directory where the products will be created +the directory where the EsoRex logs will be saved +Parameter name: skycor-scale_method. Default value:1 +Parameter name: skycor-line_hw. Default value:4 +Parameter name: skycor-sky_bkg_filter_width. Default value:12 +Parameter name: skycor-min_frac. Default value:0.8 +a list of file categories separated by a comma or a space: only products belonging to one of these categories will be broadcast to the output port +Parameter name: skycor-mask_we. Default value:2.5 +Parameter name: skycor-mask_ws. Default value:1.4 +Parameter name: objnod-mosaic_max_size. Default value:14196 +Parameter name: objnod-flux_cor. Default value:true +Parameter name: objnod-sky_cor. Default value:true +if true then the execution is paused after the execution of the recipe +Parameter name: objnod-fcol. Default value:0 +Parameter name: objnod-vury. Default value:0 +Parameter name: objnod-vurx. Default value:0 +the selected pipeline recipe (cannot be changed) +Parameter name: objnod-vlly. Default value:0 +Parameter name: objnod-vllx. Default value:0 +Parameter name: objnod-kernel_typ. Default value:tanh +Parameter name: objnod-jit_ind. Default value:true +Parameter name: objnod-tol. Default value:2 +Parameter name: objnod-hi_rej. Default value:10 +Parameter name: objnod-lo_rej. Default value:10 +Parameter name: objnod-order. Default value:2 +a list of file categories separated by a comma or a space: only input files belonging to one of these categories will be passed to the recipe +Parameter name: objnod-fine_tune_mtd. Default value:P +Parameter name: objnod-ns_ind. Default value:true +Parameter name: objnod-no_coeffs. Default value:3 +Parameter name: objnod-size_y. Default value:0 +Parameter name: objnod-size_x. Default value:0 +Parameter name: objnod-kappa. Default value:2 +Parameter name: objnod-ks_clip. Default value:true +Parameter name: objnod-scales_sky. Default value:false +Parameter name: objnod-aj_method. Default value:1 +Parameter name: stack-sub_raw_sky. Default value:true +if true, the temporary directories (where the logs, the final and the temporary products of the recipe are created) are cleaned before the execution +<p>Run: the recipe will be executed (see lazy mode)</p><p>Skip: the inputs are broadcast to the output with the following modifications: input files will be filtered according to input and output tags and recipe parameters will be filtered based on the recipe and whether the parameter is set to PORT</p><p>Disabled: the recipe is not executed and an empty SoF is generated on the output port</p> +additional parameters passed to EsoRex +Parameter name: stack-qc_thresh_max. Default value:49000 +Parameter name: stack-qc_thresh_min. Default value:0 +Parameter name: stack-warpfix_kernel. Default value:tanh +Parameter name: stack-warpfix_ind. Default value:true +Parameter name: stack-khw. Default value:2 +Parameter name: stack-gauss_ind. Default value:false +Parameter name: stack-mask_rad. Default value:4 +<p>how the purpose of the input files will be sent to the output:</p><p>Do nothing: leave the input purpose unmodified</p><p>Strip last: remove the last section of the input purpose, if there is only one section set the purpose to universal. This is the default mode, and it means that the actor has completed a reduction step and removes it from the purpose chain</p><p>Set to universal: set the output purpose to universal</p> +Parameter name: stack-ind_ind. Default value:false +Parameter name: stack-mask_ind. Default value:1 +Parameter name: stack-mflat_smooth_rad. Default value:16 +Parameter name: stack-mflat_norm_smooth. Default value:0 +Parameter name: stack-flat_ind. Default value:true +Parameter name: stack-hi_rej. Default value:0.1 +Parameter name: stack-lo_rej. Default value:0.1 +Parameter name: product-density. Default value:2 +Parameter name: lc_filt_rad. Default value:3 +if true then the actor will check whether the pipeline recipe has already been executed with the same input files and with the same recipe parameters. If this is the case then the recipe will not be executed, and instead the previously generated products (which are the same as those that would have been generated if the recipe were executed, except for a timestamp) will be broadcast to the output port. +Parameter name: lc_kappa. Default value:18 +Parameter name: lc_sw. Default value:false +Parameter name: gen-overpar. Default value:true +Parameter name: psf-switch. Default value:true +<p>it specifies the behavior of the actor if the recipe fails</p> <p>Stop: the actor produces an error message and the workflows stops. This is the default</p><p>Continue: the actor outputs an empty SoF</p><p>Ask: the actor pops up a window and asks the user whether he wants to continue or stop the execution</p> +Parameter name: std_star-pfy. Default value:3 +Parameter name: std_star-pfx. Default value:3 +Parameter name: std_star-pfm. Default value:erosion +Parameter name: std_star-extract. Default value:simple +Parameter name: std_star-compute_eff. Default value:true +Parameter name: std_star-conv_ind. Default value:true +Parameter name: std_star-fwhm_fct. Default value:5 +Parameter name: std_star-hi_rej. Default value:0.1 +Parameter name: std_star-lo_rej. Default value:0.1 +the directory the recipe will use as a working directory +if true then the execution is paused just before executing the recipe +if true then an empty sof on the input port will be broadcast to the output without executing the recipe + + + + @@ -4376,11 +4558,11 @@ - + - + @@ -4393,24 +4575,22 @@ - + - + - - - + - + - + - + @@ -4426,7 +4606,7 @@ - + @@ -4439,20 +4619,18 @@ - - - + - + - + - + @@ -4478,6 +4656,8 @@ + + @@ -4557,6 +4737,13 @@ + + + + + + + @@ -4626,7 +4813,148 @@ - + +null +null +null +<p>The RecipeExecuter executes one CPL recipe. The recipe can be chosen only when you instantiate the component: at the moment the user is presented with a list of the available recipes (the output of esorex --recipes). After the user selects the recipe the actor queries EsoRex for the recipe parameters and adds them to the actor. Each parameter is set to the default value: if the user wants to change any of the parameters then he can enter his own value or he can write the special value PORT, in which case the value is taken from the input port SoP.</p><p>The actor has three modes: Run, Skip and Disabled</p><p>Note: since this actor has very different behaviour depending on the pipeline recipe to which it is associated, it is not present in the left hand side actor list, and instead it must be instantiated from the menu.</p> +the recipe input parameters +the outputs not matching any of the output categories +the logs generated by EsoRex, empty if lazy mode is triggered +the inputs not matching any of the input categories +the warnings generated by EsoRex, empty if lazy mode is triggered +the input files +the output files +the errors generated by EsoRex, empty if lazy mode is triggered +the parameters used in the last execution of the recipe +Parameter name: stack-qc_thresh_min. Default value:0 +Parameter name: stack-warpfix_kernel. Default value:tanh +Parameter name: stack-warpfix_ind. Default value:true +Parameter name: stack-khw. Default value:2 +Parameter name: stack-gauss_ind. Default value:false + +Parameter name: stack-mask_rad. Default value:4 +Parameter name: stack-ind_ind. Default value:false +Parameter name: stack-mask_ind. Default value:1 +Parameter name: stack-mflat_smooth_rad. Default value:16 +Parameter name: stack-mflat_norm_smooth. Default value:0 +the directory where the products will be created +the directory where the EsoRex logs will be saved +Parameter name: stack-flat_ind. Default value:true +Parameter name: stack-hi_rej. Default value:0.1 +Parameter name: stack-lo_rej. Default value:0.1 +Parameter name: bp_dist-max_cut. Default value:50000 +a list of file categories separated by a comma or a space: only products belonging to one of these categories will be broadcast to the output port +Parameter name: bp_dist-min_cut. Default value:0.1 +Parameter name: bp_dist-mean_fct. Default value:999 +Parameter name: bp_dist-thr_ind. Default value:true +Parameter name: bp_dist-ury. Default value:1200 +Parameter name: bp_dist-urx. Default value:1390 +if true then the execution is paused after the execution of the recipe +Parameter name: bp_dist-lly. Default value:1000 +Parameter name: ns-dev_tol. Default value:20 +Parameter name: ns-min_diff. Default value:1 +Parameter name: ns-fwhm. Default value:2 +Parameter name: ns-hw. Default value:4 +Parameter name: ns-khw. Default value:2 +Parameter name: bp_dist-llx. Default value:1350 +Parameter name: ns-gauss_ind. Default value:false +Parameter name: bp_dist-hi_rej. Default value:0.1 +the selected pipeline recipe (cannot be changed) +Parameter name: ns-mask_ind. Default value:false +Parameter name: bp_dist-lo_rej. Default value:0.1 +Parameter name: ns-hi_rej. Default value:0.1 +Parameter name: bp_dist-it. Default value:8 +Parameter name: ns-lo_rej. Default value:0.1 +Parameter name: bp_dist-fct. Default value:999 +Parameter name: smooth_rad. Default value:3 +Parameter name: bp_dist-method_ind. Default value:1 +Parameter name: arcs_window_size. Default value:14 +Parameter name: bp_dist-s_factor. Default value:2 +Parameter name: arcs_min_arclen_factor. Default value:1.19 +Parameter name: bp-method. Default value:Normal +Parameter name: arcs_thresh_factor. Default value:0.33333 +Parameter name: lamp_flats-qc_thresh_max. Default value:49000 +Parameter name: ns-dev_tol. Default value:20 +Parameter name: lamp_flats-qc_thresh_min. Default value:0 +Parameter name: ns-min_diff. Default value:1 +a list of file categories separated by a comma or a space: only input files belonging to one of these categories will be passed to the recipe +Parameter name: ns-fwhm. Default value:2 +Parameter name: ns-hw. Default value:4 +Parameter name: ns-khw. Default value:2 +Parameter name: ns-gauss_ind. Default value:false +Parameter name: lamp_flats-qc_fpn_ymax2. Default value:1200 +Parameter name: lamp_flats-qc_fpn_ymin2. Default value:1000 +Parameter name: lamp_flats-qc_fpn_xmax2. Default value:1390 +Parameter name: lamp_flats-qc_fpn_xmin2. Default value:1350 +Parameter name: lamp_flats-qc_fpn_ymax1. Default value:1536 +Parameter name: ns-mask_ind. Default value:false +Parameter name: lamp_flats-qc_fpn_ymin1. Default value:512 +Parameter name: ns-hi_rejection. Default value:0.1 +Parameter name: lamp_flats-qc_fpn_xmax1. Default value:1536 +Parameter name: ns-lo_rejection. Default value:0.1 +Parameter name: lamp_flats-qc_fpn_xmin1. Default value:512 +Parameter name: dist-qc_thresh_max. Default value:49000 +Parameter name: lamp_flats-mean_factor. Default value:10 +Parameter name: dist-qc_thresh_min. Default value:0 +Parameter name: lamp_flats-tresh_ind. Default value:false +Parameter name: dist-diff_toll. Default value:2 +if true, the temporary directories (where the logs, the final and the temporary products of the recipe are created) are cleaned before the execution +Parameter name: dist-y_box. Default value:5 +Parameter name: dist-box_len. Default value:32 +Parameter name: dist-estimate_ind. Default value:false +Parameter name: dist-fit_edge_ind. Default value:false +<p>Run: the recipe will be executed (see lazy mode)</p><p>Skip: the inputs are broadcast to the output with the following modifications: input files will be filtered according to input and output tags and recipe parameters will be filtered based on the recipe and whether the parameter is set to PORT</p><p>Disabled: the recipe is not executed and an empty SoF is generated on the output port</p> +additional parameters passed to EsoRex +Parameter name: lamp_flats-ury. Default value:1200 +Parameter name: lamp_flats-rrx. Default value:1390 +Parameter name: lamp_flats-lly. Default value:1000 +Parameter name: lamp_flats-llx. Default value:1350 +Parameter name: lamp_flats-bad_hi_rej. Default value:10 +Parameter name: dist-fit_boltz_ind. Default value:true +Parameter name: lamp_flats-bad_lo_rej. Default value:10 +Parameter name: dist-slit_pos_ind. Default value:true +Parameter name: lamp_flats-iterations. Default value:8 +<p>how the purpose of the input files will be sent to the output:</p><p>Do nothing: leave the input purpose unmodified</p><p>Strip last: remove the last section of the input purpose, if there is only one section set the purpose to universal. This is the default mode, and it means that the actor has completed a reduction step and removes it from the purpose chain</p><p>Set to universal: set the output purpose to universal</p> +Parameter name: dist-mag_factor. Default value:8 +Parameter name: lamp_flats-factor. Default value:3 +Parameter name: dist-wave_map_ind. Default value:false +Parameter name: lamp_flats-sigma_factor. Default value:5 +Parameter name: dist-pixel_tol. Default value:5 +Parameter name: lamp_flats-bad_ind. Default value:false +Parameter name: dist-pixel_dist. Default value:15 +Parameter name: dist-par_ind. Default value:true +Parameter name: dist-wcoeff_ind. Default value:true +Parameter name: dist-sigma_factor. Default value:1.5 +Parameter name: dist-n_b_coeffs. Default value:2 +Parameter name: lamp_flats-max_rad. Default value:4 +Parameter name: lamp_flats-interpol_index. Default value:false +Parameter name: lamp_flats-hi_rej. Default value:0.1 +Parameter name: lamp_flats-lo_rej. Default value:0.1 +Parameter name: product-density. Default value:2 +Parameter name: lc_filt_rad. Default value:3 +if true then the actor will check whether the pipeline recipe has already been executed with the same input files and with the same recipe parameters. If this is the case then the recipe will not be executed, and instead the previously generated products (which are the same as those that would have been generated if the recipe were executed, except for a timestamp) will be broadcast to the output port. +Parameter name: lc_kappa. Default value:18 +Parameter name: lc_sw. Default value:false +Parameter name: gen-overpar. Default value:true +Parameter name: dist-n_a_coeffs. Default value:4 +<p>it specifies the behavior of the actor if the recipe fails</p> <p>Stop: the actor produces an error message and the workflows stops. This is the default</p><p>Continue: the actor outputs an empty SoF</p><p>Ask: the actor pops up a window and asks the user whether he wants to continue or stop the execution</p> +Parameter name: dist-max_residual. Default value:0.5 +Parameter name: dist-min_amplitude. Default value:5 +Parameter name: dist-fwhm. Default value:2.83 +Parameter name: dist-sigma. Default value:2 +Parameter name: dist-hw. Default value:7 +Parameter name: dist-min_diff_mean_med_col_int. Default value:10 +Parameter name: dist-calib_indicator. Default value:true +Parameter name: stack-sub_raw_sky. Default value:true +Parameter name: stack-qc_thresh_max. Default value:49000 +the directory the recipe will use as a working directory +if true then the execution is paused just before executing the recipe +if true then an empty sof on the input port will be broadcast to the output without executing the recipe + + + + @@ -4991,7 +5319,7 @@ - + @@ -5151,7 +5479,7 @@ - + null @@ -5182,7 +5510,7 @@ - + @@ -5560,13 +5888,11 @@ - - - + - + - + @@ -5574,7 +5900,7 @@ - + @@ -5767,7 +6093,50 @@ - + +null +null +null +<p>The RecipeExecuter executes one CPL recipe. The recipe can be chosen only when you instantiate the component: at the moment the user is presented with a list of the available recipes (the output of esorex --recipes). After the user selects the recipe the actor queries EsoRex for the recipe parameters and adds them to the actor. Each parameter is set to the default value: if the user wants to change any of the parameters then he can enter his own value or he can write the special value PORT, in which case the value is taken from the input port SoP.</p><p>The actor has three modes: Run, Skip and Disabled</p><p>Note: since this actor has very different behaviour depending on the pipeline recipe to which it is associated, it is not present in the left hand side actor list, and instead it must be instantiated from the menu.</p> +the recipe input parameters +the outputs not matching any of the output categories +the logs generated by EsoRex, empty if lazy mode is triggered +the inputs not matching any of the input categories +the warnings generated by EsoRex, empty if lazy mode is triggered +the input files +the output files +the errors generated by EsoRex, empty if lazy mode is triggered +the parameters used in the last execution of the recipe +a list of file categories separated by a comma or a space: only input files belonging to one of these categories will be passed to the recipe +the selected pipeline recipe (cannot be changed) +a list of file categories separated by a comma or a space: only products belonging to one of these categories will be broadcast to the output port +if true then the execution is paused just before executing the recipe + +the directory the recipe will use as a working directory +if true, the temporary directories (where the logs, the final and the temporary products of the recipe are created) are cleaned before the execution +if true then the actor will check whether the pipeline recipe has already been executed with the same input files and with the same recipe parameters. If this is the case then the recipe will not be executed, and instead the previously generated products (which are the same as those that would have been generated if the recipe were executed, except for a timestamp) will be broadcast to the output port. +<p>Run: the recipe will be executed (see lazy mode)</p><p>Skip: the inputs are broadcast to the output with the following modifications: input files will be filtered according to input and output tags and recipe parameters will be filtered based on the recipe and whether the parameter is set to PORT</p><p>Disabled: the recipe is not executed and an empty SoF is generated on the output port</p> +<p>how the purpose of the input files will be sent to the output:</p><p>Do nothing: leave the input purpose unmodified</p><p>Strip last: remove the last section of the input purpose, if there is only one section set the purpose to universal. This is the default mode, and it means that the actor has completed a reduction step and removes it from the purpose chain</p><p>Set to universal: set the output purpose to universal</p> +Parameter name: bp_lin-lo_rej. Default value:10 +Parameter name: bp_lin-nlin_threshold. Default value:0.5 +the directory where the EsoRex logs will be saved +Parameter name: bp_lin-thresh_sigma_fct. Default value:10 +Parameter name: bp_lin-order. Default value:2 +Parameter name: product-density. Default value:2 +Parameter name: lc_filt_rad. Default value:3 +the directory where the products will be created +Parameter name: lc_kappa. Default value:18 +Parameter name: lc_sw. Default value:false +Parameter name: gen-overpar. Default value:true +<p>it specifies the behavior of the actor if the recipe fails</p> <p>Stop: the actor produces an error message and the workflows stops. This is the default</p><p>Continue: the actor outputs an empty SoF</p><p>Ask: the actor pops up a window and asks the user whether he wants to continue or stop the execution</p> +additional parameters passed to EsoRex +Parameter name: bp_lin-hi_rej. Default value:10 +if true then the execution is paused after the execution of the recipe +if true then an empty sof on the input port will be broadcast to the output without executing the recipe + + + + @@ -5869,7 +6238,85 @@ - + +null +null +null +<p>The RecipeExecuter executes one CPL recipe. The recipe can be chosen only when you instantiate the component: at the moment the user is presented with a list of the available recipes (the output of esorex --recipes). After the user selects the recipe the actor queries EsoRex for the recipe parameters and adds them to the actor. Each parameter is set to the default value: if the user wants to change any of the parameters then he can enter his own value or he can write the special value PORT, in which case the value is taken from the input port SoP.</p><p>The actor has three modes: Run, Skip and Disabled</p><p>Note: since this actor has very different behaviour depending on the pipeline recipe to which it is associated, it is not present in the left hand side actor list, and instead it must be instantiated from the menu.</p> +the recipe input parameters +the outputs not matching any of the output categories +the logs generated by EsoRex, empty if lazy mode is triggered +the inputs not matching any of the input categories +the warnings generated by EsoRex, empty if lazy mode is triggered +the input files +the output files +the errors generated by EsoRex, empty if lazy mode is triggered +the parameters used in the last execution of the recipe +if true then the actor will check whether the pipeline recipe has already been executed with the same input files and with the same recipe parameters. If this is the case then the recipe will not be executed, and instead the previously generated products (which are the same as those that would have been generated if the recipe were executed, except for a timestamp) will be broadcast to the output port. +additional parameters passed to EsoRex +the selected pipeline recipe (cannot be changed) +the directory where the products will be created +<p>how the purpose of the input files will be sent to the output:</p><p>Do nothing: leave the input purpose unmodified</p><p>Strip last: remove the last section of the input purpose, if there is only one section set the purpose to universal. This is the default mode, and it means that the actor has completed a reduction step and removes it from the purpose chain</p><p>Set to universal: set the output purpose to universal</p> +Parameter name: bp_norm-max_cut. Default value:50000 +Parameter name: bp_norm-min_cut. Default value:0 +Parameter name: bp_norm-mean_fct. Default value:100 +if true then an empty sof on the input port will be broadcast to the output without executing the recipe +Parameter name: bp_norm-thr_ind. Default value:true +<p>Run: the recipe will be executed (see lazy mode)</p><p>Skip: the inputs are broadcast to the output with the following modifications: input files will be filtered according to input and output tags and recipe parameters will be filtered based on the recipe and whether the parameter is set to PORT</p><p>Disabled: the recipe is not executed and an empty SoF is generated on the output port</p> +if true then the execution is paused after the execution of the recipe +Parameter name: bp_norm-ury. Default value:1200 +Parameter name: bp_norm-urx. Default value:310 +Parameter name: lamp_flats-qc_thresh_max. Default value:49000 +Parameter name: bp_norm-lly. Default value:1000 +Parameter name: lamp_flats-qc_thresh_min. Default value:0 +Parameter name: bp_norm-llx. Default value:270 +Parameter name: lamp_flats-qc_fpn_ymax2. Default value:1200 +Parameter name: bp_norm-hi_rej. Default value:0.1 +Parameter name: lamp_flats-qc_fpn_ymin2. Default value:1000 +Parameter name: bp_norm-lo_rej. Default value:0.1 +Parameter name: lamp_flats-qc_fpn_xmax2. Default value:1390 +Parameter name: lamp_flats-qc_fpn_xmin2. Default value:1350 +Parameter name: lamp_flats-qc_fpn_ymax1. Default value:1536 +Parameter name: lamp_flats-qc_fpn_ymin1. Default value:512 +if true then the execution is paused just before executing the recipe +Parameter name: lamp_flats-qc_fpn_xmax1. Default value:1536 +Parameter name: lamp_flats-qc_fpn_xmin1. Default value:512 +Parameter name: lamp_flats-mean_factor. Default value:10 +Parameter name: lamp_flats-tresh_ind. Default value:false +Parameter name: lamp_flats-ury. Default value:1200 +Parameter name: lamp_flats-rrx. Default value:1390 +Parameter name: bp_norm-it. Default value:8 +Parameter name: lamp_flats-lly. Default value:1000 +Parameter name: bp_norm-fct. Default value:10 +Parameter name: lamp_flats-llx. Default value:1350 +Parameter name: bp_norm-method_ind. Default value:1 +Parameter name: bp_norm-s_factor. Default value:5 +Parameter name: product-density. Default value:2 +Parameter name: lc_filt_rad. Default value:3 +Parameter name: lc_kappa. Default value:18 +Parameter name: lc_sw. Default value:false +Parameter name: gen-overpar. Default value:true +the directory where the EsoRex logs will be saved + +a list of file categories separated by a comma or a space: only input files belonging to one of these categories will be passed to the recipe +Parameter name: lamp_flats-bad_hi_rej. Default value:10 +Parameter name: lamp_flats-bad_lo_rej. Default value:10 +<p>it specifies the behavior of the actor if the recipe fails</p> <p>Stop: the actor produces an error message and the workflows stops. This is the default</p><p>Continue: the actor outputs an empty SoF</p><p>Ask: the actor pops up a window and asks the user whether he wants to continue or stop the execution</p> +Parameter name: lamp_flats-iterations. Default value:8 +Parameter name: lamp_flats-factor. Default value:3 +a list of file categories separated by a comma or a space: only products belonging to one of these categories will be broadcast to the output port +Parameter name: lamp_flats-sigma_factor. Default value:5 +Parameter name: lamp_flats-bad_ind. Default value:false +Parameter name: lamp_flats-max_rad. Default value:4 +Parameter name: lamp_flats-interpol_index. Default value:false +Parameter name: lamp_flats-hi_rej. Default value:0.1 +the directory the recipe will use as a working directory +Parameter name: lamp_flats-lo_rej. Default value:0.1 +if true, the temporary directories (where the logs, the final and the temporary products of the recipe are created) are cleaned before the execution + + + + @@ -6058,7 +6505,61 @@ - + +null +null +null +<p>The RecipeExecuter executes one CPL recipe. The recipe can be chosen only when you instantiate the component: at the moment the user is presented with a list of the available recipes (the output of esorex --recipes). After the user selects the recipe the actor queries EsoRex for the recipe parameters and adds them to the actor. Each parameter is set to the default value: if the user wants to change any of the parameters then he can enter his own value or he can write the special value PORT, in which case the value is taken from the input port SoP.</p><p>The actor has three modes: Run, Skip and Disabled</p><p>Note: since this actor has very different behaviour depending on the pipeline recipe to which it is associated, it is not present in the left hand side actor list, and instead it must be instantiated from the menu.</p> +the recipe input parameters +the outputs not matching any of the output categories +the logs generated by EsoRex, empty if lazy mode is triggered +the inputs not matching any of the input categories +the warnings generated by EsoRex, empty if lazy mode is triggered +the input files +the output files +the errors generated by EsoRex, empty if lazy mode is triggered +the parameters used in the last execution of the recipe +if true then the actor will check whether the pipeline recipe has already been executed with the same input files and with the same recipe parameters. If this is the case then the recipe will not be executed, and instead the previously generated products (which are the same as those that would have been generated if the recipe were executed, except for a timestamp) will be broadcast to the output port. +additional parameters passed to EsoRex +the selected pipeline recipe (cannot be changed) +the directory where the products will be created +<p>how the purpose of the input files will be sent to the output:</p><p>Do nothing: leave the input purpose unmodified</p><p>Strip last: remove the last section of the input purpose, if there is only one section set the purpose to universal. This is the default mode, and it means that the actor has completed a reduction step and removes it from the purpose chain</p><p>Set to universal: set the output purpose to universal</p> +Parameter name: dark-qc_fpn_ymax. Default value:2047 +Parameter name: dark-qc_fpn_ymin. Default value:1 +Parameter name: dark-qc_fpn_xmax. Default value:2047 +if true then an empty sof on the input port will be broadcast to the output without executing the recipe +Parameter name: dark-qc_fpn_xmin. Default value:1 +<p>Run: the recipe will be executed (see lazy mode)</p><p>Skip: the inputs are broadcast to the output with the following modifications: input files will be filtered according to input and output tags and recipe parameters will be filtered based on the recipe and whether the parameter is set to PORT</p><p>Disabled: the recipe is not executed and an empty SoF is generated on the output port</p> +if true then the execution is paused after the execution of the recipe +Parameter name: dark-qc_ron_nsamp. Default value:100 +Parameter name: dark-qc_ron_hsize. Default value:4 +Parameter name: dark-qc_ron_ymax. Default value:2048 +Parameter name: dark-qc_ron_ymin. Default value:1 +Parameter name: dark-qc_ron_xmax. Default value:2048 +Parameter name: dark-qc_ron_xmin. Default value:1 +if true then the execution is paused just before executing the recipe +Parameter name: dark-hi_rej. Default value:0.1 +Parameter name: dark-lo_rej. Default value:0.1 +Parameter name: bp_noise-hi_rej. Default value:10 +Parameter name: bp_noise-lo_rej. Default value:10 +Parameter name: bp_noise-thresh_sigma_fct. Default value:10 +Parameter name: lc_filt_rad. Default value:3 +Parameter name: lc_kappa. Default value:18 +Parameter name: lc_sw. Default value:false +Parameter name: gen-overpar. Default value:true +the directory where the EsoRex logs will be saved + +a list of file categories separated by a comma or a space: only input files belonging to one of these categories will be passed to the recipe +<p>it specifies the behavior of the actor if the recipe fails</p> <p>Stop: the actor produces an error message and the workflows stops. This is the default</p><p>Continue: the actor outputs an empty SoF</p><p>Ask: the actor pops up a window and asks the user whether he wants to continue or stop the execution</p> +a list of file categories separated by a comma or a space: only products belonging to one of these categories will be broadcast to the output port +Parameter name: dark-qc_fpn_nsamp. Default value:1000 +the directory the recipe will use as a working directory +Parameter name: dark-qc_fpn_hsize. Default value:2 +if true, the temporary directories (where the logs, the final and the temporary products of the recipe are created) are cleaned before the execution + + + + @@ -6291,7 +6792,7 @@ - + @@ -6422,17 +6923,17 @@ - + - + - + - + - + - + @@ -6444,7 +6945,7 @@ - + @@ -6576,7 +7077,7 @@ Yuhong Xiong null <p>A Composite actor is an aggregation of actors. It may have a local director that is responsible for executing the contained actors. A Composite actor with a local director is called an opaque actor. Composite actors do not require a local director. Composite actors with no local director "inherit" the director from the containing workflow and are called non-opaque.</p> <p>To create a composite actor, drag and drop the Composite actor onto the Workflow canvas. Right-click the actor and select Open Actor from the drop-down menu. A new Kepler application window will open for designing the composite.</p> - + @@ -6743,7 +7244,7 @@ - + @@ -6786,13 +7287,13 @@ - + - + - + - + @@ -6915,7 +7416,7 @@ - + @@ -6954,15 +7455,15 @@ - + - + - + @@ -7204,7 +7705,7 @@ - + @@ -7495,9 +7996,9 @@ - + - + @@ -7765,17 +8266,17 @@ - + - + - + - + - + - + @@ -7799,11 +8300,11 @@ - + - + - + @@ -8006,19 +8507,9 @@ - - - + - - - - - - - - - + null @@ -8029,22 +8520,21 @@ The newest execution date of the datasets to be displayed: if not connected defaults to now The oldest execution date of the datasets to be displayed: if not connected defaults to now-24h +the file containing the bookkeeping database + The application used to inspect FITS files - - - - -the file containing the bookkeeping database The actor mode, can be either Enabled, Disabled or Triggered + + The format of start and end date - + - + @@ -8055,9 +8545,7 @@ - - - + @@ -8066,71 +8554,1680 @@ - + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - + - - - - - + - - - + + + +null +Edward A. Lee +null +<p>StringParameter specifies a persistent string. </p> <p>Change the name of the StringParameter to better identify the specified value (right-click the parameter and select "Customize Name" from the menu). Other actors may refer to the StringParameter using the $NAME syntax (e.g. $Parameter). </p> + + + + + + + + + + + + + + + + + + + + -S- + + + + + + + + + - - - + + + + + + + + + + + + + + +null +Gang Zhou +null + <p> The dynamic dataflow (DDF) domain is a superset of the synchronous dataflow(SDF) and Boolean dataflow(BDF) domains. In the SDF domain, an actor consumes and produces a fixed number of tokens per firing. This static information makes possible compile-time scheduling. In the DDF domain, there are few constraints on the production and consumption behavior of actors, and the schedulers make no attempt to construct a compile-time schedule. Instead, each actor has a set of firing rules (patterns) and can be fired if one of them is satisfied, i.e., one particular firing pattern forms a prefix of sequences of unconsumed tokens at input ports. The canonical actors in the DDF domain include Select and Switch, which consume or produce tokens on different channels based on the token received from the control port. (In practice, use DDFSelect and DDFBooleanSelect in the DDF-specific library instead of Select and BooleanSelect in the regular FlowControl library; however, Switch and BooleanSwitch in the regular FlowControl library can be used in DDF domain.)</p> <p> The dynamic scheduler implemented in this director fires all enabled and non-deferrable actors once in a basic iteration. A deferrable actor is one that will not help one of the downstream actors become enabled because that downstream actor either already has enough tokens on the channel connecting those two actors or is waiting for tokens on another channel. If no actor fires so far, which means there is no enabled and non-deferrable actor, then among all enabled and deferrable actors, this director fires those which have the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors. If still no actor fires, then there is no enabled actor. A user can treat several such basic iterations as a single iteration by adding a parameter with name <i>requiredFiringsPerIteration</i> to an actor (which is often a sink actor or an actor directly connected to output port of the composite actor) and specifying the number of times this actor must be fired in a single iteration. If the value of the parameter <i>runUntilDeadlockInOneIteration</i> is a BooleanToken with value true, one single iteration consists of repeating the basic iteration until deadlock is reached (thus overriding the previous definition of one iteration), which is the status of the model where all active actors under the control of this director are unable to fire because their firing rules are not satisfied. However, they may be able to fire again during next iteration when tokens are transferred in from an outside domain. Note <i>runUntilDeadlockInOneIteration</i> can be set to true only when this director is not on the top level.</p> <p> The algorithm implementing one basic iteration goes like this: <pre> E = set of enabled actors D = set of deferrable enabled actors </pre> One basic(default) iteration consists of: <pre> if (E\D != empty set) { fire (E\D) } else if (D != empty set) { fire minimax(D) } else { declare deadlock } </pre> The function "minimax(D)" returns a subset of D with the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors.</p> <p> Note that any SDF model can be run with a DDF Director. However, the notion of iteration is different. One could try to imitate the SDF iteration in the DDF domain by controlling the number of firings in one iteration for some actors, such as requiring a plotter to plot a fixed number of points in each iteration.</p> <p> In the DDF domain, the firing rule of any actor is specified by the token consumption rates of its input ports. A general DDF actor could change the consumption rates of its input ports after each firing of this actor. For multiports, an array token could be used to specify different rates for different channels connected to the same multiport. Note that in SDF, all channels connected to the same multiport have the same rate.</p> <p> Based on DDFSimpleSched in Ptolemy Classic, by Edward Lee. See E. A. Lee et al., "The Almagest," documentation for Ptolemy Classic, Vol. 1, Chapter 7, 1997.</p> +Specify the number of times a workflow is iterated. By default, this parameter is set to "0". Note that "0" does not mean "no iterations." Rather, "0" means that the workflow will iterate forever. Values greater than zero specify the actual number of times the director should execute the entire workflow. +A Parameter representing the maximum capacity of each receiver controlled by this director. This is an integer that defaults to 0, which means the queue in each receiver is unbounded. To specify bounded queues, set this to a positive integer. +A parameter indicating whether one iteration consists of repeated basic iterations until deadlock. If this parameter is true, the model will be executed until deadlock in one iteration. The default value is a BooleanToken with the value false. It cannot be set to true if this director is at the top level. + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +Use the Annotation attribute to annotate a workflow. Double-click the attribute to customize the content, font size, color, and basic formatting (bold and italics). +The font face. Select a font from the drop-down menu. The default is "SansSerif". +Select to indicate that the type should be italics. By default, type will not be italicized. +Select to indicate that the type should be bold. By default, type will not be bold. +The font color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The font size. Select an integer from the drop-down menu or specify a new size by typing it directly into the value field. The default is 14. +The text of the annotation. + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +<p>The Rectangle attribute renders a rectangle on the Workflow canvas. Single-click the rectangle to drag the resize handles and adjust the shape's size, or double-click the rectangle to customize its height, width, line width, color, and fill color.</p> +The vertical extent. The value is a double that defaults to 100.0. +The line width. The value is a double that defaults to 1.0. +The amount of rounding of the corners. The value is a double that defaults to 0.0, which indicates no rounding. +Indicate whether the shape should be centered on its origin. By default, the location is the upper-left corner. +Specify a dash-pattern for dashed or dotted lines. The value consists of an array of doubles that specify the length of the alternating solid and transparent segments. An empty value indicates that the line should not be dashed (the default). +The horizontal extent. The value is a double that defaults to 100.0. +The line color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The fill color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. By default, the value is "none." + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +Use the Annotation attribute to annotate a workflow. Double-click the attribute to customize the content, font size, color, and basic formatting (bold and italics). +The font face. Select a font from the drop-down menu. The default is "SansSerif". +Select to indicate that the type should be italics. By default, type will not be italicized. +Select to indicate that the type should be bold. By default, type will not be bold. +The font color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The font size. Select an integer from the drop-down menu or specify a new size by typing it directly into the value field. The default is 14. +The text of the annotation. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +<p>The Rectangle attribute renders a rectangle on the Workflow canvas. Single-click the rectangle to drag the resize handles and adjust the shape's size, or double-click the rectangle to customize its height, width, line width, color, and fill color.</p> +The line width. The value is a double that defaults to 1.0. +The vertical extent. The value is a double that defaults to 100.0. +Specify a dash-pattern for dashed or dotted lines. The value consists of an array of doubles that specify the length of the alternating solid and transparent segments. An empty value indicates that the line should not be dashed (the default). +Indicate whether the shape should be centered on its origin. By default, the location is the upper-left corner. +The amount of rounding of the corners. The value is a double that defaults to 0.0, which indicates no rounding. +The horizontal extent. The value is a double that defaults to 100.0. +The line color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The fill color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. By default, the value is "none." + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +Use the Annotation attribute to annotate a workflow. Double-click the attribute to customize the content, font size, color, and basic formatting (bold and italics). +The font face. Select a font from the drop-down menu. The default is "SansSerif". +Select to indicate that the type should be italics. By default, type will not be italicized. +Select to indicate that the type should be bold. By default, type will not be bold. +The font color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The font size. Select an integer from the drop-down menu or specify a new size by typing it directly into the value field. The default is 14. +The text of the annotation. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +Use the Annotation attribute to annotate a workflow. Double-click the attribute to customize the content, font size, color, and basic formatting (bold and italics). +The font face. Select a font from the drop-down menu. The default is "SansSerif". +Select to indicate that the type should be italics. By default, type will not be italicized. +Select to indicate that the type should be bold. By default, type will not be bold. +The font color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The font size. Select an integer from the drop-down menu or specify a new size by typing it directly into the value field. The default is 14. +The text of the annotation. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +Use the Annotation attribute to annotate a workflow. Double-click the attribute to customize the content, font size, color, and basic formatting (bold and italics). +The font face. Select a font from the drop-down menu. The default is "SansSerif". +Select to indicate that the type should be italics. By default, type will not be italicized. +Select to indicate that the type should be bold. By default, type will not be bold. +The font color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The font size. Select an integer from the drop-down menu or specify a new size by typing it directly into the value field. The default is 14. +The text of the annotation. + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +<p>StringParameter specifies a persistent string. </p> <p>Change the name of the StringParameter to better identify the specified value (right-click the parameter and select "Customize Name" from the menu). Other actors may refer to the StringParameter using the $NAME syntax (e.g. $Parameter). </p> + + + + + + + + + + + + + + + + + + + + -S- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Vinay Krishnan, Daniel Lazaro Cuadrado (contributor: Edward A. Lee) +null + <p>The StringCompare actor reads two strings and compares them using a specified comparison function. The actor outputs true if the strings satisfy the comparison criteria, or false if not.</p> <p>The comparison functions are specified with the function parameter: </p> <ul> <li>equals: Output true if the strings are equal (the default). </li> <li>startsWith: Output true if the first string starts with second string. </li> <li>endsWith: Output true if the first string ends with the second string. </li> <li>contains: Output true if the first string contains the second string. </li> </ul> <p>Strings will be read from the input ports if they are connected; otherwise strings are read from the parameters.</p> +An input port that accepts the second string. +An output port that broadcasts the result of the comparison (either true or false). +An input port that accepts the first string. +The comparison function (equals, startsWith, endsWith, contains). The default is "equals". +The second string. +Specify whether to ignore case. By default, the actor is case-sensitive. Select the parameter to ignore case. +The first string. + + + + + + + + + + + + + + + +null +Steve Neuendorffer +null +<p>The BooleanSwitch actor reads a value of any type, as well as a Boolean token that is used as a control. If the Boolean token is true, the actor outputs the received value to the trueOutput port; if the Boolean token is false, the actor outputs the received value to the falseOutput port. If the actor has never received a value on the control port, then the actor will output to the falseOutput port.</p> <p>The actor only works under certain directors. It will not work under an SDF Director, but it will under a PN Director, for example.</p> +An input port that accepts tokens of any type. +An output port that broadcasts the input token when the control is false. +An output port that broadcasts the input token when the control is true. +An input port that accepts a Boolean token used to select which output port (trueOutput or falseOutput) to broadcast. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Gang Zhou +null + <p> The dynamic dataflow (DDF) domain is a superset of the synchronous dataflow(SDF) and Boolean dataflow(BDF) domains. In the SDF domain, an actor consumes and produces a fixed number of tokens per firing. This static information makes possible compile-time scheduling. In the DDF domain, there are few constraints on the production and consumption behavior of actors, and the schedulers make no attempt to construct a compile-time schedule. Instead, each actor has a set of firing rules (patterns) and can be fired if one of them is satisfied, i.e., one particular firing pattern forms a prefix of sequences of unconsumed tokens at input ports. The canonical actors in the DDF domain include Select and Switch, which consume or produce tokens on different channels based on the token received from the control port. (In practice, use DDFSelect and DDFBooleanSelect in the DDF-specific library instead of Select and BooleanSelect in the regular FlowControl library; however, Switch and BooleanSwitch in the regular FlowControl library can be used in DDF domain.)</p> <p> The dynamic scheduler implemented in this director fires all enabled and non-deferrable actors once in a basic iteration. A deferrable actor is one that will not help one of the downstream actors become enabled because that downstream actor either already has enough tokens on the channel connecting those two actors or is waiting for tokens on another channel. If no actor fires so far, which means there is no enabled and non-deferrable actor, then among all enabled and deferrable actors, this director fires those which have the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors. If still no actor fires, then there is no enabled actor. A user can treat several such basic iterations as a single iteration by adding a parameter with name <i>requiredFiringsPerIteration</i> to an actor (which is often a sink actor or an actor directly connected to output port of the composite actor) and specifying the number of times this actor must be fired in a single iteration. If the value of the parameter <i>runUntilDeadlockInOneIteration</i> is a BooleanToken with value true, one single iteration consists of repeating the basic iteration until deadlock is reached (thus overriding the previous definition of one iteration), which is the status of the model where all active actors under the control of this director are unable to fire because their firing rules are not satisfied. However, they may be able to fire again during next iteration when tokens are transferred in from an outside domain. Note <i>runUntilDeadlockInOneIteration</i> can be set to true only when this director is not on the top level.</p> <p> The algorithm implementing one basic iteration goes like this: <pre> E = set of enabled actors D = set of deferrable enabled actors </pre> One basic(default) iteration consists of: <pre> if (E\D != empty set) { fire (E\D) } else if (D != empty set) { fire minimax(D) } else { declare deadlock } </pre> The function "minimax(D)" returns a subset of D with the smallest maximum number of tokens on their output channels which satisfy the demand of destination actors.</p> <p> Note that any SDF model can be run with a DDF Director. However, the notion of iteration is different. One could try to imitate the SDF iteration in the DDF domain by controlling the number of firings in one iteration for some actors, such as requiring a plotter to plot a fixed number of points in each iteration.</p> <p> In the DDF domain, the firing rule of any actor is specified by the token consumption rates of its input ports. A general DDF actor could change the consumption rates of its input ports after each firing of this actor. For multiports, an array token could be used to specify different rates for different channels connected to the same multiport. Note that in SDF, all channels connected to the same multiport have the same rate.</p> <p> Based on DDFSimpleSched in Ptolemy Classic, by Edward Lee. See E. A. Lee et al., "The Almagest," documentation for Ptolemy Classic, Vol. 1, Chapter 7, 1997.</p> +Specify the number of times a workflow is iterated. By default, this parameter is set to "0". Note that "0" does not mean "no iterations." Rather, "0" means that the workflow will iterate forever. Values greater than zero specify the actual number of times the director should execute the entire workflow. +A Parameter representing the maximum capacity of each receiver controlled by this director. This is an integer that defaults to 0, which means the queue in each receiver is unbounded. To specify bounded queues, set this to a positive integer. +A parameter indicating whether one iteration consists of repeated basic iterations until deadlock. If this parameter is true, the model will be executed until deadlock in one iteration. The default value is a BooleanToken with the value false. It cannot be set to true if this director is at the top level. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +Use the Annotation attribute to annotate a workflow. Double-click the attribute to customize the content, font size, color, and basic formatting (bold and italics). +The font face. Select a font from the drop-down menu. The default is "SansSerif". +Select to indicate that the type should be italics. By default, type will not be italicized. +Select to indicate that the type should be bold. By default, type will not be bold. +The font color. Specify a string representing an array of four elements: red, green, blue, and alpha, where alpha is transparency. The default is an opaque black, {0.0, 0.0, 0.0, 1.0} +The font size. Select an integer from the drop-down menu or specify a new size by typing it directly into the value field. The default is 14. +The text of the annotation. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +ESO +2.0 +The ProductExplorer allows the suer to browse all the executions of the datasets and to visualize the calibration cascade and the intermediate products. Refer to the Reflex User Manual for a more detailed documentation +If Mode is triggered a BooleanToken on this port defines whether the actor should pop up or not +The newest execution date of the datasets to be displayed: if not connected defaults to now + +The oldest execution date of the datasets to be displayed: if not connected defaults to now-24h +the file containing the bookkeeping database + +The application used to inspect FITS files + +The actor mode, can be either Enabled, Disabled or Triggered + + +The format of start and end date + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +<p>The IsPresent actor outputs "true" or "false" depending on whether it has received a data token or not.</p> <p>The actor reads tokens of any type via the channels of its input multiport. If a token is present on a channel, the actor outputs the Boolean value true on the corresponding channel of the output port; if a token is not present on a channel, the actor outputs false on the corresponding channel of the output port.</p> <p>The width of the input and output port (i.e., the number of channels on each port) must be the same.</p> <p>Note that this actor is most useful when used with synchronous directors like SDF. Under a PN Director, input is always present (by definition). Under a DE Director, the actor is only triggered if one of the input channels has data.</p> +A multiport that accepts values of any type. The width of the port must match the width of the output ports. +A multiport that broadcasts Boolean values: true if the corresponding input channel receives a token; false if the corresponding input channel does not receive a token. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Gang Zhou +null +<p> A type polymorphic select with boolean valued control for use in the DDF domain. In the first iteration, an input token at the <i>control</i> port is read and its value is noted. In the second iteration, if the <i>control</i> input read from the previous iteration is true, then an input token at the <i>trueInput</i> port is read and sent to the output. Likewise with a false <i>control</i> input and the <i>falseInput</i> port. It alternates between these two kinds of iterations until stopped. The <i>control</i> port must receive Boolean Tokens. The <i>trueInput</i> and <i>falseInput</i> ports may receive Tokens of any type. Because tokens are immutable, the same Token is sent to the output, rather than a copy.</p> <p> Note this actor sends an output token every two iterations. Contrast this with BooleanSelect which sends an output token every iteration. </p> +Input for tokens on the false path. The port type can be any type. +The output port. The type is at least the type of <i>trueInput</i> and <i>falseInput</i>. +Input for tokens on the true path. The port type can be any type. +Input that selects one of the other input ports. The type is boolean. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Xiaojun Liu +null + This actor executes a Python script. The default script has an input port and an output port. To view or edit the script, double-click on the actor. <p> As an example, a simplified version of the Scale actor can be implemented by the following script: </p> <pre> 1. class Main : 2. "scale" 3. def fire(self) : 4. if not self.input.hasToken(0) : 5. return 6. s = self.scale.getToken() 7. t = self.input.get(0) 8. self.output.broadcast(s.multiply(t)) </pre> Line 1 defines a Python class Main. This name is fixed. An instance of this class is created when the actor is initialized. Line 2 is a description of the purpose of the script. Lines 3-8 define the fire() method. In the method body, <i>input</i> and <i>output</i> are ports that have been added to the actor, and <i>scale</i> is a parameter added to the actor (these can be added in the XML that defines the actor instance in an actor library). The Main class can provide other methods in the Executable interface as needed. <p> In the script, use <code>self.actor</code> to access the actor. For example, <code>self.actor.getDirector()</code> returns the current director of the actor. For debugging, use <code>self.actor.debug(someMessage)</code>. The final message sent to the debug listeners of the actor will have the string "From script: " inserted at the beginning. To avoid generating the debug message when there are no listeners, use: <pre> if self.actor.isDebugging() : self.actor.debug(someMessage) </pre> <p> This class relies on Jython, which is a Java implementation of Python. </p> Follow the links below for more information about the Python language, licensing, downloads, etc. <p><a href="http://www.python.org" target="_top">Python</a></p> <p><a href="http://www.jython.org" target="_top">Jython</a></p> <p><a href="http://www.jython.org/docs/differences.html">Differences between Jython and the C version of Python</a></p> <p><a href="http://www.jython.org/Project/userguide.html#the-jython-registry">The Jython Registry</a> - information about how to set the search path. </p> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Vinay Krishnan, Daniel Lazaro Cuadrado (contributor: Edward A. Lee) +null + <p>The StringCompare actor reads two strings and compares them using a specified comparison function. The actor outputs true if the strings satisfy the comparison criteria, or false if not.</p> <p>The comparison functions are specified with the function parameter: </p> <ul> <li>equals: Output true if the strings are equal (the default). </li> <li>startsWith: Output true if the first string starts with second string. </li> <li>endsWith: Output true if the first string ends with the second string. </li> <li>contains: Output true if the first string contains the second string. </li> </ul> <p>Strings will be read from the input ports if they are connected; otherwise strings are read from the parameters.</p> +An input port that accepts the second string. +An output port that broadcasts the result of the comparison (either true or false). +An input port that accepts the first string. +The comparison function (equals, startsWith, endsWith, contains). The default is "equals". +The second string. +Specify whether to ignore case. By default, the actor is case-sensitive. Select the parameter to ignore case. +The first string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Paul Whitaker +null +<p>The Logic Function actor reads Boolean tokens, performs a specified logical operation (e.g., "and" or "xnor"), and outputs the evaluated result as a Boolean token.</p> <p>Specify a logic function with the function parameter. The following logic functions may be performed:</p> <table> <tr><th>Logic Function </th><th>Definition</th></tr> <tr><td>and </td><td>The logical "and" operator (the default)</td></tr> <tr><td>or </td><td>The logical "or" operator.</td></tr> <tr><td>xor</td><td>The logical "xor" operator. </td></tr> <tr><td>nand</td><td>The logical "nand" operator. Equivalent to the negation of "and". </td></tr> <tr><td>nor</td><td>The logical "nor" operator. Equivalent to the negation of "or". </td></tr> <tr><td>xnor</td><td>The logical "xnor" operator. Equivalent to the negation of "xor".</td></tr> </table> <p>For more information about these functions, see http://whatis.techtarget.com/definition/0,,sid9_gci213512,00.html.</p> <p>The actor consumes at most one token on each input channel. It does not require that each input channel have a token upon firing. As long as one channel contains a token, the actor will produce output. If no input tokens are available, then no output is produced.</p> +An output port that broadcasts Boolean tokens representing the evaluated input. +A multiport that accepts Boolean tokens. +The logical operation to perform: and, or, xor, nand, nor, xnor. For more information about these functions, see http://whatis.techtarget.com/definition/0,,sid9_gci213512,00.html. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +John Li +$Id: LogicalNot.java 57040 2010-01-27 20:52:32Z cxh $ + This actor implements a logical NOT operator. It has one input and one output port, neither of which is a multiport, and both of which have type boolean. A BooleanToken that arrives in the <i>input</i> will be negated and sent on the <i>output</i>. If no input token is available, then no output is produced. +The output port. By default, the type of this output is constrained to be at least that of the input. +The input port. This base class imposes no type constraints except that the type of the input cannot be greater than the type of the output. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Steve Neuendorffer +null +<p>The BooleanSwitch actor reads a value of any type, as well as a Boolean token that is used as a control. If the Boolean token is true, the actor outputs the received value to the trueOutput port; if the Boolean token is false, the actor outputs the received value to the falseOutput port. If the actor has never received a value on the control port, then the actor will output to the falseOutput port.</p> <p>The actor only works under certain directors. It will not work under an SDF Director, but it will under a PN Director, for example.</p> +An input port that accepts tokens of any type. +An output port that broadcasts the input token when the control is false. +An output port that broadcasts the input token when the control is true. +An input port that accepts a Boolean token used to select which output port (trueOutput or falseOutput) to broadcast. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +ESO +2.0 +The ProductExplorer allows the suer to browse all the executions of the datasets and to visualize the calibration cascade and the intermediate products. Refer to the Reflex User Manual for a more detailed documentation +If Mode is triggered a BooleanToken on this port defines whether the actor should pop up or not +The newest execution date of the datasets to be displayed: if not connected defaults to now + +The oldest execution date of the datasets to be displayed: if not connected defaults to now-24h +the file containing the bookkeeping database + +The application used to inspect FITS files + +The actor mode, can be either Enabled, Disabled or Triggered + + +The format of start and end date + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward A. Lee +null +<p>The IsPresent actor outputs "true" or "false" depending on whether it has received a data token or not.</p> <p>The actor reads tokens of any type via the channels of its input multiport. If a token is present on a channel, the actor outputs the Boolean value true on the corresponding channel of the output port; if a token is not present on a channel, the actor outputs false on the corresponding channel of the output port.</p> <p>The width of the input and output port (i.e., the number of channels on each port) must be the same.</p> <p>Note that this actor is most useful when used with synchronous directors like SDF. Under a PN Director, input is always present (by definition). Under a DE Director, the actor is only triggered if one of the input channels has data.</p> +A multiport that accepts values of any type. The width of the port must match the width of the output ports. +A multiport that broadcasts Boolean values: true if the corresponding input channel receives a token; false if the corresponding input channel does not receive a token. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +null +Vinay Krishnan, Daniel Lazaro Cuadrado (contributor: Edward A. Lee) +null + <p>The StringCompare actor reads two strings and compares them using a specified comparison function. The actor outputs true if the strings satisfy the comparison criteria, or false if not.</p> <p>The comparison functions are specified with the function parameter: </p> <ul> <li>equals: Output true if the strings are equal (the default). </li> <li>startsWith: Output true if the first string starts with second string. </li> <li>endsWith: Output true if the first string ends with the second string. </li> <li>contains: Output true if the first string contains the second string. </li> </ul> <p>Strings will be read from the input ports if they are connected; otherwise strings are read from the parameters.</p> +An input port that accepts the second string. +An output port that broadcasts the result of the comparison (either true or false). +An input port that accepts the first string. +The comparison function (equals, startsWith, endsWith, contains). The default is "equals". +The second string. +Specify whether to ignore case. By default, the actor is case-sensitive. Select the parameter to ignore case. +The first string. + + + + + + + + + + + + + + + + + + + + + + + +null +Edward Lee +null +<p>The StringConstant actor outputs a string specified via the actor's value parameter.</p> <p>Specifying strings with the StringConstant actor is convenient, as the actor does not require that strings be surrounded by quotes. The actor is often used to specify file paths, which can be selected using the Browse button available in the actor's parameters.</p> <p>Specified string values can include references to parameters within scope (i.e., parameters defined at the same level of the hierarchy or higher). </p> <p>NOTE: If using a PN Director, the 'firingCountLimit' parameter is often set to a finite integer (e.g. '1') so that the workflow will terminate. </p> +An output port that broadcasts a string constant specified by the value parameter. +A multiport that has no declared type (in other words, the port can accept any data type: double, int, array, etc.) If the port is connected, the actor will not fire until the trigger port receives an input token. Connecting the port is optional, but useful when scheduling the actor to perform at a certain time. +The limit on the number of times the actor will fire. The default value is 'NONE', meaning there is no limit on the number of time the constant will be provided to the output port. Any integer can be provided as a value for this parameter. +The value produced by the actor. Specified strings do not require enclosing quotes. (To include a '$' sign in the string, enter '$$'.) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -8152,7 +10249,7 @@ - + @@ -8171,27 +10268,47 @@ - + - + - + - + - + + + + + + + + + - + + + + + + + + + + + + + @@ -8205,7 +10322,7 @@ - + @@ -8217,10 +10334,11 @@ + - + @@ -8237,11 +10355,12 @@ + - + @@ -8250,4 +10369,7 @@ + + + diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/regtests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/regtests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/regtests/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/regtests/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -91,7 +91,8 @@ subdir = regtests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -218,6 +219,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -232,6 +240,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -331,6 +340,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/regtests/tests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/regtests/tests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/regtests/tests/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/regtests/tests/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -91,7 +91,8 @@ subdir = regtests/tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -158,6 +159,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -172,6 +180,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -271,6 +280,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/Makefile.am 2015-09-21 11:40:48.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/Makefile.am 2017-05-05 14:18:29.000000000 +0000 @@ -333,5 +333,5 @@ libsinfo_la_LDFLAGS = $(CPL_LDFLAGS) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -libsinfo_la_LIBADD = $(LIBIRPLIB) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBRECIPES) $(LIBCEXT) -libsinfo_la_DEPENDENCIES = $(LIBIRPLIB) +libsinfo_la_LIBADD = $(LIBIRPLIB) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBRECIPES) $(LIBCEXT) $(LIBHDRL) +libsinfo_la_DEPENDENCIES = $(LIBIRPLIB) $(LIBHDRL) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -93,7 +93,8 @@ subdir = sinfoni ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -341,6 +342,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -355,6 +363,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -454,6 +463,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -766,8 +776,8 @@ sinfo_atmo_disp.c libsinfo_la_LDFLAGS = $(CPL_LDFLAGS) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -libsinfo_la_LIBADD = $(LIBIRPLIB) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBRECIPES) $(LIBCEXT) -libsinfo_la_DEPENDENCIES = $(LIBIRPLIB) +libsinfo_la_LIBADD = $(LIBIRPLIB) $(LIBCPLDRS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBRECIPES) $(LIBCEXT) $(LIBHDRL) +libsinfo_la_DEPENDENCIES = $(LIBIRPLIB) $(LIBHDRL) all: all-recursive .SUFFIXES: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_atmo_disp.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_atmo_disp.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_atmo_disp.c 2015-01-21 14:02:57.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_atmo_disp.c 2017-10-01 07:33:07.000000000 +0000 @@ -232,7 +232,7 @@ nrows = cpl_table_get_nrow(ptable); expo = cpl_malloc(dim * sizeof(expo[0])); memset(&expo[0], 0, dim * sizeof(expo[0])); - const char* COL_NAME_TEMPLATE = "col_%d"; + const char* COL_NAME_VALUE = "value"; for (i = 0; i < nrows; i++) { @@ -242,7 +242,7 @@ for (j = 0; j < dim; j++) { char col_name[255]; - sprintf(col_name, COL_NAME_TEMPLATE, j); + sprintf(col_name, "col_%d" , j); expo[j] = cpl_table_get_int(ptable, col_name, i, &inull); } value = cpl_table_get(ptable, COL_NAME_VALUE, i, &inull); @@ -326,10 +326,11 @@ cpl_vector_set(vparams, 1, lambda); // calc the shift - double shift_y = cpl_polynomial_eval(poly, vparams); // North - South - double shift_x = 0; + if (CPL_ERROR_NONE == cpl_error_get_code()) { + double shift_x = 0; + double shift_y = cpl_polynomial_eval(poly, vparams); // North - South double res_shift_x = -(shift_x - l0_shift_x); double res_shift_y = -(shift_y - l0_shift_y); cpl_image* plane = NULL; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_baddist_ini_by_cpl.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_baddist_ini_by_cpl.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_baddist_ini_by_cpl.c 2015-01-20 10:25:19.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_baddist_ini_by_cpl.c 2018-02-09 09:55:57.000000000 +0000 @@ -36,6 +36,7 @@ #include "sinfo_pro_types.h" #include "sinfo_raw_types.h" #include "sinfo_globals.h" +#include "sinfo_pfits.h" #include "sinfo_functions.h" #include "sinfo_file_handling.h" diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_baryvel.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_baryvel.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_baryvel.c 2015-09-11 11:32:53.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_baryvel.c 2017-08-29 07:57:45.000000000 +0000 @@ -252,14 +252,14 @@ C = DATE[1] + DATE[2]*1.E-2 + DATE[3]*1.E-4 + UT*1.E-6; if (C > 1582.1015E0) { - IA=(int) (YP/100.D0); + IA=(int) (YP/100.); A=IA; - IB=2-IA+((int)(A/4.D0)); + IB=2-IA+((int)(A/4.)); } else { IB=0; } - *JD = ((int) (365.25E0*YP)) + ((int)(30.6001D0*(P+1.D0))) + DATE[3] + UT + *JD = ((int) (365.25E0*YP)) + ((int)(30.6001*(P+1.))) + DATE[3] + UT + IB + 1720994.5E0; /* diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_dist_config.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_dist_config.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_dist_config.c 2014-01-01 11:48:46.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_dist_config.c 2018-02-12 08:50:28.000000000 +0000 @@ -215,13 +215,13 @@ cpl_parameterlist_append(list, p); p = cpl_parameter_new_value("sinfoni.bp_dist.min_cut", CPL_TYPE_DOUBLE, - "the minimum value of real data", "sinfoni.bp_dist", 0.1); + "the minimum value of real data. For J band data taken after 31/01/2018 the default is 0.05.", "sinfoni.bp_dist", 0.1); cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "bp_dist-min_cut"); cpl_parameterlist_append(list, p); p = cpl_parameter_new_value("sinfoni.bp_dist.max_cut", CPL_TYPE_DOUBLE, - "the minimum value of real data", "sinfoni.bp_dist", + "the maximum value of real data", "sinfoni.bp_dist", 50000.); cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "bp_dist-max_cut"); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_lin.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_lin.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_lin.c 2013-12-31 13:08:51.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_lin.c 2017-09-28 14:49:24.000000000 +0000 @@ -207,14 +207,14 @@ "QC BP-MAP LIN",deg," MED"); sinfo_qclog_add_double(qclog_tbl,key_name, cpl_polynomial_get_coeff(pol,°), - "Linearity Polynomial Coeff","%g"); + "Linearity Polynomial Coeff"); } sinfo_free_polynomial(&pol); check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method")); snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p)); ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value, - "BP search method","%s")); + "BP search method")); ck0(sinfo_pro_save_tbl(det_lin,raw,sof,BP_LIN_LIN_DET_INFO_OUT_FILENAME, PRO_LIN_DET_INFO,qclog_tbl,plugin_id,config), @@ -243,15 +243,15 @@ snprintf(key_name,MAX_NAME_SIZE-1,"%s%i","QC GAIN",i); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name, cpl_table_get_double(gain,"gain",i,status), - "Detector gain","%g")); + "Detector gain")); } ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC GAIN", cpl_table_get_column_median(gain,"gain"), - "Detector gain median","%g")); + "Detector gain median")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC GAINERR", cpl_table_get_column_stdev(gain,"gain"), - "Detector gain error","%g")); + "Detector gain error")); ck0(sinfo_pro_save_tbl(gain,raw,sof,BP_LIN_GAIN_OUT_FILENAME, PRO_GAIN_INFO,qclog_tbl,plugin_id,config), @@ -306,14 +306,14 @@ snprintf(key_value,MAX_NAME_SIZE-1,"%g",cpl_vector_get(cube_mean,i)); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name, cpl_vector_get(cube_mean,i), - "Linearity Polynomial Coeff","%g")); + "Linearity Polynomial Coeff")); } sinfo_free_my_vector(&cube_mean); check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method")); snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p)); ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value, - "BP search method","%s")); + "BP search method")); ck0(sinfo_pro_save_ims(coeffs_imgl,raw,sof,cfg->coeffsCubeName, @@ -344,10 +344,10 @@ check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method")); snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p)); ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value, - "BP search method","%s")); + "BP search method")); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad, - "No of bad pixels","%d")); + "No of bad pixels")); ck0(sinfo_pro_save_ima(mask,raw,sof,cfg->outName,PRO_BP_MAP_NL,qclog_tbl, plugin_id,config), diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_noise.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_noise.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_noise.c 2013-12-31 11:06:56.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_noise.c 2017-09-28 13:18:08.000000000 +0000 @@ -129,9 +129,9 @@ check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method")); snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p)); ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value, - "BP search method","%s")); + "BP search method")); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad, - "No of bad pixels","%d")); + "No of bad pixels")); ck0(sinfo_pro_save_ima(mask,raw,sof,(char *) out_name, PRO_BP_MAP_HP,qclog_tbl,plugin_id,config), diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_norm.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_norm.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_bp_norm.c 2013-12-31 13:08:51.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_bp_norm.c 2017-09-28 13:18:08.000000000 +0000 @@ -326,11 +326,11 @@ ck0_nomsg( sinfo_qclog_add_string(qclog_tbl, "QC BP-MAP METHOD", - key_value, "BP search method", "%s")); + key_value, "BP search method")); ck0_nomsg( sinfo_qclog_add_int(qclog_tbl, "QC BP-MAP NBADPIX", n, - "No of bad pixels", "%d")); + "No of bad pixels")); ck0( sinfo_pro_save_ima(maskImage, ref_set, sof, cfg->outName, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_cube_construct.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_cube_construct.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_cube_construct.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_cube_construct.c 2017-09-23 08:53:12.000000000 +0000 @@ -553,12 +553,12 @@ mpar[k] = 1 ; } /* finally, do the least square fit using a Gaussian */ - int iters; - if ( 0 > ( iters = sinfo_new_lsqfit_c( xdat, &xdim, + //int iters; + if ( 0 > sinfo_new_lsqfit_c( xdat, &xdim, line -> data, wdat, &ndat, (*par) -> fit_par, (*par) -> derv_par, mpar, - &numpar, &tol, &its, &lab)) ) + &numpar, &tol, &its, &lab) ) { /* cpl_msg_debug ("north_south_test:", @@ -612,8 +612,8 @@ if ( counter != n_slitlets ) { - continue ; sinfo_msg_warning("wrong number of slitlets found in row: %d",row); + continue ; } /* store the distances between the sources in a buffer */ for ( i = 1 ; i < n_slitlets ; i++ ) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_dark_ini.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_dark_ini.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_dark_ini.h 2008-02-12 13:29:09.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_dark_ini.h 2017-08-29 07:58:22.000000000 +0000 @@ -29,7 +29,7 @@ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ -#include "sinfo_fitshead.h" +//#include "sinfo_fitshead.h" #include "sinfo_dark_cfg.h" #include /*---------------------------------------------------------------------------- diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_dfs.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_dfs.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_dfs.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_dfs.c 2017-09-28 19:08:09.000000000 +0000 @@ -467,12 +467,12 @@ yshift=max_ima_cy-(double)ny/2; snprintf(key_name,sizeof(key_name),"%s%d%s","QC PUPIL",n," SHIFTX"); - sinfo_qclog_add_double(*qclog_tbl,key_name,xshift, - "X shift centroid - center image","%f"); + sinfo_qclog_add_double_f(*qclog_tbl,key_name,xshift, + "X shift centroid - center image"); snprintf(key_name,sizeof(key_name),"%s%d%s","QC PUPIL",n," SHIFTY"); - sinfo_qclog_add_double(*qclog_tbl,key_name,yshift, - "Y shift centroid - center image","%f"); + sinfo_qclog_add_double_f(*qclog_tbl,key_name,yshift, + "Y shift centroid - center image"); cpl_image_delete(img); return 0; @@ -549,6 +549,30 @@ } + +/** + @brief Set dispersion as a function of band + @param band input band + @return dispersion + @note since the detector was upgrade to 2K Hawaii we use for the dispersion + the values originally thought about for the old detector in dither mode + */ + +double sinfo_get_dispersion(const char* band) +{ + double disp=0.; + if (strcmp(band,"H+K") == 0) { + disp=DISPERSION_HK_DITH; + } else if (strcmp(band,"K") == 0) { + disp=DISPERSION_K_DITH; + } else if (strcmp(band,"J") == 0) { + disp=DISPERSION_J_DITH; + } else if (strcmp(band,"H") == 0) { + disp=DISPERSION_H_DITH; + } + return disp; + +} /** @brief Check if pixel scale changes @param pix_scale input pixel scale diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_fft_base.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_fft_base.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_fft_base.c 2015-09-21 11:51:06.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_fft_base.c 2017-09-23 06:23:59.000000000 +0000 @@ -102,11 +102,11 @@ unsigned i2rev=0; unsigned i3rev=0; unsigned ibit=0; - unsigned ip2=0; + unsigned ifp1=0; unsigned ifp2=0; unsigned k2=0; - unsigned n=0; + unsigned nprev = 1; unsigned ntot = 1; register unsigned i2=0; @@ -124,9 +124,9 @@ } for (idim = ndim - 1; idim >= 0; --idim) { - n = nn[idim]; + unsigned n = nn[idim]; - ip2 = nprev * n; /* Unit step for next dimension */ + unsigned ip2 = nprev * n; /* Unit step for next dimension */ i2rev = 0; /* Bit reversed i2 */ /* This is the bit reversal section of the routine */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_focus.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_focus.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_focus.c 2015-12-09 15:59:12.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_focus.c 2017-09-23 06:23:59.000000000 +0000 @@ -1368,9 +1368,9 @@ mpar[i] = 1 ; } int fitInd ; - if ( -1 == (fitInd = sinfo_new_fit_2d_gaussian(summedIm, fit_par, derv_par, + if ( -1 == sinfo_new_fit_2d_gaussian(summedIm, fit_par, derv_par, mpar, llx, lly, halfbox_x, - halfbox_y, check)) ) + halfbox_y, check) ) { sinfo_msg_warning("sinfo_fit2dGaussian failed!") ; cpl_image_delete( summedIm) ; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_functions.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_functions.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_functions.h 2015-09-11 11:37:04.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_functions.h 2017-05-05 14:18:29.000000000 +0000 @@ -80,6 +80,7 @@ sinfo_get_keyvalue_string(cpl_frame * ref_frame, const char* key_name); int sinfo_get_strehl_type(cpl_frameset* sof); double sinfo_get_wave_cent(const char* band); +double sinfo_get_dispersion(const char* band); void sinfo_memory_status(void); int sinfo_check_rec_status(const int val); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_hidden.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_hidden.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_hidden.h 2010-02-12 17:56:35.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_hidden.h 2017-09-08 09:21:59.000000000 +0000 @@ -109,4 +109,6 @@ #define SKYSPIDER_OUT_FILENAME "out_objnod.fits" #define SKYSPIDER_MASK_OUT_FILENAME "out_mask_cube_spider.fits" #define EFFICIENCY_FILENAME "out_efficiency.fits" +#define SPECTRA_FLUXCAL_FILENAME "out_spectra_fluxcal.fits" +#define RESPONSE_FILENAME "out_response.fits" #endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_image_ops.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_image_ops.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_image_ops.c 2015-09-17 07:30:32.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_image_ops.c 2018-01-19 12:37:02.000000000 +0000 @@ -752,7 +752,7 @@ * sinfo_median is the mean of colnum/2-1 th and colnum/2 th value. */ - if ( colnum % 2 == 1 ) + if ( colnum % 2 == 1 || colnum == 0) { sinfo_median = column[colnum/2] ; } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_add_bp_map.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_add_bp_map.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_add_bp_map.c 2013-12-31 11:06:56.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_add_bp_map.c 2017-09-28 13:18:08.000000000 +0000 @@ -234,7 +234,7 @@ sinfo_msg ("number of bad pixels: %d\n", n_bad) ; cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC MBP_MAP NBADPIX", - n_bad,"No of bad pixels","%d")); + n_bad,"No of bad pixels")); if (nmsk>1) { ck0(sinfo_pro_save_ima(img_tot,ref_set,sof,out_msk, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_bezier.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_bezier.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_bezier.c 2015-09-21 11:48:22.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_bezier.c 2017-10-03 05:47:08.000000000 +0000 @@ -756,7 +756,7 @@ new_XYZW res; new_XYZW selected; float step, cumstep, selected_distance; - new_Dim *point; + new_Dim *point=NULL; double munk; int ilx = 0; int ily = 0; @@ -809,7 +809,7 @@ else { #ifdef DEBUG sinfo_msg_debug("Ignored im[%d,%d,%d]=%lf reason:%f", - i,j,k,pidata[sinfo_im_xy(im,i,j)], + i,j,k,pidata[pix], padata[pix]); #endif } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_cubes_build.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_cubes_build.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_cubes_build.c 2014-11-10 08:55:28.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_cubes_build.c 2017-09-28 13:18:08.000000000 +0000 @@ -640,7 +640,7 @@ ck0_nomsg( sinfo_qclog_add_int(qclog_tbl, "QC SKYCOR THBKGFIT", sqc->th_fit, - "Thermal background fit success", "%d")); + "Thermal background fit success")); ck0( sinfo_pro_save_ims(obj_cor, sof, sof, file_name, pro_obs, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_cubes_coadd.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_cubes_coadd.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_cubes_coadd.c 2015-08-21 08:17:51.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_cubes_coadd.c 2017-09-28 19:12:04.000000000 +0000 @@ -43,6 +43,7 @@ #include "sinfo_cube_construct.h" #include "sinfo_error.h" #include "sinfo_utils_wrappers.h" +#include "sinfo_utl_efficiency.h" //Used only for cpl_propertylist_has #include "sinfo_dfs.h" /*---------------------------------------------------------------------------- @@ -93,7 +94,7 @@ int i=0; int n=0 ; - /* int partind = 0 ; */ + int centralpix=0 ; int z_siz=0; int z_min=0; @@ -108,15 +109,7 @@ float ref_offy=0; float newcenter_x=0 ; float newcenter_y=0 ; - /* - float cd1_1=0; - float cd1_2=0; - float cd2_1=0; - float cd2_2=0; - double pixelscale=0; - */ - //double angle=0; - //float radangle=0 ; + double exptime=0 ; double * times=NULL ; @@ -182,23 +175,17 @@ } /*----parse input data and parameters to set cube_config cfg---*/ - check_nomsg(stk = cpl_frameset_new()); + stk = cpl_frameset_new(); - cknull(cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk), - "Error setting parameter configuration"); + cfg = sinfo_parse_cpl_input_objnod(config,sof,&stk); - ck0(sinfo_check_input_data(cfg),"error checking input"); + sinfo_check_input_data(cfg); if ( cfg->jitterind == 1 ) { - cknull(times = (double*) cpl_calloc (cfg->nframes, sizeof (double)), - " could not allocate memory!") ; - - cknull(offsetx = (float*) cpl_calloc (cfg->nframes, sizeof(float)), - " could not allocate memory!") ; - - cknull(offsety = (float*) cpl_calloc (cfg->nframes, sizeof(float)), - " could not allocate memory!") ; + times = (double*) cpl_calloc (cfg->nframes, sizeof (double)); + offsetx = (float*) cpl_calloc (cfg->nframes, sizeof(float)); + offsety = (float*) cpl_calloc (cfg->nframes, sizeof(float)); } if (cfg->jitterind == 0) @@ -210,10 +197,8 @@ } } - ck0(sinfo_auto_size_cube_new(cfg,&ref_offx,&ref_offy, - &offx_min,&offy_min, - &offx_max,&offy_max), - "Error resizing cube"); + sinfo_auto_size_cube_new(cfg,&ref_offx,&ref_offy,&offx_min,&offy_min, + &offx_max,&offy_max); if(NULL != cpl_frameset_find(sof,PRO_ILL_COR)) { frame = cpl_frameset_find(sof,PRO_ILL_COR); @@ -237,7 +222,6 @@ goto cleanup; } - /* get some header values and compute the CD-sinfo_matrix */ plist=cpl_propertylist_load(name,0); @@ -249,7 +233,6 @@ return -1; } - //pixelscale = sinfo_pfits_get_pixscale(plist) /2; //angle = sinfo_pfits_get_posangle(plist) ; /* in PUPIL data there is not posangle info: we reset the error */ @@ -258,14 +241,6 @@ } sinfo_free_propertylist(&plist); - // The following 5 lines are not really used here! - /* - radangle = angle * PI_NUMB / 180. ; - cd1_1 = cos(radangle) ; - cd1_2 = sin(radangle) ; - cd2_1 = -sin(radangle) ; - cd2_2 = cos(radangle) ; - */ sinfo_msg_debug("frame no.: %d, name: %s\n", n, name) ; cknull(im = cpl_image_load(name,CPL_TYPE_FLOAT,0,0), @@ -291,7 +266,6 @@ } /* end loop over n (nframes) */ - /* leak free */ if(cfg->jitterind == 0) { goto exit; @@ -308,25 +282,22 @@ if ( cfg->jitterind == 1 ) { - check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vllx")); - check_nomsg(vllx = cpl_parameter_get_int(p)); - check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vlly")); - check_nomsg(vlly = cpl_parameter_get_int(p)); - check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vurx")); - check_nomsg(vurx = cpl_parameter_get_int(p)); - check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.objnod.vury")); - check_nomsg(vury = cpl_parameter_get_int(p)); - cknull(cube_tmp = (cpl_imagelist**) cpl_calloc (cfg->nframes, - sizeof (cpl_imagelist*)), - "Could not allocate memory for cube_tmp"); - - - cknull(cubeobject = (cpl_imagelist**) cpl_calloc (cfg->nframes, - sizeof (cpl_imagelist*)), - "Could not allocate memory for cubeobject"); - check_nomsg(p=cpl_parameterlist_find(config, - "sinfoni.objnod.sky_cor")); - check_nomsg(sky_cor=cpl_parameter_get_bool(p)); + p = cpl_parameterlist_find(config, "sinfoni.objnod.vllx"); + vllx = cpl_parameter_get_int(p); + p = cpl_parameterlist_find(config, "sinfoni.objnod.vlly"); + vlly = cpl_parameter_get_int(p); + p = cpl_parameterlist_find(config, "sinfoni.objnod.vurx"); + vurx = cpl_parameter_get_int(p); + p = cpl_parameterlist_find(config, "sinfoni.objnod.vury"); + vury = cpl_parameter_get_int(p); + cube_tmp = (cpl_imagelist**) cpl_calloc (cfg->nframes, + sizeof (cpl_imagelist*)); + + + cubeobject = (cpl_imagelist**) cpl_calloc (cfg->nframes, + sizeof (cpl_imagelist*)); + p=cpl_parameterlist_find(config,"sinfoni.objnod.sky_cor"); + sky_cor=cpl_parameter_get_bool(p); for ( n = 0 ; n < cfg->nframes ; n++ ) { @@ -341,23 +312,18 @@ snprintf(file_name,MAX_NAME_SIZE-1,"%s%2.2d%s","out_cube_obj",n, ".fits"); } - check_nomsg(cube_tmp[n] = cpl_imagelist_load(file_name, - CPL_TYPE_FLOAT,0)); + cube_tmp[n] = cpl_imagelist_load(file_name,CPL_TYPE_FLOAT,0); - check_nomsg(cubeobject[n] = sinfo_new_cube_getvig( - cube_tmp[n], - 1+vllx,1+vlly, - 64 - vurx, 64 - vury)); - check_nomsg(sinfo_free_imagelist(&cube_tmp[n])); + cubeobject[n] = sinfo_new_cube_getvig(cube_tmp[n],1+vllx,1+vlly, + 64 - vurx, 64 - vury); + sinfo_free_imagelist(&cube_tmp[n]); } sinfo_free_array_imagelist(&cube_tmp); - } - /* --------------------------------------------------------------------- ------------------------JITTERING------------------------------------ @@ -368,25 +334,15 @@ { sinfo_msg("Jittering..."); - sinfo_msg("Coadded cube size. x: %d y: %d", - cfg->size_x,cfg->size_y); - check_nomsg(jittercube = cpl_imagelist_new()) ; - - - /* - --------------------------------------------------------------------- - -------------------THOMAS ALGORITHM---------------------------------- - --------------------------------------------------------------------- - */ - - check_nomsg(p=cpl_parameterlist_find(config, - "sinfoni.objnod.scales_sky")); - check_nomsg(scales_sky=cpl_parameter_get_bool(p)); - check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.ks_clip")); - check_nomsg(ks_clip = cpl_parameter_get_bool(p)); - check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.objnod.kappa")); - check_nomsg(kappa = cpl_parameter_get_double(p)); + sinfo_msg("Coadded cube size. x: %d y: %d", cfg->size_x,cfg->size_y); + jittercube = cpl_imagelist_new() ; + p=cpl_parameterlist_find(config,"sinfoni.objnod.scales_sky"); + scales_sky=cpl_parameter_get_bool(p); + p=cpl_parameterlist_find(config,"sinfoni.objnod.ks_clip"); + ks_clip = cpl_parameter_get_bool(p); + p=cpl_parameterlist_find(config,"sinfoni.objnod.kappa"); + kappa = cpl_parameter_get_double(p); if(scales_sky == 1) { sinfo_msg("Subtract spatial sinfo_median to each cube plane"); @@ -396,10 +352,7 @@ } } - - /* AMO CHECK */ - - cknull(maskcube=cpl_imagelist_new(),"could not allocate cube!"); + maskcube=cpl_imagelist_new(); /* Illumination correction */ if(ill_cor != NULL) { @@ -415,7 +368,7 @@ if(ks_clip == 1) { sinfo_msg("Cube coaddition with kappa-sigma"); } - check_nomsg(onp=cpl_imagelist_get_size(cubeobject[0])); + onp=cpl_imagelist_get_size(cubeobject[0]); for(z=0;zsize_x, - cfg->size_y,CPL_TYPE_FLOAT)); - check_nomsg(cpl_imagelist_set(jittercube,j_img,j)); - check_nomsg(m_img = cpl_image_new(cfg->size_x, - cfg->size_y,CPL_TYPE_FLOAT)); - check_nomsg(cpl_imagelist_set(maskcube,m_img,j)); + j_img=cpl_image_new(cfg->size_x,cfg->size_y,CPL_TYPE_FLOAT); + cpl_imagelist_set(jittercube,j_img,j); + m_img = cpl_image_new(cfg->size_x,cfg->size_y,CPL_TYPE_FLOAT); + cpl_imagelist_set(maskcube,m_img,j); } if(ks_clip == 1) { sinfo_new_combine_jittered_cubes_thomas_range(cubeobject, - jittercube, - maskcube, - cfg->nframes, - offsetx,offsety, - times, - cfg->kernel_type, - z_min, - z_max, + jittercube,maskcube,cfg->nframes,offsetx, + offsety,times,cfg->kernel_type,z_min,z_max, kappa); } else { - sinfo_new_combine_jittered_cubes_range(cubeobject, - jittercube, - maskcube, - cfg->nframes, - offsetx, - offsety, - times, - cfg->kernel_type, - z_min, - z_max) ; + sinfo_new_combine_jittered_cubes_range(cubeobject,jittercube, + maskcube,cfg->nframes,offsetx,offsety, + times,cfg->kernel_type,z_min,z_max) ; } } sinfo_new_convert_0_to_ZERO_for_cubes(jittercube) ; @@ -476,27 +414,6 @@ } sinfo_free_array_imagelist(&cubeobject); - //Old setting - //newcenter_x = cfg->size_x / 2. + 0.5 ; - //newcenter_y = cfg->size_y / 2. + 0.5 ; - - - /* new setting */ - /* - sinfo_msg("offx_min=%f,offy_min=%f",offx_min,offy_min); - sinfo_msg("offx_max=%f,offy_max=%f",offx_max,offy_max); - sinfo_msg("ref_offx=%f,ref_offy=%f",ref_offx,ref_offy); - - newcenter_x=2*floor(fabs(offx_min)+0.5)+32+8; - newcenter_y=-2*floor(fabs(offy_max)+0.5)+32-2; - - - newcenter_x=cfg->size_x / 2. -offsetx[0]; - newcenter_y=cfg->size_y / 2. -offsety[0]; - */ - - - if (mjd_obs > 53825. ) { /* April 1st 2006 */ newcenter_x=cfg->size_x / 2. +2*ref_offx; @@ -511,39 +428,26 @@ newcenter_y=cfg->size_y / 2. -2*ref_offy; } - - //sinfo_msg("CRPIX=%f,%f", newcenter_x, newcenter_y); - //newcenter_x=2*floor(fabs(ref_offx)+0.5); - //newcenter_y=-2*floor(fabs(ref_offy)+0.5); - //sinfo_msg_warning("Center image: %f %f",newcenter_x,newcenter_y); - cknull_nomsg(qclog = sinfo_qclog_init()); + qclog = sinfo_qclog_init(); plist=cpl_propertylist_load(file_name,0); if(sinfo_baryvel(plist, &barycor,&helicor) != CPL_ERROR_NONE) { sinfo_msg_warning("Could not compute velocity corrections"); cpl_error_reset(); } else { - check_nomsg(sinfo_qclog_add_double(qclog, - "QC VRAD BARYCOR", - barycor, - "Barycentric radial velocity correction ", - "%13.6f")); - - check_nomsg(sinfo_qclog_add_double(qclog, - "QC VRAD HELICOR", - helicor, - "Heliocentric radial velocity correction ", - "%13.6f")); + sinfo_qclog_add_double_format(qclog,"QC VRAD BARYCOR",barycor, + "Barycentric radial velocity correction "); + + sinfo_qclog_add_double_format(qclog,"QC VRAD HELICOR",helicor, + "Heliocentric radial velocity correction "); sinfo_msg("Barycor=%g Helicor=%g",barycor,helicor); sinfo_free_propertylist(&plist); } - ck0(sinfo_pro_save_ims(jittercube,sof,sof,cfg->outName, - procatg,qclog,plugin_id,config), - "cannot save cube %s", cfg->outName); - + sinfo_pro_save_ims(jittercube,sof,sof,cfg->outName,procatg,qclog, + plugin_id,config); sinfo_free_table(&qclog); /* we need to set again the following 3 */ @@ -552,41 +456,38 @@ centralLambda=sinfo_pfits_get_crval3(plist); centralpix=sinfo_pfits_get_crpix3(plist); sinfo_free_propertylist(&plist); - sinfo_new_set_wcs_cube(jittercube, cfg->outName, - centralLambda, dis, + sinfo_new_set_wcs_cube(jittercube, cfg->outName,centralLambda, dis, centralpix, newcenter_x, newcenter_y); - cknull(jitter_image = sinfo_new_median_cube(jittercube), - " could not do sinfo_medianCube()"); - cknull_nomsg(qclog = sinfo_qclog_init()); + jitter_image = sinfo_new_median_cube(jittercube); + qclog = sinfo_qclog_init(); update_bad_pixel_map(jitter_image); - check_nomsg(sinfo_qclog_add_double(qclog, - "QC FRMDIF MEANSTD", + sinfo_qclog_add_double_format(qclog,"QC FRMDIF MEANSTD", cpl_image_get_mean(jitter_image), - "mean of the collapesd cube", - "%13.6f")); - check_nomsg(sinfo_qclog_add_double(qclog, - "QC FRMDIF STDEV", + "mean of the collapesd cube"); + sinfo_qclog_add_double_format(qclog,"QC FRMDIF STDEV", cpl_image_get_stdev(jitter_image), - "standard deviation of the collapesd cube", - "%13.6f")); - ck0(sinfo_pro_save_ima(jitter_image,sof,sof,cfg->med_cube_name, - pro_med,qclog,plugin_id,config), - "cannot save ima %s", cfg->outName); + "standard deviation of the collapesd cube"); + sinfo_pro_save_ima(jitter_image,sof,sof,cfg->med_cube_name,pro_med, + qclog,plugin_id,config); + sinfo_free_table(&qclog); + + if( sinfo_can_flux_calibrate(sof) ) { + sinfo_flux_calibrate_cube(procatg, plugin_id, config, sof, sof); + } + sinfo_new_set_wcs_image(jitter_image, cfg->med_cube_name, newcenter_x,newcenter_y); sinfo_free_image(&jitter_image); - ck0(sinfo_pro_save_ims(maskcube,sof,sof,cfg->maskname, - pro_mjit,NULL,plugin_id,config), - "cannot save cube %s", cfg->maskname); - - sinfo_new_set_wcs_cube(maskcube, cfg->maskname, - centralLambda, dis, centralpix, - newcenter_x, newcenter_y); + sinfo_pro_save_ims(maskcube,sof,sof,cfg->maskname,pro_mjit,NULL, + plugin_id,config); + + sinfo_new_set_wcs_cube(maskcube, cfg->maskname,centralLambda, dis, + centralpix,newcenter_x, newcenter_y); sinfo_free_double(×) ; sinfo_free_float(&offsetx) ; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_dark.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_dark.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_dark.c 2013-12-31 11:06:56.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_dark.c 2017-09-28 19:08:09.000000000 +0000 @@ -325,20 +325,20 @@ /* QC LOG */ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED AVE", - qc_darkmed_ave,"Average of raw darks medians","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC DARKMED AVE", + qc_darkmed_ave,"Average of raw darks medians")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKMED STDEV", - qc_darkmed_stdev,"STDEV of raw darks medians","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC DARKMED STDEV", + qc_darkmed_stdev,"STDEV of raw darks medians")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RON", - qc_ron_val,"Read Out Noise","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC RON", + qc_ron_val,"Read Out Noise")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC RONRMS", - qc_ron_err,"RMS on Read Out Noise","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC RONRMS", + qc_ron_err,"RMS on Read Out Noise")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC DARKFPN", - fpn,"Fixed Pattern Noise of combined frames","%g")); + fpn,"Fixed Pattern Noise of combined frames")); /* special way to calculate RON: for each couple */ @@ -406,7 +406,7 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1, - "A description","%d")); + "A description")); ck0(sinfo_pro_save_ima(image,raw,sof,dark_name, PRO_MASTER_DARK,qclog_tbl,plugin_id,config), @@ -443,7 +443,7 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1, - "A description","%d")); + "A description")); ck0(sinfo_pro_save_ima(eclipse_image,raw,sof,dark_name, PRO_MASTER_DARK,qclog_tbl,plugin_id,config), @@ -480,7 +480,7 @@ sinfo_msg("dark_name-%s\n",dark_name); cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1, - "A description","%d")); + "A description")); ck0(sinfo_pro_save_ima(image,raw,sof,dark_name, PRO_MASTER_DARK,qclog_tbl,plugin_id,config), @@ -512,7 +512,7 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1, - "A description","%d")); + "A description")); ck0(sinfo_pro_save_ima(image,raw,sof,dark_name, PRO_MASTER_DARK,qclog_tbl,plugin_id,config), @@ -542,7 +542,7 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NAME",1, - "A description","%d")); + "A description")); ck0(sinfo_pro_save_ima(image,raw,sof,dark_name, PRO_MASTER_DARK,qclog_tbl,plugin_id,config), @@ -638,8 +638,8 @@ /* Write QC LOG */ snprintf(key_name,MAX_NAME_SIZE-1,"%s%d","QC RON",i+1); - sinfo_qclog_add_double(qclog_tbl,key_name,ron[i], - "Read Out Noise","%f"); + sinfo_qclog_add_double_f(qclog_tbl,key_name,ron[i], + "Read Out Noise"); } diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_find_distortions.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_find_distortions.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_find_distortions.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_find_distortions.c 2017-09-28 14:49:24.000000000 +0000 @@ -608,54 +608,54 @@ check_nomsg(qclog_tbl = sinfo_qclog_init()); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,0); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][0], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",1,0); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][0], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,1); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][1], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",1,1); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][1], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",2,0); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[2][0], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,2); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][2], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",2,1); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[2][1], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",1,2); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[1][2], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",3,0); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[3][0], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%d","QC COEFF",0,3); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,pcf[0][3], - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); snprintf(key_name,MAX_NAME_SIZE-1,"%s","QC OFFSET"); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,value, - "Polynomial distortion coefficient","%g")); + "Polynomial distortion coefficient")); xshift=new_compute_shift(x_c,y_c,pcf[0][0],pcf[1][0],pcf[0][1], pcf[1][1],pcf[2][0],pcf[0][2], pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT CC",xshift, - "X shift in x_c,y_c","%g")); + "X shift in x_c,y_c")); xshift=new_compute_shift(x_l,y_l,pcf[0][0],pcf[1][0],pcf[0][1], @@ -663,21 +663,21 @@ pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT LL",xshift, - "X shift in x_l,y_l","%g")); + "X shift in x_l,y_l")); xshift=new_compute_shift(x_l,y_u,pcf[0][0],pcf[1][0],pcf[0][1], pcf[1][1],pcf[2][0],pcf[0][2], pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT UL",xshift, - "X shift in x_l,y_u","%g")); + "X shift in x_l,y_u")); xshift=new_compute_shift(x_u,y_u,pcf[0][0],pcf[1][0],pcf[0][1], pcf[1][1],pcf[2][0],pcf[0][2], pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT UR",xshift, - "X shift in x_u,y_u","%g")); + "X shift in x_u,y_u")); xshift=new_compute_shift(x_u,y_l,pcf[0][0],pcf[1][0],pcf[0][1], @@ -685,7 +685,7 @@ pcf[2][1],pcf[1][2],pcf[3][0],pcf[0][3]); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC XSHIFT LR",xshift, - "X shift in x_u,y_l","%g")); + "X shift in x_u,y_l")); ck0(sinfo_pro_save_tbl(poly_tbl,set_fibre_ns,sof,cfg->outName, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_lamp_flats.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_lamp_flats.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_lamp_flats.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_lamp_flats.c 2017-09-28 19:08:09.000000000 +0000 @@ -481,7 +481,7 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_badpixels, - "No of bad pixels","%d")); + "No of bad pixels")); ck0(sinfo_pro_save_ima(maskImage,ref_set,sof,cfg->maskname, PRO_BP_MAP,qclog_tbl,plugin_id,config), @@ -653,24 +653,22 @@ ck0(new_lamp_flats_det_ncounts(raw,cfg),"error computing number of counts"); cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSAVG", - qc_lampflat.avg_di,"Average counts","%g")); + qc_lampflat.avg_di,"Average counts")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSSTD", - qc_lampflat.std_di,"Stdev counts","%g")); + qc_lampflat.std_di,"Stdev counts")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT OFFFLUX", qc_lampflat.avg_of, - "Average flux off frames","%g")); + "Average flux off frames")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl, + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl, "QC LFLAT FPN1", fpn_stdev1, - "Fixed Pattern Noise of combined frames", - "%f")); + "Fixed Pattern Noise of combined frames")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl, + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl, "QC LFLAT FPN2", fpn_stdev2, - "Fixed Pattern Noise of combined frames", - "%f")); + "Fixed Pattern Noise of combined frames")); ck0(sinfo_pro_save_ima(im_obj,ref_set,sof,cfg->outName, PRO_MASTER_FLAT_LAMP,qclog_tbl,plugin_id,config), @@ -757,19 +755,19 @@ ck0(new_lamp_flats_det_ncounts(raw,cfg),"error computing ncounts"); cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSAVG", - qc_lampflat.avg_di,"Average counts","%g")); + qc_lampflat.avg_di,"Average counts")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT NCNTSSTD", - qc_lampflat.std_di,"Stdev counts","%g")); + qc_lampflat.std_di,"Stdev counts")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SPECFLAT OFFFLUX", - qc_lampflat.avg_of,"Average flux off frames","%g")); + qc_lampflat.avg_of,"Average flux off frames")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC LFLAT FPN1",fpn_stdev1, - "Fixed Pattern Noise of combined frames","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC LFLAT FPN1",fpn_stdev1, + "Fixed Pattern Noise of combined frames")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC LFLAT FPN2",fpn_stdev2, - "Fixed Pattern Noise of combined frames","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC LFLAT FPN2",fpn_stdev2, + "Fixed Pattern Noise of combined frames")); ck0(sinfo_pro_save_ima(im_dither,ref_set,sof,outNameDither, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_objnod.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_objnod.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_objnod.c 2015-08-21 08:19:09.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_objnod.c 2017-09-23 08:23:45.000000000 +0000 @@ -43,7 +43,7 @@ #include "sinfo_cube_construct.h" #include "sinfo_error.h" #include "sinfo_utils_wrappers.h" - +#include /*---------------------------------------------------------------------------- Defines ---------------------------------------------------------------------------*/ @@ -219,7 +219,8 @@ if (cfg->jitterind == 0) { - if ( NULL != (partname = strtok(cfg->outName, "."))) + + if ( NULL != (partname = strtok(cfg->outName, "."))) { /* partname2 = strtok (NULL, ".") ;*/ /* partind = 1 ; */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_prepare_stacked_frames.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_prepare_stacked_frames.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_prepare_stacked_frames.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_prepare_stacked_frames.c 2017-09-28 19:12:04.000000000 +0000 @@ -91,10 +91,10 @@ ---------------------------------------------------------------------------*/ static int -new_get_names(const char* pcatg, const int ind, stack_config_n ** cfg); +sinfo_def_product_names(const char* pcatg, const int ind, stack_config_n ** cfg); static int -new_get_names(const char* pcatg, const int ind, stack_config_n ** cfg){ +sinfo_def_product_names(const char* pcatg, const int ind, stack_config_n ** cfg){ if (strcmp(pcatg,PRO_FIBRE_NS_STACKED_OFF) == 0) { strcpy((*cfg)->outName,DISTORTION_STACK_OFF_OUT_FILENAME); @@ -195,13 +195,12 @@ sinfo_flat_field(int mflat_norm_smooth, int smooth_rad, int pdensity, const int frm_ind, const char* plugin_id, cpl_image** flat1, stack_config_n* cfg, cpl_image** flat_smooth, - cpl_image** im_obj_flat, cpl_image** im_obj, - cpl_frameset* raw, cpl_frameset* sof, + cpl_image** im_obj, cpl_frameset* raw, cpl_frameset* sof, cpl_parameterlist* config, cpl_image** flat2, cpl_image** im_dither) { /* do flat field */ - + cpl_image * im_obj_flat=NULL ; sinfo_msg("Flatfielding"); *flat1 = cpl_image_load(cfg->flatfield1, CPL_TYPE_FLOAT, 0, 0); if (mflat_norm_smooth) { @@ -211,7 +210,7 @@ sinfo_free_image(flat_smooth); } - *im_obj_flat = sinfo_new_div_images_robust(*im_obj, *flat1); + im_obj_flat = sinfo_new_div_images_robust(*im_obj, *flat1); /* AMO ** */ if (pdensity > 1) { @@ -232,8 +231,8 @@ sinfo_free_image(flat1); sinfo_free_image(im_obj); - *im_obj = cpl_image_duplicate(*im_obj_flat); - sinfo_free_image(im_obj_flat); + *im_obj = cpl_image_duplicate(im_obj_flat); + sinfo_free_image(&im_obj_flat); if (pdensity > 1) { if (cfg->contains_dither == 1) { *flat2 = cpl_image_load(cfg->flatfield2, CPL_TYPE_FLOAT, 0, 0); @@ -283,7 +282,7 @@ cpl_image* int_im=NULL; cpl_image* int_im_dith=NULL; float** slit_edges=NULL; - char file_name[MAX_NAME_SIZE]; + int status = 0; mask_im = cpl_image_load(cfg->mask, CPL_TYPE_FLOAT, 0, 0); @@ -291,6 +290,7 @@ if (cfg->indind == 0) { /* open the ASCII list of the slitlet positions */ /*READ TFITS TABLE*/ + char file_name[MAX_NAME_SIZE]; strcpy(file_name, cfg->slitposList); cpl_table* tbl_slitpos = cpl_table_load(file_name, 1, 0); if (cpl_table_has_column(tbl_slitpos, "pos1") != 1) { @@ -383,6 +383,7 @@ for (i = 0; i < n; i++) { strcpy(*in_nam[i], cpl_table_get_string(tbl_index, "name", i)); } + sinfo_free_table(&tbl_index); cpl_imagelist* iCube = NULL; cpl_imagelist* jCube = NULL; @@ -470,12 +471,14 @@ if (cpl_table_has_column(tbl_slitpos, "pos1") != 1) { sinfo_msg_error("Column 'pos1' not found in %s table %s", PRO_SLIT_POS, file_name); + sinfo_free_image(&mask_im); return CPL_ERROR_ILLEGAL_INPUT; } if (cpl_table_has_column(tbl_slitpos, "pos2") != 1) { sinfo_msg_error("Column 'pos2' not found in %s table %s", PRO_SLIT_POS, file_name); + sinfo_free_image(&mask_im); return CPL_ERROR_ILLEGAL_INPUT; } @@ -527,6 +530,7 @@ else { sinfo_msg_error( "wrong name in index list or needed file not there!"); + sinfo_free_image(&mask_im); return CPL_ERROR_ILLEGAL_INPUT; } @@ -600,29 +604,28 @@ /* sinfo_det_ncounts(raw, cfg->qc_thresh_max); */ cpl_table* qclog_tbl = sinfo_qclog_init(); sinfo_qclog_add_double(qclog_tbl, "QC FRMON MEANFLUX", - qc->avg_on, "Average of flux", "%g"); + qc->avg_on, "Average of flux"); /* ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FRMON MEANFLUX", - qc->avg_on,"Average of flux","%g"));*/ + qc->avg_on,"Average of flux"));*/ sinfo_qclog_add_double(qclog_tbl, "QC FRMOFF MEANFLUX", - qc->avg_of, "Average of flux", "%g"); + qc->avg_of, "Average of flux"); sinfo_qclog_add_double(qclog_tbl, "QC FRMDIF MEANFLUX", - qc->avg_di, "Average of flux", "%g"); + qc->avg_di, "Average of flux"); sinfo_qclog_add_double(qclog_tbl, "QC FRMON MAXFLUX", - qc->max_on, "Max of flux", "%g"); + qc->max_on, "Max of flux"); sinfo_qclog_add_double(qclog_tbl, "QC FRMOFF MAXFLUX", - qc->max_of, "Max of flux", "%g"); + qc->max_of, "Max of flux"); sinfo_qclog_add_double(qclog_tbl, "QC FRMDIF MAXFLUX", - qc->max_di, "Max of flux", "%g"); + qc->max_di, "Max of flux"); sinfo_qclog_add_int(qclog_tbl, "QC FRMON NPIXSAT", qc->nsat, - "Number of saturated pixels", "%d"); + "Number of saturated pixels"); update_bad_pixel_map(im_obj); - sinfo_qclog_add_double(qclog_tbl, "QC FRMDIF MEANSTD", + sinfo_qclog_add_double_format(qclog_tbl, "QC FRMDIF MEANSTD", cpl_image_get_mean(im_obj), - "mean of the image", "%13.6f"); - sinfo_qclog_add_double(qclog_tbl, "QC FRMDIF STDEV", + "mean of the image"); + sinfo_qclog_add_double_format(qclog_tbl, "QC FRMDIF STDEV", cpl_image_get_stdev(im_obj), - "standard deviation of the image", - "%13.6f"); + "standard deviation of the image"); return qclog_tbl; @@ -635,7 +638,7 @@ cpl_parameterlist* config, stack_config_n* cfg) { - char file_name[MAX_NAME_SIZE]; + cpl_frame* sky_frame = cpl_frameset_get_frame(raw,i); char* sky_name = (char* ) cpl_frame_get_filename(sky_frame); /* check_nomsg(sky_tag = (char*) cpl_frame_get_tag(sky_frame)); */ @@ -681,6 +684,7 @@ /* if (frm_ind == 0) { */ if (cfg->warpfixInd == 1) { sinfo_msg("Correct sky for distortions"); + char file_name[MAX_NAME_SIZE]; snprintf(file_name, MAX_NAME_SIZE - 1, "%s%d%s", STACK_SKY_DIST_OUT_FILENAME, frm_ind, ".fits"); cpl_image* sky_dist = sinfo_new_image_warp_fits(sky_img_flat, @@ -697,202 +701,454 @@ } return cpl_error_get_code(); } - -int sinfo_new_prepare_stacked_frames (const char* plugin_id, - cpl_parameterlist* config, - cpl_frameset* sof, - cpl_frameset* ref_set, - const char* frm_pro_ctg, - const int frm_ind, - fake* fk) +static cpl_error_code +sinfo_set_variables_from_parameters(cpl_parameterlist* config, + int* mflat_norm_smooth, int* smooth_rad, + int* sub_raw_sky, int* pdensity) { + /* + ----------------------------------------------------------------- + 1) parse the file names and parameters to the psf_config data + structure cfg + ----------------------------------------------------------------- + */ + cpl_parameter* p; + p = cpl_parameterlist_find(config, "sinfoni.product.density"); + *pdensity = cpl_parameter_get_int(p); - stack_config_n * cfg =NULL; - cpl_imagelist * list_object=NULL ; - cpl_imagelist * list_dither_object=NULL; - cpl_imagelist * list_dither_sky=NULL; - cpl_imagelist * list_sky=NULL; - cpl_imagelist * list_dark=NULL; + p = cpl_parameterlist_find(config,"sinfoni.stacked.mflat_norm_smooth"); + *mflat_norm_smooth = cpl_parameter_get_int(p); - cpl_image * ref_im1=NULL ; - cpl_image * ref_im2=NULL ; - cpl_image ** im=NULL ; - cpl_image * im_obj=NULL ; + p = cpl_parameterlist_find(config,"sinfoni.stacked.mflat_smooth_rad"); + *smooth_rad = cpl_parameter_get_int(p); - cpl_image * im_dark=NULL ; - cpl_image * im_sky=NULL ; - cpl_image * im_dither=NULL ; - cpl_image * im_dither_sky=NULL ; - cpl_image * im_obj_flat=NULL ; - cpl_image * int_im_shifted=NULL ; - cpl_image * int_im_dith_shifted=NULL ; - cpl_image * im_conv=NULL ; + p = cpl_parameterlist_find(config,"sinfoni.stacked.sub_raw_sky"); + *sub_raw_sky = cpl_parameter_get_bool(p); - cpl_image * mask_im=NULL ; - cpl_image * flat_smooth=NULL ; - cpl_image * flat1=NULL ; - cpl_image * flat2=NULL ; + return cpl_error_get_code(); - cpl_image * sky_img_flat=NULL; - cpl_image * sky_dist=NULL; +} - cpl_image* sky_img=NULL; - cpl_image* mdark=NULL; - char* name=NULL; - int typ=0; - int pos=0; - int i = 0; - int cnt = 0 ; - float val_x=0; - float val_y=0; +static cpl_error_code +sinfo_check_configuration(stack_config_n* cfg) +{ + if (cfg->flatInd == 1) { + if (sinfo_is_fits_file(cfg->flatfield1) != 1) { + sinfo_msg_error("Input FF file %s is not FITS", cfg->flatfield1); + cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT); + } + } + if (cfg->maskInd == 1) { + if (sinfo_is_fits_file(cfg->mask) != 1) { + sinfo_msg_error("Input mask file %s is not FITS", cfg->mask); + cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT); + } + if (cfg->indind == 0) { + if (sinfo_is_fits_file(cfg->slitposList) != 1) { + sinfo_msg_error("Input slitpos file %s is not FITS", + cfg->slitposList); + cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT); + } + } + } + if (cfg->sfInd == 1) { + if (cfg->contains_dark == 0) { + sinfo_msg_warning("no sinfo_dark frames given!"); + } + if (cfg->contains_ref == 0) { + sinfo_msg_error("no reference frames given!"); + cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT); + } + } + if (cfg->contains_dither == 0 && cfg->nditheroff > 0) { + sinfo_msg_error("please use non-dithered off-frames, remove the 2!"); + cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT); + } + return cpl_error_get_code(); +} +static cpl_error_code +sinfo_allocate_memory_for_lists(stack_config_n* cfg, cpl_imagelist** list_object, + cpl_imagelist** list_dither_object, + cpl_imagelist** list_sky, + cpl_imagelist** list_dither_sky, + cpl_imagelist** list_dark) +{ - float** slit_edges=NULL; + /* allocate memory for lists of object, sky and dithered frames */ + *list_object = cpl_imagelist_new(); + if (cfg->contains_dither == 1) { + *list_dither_object = cpl_imagelist_new(); + } + if (cfg->contains_sky == 1) { + *list_sky = cpl_imagelist_new(); + } + if (cfg->contains_dither == 1 && cfg->nditheroff > 0) { + *list_dither_sky = cpl_imagelist_new(); + } + if (cfg->contains_dark == 1 && cfg->sfInd == 1) { + *list_dark = cpl_imagelist_new(); + } + + return cpl_error_get_code(); + +} + +static cpl_error_code +sinfo_fill_lists( int pdensity,const char* plugin_id,const char* frm_pro_ctg, + int mflat_norm_smooth, int smooth_rad, stack_config_n* cfg, + cpl_image** im, + cpl_imagelist* list_object, cpl_imagelist* list_sky, fake* fk, + const int frm_ind, cpl_image** sky_img, cpl_frameset* raw, + cpl_frameset* sof, cpl_parameterlist* config, + cpl_imagelist* list_dark, int* nob, int* nsky,int* nda, cpl_image** ref_im1, + cpl_imagelist* list_dither_object, int* nobjdith, + int* nskydith, cpl_image** ref_im2) +{ + /* up to here leak free */ + /* rhead=0; */ - int nob = 0; - int nsky = 0; - int nobjdith = 0; - int nskydith = 0; - int nda = 0; - char name_list[MAX_NAME_SIZE]; char fake_sky_name[MAX_NAME_SIZE]; - int no=0; - float lo_cut=0; - float hi_cut=0; + for (int i = 0; i < cfg->nframes; i++) { + int typ = sinfo_new_intarray_get_value(cfg->frametype, i); + int pos = sinfo_new_intarray_get_value(cfg->frameposition, i); - cpl_imagelist* list_object_tmp=NULL; - cpl_imagelist* list_dither_object_tmp=NULL; - cpl_imagelist* list_sky_tmp=NULL; - cpl_imagelist* list_dither_sky_tmp=NULL; - cpl_frameset* raw=NULL; + if (pos == 2) { + if (typ == 1) { + cpl_imagelist_set(list_object,cpl_image_duplicate(im[i]),*nob); + *nob = *nob + 1; + } + else if (typ == 0) { + cpl_imagelist_set(list_sky,cpl_image_duplicate(im[i]),*nsky); + *nsky = *nsky + 1; + if (pdensity > 0) { + if (fk->is_fake_sky == 1) { + snprintf(fake_sky_name, MAX_NAME_SIZE - 1, "%s%d%s", + "out_fake_sky", frm_ind, ".fits"); + *sky_img = cpl_image_load(fake_sky_name, CPL_TYPE_FLOAT, + 0, 0); + sinfo_pro_save_ima(*sky_img,raw,sof,fake_sky_name, + PRO_SKY_DUMMY,NULL, plugin_id,config); - cpl_table* tbl_index = NULL; - cpl_table* tbl_slitpos=NULL; - /* int rhead=0; */ + sinfo_free_image(sky_img); + } + } - /* char* sky_tag = NULL; */ - qc_wcal* qc=sinfo_qc_wcal_new(); + if ((pdensity == 3) || (pdensity == 1) + || (pdensity == 2 && frm_ind == 0)) { - cpl_parameter* p=NULL; - int pdensity=0; - int mflat_norm_smooth=FALSE; + sinfo_special_case(i, frm_pro_ctg, plugin_id, + mflat_norm_smooth, smooth_rad, raw, frm_ind, + sof, config, cfg); + } + } + else if (typ == 5) { + if (cfg->sfInd == 1) { + cpl_imagelist_set(list_dark,cpl_image_duplicate(im[i]),*nda); + *nda = *nda + 1; + } + else { + sinfo_free_image(&(im[i])); + } + } + else if (typ == 4) { + if (cfg->sfInd == 1) { + *ref_im1 = im[i]; + } + else { + sinfo_free_image(&(im[i])); + } + } + } + else { + if (typ == 1) { + cpl_imagelist_set(list_dither_object,cpl_image_duplicate(im[i]), + *nobjdith); + *nobjdith = *nobjdith + 1; + } + else if (typ == 0) { + cpl_imagelist_set(list_dither_object,cpl_image_duplicate(im[i]), + *nskydith); + *nskydith = *nskydith + 1; + } + else if (typ == 4) { + if (cfg->sfInd == 1) { + *ref_im2 = cpl_image_duplicate(im[i]); + } + else { + sinfo_free_image(&(im[i])); + } + } + } + } + return cpl_error_get_code(); +} +static cpl_error_code +sinfo_shift_along_wave(stack_config_n* cfg, cpl_image* im_dark, + cpl_imagelist* list_dark, cpl_imagelist** list_object, + cpl_image* ref_im1, cpl_imagelist** list_dither_object, + cpl_image* ref_im2, cpl_imagelist** list_sky, + cpl_imagelist** list_dither_sky) +{ - int smooth_rad=16; - int sub_raw_sky=1; + cpl_imagelist* list_object_tmp=NULL; + cpl_imagelist* list_dither_object_tmp=NULL; + cpl_imagelist* list_sky_tmp=NULL; + cpl_imagelist* list_dither_sky_tmp = NULL; /* - ----------------------------------------------------------------- - 1) parse the file names and parameters to the psf_config data - structure cfg - ----------------------------------------------------------------- + first take the mean of the sinfo_dark frames and subtract the result + from all cubes */ + sinfo_msg("Shift cube images in spectral direction with " + "respect to reference"); + if (cfg->contains_dark == 1) { + sinfo_msg("cfg->contains_dark == 1"); + if (cfg->loReject * cfg->ndark < 1. + && cfg->hiReject * cfg->ndark < 1.) { + /* + im_dark = sinfo_new_average_cube_to_image( list_dark ); + */ + im_dark = cpl_imagelist_collapse_create(list_dark); + } + else { + int no = cpl_imagelist_get_size(list_dark); + float lo_cut = (floor)(cfg->loReject * no + 0.5); + float hi_cut = (floor)(cfg->hiReject * no + 0.5); + im_dark = cpl_imagelist_collapse_minmax_create(list_dark, lo_cut, + hi_cut); - check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.product.density")); - check_nomsg(pdensity=cpl_parameter_get_int(p)); + } + sinfo_free_imagelist(&list_dark); + list_object_tmp = cpl_imagelist_duplicate(*list_object); + cpl_imagelist_subtract_image(list_object_tmp, im_dark); + /* + cube_object_tmp = sinfo_subImageFromCube (cube_object, im_dark); + */ + } + else { + sinfo_msg("cfg->contains_dark == 0"); + list_object_tmp = cpl_imagelist_duplicate(*list_object); + } + sinfo_free_imagelist(list_object); + *list_object = sinfo_align_cube_to_reference(list_object_tmp, + ref_im1, cfg->sfOrder, cfg->sfType); + sinfo_free_imagelist(&list_object_tmp); + if (cfg->contains_dither == 1) { + if (cfg->contains_dark == 1) { + list_dither_object_tmp = cpl_imagelist_duplicate( + *list_dither_object); + cpl_imagelist_subtract_image(list_dither_object_tmp, im_dark); + /* + list_dither_object_tmp = + sinfo_new_sub_image_from_cube(list_dither_object, + im_dark); + */ - check_nomsg(p=cpl_parameterlist_find(config, - "sinfoni.stacked.mflat_norm_smooth")); - check_nomsg(mflat_norm_smooth=cpl_parameter_get_int(p)); + } + else { + list_dither_object_tmp = cpl_imagelist_duplicate(*list_dither_object); + } + sinfo_free_imagelist(list_dither_object); + *list_dither_object = sinfo_align_cube_to_reference( + list_dither_object_tmp, ref_im2, + cfg->sfOrder, cfg->sfType); + sinfo_free_imagelist(&list_dither_object_tmp); + } + if (cfg->contains_sky == 1) { + if (cfg->contains_dark == 1) { + list_sky_tmp = cpl_imagelist_duplicate(*list_sky); + cpl_imagelist_subtract_image(list_sky_tmp, im_dark); + /* + cube_sky_tmp = sinfo_subImageFromCube (cube_sky, im_dark); + */ - check_nomsg(p=cpl_parameterlist_find(config, - "sinfoni.stacked.mflat_smooth_rad")); - check_nomsg(smooth_rad=cpl_parameter_get_int(p)); + } + else { + list_sky_tmp = cpl_imagelist_duplicate(*list_sky); + } + //list_sky_tmp = cpl_imagelist_duplicate(*list_sky); + + *list_sky = sinfo_align_cube_to_reference(list_sky_tmp, + ref_im1, cfg->sfOrder, cfg->sfType); - check_nomsg(p=cpl_parameterlist_find(config,"sinfoni.stacked.sub_raw_sky")); - check_nomsg(sub_raw_sky=cpl_parameter_get_bool(p)); + sinfo_free_imagelist(&list_sky_tmp); + } + if (cfg->contains_dither == 1 && cfg->contains_sky == 1) { + if (cfg->contains_dark == 1) { + list_dither_sky_tmp = cpl_imagelist_duplicate(*list_dither_sky); + cpl_imagelist_subtract_image(list_dither_sky_tmp, im_dark); + /* + cube_dither_sky_tmp = sinfo_subImageFromCube (cube_dither_sky, im_dark); + */ + + } + else { + list_dither_sky_tmp = cpl_imagelist_duplicate(*list_dither_sky); + } + sinfo_free_imagelist(list_dither_sky); + *list_dither_sky = sinfo_align_cube_to_reference( + list_dither_sky_tmp, ref_im2, + cfg->sfOrder, cfg->sfType); - check_nomsg(raw=cpl_frameset_new()); - cknull(cfg = sinfo_parse_cpl_input_stack(config,sof,&raw, fk), - "could not parse cpl input file!") ; + sinfo_free_imagelist(&list_dither_sky_tmp); + } + sinfo_free_image(&ref_im1); + if (cfg->contains_dither == 1) { + sinfo_free_image(&ref_im2); + } + if (cfg->contains_dark == 1) { + sinfo_free_image(&im_dark); + } + return cpl_error_get_code(); - ck0(sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc),"computing det ncounts"); +} +static cpl_error_code +sinfo_average_cubes(int nsky, int nobjdith,int nskydith, stack_config_n* cfg, + cpl_image** im_obj,cpl_imagelist** list_object, + cpl_image** im_sky,cpl_imagelist** list_sky, + cpl_image** im_dither,cpl_imagelist* list_dither_object, + cpl_image** im_dither_sky, cpl_imagelist* list_dither_sky) +{ - if(ref_set != NULL) { - sinfo_free_frameset(&raw); - raw=cpl_frameset_duplicate(ref_set); + int no; + float lo_cut; + float hi_cut; + if (cfg->loReject * cfg->nobj < 1. && cfg->hiReject * cfg->nobj < 1.) { + *im_obj = cpl_imagelist_collapse_create(*list_object); + } + else { + no = cpl_imagelist_get_size(*list_object); + lo_cut = (floor)(cfg->loReject * no + 0.5); + hi_cut = (floor)(cfg->hiReject * no + 0.5); + *im_obj = cpl_imagelist_collapse_minmax_create(*list_object, lo_cut, + hi_cut); } - /* defines output file name for stack set i */ - ck0_nomsg(new_get_names(frm_pro_ctg, frm_ind, &cfg)); - if (cfg->flatInd == 1){ - if(sinfo_is_fits_file(cfg->flatfield1) != 1) { - sinfo_msg_error("Input FF file %s is not FITS",cfg->flatfield1); - goto cleanup; + sinfo_free_imagelist(list_object); + if (cfg->contains_sky == 1) { + if (cfg->loReject * nsky < 1. && cfg->hiReject * nsky < 1.) { + /* here might explode in dither mode */ + *im_sky = cpl_imagelist_collapse_create(*list_sky); } + else { + no = cpl_imagelist_get_size(*list_sky); + lo_cut = (floor)(cfg->loReject * no + 0.5); + hi_cut = (floor)(cfg->hiReject * no + 0.5); + *im_sky = cpl_imagelist_collapse_minmax_create(*list_sky, lo_cut, + hi_cut); + } + sinfo_free_imagelist(list_sky); } - if (cfg->maskInd == 1) { - if(sinfo_is_fits_file(cfg->mask) != 1) { - sinfo_msg_error("Input mask file %s is not FITS",cfg->mask); - goto cleanup; + if (cfg->contains_dither == 1) { + if (cfg->loReject * nobjdith < 1. && cfg->hiReject * nobjdith < 1.) { + *im_dither = cpl_imagelist_collapse_create(list_dither_object); } - if(cfg -> indind == 0) { - if(sinfo_is_fits_file(cfg->slitposList) != 1) { - sinfo_msg_error("Input slitpos file %s is not FITS",cfg->slitposList); - goto cleanup; - } + else { + + no = cpl_imagelist_get_size(list_dither_object); + lo_cut = (floor)(cfg->loReject * no + 0.5); + hi_cut = (floor)(cfg->hiReject * no + 0.5); + *im_dither = cpl_imagelist_collapse_minmax_create( + list_dither_object, lo_cut, hi_cut); } + sinfo_free_imagelist(&list_dither_object); } - - /* - #--------------------------------------------------------- - # Take a clean mean of several images - # input is 1 or more similar images - #--------------------------------------------------------- - */ - - if (cfg->sfInd == 1){ - if (cfg->contains_dark == 0) { - sinfo_msg_warning("no sinfo_dark frames given!"); + if (cfg->contains_dither == 1 && nskydith > 0) { + if (cfg->loReject * nskydith < 1. && cfg->hiReject * nskydith < 1.) { + *im_dither_sky = cpl_imagelist_collapse_create(list_dither_sky); } - if (cfg->contains_ref == 0) { - sinfo_msg_error("no reference frames given!"); - goto cleanup; + else { + + no = cpl_imagelist_get_size(list_dither_sky); + lo_cut = (floor)(cfg->loReject * no + 0.5); + hi_cut = (floor)(cfg->hiReject * no + 0.5); + *im_dither_sky = cpl_imagelist_collapse_minmax_create( + list_dither_sky, + lo_cut, hi_cut); } + sinfo_free_imagelist(&list_dither_sky); } + return cpl_error_get_code(); - /* allocate memory for lists of object, sky and dithered frames */ - check(list_object=cpl_imagelist_new(), - "could not allocate memory for object frame"); +} - if (cfg->contains_dither == 1) { - check(list_dither_object=cpl_imagelist_new(), - "could not allocate memory for dither object frame"); - } +int sinfo_new_prepare_stacked_frames (const char* plugin_id, + cpl_parameterlist* config, + cpl_frameset* sof, + cpl_frameset* ref_set, + const char* frm_pro_ctg, + const int frm_ind, + fake* fk) +{ - if (cfg->contains_sky == 1) { - check(list_sky = cpl_imagelist_new(), - "could not allocate memory for off frame list"); - } + stack_config_n * cfg =NULL; + cpl_frameset* raw=NULL; + qc_wcal* qc=sinfo_qc_wcal_new(); - if (cfg->contains_dither == 1 && cfg->nditheroff > 0) { - check(list_dither_sky = cpl_imagelist_new(), - "could not allocate memory for dither frame list"); + int pdensity=0; + int mflat_norm_smooth=FALSE; + int smooth_rad=16; + int sub_raw_sky=1; + cpl_image * flat2=NULL ; + cpl_image * flat_smooth=NULL ; + cpl_image * flat1=NULL ; + cpl_image* im_obj_noflat=NULL; + cpl_image* im_dither_noflat=NULL; + cpl_image * mask_im=NULL ; + cpl_image * im_obj=NULL ; + cpl_image * im_sky=NULL ; + cpl_image * im_dither=NULL ; + cpl_image * im_dither_sky=NULL ; + cpl_imagelist * list_sky=NULL; + cpl_imagelist * list_object=NULL ; + cpl_image* sky_img=NULL; + + sinfo_set_variables_from_parameters(config,&mflat_norm_smooth, &smooth_rad, + &sub_raw_sky,&pdensity); + + + raw=cpl_frameset_new(); + cfg = sinfo_parse_cpl_input_stack(config,sof,&raw, fk); + sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc); + + if(ref_set != NULL) { + sinfo_free_frameset(&raw); + raw=cpl_frameset_duplicate(ref_set); } - if (cfg->contains_dark == 1 && cfg->sfInd == 1) { - check(list_dark = cpl_imagelist_new(), - "could not allocate memory for sinfo_dark frame"); + sinfo_def_product_names(frm_pro_ctg, frm_ind, &cfg); + + /* make consistency checks */ + if(CPL_ERROR_NONE != sinfo_check_configuration(cfg) ) { + goto cleanup; } + cpl_imagelist * list_dither_object=NULL; + cpl_imagelist * list_dither_sky=NULL; + cpl_imagelist * list_dark=NULL; + sinfo_allocate_memory_for_lists(cfg, &list_object, &list_dither_object, + &list_sky, &list_dither_sky,&list_dark); + if (cfg->contains_dither == 0 && cfg->nditheroff > 0) { sinfo_msg_error("please use non-dithered off-frames, remove the 2!"); goto cleanup; } /* build different image lists for the different cases */ - cknull_nomsg(im=(cpl_image**)cpl_calloc(cfg -> nframes, sizeof(cpl_image*))); - - for (i=0; i< cfg->nframes; i++) { + cpl_image ** im=(cpl_image**)cpl_calloc(cfg -> nframes, sizeof(cpl_image*)); + char* name=NULL; + for (int i=0; i< cfg->nframes; i++) { name = cfg->framelist[i]; if(sinfo_is_fits_file(name) != 1) { sinfo_msg_error("Input file %s is not FITS",name); @@ -902,78 +1158,21 @@ } /* up to here leak free */ - /* rhead=0; */ - for (i=0; i< cfg->nframes; i++) { - typ = sinfo_new_intarray_get_value( cfg->frametype, i ); - pos = sinfo_new_intarray_get_value( cfg->frameposition, i ); - cknull(im[i],"could not load image"); - - if (pos == 2) { - if (typ == 1) { - check_nomsg(cpl_imagelist_set(list_object, - cpl_image_duplicate(im[i]),nob)); - nob = nob + 1; - } - else if ( typ == 0 ) { - check_nomsg(cpl_imagelist_set(list_sky, - cpl_image_duplicate(im[i]),nsky)); - nsky = nsky + 1; - if(pdensity > 0) { - if(fk->is_fake_sky==1) { - snprintf(fake_sky_name,MAX_NAME_SIZE-1,"%s%d%s","out_fake_sky", - frm_ind,".fits"); - check_nomsg(sky_img=cpl_image_load(fake_sky_name,CPL_TYPE_FLOAT,0,0)); - ck0(sinfo_pro_save_ima(sky_img,raw,sof,fake_sky_name, - PRO_SKY_DUMMY,NULL, - plugin_id,config), - "cannot save sky ima %s", fake_sky_name); - - sinfo_free_image(&sky_img); - } - } - - - if((pdensity == 3) || (pdensity == 1) || - (pdensity == 2 && frm_ind == 0)) { - + cpl_image * ref_im1=NULL ; + cpl_image * ref_im2=NULL ; + int nob = 0; + int nsky = 0; + int nobjdith = 0; + int nskydith = 0; + int nda = 0; + sinfo_msg("Create and fill cubes with the different images"); + sinfo_fill_lists( pdensity,plugin_id, frm_pro_ctg, mflat_norm_smooth, smooth_rad, cfg, + im, list_object, list_sky, fk, frm_ind, &sky_img, raw, sof, + config, list_dark, &nob, &nsky,&nda, &ref_im1, list_dither_object, + &nobjdith, &nskydith, &ref_im2); - sinfo_special_case(i, frm_pro_ctg, plugin_id, - mflat_norm_smooth, smooth_rad, - raw, frm_ind, sof, config, cfg); - } - } else if ( typ == 5 ) { - if (cfg->sfInd == 1) { - check_nomsg(cpl_imagelist_set(list_dark, - cpl_image_duplicate(im[i]),nda)); - nda = nda + 1; - } else { - sinfo_free_image(&(im[i])); - } - } else if ( typ == 4 ) { - if ( cfg->sfInd == 1) { - ref_im1 = im[i]; - } else { - sinfo_free_image(&(im[i])); - } - } - } else { - if (typ == 1) { - check_nomsg(cpl_imagelist_set(list_dither_object, - cpl_image_duplicate(im[i]),nobjdith)); - nobjdith = nobjdith + 1; - } else if (typ == 0) { - check_nomsg(cpl_imagelist_set(list_dither_object, - cpl_image_duplicate(im[i]),nskydith)); - nskydith = nskydith + 1; - } else if (typ == 4) { - if (cfg->sfInd == 1) { - ref_im2 = cpl_image_duplicate(im[i]); - } else { - sinfo_free_image(&(im[i])); - } - } - } - } /* end for loop on i */ + /* create and fill cubes with the different image lists */ + cknull(list_object,"could not create object data cube!"); if (nob != cfg->nobj || cfg->noff != nsky || @@ -990,148 +1189,24 @@ sinfo_msg_error("something is wrong with the number of sinfo_dark frames"); goto cleanup; } - sinfo_msg("Create and fill cubes with the different images"); - /* create and fill cubes with the different image lists */ - cknull(list_object,"could not create object data cube!"); - - /* shift the images in the cubes-if indicated-in spectral direction - with respect to the reference image - */ + cpl_image * im_dark=NULL ; if (cfg->sfInd == 1) { /* - first take the mean of the sinfo_dark frames and subtract the result - from all cubes + if requested, shift the images in the cubes in wavelength direction + with respect to the reference image + first compute and subtract the mean of the dark frames from all cubes */ - sinfo_msg("Shift cube images in spectral direction with " - "respect to reference"); - - if (cfg->contains_dark == 1) { - sinfo_msg("cfg->contains_dark == 1"); - if (cfg->loReject*cfg->ndark < 1. && cfg->hiReject * cfg->ndark < 1.) { - /* - im_dark = sinfo_new_average_cube_to_image( list_dark ); - */ - check(im_dark = cpl_imagelist_collapse_create( list_dark ), - "sinfo_averageCubeToImage failed" ); - } - else { - - check_nomsg(no=cpl_imagelist_get_size(list_dark)); - lo_cut=(floor)( cfg->loReject*no+0.5); - hi_cut=(floor)( cfg->hiReject*no+0.5); - check(im_dark=cpl_imagelist_collapse_minmax_create(list_dark,lo_cut, - hi_cut), - "sinfo_average_with_rejection failed" ); - - } - sinfo_free_imagelist(&list_dark); - check_nomsg(list_object_tmp = cpl_imagelist_duplicate (list_object)); - check(cpl_imagelist_subtract_image (list_object_tmp, im_dark), - "cpl_imagelist_subtract_image failed" ); - /* - cube_object_tmp = sinfo_subImageFromCube (cube_object, im_dark); - */ - } else { - sinfo_msg("cfg->contains_dark == 0"); - check_nomsg(list_object_tmp = cpl_imagelist_duplicate(list_object)); - } - sinfo_free_imagelist(&list_object); - - cknull(list_object = sinfo_align_cube_to_reference (list_object_tmp, - ref_im1, - cfg->sfOrder, - cfg->sfType), - "sinfo_align_cube_to_reference failed" ); - - sinfo_free_imagelist(&list_object_tmp); - if (cfg->contains_dither == 1) { - if (cfg->contains_dark == 1) { - check_nomsg(list_dither_object_tmp = - cpl_imagelist_duplicate(list_dither_object)); - check(cpl_imagelist_subtract_image(list_dither_object_tmp,im_dark), - "sinfo_average_with_rejection failed" ); - - /* - list_dither_object_tmp = - sinfo_new_sub_image_from_cube(list_dither_object, - im_dark); - */ - - } else { - check_nomsg(list_dither_object_tmp= - cpl_imagelist_duplicate(list_dither_object)); - } - sinfo_free_imagelist(&list_dither_object); - - cknull(list_dither_object= - sinfo_align_cube_to_reference (list_dither_object_tmp, - ref_im2, - cfg->sfOrder, - cfg->sfType), - "sinfo_align_cube_to_reference failed" ); - - sinfo_free_imagelist(&list_dither_object_tmp); - } - if (cfg->contains_sky == 1) { - if (cfg->contains_dark == 1) { - check_nomsg(list_sky_tmp = cpl_imagelist_duplicate(list_sky)); - check(cpl_imagelist_subtract_image (list_sky_tmp, im_dark), - "sinfo_average_with_rejection failed" ); - /* - cube_sky_tmp = sinfo_subImageFromCube (cube_sky, im_dark); - */ - - } else { - check_nomsg(list_sky_tmp = cpl_imagelist_duplicate(list_sky)); - } - check_nomsg(list_sky_tmp=cpl_imagelist_duplicate(list_sky)); - - check(list_sky = sinfo_align_cube_to_reference (list_sky_tmp, - ref_im1, - cfg->sfOrder, - cfg->sfType), - "sinfo_alignCubeToReference failed" ); - - check_nomsg(cpl_imagelist_delete(list_sky_tmp)); - } - if (cfg->contains_dither == 1 && cfg->contains_sky == 1) { - if (cfg->contains_dark == 1) { - check_nomsg(list_dither_sky_tmp=cpl_imagelist_duplicate(list_dither_sky)); - check(cpl_imagelist_subtract_image(list_dither_sky_tmp,im_dark), - "sinfo_average_with_rejection failed" ); - /* - cube_dither_sky_tmp = sinfo_subImageFromCube (cube_dither_sky, im_dark); - */ - - } else { - check_nomsg(list_dither_sky_tmp=cpl_imagelist_duplicate(list_dither_sky)); - } - sinfo_free_imagelist(&list_dither_sky); - - check(list_dither_sky=sinfo_align_cube_to_reference(list_dither_sky_tmp, - ref_im2, - cfg->sfOrder, - cfg->sfType), - "sinfo_alignCubeToReference failed" ); - - sinfo_free_imagelist(&list_dither_sky_tmp); - } - sinfo_free_image(&ref_im1); - if (cfg->contains_dither == 1) { - sinfo_free_image(&ref_im2); - } - if (cfg->contains_dark == 1) { - sinfo_free_image(&im_dark); - } - - } /* end if over sfInd */ + sinfo_shift_along_wave(cfg, im_dark, list_dark, &list_object, ref_im1, + &list_dither_object, ref_im2, &list_sky, + &list_dither_sky); + } /* subtracts the master dark from different frames if present */ if(cfg->mdark_ind==1){ sinfo_msg("Subtract master dark %s ",cfg->mdark); - + cpl_image* mdark=NULL; check_nomsg(mdark=cpl_image_load(cfg->mdark,CPL_TYPE_FLOAT,0,0)); if (list_object !=NULL) { cpl_imagelist_subtract_image (list_object, mdark); @@ -1141,218 +1216,191 @@ } sinfo_free_image(&mdark); } - /* take the average with rejection of the different cubes */ - sinfo_msg("Take the average of the different cubes"); - if (cfg->loReject*cfg->nobj < 1. && cfg->hiReject * cfg->nobj < 1.) { - //sinfo_msg("ok0 %d",cpl_imagelist_get_size(list_object)); - check(im_obj = cpl_imagelist_collapse_create(list_object), - "Average with rejection failed" ); - } else { - //sinfo_msg("ok01"); - check_nomsg(no=cpl_imagelist_get_size(list_object)); - //sinfo_msg("ok02"); - lo_cut=(floor)( cfg->loReject*no+0.5); - hi_cut=(floor)( cfg->hiReject*no+0.5); - //sinfo_msg("ok03"); - check(im_obj=cpl_imagelist_collapse_minmax_create(list_object, - lo_cut,hi_cut),"Average with rejection failed" ); - //sinfo_msg("ok04"); - } - //sinfo_msg("ok1"); - sinfo_free_imagelist(&list_object); - if (cfg->contains_sky == 1) { - if (cfg->loReject*nsky < 1. && cfg->hiReject*nsky < 1.) { - /* here might explode in dither mode */ - cknull(im_sky = cpl_imagelist_collapse_create( list_sky ), - "Average with rejection failed"); - } else { - - check_nomsg(no=cpl_imagelist_get_size(list_sky)); - lo_cut=(floor)( cfg->loReject*no+0.5); - hi_cut=(floor)( cfg->hiReject*no+0.5); - check(im_sky=cpl_imagelist_collapse_minmax_create(list_sky,lo_cut,hi_cut), - "Average with rejection failed"); - } - sinfo_free_imagelist(&list_sky); - } - - if (cfg->contains_dither == 1) { - if (cfg->loReject*nobjdith < 1. && cfg->hiReject*nobjdith < 1.) { - check(im_dither = cpl_imagelist_collapse_create( list_dither_object ), - "Average with rejection failed"); - } else { - - check_nomsg(no=cpl_imagelist_get_size(list_dither_object)); - lo_cut=(floor)( cfg->loReject*no+0.5); - hi_cut=(floor)( cfg->hiReject*no+0.5); - check(im_dither=cpl_imagelist_collapse_minmax_create(list_dither_object, - lo_cut,hi_cut), - "Average with rejection failed"); + /* take the average with rejection of the different cubes */ + sinfo_msg("Take the average of the different cubes"); + sinfo_average_cubes(nsky, nobjdith, nskydith,cfg, &im_obj, &list_object, + &im_sky, &list_sky, &im_dither,list_dither_object, + &im_dither_sky, list_dither_sky); - } - sinfo_free_imagelist(&list_dither_object); - } - //sinfo_msg("ok2"); - if (cfg->contains_dither == 1 && nskydith > 0) { - if (cfg->loReject*nskydith < 1. && cfg->hiReject*nskydith < 1.) { - check(im_dither_sky = cpl_imagelist_collapse_create( list_dither_sky ), - "Average with rejection failed"); - } else { - - check_nomsg(no=cpl_imagelist_get_size(list_dither_sky)); - lo_cut=(floor)( cfg->loReject*no+0.5); - hi_cut=(floor)( cfg->hiReject*no+0.5); - check(im_dither_sky=cpl_imagelist_collapse_minmax_create(list_dither_sky, - lo_cut,hi_cut), - "Average with rejection failed"); - } - sinfo_free_imagelist(&list_dither_sky); - } - //sinfo_msg("ok3"); - /* - #--------------------------------------------------------- - # Subtract the resulting off-frame (sky) from the on-frame - #------------------------------------------------------- - # finally, subtract off from on frames and store the result - # in the object cube - */ + /* Compute on (object) - off (sky) frame and store result in object image */ if (sub_raw_sky == 1) { sinfo_subtract_raw_sky(nskydith, cfg, &im_obj, &im_sky, &im_dither, im_dither_sky); } - /* - #--------------------------------------------------------- - # Flatfielding - #--------------------------------------------------------- + + /* if input frame is STD star set a variable to be used later to create and + * use a frame not flat fielded */ + cpl_frame* frm_std=NULL; + int frm_is_std=0; + frm_std=cpl_frameset_find(sof,RAW_STD); + if(frm_std != NULL) { + frm_is_std=1; + } + + if(frm_is_std == 1) { + im_obj_noflat=cpl_image_duplicate(im_obj); + if(im_dither != NULL) { + im_dither_noflat=cpl_image_duplicate(im_dither); + } + } - if (cfg->flatInd == 1) { + if (cfg->flatInd == 1) { /* do flat field */ sinfo_flat_field(mflat_norm_smooth, smooth_rad, pdensity, - frm_ind, plugin_id, &flat1, cfg, &flat_smooth, - &im_obj_flat, &im_obj, raw, sof, config, - &flat2, &im_dither); + frm_ind, plugin_id, &flat1, cfg, &flat_smooth,&im_obj, + raw, sof, config, &flat2, &im_dither); } - /* - #--------------------------------------------------------- - # static bad pixel correction - #--------------------------------------------------------- - */ - - if (cfg->maskInd == 1) { - + float val_x=0; + float val_y=0; + int cnt = 0 ; + switch (cfg->maskInd) { + case 1: sinfo_mask_bad_pixels(val_x, val_y, mask_im, cfg, &im_obj, &im_dither); - - } - - /* - #--------------------------------------------------------- - # static bad pixel correction BEZIER - #--------------------------------------------------------- - */ - - if (cfg->maskInd == 2){ - + break; + case 2: sinfo_correct_bad_pixels_bezier(cnt,cfg, &im_obj, name, &im_dither); - } - - if (cfg->maskInd == 3) { - + break; + case 3: sinfo_correct_bad_pixels_bezier3(cnt, cfg, &im_obj, &im_dither); - + break; } + + if(frm_is_std == 1) { + switch (cfg->maskInd) { + case 1: + sinfo_mask_bad_pixels(val_x, val_y, mask_im, cfg, &im_obj_noflat, + &im_dither_noflat); + break; + case 2: + sinfo_correct_bad_pixels_bezier(cnt,cfg, &im_obj_noflat, name, + &im_dither_noflat); + break; + case 3: + sinfo_correct_bad_pixels_bezier3(cnt, cfg, &im_obj_noflat, + &im_dither_noflat); + break; + } + } - /* - #--------------------------------------------------------- - # correction of distortions - #--------------------------------------------------------- - */ - - /* here memory leak */ + /* correction of distortions */ sinfo_msg("cfg->warpfixInd=%d",cfg->warpfixInd); /* AMO forced this */ sinfo_msg("pro catg=%s",frm_pro_ctg); - /* - if(strcmp(frm_pro_ctg,PRO_WAVE_LAMP_STACKED) == 0) { - cfg->warpfixInd=0; - sinfo_msg("cfg->warpfixInd=%d",cfg->warpfixInd); - //exit(0); - } - */ - if (cfg->warpfixInd == 1){ /*#open ASCII file containing the slope parameter and read it*/ sinfo_msg("Correct object for distortions"); - //cpl_image_save(im_obj,"im_obj_before_dist.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); - cknull(int_im_shifted=sinfo_new_image_warp_fits(im_obj, - cfg->kernel, - cfg->polyFile), - "could not carry out sinfo_image_warp_fits" ); - + cpl_image * int_im_shifted=NULL ; + int_im_shifted=sinfo_new_image_warp_fits(im_obj, cfg->kernel, + cfg->polyFile); sinfo_free_image(&im_obj); im_obj = cpl_image_duplicate(int_im_shifted); - //cpl_image_save(im_obj,"im_obj_after_dist.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + sinfo_free_image(&int_im_shifted); + + if(frm_is_std == 1) { + cpl_image * int_im_shifted=NULL ; + int_im_shifted=sinfo_new_image_warp_fits(im_obj_noflat, cfg->kernel, + cfg->polyFile); + sinfo_free_image(&im_obj_noflat); + im_obj_noflat = cpl_image_duplicate(int_im_shifted); + sinfo_free_image(&int_im_shifted); + } + if (cfg->contains_dither == 1){ - cknull(int_im_dith_shifted=sinfo_new_image_warp_fits(im_dither, - cfg->kernel, - cfg->polyFile), - "could not carry out sinfo_image_warp_fits" ); + cpl_image * int_im_dith_shifted=NULL ; + int_im_dith_shifted=sinfo_new_image_warp_fits(im_dither,cfg->kernel, + cfg->polyFile); sinfo_free_image(&im_dither); im_dither = cpl_image_duplicate(int_im_dith_shifted); + sinfo_free_image(&int_im_dith_shifted); + if(frm_is_std == 1) { + int_im_dith_shifted=sinfo_new_image_warp_fits(im_dither_noflat, + cfg->kernel, cfg->polyFile); + sinfo_free_image(&im_dither_noflat); + im_dither_noflat = cpl_image_duplicate(int_im_dith_shifted); + sinfo_free_image(&int_im_dith_shifted); + } } } - /* - #--------------------------------------------------------- - # merge (interleave) both resulting frames - #--------------------------------------------------------- - */ + /* merge (interleave) both resulting frames */ if (cfg->interInd == 1 && cfg->contains_dither == 1){ + if (pdensity > 1) { cpl_image * im9=NULL ; sinfo_interleave_frames(im_obj,&im_dither, cfg->noRows, &im9); sinfo_pro_save_ima(im9, raw, sof, cfg->outName, frm_pro_ctg, NULL, plugin_id, config); sinfo_free_image(&im9); + if(frm_is_std == 1) { + cpl_image * im9=NULL ; + sinfo_interleave_frames(im_obj_noflat,&im_dither_noflat, + cfg->noRows, &im9); + sinfo_pro_save_ima(im9, raw, sof, "im_obj_noflat.fits", + "IM_OBJ_NOFLAT", NULL,plugin_id, config); + sinfo_free_image(&im9); + } } - - /* - #--------------------------------------------------------- - # convolve spectra with Gaussian - #--------------------------------------------------------- - */ } else if (cfg->gaussInd == 1 && cfg->interInd == 0) { + + /* convolve spectra with Gaussian */ sinfo_msg("Convolve spectra with Gaussian"); if(pdensity > 1) { - cknull(im_conv = sinfo_new_convolve_image_by_gauss ( im_obj, cfg->hw ), - "sinfo_convolveImageByGauss failed" ); + cpl_image * im_conv=NULL ; + im_conv = sinfo_new_convolve_image_by_gauss (im_obj, cfg->hw ); - ck0(sinfo_pro_save_ima(im_conv,raw,sof,cfg->outName, - frm_pro_ctg,NULL,plugin_id,config), - "cannot save ima %s", cfg->outName); + sinfo_pro_save_ima(im_conv,raw,sof,cfg->outName,frm_pro_ctg,NULL, + plugin_id,config); - sinfo_free_image(&im_obj); sinfo_free_image(&im_conv); + sinfo_free_image(&im_obj); if (cfg->contains_dither == 1){ sinfo_free_image(&im_dither); } + + if(frm_is_std == 1) { + cpl_image * im_conv=NULL ; + im_conv=sinfo_new_convolve_image_by_gauss(im_obj_noflat,cfg->hw); + + sinfo_pro_save_ima(im_conv,raw,sof,"im_obj_noflat.fits", + "IM_OBJ_NOFLAT", NULL,plugin_id,config); + + sinfo_free_image(&im_conv); + sinfo_free_image(&im_obj_noflat); + if (cfg->contains_dither == 1){ + sinfo_free_image(&im_dither_noflat); + } + } } } else { - cpl_table* qclog_tbl = sinfo_compute_qc(qc, im_obj); sinfo_pro_save_ima(im_obj, raw, sof, cfg->outName, frm_pro_ctg, qclog_tbl, plugin_id, config); sinfo_free_table(&qclog_tbl); sinfo_free_image(&im_obj); + if(frm_is_std == 1) { + cpl_table* qclog_tbl = sinfo_compute_qc(qc, im_obj_noflat); + /* + sinfo_pro_save_ima(im_obj_noflat, raw, sof, "im_obj_noflat.fits", + "IM_OBJ_NOFLAT", qclog_tbl, plugin_id, config); + */ + sinfo_free_table(&qclog_tbl); + sinfo_free_image(&im_obj_noflat); + } + + + + if (cfg->contains_dither == 1 && cfg->interInd == 0) { + char name_list[MAX_NAME_SIZE]; if (strstr(cfg->outName, ".fits") != NULL) { snprintf(name_list, MAX_NAME_SIZE - 1, "%s%s", sinfo_new_get_rootname(cfg->outName), @@ -1372,41 +1420,31 @@ } } } - - /* the following generates a valgrind error - but without it 8 bytes are leaked */ + + /* the next generates a valgrind error but without it 8 bytes are leaked */ sinfo_free_image_array(&im,cfg->nframes); - /*AMO: check if those images can be deleted before */ - sinfo_free_image(&int_im_shifted); - sinfo_free_image(&im_obj_flat); - sinfo_stack_free(&cfg); sinfo_free_frameset(&raw); sinfo_qc_wcal_delete(&qc); - + return 0; cleanup: - sinfo_free_table(&tbl_slitpos); - sinfo_free_table(&tbl_index); - if(slit_edges!=NULL) sinfo_new_destroy_2Dfloatarray(&slit_edges, 32); + sinfo_free_image(&flat1); sinfo_free_image(&flat_smooth); - sinfo_free_image(&int_im_shifted); sinfo_free_image(&im_dither); + sinfo_free_image(&im_dither_noflat); sinfo_free_image(&flat2); - sinfo_free_image(&im_obj_flat); sinfo_free_image(&im_obj); + sinfo_free_image(&im_obj_noflat); sinfo_free_image(&mask_im); sinfo_free_image(&im_sky); - sinfo_free_imagelist(&list_object_tmp); - sinfo_free_image(&sky_img_flat); - sinfo_free_image(&sky_dist); sinfo_free_image(&sky_img); sinfo_free_imagelist(&list_object); sinfo_free_imagelist(&list_sky); - if(im != NULL) sinfo_free_image_array(&im,cfg->nframes); + //if(im != NULL) sinfo_free_image_array(&im,cfg->nframes); sinfo_stack_free(&cfg); sinfo_free_frameset(&raw); sinfo_qc_wcal_delete(&qc); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_psf.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_psf.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_psf.c 2015-02-23 14:43:03.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_psf.c 2017-09-28 19:08:09.000000000 +0000 @@ -401,8 +401,8 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); check_nomsg(sinfo_add_com_psf_qclog(fname1,&qclog_tbl)); if(irplib_isnan(strehl1)) strehl1=-100.; - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL025",strehl1, - "STREHL 25 mas","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL025",strehl1, + "STREHL 25 mas")); ck0(sinfo_pro_save_ima(med_img1,ref_set,sof,PSF_MED_CUB_025_FILENAME, PRO_MED_COADD_PSF,qclog_tbl,plugin_id,config), "cannot save ima %s", PSF_MED_CUB_100_FILENAME); @@ -412,13 +412,13 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); check_nomsg(sinfo_add_com_psf_qclog(fname2,&qclog_tbl)); if(irplib_isnan(strehl2)) strehl2=-100.; - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL100",strehl2, - "STREHL 100 mas","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL100",strehl2, + "STREHL 100 mas")); if(irplib_isnan(strehl)) strehl=-100.; - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL",strehl, - "STREHL from both pixel scale images","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL",strehl, + "STREHL from both pixel scale images")); ck0(sinfo_pro_save_ima(med_img2,ref_set,sof,PSF_MED_CUB_100_FILENAME, PRO_MED_COADD_PSF,qclog_tbl,plugin_id,config), "cannot save ima %s", PSF_MED_CUB_100_FILENAME); @@ -436,24 +436,24 @@ if(strehl_sw==0) { if(irplib_isnan(strehl)) strehl=-100.; - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL",strehl, - "STREHL from image","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL",strehl, + "STREHL from image")); } check_nomsg(strehl=cpl_table_get_column_median(ao_performance,"strehl")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL MED",strehl, - "STREHL MEDIAN","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL MED",strehl, + "STREHL MEDIAN")); check_nomsg(strehl=cpl_table_get_column_mean(ao_performance,"strehl")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL AVG",strehl, - "STREHL AVERAGE","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL AVG",strehl, + "STREHL AVERAGE")); /* strehl=sinfo_get_strehl_from_ima(med_img1,frm1); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC STREHL AVG",strehl, + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC STREHL AVG",strehl, "STREHL AVERAGE","%f")); */ for(i=1;ioutName,PRO_PSF, qclog_tbl,plugin_id,config), @@ -562,7 +562,7 @@ if (cpl_propertylist_has(plist, KEY_NAME_LOOP_STATE)) { sinfo_qclog_add_string(*qclog_tbl,KEY_NAME_LOOP_STATE, cpl_propertylist_get_string(plist,KEY_NAME_LOOP_STATE), - KEY_HELP_LOOP_STATE,"%s"); + KEY_HELP_LOOP_STATE); } @@ -570,14 +570,14 @@ if (cpl_propertylist_has(plist, KEY_NAME_LOOP_LGS)) { sinfo_qclog_add_int(*qclog_tbl,KEY_NAME_LOOP_LGS, cpl_propertylist_get_int(plist,KEY_NAME_LOOP_LGS), - KEY_HELP_LOOP_LGS,"%d"); + KEY_HELP_LOOP_LGS); } if (cpl_propertylist_has(plist, KEY_NAME_INS1_MODE)) { sinfo_qclog_add_string(*qclog_tbl,KEY_NAME_INS1_MODE, cpl_propertylist_get_string(plist,KEY_NAME_INS1_MODE), - KEY_HELP_INS1_MODE,"%s"); + KEY_HELP_INS1_MODE); } @@ -1009,9 +1009,9 @@ if(!isnan(flux) && !isnan(flux_max)) { enc_en=flux/flux_max; } - ck0_nomsg(sinfo_qclog_add_double(*qclog_tbl,"QC ENC CORE", + ck0_nomsg(sinfo_qclog_add_double_f(*qclog_tbl,"QC ENC CORE", enc_en, - "Encircled energy within PSF core","%f")); + "Encircled energy within PSF core")); return enc_energy; cleanup: diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_slit_pos.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_slit_pos.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_slit_pos.c 2017-04-03 13:01:18.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_slit_pos.c 2017-09-28 19:08:09.000000000 +0000 @@ -390,13 +390,13 @@ sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc); qclog_tbl = sinfo_qclog_init(); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL", - n_lines,"Number of found lines","%d")); + n_lines,"Number of found lines")); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE NPIXSAT", - qc->nsat,"Number of saturated pixels","%d")); + qc->nsat,"Number of saturated pixels")); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE MAXFLUX", - qc->max_di,"Max int off-lamp subracted frm","%g")); + qc->max_di,"Max int off-lamp subracted frm")); if(-1 == sinfo_pro_save_ima(map,raw,sof,cfg->outName, PRO_WAVE_MAP,qclog_tbl,cpl_func,config)) { @@ -423,7 +423,7 @@ qclog_tbl = sinfo_qclog_init(); key_name = cpl_calloc(FILE_NAME_SZ,sizeof(char)); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL", - n_lines,"Number of found lines","%d")); + n_lines,"Number of found lines")); @@ -447,12 +447,12 @@ //trow=1+i; snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," AVG"); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_avg, - "Average wavecal Coef","%g")); + "Average wavecal Coef")); //trow=1+i+cfg->nrDispCoefficients; snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," MED"); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_med, - "Median wavecal Coef","%g")); + "Median wavecal Coef")); } @@ -514,7 +514,7 @@ qclog_tbl = sinfo_qclog_init(); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_found_lines, - "Number of Found lines","%d")); + "Number of Found lines")); for ( i = 0 ; i < par[0] -> n_params ; i++ ) { @@ -533,11 +533,11 @@ fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1"); fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1"); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med, - "Median FWHM of found lines","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM MED",fwhm_med, + "Median FWHM of found lines")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg, - "Average FWHM of found lines","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM AVG",fwhm_avg, + "Average FWHM of found lines")); if(-1 == sinfo_pro_save_tbl(tbl_fp,raw,sof,cfg->paramsList, @@ -636,17 +636,17 @@ sinfo_det_ncounts(raw, cfg->qc_thresh_max,qc); qclog_tbl = sinfo_qclog_init(); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_lines, - "Number of found lines","%d")); + "Number of found lines")); fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1"); fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1"); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med, - "Median FWHM of found lines","%f")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg, - "Average FWHM of found lines","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM MED",fwhm_med, + "Median FWHM of found lines")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM AVG",fwhm_avg, + "Average FWHM of found lines")); if(-1 == sinfo_pro_save_ima(map,raw,sof,cfg->outName, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_stdstar.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_stdstar.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_stdstar.c 2017-02-12 09:22:26.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_stdstar.c 2018-01-19 12:12:16.000000000 +0000 @@ -39,12 +39,14 @@ Includes ---------------------------------------------------------------------------*/ #include +#include <../hdrl/hdrl.h> //Used only for cpl_propertylist_has #include #include #include "irplib_utils.h" #include "sinfo_dfs.h" +//#include "sinfo_eff_resp.h" #include "sinfo_tpl_utils.h" #include "sinfo_new_stdstar.h" @@ -58,6 +60,7 @@ #include "sinfo_utl_efficiency.h" #include "sinfo_error.h" #include "sinfo_utils_wrappers.h" + /*---------------------------------------------------------------------------- Defines ---------------------------------------------------------------------------*/ @@ -391,23 +394,24 @@ } cpl_image * -sinfo_simple_extraction_from_cube(cpl_imagelist * cube, cpl_mask* obj_mask, +sinfo_simple_extraction_from_cube(cpl_imagelist * cube, + const cpl_mask* obj_mask, const char* name, cpl_table** spectrum, - int qc_info, - int* check2){ + int qc_info){ cpl_image * retIm ; int sz=cpl_imagelist_get_size(cube); float* podata=NULL; - double gfit_par[7] ; - float dispersion = 0; - float lambda_start=0; - float cenpix = 0; - float cenLambda = 0; + double gfit_par[7] = {0,0,0,0,0,0,0}; + double dispersion = 0; + double lambda_start=0; + double cenpix = 0; + double cenLambda = 0; cpl_propertylist* plist; - int nima=cpl_image_get_size_x(obj_mask)*cpl_image_get_size_y(obj_mask); + + int nima=cpl_mask_get_size_x(obj_mask)*cpl_mask_get_size_y(obj_mask); cpl_mask* sky_mask=cpl_mask_duplicate(obj_mask); cpl_mask_not(sky_mask); @@ -442,7 +446,7 @@ for(int z=0; z< sz; z++){ cpl_image* i_img=cpl_imagelist_get(cube,z); //cpl_image_save(i_img, "i_img.fits", CPL_BPP_IEEE_FLOAT,NULL, CPL_IO_DEFAULT); - float* pidata=cpl_image_get_data_float(i_img); + //float* pidata=cpl_image_get_data_float(i_img); float weighted_sum = 0. ; float counts_tot=0.; float counts_bkg=0.; @@ -454,7 +458,7 @@ cpl_mask* sky_mask_tmp=cpl_mask_duplicate(sky_mask); cpl_mask* obj_mask_tmp=cpl_mask_duplicate(obj_mask); int obj_numb; - + cpl_mask* old_bpm=NULL; /* flag NAN in image (SINFONI BP conventions) before getting med */ //cpl_image_reject_value(i_img,CPL_VALUE_NAN); /* extract mask of NANs to be used later */ @@ -466,11 +470,15 @@ cpl_mask_or(sky_mask_tmp,nan_mask_tmp); //cpl_mask_save(sky_mask_tmp,"sky_mask_tmp.fits",NULL,CPL_IO_CREATE); - cpl_image_set_bpm(i_img,sky_mask_tmp); + old_bpm=cpl_image_set_bpm(i_img,cpl_mask_duplicate(sky_mask_tmp)); + + nbad_sky=cpl_mask_count(sky_mask_tmp); if(nbad_sky0) { + eff_avg=cpl_table_get_column_mean(tmp_eff,"EFF"); + eff_med=cpl_table_get_column_median(tmp_eff,"EFF"); + eff_min=cpl_table_get_column_min(tmp_eff,"EFF"); + eff_max=cpl_table_get_column_max(tmp_eff,"EFF"); + eff_std=cpl_table_get_column_stdev(tmp_eff,"EFF"); + + + sprintf(key_name,"QC EFF WIN%d WLMIN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmin, + "[um] Min window wavelength for eff comp"); + + sprintf(key_name,"QC EFF WIN%d WLMAX",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmax, + "[um] Max window wavelength for eff comp"); + + + sprintf(key_name,"QC EFF WIN%d MEAN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_avg, + "Mean efficiency on window"); + + sprintf(key_name,"QC EFF WIN%d MEDIAN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_med, + "Median efficiency on window"); + + sprintf(key_name,"QC EFF WIN%d MIN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_min, + "Min efficiency on window"); + + sprintf(key_name,"QC EFF WIN%d MAX",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_max, + "Max efficiency on window"); + + sprintf(key_name,"QC EFF WIN%d RMS",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_std, + "RMS efficiency on window"); + } + cpl_table_select_all(tot_eff); + sinfo_free_table(&tmp_eff); + + } + wmin=cpl_table_get_column_min(ew_tab,"WMIN"); + wmax=cpl_table_get_column_max(ew_tab,"WMAX"); + eff_avg=cpl_table_get_column_mean(tot_eff,"EFF"); + eff_med=cpl_table_get_column_median(tot_eff,"EFF"); + eff_min=cpl_table_get_column_min(tot_eff,"EFF"); + eff_max=cpl_table_get_column_max(tot_eff,"EFF"); + eff_std=cpl_table_get_column_stdev(tot_eff,"EFF"); + + + sprintf(key_name,"QC EFF WLMIN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmin, + "[um] Min wavelength for eff comp"); + + sprintf(key_name,"QC EFF WLMAX"); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmax, + "[um] Max wavelength for eff comp"); + + sprintf(key_name,"QC EFF MEAN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_avg, + "Mean efficiency"); + + sprintf(key_name,"QC EFF MEDIAN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_med, + "Median efficiency"); + + sprintf(key_name,"QC EFF MIN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_min, + "Min efficiency"); + + sprintf(key_name,"QC EFF MAX"); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_max, + "Max efficiency"); + + sprintf(key_name,"QC EFF RMS"); + sinfo_qclog_add_double(*qclog_tbl, key_name, eff_std, + "RMS efficiency"); + sinfo_free_table(&ew_tab); + return cpl_error_get_code(); +} + + + + + + +static cpl_error_code +sinfo_extract(const char* extract_method, int qc_info, + cpl_errorstate clean_state, const char* plugin_id, + int do_compute_eff, float cenLambda, double disp, double cenpix, + standstar_config* cfg, cpl_imagelist** cube, + cpl_mask* obj_mask, cpl_table** qclog_tbl, cpl_frameset* ref_set, + cpl_frameset* sof, cpl_parameterlist* config) +{ + + + int check2; + int check3; + int no; + double lo_cut=0.; + double hi_cut=0.; + double convfactor=0; + double cleanfactor=0; + float* factor=NULL; + cpl_image* img_spct=NULL; + if (cfg->convInd == 1) { + factor = sinfo_new_floatarray(cfg->nframes); + } + cpl_imagelist* list_object=cpl_imagelist_new(); + cpl_table* tbl_spectrum=NULL; + cpl_image** spectrum = (cpl_image**) cpl_calloc(cfg->nframes, sizeof(cpl_image*)); + for (int fra = 0; fra < cfg->nframes; fra++) { + char* name = cfg->inFrameList[fra]; + if (sinfo_is_fits_file(name) != 1) { + sinfo_msg_error("Input file %s is not FITS", name); + cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT); + + + } + *cube = cpl_imagelist_load(name, CPL_TYPE_FLOAT, 0); + + + float exptime = sinfo_pfits_get_ditndit(name); + + sinfo_msg("cfg->gain %f", cfg->gain); + tbl_spectrum = cpl_table_new(cpl_imagelist_get_size(*cube)); + + if (strcmp(extract_method, "optimal") == 0) { + sinfo_msg("optimal extraction"); + if (NULL == (spectrum[fra] = sinfo_new_optimal_extraction_from_cube( + *cube, cfg->llx, + cfg->lly, + cfg->halfbox_x, + cfg->halfbox_y, + cfg->fwhm_factor, + BKG_VARIANCE, + SKY_FLUX, cfg->gain, + exptime, name, + &tbl_spectrum, + qc_info, &check2))) { + + irplib_error_recover(clean_state, + "could not do sinfo_optimalExtractionFromCube"); + } + else { + cpl_imagelist_set(list_object, + cpl_image_duplicate(spectrum[fra]), fra); + + } + + } + else { + sinfo_msg("simple extraction"); + if (NULL == (spectrum[fra] = sinfo_simple_extraction_from_cube( + *cube, obj_mask, + name, &tbl_spectrum, + qc_info))) { + + irplib_error_recover(clean_state, + "could not do sinfo_simpleExtractionFromCube"); + + } + else { + + cpl_imagelist_set(list_object, + cpl_image_duplicate(spectrum[fra]), fra); + } + + } + if (obj_mask != NULL) { + cpl_mask_delete(obj_mask); + } + sinfo_qclog_add_int(*qclog_tbl, "QC CHECK2", check2, + "Check on evaluation box"); + + sinfo_pro_save_tbl(tbl_spectrum, ref_set, sof, + (char*) STDSTAR_OUT_TABLE, + PRO_STD_STAR_SPECTRA, *qclog_tbl, plugin_id, config); + + /*----determine the intensity conversion factor if wished--------*/ + if (cfg->convInd == 1) { + sinfo_msg("Determines convertion factor"); + + convfactor = sinfo_new_determine_conversion_factor(*cube, cfg->mag, + exptime, cfg->llx, cfg->lly, cfg->halfbox_x, + cfg->halfbox_y, &check3); + + if (convfactor < -100000.) { + sinfo_msg_warning( + "could not do sinfo_determineConversionFactor!"); + /* goto cleanup; */ + } + else { + sinfo_new_array_set_value(factor, convfactor, fra); + } + } + sinfo_free_imagelist(cube); + } + + sinfo_free_table(&tbl_spectrum); + sinfo_free_image_array(&spectrum, cfg->nframes); + if (cfg->convInd == 1) { + sinfo_msg("Determines clean factor"); + cleanfactor = sinfo_new_clean_mean(factor, cfg->nframes, + cfg->lo_reject * 100., cfg->hi_reject * 100.); + } + if (cleanfactor > 100000. || cleanfactor == FLAG) { + sinfo_msg_error("could not do sinfo_clean_mean!"); + cpl_error_set(cpl_func,CPL_ERROR_UNSPECIFIED); + } + /*---read the fits header to change the gain and noise parameter-----*/ + sinfo_msg("Average with rejection"); + no = cpl_imagelist_get_size(list_object); + lo_cut = (floor)(cfg->lo_reject * no + 0.5); + hi_cut = (floor)(cfg->hi_reject * no + 0.5); + if (no > 0) { + img_spct = cpl_imagelist_collapse_minmax_create(list_object, lo_cut, + hi_cut); + } + sinfo_free_imagelist(&list_object); + if (no > 0) { + //*qclog_tbl = sinfo_qclog_init(); + + sinfo_qclog_add_double(*qclog_tbl, "QC CONVFCT", cleanfactor, + "Conversion factor"); + sinfo_qclog_add_int(*qclog_tbl, "QC CHECK3", check3, + "Check evaluation box"); + sinfo_pro_save_ima(img_spct, ref_set, sof, cfg->outName, + PRO_STD_STAR_SPECTRUM, *qclog_tbl, plugin_id, config); + + sinfo_new_set_wcs_spectrum(img_spct, cfg->outName, cenLambda, disp, + cenpix); + //sinfo_free_table(qclog_tbl); + } + /*#---free memory---*/ + if (factor != NULL) + sinfo_new_destroy_array(&factor); + + sinfo_free_image(&img_spct); + sinfo_print_rec_status(0); + return cpl_error_get_code(); + +} + +static cpl_error_code +sinfo_efficiency(const char* plugin_id, cpl_parameterlist* config, + cpl_frameset* sof,cpl_frameset* ref_set) +{ + + + cpl_errorstate clean_state = cpl_errorstate_get(); + cpl_table* qclog_tbl=NULL; + cpl_table* tot_eff=NULL; + cpl_parameter* p; + p = cpl_parameterlist_find(config,"sinfoni.stacked.flat_index"); + int flat_ind=cpl_parameter_get_bool(p); + cpl_frame* frm_std_cat = cpl_frameset_find(sof, FLUX_STD_CATALOG); + cpl_frame* frm_atmext = cpl_frameset_find(sof, EXTCOEFF_TABLE); + cpl_frame* frm_sci = cpl_frameset_find(sof, PRO_STD_STAR_SPECTRA); + cpl_frame* frm_eff_wind_qc = cpl_frameset_find(sof, EFFICIENCY_WINDOWS); + // EFFICIENCY + if ( flat_ind == 0 && frm_std_cat != NULL && frm_atmext != NULL ) { + sinfo_msg("compute efficiency"); + + tot_eff = sinfo_efficiency_compute(frm_sci, frm_std_cat, + frm_atmext); + + qclog_tbl = sinfo_qclog_init(); + if( tot_eff != NULL && frm_eff_wind_qc != NULL) { + + sinfo_eff_qc(tot_eff, frm_eff_wind_qc, &qclog_tbl); + + } + + if( tot_eff == NULL ) { + irplib_error_recover(clean_state, + "could not compute efficiency"); + } else { + sinfo_pro_save_tbl(tot_eff, ref_set, sof, + (char*) EFFICIENCY_FILENAME, + PRO_EFFICIENCY, qclog_tbl, plugin_id, config); + } + + //sinfo_free_table(qclog_tbl); + sinfo_free_table(&tot_eff); + } + sinfo_free_table(&qclog_tbl); + sinfo_print_rec_status(0); + + return cpl_error_get_code(); + +} /*---------------------------------------------------------------------------- Function Definitions ---------------------------------------------------------------------------*/ -/* temporally commented out as not yet used -static int -sinfo_compute_efficiency(cpl_frameset* sof, - const char* name, - standstar_config ** cfg, - cpl_imagelist * cube, - cpl_table** tbl_spectrum); - -*/ /**@{*/ /** @@ -569,32 +1026,9 @@ cpl_errorstate clean_state = cpl_errorstate_get(); standstar_config * cfg=NULL ; cpl_imagelist * cube=NULL ; - - cpl_imagelist * list_object=NULL ; - cpl_image ** spectrum=NULL ; - cpl_image * img_spct=NULL ; - - - cpl_frameset* raw=NULL; - cpl_frame* frame=NULL; - cpl_image* std_med_ima=NULL; - cpl_image* std_med_dup=NULL; - cpl_table* qclog_tbl=NULL; - cpl_table* tbl_spectrum=NULL; cpl_propertylist* plist=NULL; - //char band[FILE_NAME_SZ]; - - char * name=NULL ; - int fra=0; - float exptime=0 ; - double convfactor=0; - double cleanfactor=0; - float* factor=NULL; - - char std_med_filename[MAX_NAME_SIZE]; - char std_cub_filename[MAX_NAME_SIZE]; double max_ima_cx=0; double max_ima_cy=0; @@ -619,183 +1053,34 @@ int ima_szx=0; int ima_szy=0; int check1=0; - int check2=0; - int check3=0; int check4=0; double xshift=0; double yshift=0; - float cenpix = 0; - float cenLambda = 0; - - int no=0; - double lo_cut=0.; - double hi_cut=0.; - /* - const char* stdstars=NULL; - const char* sed=NULL; - */ - cpl_frame* frm_sci=NULL; - cpl_frame* frm_atmext=NULL; - cpl_frame* frm_std_cat=NULL; - cpl_table* tot_eff=NULL; + double cenpix = 0; + double cenLambda = 0; double fpar[7]; double dpar[7]; int mpar[7]; int do_compute_eff=0; - cpl_parameter* p=NULL; + int pfx=3; int pfy=3; const char* extract_method; const char* pfm; - //For new way to compute efficiency - //char band[80]; - //const char * seds_file=NULL; - //const char * filter=NULL; - //cpl_table* tbl_eff=NULL; - /* - parse the file names and parameters to the cube_config - data structure cfg - */ - /* sinfo_msg("Parse cpl input"); */ check_nomsg(raw=cpl_frameset_new()); cknull(cfg=sinfo_parse_cpl_input_standstar(config,sof,&raw), "could not parse cpl input!") ; - cknull_nomsg(p = cpl_parameterlist_find(config, - "sinfoni.std_star.compute_eff")); - check_nomsg(do_compute_eff = cpl_parameter_get_bool(p)); - - - cknull_nomsg(p = cpl_parameterlist_find(config, - "sinfoni.std_star.extract")); - check_nomsg(extract_method = cpl_parameter_get_string(p)); - - cknull_nomsg(p = cpl_parameterlist_find(config, - "sinfoni.std_star.pfm")); - check_nomsg(pfm = cpl_parameter_get_string(p)); - - cknull_nomsg(p = cpl_parameterlist_find(config, - "sinfoni.std_star.pfx")); - check_nomsg(pfx = cpl_parameter_get_int(p)); - - cknull_nomsg(p = cpl_parameterlist_find(config, - "sinfoni.std_star.pfy")); - check_nomsg(pfy = cpl_parameter_get_int(p)); - - cknull(list_object = cpl_imagelist_new (), - "could not allocate memory"); - - /* - sed = sinfo_extract_filename(sof, SINFO_CALIB_SED) ; - stdstars = sinfo_extract_filename(sof, SINFO_CALIB_STDSTARS) ; - */ - - if (cfg->convInd == 1) { - factor = sinfo_new_floatarray(cfg->nframes); - } - - if(NULL != cpl_frameset_find(sof,PRO_COADD_STD)) { - frame = cpl_frameset_find(sof,PRO_COADD_STD); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - } else if(NULL != cpl_frameset_find(sof,PRO_COADD_PSF)) { - frame = cpl_frameset_find(sof,PRO_COADD_PSF); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - } else if(NULL != cpl_frameset_find(sof,PRO_COADD_OBJ)) { - frame = cpl_frameset_find(sof,PRO_COADD_OBJ); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - } else if(NULL != cpl_frameset_find(sof,PRO_COADD_PUPIL)) { - frame = cpl_frameset_find(sof,PRO_COADD_PUPIL); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - } else { - sinfo_msg_error("Frame %s, %s, %s or %s not found! Exit!", - PRO_COADD_STD,PRO_COADD_PSF, - PRO_COADD_OBJ,PRO_COADD_PUPIL ); - goto cleanup; - } - - cknull(plist = cpl_propertylist_load(std_cub_filename, 0), - "getting header from reference ima frame %s",std_cub_filename); - - cenpix = sinfo_pfits_get_crpix3(plist); - cenLambda = sinfo_pfits_get_crval3(plist); - /* dispersion = sinfo_pfits_get_cdelt3(plist); */ - - - if (cpl_propertylist_has(plist, KEY_NAME_CDELT3)) { - disp=cpl_propertylist_get_double(plist, KEY_NAME_CDELT3); - } else { - sinfo_msg_warning("Keyword %s not found.",KEY_NAME_CDELT3); - } - - - sinfo_free_propertylist(&plist) ; - - /* we find automatiocally extraction parameters */ - - if(NULL != cpl_frameset_find(sof,PRO_MED_COADD_STD)) { - frame = cpl_frameset_find(sof,PRO_MED_COADD_STD); - strcpy(std_med_filename,cpl_frame_get_filename(frame)); - check_nomsg(std_med_ima=cpl_image_load(std_med_filename, - CPL_TYPE_FLOAT,0,0)); - } else if(NULL != cpl_frameset_find(sof,PRO_OBS_STD)) { - check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_STD)); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - check_nomsg(cube = cpl_imagelist_load(std_cub_filename, - CPL_TYPE_FLOAT,0)); - strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE); - check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube)); - sinfo_free_imagelist(&cube); - - ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE, - PRO_MED_OBS_PSF,NULL,plugin_id,config), - "Error saving image %s tag %s",STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_PSF); - - } else if(NULL != cpl_frameset_find(sof,PRO_MED_COADD_PSF)) { - check_nomsg(frame = cpl_frameset_find(sof,PRO_MED_COADD_PSF)); - strcpy(std_med_filename,cpl_frame_get_filename(frame)); - check_nomsg(std_med_ima=cpl_image_load(std_med_filename, - CPL_TYPE_FLOAT,0,0)); - } else if(NULL != cpl_frameset_find(sof,PRO_OBS_PSF)) { - check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_PSF)); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - check_nomsg(cube=cpl_imagelist_load(std_cub_filename,CPL_TYPE_FLOAT,0)); - strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE); - check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube)); - sinfo_free_imagelist(&cube); - - ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE, - PRO_MED_OBS_PSF,NULL,plugin_id,config), - "Error saving image %s tag %s",STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_PSF); - - } else if(NULL != cpl_frameset_find(sof,PRO_MED_COADD_OBJ)) { - check_nomsg(frame = cpl_frameset_find(sof,PRO_MED_COADD_OBJ)); - strcpy(std_med_filename,cpl_frame_get_filename(frame)); - check_nomsg(std_med_ima=cpl_image_load(std_med_filename, - CPL_TYPE_FLOAT,0,0)); - } else if(NULL != cpl_frameset_find(sof,PRO_OBS_OBJ)) { - check_nomsg(frame = cpl_frameset_find(sof,PRO_OBS_OBJ)); - strcpy(std_cub_filename,cpl_frame_get_filename(frame)); - check_nomsg(cube = cpl_imagelist_load(std_cub_filename, - CPL_TYPE_FLOAT,0)); - strcpy(std_med_filename,STDSTAR_OUT_MED_CUBE); - check_nomsg(std_med_ima=cpl_imagelist_collapse_median_create(cube)); - sinfo_free_imagelist(&cube); - - ck0(sinfo_pro_save_ima(std_med_ima,ref_set,sof,STDSTAR_OUT_MED_CUBE, - PRO_MED_OBS_OBJ,NULL,plugin_id,config), - "Error saving image %s tag %s",STDSTAR_OUT_MED_CUBE,PRO_MED_OBS_OBJ); - } else { - sinfo_msg_error("Frame %s %s %s %s %s %s not found! Exit!", - PRO_MED_COADD_STD, PRO_OBS_STD, - PRO_MED_COADD_PSF, PRO_OBS_PSF, - PRO_MED_COADD_OBJ, PRO_OBS_OBJ); - goto cleanup; - } + sinfo_set_params(&do_compute_eff, &extract_method, config,&pfm, &pfx, &pfy); + cpl_image* std_med_ima=NULL; + sinfo_get_cube_and_med_image(plugin_id, sof, ref_set, config, &cube, + &std_med_ima,&cenpix, &cenLambda, &disp); + cpl_image* std_med_dup=NULL; check_nomsg(std_med_dup=cpl_image_duplicate(std_med_ima)); cpl_image_reject_value(std_med_dup,CPL_VALUE_NAN); sinfo_clean_nan(&std_med_dup); @@ -811,8 +1096,8 @@ cpl_image_reject_value(std_med_dup,CPL_VALUE_NAN); double peak=0; - double max_x; - double max_y; + double max_x=0; + double max_y=0; sinfo_gaussian_maxpos(std_med_dup,5,&max_x,&max_y,&peak); max_ima_x=(int)(max_x+0.5); max_ima_y=(int)(max_y+0.5); @@ -842,16 +1127,16 @@ check_nomsg(max_ima_cy=cpl_image_get_centroid_y_window(std_med_ima,wllx, wlly,wurx,wury)); - xshift=max_ima_cx-ima_szx/2; - yshift=max_ima_cy-ima_szy/2; + //xshift=max_ima_cx-ima_szx/2; + //yshift=max_ima_cy-ima_szy/2; xshift=max_x-ima_szx/2; yshift=max_y-ima_szy/2; - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SHIFTX",xshift, - "X shift centroid - center image","%f")); + sinfo_qclog_add_double_f(qclog_tbl,"QC SHIFTX",xshift, + "X shift centroid - center image"); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC SHIFTY",yshift, - "Y shift centroid - center image","%f")); + sinfo_qclog_add_double_f(qclog_tbl,"QC SHIFTY",yshift, + "Y shift centroid - center image"); if( ((max_ima_x-psf_sz) < 1) || @@ -868,14 +1153,12 @@ psf_sz = (psf_sz > 4) ? psf_sz : 4; } - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM LLX",cfg->llx, - "STD star FWHM LLX","%d")); - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM LLY",cfg->lly, - "STD star FWHM LLY","%d")); - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM HBX",cfg->halfbox_x, - "STD star FWHM HBX","%d")); - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC FWHM HBX",cfg->halfbox_y, - "STD star FWHM HBY","%d")); + sinfo_qclog_add_int(qclog_tbl,"QC FWHM LLX",cfg->llx, "STD star FWHM LLX"); + sinfo_qclog_add_int(qclog_tbl,"QC FWHM LLY",cfg->lly, "STD star FWHM LLY"); + sinfo_qclog_add_int(qclog_tbl,"QC FWHM HBX",cfg->halfbox_x, + "STD star FWHM HBX"); + sinfo_qclog_add_int(qclog_tbl,"QC FWHM HBX",cfg->halfbox_y, + "STD star FWHM HBY"); /* call the 2D-Gaussian fit routine */ @@ -885,55 +1168,31 @@ } - if(-1 == sinfo_new_fit_2d_gaussian(std_med_ima, - fpar, - dpar, - mpar, - cfg->llx, - cfg->lly, - cfg->halfbox_x, - cfg->halfbox_y, + if(-1 == sinfo_new_fit_2d_gaussian(std_med_ima, fpar, dpar, mpar, + cfg->llx, cfg->lly, cfg->halfbox_x, cfg->halfbox_y, &check4 ) ) { irplib_error_recover(clean_state,"2d Gaussian fit failed"); /* return 0; */ } else { - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MAJ",fpar[4], - "STD star FWHM on major axis","%f")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MIN",fpar[5], - "STD star FWHM on minor axis","%f")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC THETA",fpar[6], - "STD star ellipsis angle theta","%f")); + sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM MAJ",fpar[4], + "STD star FWHM on major axis"); + sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM MIN",fpar[5], + "STD star FWHM on minor axis"); + sinfo_qclog_add_double_f(qclog_tbl,"QC THETA",fpar[6], + "STD star ellipsis angle theta"); } - /* - sinfo_msg("Gauss fit params: xc,yc,amp,bkg,fwhm_x,fwhm_y,angle\n"); - for ( i = 0 ; i < 7 ; i++ ) - { - sinfo_msg("fpar[%d]=%f dpar[%d]=%f\n",i,fpar[i],i,dpar[i]); - } - */ + if(CPL_ERROR_NONE == cpl_image_fit_gaussian(std_med_ima,max_ima_x,max_ima_y, + psf_sz,&norm,&xcen,&ycen,&sig_x,&sig_y,&fwhm_x,&fwhm_y)) { - if(CPL_ERROR_NONE == cpl_image_fit_gaussian(std_med_ima, - max_ima_x, - max_ima_y, - psf_sz, - &norm, - &xcen, - &ycen, - &sig_x, - &sig_y, - &fwhm_x, - &fwhm_y)) { - - - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHMX",fwhm_x, - "STD star FWHM on X","%f")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHMY",fwhm_y, - "STD star FWHM on Y","%f")); + sinfo_qclog_add_double_f(qclog_tbl,"QC FWHMX",fwhm_x, + "STD star FWHM on X"); + sinfo_qclog_add_double_f(qclog_tbl,"QC FWHMY",fwhm_y, + "STD star FWHM on Y"); cfg -> halfbox_x = (floor)(0.5*(fwhm_x+fwhm_y)*cfg->fwhm_factor+0.5); @@ -947,22 +1206,13 @@ } /* we use a large value of kappa to be sure to flag well the object */ - cpl_mask* obj_mask; + cpl_mask* obj_mask=NULL; if(strcmp(extract_method,"optimal") != 0) { double kappa=5.; obj_mask=sinfo_object_mask(std_med_ima,pfm,pfx,pfy,kappa); } - - //sinfo_free_image(&std_med_ima); - - /* - sinfo_msg("max ima=%d %d psf_sz=%d\n",max_ima_x,max_ima_y,psf_sz); - sinfo_msg("centroid ima=%f %f\n",max_ima_cx,max_ima_cy); - sinfo_msg("gauss=norm=%f xcen=%f ycen=%f sig_x=%f " - "sig_y=%f fwhm_x=%f fwhm_y=%f\n", - norm,xcen,ycen,sig_x,sig_y,fwhm_x,fwhm_y); - */ + sinfo_free_image(&std_med_ima); cfg -> llx = (int)(xcen-cfg->halfbox_x); cfg -> llx = (cfg -> llx > 0 ) ? cfg -> llx : 1; @@ -978,210 +1228,51 @@ cfg -> halfbox_y=(int) ((ima_szy-cfg->lly-1)/2); check1++; } - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC CHECK1",check1, - "Check on evaluation box","%d")); - - /* - sinfo_msg("llx= %d lly= %d\n",cfg->llx, cfg->lly); - sinfo_msg("halfbox_x=%d halfbox_y=%d\n",cfg->halfbox_x,cfg->halfbox_y); - */ - - /* -#---------------------------------------------------------------------- -#---------------------------EXTRACTION--------------------------------- -#---------------------------------------------------------------------- - */ - + sinfo_qclog_add_int(qclog_tbl,"QC CHECK1",check1, + "Check on evaluation box"); + /* EXTRACTION */ sinfo_msg("Extraction"); - cknull(spectrum = (cpl_image**) cpl_calloc (cfg -> nframes, - sizeof(cpl_image*)), - "Could not allocate memory for spectrum image"); - - for (fra=0; fra < cfg->nframes; fra++) { - name = cfg->inFrameList[fra]; - if(sinfo_is_fits_file(name) != 1) { - sinfo_msg_error("Input file %s is not FITS",name); - goto cleanup; - } - cknull(cube = cpl_imagelist_load(name,CPL_TYPE_FLOAT,0), - "could not load data cube" ); - - if (exptime == FLAG) { - sinfo_msg_error("could not find exposure time in the fits header"); - return -1; - } - exptime = sinfo_pfits_get_ditndit(name); - - - - sinfo_msg("cfg->gain %f",cfg->gain); - check_nomsg(tbl_spectrum=cpl_table_new(cpl_imagelist_get_size(cube))); - - if(strcmp(extract_method,"optimal") == 0) { - sinfo_msg("optimal extraction"); - if(NULL==(spectrum[fra]=sinfo_new_optimal_extraction_from_cube( cube, - cfg->llx, - cfg->lly, - cfg->halfbox_x, - cfg->halfbox_y, - cfg->fwhm_factor, - BKG_VARIANCE, - SKY_FLUX, - cfg->gain, - exptime, - name, - &tbl_spectrum, - qc_info, - &check2))){ - - irplib_error_recover(clean_state, - "could not do sinfo_optimalExtractionFromCube"); - } else { - check_nomsg(cpl_imagelist_set(list_object, - cpl_image_duplicate(spectrum[fra]), fra)); - - } - - - } else { - sinfo_msg("simple extraction"); - if(NULL==(spectrum[fra]=sinfo_simple_extraction_from_cube(cube,obj_mask, - name,&tbl_spectrum,qc_info,&check2))){ - - irplib_error_recover(clean_state, - "could not do sinfo_simpleExtractionFromCube"); - - } else { - - check_nomsg(cpl_imagelist_set(list_object, - cpl_image_duplicate(spectrum[fra]), fra)); - } - - } - cpl_mask_delete(obj_mask); - - - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC CHECK2", - check2,"Check on evaluation box","%d")); - - - ck0(sinfo_pro_save_tbl(tbl_spectrum,ref_set,sof, - (char*)STDSTAR_OUT_TABLE, - PRO_STD_STAR_SPECTRA,qclog_tbl, - plugin_id,config), - "cannot dump ima %s", "out_std_star_spectrum.fits"); - - - sinfo_free_table(&qclog_tbl); - - if (do_compute_eff!=0 && frm_std_cat !=NULL && frm_atmext != NULL) { - sinfo_msg("compute efficiency"); - frm_sci = cpl_frameset_find(sof,PRO_STD_STAR_SPECTRA); - frm_std_cat = cpl_frameset_find(sof,FLUX_STD_CATALOG); - frm_atmext = cpl_frameset_find(sof,EXTCOEFF_TABLE); - - - - check_nomsg(tot_eff=sinfo_efficiency_compute(frm_sci,frm_std_cat, - frm_atmext)); - ck0(sinfo_pro_save_tbl(tot_eff,ref_set,sof,(char*)EFFICIENCY_FILENAME, - PRO_EFFICIENCY,qclog_tbl,plugin_id,config), - "cannot dump ima %s", "out_.fits"); - } - - /* - if(spectrum[fra] != NULL ) { - sinfo_free_image(&(spectrum)[fra]); - } - */ - /*----determine the intensity conversion factor if wished--------*/ - if (cfg->convInd == 1) { - sinfo_msg("Determines convertion factor"); - - convfactor = sinfo_new_determine_conversion_factor( cube, - cfg->mag, - exptime, - cfg->llx, - cfg->lly, - cfg->halfbox_x, - cfg->halfbox_y, - &check3 ); - - - if (convfactor < -100000.) { - sinfo_msg_warning("could not do sinfo_determineConversionFactor!" ); - /* goto cleanup; */ - } else { - sinfo_new_array_set_value(factor, convfactor, fra); - } - } - sinfo_free_imagelist(&cube); - } /* end loop over fra */ - - sinfo_free_table(&tbl_spectrum); - sinfo_free_image_array(&spectrum,cfg->nframes); - if (cfg->convInd == 1) { - sinfo_msg("Determines clean factor"); - cleanfactor = sinfo_new_clean_mean(factor, - cfg->nframes, - cfg->lo_reject*100., - cfg->hi_reject*100.); - } - if (cleanfactor > 100000. || cleanfactor == FLAG) { - sinfo_msg_error("could not do sinfo_clean_mean!" ); - goto cleanup; + sinfo_extract(extract_method, qc_info, clean_state, plugin_id, + do_compute_eff, cenLambda, disp,cenpix, cfg, &cube, + obj_mask, &qclog_tbl, ref_set, sof, config); + + cpl_parameter* p; + p = cpl_parameterlist_find(config,"sinfoni.stacked.flat_index"); + int flat_ind=cpl_parameter_get_bool(p); + if ( flat_ind == 1 && sinfo_can_compute_response( sof ) == 1 ) { + sinfo_msg("Response Computation"); + if(CPL_ERROR_NONE != sinfo_response_compute(plugin_id, config, ref_set, sof)) { + irplib_error_recover(clean_state,"Response computation failed"); + } + } + + if( flat_ind == 1 && sinfo_can_flux_calibrate( sof ) ) { + sinfo_msg("Flux Calibration"); + sinfo_flux_calibrate_spectra(plugin_id, config, ref_set, sof); + sinfo_flux_calibrate_cube(PRO_COADD_STD, plugin_id, config, sof, sof); + } + + if(flat_ind == 0 && do_compute_eff != 0) { + sinfo_msg("Efficiency Computation"); + sinfo_efficiency(plugin_id, config, sof, ref_set); } - /*---read the fits header to change the gain and noise parameter-----*/ - sinfo_msg("Average with rejection"); + //exit(0); - no=cpl_imagelist_get_size(list_object); - lo_cut=(floor)(cfg->lo_reject*no+0.5); - hi_cut=(floor)(cfg->hi_reject*no+0.5); - if(no > 0) { - cknull(img_spct=cpl_imagelist_collapse_minmax_create(list_object, - lo_cut,hi_cut), - "sinfo_average_with_rejection failed" ); - } - - sinfo_free_imagelist(&list_object); - - if(no > 0) { - check_nomsg(qclog_tbl = sinfo_qclog_init()); - - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC CONVFCT",cleanfactor, - "Conversion factor","%g")); - ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC CHECK3",check3, - "Check evaluation box","%d")); - ck0(sinfo_pro_save_ima(img_spct,ref_set,sof,cfg->outName, - PRO_STD_STAR_SPECTRUM,qclog_tbl, - plugin_id,config), - "cannot dump ima %s", cfg->outName); - - sinfo_new_set_wcs_spectrum(img_spct,cfg->outName,cenLambda,disp,cenpix); - sinfo_free_table(&qclog_tbl); - } - /*#---free memory---*/ - if(factor != NULL) sinfo_new_destroy_array(&factor); - sinfo_free_image(&img_spct); - sinfo_free_image(&std_med_ima); sinfo_stdstar_free(&cfg); sinfo_free_frameset(&raw); - + sinfo_free_table(&qclog_tbl); + sinfo_print_rec_status(0); return 0; cleanup: - sinfo_free_table(&tbl_spectrum); sinfo_free_table(&qclog_tbl); - sinfo_free_imagelist(&list_object); - if(spectrum != NULL) sinfo_free_image_array(&spectrum,cfg->nframes); sinfo_free_image(&std_med_ima); sinfo_free_image(&std_med_dup); sinfo_free_imagelist(&cube); sinfo_free_propertylist(&plist) ; - if(factor != NULL) sinfo_new_destroy_array(&factor); - sinfo_free_image(&img_spct); + sinfo_stdstar_free (&cfg); sinfo_free_frameset(&raw); return -1; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_stdstar.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_stdstar.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_stdstar.h 2007-09-21 14:13:43.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_stdstar.h 2017-08-29 08:00:14.000000000 +0000 @@ -61,9 +61,18 @@ cpl_parameterlist* config, cpl_frameset* sof,cpl_frameset* ref_set) ; +cpl_mask * sinfo_bpm_filter( + const cpl_mask * input_mask, + cpl_size kernel_nx, + cpl_size kernel_ny, + cpl_filter_mode filter); - - +cpl_image * +sinfo_simple_extraction_from_cube(cpl_imagelist * cube, + const cpl_mask* obj_mask, + const char* name, + cpl_table** spectrum, + int qc_info); #endif /*!SINFO_STDSTAR_H*/ /*--------------------------------------------------------------------------*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_wave_cal_slit2.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_wave_cal_slit2.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_new_wave_cal_slit2.c 2017-04-03 13:01:30.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_new_wave_cal_slit2.c 2017-09-28 19:08:09.000000000 +0000 @@ -360,13 +360,13 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL",n_lines, - "Number of found lines","%d")); + "Number of found lines")); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE NPIXSAT",qc->nsat, - "Number of saturated pixels","%d")); + "Number of saturated pixels")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC WAVE MAXFLUX",qc->max_di, - "Max int off-lamp subtracted frm","%g")); + "Max int off-lamp subtracted frm")); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC WAVE POSERR",shift, - "Overall positioning error in mum","%g")); + "Overall positioning error in mum")); ck0(sinfo_pro_save_ima(map_img,ref_set,sof,cfg->outName, PRO_WAVE_MAP,qclog_tbl,plugin_id,config), @@ -389,7 +389,7 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC WAVE ALL",n_lines, - "Number found lines","%d")); + "Number found lines")); for (j=0; j< lx; j++) { for (i=0; i< cfg->nrDispCoefficients; i++) { @@ -406,11 +406,11 @@ snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," AVG"); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_avg, - "Average wavecal Coef","%g")); + "Average wavecal Coef")); snprintf(key_name,MAX_NAME_SIZE-1,"%s%d%s","QC COEF",i," MED"); ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,key_name,coef_med, - "Median wavecal Coef","%g")); + "Median wavecal Coef")); } if(pdensity >1) { @@ -466,16 +466,16 @@ sinfo_msg("avg=%d",avg_lines); sinfo_qclog_add_int(qclog_tbl,"QC NLINES",avg_lines, - "Average number of detected lines","%d"); + "Average number of detected lines"); sinfo_qclog_add_int(qclog_tbl,"QC NLINES MIN",min_lines, - "Minimum number of detected lines","%d"); + "Minimum number of detected lines"); sinfo_qclog_add_int(qclog_tbl,"QC NLINES MAX",max_lines, - "Maximum number of detected lines","%d"); + "Maximum number of detected lines"); sinfo_qclog_add_int(qclog_tbl,"QC NLINES MIN POS",min_lines_col, - "Minimum number of detected lines","%d"); + "Column with minimum number of detected lines"); sinfo_qclog_add_int(qclog_tbl,"QC NLINES MAX POS",max_lines_col, - "Maximum number of detected lines","%d"); + "Column with maximum number of detected lines"); for ( i = 0 ; i < par[0] -> n_params ; i++ ) { @@ -501,10 +501,10 @@ check_nomsg(fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1")); check_nomsg(fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med, - "Median FWHM of found lines","%f")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg, - "Average FWHM of found lines","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM MED",fwhm_med, + "Median FWHM of found lines")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM AVG",fwhm_avg, + "Average FWHM of found lines")); if(pdensity > 1) { ck0(sinfo_pro_save_tbl(tbl_fp,ref_set,sof,cfg->paramsList, @@ -583,15 +583,15 @@ cknull_nomsg(qclog_tbl = sinfo_qclog_init()); ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC NLINES",n_lines, - "Number of found lines","%d")); + "Number of found lines")); check_nomsg(fwhm_avg = cpl_table_get_column_mean(tbl_fp,"fpar1")); check_nomsg(fwhm_med = cpl_table_get_column_median(tbl_fp,"fpar1")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM MED",fwhm_med, - "Median FWHM of found lines","%f")); - ck0_nomsg(sinfo_qclog_add_double(qclog_tbl,"QC FWHM AVG",fwhm_avg, - "Average FWHM of found lines","%f")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM MED",fwhm_med, + "Median FWHM of found lines")); + ck0_nomsg(sinfo_qclog_add_double_f(qclog_tbl,"QC FWHM AVG",fwhm_avg, + "Average FWHM of found lines")); ck0(sinfo_pro_save_ima(map_img,ref_set,sof,cfg->outName, PRO_WAVE_MAP,qclog_tbl,plugin_id,config), diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pfits.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pfits.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pfits.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pfits.c 2017-09-20 17:54:22.000000000 +0000 @@ -131,6 +131,27 @@ return exptime; } +/*--------------------------------------------------------------------------- */ +/** + @brief find out the GAIN value + @param plist property list to read from + @return the requested value +*/ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_get_gain (const cpl_propertylist * plist) +{ + + return cpl_propertylist_get_double(plist,SINFO_DET_GAIN); + +} + + +double sinfo_pfits_get_airm_end (const cpl_propertylist * plist) +{ + + return cpl_propertylist_get_double(plist,SINFO_AIRM_END); + +} @@ -366,13 +387,24 @@ @return keyword value */ /*---------------------------------------------------------------------------*/ +double sinfo_pfits_get_crpix1(const cpl_propertylist * plist) +{ + return cpl_propertylist_get_double(plist,"CRPIX1"); +} + +/*---------------------------------------------------------------------------*/ +/** + @brief find out the character string associated to the CRPIX2 keyword + @param plist FITS header + @return keyword value + */ +/*---------------------------------------------------------------------------*/ double sinfo_pfits_get_crpix2(const cpl_propertylist * plist) { return cpl_propertylist_get_double(plist,"CRPIX2"); } - /*---------------------------------------------------------------------------*/ /** @brief find out the character string associated to the CRPIX3 keyword @@ -465,6 +497,24 @@ } + + + + +cpl_error_code +sinfo_get_wcs_cube(const cpl_propertylist* plist, double *clambda, + double *dis, double *cpix, double *cx, double *cy) +{ + + *clambda=sinfo_pfits_get_crval3(plist); + *dis=sinfo_pfits_get_cdelt3(plist); + *cpix=sinfo_pfits_get_crpix3(plist); + *cx=sinfo_pfits_get_crpix1(plist); + *cy=sinfo_pfits_get_crpix2(plist); + + return cpl_error_get_code(); + +} /*---------------------------------------------------------------------------*/ /** @brief find out the RA keyword in a SINFONI header @@ -560,5 +610,37 @@ return cpl_error_get_code(); } +/*--------------------------------------------------------------------------- */ +/** + @brief find out the TEL AIRM START value + @param plist property list to read from + @return the requested value +*/ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_get_airm_start (const cpl_propertylist * plist) +{ + + return cpl_propertylist_get_double(plist,SINFO_AIRM_START); +} + + + +/*--------------------------------------------------------------------------- */ +/** + @brief find out the mean airmass value + @param plist property list to read from + @return the requested value +*/ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_get_airm_mean (const cpl_propertylist * plist) +{ + double airmass_start=0; + double airmass_end=0; + airmass_start = sinfo_pfits_get_airm_start(plist); + airmass_end = sinfo_pfits_get_airm_end(plist); + + return 0.5*(airmass_start+airmass_end); +} + /**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pfits.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pfits.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pfits.h 2015-09-21 11:47:17.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pfits.h 2017-09-20 17:54:22.000000000 +0000 @@ -40,11 +40,20 @@ /*----------------------------------------------------------------------------- Functions prototypes -----------------------------------------------------------------------------*/ +#define SINFO_AIRM_START "ESO TEL AIRM START" +#define SINFO_AIRM_END "ESO TEL AIRM END" +#define SINFO_DET_GAIN "ESO DET OUT1 GAIN" +#define SINFO_AIRM_START "ESO TEL AIRM START" +#define SINFO_AIRM_END "ESO TEL AIRM END" CPL_BEGIN_DECLS float sinfo_pfits_get_pixelscale (const char * filename ); double sinfo_pfits_get_targ_alpha(const cpl_propertylist * plist); double sinfo_pfits_get_targ_delta(const cpl_propertylist * plist); +double sinfo_pfits_get_airm_mean (const cpl_propertylist * plist); +double sinfo_pfits_get_gain (const cpl_propertylist * plist); +double sinfo_pfits_get_airm_start (const cpl_propertylist * plist); +double sinfo_pfits_get_airm_end (const cpl_propertylist * plist); /* char * sinfo_pfits_get_rec1raw1name(const char * filename) ; @@ -80,12 +89,16 @@ double sinfo_pfits_get_crval2(const cpl_propertylist *) ; double sinfo_pfits_get_crval3(const cpl_propertylist *) ; +double sinfo_pfits_get_crpix1(const cpl_propertylist *) ; double sinfo_pfits_get_crpix2(const cpl_propertylist *) ; double sinfo_pfits_get_crpix3(const cpl_propertylist *) ; double sinfo_pfits_get_cdelt1(const cpl_propertylist *) ; double sinfo_pfits_get_cdelt2(const cpl_propertylist *) ; double sinfo_pfits_get_cdelt3(const cpl_propertylist *) ; +cpl_error_code +sinfo_get_wcs_cube(const cpl_propertylist* plist, double *clambda, + double *dis, double *cpix, double *cx, double *cy); cpl_error_code sinfo_plist_set_extra_keys(cpl_propertylist* plist, diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pro_save.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pro_save.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pro_save.c 2015-09-21 11:46:57.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pro_save.c 2017-09-28 19:12:04.000000000 +0000 @@ -503,15 +503,14 @@ sinfo_qclog_add_int(cpl_table* table, const char* key_name, const int value, - const char* key_help, - const char* format) + const char* key_help) { int sz = cpl_table_get_nrow(table); int raw = sz; char key_value[FILE_NAME_SZ]; char key_type[FILE_NAME_SZ]; - snprintf(key_value,MAX_NAME_SIZE-1,format,value); + snprintf(key_value,MAX_NAME_SIZE-1,"%d",value); strcpy(key_type,"CPL_TYPE_INT"); cpl_table_set_size(table,sz+1); @@ -531,15 +530,14 @@ sinfo_qclog_add_bool(cpl_table* table, const char* key_name, const char value, - const char* key_help, - const char* format) + const char* key_help) { int sz = cpl_table_get_nrow(table); int raw = sz; char key_value[FILE_NAME_SZ]; char key_type[FILE_NAME_SZ]; - snprintf(key_value,MAX_NAME_SIZE-1,format,value); + snprintf(key_value,MAX_NAME_SIZE-1,"%d",value); strcpy(key_type,"CPL_TYPE_BOOL"); cpl_table_set_size(table,sz+1); @@ -558,15 +556,64 @@ sinfo_qclog_add_double(cpl_table* table, const char* key_name, const double value, - const char* key_help, - const char* format) + const char* key_help) { int sz = cpl_table_get_nrow(table); int raw = sz; char key_value[FILE_NAME_SZ]; char key_type[FILE_NAME_SZ]; - snprintf(key_value,MAX_NAME_SIZE-1,format,value); + snprintf(key_value,MAX_NAME_SIZE-1,"%g",value); + strcpy(key_type,"CPL_TYPE_DOUBLE"); + + cpl_table_set_size(table,sz+1); + + cpl_table_set_string(table,"key_name" ,raw,key_name); + cpl_table_set_string(table,"key_type" ,raw,key_type); + cpl_table_set_string(table,"key_value",raw,key_value); + cpl_table_set_string(table,"key_help" ,raw,key_help); + + return 0; + +} + +int +sinfo_qclog_add_double_f(cpl_table* table, + const char* key_name, + const double value, + const char* key_help) +{ + int sz = cpl_table_get_nrow(table); + int raw = sz; + char key_value[FILE_NAME_SZ]; + char key_type[FILE_NAME_SZ]; + + snprintf(key_value,MAX_NAME_SIZE-1,"%f",value); + strcpy(key_type,"CPL_TYPE_DOUBLE"); + + cpl_table_set_size(table,sz+1); + + cpl_table_set_string(table,"key_name" ,raw,key_name); + cpl_table_set_string(table,"key_type" ,raw,key_type); + cpl_table_set_string(table,"key_value",raw,key_value); + cpl_table_set_string(table,"key_help" ,raw,key_help); + + return 0; + +} + +int +sinfo_qclog_add_double_format(cpl_table* table, + const char* key_name, + const double value, + const char* key_help) +{ + int sz = cpl_table_get_nrow(table); + int raw = sz; + char key_value[FILE_NAME_SZ]; + char key_type[FILE_NAME_SZ]; + + snprintf(key_value,MAX_NAME_SIZE-1,"%13.6f",value); strcpy(key_type,"CPL_TYPE_DOUBLE"); cpl_table_set_size(table,sz+1); @@ -584,15 +631,14 @@ sinfo_qclog_add_string(cpl_table* table, const char* key_name, const char* value, - const char* key_help, - const char* format) + const char* key_help) { int sz = cpl_table_get_nrow(table); int raw = sz; char key_value[FILE_NAME_SZ]; char key_type[FILE_NAME_SZ]; - snprintf(key_value,MAX_NAME_SIZE-1,format,value); + snprintf(key_value,MAX_NAME_SIZE-1,"%s",value); strcpy(key_type,"CPL_TYPE_STRING"); cpl_table_set_size(table,sz+1); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pro_save.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pro_save.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pro_save.h 2015-09-21 11:46:55.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pro_save.h 2017-09-28 19:12:04.000000000 +0000 @@ -185,31 +185,37 @@ sinfo_qclog_add_int(cpl_table* table, const char* name, const int value, - const char* help, - const char* format); + const char* help); int sinfo_qclog_add_bool(cpl_table* table, const char* name, const char value, - const char* help, - const char* format); + const char* help); int sinfo_qclog_add_double(cpl_table* table, const char* name, const double value, - const char* help, - const char* format); + const char* help); +int +sinfo_qclog_add_double_f(cpl_table* table, + const char* key_name, + const double value, + const char* key_help); +int +sinfo_qclog_add_double_format(cpl_table* table, + const char* name, + const double value, + const char* help); int sinfo_qclog_add_string(cpl_table* table, const char* name, const char* value, - const char* help, - const char* format); + const char* help); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pro_types.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pro_types.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_pro_types.h 2010-02-12 17:57:38.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_pro_types.h 2017-09-08 09:22:21.000000000 +0000 @@ -147,6 +147,7 @@ #define PRO_FOCUS_GAUSS "FOCUS_GAUSS" #define PRO_WAVE_MAP "WAVE_MAP" #define PRO_STD_STAR_SPECTRA "STD_STAR_SPECTRA" +#define PRO_STD_STAR_SPECTRA_FLUXCAL "STD_STAR_SPECTRA_FLUXCAL" #define PRO_STD_STAR_SPECTRUM "STD_STAR_SPECTRUM" #define PRO_CUBE "CUBE" @@ -158,6 +159,13 @@ #define PRO_COADD_OBJ "COADD_OBJ" #define PRO_COADD_PUPIL "COADD_PUPIL" + + +#define PRO_COADD_SKY_FLUXCAL "COADD_SKY_FLUXCAL" +#define PRO_COADD_PSF_FLUXCAL "COADD_PSF_FLUXCAL" +#define PRO_COADD_STD_FLUXCAL "COADD_STD_FLUXCAL" +#define PRO_COADD_OBJ_FLUXCAL "COADD_OBJ_FLUXCAL" + #define PRO_OBS_PSF "OBS_PSF" #define PRO_OBS_STD "OBS_STD" #define PRO_OBS_OBJ "OBS_OBJ" @@ -187,5 +195,6 @@ #define PRO_OBJ_CUBE "OBJ_CUBE" #define PRO_BP_COEFF "BP_COEFF" #define PRO_EFFICIENCY "EFFICIENCY" +#define PRO_RESPONSE "RESPONSE" CPL_END_DECLS #endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_recipes.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_recipes.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_recipes.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_recipes.c 2017-08-29 08:00:30.000000000 +0000 @@ -482,7 +482,7 @@ @param im input image @return nothing */ -void sinfo_new_convert_ZEROs_to_0_for_images(cpl_image * im) +static void sinfo_new_convert_ZEROs_to_0_for_images(cpl_image * im) { int i ; int ilx=0; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_rec_utils.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_rec_utils.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_rec_utils.c 2015-09-21 11:46:43.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_rec_utils.c 2017-09-09 11:30:42.000000000 +0000 @@ -568,7 +568,6 @@ char outname[FILE_NAME_SZ]; char filename[FILE_NAME_SZ]; - cpl_frameset * obj_set=NULL; cpl_frameset * sky_set=NULL; cpl_frameset * cdb_set=NULL; @@ -606,7 +605,6 @@ cknull(obj_frm = cpl_frameset_get_frame(obj_set,0), "No object frames in input set."); - strcpy(tag,cpl_frame_get_tag(obj_frm)); if(NULL!=sinfo_new_set_obj_procatg(tag)){ *pro_ctg_cube=sinfo_new_set_obj_procatg(tag); @@ -615,7 +613,6 @@ goto cleanup; } - if(NULL!=sinfo_new_set_stk_procatg(tag)){ strcpy(pro_ctg_stack,sinfo_new_set_stk_procatg(tag)); } else { @@ -632,84 +629,72 @@ goto cleanup; } - if ( (nobj != 0) && (nsky != 0) ) { /* We have either OBJ and SKY: we need to create OBJ-SKY pairs */ sinfo_msg("------------------------------") ; sinfo_msg("Generates OBJ-SKY pairs"); sinfo_msg("------------------------------") ; - check_nomsg(tot_set=cpl_frameset_new()); - check_nomsg(p = cpl_parameterlist_find(config, - "sinfoni.objnod.autojitter_method")); - check_nomsg(cpl_parameter_set_int(p,0)); + tot_set=cpl_frameset_new(); + p = cpl_parameterlist_find(config, + "sinfoni.objnod.autojitter_method"); + cpl_parameter_set_int(p,0); for (i=0;i 1) { fk->is_fake_sky=1; - ck0(sinfo_get_dummy_obj_sky_stacked_and_cubes(obj_set,&(*set),config, - fk,pro_ctg_stack,recipe_id), - "Found error to get obj-sky-stacked frame"); + sinfo_get_dummy_obj_sky_stacked_and_cubes(obj_set,&(*set),config, + fk,pro_ctg_stack,recipe_id); } else { sinfo_msg("Only one object frame, no sky"); - check_nomsg(p=cpl_parameterlist_find(config, - "sinfoni.sinfo_utl_skycor.rot_cor")); - check_nomsg(cpl_parameter_set_bool(p,FALSE)); + p=cpl_parameterlist_find(config, + "sinfoni.sinfo_utl_skycor.rot_cor"); + cpl_parameter_set_bool(p,FALSE); - ck0(sinfo_new_stack_frames(config,*set,pro_ctg_stack,0,fk,recipe_id), - "Error stacking frame"); + sinfo_new_stack_frames(config,*set,pro_ctg_stack,0,fk,recipe_id); /* cube generation */ sinfo_msg("------------------------------") ; sinfo_msg("BUILDING CUBE %d",i); sinfo_msg("------------------------------") ; - ck0(sinfo_new_cubes_build(recipe_id,config,*set,*pro_ctg_cube,i), - "Error GENERATING CUBE %d", i) ; + sinfo_new_cubes_build(recipe_id,config,*set,*pro_ctg_cube,i); sinfo_msg("------------------------------") ; sinfo_msg("BUILT CUBE %d",i); @@ -842,52 +807,44 @@ sinfo_msg("------------------------------") ; sinfo_msg("staks each OBJECT "); sinfo_msg("------------------------------") ; - check_nomsg(tot_set=cpl_frameset_new()); + tot_set=cpl_frameset_new(); for (i=0;i0) { - check_nomsg(sky_frm_inf=cpl_frameset_get_frame(*obj_set,i-1)); - mjd_sky_inf = sinfo_get_mjd_obs(sky_frm_inf); - sky_inf_cumx=sinfo_get_cumoffsetx(sky_frm_inf); - sky_inf_cumy=sinfo_get_cumoffsety(sky_frm_inf); - } - - if(i cum_thres) || - (fabs(sky_inf_cumy-obj_cumy) > cum_thres)) { - *sky_frm = sky_frm_inf; - } else { - *sky_frm = sky_frm_sup; - } - } else { - if((fabs(sky_sup_cumx-obj_cumx) > cum_thres) || - (fabs(sky_sup_cumy-obj_cumy) > cum_thres)) { - *sky_frm = sky_frm_sup; - } else { - *sky_frm = sky_frm_inf; - } - } - } - return 0; - - cleanup: - return -1; - -} - */ /**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_ref_types.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_ref_types.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_ref_types.h 2012-08-10 07:55:23.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_ref_types.h 2017-09-13 13:57:11.000000000 +0000 @@ -38,9 +38,15 @@ #define DRS_SETUP_WAVE "DRS_SETUP_WAVE" #define EXTCOEFF_TABLE "EXTCOEFF_TABLE" #define FLUX_STD_TABLE "FLUX_STD_TABLE" +#define FLUX_STD_CATALOG "FLUX_STD_CATALOG" +#define TELL_MOD_CATALOG "TELL_MOD_CATALOG" +#define RESP_FIT_POINTS_CAT "RESP_FIT_POINTS_CATALOG" /* catalog of flux of standard stars*/ -#define FLUX_STD_CATALOG "FLUX_STD_CATALOG" - +#define EFFICIENCY_WINDOWS "EFFICIENCY_WINDOWS" +#define RESPONSE_WINDOWS "RESPONSE_WINDOWS" +#define QUALITY_AREAS "QUALITY_AREAS" +#define FIT_AREAS "FIT_AREAS" +#define HIGH_ABS_REGIONS "HIGH_ABS_REGIONS" CPL_END_DECLS #endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_spectrum_ops.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_spectrum_ops.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_spectrum_ops.c 2016-06-29 12:54:08.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_spectrum_ops.c 2017-09-23 06:23:59.000000000 +0000 @@ -777,7 +777,7 @@ mpar[i] = 1 ; } - if ( -1 == (fitInd = sinfo_new_fit_2d_gaussian(averagedIm, + if ( -1 == sinfo_new_fit_2d_gaussian(averagedIm, fit_par, derv_par, mpar, @@ -785,7 +785,7 @@ lly, halfbox_x, halfbox_y, - check2 )) ) + check2 ) ) { sinfo_msg_warning("sinfo_fit2dGaussian failed!") ; cpl_image_delete(retIm) ; diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_stack_ini_by_cpl.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_stack_ini_by_cpl.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_stack_ini_by_cpl.c 2013-12-28 16:58:56.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_stack_ini_by_cpl.c 2017-05-05 14:18:29.000000000 +0000 @@ -211,89 +211,89 @@ /* Browse through the charmatrix to get names and file types */ /* for (i=0 ; iframelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); - cfg->frametype[i] = FRAME_OFF ; - found_sky = 1; - if (sinfo_frame_is_dither(frame)) - { - cfg->frameposition[i] = FRAME_POS2 ; - nditheroff++ ; + /* to go on the file must exist */ + if(cpl_frame_get_tag(frame) != NULL) { + /* If the frame has a tag we process it. Else it is an object */ + tag= (char*) cpl_frame_get_tag(frame); + if((sinfo_frame_is_on(frame) == 0) || + (sinfo_frame_is_sky(frame) == 1)) + { + cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); + cfg->frametype[i] = FRAME_OFF ; + found_sky = 1; + if (sinfo_frame_is_dither(frame)) + { + cfg->frameposition[i] = FRAME_POS2 ; + nditheroff++ ; + } + else + { + cfg->frameposition[i] = FRAME_POS1 ; + noff++ ; + } + } + else if(strstr(tag,RAW_REF) != NULL) + { + cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); + cfg->frametype[i] = FRAME_REF ; + found_ref=1; + if (sinfo_frame_is_dither(frame)) + { + cfg->frameposition[i] = FRAME_POS2 ; + } + else + { + cfg->frameposition[i] = FRAME_POS1 ; + } + } + else if(sinfo_is_dark(tag)) + { + cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); + cfg->frametype[i] = FRAME_DRK ; + cfg->frameposition[i] = FRAME_POS1 ; + found_dark=1; + ndark++; + sinfo_msg("Frame is sinfo_dark on\n"); + } + else + { + + cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); + cfg->frametype[i] = FRAME_ON ; + found_ref=1; + if (sinfo_frame_is_dither(frame)) + { + cfg->frameposition[i] = FRAME_POS2 ; + found_dither=1; + nditherobj++; + } + else + { + cfg->frameposition[i] = FRAME_POS1 ; + nobj++; + } + } } - else + else { - cfg->frameposition[i] = FRAME_POS1 ; - noff++ ; + /* No type means an object */ + cfg->frametype[i] = FRAME_ON ; + /* No type means position 1 */ + cfg->frameposition[i] = FRAME_POS1 ; + + nobj ++ ; } - } - else if(strstr(tag,RAW_REF) != NULL) - { - cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); - cfg->frametype[i] = FRAME_REF ; - found_ref=1; - if (sinfo_frame_is_dither(frame)) - { - cfg->frameposition[i] = FRAME_POS2 ; - } - else - { - cfg->frameposition[i] = FRAME_POS1 ; - } - } - else if(sinfo_is_dark(tag)) - { - cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); - cfg->frametype[i] = FRAME_DRK ; - cfg->frameposition[i] = FRAME_POS1 ; - found_dark=1; - ndark++; - sinfo_msg("Frame is sinfo_dark on\n"); - } - else - { - - cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame)); - cfg->frametype[i] = FRAME_ON ; - found_ref=1; - if (sinfo_frame_is_dither(frame)) - { - cfg->frameposition[i] = FRAME_POS2 ; - found_dither=1; - nditherobj++; - } - else - { - cfg->frameposition[i] = FRAME_POS1 ; - nobj++; - } - } - } - else - { - /* No type means an object */ - cfg->frametype[i] = FRAME_ON ; - /* No type means position 1 */ - cfg->frameposition[i] = FRAME_POS1 ; - - nobj ++ ; - } - } - - /* Store file name into framelist */ - } - + } + + /* Store file name into framelist */ + } + sinfo_msg("Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d", - noff,nobj,nditheroff,nditherobj); - + noff,nobj,nditheroff,nditherobj); + /* Copy relevant information into the blackboard */ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_stack_ini.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_stack_ini.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_stack_ini.h 2007-06-06 07:10:46.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_stack_ini.h 2017-08-29 08:00:45.000000000 +0000 @@ -90,6 +90,6 @@ */ /*--------------------------------------------------------------------------*/ -stack_config * parse_stack_ini_file(char * ini_name) ; +stack_config_n * parse_stack_ini_file(char * ini_name) ; #endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_standstar_ini.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_standstar_ini.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_standstar_ini.h 2007-06-06 07:10:46.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_standstar_ini.h 2017-08-29 08:01:03.000000000 +0000 @@ -37,7 +37,7 @@ ---------------------------------------------------------------------------*/ #include -#include "standstar_cfg.h" +#include "sinfo_standstar_cfg.h" diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_tpl_dfs.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_tpl_dfs.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_tpl_dfs.c 2014-11-10 08:56:45.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_tpl_dfs.c 2017-09-09 11:30:42.000000000 +0000 @@ -183,10 +183,18 @@ || !strcmp(tag, EXTCOEFF_TABLE) || !strcmp(tag, FLUX_STD_TABLE) || !strcmp(tag, FLUX_STD_CATALOG) + || !strcmp(tag, EFFICIENCY_WINDOWS) + || !strcmp(tag, RESPONSE_WINDOWS) + || !strcmp(tag, TELL_MOD_CATALOG) + || !strcmp(tag, RESP_FIT_POINTS_CAT) + || !strcmp(tag, QUALITY_AREAS) + || !strcmp(tag, FIT_AREAS) + || !strcmp(tag, HIGH_ABS_REGIONS) || !strcmp(tag, PRO_IMA) || !strcmp(tag, PRO_CUBE) || !strcmp(tag, REF_BP_MAP) || !strcmp(tag, PRO_SKY_DUMMY) || !strcmp(tag, PRO_REF_ATM_REF_CORR) + || !strcmp(tag, PRO_RESPONSE) || !strcmp(tag, PRO_SPECTRUM)) cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_CALIB); else if (!strcmp(tag, PRO_OBS_OBJ) || !strcmp(tag, PRO_MED_OBS_OBJ) diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_utl_efficiency.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_utl_efficiency.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_utl_efficiency.c 2015-09-21 11:43:02.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_utl_efficiency.c 2018-02-19 10:35:35.000000000 +0000 @@ -31,35 +31,45 @@ #include /* irplib */ #include +/* hdrl */ +#include <../hdrl/hdrl.h> + #include #include #include #include #include +#include #include "sinfo_utl_efficiency.h" #include - -#define PRO_STD_STAR_SPECTRA "STD_STAR_SPECTRA" -static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH"; -static const char COL_NAME_WAVELENGTH_C[] = "WAVELENGTH"; -static const char COL_NAME_LAMBDA[] = "LAMBDA"; -static const char COL_NAME_LA_SILLA[] = "LA_SILLA"; +#include "sinfo_pro_save.h" +#include "sinfo_pro_types.h" +#include "sinfo_hidden.h" +//static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH"; +//static const char COL_NAME_WAVELENGTH_C[] = "WAVELENGTH"; +//static const char COL_NAME_LAMBDA[] = "LAMBDA"; +//static const char COL_NAME_LA_SILLA[] = "LA_SILLA"; static const char COL_NAME_REF[] = "REF"; static const char COL_NAME_COR[] = "COR"; static const char COL_NAME_SRC_COR[] = "SRC_COR"; -static const char COL_NAME_COUNTS_BKG[] = "INT_OBJ";//"counts_tot"; -static const char COL_NAME_FLUX[] = "FLUX"; +//static const char COL_NAME_COUNTS_BKG[] = "INT_OBJ";//"counts_tot"; +//static const char COL_NAME_FLUX[] = "FLUX"; static const char COL_NAME_EPHOT[] = "EPHOT"; static const char COL_NAME_EXT[] = "EXT"; static const char COL_NAME_SRC_EFF[] = "EFF"; -static const char PAR_NAME_DIT[] = "ESO DET DIT"; +//static const char PAR_NAME_DIT[] = "ESO DET DIT"; static char FRM_RAW_IMA_SLIT[] = PRO_STD_STAR_SPECTRA; static char FRM_FLUX_STD_TAB[] = FLUX_STD_TABLE; static char FRM_FLUX_STD_CAT[] = FLUX_STD_CATALOG; static char FRM_EXTCOEFF_TAB[] = EXTCOEFF_TABLE; + +const hdrl_spectrum1D_wave_scale +global_scale = hdrl_spectrum1D_wave_scale_linear; + + static int sinfo_column_to_double(cpl_table* ptable, const char* column); @@ -175,31 +185,34 @@ double EPSILON, cpl_table** pptable) { - const char* name = NULL; - if (cat) { - check_nomsg(name=cpl_frame_get_filename(cat)); - if (name) { - star_index* pstarindex = star_index_load(name); - if (pstarindex) { - const char* star_name = 0; - sinfo_msg("The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]", dRA, dDEC, EPSILON); - *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name); - if (*pptable && star_name) { - sinfo_msg("REF table is found in the catalog, star name is [%s]", star_name); - } - else { - sinfo_msg("ERROR - REF table could not be found in the catalog"); - } - } - else { - sinfo_msg("ERROR - could not load the catalog"); - } - } + if (cat != NULL) { + + const char* name = cpl_frame_get_filename(cat); + + if (name) { + star_index* pstarindex = star_index_load(name); + if (pstarindex) { + const char* star_name = 0; + sinfo_msg("The catalog is loaded, looking for star in RA[%f] DEC[%f] tolerance[%f]", dRA, dDEC, EPSILON); + *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, &star_name); + if (*pptable && star_name) { + sinfo_msg("REF table is found in the catalog, star name is [%s]", star_name); + } + else { + sinfo_msg("ERROR - REF table could not be found in the catalog"); + } + } + else { + sinfo_msg("ERROR - could not load the catalog"); + } + star_index_delete(pstarindex); + + } } - cleanup: + return; } @@ -648,6 +661,1023 @@ return tbl_sel; } +static hdrl_spectrum1D * +sinfo_sci_frame_to_hdrl_spectrum1D(cpl_frame* frm_sci) +{ + cpl_ensure(frm_sci != NULL, CPL_ERROR_NULL_INPUT, NULL); + hdrl_spectrum1D * sci_s1d; + const char* name_sci=NULL; + name_sci=cpl_frame_get_filename(frm_sci); + cpl_table* sci_tab=NULL; + sci_tab=cpl_table_load(name_sci,1,0); + cpl_ensure(sci_tab != NULL, CPL_ERROR_NULL_INPUT, NULL); + + + sci_s1d=hdrl_spectrum1D_convert_from_table(sci_tab, "counts_bkg", + "wavelength", NULL, NULL, global_scale); + sinfo_free_table(&sci_tab); + return sci_s1d; + +} + + + + +static hdrl_spectrum1D * +sinfo_std_cat_frame_to_hdrl_spectrum1D(cpl_frame* frm_std_cat,const double dRA, + const double dDEC) +{ + cpl_ensure(frm_std_cat != NULL, CPL_ERROR_NULL_INPUT, NULL); + hdrl_spectrum1D * std_s1d; + + //const char* name = cpl_frame_get_filename(frm_std_cat); + cpl_table* tbl_ref = NULL; + + double dEpsilon=0.1; + + sinfo_parse_catalog_std_stars(frm_std_cat,dRA,dDEC,dEpsilon,&tbl_ref); + + if(tbl_ref == NULL) { + sinfo_msg_error("Provide std sar catalog frame"); + return NULL; + } + + std_s1d=hdrl_spectrum1D_convert_from_table(tbl_ref, "FLUX", + "LAMBDA", NULL, NULL, global_scale); + sinfo_free_table(&tbl_ref); + return std_s1d; +} + + +static hdrl_spectrum1D * +sinfo_atmext_frame_to_hdrl_spectrum1D(cpl_frame* frm_atmext) +{ + cpl_ensure(frm_atmext != NULL, CPL_ERROR_NULL_INPUT, NULL); + hdrl_spectrum1D * ext_s1d; + const char* name_atm = cpl_frame_get_filename(frm_atmext); + + cpl_table* tbl_atmext = cpl_table_load(name_atm,1,0); + + + ext_s1d=hdrl_spectrum1D_convert_from_table(tbl_atmext, "EXTINCTION", + "LAMBDA", NULL, NULL, global_scale); + sinfo_free_table(&tbl_atmext); + return ext_s1d; +} + +static hdrl_parameter* +sinfo_response_parameters_calc_par(cpl_propertylist* plist) +{ + cpl_ensure(plist != NULL, CPL_ERROR_NULL_INPUT, NULL); + hdrl_value Ap = {0}; + + double airmass=0; + double airmass_start=0; + double airmass_end=0; + airmass_start=sinfo_pfits_get_airmass_end(plist); + airmass_end=sinfo_pfits_get_airmass_end(plist); + airmass=0.5*(airmass_start+airmass_end); + + hdrl_value Am = {airmass}; + + double gain=2.42; + hdrl_value G= {gain}; + sinfo_msg("resp gain=%g",gain); + double exptime=sinfo_pfits_get_dit(plist); + sinfo_msg("resp exptime=%g",exptime); + + hdrl_value Tex= {exptime}; + hdrl_parameter* calc_par = hdrl_response_parameter_create(Ap, Am, G, Tex); + + return calc_par; + +} + +static hdrl_spectrum1Dlist * +sinfo_get_telluric_models(const cpl_frame * telluric_cat){ + + cpl_ensure(telluric_cat != NULL, CPL_ERROR_NULL_INPUT, NULL); + const char * cat_name = cpl_frame_get_filename(telluric_cat); + const cpl_size next = cpl_frame_get_nextensions(telluric_cat); + + hdrl_spectrum1Dlist * list = hdrl_spectrum1Dlist_new(); + + for(cpl_size i = 0; i < next; ++i){ + cpl_table * tab = cpl_table_load(cat_name, 1 + i, 1); + + hdrl_spectrum1D * s = + hdrl_spectrum1D_convert_from_table(tab, + "flux", + "lam", + NULL, + NULL, + global_scale); + cpl_table_delete(tab); + /*um to nm*/ + hdrl_spectrum1D_wavelength_mult_scalar_linear(s, 1e3); + hdrl_spectrum1Dlist_set(list, s, i); + } + + return list; +} + + +static cpl_bivector * +sinfo_read_wlen_windows(const cpl_frame * fit_areas_frm){ + + cpl_ensure(fit_areas_frm != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_table * tab = NULL; + + tab = cpl_table_load(cpl_frame_get_filename(fit_areas_frm),1,0); + + + const cpl_size nrow = cpl_table_get_nrow(tab); + + double * pwmin = cpl_table_unwrap(tab,"LAMBDA_MIN"); + double * pwmax = cpl_table_unwrap(tab,"LAMBDA_MAX"); + + cpl_vector * wmin = cpl_vector_wrap(nrow, pwmin); + cpl_vector * wmax = cpl_vector_wrap(nrow, pwmax); + cpl_bivector * to_ret = cpl_bivector_wrap_vectors(wmin, wmax); + cpl_table_delete(tab); + sinfo_print_rec_status(0); + return to_ret; +} + +static cpl_array * +sinfo_read_fit_points(const cpl_frame * frm_fit_points, + const double ra, const double dec, const double ra_dec_tolerance){ + + cpl_ensure(frm_fit_points != NULL, CPL_ERROR_NULL_INPUT, NULL); + const char * fname = cpl_frame_get_filename(frm_fit_points); + + cpl_table * index_table = cpl_table_load(fname, 1, CPL_FALSE); + const cpl_size sz = cpl_table_get_nrow(index_table); + + cpl_size selected_ext = -1; + + for(cpl_size i = 0; i < sz; ++i){ + int rej; + const int ext_id = cpl_table_get_int(index_table, "ext_id", i ,&rej); + const double curr_ra = cpl_table_get(index_table, "ra", i, &rej); + const double curr_dec = cpl_table_get(index_table, "dec", i, &rej); + if ((ext_id > 0) && (fabs(curr_ra - ra) < ra_dec_tolerance) && + (fabs(curr_dec - dec) < ra_dec_tolerance)){ + selected_ext = ext_id; + } + } + + cpl_table_delete(index_table); + cpl_ensure(selected_ext >= 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL); + + + cpl_table * tb = cpl_table_load(fname, selected_ext, CPL_FALSE); + + const cpl_size sz_points = cpl_table_get_nrow(tb); + cpl_array * fit_points = cpl_array_new(sz_points, CPL_TYPE_DOUBLE); + + for(cpl_size i = 0; i < sz_points; ++i){ + int rej = 0; + const double d = cpl_table_get(tb, "LAMBDA", i, &rej); + cpl_array_set(fit_points, i, d); + } + + cpl_table_delete(tb); + return fit_points; +} + +static inline cpl_size +get_before(const double wmin_spectrum, const double wmin_interval, const double step){ + const double num = (wmin_spectrum - wmin_interval) / step; + if(num <= 0) return 0; + return (cpl_size) ceil(num); +} + +static inline cpl_size +get_after(const double wmax_spectrum, const double wmax_interval, const double step){ + const double num = (wmax_interval - wmax_spectrum) / step; + if(num <= 0) return 0; + return (cpl_size) ceil(num); +} + +static inline +hdrl_spectrum1D * extend_hdrl_spectrum(const double wmin, const double wmax, + const hdrl_spectrum1D * s){ + + cpl_ensure(wmin < wmax, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(s != NULL, CPL_ERROR_NULL_INPUT, NULL); + + const cpl_array * lambadas_s = hdrl_spectrum1D_get_wavelength(s).wavelength; + const double s_wmin = cpl_array_get_min(lambadas_s); + const double s_wmax = cpl_array_get_max(lambadas_s); + + const cpl_size sz_s = cpl_array_get_size(lambadas_s); + const double step = (s_wmax - s_wmin)/sz_s; + + sinfo_msg("min=%g max=%g step=%g",s_wmin,s_wmax,step); + cpl_size n_before = get_before(s_wmin, wmin, step); + cpl_size n_after = get_after(s_wmax, wmax, step); + + const cpl_size new_size = n_before + n_after + sz_s; + cpl_array * new_lambdas = cpl_array_new(new_size, + cpl_array_get_type(lambadas_s)); + hdrl_image * new_flux = hdrl_image_new(new_size, 1); + + double lambda = s_wmin; + for(cpl_size i = n_before - 1; i >= 0; i--){ + lambda -= step; + cpl_array_set(new_lambdas, i, lambda); + hdrl_image_reject(new_flux, i + 1, 1); + } + + lambda = s_wmax; + for(cpl_size i = n_before + sz_s; i < new_size; i++){ + lambda += step; + cpl_array_set(new_lambdas, i, lambda); + hdrl_image_reject(new_flux, i + 1, 1); + } + + for(cpl_size i = n_before; i < n_before + sz_s; i++){ + const cpl_size idx_ori = i - n_before; + int rej = 0; + const double lambda = + hdrl_spectrum1D_get_wavelength_value(s, idx_ori, &rej); + cpl_array_set(new_lambdas, i, lambda); + + if(rej) { + hdrl_image_reject(new_flux, i + 1, 1); + continue; + } + + hdrl_value val = hdrl_spectrum1D_get_flux_value(s, idx_ori, NULL); + hdrl_image_set_pixel(new_flux, i + 1, 1, val); + } + + const hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_get_scale(s); + + hdrl_spectrum1D * to_ret = + hdrl_spectrum1D_create(hdrl_image_get_image(new_flux), + hdrl_image_get_error(new_flux), + new_lambdas, + scale); + + + cpl_array_delete(new_lambdas); + hdrl_image_delete(new_flux); + + return to_ret; +} + +int sinfo_can_compute_response(cpl_frameset* sof) { + + int has_std_star_spectra=1; + int has_flux_std_catalog=1; + int has_tel_mod_catalog=1; + int has_resp_fit_points_cat=1; + int has_extcoeff_table=1; + int has_high_abs_regions=1; + int has_quality_areas=1; + int has_fit_areas=1; + int has_resp_windows=1; + + if (NULL == cpl_frameset_find(sof, PRO_STD_STAR_SPECTRA) ){ + sinfo_msg_warning("Provide %s to do compute response.",PRO_STD_STAR_SPECTRA); + has_std_star_spectra=0; + } + + if (NULL == cpl_frameset_find(sof, FLUX_STD_CATALOG) ){ + sinfo_msg_warning("Provide %s to do compute response.",FLUX_STD_CATALOG); + has_flux_std_catalog=0; + } + if (NULL == cpl_frameset_find(sof, TELL_MOD_CATALOG) ){ + sinfo_msg_warning("Provide %s to do compute response.",TELL_MOD_CATALOG); + has_tel_mod_catalog=0; + } + if (NULL == cpl_frameset_find(sof, RESP_FIT_POINTS_CAT) ){ + sinfo_msg_warning("Provide %s to do compute response.",RESP_FIT_POINTS_CAT); + has_resp_fit_points_cat=0; + } + + if (NULL == cpl_frameset_find(sof, EXTCOEFF_TABLE) ){ + sinfo_msg_warning("Provide %s to do compute response.",EXTCOEFF_TABLE); + has_extcoeff_table=0; + } + + if (NULL == cpl_frameset_find(sof, HIGH_ABS_REGIONS) ){ + sinfo_msg_warning("Frame %s not provided to do compute response.",HIGH_ABS_REGIONS); + has_high_abs_regions=1; + //return 0; + } + + if (NULL == cpl_frameset_find(sof, QUALITY_AREAS) ){ + sinfo_msg_warning("Provide %s to do compute response.",QUALITY_AREAS); + has_quality_areas=0; + } + + if (NULL == cpl_frameset_find(sof, FIT_AREAS) ){ + sinfo_msg_warning("Provide %s to do compute response.",FIT_AREAS); + has_fit_areas=0; + } + + if (NULL == cpl_frameset_find(sof, RESPONSE_WINDOWS) ){ + sinfo_msg_warning("Provide %s to do compute response.",RESPONSE_WINDOWS); + has_resp_windows=0; + } + + return has_std_star_spectra * + has_flux_std_catalog * + has_tel_mod_catalog * + has_resp_fit_points_cat * + has_extcoeff_table * + has_high_abs_regions * + has_quality_areas * + has_fit_areas * + has_resp_windows; + +} + +int sinfo_can_flux_calibrate(cpl_frameset* sof) { + + + int has_extcoeff_table=1; + int has_response=1; + if (NULL == cpl_frameset_find(sof, EXTCOEFF_TABLE) ){ + sinfo_msg_warning("Provide %s to do flux calibration.",EXTCOEFF_TABLE); + has_extcoeff_table=0; + } + + if (NULL == cpl_frameset_find(sof, PRO_RESPONSE) ) { + sinfo_msg_warning("Provide %s to do flux calibration.",PRO_RESPONSE); + has_response=0; + + } + return has_extcoeff_table * has_response; +} + +cpl_error_code +sinfo_flux_calibrate_spectra(const char* plugin_id, cpl_parameterlist* config, + cpl_frameset* ref_set, cpl_frameset* sof){ + + /* Flux calibrate the spectrum */ + const char* fname; + + hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + //cpl_frame* response=cpl_frameset_find(sof, PRO_RESPONSE); + cpl_frame* spectra_frm=cpl_frameset_find(sof, PRO_STD_STAR_SPECTRA); + fname = cpl_frame_get_filename(spectra_frm); + cpl_table* spectra_tab=cpl_table_load(fname,1,0); + char band[FILE_NAME_SZ]; + sinfo_get_band(spectra_frm,band); + double bin_size=sinfo_get_dispersion(band); + sinfo_msg("bin_size=%g",bin_size); + double um2nm=1.e3; + double nm2AA=10; + double bin_size_scale_factor=bin_size*um2nm*nm2AA; + + //double sci_wmin=cpl_table_get_column_min(spectra_tab,"wavelength"); + //double sci_wmax=cpl_table_get_column_max(spectra_tab,"wavelength"); + + + cpl_propertylist* plist=cpl_propertylist_load(fname,0); + double dit = sinfo_pfits_get_dit(plist); + //int ndit = sinfo_pfits_get_ndit(plist); + double exptime = dit; // for NIR (SINFONI data) we use only DIT + double gain = 2.42; // sinfo_pfits_get_gain(plist); + double airm = sinfo_pfits_get_airm_mean(plist); + sinfo_free_propertylist(&plist); + + double factor=1./(gain*exptime*bin_size_scale_factor); + + + hdrl_spectrum1D * obs_s1d = + hdrl_spectrum1D_convert_from_table(spectra_tab, "counts_bkg", + "wavelength", NULL, NULL, scale); + //hdrl_spectrum1D_save(obs_s1d, "obs_s1d.fits"); + + cpl_frame* resp_frm=cpl_frameset_find(sof, PRO_RESPONSE); + fname = cpl_frame_get_filename(resp_frm); + cpl_table* resp_tab=cpl_table_load(fname,1,0); + + hdrl_spectrum1D * resp_s1d = + hdrl_spectrum1D_convert_from_table(resp_tab, "response_smo", + "wavelength", "response_smo_error", "response_smo_bpm", scale); + //hdrl_spectrum1D_save(resp_s1d, "resp_s1d.fits"); + + + cpl_frame* atm_ext_frm=cpl_frameset_find(sof, EXTCOEFF_TABLE); + fname = cpl_frame_get_filename(atm_ext_frm); + cpl_table* atm_ext_tab=cpl_table_load(fname,1,0); + + hdrl_spectrum1D * ext_s1d = + hdrl_spectrum1D_convert_from_table(atm_ext_tab, "EXTINCTION", + "LAMBDA", NULL, NULL, scale); + + //hdrl_spectrum1D * ext_s1d_e = extend_hdrl_spectrum(sci_wmin * um2nm, sci_wmax * um2nm, ext_s1d); + //hdrl_spectrum1D_save(ext_s1d_e, "ext_s1d_e.fits"); + + //sinfo_msg("factor=%g", factor); + + cpl_msg_warning("","%f %f", cpl_array_get_min(hdrl_spectrum1D_get_wavelength(obs_s1d).wavelength), cpl_array_get_max(hdrl_spectrum1D_get_wavelength(obs_s1d).wavelength)); + cpl_msg_warning("","%f %f", cpl_array_get_min(hdrl_spectrum1D_get_wavelength(resp_s1d).wavelength), cpl_array_get_max(hdrl_spectrum1D_get_wavelength(resp_s1d).wavelength)); + + + hdrl_spectrum1D* flux_s1d = hdrl_spectrum1D_mul_spectrum_create(obs_s1d, resp_s1d); + + hdrl_spectrum1D_mul_scalar(flux_s1d,(hdrl_value){factor,0.}); + + //hdrl_spectrum1D_save(flux_s1d, "flux_s1d_0.fits"); + + double* pflux = cpl_image_get_data_double(hdrl_image_get_image(flux_s1d->flux)); + int sx=hdrl_image_get_size_x(flux_s1d->flux); + + + double* pext = cpl_image_get_data_double(hdrl_image_get_image(ext_s1d->flux)); + for(int i=0;iflux); + double* pext = cpl_image_get_data_double(hdrl_image_get_image(ext_s1d->flux)); + + /* Flux calibrate the cube */ + + double* presp = cpl_image_get_data_double(hdrl_image_get_image(resp_s1d->flux)); + + + /* + hdrl_value exp = {-0.4*airm, 0}; + hdrl_spectrum1D* ext_s1d_cor = + hdrl_spectrum1D_mul_scalar_create(ext_s1d, exp); + hdrl_spectrum1D_pow_scalar(ext_s1d_cor, ) + */ + + for(int i=0;i0) { + resp_avg=cpl_table_get_column_mean(tmp_resp,"response_smo"); + resp_med=cpl_table_get_column_median(tmp_resp,"response_smo"); + resp_min=cpl_table_get_column_min(tmp_resp,"response_smo"); + resp_max=cpl_table_get_column_max(tmp_resp,"response_smo"); + resp_std=cpl_table_get_column_stdev(tmp_resp,"response_smo"); + /* + sinfo_msg("wmin=%g wmax=%g avg=%g med=%g min=%g max=%g std=%g", + wmin, wmax, resp_avg,resp_med,resp_min,resp_max,resp_std); + */ + sprintf(key_name,"QC RESP WIN%d WLMIN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmin, + "[um] Min window wavelength for resp comp"); + + sprintf(key_name,"QC RESP WIN%d WLMAX",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmax, + "[um] Max window wavelength for resp comp"); + + + sprintf(key_name,"QC RESP WIN%d MEAN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_avg, + "Mean response on window"); + + sprintf(key_name,"QC RESP WIN%d MEDIAN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_med, + "Median response on window"); + + sprintf(key_name,"QC RESP WIN%d MIN",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_min, + "Min response on window"); + + sprintf(key_name,"QC RESP WIN%d MAX",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_max, + "Max response on window"); + + sprintf(key_name,"QC RESP WIN%d RMS",i); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_std, + "RMS response on window"); + } + cpl_table_select_all(resp); + sinfo_free_table(&tmp_resp); + + } + cpl_table_select_all(resp); + wmin=cpl_table_get_column_min(ew_tab,"WMIN"); + wmax=cpl_table_get_column_max(ew_tab,"WMAX"); + cpl_table_and_selected_double(resp,"wavelength",CPL_NOT_LESS_THAN,wmin_g); + cpl_table_and_selected_double(resp,"wavelength",CPL_NOT_GREATER_THAN,wmax_g); + tmp_resp=cpl_table_extract_selected(resp); + + resp_avg=cpl_table_get_column_mean(tmp_resp,"response_smo"); + resp_med=cpl_table_get_column_median(tmp_resp,"response_smo"); + resp_min=cpl_table_get_column_min(tmp_resp,"response_smo"); + resp_max=cpl_table_get_column_max(tmp_resp,"response_smo"); + resp_std=cpl_table_get_column_stdev(tmp_resp,"response_smo"); + /* + sinfo_msg("wmin=%g wmax=%g avg=%g med=%g min=%g max=%g std=%g", + wmin, wmax,resp_avg,resp_med,resp_min,resp_max,resp_std); + */ + sprintf(key_name,"QC RESP WLMIN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmin, + "[um] Min wavelength for resp comp"); + + sprintf(key_name,"QC RESP WLMAX"); + sinfo_qclog_add_double(*qclog_tbl, key_name, wmax, + "[um] Max wavelength for resp comp"); + + sprintf(key_name,"QC RESP MEAN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_avg, + "Mean response"); + + sprintf(key_name,"QC RESP MEDIAN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_med, + "Median response"); + + sprintf(key_name,"QC RESP MIN"); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_min, + "Min response"); + + sprintf(key_name,"QC RESP MAX"); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_max, + "Max response"); + + sprintf(key_name,"QC RESP RMS"); + sinfo_qclog_add_double(*qclog_tbl, key_name, resp_std, + "RMS response"); + sinfo_free_table(&tmp_resp); + sinfo_free_table(&ew_tab); + sinfo_print_rec_status(0); + return cpl_error_get_code(); +} + +cpl_error_code +sinfo_response_compute(const char* plugin_id, cpl_parameterlist* config, + cpl_frameset* ref_set,cpl_frameset* sof) +{ + + + cpl_frame* frm_sci = cpl_frameset_find(sof, PRO_STD_STAR_SPECTRA); + cpl_frame* frm_std_cat = cpl_frameset_find(sof, FLUX_STD_CATALOG); + cpl_frame* frm_atmext = cpl_frameset_find(sof, EXTCOEFF_TABLE); + cpl_frame* frm_tell_cat = cpl_frameset_find(sof, TELL_MOD_CATALOG); + cpl_frame* frm_resp_fit_points = cpl_frameset_find(sof, RESP_FIT_POINTS_CAT); + cpl_frame* frm_high_abs_reg = cpl_frameset_find(sof, HIGH_ABS_REGIONS); + cpl_frame* frm_resp_quality_areas = cpl_frameset_find(sof, QUALITY_AREAS); + cpl_frame* frm_resp_fit_areas = cpl_frameset_find(sof, FIT_AREAS); + + cpl_ensure(frm_sci != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + cpl_ensure(frm_std_cat != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + cpl_ensure(frm_atmext != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + cpl_ensure(frm_tell_cat != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + cpl_ensure(frm_resp_fit_points != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + /* HIGH_ABS_REGIONS is an optional input + cpl_ensure(frm_high_abs_reg != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + */ + cpl_ensure(frm_resp_quality_areas != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + cpl_ensure(frm_resp_fit_areas != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + + const char* name_sci=NULL; + cpl_propertylist* plist=NULL; + cpl_table* sci_tab=NULL; + name_sci=cpl_frame_get_filename(frm_sci); + plist=cpl_propertylist_load(name_sci,0); + double dRA=sinfo_pfits_get_ra(plist); + double dDEC=sinfo_pfits_get_dec(plist); + sci_tab=cpl_table_load(name_sci,1,0); + double sci_wmin=cpl_table_get_column_min(sci_tab,"wavelength"); + double sci_wmax=cpl_table_get_column_max(sci_tab,"wavelength"); + sinfo_free_table(&sci_tab); + //cpl_table* resp=NULL; + + + //hdrl_spectrum1D * eff_s1d; + + double um2nm=1.e3; + + hdrl_spectrum1D * sci_s1d = sinfo_sci_frame_to_hdrl_spectrum1D(frm_sci); + + + /* HDRL expects results in nm */ + hdrl_spectrum1D_wavelength_mult_scalar_linear(sci_s1d,um2nm); + + /* because the reference flux std assumes the flux in units of ergs/cm2/s/A + * we need to convert the spectrum to Angstroms and know the size of a bin + * in angstroms + */ + char band[FILE_NAME_SZ]; + sinfo_get_band(frm_sci,band); + + double conv_factor=0; + double nm2AA = 10.; + /* the following is the bin size in um */ + double bin_size=sinfo_get_dispersion(band); + sinfo_msg("bin_size=%g",bin_size); + conv_factor=bin_size*um2nm*nm2AA; + + hdrl_spectrum1D_div_scalar(sci_s1d,(hdrl_value){conv_factor,0.}); + + hdrl_spectrum1D * std_s1d = sinfo_std_cat_frame_to_hdrl_spectrum1D(frm_std_cat,dRA,dDEC); + + cpl_ensure(std_s1d != NULL, CPL_ERROR_NULL_INPUT, CPL_ERROR_NULL_INPUT); + + hdrl_spectrum1D * ext_s1d = sinfo_atmext_frame_to_hdrl_spectrum1D(frm_atmext); + + + //hdrl_parameter* eff_pars; + /*HDRL expects telescope area in cm2 */ + + hdrl_spectrum1Dlist * telluric_models = + sinfo_get_telluric_models(frm_tell_cat); + + + cpl_bivector * fit_areas = sinfo_read_wlen_windows(frm_resp_fit_areas); + cpl_bivector * quality_areas = sinfo_read_wlen_windows(frm_resp_quality_areas); + cpl_bivector * high_abs_regions = NULL; + + if(frm_high_abs_reg!= NULL) + high_abs_regions = sinfo_read_wlen_windows(frm_high_abs_reg); + + + + + + /* set [parameters */ + double wmin=0; + double wmax=0; + cpl_boolean velocity_enable = CPL_TRUE; + if (strcmp(band,"J") == 0) { + //J + wmin=7.001; //log scale + wmax=7.100; + velocity_enable = CPL_TRUE; + } else if (strcmp(band,"H") == 0) { + //H + wmin=7.268; //log scale + wmax=7.531; + velocity_enable = CPL_FALSE; + } else if (strcmp(band,"K") == 0) { + //K + wmin=7.565; //log scale + wmax=7.812; + velocity_enable = CPL_FALSE; + } else if (strcmp(band,"H+K") == 0) { + //HK + wmin=7.268; //log scale + wmax=7.812; + velocity_enable = CPL_FALSE; + } + + //sinfo_msg("band=%s wmin=%g wmax=%g",band,wmin,wmax); + + const hdrl_data_t lmin = (hdrl_data_t)wmin; + const hdrl_data_t lmax = (hdrl_data_t)wmax; + + + const cpl_boolean xcorr_normalize = (cpl_boolean) CPL_TRUE; + const cpl_boolean shift_in_log_scale = (cpl_boolean) CPL_TRUE; + + const hdrl_data_t wguess = 1094.12; // um + const hdrl_data_t range_wmin =1000; + const hdrl_data_t range_wmax =1200; + const hdrl_data_t fit_wmin = 1090; + const hdrl_data_t fit_wmax = 1100; + const hdrl_data_t fit_half_win = 1.5; + + hdrl_parameter* shift_par = NULL; + if(velocity_enable) { + shift_par = hdrl_spectrum1D_shift_fit_parameter_create(wguess, range_wmin, + range_wmax, fit_wmin, fit_wmax,fit_half_win); + } + + + hdrl_parameter* resp_calc_par = sinfo_response_parameters_calc_par(plist); + + double ra_dec_tolerance=0.1; + cpl_array * fit_points = sinfo_read_fit_points(frm_resp_fit_points, + dRA, dDEC, ra_dec_tolerance); + + hdrl_parameter * telluric_par=NULL; + if(telluric_models != NULL && quality_areas != NULL && fit_areas != NULL) { + const cpl_size xcorr_half_win = 200; + hdrl_data_t xcorr_w_step=1e-5; + telluric_par = hdrl_response_telluric_evaluation_parameter_create(telluric_models, + xcorr_w_step, xcorr_half_win, xcorr_normalize, shift_in_log_scale, quality_areas, + fit_areas, lmin, lmax); + } + + const cpl_size post_smoothing_radius=11; + + //TODO: fill following params + const hdrl_data_t fit_wrange=4.0; + hdrl_parameter* resp_par = + hdrl_response_fit_parameter_create(post_smoothing_radius, fit_points, + fit_wrange, high_abs_regions); + + hdrl_spectrum1D * std_s1d_e = extend_hdrl_spectrum(sci_wmin * um2nm, sci_wmax * um2nm, std_s1d); + hdrl_spectrum1D * ext_s1d_e = extend_hdrl_spectrum(sci_wmin * um2nm, sci_wmax * um2nm, ext_s1d); + + hdrl_response_result * response = + hdrl_response_compute(sci_s1d,std_s1d_e,ext_s1d_e,telluric_par,shift_par, + resp_calc_par,resp_par); + sinfo_msg("size sci = %lld size resp = %lld", + hdrl_spectrum1D_get_size(sci_s1d), + hdrl_spectrum1D_get_size(response->final_response)); + + hdrl_spectrum1D_delete(&std_s1d_e); + hdrl_spectrum1D_delete(&ext_s1d_e); + /* extends response to same wavelength range as observed sci to flux-cal */ + + + + if(response != NULL){ + + const hdrl_spectrum1D * resp_s1d_smo = + hdrl_response_result_get_final_response(response); + + const hdrl_spectrum1D * resp_s1d_raw = + hdrl_response_result_get_raw_response(response); + //sinfo_msg("wmin=%g wmax=%g",sci_wmin,sci_wmax); + + + + cpl_table* tab=hdrl_spectrum1D_convert_to_table(resp_s1d_smo, + "response", "wavelength", "response_error", "response_bpm"); + + sci_wmin=cpl_table_get_column_min(tab,"wavelength"); + sci_wmax=cpl_table_get_column_max(tab,"wavelength"); + //sinfo_msg("wmin=%g wmax=%g",sci_wmin,sci_wmax); + + cpl_table* resp_smo=NULL; + cpl_table* resp_raw=NULL; + cpl_table* resp_pts=NULL; + resp_smo = hdrl_spectrum1D_convert_to_table(resp_s1d_smo, + "response_smo", "wavelength", "response_smo_error", + "response_smo_bpm"); + + resp_raw = hdrl_spectrum1D_convert_to_table(resp_s1d_raw, + "response_raw", "wavelength", "response_raw_error", + "response_raw_bpm"); + + resp_pts = hdrl_spectrum1D_convert_to_table( + hdrl_response_result_get_selected_response(response), + "response_fit_pts", "wavelength", "response_fit_pts_error", + "response_fit_pts_bpm"); + sinfo_free_table(&tab); + + + const double um2nm = 1e3; + cpl_table_divide_scalar(resp_smo,"wavelength",um2nm); + cpl_table_divide_scalar(resp_raw,"wavelength",um2nm); + cpl_table_divide_scalar(resp_pts,"wavelength",um2nm); + + cpl_table* qclog_tbl = sinfo_qclog_init(); + cpl_frame* frm_resp_wind_qc = cpl_frameset_find(sof, RESPONSE_WINDOWS); + + const hdrl_spectrum1D * selected_points = hdrl_response_result_get_selected_response(response); + const cpl_array * waves = hdrl_spectrum1D_get_wavelength(selected_points).wavelength; + const double wmin_g = cpl_array_get_min(waves)/um2nm; + const double wmax_g = cpl_array_get_max(waves)/um2nm; + //sinfo_msg("good wavelengths wmin=%g wmax=%g",wmin_g,wmax_g); + + + if( resp_smo != NULL && frm_resp_wind_qc != NULL) { + + sinfo_resp_qc(resp_smo, frm_resp_wind_qc, wmin_g, wmax_g, &qclog_tbl); + + } + + sinfo_pro_save_tbl(resp_smo, ref_set, sof,(char*) RESPONSE_FILENAME, + PRO_RESPONSE, qclog_tbl, plugin_id, config); + + cpl_table_save(resp_raw,NULL,NULL,RESPONSE_FILENAME,CPL_IO_EXTEND); + cpl_table_save(resp_pts,NULL,NULL,RESPONSE_FILENAME,CPL_IO_EXTEND); + cpl_table_delete(qclog_tbl); + cpl_table_delete(resp_smo); + cpl_table_delete(resp_raw); + cpl_table_delete(resp_pts); + + } + cpl_bivector_delete(quality_areas); + cpl_bivector_delete(fit_areas); + cpl_bivector_delete(high_abs_regions); + + hdrl_parameter_delete(telluric_par); + hdrl_parameter_delete(shift_par); + hdrl_parameter_delete(resp_calc_par); + hdrl_parameter_delete(resp_par); + + hdrl_spectrum1D_delete(&sci_s1d); + hdrl_spectrum1D_delete(&std_s1d); + hdrl_spectrum1D_delete(&ext_s1d); + sinfo_free_propertylist(&plist); + hdrl_spectrum1Dlist_delete(telluric_models); + + + cpl_array_delete(fit_points); + hdrl_response_result_delete(response); + sinfo_print_rec_status(0); + return cpl_error_get_code(); +} + + + cpl_table* sinfo_efficiency_compute(cpl_frame* frm_sci, cpl_frame* frm_cat, @@ -660,57 +1690,111 @@ cpl_table* tbl_eff=NULL; cpl_table* tbl_ref=NULL; cpl_table* tbl_atmext=NULL; - cpl_table* tbl_sci=NULL; + cpl_table* sci_tab=NULL; + - double exptime=600; double airmass=0; double airmass_start=0; double airmass_end=0; double dRA=0; double dDEC=0; double gain=0; - double aimprim=0; + //double aimprim=0; double dEpsilon=0.1; - double um2AA=1.e4; + //double um2AA=1.e4; + double um2nm=1000.; + double nm2um=0.001; + double m2tocm2=1.e4; /* int nrow=0; */ - int biny=1; + const char* name_sci=NULL; const char* name_atm=NULL; name_sci=cpl_frame_get_filename(frm_sci); - sinfo_msg("name_sci=%s",name_sci); - check_nomsg(plist=cpl_propertylist_load(name_sci,0)); - check_nomsg(tbl_sci=cpl_table_load(name_sci,1,0)); - check_nomsg(dRA=sinfo_pfits_get_ra(plist)); + plist=cpl_propertylist_load(name_sci,0); + sci_tab=cpl_table_load(name_sci,1,0); + dRA=sinfo_pfits_get_ra(plist); dDEC=sinfo_pfits_get_dec(plist); airmass_start=sinfo_pfits_get_airmass_end(plist); - airmass_end=sinfo_pfits_get_airmass_end(plist); - airmass=0.5*(airmass_start+airmass_end); + airmass_end=sinfo_pfits_get_airmass_end(plist); + airmass=0.5*(airmass_start+airmass_end); gain=2.42; - biny=1; - check_nomsg(exptime=sinfo_pfits_get_dit(plist)); + //int biny=1; + double exptime=sinfo_pfits_get_dit(plist); sinfo_free_propertylist(&plist); sinfo_msg("gain=%g airm=%g exptime=%g airmass=%g ra=%g dec=%g", gain,airmass,exptime,airmass,dRA,dDEC); sinfo_msg("table sci spectra=%s",name_sci); - /* nrow=cpl_table_get_nrow(tbl_sci); */ - check_nomsg(name_atm=cpl_frame_get_filename(frm_atmext)); - check_nomsg(tbl_atmext=cpl_table_load(name_atm,1,0)); + name_atm=cpl_frame_get_filename(frm_atmext); + tbl_atmext=cpl_table_load(name_atm,1,0); - check_nomsg(sinfo_parse_catalog_std_stars(frm_cat,dRA,dDEC,dEpsilon,&tbl_ref)); + sinfo_parse_catalog_std_stars(frm_cat,dRA,dDEC,dEpsilon,&tbl_ref); if(tbl_ref == NULL) { sinfo_msg_error("Provide std sar catalog frame"); return NULL; - //cpl_table_dump(tbl_ref,0,3,stdout); } - check_nomsg(cpl_table_save(tbl_sci,NULL,NULL,"sci.fits",CPL_IO_DEFAULT)); - check_nomsg(tbl_eff=sinfo_utl_efficiency_internal(tbl_sci,tbl_atmext,tbl_ref, + cpl_table_save(sci_tab,NULL,NULL,"sci.fits",CPL_IO_DEFAULT); + + + hdrl_spectrum1D * sci_s1d; + hdrl_spectrum1D * std_s1d; + hdrl_spectrum1D * ext_s1d; + hdrl_spectrum1D * eff_s1d; + hdrl_spectrum1D_wave_scale scale = hdrl_spectrum1D_wave_scale_linear; + + sci_s1d=hdrl_spectrum1D_convert_from_table(sci_tab, "counts_bkg", + "wavelength", NULL, NULL, scale); + /* HDRL expects results in nm */ + hdrl_spectrum1D_wavelength_mult_scalar_linear(sci_s1d,um2nm); + + /* because the reference flux std assumes the flux in units of ergs/cm2/s/A + * we need to convert the spectrum to Angstroms and know the size of a bin + * in angstroms + */ + char band[FILE_NAME_SZ]; + sinfo_get_band(frm_sci,band); + + double conv_factor=0; + double nm2AA = 10.; + double um2AA = um2nm * nm2AA; + /* the following is the bin size in um */ + double bin_size=sinfo_get_dispersion(band); + conv_factor=bin_size*um2nm*nm2AA; + + hdrl_spectrum1D_div_scalar(sci_s1d,(hdrl_value){conv_factor,0.}); + std_s1d=hdrl_spectrum1D_convert_from_table(tbl_ref, "FLUX", + "LAMBDA", NULL, NULL, scale); + + ext_s1d=hdrl_spectrum1D_convert_from_table(tbl_atmext, "EXTINCTION", + "LAMBDA", NULL, NULL, scale); + + hdrl_parameter* eff_pars; + + hdrl_value Ap = {0}; + hdrl_value Am = {airmass}; + hdrl_value G= {gain}; + hdrl_value Tex= {exptime}; + /*HDRL expects telescope area in cm2 */ + hdrl_value Atel={TELESCOPE_SURFACE*m2tocm2}; + + eff_pars = hdrl_efficiency_parameter_create(Ap, Am, G,Tex, Atel); + + + eff_s1d = hdrl_efficiency_compute(sci_s1d, std_s1d, ext_s1d, eff_pars); + /* HDRL expects results in nm */ + hdrl_spectrum1D_wavelength_mult_scalar_linear(eff_s1d,nm2um); + cpl_propertylist_delete(plist); + tbl_eff=hdrl_spectrum1D_convert_to_table(eff_s1d, "EFF", "WAVE", NULL,NULL); + cpl_table_save(tbl_eff,NULL,NULL,"efficiency.fits",CPL_IO_DEFAULT); + + /* + check_nomsg(tbl_eff=sinfo_utl_efficiency_internal(sci_tab,tbl_atmext,tbl_ref, exptime,airmass,aimprim,gain, biny,um2AA, "LAMBDA", @@ -720,8 +1804,15 @@ "BIN_WIDTH", "wavelength", "counts_bkg")); + */ cleanup: + hdrl_spectrum1D_delete(&std_s1d); + hdrl_spectrum1D_delete(&sci_s1d); + hdrl_spectrum1D_delete(&ext_s1d); + hdrl_spectrum1D_delete(&eff_s1d); + hdrl_parameter_delete(eff_pars); + sinfo_free_table(&sci_tab); sinfo_free_table(&tbl_ref); sinfo_free_table(&tbl_atmext); sinfo_free_propertylist(&plist); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_utl_efficiency.h cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_utl_efficiency.h --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/sinfo_utl_efficiency.h 2010-02-08 07:18:21.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/sinfo_utl_efficiency.h 2017-09-09 11:30:42.000000000 +0000 @@ -87,5 +87,17 @@ cpl_frame* frm_cat, cpl_frame* frm_atmext); +cpl_error_code +sinfo_response_compute(const char* plugin_id, cpl_parameterlist* config, + cpl_frameset* ref_set,cpl_frameset* sof); +cpl_error_code +sinfo_flux_calibrate_spectra(const char* plugin_id, + cpl_parameterlist* config, cpl_frameset* ref_set, cpl_frameset* sof); + +cpl_error_code +sinfo_flux_calibrate_cube(const char* procatg, const char* plugin_id, + cpl_parameterlist* config, cpl_frameset* ref_set, cpl_frameset* sof); +int sinfo_can_flux_calibrate(cpl_frameset* sof); +int sinfo_can_compute_response(cpl_frameset* sof); #endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/Makefile.am cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/Makefile.am --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/Makefile.am 2017-01-04 17:11:09.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/Makefile.am 2017-05-05 14:18:29.000000000 +0000 @@ -30,11 +30,11 @@ #LIBSINFONI = $(top_builddir)/sinfoni/libsinfo.la #AM_CPPFLAGS = -I$(top_builddir)/sinfoni -I$(top_builddir)/irplib -AM_CPPFLAGS = $(all_includes) +AM_CPPFLAGS = $(all_includes) $(GSL_INCLUDES) LDADD = $(LIBSINFONI) -AM_LDFLAGS = -static +AM_LDFLAGS = -static $(GSL_LDFLAGS) -noinst_HEADERS = +noinst_HEADERS = sinfo_eff_resp.h check_PROGRAMS = sinfo_skycor_test \ sinfo_strehl_test \ @@ -55,7 +55,9 @@ sinfo_baryvel_test \ sinfo_intensity_scale_test \ sinfo_find_lines_test \ - sinfo_arc_lamp_simul_test + sinfo_arc_lamp_simul_test \ + sinfo_response_test \ + sinfo_compute_efficiency_test TESTS = sinfo_skycor_test sinfo_strehl_test sinfo_cube_coadd_test \ sinfo_image_ops_test sinfo_cube_ops_test sinfo_table_ops_test \ @@ -63,8 +65,11 @@ sinfo_star_index_test sinfo_star_catalog sinfo_line_corr_test \ test_atmo_disp sinfo_cube_measure_centroid_test sinfo_absolute_test \ sinfo_boltzmann_test sinfo_baryvel_test sinfo_intensity_scale_test \ - sinfo_find_lines_test sinfo_arc_lamp_simul_test + sinfo_find_lines_test sinfo_arc_lamp_simul_test sinfo_response_test +# sinfo_compute_efficiency_test +sinfo_response_test_SOURCES = sinfo_response_test.c sinfo_eff_resp.c +sinfo_compute_efficiency_test_SOURCES = sinfo_compute_efficiency_test.c sinfo_eff_resp.c sinfo_arc_lamp_simul_test_SOURCES = sinfo_arc_lamp_simul_test.c sinfo_find_lines_test_SOURCES = sinfo_find_lines_test.c sinfo_intensity_scale_test_SOURCES = sinfo_intensity_scale_test.c @@ -93,6 +98,7 @@ OBJEXT="$(OBJEXT)" EXEEXT="$(EXEEXT)" + # We need to remove any files that the above tests created. clean-local: $(RM) *.fits *.log diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/Makefile.in cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/Makefile.in --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/Makefile.in 2017-04-20 15:53:05.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/Makefile.in 2018-04-13 15:46:37.000000000 +0000 @@ -101,7 +101,9 @@ sinfo_baryvel_test$(EXEEXT) \ sinfo_intensity_scale_test$(EXEEXT) \ sinfo_find_lines_test$(EXEEXT) \ - sinfo_arc_lamp_simul_test$(EXEEXT) + sinfo_arc_lamp_simul_test$(EXEEXT) \ + sinfo_response_test$(EXEEXT) \ + sinfo_compute_efficiency_test$(EXEEXT) TESTS = sinfo_skycor_test$(EXEEXT) sinfo_strehl_test$(EXEEXT) \ sinfo_cube_coadd_test$(EXEEXT) sinfo_image_ops_test$(EXEEXT) \ sinfo_cube_ops_test$(EXEEXT) sinfo_table_ops_test$(EXEEXT) \ @@ -114,11 +116,13 @@ sinfo_baryvel_test$(EXEEXT) \ sinfo_intensity_scale_test$(EXEEXT) \ sinfo_find_lines_test$(EXEEXT) \ - sinfo_arc_lamp_simul_test$(EXEEXT) + sinfo_arc_lamp_simul_test$(EXEEXT) \ + sinfo_response_test$(EXEEXT) subdir = sinfoni/tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4macros/cpl.m4 \ - $(top_srcdir)/m4macros/eso.m4 \ + $(top_srcdir)/m4macros/eso.m4 $(top_srcdir)/m4macros/gsl.m4 \ + $(top_srcdir)/m4macros/hdrl.m4 \ $(top_srcdir)/m4macros/libtool.m4 \ $(top_srcdir)/m4macros/ltoptions.m4 \ $(top_srcdir)/m4macros/ltsugar.m4 \ @@ -156,6 +160,13 @@ sinfo_boltzmann_test_OBJECTS = $(am_sinfo_boltzmann_test_OBJECTS) sinfo_boltzmann_test_LDADD = $(LDADD) sinfo_boltzmann_test_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_sinfo_compute_efficiency_test_OBJECTS = \ + sinfo_compute_efficiency_test.$(OBJEXT) \ + sinfo_eff_resp.$(OBJEXT) +sinfo_compute_efficiency_test_OBJECTS = \ + $(am_sinfo_compute_efficiency_test_OBJECTS) +sinfo_compute_efficiency_test_LDADD = $(LDADD) +sinfo_compute_efficiency_test_DEPENDENCIES = $(am__DEPENDENCIES_1) am_sinfo_cube_coadd_test_OBJECTS = sinfo_cube_coadd_test.$(OBJEXT) sinfo_cube_coadd_test_OBJECTS = $(am_sinfo_cube_coadd_test_OBJECTS) sinfo_cube_coadd_test_LDADD = $(LDADD) @@ -200,6 +211,11 @@ sinfo_line_corr_test_OBJECTS = $(am_sinfo_line_corr_test_OBJECTS) sinfo_line_corr_test_LDADD = $(LDADD) sinfo_line_corr_test_DEPENDENCIES = $(am__DEPENDENCIES_1) +am_sinfo_response_test_OBJECTS = sinfo_response_test.$(OBJEXT) \ + sinfo_eff_resp.$(OBJEXT) +sinfo_response_test_OBJECTS = $(am_sinfo_response_test_OBJECTS) +sinfo_response_test_LDADD = $(LDADD) +sinfo_response_test_DEPENDENCIES = $(am__DEPENDENCIES_1) am_sinfo_skycor_test_OBJECTS = sinfo_skycor_test.$(OBJEXT) sinfo_skycor_test_OBJECTS = $(am_sinfo_skycor_test_OBJECTS) sinfo_skycor_test_LDADD = $(LDADD) @@ -261,6 +277,7 @@ SOURCES = $(sinfo_absolute_test_SOURCES) \ $(sinfo_arc_lamp_simul_test_SOURCES) \ $(sinfo_baryvel_test_SOURCES) $(sinfo_boltzmann_test_SOURCES) \ + $(sinfo_compute_efficiency_test_SOURCES) \ $(sinfo_cube_coadd_test_SOURCES) \ $(sinfo_cube_measure_centroid_test_SOURCES) \ $(sinfo_cube_ops_test_SOURCES) \ @@ -270,13 +287,14 @@ $(sinfo_image_ops_test_SOURCES) \ $(sinfo_intensity_scale_test_SOURCES) \ $(sinfo_kappa_sigma_test_SOURCES) \ - $(sinfo_line_corr_test_SOURCES) $(sinfo_skycor_test_SOURCES) \ - $(sinfo_star_catalog_SOURCES) $(sinfo_star_index_test_SOURCES) \ - $(sinfo_strehl_test_SOURCES) $(sinfo_table_ops_test_SOURCES) \ - $(test_atmo_disp_SOURCES) + $(sinfo_line_corr_test_SOURCES) $(sinfo_response_test_SOURCES) \ + $(sinfo_skycor_test_SOURCES) $(sinfo_star_catalog_SOURCES) \ + $(sinfo_star_index_test_SOURCES) $(sinfo_strehl_test_SOURCES) \ + $(sinfo_table_ops_test_SOURCES) $(test_atmo_disp_SOURCES) DIST_SOURCES = $(sinfo_absolute_test_SOURCES) \ $(sinfo_arc_lamp_simul_test_SOURCES) \ $(sinfo_baryvel_test_SOURCES) $(sinfo_boltzmann_test_SOURCES) \ + $(sinfo_compute_efficiency_test_SOURCES) \ $(sinfo_cube_coadd_test_SOURCES) \ $(sinfo_cube_measure_centroid_test_SOURCES) \ $(sinfo_cube_ops_test_SOURCES) \ @@ -286,10 +304,10 @@ $(sinfo_image_ops_test_SOURCES) \ $(sinfo_intensity_scale_test_SOURCES) \ $(sinfo_kappa_sigma_test_SOURCES) \ - $(sinfo_line_corr_test_SOURCES) $(sinfo_skycor_test_SOURCES) \ - $(sinfo_star_catalog_SOURCES) $(sinfo_star_index_test_SOURCES) \ - $(sinfo_strehl_test_SOURCES) $(sinfo_table_ops_test_SOURCES) \ - $(test_atmo_disp_SOURCES) + $(sinfo_line_corr_test_SOURCES) $(sinfo_response_test_SOURCES) \ + $(sinfo_skycor_test_SOURCES) $(sinfo_star_catalog_SOURCES) \ + $(sinfo_star_index_test_SOURCES) $(sinfo_strehl_test_SOURCES) \ + $(sinfo_table_ops_test_SOURCES) $(test_atmo_disp_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -553,6 +571,13 @@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ +GSL_INCLUDES = @GSL_INCLUDES@ +GSL_LDFLAGS = @GSL_LDFLAGS@ +GSL_LIBS = @GSL_LIBS@ +HDRL_INCLUDES = @HDRL_INCLUDES@ +HDRL_INTERNAL_CFLAGS = @HDRL_INTERNAL_CFLAGS@ +HDRL_LDFLAGS = @HDRL_LDFLAGS@ +HDRL_LIBS = @HDRL_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -567,6 +592,7 @@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ LIBCPLUI = @LIBCPLUI@ +LIBHDRL = @LIBHDRL@ LIBIRPLIB = @LIBIRPLIB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -666,6 +692,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ +subdirs = @subdirs@ sysconfdir = @sysconfdir@ target = @target@ target_alias = @target_alias@ @@ -684,10 +711,13 @@ #LIBSINFONI = $(top_builddir)/sinfoni/libsinfo.la #AM_CPPFLAGS = -I$(top_builddir)/sinfoni -I$(top_builddir)/irplib -AM_CPPFLAGS = $(all_includes) +AM_CPPFLAGS = $(all_includes) $(GSL_INCLUDES) LDADD = $(LIBSINFONI) -AM_LDFLAGS = -static -noinst_HEADERS = +AM_LDFLAGS = -static $(GSL_LDFLAGS) +noinst_HEADERS = sinfo_eff_resp.h +# sinfo_compute_efficiency_test +sinfo_response_test_SOURCES = sinfo_response_test.c sinfo_eff_resp.c +sinfo_compute_efficiency_test_SOURCES = sinfo_compute_efficiency_test.c sinfo_eff_resp.c sinfo_arc_lamp_simul_test_SOURCES = sinfo_arc_lamp_simul_test.c sinfo_find_lines_test_SOURCES = sinfo_find_lines_test.c sinfo_intensity_scale_test_SOURCES = sinfo_intensity_scale_test.c @@ -774,6 +804,10 @@ @rm -f sinfo_boltzmann_test$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sinfo_boltzmann_test_OBJECTS) $(sinfo_boltzmann_test_LDADD) $(LIBS) +sinfo_compute_efficiency_test$(EXEEXT): $(sinfo_compute_efficiency_test_OBJECTS) $(sinfo_compute_efficiency_test_DEPENDENCIES) $(EXTRA_sinfo_compute_efficiency_test_DEPENDENCIES) + @rm -f sinfo_compute_efficiency_test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(sinfo_compute_efficiency_test_OBJECTS) $(sinfo_compute_efficiency_test_LDADD) $(LIBS) + sinfo_cube_coadd_test$(EXEEXT): $(sinfo_cube_coadd_test_OBJECTS) $(sinfo_cube_coadd_test_DEPENDENCIES) $(EXTRA_sinfo_cube_coadd_test_DEPENDENCIES) @rm -f sinfo_cube_coadd_test$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sinfo_cube_coadd_test_OBJECTS) $(sinfo_cube_coadd_test_LDADD) $(LIBS) @@ -814,6 +848,10 @@ @rm -f sinfo_line_corr_test$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sinfo_line_corr_test_OBJECTS) $(sinfo_line_corr_test_LDADD) $(LIBS) +sinfo_response_test$(EXEEXT): $(sinfo_response_test_OBJECTS) $(sinfo_response_test_DEPENDENCIES) $(EXTRA_sinfo_response_test_DEPENDENCIES) + @rm -f sinfo_response_test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(sinfo_response_test_OBJECTS) $(sinfo_response_test_LDADD) $(LIBS) + sinfo_skycor_test$(EXEEXT): $(sinfo_skycor_test_OBJECTS) $(sinfo_skycor_test_DEPENDENCIES) $(EXTRA_sinfo_skycor_test_DEPENDENCIES) @rm -f sinfo_skycor_test$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sinfo_skycor_test_OBJECTS) $(sinfo_skycor_test_LDADD) $(LIBS) @@ -848,9 +886,11 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_arc_lamp_simul_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_baryvel_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_boltzmann_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_compute_efficiency_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_cube_coadd_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_cube_measure_centroid_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_cube_ops_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_eff_resp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_efficiency_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_find_lines_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_gauss_fit_test.Po@am__quote@ @@ -858,6 +898,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_intensity_scale_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_kappa_sigma_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_line_corr_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_response_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_skycor_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_star_catalog.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sinfo_star_index_test.Po@am__quote@ @@ -1224,6 +1265,13 @@ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +sinfo_response_test.log: sinfo_response_test$(EXEEXT) + @p='sinfo_response_test$(EXEEXT)'; \ + b='sinfo_response_test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) .test.log: @p='$<'; \ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_arc_lamp_simul_test.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_arc_lamp_simul_test.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_arc_lamp_simul_test.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_arc_lamp_simul_test.c 2017-09-21 09:48:42.000000000 +0000 @@ -116,7 +116,7 @@ double x=0; double x2=0; double x3=0; - double y=0; + double a=0; double arg=0; //float begin_wave=1.25; //j @@ -144,7 +144,7 @@ sinfo_msg_warning("FWHM=%g",FWHM); for(int j=0;j +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/*----------------------------------------------------------------------------- + Defines + -----------------------------------------------------------------------------*/ +static const double STAR_MATCH_DEPSILON=0.0166667; /*60 arcsecs */ +static const char COL_NAME_ORD_OBJ[] = "ORD";//"counts_tot"; +static const char COL_NAME_WAVE_OBJ[] = "WAVELENGTH"; +static const char COL_NAME_INT_OBJ[] = "INT_OBJ";//"counts_tot" +static const char COL_NAME_WAVE_ATMDISP[] = "LAMBDA"; +static const char COL_NAME_ABS_ATMDISP[] = SINFO_ATMOS_EXT_LIST_COLNAME_K; +static const char COL_NAME_WAVE_REF[] = "LAMBDA"; +static const char COL_NAME_FLUX_REF[] = "FLUX"; +static const char COL_NAME_BINWIDTH_REF[] = "BIN_WIDTH"; +#define SINFO_QC_EFF_PEAK_ORD "ESO QC EFF PEAK ORD" +#define SINFO_QC_EFF_MED_ORD "ESO QC EFF MED ORD" +const char* SINFO_EFFICIENCY_BUG_REPORT = "amodigli@eso.org"; +static const char COL_NAME_HIGH_ABS[] = "HIGH_ABS"; +static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH"; +/*----------------------------------------------------------------------------- + Functions prototypes + -----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/** + * @defgroup sinfo_skycor_test SINFO library unit tests + */ +/*----------------------------------------------------------------------------*/ +/**@{*/ +#define SYNTAX "Test efficiency computation algorithm\n"\ + "usage : \n"\ + "./sinfo_compute_efficiency_test REC1D_SPECTRA STD_STAR_CAT ATM_EXT_TAB HIGH_ABS\n"\ + "REC1D_SPECTRA => extracted std star spectrum order by order\n"\ + "ATM_EXT_TAB => Table with atm extinction coeffs\n"\ + "MERGED_RESPONSE1D => Table with response fit points\n" + +/*----------------------------------------------------------------------------*/ +/** + @brief SINFONI pipeline unit test for skycor + +**/ +/*----------------------------------------------------------------------------*/ +// TO BE FIXED (gain is wrong in NIR) +static void +sinfo_frame_sci_get_gain_airmass_exptime_naxis1_biny(cpl_frame* frm_sci, + new_sinfo_band band, + double* gain, + double* airmass, + double* exptime, + int* naxis1, + int* biny) +{ + + const char* name_sci=NULL; + cpl_propertylist* plist=NULL; + + name_sci=cpl_frame_get_filename(frm_sci); + check_nomsg(plist=cpl_propertylist_load(name_sci,0)); + check_nomsg(*naxis1=sinfo_pfits_get_naxis1(plist)); + *airmass=sinfo_pfits_get_airm_mean(plist); + + if( band == INSTRUMENT_BAND_NIR || + band == INSTRUMENT_BAND_J || + band == INSTRUMENT_BAND_H || + band == INSTRUMENT_BAND_K || + band == INSTRUMENT_BAND_L + ){ + *gain=2.12; + *biny=1; + check_nomsg(*exptime=sinfo_pfits_get_dit(plist)); + } else { + check_nomsg(*gain=sinfo_pfits_get_conad(plist)); + check_nomsg(*biny=sinfo_pfits_get_biny(plist)); + check_nomsg(*exptime=sinfo_pfits_get_win1_dit1(plist)); + } + +cleanup: + sinfo_free_propertylist(&plist); + + return; +} + + +static cpl_error_code +sinfo_efficiency_add_high_abs_regions(cpl_table** eff,HIGH_ABS_REGION * phigh) +{ + + sinfo_msg_warning("eff=%p",*eff); + int nrow=cpl_table_get_nrow(*eff); + double* pwav=NULL; + int* phigh_abs=NULL; + + + + cpl_table_new_column(*eff,COL_NAME_HIGH_ABS,CPL_TYPE_INT); + cpl_table_fill_column_window_int(*eff,COL_NAME_HIGH_ABS,0,nrow,0); + pwav=cpl_table_get_data_double(*eff,COL_NAME_WAVELENGTH); + phigh_abs=cpl_table_get_data_int(*eff,COL_NAME_HIGH_ABS); + + if ( phigh != NULL ) { + for( int k = 0 ; phigh->lambda_min != 0. ; k++, phigh++ ) { + for(int i=0;i=phigh->lambda_min && pwav[i]<=phigh->lambda_max) { + phigh_abs[i]=1; + } + } + } + } + + return cpl_error_get_code(); + +} + +/** +@brief computes efficiency +@param frm_sci science frame +@param frm_cat catalog frame +@param frm_atmext atmospheric extinction frame +@param instrument instrument arm setting + */ +cpl_frame* +sinfo_efficiency_compute(cpl_frame* frm_sci, + cpl_frame* frm_cat, + cpl_frame* frm_atmext, + cpl_frame* high_abs_win, + new_sinfo_band band) + +{ + + cpl_image* ima_sci=NULL; + cpl_vector* vec_ord=NULL; + cpl_image* ima_obj=NULL; + cpl_table* obj_tab=NULL; + + const char* name_sci=NULL; + const char* name_atm=NULL; + cpl_propertylist* plist=NULL; + cpl_propertylist* x_plist=NULL; + + + cpl_table* tbl_ord=NULL; + cpl_table* tot_eff=NULL; + cpl_table* tbl_eff=NULL; + cpl_table* tbl_ref=NULL; + cpl_table* tbl_atmext=NULL; + + double * pobj=NULL; + double * pw=NULL; + double * pf=NULL; + int * po=NULL; + + cpl_frame* frm_eff=NULL; + + //char name_eff[256]; + + double crval1=0; + double cdelt1=0; + int naxis1=0; + int nrow=0; + + + double exptime=600; + cpl_vector* rec_profile=NULL; + int i=0; + double airmass=0; + double dRA=0; + double dDEC=0; + char key_name[40]; + int next=0; + int nord=0; + + + + int j=0; + double wav=0; + double gain=0; + int biny=1; + double aimprim=0; + int ord=0; + //double nm2AA=10.; + double nm2nm=1.; + + char fname[256]; + char tag[256]; + double emax=0; + double emed=0; + int nclip=0; + int ntot=0; + + int nclip_tot=0; + int neff_tot=0; + double fclip=0; + sinfo_std_star_id std_star_id=0; + int vec_size=0; + char name_eff[80]; + + SINFO_ASSURE_NOT_NULL_MSG(frm_sci,"Null input sci frame set!Exit"); + SINFO_ASSURE_NOT_NULL_MSG(frm_cat,"Null input std star cat frame set!Exit"); + SINFO_ASSURE_NOT_NULL_MSG(frm_atmext,"Null input atmospheric ext frame set!Exit"); + + + check_nomsg(next = cpl_frame_get_nextensions(frm_sci)); + //sinfo_msg("next=%d",next); + nord=(next+1)/3; + + sinfo_frame_sci_get_ra_dec_airmass(frm_sci,&dRA,&dDEC,&airmass); + name_sci=cpl_frame_get_filename(frm_sci); + + sinfo_msg_warning("name_sci = %s", name_sci ? name_sci : "NULL"); + + plist=cpl_propertylist_load(name_sci,0); + sinfo_frame_sci_get_gain_airmass_exptime_naxis1_biny(frm_sci,band, + &gain,&airmass,&exptime, + &naxis1,&biny); + + + + cpl_error_code fail = (sinfo_parse_catalog_std_stars(frm_cat,dRA,dDEC,STAR_MATCH_DEPSILON, + &tbl_ref,&std_star_id)); + + if(fail){ + sinfo_msg_error("Unable to parse the star catalog"); + return NULL; + } + + + /* + sinfo_msg_dbg_medium("gain=%g airm=%g exptime=%g airmass=%g ra=%g dec=%g", + gain,airmass,exptime,airmass,dRA,dDEC); + + sinfo_msg_dbg_medium("name_sci=%s",name_sci); + */ + nrow=naxis1*nord; + /* note that this table is overdimensioned: naxis1 is the size of the multi + extension image holding the 2D spectrum (usually order by order) + but orders may have different length==> different naxis1 + */ + obj_tab=cpl_table_new(nrow); + + + cpl_table_new_column(obj_tab,COL_NAME_ORD_OBJ,CPL_TYPE_INT); + cpl_table_new_column(obj_tab,COL_NAME_WAVE_OBJ,CPL_TYPE_DOUBLE); + cpl_table_new_column(obj_tab,COL_NAME_INT_OBJ,CPL_TYPE_DOUBLE); + + check_nomsg(cpl_table_fill_column_window_int(obj_tab,COL_NAME_ORD_OBJ,0,nrow,-1)); + check_nomsg(cpl_table_fill_column_window_double(obj_tab,COL_NAME_WAVE_OBJ,0,nrow,-1)); + check_nomsg(cpl_table_fill_column_window_double(obj_tab,COL_NAME_INT_OBJ,0,nrow,-1)); + + + + /* extract the object signal on a given slit + extract the sky signal on 2 given slits + computes the extracted sky per pixel on each sky window + average the two extracted sky + rescale the averaged sky to the object windows and + subtract it from the object + */ + + check_nomsg(name_atm=cpl_frame_get_filename(frm_atmext)); + //sinfo_msg_dbg_medium("name_atm=%s",name_atm); + check_nomsg(tbl_atmext=cpl_table_load(name_atm,1,0)); + + if(!cpl_table_has_column(tbl_atmext,SINFO_ATMOS_EXT_LIST_COLNAME_K)){ + sinfo_msg_warning("You are using an obsolete atm extinction line table"); + cpl_table_duplicate_column(tbl_atmext,SINFO_ATMOS_EXT_LIST_COLNAME_K, + tbl_atmext,SINFO_ATMOS_EXT_LIST_COLNAME_OLD); + } + + + + if(tbl_ref == NULL) { + sinfo_msg_error("Provide std sar catalog frame"); + return NULL; + //cpl_table_dump(tbl_ref,0,3,stdout); + } + + double factor; + + /* Trick to make it work with SINFONI data */ + if(band == INSTRUMENT_BAND_UVB || + band == INSTRUMENT_BAND_VIS || + band == INSTRUMENT_BAND_NIR ) + { + factor=1.; /*XSHOOTER*/ + } else { + next=1; /*SINFONI*/ + nord=1; + factor=1000.; + } + int crpix1; + for(i=0;i0) { + check_nomsg(emax=cpl_table_get_column_max(tbl_eff,"EFF")); + } else { + emax=-999; + } + sprintf(key_name,"%s%2d", SINFO_QC_EFF_PEAK_ORD,ord); + cpl_propertylist_append_double(plist,key_name,emax); + cpl_propertylist_set_comment(plist,key_name,"Peak efficiency"); + if(nrow>0) { + check_nomsg(emed=cpl_table_get_column_median(tbl_eff,"EFF")); + } else { + emed=-999; + } + sprintf(key_name,"%s%2d", SINFO_QC_EFF_MED_ORD,ord); + cpl_propertylist_append_double(plist,key_name,emed); + cpl_propertylist_set_comment(plist,key_name,"Median efficiency"); + + + neff_tot+=ntot; + //sinfo_msg("neff_tot=%d vec_size=%d",neff_tot,vec_size); + if(ord==0) { + tot_eff=cpl_table_duplicate(tbl_eff); + } else { + cpl_table_insert(tot_eff,tbl_eff,neff_tot); + } + nclip_tot+=nclip; + + //sprintf(name_eff,"eff_ord%d.fits",ord); + //check(cpl_table_save(tbl_eff,plist, x_plist,name_eff, CPL_IO_DEFAULT)); + } + + //abort(); + + sinfo_msg("nclip_tot=%d",nclip_tot); + HIGH_ABS_REGION * phigh=NULL; + phigh=sinfo_fill_high_abs_regions(band,high_abs_win); + + check_nomsg(sinfo_efficiency_add_high_abs_regions(&tot_eff,phigh)); + /* + sprintf(tag,"EFFICIENCY_%s_%s",sinfo_instrument_mode_tostring(band), + sinfo_instrument_arm_tostring(band)); + */ + //AMO: changed from XSHOOTER + + const char * nm = name_sci + strlen(name_sci); + + while(*nm != '/') nm--; + + nm++; + + sprintf(tag,"EFFICIENCY_%s",nm); + sprintf(fname,"%s",tag); + + nrow=cpl_table_get_nrow(tot_eff); + fclip=nclip_tot; + + if(neff_tot > 0) { + fclip/=neff_tot; + } else { + fclip=-999; + } + + sinfo_msg("nclip_tot =%d neff_tot=%d fclip=%g",nclip_tot,neff_tot,fclip); + sinfo_pfits_set_qc_eff_fclip(plist,fclip); + sinfo_pfits_set_qc_eff_nclip(plist,nclip_tot); + + //cpl_propertylist_dump(plist,stdout); + check_nomsg(cpl_table_save(tot_eff,plist, x_plist,fname, CPL_IO_DEFAULT)); + + sinfo_free_table(&obj_tab); + + check_nomsg(frm_eff=sinfo_frame_product(fname,tag,CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_CALIB, + CPL_FRAME_LEVEL_FINAL)); + + + + cleanup: + + //if(phigh!=NULL) cpl_free(phigh); + + + sinfo_free_table(&tot_eff); + sinfo_free_table(&tbl_ref); + sinfo_free_table(&tbl_atmext); + sinfo_free_table(&obj_tab); + sinfo_free_table(&tbl_ord); + sinfo_free_table(&tbl_eff); + sinfo_free_image(&ima_sci); + cpl_vector_delete(rec_profile); + cpl_vector_delete(vec_ord); + sinfo_free_image(&ima_obj); + sinfo_free_propertylist(&plist); + sinfo_free_propertylist(&x_plist); + + return frm_eff; + +} + + +cpl_frame* sinfo_compute_efficiency(cpl_frame* mer1D, cpl_frame* std_cat, + cpl_frame* atm_ext, cpl_frame* high_abs_win, + new_sinfo_band band) +{ + + cpl_frame* eff=NULL; + + if(NULL == (eff=sinfo_efficiency_compute(mer1D,std_cat,atm_ext,high_abs_win,band))) { + sinfo_msg_error("An error occurred during efficiency computation"); + sinfo_msg_error("The recipe recovers without efficiency product generation"); + cpl_error_reset(); + } + + cleanup: + return eff; +} + +void +sinfo_compute_efficiency_drive(const char* res1D_name, const char* std_cat_name, + const char* atm_ext_name, const char* high_abs_name, + new_sinfo_band band) +{ + + cpl_test(CPL_ERROR_NONE == CPL_ERROR_NONE); + cpl_frame * obs_std_star = NULL; + cpl_frame * flux_std_star_cat = NULL; + cpl_frame * atmos_ext = NULL; + cpl_frame* high_abs = NULL; + cpl_frame* resp_fit_points = NULL; + cpl_frame* tell_mod_cat = NULL; + + + obs_std_star=sinfo_frame_product(res1D_name, "STD_STAR_SPECTRA", + CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL); + + flux_std_star_cat=sinfo_frame_product(std_cat_name, "FLUX_STD_CATALOG_NIR", + CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL); + + atmos_ext = sinfo_frame_product(atm_ext_name, "ATMOS_EXT_NIR", + CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL); + + if(high_abs_name!= NULL) { + high_abs=sinfo_frame_product(high_abs_name, "ATMOS_EXT_NIR", + CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL); + } + cpl_propertylist* plist = cpl_propertylist_load(res1D_name,0); + char test_band[10]; + char instrume[10]; + const char * strmen = cpl_propertylist_get_string(plist, "INSTRUME"); + strcpy(instrume, strmen); + + if (!strcmp(instrume, "SINFONI")) { + strcpy(test_band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME)); + if (!strcmp(test_band, "J")) { + band=INSTRUMENT_BAND_J ; + } else if (!strcmp(test_band, "H")) { + band=INSTRUMENT_BAND_H ; + } else if (!strcmp(test_band, "K")) { + band=INSTRUMENT_BAND_K ; + } else { + band=INSTRUMENT_BAND_L ; + } + } else if (!strcmp(instrume, "XSHOOTER")) { + strcpy(test_band, cpl_propertylist_get_string(plist, "ESO SEQ ARM")); + if (!strcmp(test_band, "UVB")) { + band=INSTRUMENT_BAND_UVB ; + } else if (!strcmp(test_band, "VIS")) { + band=INSTRUMENT_BAND_VIS ; + } else if (!strcmp(test_band, "NIR")) { + band=INSTRUMENT_BAND_NIR ; + } + } + sinfo_free_propertylist(&plist); + cpl_frame* eff=NULL; + eff=sinfo_compute_efficiency(obs_std_star, flux_std_star_cat, + atmos_ext, high_abs, band); + + + sinfo_free_frame(&obs_std_star); + sinfo_free_frame(&flux_std_star_cat); + sinfo_free_frame(&atmos_ext); + //sinfo_free_frame(&high_abs); + sinfo_free_frame(&resp_fit_points); + sinfo_free_frame(&tell_mod_cat); + sinfo_free_frame(&eff); + +} + +int main(int argc, char** argv) +{ + cpl_test_init(SINFO_EFFICIENCY_BUG_REPORT, CPL_MSG_WARNING); + + const char * res1Deso_eff_frame_name = NULL; + const char * frm_std_cat_name = NULL; + + const char * atm_ext_name = NULL; + const char * high_abs_name = NULL; + + new_sinfo_band band = SINFO_BAND_J; + + /* Analyse parameters */ + sinfo_msg_warning("argc=%d",argc); + if ( argc == 3) { + sinfo_ima2table(argv); + } else if ( argc > 3) { + res1Deso_eff_frame_name = argv[1]; + frm_std_cat_name = argv[2]; + atm_ext_name = argv[3]; + if ( argc > 4) { + high_abs_name = argv[4]; + } + sinfo_msg_warning("res1Deso_eff_frame_name=%s frm_std_cat_name=%s high_abs_name=%s atm_ext_name=%s", + res1Deso_eff_frame_name,frm_std_cat_name, high_abs_name,atm_ext_name); + + sinfo_compute_efficiency_drive(res1Deso_eff_frame_name, frm_std_cat_name, + atm_ext_name, high_abs_name, band); + + sinfo_msg_warning("Execution terminated!"); + + + } + else{ + printf(SYNTAX); + return cpl_test_end(0); + + } + +} + +/**@}*/ diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_cube_coadd_test.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_cube_coadd_test.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_cube_coadd_test.c 2015-08-21 08:24:49.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_cube_coadd_test.c 2017-09-21 09:48:42.000000000 +0000 @@ -168,11 +168,8 @@ float* offx, float* offy, double* times) { int onp; - int z_stp=8; - int z_siz=0; - int z_min=0; - int z_max=0; - int kappa=2; + + char name[SIZE]; cpl_image* img_j=NULL; cpl_image* img_m=NULL; @@ -181,11 +178,13 @@ onp = cpl_imagelist_get_size(cube_obj[0]); sinfo_msg_warning("Coadd data"); + int z_stp=8; + int kappa=2; for (int z = 0; z < onp; z += z_stp) { - z_siz = (z_stp < (onp - z)) ? z_stp : (onp - z); - z_min = z; - z_max = z_min + z_siz; + int z_siz = (z_stp < (onp - z)) ? z_stp : (onp - z); + int z_min = z; + int z_max = z_min + z_siz; sinfo_msg("Coadding cubes: range [%4.4d,%4.4d) of 0-%d\n", z_min, z_max, onp); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_eff_resp.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_eff_resp.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_eff_resp.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_eff_resp.c 2017-09-23 06:23:59.000000000 +0000 @@ -0,0 +1,3598 @@ +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include +#include +#include + +#define SINFO_EXTCOEFF_TAB "EXTCOEFF_TABLE" + +#define PRO_STD_STAR_SPECTRA "STD_STAR_SPECTRA" +static const char COL_NAME_HIGH_ABS[] = "HIGH_ABS"; +static const char COL_NAME_WAVELENGTH[] = "WAVELENGTH"; +//static const char COL_NAME_WAVELENGTH_C[] = "WAVELENGTH"; +static const char COL_NAME_WAVE_ATMDISP[] = "LAMBDA"; +static const char COL_NAME_ABS_ATMDISP[] = SINFO_ATMOS_EXT_LIST_COLNAME_K; + +static const char COL_NAME_REF[] = "REF"; +static const char COL_NAME_COR[] = "COR"; +static const char COL_NAME_SRC_COR[] = "SRC_COR"; + +static const char COL_NAME_WAVE_OBJ[] = "WAVELENGTH"; +static const char COL_NAME_INT_OBJ[] = "INT_OBJ";//"counts_tot"; +static const char COL_NAME_ORD_OBJ[] = "ORD";//"counts_tot"; +static const char COL_NAME_WAVE_REF[] = "LAMBDA"; +static const char COL_NAME_FLUX_REF[] = "FLUX"; +static const char COL_NAME_BINWIDTH_REF[] = "BIN_WIDTH"; +static const char COL_NAME_EPHOT[] = "EPHOT"; +static const char COL_NAME_EXT[] = "EXT"; +static const char COL_NAME_SRC_EFF[] = "EFF"; +//static const char PAR_NAME_DIT[] = "ESO DET DIT"; +//static const double UVES_flux_factor =1.e16; + + +HIGH_ABS_REGION NirJHighAbsRegions[] = { + {1076.0, 1100.0}, // nm (water vapour) dummy + {1112.0, 1176.0}, // nm (water vapour) + {1260.0, 1296.0}, // nm (water vapour) + {1330.0, 1506.0}, // nm (region between J and H) + {0., 0.} +} ; + +HIGH_ABS_REGION NirHHighAbsRegions[] = { + {1076.0, 1176.0}, // nm (water vapour) + {1236.0, 1296.0}, // nm (water vapour) + {1316.0, 1506.0}, // nm (region between J and H) + {1736.0, 1986.0}, // nm (region between H and K) + {1996.0, 2036.0}, // nm (region between H and K) + {2046.0, 2086.0}, // nm (region between H and K) + {0., 0.} +} ; + +HIGH_ABS_REGION NirKHighAbsRegions[] = { +// {1076.0, 1176.0}, // nm (water vapour) +// {1236.0, 1296.0}, // nm (water vapour) +// {1316.0, 1506.0}, // nm (region between J and H) +// {1736.0, 1986.0}, // nm (region between H and K) + {1996.0, 2036.0}, // nm (region between H and K) + {2046.0, 2086.0}, // nm (region between H and K) + {0., 0.} +} ; + +HIGH_ABS_REGION NirHKHighAbsRegions[] = { + {1076.0, 1176.0}, // nm (water vapour) + {1236.0, 1296.0}, // nm (water vapour) + {1316.0, 1506.0}, // nm (region between J and H) + {1736.0, 1986.0}, // nm (region between H and K) + {1996.0, 2036.0}, // nm (region between H and K) + {2046.0, 2086.0}, // nm (region between H and K) + {0., 0.} +} ; + +HIGH_ABS_REGION NirHighAbsRegions[] = { + {1076.0, 1176.0}, // nm (water vapour) + {1236.0, 1296.0}, // nm (water vapour) + {1316.0, 1506.0}, // nm (region between J and H) + {1736.0, 1986.0}, // nm (region between H and K) + {1996.0, 2036.0}, // nm (region between H and K) + {2046.0, 2086.0}, // nm (region between H and K) + {0., 0.} +} ; + + +HIGH_ABS_REGION AllHighAbsRegions[] = { + {500.0, 532.0}, // nm + {634.0, 642.0}, // nm + {684.5, 696.0}, // nm + {758.0, 770.0}, // nm + {812.0, 819.0}, // nm + {894.0, 924.0}, // nm + {928.0, 968.0}, // nm + {974.0, 984.0}, // nm + {1076.0, 1176.0}, // nm (water vapour) + {1236.0, 1296.0}, // nm (water vapour) + {1316.0, 1506.0}, // nm (region between J and H) + {1736.0, 1986.0}, // nm (region between H and K) + {1996.0, 2036.0}, // nm (region between H and K) + {2046.0, 2086.0}, // nm (region between H and K) + {0., 0.} +} ; + + +/* 1.5.32 */ +HIGH_ABS_REGION VisHighAbsRegions[] = { + {506.0, 509.0}, // nm + {512.0, 532.0}, // nm + {634.0, 642.0}, // nm + {684.5, 696.0}, // nm + {758.0, 770.0}, // nm + {812.0, 819.0}, // nm + {894.0, 924.0}, // nm + {928.0, 968.0}, // nm + {974.0, 984.0}, // nm + {0., 0.} +} ; + + +HIGH_ABS_REGION UvbHighAbsRegions[] = { + {556.0, 580.0}, // nm + {0., 0.} +} ; + + + + + + + +static char FRM_EXTCOEFF_TAB[] = SINFO_EXTCOEFF_TAB; +static void +sinfo_frame_config(const char* fname, + const char* tag, + cpl_frame_type type, + cpl_frame_group group, + cpl_frame_level level, + cpl_frame** frame) +{ + + cpl_frame_set_filename(*frame,fname); + cpl_frame_set_tag(*frame,tag); + cpl_frame_set_type(*frame,type); + cpl_frame_set_group(*frame,group); + cpl_frame_set_level(*frame,level); + + return; + +} +/*---------------------------------------------------------------------------*/ +/** + @brief free memory associated to a rec_list + @param list the rec_list to free +*/ +/*---------------------------------------------------------------------------*/ +void sinfo_rec_list_free(sinfo_rec_list** list) +{ + if (list != NULL && *list != NULL ) { + /* + BUG - Laurent - 09-01-2009 + Something strange occurs (under Linux, not MacOs): + in the recipe sinfo_scired_slit_nod, for UVB (not for VIS), there is + a crash in this function during one of the cpl_free calls. + In order to allow continuation of tests, freeing of the rec_list + is - temporarily - disable until the problem is understood and + fixed. + */ + int i ; + sinfo_rec_list * plist = NULL; + + plist = *list; + /* free the list */ + + for (i = 0; i < plist->size; i++) { + sinfo_rec * pr = &(plist->list[i]) ; + + //sinfo_msg_dbg_high( "Freeing order index %d", i ) ; + if ( pr == NULL ) continue ; + //sinfo_msg_dbg_high( " Abs Order: %d", pr->order ) ; + cpl_free( pr->slit ) ; + cpl_free( pr->lambda ) ; + cpl_free( pr->data1 ) ; + cpl_free( pr->errs1 ) ; + cpl_free( pr->qual1 ) ; + } + if ((*list)->list){ + cpl_free((*list)->list); + } + + sinfo_free_propertylist(&((*list)->header)); + cpl_free(*list); + *list = NULL; + } +} +/*---------------------------------------------------------------------------*/ +/** + @brief + Allocate memory for the order idx of the rectify list + @param[in] list + The rectify list + @param[in] idx + The index of the order in the list + @param[in] absorder + The absorder of the order + @param[in] nlambda + The number of lambda values + @param[in] ns + The number of slit values +*/ +/*---------------------------------------------------------------------------*/ +static void sinfo_rec_list_set_data_size( sinfo_rec_list * list, int idx, int absorder, + int nlambda, int ns ) +{ + sinfo_rec * prec = NULL ; + int depth ; + + SINFO_ASSURE_NOT_NULL( list) ; + SINFO_ASSURE_NOT_ILLEGAL( idx < list->size); + assure( idx >= 0, CPL_ERROR_ILLEGAL_INPUT, "Index not in range"); + assure( idx < list->size, CPL_ERROR_ILLEGAL_INPUT,"Index not in range"); + assure( ns > 0, CPL_ERROR_ILLEGAL_INPUT,"Check size in slit"); + assure( nlambda > 0, CPL_ERROR_ILLEGAL_INPUT,"Check size in lambda"); + + prec = &list->list[idx] ; + SINFO_ASSURE_NOT_NULL( prec); + + //if ( list->max_nlambda < nlambda ) list->max_nlambda = nlambda ; + //if ( list->max_nslit < ns ) list->max_nslit = ns; + depth = nlambda*ns; + + prec->order = absorder; + prec->nlambda = nlambda; + prec->nslit = ns; + /* + sinfo_msg_dbg_high( "Rec Data Size: nlambda: %d, ns: %d, depth: %d", + nlambda, ns, depth); + */ + SINFO_CALLOC( prec->slit, float, ns) ; + SINFO_CALLOC( prec->lambda, double, nlambda); + SINFO_CALLOC( prec->data1, float, depth); + SINFO_CALLOC( prec->errs1, float, depth); + SINFO_CALLOC( prec->qual1, int, depth); + + cleanup: + return ; +} + + +sinfo_rec_list* sinfo_rec_list_load_eso(cpl_frame* frame, + new_sinfo_band band) +{ + sinfo_rec_list* result = NULL; + const char * imagelist_name = NULL ; + cpl_image * ima_data = NULL; + cpl_image * ima_errs = NULL; + cpl_image * ima_qual = NULL; + cpl_propertylist* header = NULL; + cpl_propertylist* hdata=NULL; + cpl_propertylist* herrs=NULL; + cpl_propertylist* hqual=NULL; + const char* ext_name=NULL; + + int nbext, i,j ; + int size; + + /* check input parameters */ + SINFO_ASSURE_NOT_NULL(frame); + //SINFO_ASSURE_NOT_NULL(instrument); + + + /* get table filename */ + check_nomsg(imagelist_name = cpl_frame_get_filename(frame)); + //sinfo_msg_dbg_low( "Loading Rectified Frame: %s", imagelist_name ) ; + + check_nomsg( nbext = cpl_frame_get_nextensions( frame)); + + + size=(nbext+1)/3; + + /* Create internal structure */ + /* Allocate memory */ + SINFO_CALLOC(result, sinfo_rec_list, 1); + result->size = size; + SINFO_ASSURE_NOT_ILLEGAL(result->size > 0); + result->band = band; + + SINFO_CALLOC( result->list, sinfo_rec, result->size); + + SINFO_NEW_PROPERTYLIST( result->header); + + + check_nomsg(header = cpl_propertylist_load(imagelist_name,0)); + check_nomsg(cpl_propertylist_erase_regexp(header, + "^(ARCFILE|ORIGFILE|CHECKSUM|DATASUM)$", CPL_FALSE)); + check_nomsg(cpl_propertylist_append(result->header, header)); + + sinfo_free_propertylist(&header); + + //nbext = size; + + //sinfo_msg_dbg_medium( " Nb of extensions: %d", nbext ) ; + /* Loop over FITS extensions */ + + for( i = 0,j=0 ; jlist[i].order = order ; + + nlambda=sinfo_pfits_get_naxis1(herrs); + nslit=sinfo_pfits_get_naxis2(herrs); + + w_step=sinfo_pfits_get_cdelt1(herrs); + s_step=sinfo_pfits_get_cdelt2(herrs); + + w_start=sinfo_pfits_get_crval1(herrs); + s_start=sinfo_pfits_get_crval2(herrs); + + result->list[i].nlambda = nlambda ; + result->list[i].nslit = nslit ; + + sinfo_rec_list_set_data_size( result, i, order, nlambda, nslit ) ; + + /* Get arrays (slit, lambda) */ + if (nslit > 1){ + for(k=0;klist[i].slit+k)=(s_start+k*s_step); + } + } + else{ + for(k=0;klist[i].slit+k)=0; + } + } + + + for(k=0;klist[i].lambda+k)=(w_start+k*w_step); + } + /* Get arrays (flux, errs, qual ) */ + depth = nlambda*nslit ; + + /* Copy FLUX1 data to rec_list */ + check_nomsg( farray = cpl_image_get_data_float( ima_data)) ; + sx = cpl_image_get_size_x( ima_data ) ; + sy = cpl_image_get_size_y( ima_data ) ; + SINFO_ASSURE_NOT_ILLEGAL( sx*sy == depth ) ; + + for( k = 0 ; klist[i].data1+k) = *farray++ ; + farray = NULL ; + + /* Copy ERRS1 data to rec_list */ + check_nomsg( farray = cpl_image_get_data_float( ima_errs)) ; + for( k = 0 ; klist[i].errs1+k) = *farray++ ; + + /* Copy QUAL1 data to rec_list */ + check_nomsg( iarray = cpl_image_get_data_int( ima_qual)) ; + for( k = 0 ; klist[i].qual1+k) = *iarray++ ; + + /* + sinfo_msg_dbg_low( " Loaded, order %d, nlambda %d, nslit %d", + order, nlambda, nslit ) ; + */ + sinfo_free_image( &ima_data ) ; + sinfo_free_image( &ima_errs ) ; + sinfo_free_image( &ima_qual ) ; + sinfo_free_propertylist( &hdata ) ; + sinfo_free_propertylist( &herrs ) ; + sinfo_free_propertylist( &hqual ) ; + + } + + cleanup: + sinfo_free_image( &ima_data ) ; + sinfo_free_image( &ima_errs ) ; + sinfo_free_image( &ima_qual ) ; + sinfo_free_propertylist( &hdata ) ; + sinfo_free_propertylist( &herrs ) ; + sinfo_free_propertylist( &hqual ) ; + + sinfo_free_propertylist(&header); + + return result ; +} +/*****************************************************************************/ +/** + @brief + Compute flux and error associated to each merged spectrum point + @param[in] flux_a + Input flux from a contribute + @param[in] err_a + Error associated to flux_a + @param[in] weight_a + Weight associated to flux_a + @param[in] flux_b + Input flux from b contribute + @param[in] err_b + Error associated to flux_b + @param[in] weight_b + Weight associated to flux_b + @param[out] flux_res + Input flux from merged contributes + @param[out] err_res + Error associated to flux_res + + @return + void ( +*/ +/*****************************************************************************/ +void sinfo_merge_point( double flux_a, double weight_a, + double flux_b, double weight_b, double *flux_res, + double *err_res) +{ + SINFO_ASSURE_NOT_NULL( flux_res); + SINFO_ASSURE_NOT_NULL( err_res); + + double tmp_val = 1.0/(weight_a+weight_b); + *flux_res = (weight_a*flux_a+weight_b*flux_b) * tmp_val; + *err_res = sqrt(tmp_val); + + cleanup: + return; +} + +sinfo_rec_list* sinfo_rec_list_load_eso_1d(cpl_frame* frame, + new_sinfo_band band) +{ + sinfo_rec_list* result = NULL; + const char * imagelist_name = NULL ; + cpl_vector * vec_data = NULL; + cpl_vector * vec_errs = NULL; + cpl_vector * vec_qual = NULL; + cpl_propertylist* header = NULL; + cpl_propertylist* hdata=NULL; + cpl_propertylist* herrs=NULL; + cpl_propertylist* hqual=NULL; + const char* ext_name=NULL; + + int nbext, i,j ; + int size; + + /* check input parameters */ + SINFO_ASSURE_NOT_NULL(frame); + //SINFO_ASSURE_NOT_NULL(instrument); + + + /* get table filename */ + check_nomsg(imagelist_name = cpl_frame_get_filename(frame)); + //sinfo_msg_dbg_low( "Loading Rectified Frame: %s", imagelist_name ) ; + + check_nomsg( nbext = cpl_frame_get_nextensions( frame)); + + + size=(nbext+1)/3; + + /* Create internal structure */ + /* Allocate memory */ + SINFO_CALLOC(result, sinfo_rec_list, 1); + result->size = size; + SINFO_ASSURE_NOT_ILLEGAL(result->size > 0); + result->band = band; + + SINFO_CALLOC( result->list, sinfo_rec, result->size); + + SINFO_NEW_PROPERTYLIST( result->header); + + + check_nomsg(header = cpl_propertylist_load(imagelist_name,0)); + check_nomsg(cpl_propertylist_erase_regexp(header, + "^(ARCFILE|ORIGFILE|CHECKSUM|DATASUM)$", CPL_FALSE)); + check_nomsg(cpl_propertylist_append(result->header, header)); + + sinfo_free_propertylist(&header); + + //nbext = size; + + //sinfo_msg_dbg_medium( " Nb of extensions: %d", nbext ) ; + /* Loop over FITS extensions */ + + for( i = 0,j=0 ; jlist[i].order = order ; + + nlambda=sinfo_pfits_get_naxis1(herrs); + + w_step=sinfo_pfits_get_cdelt1(herrs); + + w_start=sinfo_pfits_get_crval1(herrs); + + result->list[i].nlambda = nlambda ; + + sinfo_rec_list_set_data_size( result, i, order, nlambda, 1 ) ; + + /* Get arrays (lambda) */ + for(k=0;klist[i].lambda+k)=(w_start+k*w_step); + } + /* Get arrays (flux, errs, qual ) */ + depth = nlambda; + + /* Copy FLUX1 data to rec_list */ + check_nomsg( farray = cpl_vector_get_data( vec_data)) ; + sx = cpl_vector_get_size( vec_data ) ; + SINFO_ASSURE_NOT_ILLEGAL( sx == depth ) ; + + for( k = 0 ; klist[i].data1+k) = (float)*farray++ ; + farray = NULL ; + + /* Copy ERRS1 data to rec_list */ + check_nomsg( farray = cpl_vector_get_data( vec_errs)) ; + for( k = 0 ; klist[i].errs1+k) = (float)*farray++ ; + + /* Copy QUAL1 data to rec_list */ + check_nomsg( iarray = cpl_vector_get_data( vec_qual)) ; + for( k = 0 ; klist[i].qual1+k) = (int)*iarray++ ; + + //sinfo_msg_dbg_low( " Loaded, order %d, nlambda %d",order, nlambda) ; + + cpl_vector_delete( vec_data ) ; + cpl_vector_delete( vec_errs ) ; + cpl_vector_delete( vec_qual ) ; + sinfo_free_propertylist( &hdata ) ; + sinfo_free_propertylist( &herrs ) ; + sinfo_free_propertylist( &hqual ) ; + + } + + cleanup: + cpl_vector_delete( vec_data ) ; + cpl_vector_delete( vec_errs ) ; + cpl_vector_delete( vec_qual ) ; + sinfo_free_propertylist( &hdata ) ; + sinfo_free_propertylist( &herrs ) ; + sinfo_free_propertylist( &hqual ) ; + + sinfo_free_propertylist(&header); + + return result ; +} + + +/*---------------------------------------------------------------------------*/ +/** + @brief load an rec list from a frame + @param frame the table wich contains polynomials coefficients of the + orders + @param instrument instrument in use + @return the rec list structure + +*/ +/*---------------------------------------------------------------------------*/ + +sinfo_rec_list* sinfo_rec_list_load(cpl_frame* frame, + new_sinfo_band band) +{ + sinfo_rec_list* result = NULL; + const char * tablename = NULL ; + cpl_table * table = NULL; + cpl_propertylist* header = NULL; + int nbext, i ; + int size; + + /* check input parameters */ + SINFO_ASSURE_NOT_NULL(frame); + //SINFO_ASSURE_NOT_NULL(instrument); + + /* get table filename */ + check_nomsg(tablename = cpl_frame_get_filename(frame)); + //sinfo_msg_dbg_low( "Loading Rectified Frame: %s", tablename ) ; + + check_nomsg( size = cpl_frame_get_nextensions( frame)); + + /* Create internal structure */ + /* Allocate memory */ + SINFO_CALLOC(result, sinfo_rec_list, 1); + result->size = size; + SINFO_ASSURE_NOT_ILLEGAL(result->size > 0); + result->band = band; + + SINFO_CALLOC( result->list, sinfo_rec, result->size); + + SINFO_NEW_PROPERTYLIST( result->header); + + check_nomsg(header = cpl_propertylist_load(tablename,0)); + check_nomsg(cpl_propertylist_erase_regexp(header, + "^(ARCFILE|ORIGFILE|CHECKSUM|DATASUM)$", CPL_FALSE)); + check_nomsg(cpl_propertylist_append(result->header, header)); + //sinfo_msg("tablename=%s",tablename); + //check(result->slit_min=sinfo_pfits_get_extract_slit_min(header)); + //check(result->slit_max=sinfo_pfits_get_extract_slit_max(header)); + + sinfo_free_propertylist(&header); + + nbext = size; + + //sinfo_msg_dbg_medium( " Nb of extensions: %d", nbext ) ; + /* Loop over FITS extensions */ + for( i = 0 ; ilist[i].order = order ; + check_nomsg(sinfo_get_table_value(table, SINFO_REC_TABLE_COLNAME_NLAMBDA, + CPL_TYPE_INT, 0, &nlambda )); + result->list[i].nlambda = nlambda ; + check_nomsg(sinfo_get_table_value(table, SINFO_REC_TABLE_COLNAME_NSLIT, + CPL_TYPE_INT, 0, &nslit )); + result->list[i].nslit = nslit ; + sinfo_rec_list_set_data_size( result, i, order, nlambda, nslit ) ; + /* Get arrays (slit, lambda) */ + if (nslit > 1){ + check_nomsg( sinfo_table_get_array_float( table, SINFO_REC_TABLE_COLNAME_SLIT, + result->list[i].slit, nslit)); + } + else{ + check_nomsg(sinfo_get_table_value(table, SINFO_REC_TABLE_COLNAME_SLIT, + CPL_TYPE_FLOAT, 0, result->list[i].slit )); + } + check_nomsg( sinfo_table_get_array_double( table, SINFO_REC_TABLE_COLNAME_LAMBDA, + result->list[i].lambda, nlambda)); + + /* Get arrays (flux, errs, qual ) */ + depth = nlambda*nslit ; + + check_nomsg( data_array = cpl_table_get_array( table, + SINFO_REC_TABLE_COLNAME_FLUX1, + 0 )) ; + nb = cpl_array_get_size( data_array ) ; + SINFO_ASSURE_NOT_ILLEGAL( nb == depth ) ; + + /* Copy FLUX1 data to rec_list */ + check_nomsg( farray = cpl_array_get_data_float_const( data_array ) ) ; + for( k = 0 ; klist[i].data1+k) = *farray++ ; + + farray = NULL ; + check_nomsg( data_array = cpl_table_get_array( table, + SINFO_REC_TABLE_COLNAME_ERRS1, + 0 )) ; + check_nomsg( nb = cpl_array_get_size( data_array ) ) ; + /* Copy ERRS1 data to rec_list */ + check_nomsg( farray = cpl_array_get_data_float_const( data_array ) ) ; + for( k = 0 ; klist[i].errs1+k) = *farray++ ; + + check_nomsg( data_array = cpl_table_get_array( table, + SINFO_REC_TABLE_COLNAME_QUAL1, + 0 )) ; + nb = cpl_array_get_size( data_array ) ; + /* Copy QUAL1 data to rec_list */ + iarray = cpl_array_get_data_int_const( data_array ) ; + for( k = 0 ; klist[i].qual1+k) = *iarray++ ; + /* + sinfo_msg_dbg_low( " Loaded, order %d, nlambda %d, nslit %d", + order, nlambda, nslit ) ; + */ + cpl_table_delete( table ) ; + } + + cleanup: + sinfo_free_propertylist(&header); + return result ; +} + + +/*---------------------------------------------------------------------------*/ +/** + @brief Read a table value from a fits table + @param table table to read + @param colname Name of column to read + @param coltype Type of column + @param i row to read + @param result The value read + + @return CPL_ERROR_NONE iff OK + @note derived from UVES pipeline +*/ +/*---------------------------------------------------------------------------*/ +cpl_error_code sinfo_get_table_value (const cpl_table* table, + const char *colname, cpl_type coltype, int i, void* result) +{ + int flag = 0; + /* Check input */ + SINFO_ASSURE_NOT_NULL( table); + SINFO_ASSURE_NOT_NULL( colname); + SINFO_ASSURE_NOT_NULL( result); + + /* Read the column */ + + switch (coltype) { + case CPL_TYPE_INT: + check (*((int *) result) = cpl_table_get_int(table,colname,i,&flag), + "Could not get (integer) value of %s at row %d", colname,i); + break; + case CPL_TYPE_FLOAT: + check (*((float *) result) = cpl_table_get_float( table, + colname,i,&flag), + "Could not get (float) value of %s at row %d",colname,i); + break; + case CPL_TYPE_DOUBLE: + check (*((double *) result) = cpl_table_get_double (table, + colname,i,&flag), + "Could not get (double) value of %s at row %d",colname,i); + break; + case CPL_TYPE_STRING: + check(*((const char **) result) = + cpl_table_get_string (table, colname,i), + "Could not get (string) value of %s at row %d",colname,i); + break; + default: + assure (false, CPL_ERROR_INVALID_TYPE, "Unknown type"); + } + +cleanup: + return cpl_error_get_code (); +} + + +SINFO_TABLE_GET_ARRAY(int) +SINFO_TABLE_GET_ARRAY(float) +SINFO_TABLE_GET_ARRAY(double) + +/*---------------------------------------------------------------------------*/ +/** + * @brief Create a 1D spectrum structure + * + * @param[in] lambda_min minimum wavelength of spectrum + * @param[in] lambda_max maximum wavelength of spectrum + * @param[in] lambda_step lambda binning + * + * @return the spectrum structure + */ +/*---------------------------------------------------------------------------*/ +sinfo_spectrum* sinfo_spectrum_1D_create( double lambda_min, double lambda_max, + double lambda_step) +{ + sinfo_spectrum* result = NULL; + + + /* check input parameters */ + SINFO_ASSURE_NOT_ILLEGAL( lambda_min >= 0.0 && lambda_min <= lambda_max); + SINFO_ASSURE_NOT_ILLEGAL( lambda_step >=0); + + SINFO_CALLOC(result, sinfo_spectrum,1); + + result->lambda_min = lambda_min; + result->lambda_max = lambda_max; + result->lambda_step = lambda_step; + + SINFO_NEW_PROPERTYLIST( result->flux_header); + check_nomsg(sinfo_pfits_set_wcs1(result->flux_header, 1.0, lambda_min, lambda_step)); + + SINFO_NEW_PROPERTYLIST( result->errs_header); + check_nomsg( sinfo_pfits_set_extname ( result->errs_header, "ERRS")); + check_nomsg(sinfo_pfits_set_wcs1(result->errs_header, 1.0, lambda_min, lambda_step)); + + SINFO_NEW_PROPERTYLIST( result->qual_header); + check_nomsg( sinfo_pfits_set_extname ( result->qual_header, "QUAL")); + + + result->size_lambda = (int)((lambda_max-lambda_min)/lambda_step+0.5)+1; + result->size_slit = 1; + result->slit_min = 0; + result->slit_max = 0; + result->size = result->size_lambda; + + check_nomsg( result->flux = cpl_image_new( result->size_lambda, 1, + CPL_TYPE_DOUBLE)); + check_nomsg( result->errs = cpl_image_new( result->size_lambda, 1, + CPL_TYPE_DOUBLE)); + check_nomsg( result->qual = cpl_image_new( result->size_lambda, 1, + CPL_TYPE_INT)); + + cleanup: + if (cpl_error_get_code() != CPL_ERROR_NONE) { + sinfo_spectrum_free(&result); + } + return result; +} + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Create a 2D spectrum structure + * + * @param[in] lambda_min minimum wavelength of spectrum + * @param[in] lambda_max maximum wavelength of spectrum + * @param[in] lambda_step lambda binning + * @param[in] slit_min minimum slit value + * @param[in] slit_max maximum slit value + * @param[in] slit_step slit step + * + * @return the spectrum structure + */ +/*---------------------------------------------------------------------------*/ +sinfo_spectrum* sinfo_spectrum_2D_create( double lambda_min, double lambda_max, + double lambda_step, double slit_min, double slit_max, double slit_step) +{ + sinfo_spectrum* result = NULL; + + /* check input parameters */ + SINFO_ASSURE_NOT_ILLEGAL( lambda_min >= 0.0 && lambda_min <= lambda_max); + SINFO_ASSURE_NOT_ILLEGAL( lambda_step >=0); + SINFO_ASSURE_NOT_ILLEGAL( slit_min <= slit_max); + SINFO_ASSURE_NOT_ILLEGAL( slit_step >=0); + + + SINFO_CALLOC(result, sinfo_spectrum,1); + + result->lambda_min = lambda_min; + result->lambda_max = lambda_max; + result->lambda_step = lambda_step; + result->slit_min = slit_min; + result->slit_max = slit_max; + result->slit_step = slit_step; + + SINFO_NEW_PROPERTYLIST( result->flux_header); + check_nomsg(sinfo_pfits_set_wcs1(result->flux_header, 1.0, lambda_min, lambda_step)); + check_nomsg(sinfo_pfits_set_wcs2(result->flux_header, 1.0, slit_min, slit_step)); + + check_nomsg(sinfo_set_cd_matrix2d(result->flux_header)); + + SINFO_NEW_PROPERTYLIST( result->errs_header); + check_nomsg( sinfo_pfits_set_extname ( result->errs_header, "ERRS")); + SINFO_NEW_PROPERTYLIST( result->qual_header); + check_nomsg( sinfo_pfits_set_extname ( result->qual_header, "QUAL")); + + + result->size_lambda = (int)((lambda_max-lambda_min)/lambda_step+0.5)+1; + result->size_slit = (int)((slit_max-slit_min)/slit_step+0.5)+1; + result->size = result->size_lambda * result->size_slit; + check_nomsg( result->flux = cpl_image_new( result->size_lambda, result->size_slit, + CPL_TYPE_DOUBLE)); + check_nomsg( result->errs = cpl_image_new( result->size_lambda, result->size_slit, + CPL_TYPE_DOUBLE)); + check_nomsg( result->qual = cpl_image_new( result->size_lambda, result->size_slit, + CPL_TYPE_INT)); + + cleanup: + if (cpl_error_get_code() != CPL_ERROR_NONE) { + sinfo_spectrum_free(&result); + } + return result; +} + + +/*----------------------------------------------------------------*/ +/** + * @brief Convert a CPL type to a string + * @param t Type to convert + * @return A textual representation of @em t. + */ +/*----------------------------------------------------------------*/ +const char * +sinfo_tostring_cpl_type (cpl_type t) +{ + + /* Note that CPL_TYPE_STRING is shorthand + for CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY . */ + + if (!(t & CPL_TYPE_FLAG_ARRAY)) + switch (t & (~CPL_TYPE_FLAG_ARRAY)) { + case CPL_TYPE_CHAR: + return "char"; + break; + case CPL_TYPE_UCHAR: + return "uchar"; + break; + case CPL_TYPE_BOOL: + return "boolean"; + break; + case CPL_TYPE_INT: + return "int"; + break; + case CPL_TYPE_UINT: + return "uint"; + break; + case CPL_TYPE_LONG: + return "long"; + break; + case CPL_TYPE_ULONG: + return "ulong"; + break; + case CPL_TYPE_FLOAT: + return "float"; + break; + case CPL_TYPE_DOUBLE: + return "double"; + break; + case CPL_TYPE_POINTER: + return "pointer"; + break; +/* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex"; break; */ + case CPL_TYPE_INVALID: + return "invalid"; + break; + default: + return "unrecognized type"; + } + else + switch (t & (~CPL_TYPE_FLAG_ARRAY)) { + case CPL_TYPE_CHAR: + return "string (char array)"; + break; + case CPL_TYPE_UCHAR: + return "uchar array"; + break; + case CPL_TYPE_BOOL: + return "boolean array"; + break; + case CPL_TYPE_INT: + return "int array"; + break; + case CPL_TYPE_UINT: + return "uint array"; + break; + case CPL_TYPE_LONG: + return "long array"; + break; + case CPL_TYPE_ULONG: + return "ulong array"; + break; + case CPL_TYPE_FLOAT: + return "float array"; + break; + case CPL_TYPE_DOUBLE: + return "double array"; + break; + case CPL_TYPE_POINTER: + return "pointer array"; + break; +/* not in CPL3.0: case CPL_TYPE_COMPLEX: return "complex array"; break; */ + case CPL_TYPE_INVALID: + return "invalid (array)"; + break; + default: + return "unrecognized type"; + } +} + +/*---------------------------------------------------------------------------*/ +/** + @brief Read a property value from a property list + @param plist Propertylist to read + @param keyword Name of property to read + @param keywordtype Type of keyword + @param result The value read + + @return CPL_ERROR_NONE iff OK + + This function wraps @c cpl_propertylist_get_int(), + @c cpl_propertylist_get_bool(), @c cpl_propertylist_get_double() and + @c cpl_propertylist_get_string(). + It checks existence and type of the requested keyword before reading + and describes what went wrong if the property could not be read. + + @note The result is written to the variable pointed to by the + parameter @em result. Because this is a void pointer, + it is the responsibility of the caller to make sure that the type + of this pointer variable corresponds to the requested @em keywordtype. + E.g. if @em keywordtype is CPL_TYPE_BOOL, then @em result must be an bool + pointer (bool *). If @em keywordtype isCPL_TYPE_STRING, then @em result + must be a char **, and so on. + +*/ +/*---------------------------------------------------------------------------*/ +cpl_error_code +sinfo_get_property_value(const cpl_propertylist * plist, + const char *keyword, + cpl_type keywordtype, + void *result) +{ + cpl_type t; + + /* Check input */ + assure (plist != NULL, CPL_ERROR_NULL_INPUT, "Null property list"); + assure (keyword != NULL, CPL_ERROR_NULL_INPUT, "Null keyword"); + /* Check for existence... */ + assure (cpl_propertylist_has (plist, keyword), CPL_ERROR_DATA_NOT_FOUND, + "Keyword %s does not exist", keyword); + /* ...and type of keyword */ + check(t = cpl_propertylist_get_type (plist, keyword), + "Could not read type of keyword '%s'", keyword); + assure (t == keywordtype, CPL_ERROR_TYPE_MISMATCH, + "Keyword '%s' has wrong type (%s). %s expected", + keyword, sinfo_tostring_cpl_type (t), + sinfo_tostring_cpl_type (keywordtype)); + /* Read the keyword */ + switch (keywordtype) { + case CPL_TYPE_INT: + check(*((int *) result) = cpl_propertylist_get_int (plist, keyword), + "Could not get (integer) value of %s", keyword); + break; + case CPL_TYPE_BOOL: + check(*((bool *) result) = cpl_propertylist_get_bool (plist, keyword), + "Could not get (boolean) value of %s", keyword); + break; + case CPL_TYPE_DOUBLE: + check(*((double *) result) = + cpl_propertylist_get_double (plist, keyword), + "Could not get (double) value of %s", keyword); + break; + case CPL_TYPE_STRING: + check(*((const char **) result) = + cpl_propertylist_get_string (plist, keyword), + "Could not get (string) value of %s", keyword); + break; + default: + assure (false, CPL_ERROR_INVALID_TYPE, "Unknown type"); + } + +cleanup: + return cpl_error_get_code (); +} + + +/** + @brief find out the rectify space (slit) binning + @param plist property list to read from + @return double the requested value + */ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_get_rectify_bin_space(cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check(sinfo_get_property_value (plist, SINFO_RECTIFY_BIN_SPACE, + CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_RECTIFY_BIN_SPACE); + +cleanup: + return returnvalue; +} +/** + @brief find out the rectify SPACE max + @param plist property list to read from + @return double the requested value + */ +double sinfo_pfits_get_rectify_space_max(cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check (sinfo_get_property_value (plist, SINFO_RECTIFY_SPACE_MAX, + CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_RECTIFY_SPACE_MAX); + +cleanup: + return returnvalue; +} +/** + @brief find out the rectify space min + @param plist property list to read from + @return double the requested value + */ +double sinfo_pfits_get_rectify_space_min(cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check (sinfo_get_property_value (plist, SINFO_RECTIFY_SPACE_MIN, + CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_RECTIFY_SPACE_MIN); + +cleanup: + return returnvalue; +} +/** + @brief find out the rectify lambda min + @param plist property list to read from + @return double the requested value + */ +double sinfo_pfits_get_rectify_lambda_min(cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check (sinfo_get_property_value (plist, SINFO_RECTIFY_LAMBDA_MIN, + CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_RECTIFY_LAMBDA_MIN); + +cleanup: + return returnvalue; +} + +/** + @brief find out the rectify lambda max + @param plist property list to read from + @return double the requested value + */ +double sinfo_pfits_get_rectify_lambda_max(cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check (sinfo_get_property_value (plist, SINFO_RECTIFY_LAMBDA_MAX, + CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_RECTIFY_LAMBDA_MAX); + +cleanup: + return returnvalue; +} + + +/** + @brief find out the rectify lambda binning + @param plist property list to read from + @return double the requested value + */ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_get_rectify_bin_lambda(cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check(sinfo_get_property_value (plist, SINFO_RECTIFY_BIN_LAMBDA, + CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_RECTIFY_BIN_LAMBDA); + +cleanup: + return returnvalue; +} +/*--------------------------------------------------------------------------- */ +/** + * @brief find out the pcatg + * @param plist property list to read from + * @return pointer to statically allocated character string + * */ +/*--------------------------------------------------------------------------- */ +const char * sinfo_pfits_get_pcatg (const cpl_propertylist * plist) +{ + const char *returnvalue = ""; + + check(sinfo_get_property_value + (plist, SINFO_PCATG, CPL_TYPE_STRING, &returnvalue), + "Error reading keyword '%s'", SINFO_PCATG); +cleanup: + return returnvalue; +} +/*--------------------------------------------------------------------------- */ +/** + * @brief find out the EXTNAME + * @param plist property list to read from + * @return pointer to statically allocated character string + * */ +/*--------------------------------------------------------------------------- */ +const char * +sinfo_pfits_get_extname (const cpl_propertylist * plist) +{ + const char *returnvalue = ""; + + check (sinfo_get_property_value + (plist, SINFO_EXTNAME, CPL_TYPE_STRING, &returnvalue), + "Error reading keyword '%s'", SINFO_EXTNAME); +cleanup: + return returnvalue; +} +/*---------------------------------------------------------------------------*/ +/** + @brief find out the BINX value + @param plist property list to read from + @return the requested value +*/ +/*---------------------------------------------------------------------------*/ +int sinfo_pfits_get_binx(const cpl_propertylist * plist) +{ + int ret = 0; + + SINFO_PFITS_GET( ret, plist, SINFO_WIN_BINX, CPL_TYPE_INT); + + cleanup: + return ret; +} + +/*---------------------------------------------------------------------------*/ +/** + @brief find out the BINY value + @param plist property list to read from + @return the requested value +*/ +/*---------------------------------------------------------------------------*/ +int sinfo_pfits_get_biny(const cpl_propertylist * plist) +{ + int ret = 0; + + SINFO_PFITS_GET( ret, plist, SINFO_WIN_BINY, CPL_TYPE_INT); + + cleanup: + return ret; +} + +void +sinfo_pfits_set_extname (cpl_propertylist * plist, const char *value) +{ + check(cpl_propertylist_update_string (plist, SINFO_EXTNAME, value), + "Error writing keyword '%s'", SINFO_EXTNAME); +cleanup: + return; +} +void sinfo_pfits_set_ctype1(cpl_propertylist * plist, const char* value) +{ + check (cpl_propertylist_update_string (plist, SINFO_CTYPE1, value), + "Error writing keyword '%s'", SINFO_CTYPE1); + cleanup: + return; +} +void sinfo_pfits_set_cunit1(cpl_propertylist * plist, const char* value) +{ + check (cpl_propertylist_update_string (plist, SINFO_CUNIT1, value), + "Error writing keyword '%s'", SINFO_CUNIT1); + cleanup: + return; +} + + +void +sinfo_pfits_set_pcatg (cpl_propertylist * plist, const char *value) +{ + cpl_propertylist_update_string (plist, SINFO_PCATG, value); + + return; +} + +const char * +sinfo_tostring_cpl_frame_type (cpl_frame_type ft) +{ + switch (ft) { + case CPL_FRAME_TYPE_NONE: + return "NONE"; + break; + case CPL_FRAME_TYPE_IMAGE: + return "IMAGE"; + break; + case CPL_FRAME_TYPE_MATRIX: + return "MATRIX"; + break; + case CPL_FRAME_TYPE_TABLE: + return "TABLE"; + break; + default: + return "unrecognized frame type"; + } +} + + +int +sinfo_print_rec_status(const int val) { + if(cpl_error_get_code() != CPL_ERROR_NONE) { + sinfo_msg_error("Recipe status at %d",val); + sinfo_msg_error("%s",(const char*) cpl_error_get_message()); + sinfo_msg_error("%s",(const char*) cpl_error_get_where()); + return -1; + } + return 0; +} + +const char* sinfo_band_tostring(new_sinfo_band band){ + return + (band == INSTRUMENT_BAND_UVB) ? "UVB" : + (band == INSTRUMENT_BAND_VIS) ? "VIS" : + (band == INSTRUMENT_BAND_NIR) ? "NIR" : + (band == INSTRUMENT_BAND_J) ? "J" : + (band == INSTRUMENT_BAND_H) ? "H" : + (band == INSTRUMENT_BAND_K) ? "K" : "HK"; +} + + + + +cpl_frame* +sinfo_frame_product(const char* fname, const char* tag, cpl_frame_type type, + cpl_frame_group group,cpl_frame_level level) +{ + cpl_frame* frame=NULL; + frame=cpl_frame_new(); + + sinfo_frame_config(fname,tag,type,group,level,&frame); + + return frame; + +} + +void sinfo_pfits_set_bunit(cpl_propertylist * plist, const char* value) +{ + check (cpl_propertylist_update_string (plist, SINFO_BUNIT, value), + "Error writing keyword '%s'", SINFO_BUNIT); + cleanup: + return; +} + +double sinfo_pfits_get_airm_mean (const cpl_propertylist * plist) +{ + double airmass_start=0; + double airmass_end=0; + airmass_start = sinfo_pfits_get_airm_start(plist); + airmass_end = sinfo_pfits_get_airm_end(plist); + + return 0.5*(airmass_start+airmass_end); +} + + + +int +sinfo_pfits_get_naxis1 (const cpl_propertylist * plist) +{ + int ret = 0; + + sinfo_get_property_value( plist, SINFO_NAXIS1, CPL_TYPE_INT, &ret); + + cleanup: + return ret; +} + + + +int sinfo_pfits_get_naxis (const cpl_propertylist * plist) +{ + int ret = 0; + + sinfo_get_property_value( plist, SINFO_NAXIS, CPL_TYPE_INT, &ret); + + cleanup: + return ret; +} + +cpl_error_code +sinfo_pfits_set_wcs1(cpl_propertylist* header, + const double crpix1, + const double crval1, + const double cdelt1) { + + cpl_propertylist_append_double(header, SINFO_CRPIX1, crpix1); + cpl_propertylist_append_double(header, SINFO_CRVAL1, crval1); + cpl_propertylist_append_double(header, SINFO_CDELT1, cdelt1); + cpl_propertylist_append_string(header, SINFO_CTYPE1, "LINEAR"); + + return cpl_error_get_code(); +} + + +cpl_error_code +sinfo_pfits_set_wcs2(cpl_propertylist* header, + const double crpix2, + const double crval2, + const double cdelt2) { + + cpl_propertylist_append_double(header, SINFO_CRPIX2, crpix2); + cpl_propertylist_append_double(header, SINFO_CRVAL2, crval2); + cpl_propertylist_append_double(header, SINFO_CDELT2, cdelt2); + cpl_propertylist_append_string(header, SINFO_CTYPE2, "LINEAR"); + + return cpl_error_get_code(); +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD1_1 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd11(cpl_propertylist * plist, double value) +{ + check(cpl_propertylist_update_double (plist, SINFO_CD11, value), + "Error writing keyword '%s'", SINFO_CD11); + cleanup: + return; +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD1_2 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd12(cpl_propertylist * plist, double value) +{ + check(cpl_propertylist_update_double (plist, SINFO_CD12, value), + "Error writing keyword '%s'", SINFO_CD12); + cleanup: + return; +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD2_1 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd21(cpl_propertylist * plist, double value) +{ + check(cpl_propertylist_update_double (plist, SINFO_CD21, value), + "Error writing keyword '%s'", SINFO_CD21); + cleanup: + return; +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD2_2 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd22(cpl_propertylist * plist, double value) +{ + check(cpl_propertylist_update_double (plist, SINFO_CD22, value), + "Error writing keyword '%s'", SINFO_CD22); + cleanup: + return; +} +static cpl_error_code +sinfo_pfits_set_cd_matrix(cpl_propertylist* header, + const double cdelt1, + const double cdelt2) { + + sinfo_pfits_set_cd11(header, cdelt1); + sinfo_pfits_set_cd12(header, 0); + sinfo_pfits_set_cd21(header, 0); + sinfo_pfits_set_cd22(header, cdelt2); + + return cpl_error_get_code(); +} + + + +cpl_error_code +sinfo_pfits_set_wcs(cpl_propertylist* header, const double crpix1, + const double crval1, const double cdelt1, const double crpix2, + const double crval2, const double cdelt2) { + + sinfo_pfits_set_wcs1(header, crpix1, crval1, cdelt1); + sinfo_pfits_set_wcs2(header, crpix2, crval2, cdelt2); + sinfo_pfits_set_cd_matrix(header, cdelt1, cdelt2); + + return cpl_error_get_code(); +} + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Set CD matrix + * @param plist input propertylist + * @return updated propertylist + */ +/*---------------------------------------------------------------------------*/ +cpl_error_code sinfo_set_cd_matrix2d(cpl_propertylist* plist) +{ + double cdelt1=0; + double cdelt2=0; + + /* dummy values */ + check_nomsg(cdelt1=sinfo_pfits_get_cdelt1(plist)); + check_nomsg(cdelt2=sinfo_pfits_get_cdelt2(plist)); + check_nomsg(sinfo_pfits_set_cd11(plist,cdelt1)); + check_nomsg(sinfo_pfits_set_cd12(plist,0.)); + check_nomsg(sinfo_pfits_set_cd21(plist,0.)); + check_nomsg(sinfo_pfits_set_cd22(plist,cdelt2)); + + cleanup: + + return cpl_error_get_code(); + +} + + + +/*--------------------------------------------------------------------------- */ +/** + @brief find out the BUNIT + @param plist property list to read from + @return pointer to statically allocated character string + */ +/*--------------------------------------------------------------------------- */ +const char * +sinfo_pfits_get_bunit (const cpl_propertylist * plist) +{ + const char *returnvalue = ""; + + check (sinfo_get_property_value + (plist, SINFO_BUNIT, CPL_TYPE_STRING, &returnvalue), + "Error reading keyword '%s'", SINFO_BUNIT); + +cleanup: + return returnvalue; +} + +void sinfo_pfits_set_qc_eff_fclip( cpl_propertylist * plist, + double value ) +{ + check(cpl_propertylist_update_double(plist,SINFO_QC_EFF_FCLIP,value), + "error writing keyword '%s'", SINFO_QC_EFF_FCLIP); + cleanup: + return ; +} +/*--------------------------------------------------------------------------- */ +/** + @brief find out the DET WIN1 DIT1 value + @param plist property list to read from + @return the requested value + */ +/*--------------------------------------------------------------------------- */ +double +sinfo_pfits_get_win1_dit1 (const cpl_propertylist * plist) +{ + double returnvalue = 0; + + check (sinfo_get_property_value + (plist, SINFO_DET_WIN1_DIT1, CPL_TYPE_DOUBLE, &returnvalue), + "Error reading keyword '%s'", SINFO_DET_WIN1_DIT1); + +cleanup: + return returnvalue; +} +void sinfo_pfits_set_qc_eff_nclip( cpl_propertylist * plist, + int value ) +{ + check(cpl_propertylist_update_int(plist,SINFO_QC_EFF_NCLIP,value), + "error writing keyword '%s'", SINFO_QC_EFF_NCLIP); + cleanup: + return ; +} +/*--------------------------------------------------------------------------- */ +/** + @brief find out the CONAD value + @param plist property list to read from + @return the requested value +*/ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_get_conad (const cpl_propertylist * plist) +{ + double ret = 0; + + SINFO_PFITS_GET( ret, plist, SINFO_CONAD, CPL_TYPE_DOUBLE); + + cleanup: + return ret; +} + +/*--------------------------------------------------------------------------*/ +/** + @brief Computes round(x) + @param x input + @return round(x) +*/ +/*--------------------------------------------------------------------------*/ +long sinfo_round_double(double x) +{ + return (x >=0) ? (long)(x+0.5) : (long)(x-0.5); +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief free memory associated to an 1D spectrum + * + * @param[in] s spectrum structure to free +*/ +/*---------------------------------------------------------------------------*/ +void sinfo_spectrum_free( sinfo_spectrum** s) +{ + if (s && *s){ + sinfo_free_propertylist( &((*s)->flux_header)); + sinfo_free_propertylist( &((*s)->errs_header)); + sinfo_free_propertylist( &((*s)->qual_header)); + sinfo_free_image( &((*s)->flux)); + sinfo_free_image( &((*s)->errs)); + sinfo_free_image( &((*s)->qual)); + SINFO_FREE( (*s)); + } +} + +/** +@brief get RA, DEC, airmass (mean) of a frame +@param frm_sci input frame +@param ra right ascension +@param dec declination +@param airmass airmass (mean) +@return void + */ +void +sinfo_frame_sci_get_ra_dec_airmass(cpl_frame* frm_sci, + double* ra, + double* dec, + double* airmass) +{ + + const char* name_sci=NULL; + cpl_propertylist* plist=NULL; + + name_sci=cpl_frame_get_filename(frm_sci); + cpl_msg_warning("", "RA/DEC/Amass loadfing from %s", name_sci); + check_nomsg(plist=cpl_propertylist_load(name_sci,0)); + *ra=sinfo_pfits_get_ra(plist); + *dec=sinfo_pfits_get_dec(plist); + *airmass=sinfo_pfits_get_airm_mean(plist); + +cleanup: + + sinfo_free_propertylist(&plist); + return; +} + +//typedef struct _star_index_ star_index; +static const char* COL_NAME_EXTID = "ext_id"; +static const char* COL_NAME_NAME = "name"; +static const char* COL_NAME_RA = "ra"; +static const char* COL_NAME_DEC = "dec"; + +static star_index* star_index_construct(const char* fits_file); +static void star_index_destruct(star_index* pindex); +// private functions + +static star_index* star_index_construct(const char* fits_file) +{ + star_index* pret = cpl_malloc(sizeof(star_index)); + pret->index_size = 0; + pret->index_table = 0; + pret->cache_size = 0; + pret->cache = 0; + pret->cache_index = 0; + if (fits_file) + { + size_t bt = strlen(fits_file) * sizeof(*fits_file)+1; + pret->fits_file_name = cpl_malloc(bt); + strcpy(pret->fits_file_name, fits_file); + } + else + { + pret->fits_file_name = 0; + } + return pret; +} + +static void star_index_destruct(star_index* pindex) +{ + if(pindex) + { + if (pindex->cache) + { + int i = 0; + for ( i = 0; i < pindex->cache_size; i++) + { + cpl_table_delete(pindex->cache[i]); + } + cpl_free(pindex->cache); + pindex->cache = 0; + pindex->cache_size = 0; + } + cpl_table_delete(pindex->index_table); + if(pindex->fits_file_name) + { + cpl_free(pindex->fits_file_name); + } + cpl_free(pindex->cache_index); + cpl_free(pindex); + } + +} +star_index* star_index_create(void) +{ + star_index* pret = star_index_construct(0); + // initialize table + pret->index_table = cpl_table_new(pret->index_size); + // create columns ext_id, name, ra, dec + check_nomsg(cpl_table_new_column(pret->index_table, COL_NAME_EXTID, CPL_TYPE_INT)); + check_nomsg(cpl_table_new_column(pret->index_table, COL_NAME_NAME, CPL_TYPE_STRING)); + check_nomsg(cpl_table_new_column(pret->index_table, COL_NAME_RA, CPL_TYPE_DOUBLE)); + check_nomsg(cpl_table_new_column(pret->index_table, COL_NAME_DEC, CPL_TYPE_DOUBLE)); + return pret; + cleanup: + star_index_destruct(pret); + return 0; +} +star_index* star_index_load(const char* fits_file) +{ + star_index* pret = star_index_construct(fits_file); + // load index table from the file + cpl_table* pindex = 0; + check_nomsg(pindex = cpl_table_load(fits_file,1,0)); + // TODO check the structure of the table + pret->index_table = pindex; + check_nomsg(pret->index_size = cpl_table_get_nrow(pindex)); + return pret; + cleanup: + star_index_destruct(pret); + cpl_error_reset(); + return 0; +} +void star_index_delete(star_index* pindex) +{ + star_index_destruct(pindex); +} +int star_index_add(star_index* pindex, double RA, double DEC, const char* star_name, cpl_table* ptable) +{ + int retval = 0; + if (pindex) + { + // expand the index table + + check_nomsg(cpl_table_insert_window(pindex->index_table, pindex->index_size++, 1)); + if (!pindex->cache) + { + pindex->cache_size = 1; + pindex->cache = cpl_malloc(sizeof(cpl_table*) * pindex->cache_size); + pindex->cache_index = cpl_malloc(sizeof(pindex->cache_index[0]) * pindex->cache_size); + } + else + { + // add new entry + pindex->cache_size++; + pindex->cache = cpl_realloc(pindex->cache, sizeof(cpl_table*) * pindex->cache_size); + } + check_nomsg(pindex->cache[pindex->cache_size - 1] = cpl_table_duplicate(ptable)); + // fill the index table with values + check_nomsg(cpl_table_set_string(pindex->index_table, COL_NAME_NAME, pindex->index_size - 1 ,star_name)); + check_nomsg(cpl_table_set(pindex->index_table, COL_NAME_RA, pindex->index_size - 1 ,RA)); + check_nomsg(cpl_table_set(pindex->index_table, COL_NAME_DEC, pindex->index_size - 1,DEC)); + check_nomsg(cpl_table_set_int(pindex->index_table, COL_NAME_EXTID, pindex->index_size - 1 ,pindex->index_size + 1)); + retval = pindex->index_size; + } + return retval; + + cleanup: + return 0; +} + +int start_index_get_size(star_index* pindex) +{ + return pindex ? pindex->index_size : 0; +} + +int star_index_remove_by_name(star_index* pindex, const char* starname) +{ + int i = 0; + int index_pos = -1; + for (i = 0; i < pindex->index_size; i++) + { + const char* curr_star_name = 0; + check_nomsg(curr_star_name = cpl_table_get_string(pindex->index_table, COL_NAME_NAME, i)); + if (strcmp(curr_star_name, starname) == 0) + { + index_pos = i; + break; + } + } + if (index_pos >= 0) + { + // star is found + // clear only the index table, real data would be cleaned during save operation + cpl_table_set_int(pindex->index_table, COL_NAME_EXTID, index_pos, -1); + if (index_pos - pindex->index_size + pindex->cache_size >= 0) + { + // clear cache + int cache_index = index_pos - pindex->index_size + pindex->cache_size; + cpl_table_delete(pindex->cache[cache_index]); + pindex->cache[cache_index] = 0; + } + } + cleanup: + return index_pos; +} + +int star_index_save(star_index* pindex, const char* fits_file) +{ + int i = 0; + int inull = 0; + cpl_table* pnew_index = 0; + int nrows = 0; + // firstly save the index table - deleted entries should be removed firstly + check_nomsg(cpl_table_unselect_all(pindex->index_table)); + check_nomsg(cpl_table_or_selected_int(pindex->index_table, COL_NAME_EXTID, CPL_EQUAL_TO, -1)); + // inverse selection + check_nomsg(cpl_table_not_selected(pindex->index_table)); + check_nomsg(pnew_index = cpl_table_extract_selected(pindex->index_table)); + + nrows = cpl_table_get_nrow(pnew_index); + for (i = 0; i < nrows; i++) + { + cpl_table_set_int(pnew_index, COL_NAME_EXTID, i, i+2); // ext in fits starts from 1, and another 1 is used by index_table + } + check_nomsg(cpl_table_save(pnew_index, NULL, NULL, fits_file, CPL_IO_CREATE)); + cpl_table_delete(pnew_index); + pnew_index = 0; + // save the data + for (i = 0;i < pindex->index_size; i++) + { + // 2. save cache + int saved_ext = cpl_table_get_int(pindex->index_table, COL_NAME_EXTID, i, &inull); + if (saved_ext > 0) // check that was not removed + { + cpl_table* ptable = 0; + if (i < pindex->index_size - pindex->cache_size) + { + check_nomsg(ptable = cpl_table_load(pindex->fits_file_name, saved_ext, 0)); + } + else + { + ptable = cpl_table_duplicate(pindex->cache[i - pindex->index_size + pindex->cache_size ]); + } + check_nomsg(cpl_table_save(ptable, NULL, NULL, fits_file, CPL_IO_EXTEND)); + cpl_table_delete(ptable); + } + } + cleanup: + return nrows; +} +cpl_table* star_index_get(star_index* pindex, double RA, double DEC, double RA_EPS, double DEC_EPS, const char** pstar_name) +{ + int i = 0; + cpl_table* pret = 0; + int inull = 0; + + for (i = 0; i < pindex->index_size; i++) + { + double curr_ra = 0; + double curr_dec = 0; + int ext_id = 0; + + check_nomsg(ext_id = cpl_table_get_int(pindex->index_table, COL_NAME_EXTID, i ,&inull)); + check_nomsg(curr_ra = cpl_table_get(pindex->index_table, COL_NAME_RA, i,&inull)); + check_nomsg(curr_dec = cpl_table_get(pindex->index_table, COL_NAME_DEC, i,&inull)); + if ((ext_id > 0) && (fabs(curr_ra - RA) < RA_EPS) && (fabs(curr_dec - DEC) < DEC_EPS)) + { + cpl_msg_warning("", "EXETION SELECTED FOR fit POINTS : %i", ext_id); + // found + // retrieve the data + if (i - pindex->index_size + pindex->cache_size >= 0) + { + // data is in cache + pret = cpl_table_duplicate(pindex->cache[i - pindex->index_size + pindex->cache_size ]); + } + else + { + // data is on disk + pret = cpl_table_load(pindex->fits_file_name, ext_id, 0); + } + if (pret && pstar_name) + { + check_nomsg(*pstar_name = cpl_table_get_string(pindex->index_table, COL_NAME_NAME, i)); + } + break; + } + } + cleanup: + return pret; +} + +void star_index_dump(star_index* pindex, FILE* pfile) +{ + cpl_table_dump(pindex->index_table, 0, cpl_table_get_nrow(pindex->index_table), pfile); +} + + +/*---------------------------------------------------------------------------*/ +/** + @brief parse referece std stars catalog + + @param cat input frame catalog + @param dRA Right Ascension + @param dDEC Declination + @param EPSILON tolerance to find ref spectra on catalog on (ra,dec) + @param pptable pointer to new table + @return cpl error code. The table will contain interpolated data points + */ +/*---------------------------------------------------------------------------*/ + +cpl_error_code sinfo_parse_catalog_std_stars(cpl_frame* cat, double dRA, + double dDEC, double EPSILON, cpl_table** pptable,sinfo_std_star_id* std_star_id) { + const char* name = NULL; + SINFO_ASSURE_NOT_NULL_MSG(cat, "Provide input catalog"); + if (cat) { + check_nomsg(name=cpl_frame_get_filename(cat)); + if (name) { + star_index* pstarindex = star_index_load(name); + if (pstarindex) { + const char* star_name = NULL; + cpl_msg_warning("", + "Searching std RA[%f] DEC[%f] with tolerance[%f] in star catalog", dRA, dDEC, EPSILON); + *pptable = star_index_get(pstarindex, dRA, dDEC, EPSILON, EPSILON, + &star_name); + if(star_name != NULL) { + if ( strcmp(star_name,"GD71") == 0 ) *std_star_id = SINFO_GD71; + else if ( strcmp(star_name,"Feige110") == 0 ) *std_star_id = SINFO_Feige110; + else if ( strcmp(star_name,"GD153") == 0 ) *std_star_id = SINFO_GD153; + else if ( strcmp(star_name,"LTT3218") == 0 ) *std_star_id = SINFO_LTT3218; + else if ( strcmp(star_name,"LTT7987") == 0 ) *std_star_id = SINFO_LTT7987; + else if ( strcmp(star_name,"BD17") == 0 ) *std_star_id = SINFO_BD17; + else if ( strcmp(star_name,"EG274") == 0 ) *std_star_id = SINFO_EG274; + else if ( strcmp(star_name,"SYNTH") == 0 ) *std_star_id = SINFO_SINTH; + } + sinfo_msg_warning("star index=%d",*std_star_id); + sinfo_msg_warning("pptable=%p",*pptable); + sinfo_msg_warning("star_name=%s",star_name); + if (*pptable && star_name != NULL) { + sinfo_msg_warning("Found STD star: %s", star_name); + + } else { + sinfo_msg_warning( + "ERROR - REF star %s could not be found in the catalog", star_name); + } + } else { + sinfo_msg("ERROR - could not load the catalog"); + } + star_index_delete(pstarindex); + } + } + cleanup: return cpl_error_get_code(); +} + + + + + + +/*---------------------------------------------------------------------------*/ +/** + @brief Interpolate data points + @param wav value at which is desired an interpolated value + @param nrow number of data points + @param pw pointer to wave array + @param pe pointer to efficiency array + @return Interpolated data points + */ +/*---------------------------------------------------------------------------*/ +double +sinfo_data_interpolate( + double wav, + int nrow, + double* pw, + double* pe + ) +{ + double y = 0; + double w1=pw[0]; + double w2=pw[nrow-1]; + double y1_=pe[0]; /*was changed from y1 to y1_ due a warning from compiler - shadowed variable*/ + double y2=pe[nrow-1]; + if(wav < pw[0]) + { + w1=pw[0]; + w2=pw[1]; + y1_=pe[0]; + y2=pe[1]; + } + else if (wav > pw[nrow - 1]) + { + w1=pw[nrow - 2]; + w2=pw[nrow - 1]; + y1_=pe[nrow - 2]; + y2=pe[nrow - 1]; + } + else + { + int l = 0; + int h = nrow - 1; + int curr_row = 0; + curr_row = (h-l) / 2; + while( h-l >1 ) + { + if(wav < pw[curr_row]) + { + h = curr_row; + } + else + { + l = curr_row; + } + curr_row = (h-l) / 2 + l; + } + w1=pw[curr_row]; + w2=pw[curr_row + 1]; + y1_=pe[curr_row]; + y2=pe[curr_row + 1]; + } + y=y1_+(y2-y1_)/(w2-w1)*(wav-w1); + return y; +} + +int +sinfo_column_to_double(cpl_table* ptable, const char* column) +{ + const char* TEMP = "_temp_"; + check_nomsg(cpl_table_duplicate_column(ptable, TEMP, ptable, column)); + check_nomsg(cpl_table_erase_column(ptable, column)); + check_nomsg(cpl_table_cast_column(ptable, TEMP, column, CPL_TYPE_DOUBLE)); + check_nomsg(cpl_table_erase_column(ptable, TEMP )); + return 0; + cleanup: + sinfo_msg(" error column to double [%s]", column); + return -1; +} + +double* +sinfo_create_column_double(cpl_table* tbl, const char* col_name, int nrow) +{ + double* retval = 0; + check_nomsg(cpl_table_new_column(tbl, col_name, CPL_TYPE_DOUBLE)); + check_nomsg(cpl_table_fill_column_window_double(tbl, col_name, 0, nrow, -1)); + check_nomsg(retval = cpl_table_get_data_double(tbl,col_name)); + return retval; + cleanup: + return retval; +} +/*---------------------------------------------------------------------------*/ +/** + @brief Interpolate table columns + @param tbl Table + @param wav value at which is desired to get an interpolated value + @param colx 1st column name + @param coly 2nd column name + + @return interpolated value if ok + +*/ +/*---------------------------------------------------------------------------*/ +double +sinfo_table_interpolate(cpl_table* tbl, + double wav, + const char* colx, + const char* coly) +{ + + double y=0; + double* pe=NULL; + double* pw=NULL; + int nrow=0; + + check_nomsg(pw=cpl_table_get_data_double(tbl,colx)); + check_nomsg(pe=cpl_table_get_data_double(tbl,coly)); + check_nomsg(nrow=cpl_table_get_nrow(tbl)); + + y = sinfo_data_interpolate(wav, nrow, pw, pe); + cleanup: + return y; + +} +/*---------------------------------------------------------------------------*/ +/** + @brief Compute efficiency + @param tbl_obj_spectrum input object spectrum + @param tbl_atmext input atmospheric extinction table + @param tbl_ref input reference flux STD table + @param exptime input exposure time + @param airmass input observed frame airmass + @param aimprim input airmass corrective factor + @param gain input gain + @param biny bin on Y (spatial) direction + @param src2ref_wave_sampling input cnversion factor to pass from src 2 ref units + @param col_name_atm_wave atmospheric extinction table wave column name + @param col_name_atm_abs atmospheric extinction table absorption column name + @param col_name_ref_wave reference flux std table wave column name + @param col_name_ref_flux reference flux std table flux column name + @param col_name_ref_bin reference flux std table bin value + @param col_name_obj_wave observed std table wave column name + @param col_name_obj_flux observed std table flux column name + + @return table with computed efficiency + */ +/*---------------------------------------------------------------------------*/ + +cpl_table* +sinfo_utils_efficiency_internal(cpl_table* tbl_obj_spectrum, + cpl_table* tbl_atmext, + cpl_table* tbl_ref, + double exptime, + double airmass, + double aimprim, + double gain, + int biny, + double src2ref_wave_sampling, + const char* col_name_atm_wave, + const char* col_name_atm_abs, + const char* col_name_ref_wave, + const char* col_name_ref_flux, + const char* col_name_ref_bin, + const char* col_name_obj_wave, + const char* col_name_obj_flux, + int* ntot, + int* nclip + ) +{ + + const double TEL_AREA = 51.2e4; /* collecting area in cm2 */ + double cdelta1 = 0; + int i = 0; + cpl_table* tbl_sel = NULL; + + /* structure of the input table + * col type description + * wavelength double + * flux double + * */ + cpl_table* tbl_result = NULL; // output table + + /* + * structure of the output table + * col type description + * wavelength double + * EFF double efficiency in range 0-1 + * */ + + double* pref = NULL; + double* pext = NULL; + double* pcor = NULL; + double* peph = NULL; + + double* pw = NULL; // wavelength of the input table + int nrow = 0; + double ref_bin_size=0; + double um2nm=0.001; + double eff_med=0.; + double eff_rms=0.; + double eff_thresh=0.; + + double kappa=5; + double nm2AA=10.; + int nsel=0; + double eff=0; + nrow = cpl_table_get_nrow(tbl_obj_spectrum); + /* + sinfo_msg_dbg_medium("Starting efficiency calculation: exptime[%f] airmass[%f] nrow[%d]", + exptime, airmass, nrow); + */ + //cpl_table_dump(tbl_obj_spectrum,0,3,stdout); + //sinfo_msg("col wave=%s col_flux=%s",col_name_obj_wave,col_name_obj_flux); + + /* convert to double */ + sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_wave); + sinfo_column_to_double(tbl_obj_spectrum,col_name_obj_flux); + + check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_wave )); + check_nomsg(sinfo_column_to_double(tbl_atmext,col_name_atm_abs )); + check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_wave )); + check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_flux )); + check_nomsg(sinfo_column_to_double(tbl_ref,col_name_ref_bin )); + + /* as the reference spectra are erg cm-2 s-1 AA-1 and the wave scale + have been converted from AA to nm to be uniform to XSH scale + we apply a corresponding factor to the flux */ + //check_nomsg(cpl_table_multiply_scalar(tbl_ref,col_name_ref_flux,nm2AA)); + + /* get bin size of ref STD star spectrum */ + ref_bin_size=cpl_table_get_double(tbl_ref,col_name_ref_bin,0,NULL); + //sinfo_msg_dbg_medium("ref_bin_size[nm]=%g",ref_bin_size); + + /* + sinfo_msg("Unit conversion factor src/ref STD spectrum=%g", + src2ref_wave_sampling); + */ + + /* convert obj spectrum wave unit to the same of the reference one + This is required to be able to obtain the interpolated value of + the extinction and reference std star spectrum at the sampled + object wavelength when we compute the correction term due to + atmospheric extinction + */ + check_nomsg(cpl_table_multiply_scalar(tbl_obj_spectrum,col_name_obj_wave, + src2ref_wave_sampling)); + + + /* Computes the atmospheric distorsion correction: + COL_NAME_REF: reference std star flux value + COL_NAME_EXT: atm extinction + COL_NAME_EPHOT: photon energy + COL_NAME_COR: corrective factor (due to atmospheric extinction) + */ + //sinfo_msg_dbg_medium("object 2 src std wave factor %g",src2ref_wave_sampling); + check_nomsg(pw=cpl_table_get_data_double(tbl_obj_spectrum,col_name_obj_wave)); + + // prepare columns for the output data + check_nomsg(tbl_result=cpl_table_new(nrow)); + check_nomsg(pref=sinfo_create_column_double(tbl_result, COL_NAME_REF, nrow)); + check_nomsg(pext=sinfo_create_column_double(tbl_result, COL_NAME_EXT, nrow)); + check_nomsg(pcor=sinfo_create_column_double(tbl_result, COL_NAME_COR, nrow)); + check_nomsg(peph=sinfo_create_column_double(tbl_result, COL_NAME_EPHOT, nrow)); + //sinfo_msg_dbg_medium("wave range: [%g,%g] nm",pw[0],pw[nrow-1]); + //sinfo_msg_dbg_medium("src_bin_size[nm]=%g",pw[1] - pw[0]); + + cdelta1 = (pw[1] - pw[0]) / src2ref_wave_sampling ; /* we want the delta in original units. As we rescaled to AA we need to correct for this */ + //sinfo_msg_dbg_medium("nrow=%d cdelta1=%g",nrow,cdelta1); + for (i = 0; i < nrow; i++) + { + check_nomsg(pext[i] = sinfo_table_interpolate(tbl_atmext, pw[i],col_name_atm_wave, col_name_atm_abs)); + check_nomsg(pref[i] = sinfo_table_interpolate(tbl_ref, pw[i], col_name_ref_wave,col_name_ref_flux)); + pcor[i] = pow(10,(0.4*pext[i] * (aimprim - airmass))); + /*formula expects pw to be in um, but it is in nm. So we need to convert it*/ + eff = 1.e7*1.986e-19/(pw[i]*um2nm); + if(!isnan(eff)) { + peph[i]=eff; + } else { + /* + sinfo_msg("pw=%g pext=%g pref=%g pcor=%g pef=%g", + pw[i],pext[i],pref[i],pcor[i],peph[i]); + */ + cpl_table_set_invalid(tbl_result,COL_NAME_EPHOT,i); + } + /* ph energy: 1.986*10^-19(J.ph^-1)/lam(um) ==> + in as pw is expressed in nm units we need to multiply by um2nm: 10-3 + */ + /* + if(i< 2) { + sinfo_msg("pw[i]=%g,pcor=%g peph=%g",pw[i],pcor[i],peph[i]); + } + */ + } + cpl_table_erase_invalid(tbl_result); + + /* + sinfo_msg("atm: %s, %s ref: %s, %s obj: %s, %s", + col_name_atm_wave,col_name_atm_abs, + col_name_ref_wave,col_name_ref_flux, + col_name_obj_wave,col_name_obj_flux); + */ + /* add in result table also ORDER, OBJ(flux), WAVELENGTH columns */ + check_nomsg(cpl_table_duplicate_column(tbl_result,"ORDER", + tbl_obj_spectrum,COL_NAME_ORD_OBJ )); + check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_COR, + tbl_obj_spectrum, col_name_obj_flux)); + check_nomsg(cpl_table_duplicate_column(tbl_result,col_name_obj_wave, + tbl_obj_spectrum,col_name_obj_wave)); + + /* correct for atmospheric extintion: + bring the observed STD star out of the atmosphere */ + check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_COR,COL_NAME_COR)); + + /* correct object flux by binning: + As the reference std star spectra flux values are in units of + erg/cm2/s/A we have to obtain the bin size in Angstrom units. + Because the sampling step is in nm units, we need to apply a nm2AA factor: + cdelt1[src_sampling]*src2ref_wave_sampling*nm2AA */ + cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, src2ref_wave_sampling); + cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, cdelta1); + cpl_table_divide_scalar(tbl_result, COL_NAME_SRC_COR, nm2AA); + /* correct for spatial bin size: Why?? */ + cpl_table_divide_scalar(tbl_result,COL_NAME_SRC_COR,biny); + + + /*correct ref std star flux by binning: + divides by the bin size in ref_wave_sampling (usually AA) */ + check_nomsg(cpl_table_divide_scalar(tbl_result,COL_NAME_REF,ref_bin_size)); + + /* create efficiency column, initialized with the intensity value (ADU) + corrected for extinction and sampling step */ + check_nomsg(cpl_table_duplicate_column(tbl_result,COL_NAME_SRC_EFF, + tbl_result,COL_NAME_SRC_COR)); + + /* We need now to convert ADU to erg/cm2/s : + correct for detector gain, exposure time, telescope area: we are now + in units of electrons/s/cm2 */ + check_nomsg(cpl_table_multiply_scalar(tbl_result,COL_NAME_SRC_EFF, + gain / (exptime * TEL_AREA))); + + /* To pass from electron to ergs we correct for photon energy */ + check_nomsg(cpl_table_multiply_columns(tbl_result,COL_NAME_SRC_EFF, + COL_NAME_EPHOT)); + + /* our observed STD star value is now finally in the same units + as the one of the reference STD star: the efficiency is the ratio + observed_flux/reference_flux */ + + check_nomsg(cpl_table_divide_columns(tbl_result,COL_NAME_SRC_EFF,COL_NAME_REF)); + /* apply factor UVES_flux_factor (1.e16) as reference catalog has fluxes + in units of UVES_flux_factor (1e-16) */ + + + + /* To have cleaner plots we clean from outliers */ + + *ntot=cpl_table_get_nrow(tbl_result); + *nclip = 0; + cpl_boolean cleanup = CPL_FALSE; + if(cleanup){ + eff_med=cpl_table_get_column_median(tbl_result,COL_NAME_SRC_EFF); + eff_rms=cpl_table_get_column_stdev(tbl_result,COL_NAME_SRC_EFF); + + eff_thresh=(eff_med+kappa*eff_rms<10.) ? eff_med+kappa*eff_rms:10.; + if(irplib_isinf(eff_thresh)) eff_thresh=10.; + + cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF, + CPL_GREATER_THAN,1.e-5); + + cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF, + CPL_LESS_THAN,eff_thresh); + + eff_med=cpl_table_get_column_median(tbl_result,COL_NAME_SRC_EFF); + eff_rms=cpl_table_get_column_stdev(tbl_result,COL_NAME_SRC_EFF); + + eff_thresh=(eff_med+kappa*eff_rms<10.) ? eff_med+kappa*eff_rms:10.; + if(irplib_isinf(eff_thresh)) eff_thresh=10.; + + cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF, + CPL_LESS_THAN,eff_thresh); + + nsel=cpl_table_and_selected_double(tbl_result,COL_NAME_SRC_EFF, + CPL_LESS_THAN,1); + + *nclip=(*ntot)-nsel; + tbl_sel=cpl_table_extract_selected(tbl_result); + } else { + tbl_sel=cpl_table_duplicate(tbl_result); + } + + cleanup: + sinfo_free_table(&tbl_result); + return tbl_sel; +} + + +HIGH_ABS_REGION * +sinfo_fill_high_abs_regions( + new_sinfo_band band, + cpl_frame* high_abs_frame) +{ + HIGH_ABS_REGION * phigh=NULL; + int nrow=0; + double* pwmin=0; + double* pwmax=0; + int i=0; + cpl_table* high_abs_tab=NULL; + //XSH_ARM the_arm; + + if(high_abs_frame !=NULL) { + high_abs_tab=cpl_table_load(cpl_frame_get_filename(high_abs_frame),1,0); + } + //the_arm=xsh_instrument_get_arm(instrument); + + + + if(high_abs_tab!=NULL) { + nrow=cpl_table_get_nrow(high_abs_tab); + check_nomsg(pwmin=cpl_table_get_data_double(high_abs_tab,"LAMBDA_MIN")); + check_nomsg(pwmax=cpl_table_get_data_double(high_abs_tab,"LAMBDA_MAX")); + + phigh = (HIGH_ABS_REGION *) cpl_calloc(nrow + 1, sizeof(HIGH_ABS_REGION)); + for(i=0;iflux_header , "FLUX")); + check_nomsg(sinfo_plist_set_extra_keys(s->flux_header,"IMAGE","DATA","RMSE", + "FLUX","ERRS","QUAL",0)); + + check_nomsg( sinfo_pfits_set_extname(s->errs_header , "ERRS")); + check_nomsg(sinfo_plist_set_extra_keys(s->errs_header,"IMAGE","DATA","RMSE", + "FLUX","ERRS","QUAL",1)); + + check_nomsg( sinfo_pfits_set_extname(s->qual_header , "QUAL")); + check_nomsg(sinfo_plist_set_extra_keys(s->qual_header,"IMAGE","DATA","RMSE", + "FLUX","ERRS","QUAL",2)); + + /* Save the file */ + if ( s->size_slit > 1){ + + double crval1=0; + double crpix1=0; + double cdelt1=0; + + double crval2=0; + double crpix2=0; + double cdelt2=0; + + crval1=sinfo_pfits_get_crval1(s->flux_header); + crpix1=sinfo_pfits_get_crpix1(s->flux_header); + cdelt1=sinfo_pfits_get_cdelt1(s->flux_header); + + crval2=sinfo_pfits_get_crval2(s->flux_header); + crpix2=sinfo_pfits_get_crpix2(s->flux_header); + cdelt2=sinfo_pfits_get_cdelt2(s->flux_header); + + sinfo_pfits_set_wcs(s->errs_header,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2); + sinfo_pfits_set_wcs(s->qual_header,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2); + + check_nomsg( sinfo_pfits_set_pcatg( s->flux_header, tag)); + check(cpl_image_save ( s->flux, filename, SINFO_SPECTRUM_DATA_BPP, + s->flux_header, CPL_IO_DEFAULT), + "Could not save data to %s extension 0", filename); + check(cpl_image_save ( s->errs, filename, SINFO_SPECTRUM_ERRS_BPP, + s->errs_header, CPL_IO_EXTEND), + "Could not save errs to %s extension 1", filename); + check(cpl_image_save ( s->qual, filename, SINFO_SPECTRUM_QUAL_BPP, + s->qual_header, CPL_IO_EXTEND), + "Could not save qual to %s extension 2", filename); + } + else{ + cpl_vector *flux1D = NULL; + cpl_vector *err1D = NULL; + cpl_vector *qual1D = NULL; + + double crval1=0; + double crpix1=0; + double cdelt1=0; + + crval1=sinfo_pfits_get_crval1(s->flux_header); + crpix1=sinfo_pfits_get_crpix1(s->flux_header); + cdelt1=sinfo_pfits_get_cdelt1(s->flux_header); + + + + sinfo_pfits_set_ctype1(s->flux_header,"LINEAR"); + sinfo_pfits_set_cunit1(s->flux_header,"nm"); + cpl_propertylist_erase_regexp(s->flux_header, "^CTYPE2", 0); + + + + check_nomsg(sinfo_pfits_set_wcs1(s->errs_header, crpix1, crval1, cdelt1)); + sinfo_pfits_set_cunit1(s->errs_header,"nm"); + + check_nomsg(sinfo_pfits_set_wcs1(s->qual_header, crpix1, crval1, cdelt1)); + sinfo_pfits_set_cunit1(s->qual_header,"nm"); + sinfo_pfits_set_bunit(s->qual_header,SINFO_BUNIT_NONE_C); + + check_nomsg( flux1D = cpl_vector_new_from_image_row( s->flux, 1)); + check_nomsg( err1D = cpl_vector_new_from_image_row( s->errs, 1)); + check_nomsg( qual1D = cpl_vector_new_from_image_row( s->qual, 1)); + check_nomsg( cpl_vector_save( flux1D, filename, SINFO_SPECTRUM_DATA_BPP, + s->flux_header, CPL_IO_DEFAULT)); + check_nomsg( cpl_vector_save( err1D, filename, SINFO_SPECTRUM_ERRS_BPP, + s->errs_header, CPL_IO_EXTEND)); + check_nomsg( cpl_vector_save( qual1D, filename, SINFO_SPECTRUM_QUAL_BPP, + s->qual_header, CPL_IO_EXTEND)); + cpl_vector_delete( flux1D); + cpl_vector_delete( err1D); + cpl_vector_delete( qual1D); + } + + + check_nomsg( product_frame = cpl_frame_new() ) ; + check_nomsg( cpl_frame_set_filename( product_frame,filename )); + check_nomsg( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ; + check_nomsg( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ; + check_nomsg( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT )); + + cleanup: + if (cpl_error_get_code () != CPL_ERROR_NONE) { + sinfo_free_frame(&product_frame); + product_frame = NULL; + } + return product_frame; +} + +/*---------------------------------------------------------------------------*/ +/** + @brief Normalize a spectrum + @param spectrum The 1d (merged) or 2d (non-merged or 2d + extracted+merged) spectrum to be normalized + @param spectrum_error Error (1 sigma) of @em spectrum, or NULL. + @param spectrum_header Header describing the geometry of the input spectrum + @param binx x bin + @param gain detector's gain + @param exptime observed object's exposure time + @param airmass observed object's airmass + @param n_traces Number of spatial bins (1 unless 2d extracted) + @param atm_extinction The table of extinction coefficients + @param scaled_error (output) If non-NULL, error of output spectrum + @return The normalized spectrum + + The spectrum is divided by exposure time, gain and (optionally) binning. + Also corrected for atmospheric extinction using the provided table of + extinction coefficients. + + Bad pixels are propagated.sinfo_utils.h +*/ +/* Needs to be updated for multi extension (ORDER-BY-ORDER) */ +/*----------------------------------------------------------------------------*/ +static cpl_image * +sinfo_normalize_spectrum_image(const cpl_image *spectrum, + const cpl_image *spectrum_error, + const cpl_propertylist *spectrum_header, + const int bin_size, + const double gain, + const double exptime, + const double airmass, + const int n_traces, + const cpl_table *atm_extinction, + cpl_image **scaled_error) +{ + cpl_image *scaled = NULL; + int norders, ny, nx; + double cor_fct=gain*exptime*bin_size; + SINFO_ASSURE_NOT_NULL_MSG(spectrum,"Null input spectrum"); + SINFO_ASSURE_NOT_NULL_MSG(scaled_error,"Null input scaled error"); + SINFO_ASSURE_NOT_NULL_MSG(spectrum_error, "Null input spectrum error"); + SINFO_ASSURE_NOT_NULL_MSG(spectrum_header,"Null input spectrum header"); + SINFO_ASSURE_NOT_NULL_MSG(atm_extinction,"Null input atmospheric extinction table"); + + nx = cpl_image_get_size_x(spectrum); + ny = cpl_image_get_size_y(spectrum); + + + if (spectrum_error != NULL) + { + assure( nx == cpl_image_get_size_x(spectrum_error) && + ny == cpl_image_get_size_y(spectrum_error), CPL_ERROR_INCOMPATIBLE_INPUT, + "Error spectrum geometry differs from spectrum: %" CPL_SIZE_FORMAT "x%" CPL_SIZE_FORMAT " vs. %dx%d", + cpl_image_get_size_x(spectrum_error), + cpl_image_get_size_y(spectrum_error), + nx, ny); + } + + assure( ny % n_traces == 0, CPL_ERROR_INCOMPATIBLE_INPUT, + "Spectrum image height (%d) is not a multiple of " + "the number of traces (%d). Confused, bailing out", + ny, n_traces); + + norders = ny / n_traces; + + /* + * Correct for exposure time, gain, bin + */ + assure( exptime > 0, CPL_ERROR_ILLEGAL_INPUT, "Non-positive exposure time: %f s", exptime); + assure( gain > 0, CPL_ERROR_ILLEGAL_INPUT, "Non-positive gain: %f", gain); + assure( bin_size > 0, CPL_ERROR_ILLEGAL_INPUT, "Illegal binning: %d", bin_size); + + //sinfo_msg_dbg_medium("Correcting for exposure time = %f s, gain = %f, bin_size = %d", exptime, gain, bin_size); + + check(scaled=cpl_image_divide_scalar_create(spectrum,cor_fct), + "Error correcting spectrum for gain, exposure time, binning"); + + if (scaled_error != NULL) + { + check( *scaled_error=cpl_image_divide_scalar_create(spectrum_error, + cor_fct), + "Error correcting rebinned spectrum for gain, exposure time, binning"); + } + + /* + * Correct for atmospheric extinction + */ + { + double dlambda, lambda_start; + int order; + + //sinfo_msg_dbg_medium("Correcting for extinction through airmass %f", airmass); + check( dlambda = sinfo_pfits_get_cdelt1(spectrum_header), + "Error reading bin width from header"); + + for (order = 1; order <= norders; order++) + { + int trace; + + /* If spectrum was already merged, then read crval1, + * otherwise read wstart for each order + */ + + if (norders == 1) + { + check( lambda_start = sinfo_pfits_get_crval1(spectrum_header), + "Error reading start wavelength from header"); + } + else + { + /* Here need to be updated for multi extension (ORDER-BY-ORDER) */ + check( lambda_start = sinfo_pfits_get_crval1(spectrum_header), + "Error reading start wavelength from header"); + } + + for (trace = 1; trace <= n_traces; trace++) + { + int spectrum_row = (order - 1)*n_traces + trace; + int x; + + for (x = 1; x <= nx; x++) + { + int pis_rejected1; + int pis_rejected2; + double flux; + double dflux = 0; + double extinction; + double lambda; + + lambda = lambda_start + (x-1) * dlambda; + + flux = cpl_image_get(scaled, x, spectrum_row, &pis_rejected1); + if (scaled_error != NULL) + { + dflux = cpl_image_get(*scaled_error, x, + spectrum_row, &pis_rejected2); + } + + if (!pis_rejected1 && (scaled_error == NULL || !pis_rejected2)) + { + int istart = 0; + + /* Read extinction (units: magnitude per airmass) */ + check( extinction = + sinfo_spline_hermite_table( + lambda, atm_extinction, + "D_LAMBDA", "D_EXTINCTION", &istart), + "Error interpolating extinction coefficient"); + + /* Correct for extinction using + * the magnitude/flux relation + * m = -2.5 log_10 F + * => + * F = 10^(-m*0.4) + * + * m_top-of-atmosphere = m - ext.coeff*airmass + * F_top-of-atmosphere = F * 10^(0.4 * ext.coeff*airmass) + */ + + cpl_image_set( + scaled, x, spectrum_row, + flux * pow(10, 0.4 * extinction * airmass)); + if (scaled_error != NULL) + { + cpl_image_set( + *scaled_error, x, spectrum_row, + dflux * pow(10, 0.4 * extinction * airmass)); + } + } + else + { + cpl_image_reject(scaled, x, spectrum_row); + if (scaled_error != NULL) + { + cpl_image_reject(*scaled_error, x, spectrum_row); + } + } + } /* for each x */ + + } /* for each (possibly only 1) trace */ + + } /* for each (possibly only 1) order */ + } + + cleanup: + if (cpl_error_get_code() != CPL_ERROR_NONE) + { + sinfo_free_image(&scaled); + if (scaled_error != NULL) + { + sinfo_free_image(scaled_error); + } + } + + return scaled; +} + + + +/*---------------------------------------------------------------------------*/ +/** + @brief Normalize spectrum slice + @param name_s spectrum filename + @param tag_o output frame pro catg + @param ext extension value + @param binx X bin size + @param gain detector's gain + @param exptime exposure time + @param airmass airmass + @param tbl_atm_ext atmospheric extinction table + @return CPL error code + + The spectrum is divided by exposure time, gain and (optionally) binning. + Also corrected for atmospheric extinction using the provided table of + extinction coefficients. + + Bad pixels are propagated.sinfo_utils.h +*/ +cpl_error_code +sinfo_normalize_spectrum_image_slice(const char* name_s, + const char* tag_o, + const int ext, + const int bin_size, + const double gain, + const double exptime, + const double airmass, + const cpl_table* tbl_atm_ext) +{ + + + cpl_image* data_ima=NULL; + cpl_image* errs_ima=NULL; + cpl_image* qual_ima=NULL; + cpl_image* data_nrm=NULL; + cpl_image* errs_nrm=NULL; + + cpl_image* data_tmp=NULL; + cpl_image* errs_tmp=NULL; + + cpl_image* data_nrm_tmp=NULL; + cpl_image* errs_nrm_tmp=NULL; + + cpl_vector* data_vec=NULL; + cpl_vector* errs_vec=NULL; + cpl_vector* qual_vec=NULL; + + cpl_propertylist* hdat=NULL; + cpl_propertylist* herr=NULL; + cpl_propertylist* hqua=NULL; + int naxis=0; + char name_o[256]; + + sprintf(name_o,"%s.fits",tag_o); + + sinfo_free_propertylist(&hdat); + sinfo_free_propertylist(&herr); + sinfo_free_propertylist(&hqua); + + hdat=cpl_propertylist_load(name_s,ext+0); + herr=cpl_propertylist_load(name_s,ext+1); + hqua=cpl_propertylist_load(name_s,ext+2); + + + naxis=sinfo_pfits_get_naxis(hdat); + sinfo_pfits_set_pcatg(hdat,tag_o); + if(naxis == 1) { + + check_nomsg(data_vec=cpl_vector_load(name_s,ext+0)); + check_nomsg(errs_vec=cpl_vector_load(name_s,ext+1)); + sinfo_free_image(&data_ima); + sinfo_free_image(&errs_ima); + check_nomsg(data_ima=sinfo_vector_to_image(data_vec,CPL_TYPE_FLOAT)); + check_nomsg(errs_ima=sinfo_vector_to_image(errs_vec,CPL_TYPE_FLOAT)); + cpl_vector_delete(data_vec); + cpl_vector_delete(errs_vec); + + } else { + + sinfo_free_image(&data_ima); + sinfo_free_image(&errs_ima); + sinfo_free_image(&qual_ima); + check_nomsg(data_ima=cpl_image_load(name_s,CPL_TYPE_FLOAT,0,ext+0)); + check_nomsg(errs_ima=cpl_image_load(name_s,CPL_TYPE_FLOAT,0,ext+1)); + check_nomsg(qual_ima=cpl_image_load(name_s,CPL_TYPE_INT,0,ext+2)); + + } + sinfo_free_image(&data_tmp); + sinfo_free_image(&errs_tmp); + data_tmp=cpl_image_cast(data_ima,CPL_TYPE_DOUBLE); + errs_tmp=cpl_image_cast(errs_ima,CPL_TYPE_DOUBLE); + + sinfo_free_image(&data_nrm_tmp); + sinfo_free_image(&errs_nrm_tmp); + + check_nomsg(data_nrm_tmp=sinfo_normalize_spectrum_image(data_tmp,errs_tmp,hdat, + bin_size,gain,exptime,airmass,1, + tbl_atm_ext,&errs_nrm_tmp)); + + sinfo_free_image(&data_nrm); + sinfo_free_image(&errs_nrm); + check_nomsg(data_nrm=cpl_image_cast(data_nrm_tmp,CPL_TYPE_FLOAT)); + check_nomsg(errs_nrm=cpl_image_cast(errs_nrm_tmp,CPL_TYPE_FLOAT)); + + if(naxis==1) { + if(data_vec != NULL) cpl_vector_delete(data_vec); + if(errs_vec != NULL) cpl_vector_delete(errs_vec); + + check_nomsg(data_vec=sinfo_image_to_vector(data_nrm)); + check_nomsg(errs_vec=sinfo_image_to_vector(errs_nrm)); + + if(ext==0) { + check_nomsg(cpl_vector_save(data_vec,name_o,CPL_TYPE_FLOAT,hdat,CPL_IO_DEFAULT)); + } else { + check_nomsg(cpl_vector_save(data_vec,name_o,CPL_TYPE_FLOAT,hdat,CPL_IO_EXTEND)); + } + check_nomsg(cpl_vector_save(errs_vec,name_o,CPL_TYPE_FLOAT,herr,CPL_IO_EXTEND)); + cpl_vector_delete(qual_vec); + check_nomsg(qual_vec=cpl_vector_load(name_s,ext+2)); + check_nomsg(cpl_vector_save(qual_vec,name_o,CPL_TYPE_FLOAT,hqua,CPL_IO_EXTEND)); + + + } else { + if(ext==0) { + check_nomsg(cpl_image_save(data_nrm,name_o,CPL_TYPE_FLOAT,hdat,CPL_IO_DEFAULT)); + } else { + check_nomsg(cpl_image_save(data_nrm,name_o,CPL_TYPE_FLOAT,hdat,CPL_IO_EXTEND)); + } + check_nomsg(cpl_image_save(errs_nrm,name_o,CPL_TYPE_FLOAT,herr,CPL_IO_EXTEND)); + check_nomsg(cpl_image_save(qual_ima,name_o,CPL_TYPE_INT,hqua,CPL_IO_EXTEND)); + + } + /* the qual ext is treated separately: we duplicate it to product */ + + + cleanup: + sinfo_free_image(&data_ima); + sinfo_free_image(&errs_ima); + sinfo_free_image(&qual_ima); + sinfo_free_image(&data_nrm); + sinfo_free_image(&errs_nrm); + sinfo_free_image(&data_tmp); + sinfo_free_image(&errs_tmp); + sinfo_free_image(&data_nrm_tmp); + sinfo_free_image(&errs_nrm_tmp); + + sinfo_free_propertylist(&hdat); + sinfo_free_propertylist(&herr); + sinfo_free_propertylist(&hqua); + + cpl_vector_delete(data_vec); + cpl_vector_delete(errs_vec); + cpl_vector_delete(qual_vec); + + return cpl_error_get_code(); +} + + +/*--------------------------------------------------------------------------- */ +/** + @brief find out the exposure time + @param plist property list to read from + @return Exposure time + */ +/*--------------------------------------------------------------------------- */ +double sinfo_pfits_getexptime (const cpl_propertylist * plist) +{ + double returnvalue = 0.0; + + check(sinfo_get_property_value (plist, SINFO_EXPTIME,CPL_TYPE_DOUBLE, + &returnvalue), + "Error reading keyword '%s'", SINFO_EXPTIME); + +cleanup: + return returnvalue; +} + + +/** + * Return the number of slit from a sinfo_rec_list structure. + * + * @param list Rectify structure pointer + * @param idx Index in the list + * + * @return Nb of slit + */ +int sinfo_rec_list_get_nslit( sinfo_rec_list* list, int idx ) +{ + int res = 0 ; + + SINFO_ASSURE_NOT_NULL(list); + res = list->list[idx].nslit ; + + cleanup: + return res ; +} + +/*---------------------------------------------------------------------------*/ +/** + @brief Normalize a spectrum + @param obj_frame The 1d (merged) or 2d (non-merged or 2d extracted+merged) spectrum to be normalized + @param atm_ext_frame The frame with atmospheric extinction spectrum + @param correct_binning Flag indicating whether or not to divide by the x-binning factor + @param instrument instrument arm + @param tag_o output product tag + @return The normalized spectrum + + The spectrum is divided by exposure time, gain and (optionally) binning. + Also corrected for atmospheric extinction using the provided table of + extinction coefficients. + + Bad pixels are propagated.sinfo_utils.h +*/ +/* Needs to be updated for multi extension (ORDER-BY-ORDER) */ +cpl_frame * +sinfo_normalize_spectrum_ord(const cpl_frame *obj_frame, + const cpl_frame *atm_ext_frame, + cpl_boolean correct_binning, + new_sinfo_band band, + const char* tag_o) +{ + + cpl_frame* result=NULL; + const char* name_s=NULL; + const char* aname=NULL; + + cpl_table* tbl_atm_ext=NULL; + cpl_propertylist* hdat=NULL; + char* name_o=NULL; + + int next=0; + int ext=0; + int binx=1; + int biny=1; + int bin_size=1; + double gain=0; + double exptime=0; + double airmass=0; + + SINFO_ASSURE_NOT_NULL_MSG(obj_frame,"Null input object frame"); + SINFO_ASSURE_NOT_NULL_MSG(atm_ext_frame,"Null input atm ext frame"); + + next=cpl_frame_get_nextensions( obj_frame); + name_s=cpl_frame_get_filename(obj_frame); + + aname=cpl_frame_get_filename(atm_ext_frame); + tbl_atm_ext=cpl_table_load(aname,1,0); + check_nomsg(cpl_table_cast_column( tbl_atm_ext,"LAMBDA","D_LAMBDA",CPL_TYPE_DOUBLE)); + if(!cpl_table_has_column(tbl_atm_ext,SINFO_ATMOS_EXT_LIST_COLNAME_K)){ + sinfo_msg_warning("You are using an obsolete atm extinction line table"); + cpl_table_duplicate_column(tbl_atm_ext,SINFO_ATMOS_EXT_LIST_COLNAME_K, + tbl_atm_ext,SINFO_ATMOS_EXT_LIST_COLNAME_OLD); + } + check_nomsg(cpl_table_cast_column( tbl_atm_ext,SINFO_ATMOS_EXT_LIST_COLNAME_K,"D_EXTINCTION",CPL_TYPE_DOUBLE)); + name_o=cpl_sprintf("%s.fits",tag_o); + + hdat=cpl_propertylist_load(name_s,0); + /* observed frame scaling factors */ + check_nomsg(exptime = sinfo_pfits_getexptime(hdat)); + if( band == INSTRUMENT_BAND_NIR){ + /* we assume gain in units of ADU/e- as ESO standard */ + gain=1./2.12; + } else { + check_nomsg(gain = sinfo_pfits_get_gain(hdat)); + } + + if (correct_binning && (band != INSTRUMENT_BAND_NIR)) { + /* x-binning of rotated image is y-binning of raw image */ + check_nomsg(binx = sinfo_pfits_get_binx(hdat)); + check_nomsg(biny = sinfo_pfits_get_biny(hdat)); + bin_size=binx*biny; + } else { + //sinfo_msg_dbg_medium("Spectrum will not be normalized to unit binning"); + } + check_nomsg(airmass=sinfo_pfits_get_airm_mean(hdat)); + + for(ext=0;extlist[idx].data1 ; + + cleanup: + return res ; +} + +/** + * Return the errs1 buffer from a sinfo_rec_list structure. + * + * @param list Rectify structure pointer + * @param idx Index in the list + * + * @return Pointer to errs1 buffer + */ +float * sinfo_rec_list_get_errs1( sinfo_rec_list* list, int idx ) +{ + float * res = NULL ; + + SINFO_ASSURE_NOT_NULL(list); + res = list->list[idx].errs1 ; + + cleanup: + return res ; +} + +/** + * Return the qual1 buffer from a sinfo_rec_list structure. + * + * @param list Rectify structure pointer + * @param idx Index in the list + * + * @return Pointer to qual1 buffer + */ +int * sinfo_rec_list_get_qual1( sinfo_rec_list* list, int idx ) +{ + int * res = NULL ; + + SINFO_ASSURE_NOT_NULL(list); + res = list->list[idx].qual1 ; + + cleanup: + return res ; +} + +/** + * Return the number of lambda from a sinfo_rec_list structure. + * + * @param list Rectify structure pointer + * @param idx Index in the list + * + * @return nlambda + */ +int sinfo_rec_list_get_nlambda( sinfo_rec_list* list, int idx ) +{ + int res = 0 ; + + SINFO_ASSURE_NOT_NULL( list); + res = list->list[idx].nlambda ; + + cleanup: + return res ; +} + +/** + * Return the slit buffer from a sinfo_rec_list structure. + * + * @param list Rectify structure pointer + * @param idx Index in the list + * + * @return Pointer to slit buffer + */ +float * sinfo_rec_list_get_slit( sinfo_rec_list* list, int idx ) +{ + float * res = NULL ; + + SINFO_ASSURE_NOT_NULL(list); + res = list->list[idx].slit ; + + cleanup: + return res ; +} + +double sinfo_rec_list_get_lambda_min( sinfo_rec_list* list) +{ + double lambda_min = 10000; + int i; + + SINFO_ASSURE_NOT_NULL( list); + + for( i=0; i< list->size; i++){ + if ( list->list[i].lambda != NULL){ + double lambda; + + lambda = list->list[i].lambda[0]; + if ( lambda < lambda_min){ + lambda_min = lambda; + } + } + } + + cleanup: + return lambda_min; +} + +/** + * Return the lambda buffer from a sinfo_rec_list structure. + * + * @param list Rectify structure pointer + * @param idx Index in the list + * + * @return Pointer to lambda buffer + */ +double* sinfo_rec_list_get_lambda( sinfo_rec_list* list, int idx ) +{ + double* res = NULL ; + + SINFO_ASSURE_NOT_NULL(list); + res = list->list[idx].lambda ; + + cleanup: + return res ; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get slit axis ize of spectrum + * + * @param[in] s spectrum structure + * + * @return the slit axis size of flux data in spectrum + */ +/*---------------------------------------------------------------------------*/ +int sinfo_spectrum_get_size_slit( sinfo_spectrum* s) +{ + int res=0; + + SINFO_ASSURE_NOT_NULL( s); + + res = s->size_slit; + + cleanup: + return res; +} +/*---------------------------------------------------------------------------*/ +/** + * @brief Get flux of spectrum + * + * @param[in] s spectrum structure + * + * @return the flux data of spectrum + */ +/*---------------------------------------------------------------------------*/ +double* sinfo_spectrum_get_flux( sinfo_spectrum* s) +{ + double *res=NULL; + + SINFO_ASSURE_NOT_NULL( s); + + check_nomsg( res = cpl_image_get_data_double( s->flux)); + + cleanup: + return res; +} + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get errs of spectrum + * + * @param[in] s spectrum structure + * + * @return the errs data of spectrum + */ +/*---------------------------------------------------------------------------*/ +double* sinfo_spectrum_get_errs( sinfo_spectrum* s) +{ + double *res=NULL; + + SINFO_ASSURE_NOT_NULL( s); + + check_nomsg( res = cpl_image_get_data_double( s->errs)); + + cleanup: + return res; +} + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get qual of spectrum + * + * @param[in] s spectrum structure + * + * @return the qual data of spectrum + */ +/*---------------------------------------------------------------------------*/ +int* sinfo_spectrum_get_qual( sinfo_spectrum* s) +{ + int* res = NULL; + + SINFO_ASSURE_NOT_NULL( s); + + check_nomsg( res = cpl_image_get_data_int( s->qual)); + + cleanup: + return res; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get lambda axis size of spectrum + * + * @param[in] s spectrum structure + * + * @return the lambda axis size of flux data in spectrum + */ +/*---------------------------------------------------------------------------*/ +int sinfo_spectrum_get_size_lambda( sinfo_spectrum* s) +{ + int res=0; + + SINFO_ASSURE_NOT_NULL( s); + + res = s->size_lambda; + + cleanup: + return res; +} + + + +/*----------------------------------------------------------------------------*/ +/** + @brief Spline interpolation based on Hermite polynomials + @param xp x-value to interpolate + @param x x-values + @param y y-values + @param n array length + @param istart (input/output) initial row (set to 0 to search all row) + + @return The interpolated value. + + The x column must be sorted (ascending or descending) and all x column + values must be different. + + Adopted from: Cristian Levin - ESO La Silla, 1-Apr-1991 +*/ +/*----------------------------------------------------------------------------*/ +static double +sinfo_spline_hermite( double xp, const double *x, const double *y, int n, int *istart ) +{ + double yp1, yp2, yp = 0; + double xpi, xpi1, l1, l2, lp1, lp2; + int i; + + if ( x[0] <= x[n-1] && (xp < x[0] || xp > x[n-1]) ) return 0.0; + if ( x[0] > x[n-1] && (xp > x[0] || xp < x[n-1]) ) return 0.0; + + if ( x[0] <= x[n-1] ) + { + for ( i = (*istart)+1; i <= n && xp >= x[i-1]; i++ ) + ; + } + else + { + for ( i = (*istart)+1; i <= n && xp <= x[i-1]; i++ ) + ; + } + + *istart = i; + i--; + + lp1 = 1.0 / (x[i-1] - x[i]); + lp2 = -lp1; + + if ( i == 1 ) + { + yp1 = (y[1] - y[0]) / (x[1] - x[0]); + } + else + { + yp1 = (y[i] - y[i-2]) / (x[i] - x[i-2]); + } + + if ( i >= n - 1 ) + { + yp2 = (y[n-1] - y[n-2]) / (x[n-1] - x[n-2]); + } + else + { + yp2 = (y[i+1] - y[i-1]) / (x[i+1] - x[i-1]); + } + + xpi1 = xp - x[i]; + xpi = xp - x[i-1]; + l1 = xpi1*lp1; + l2 = xpi*lp2; + + yp = y[i-1]*(1 - 2.0*lp1*xpi)*l1*l1 + + y[i]*(1 - 2.0*lp2*xpi1)*l2*l2 + + yp1*xpi*l1*l1 + yp2*xpi1*l2*l2; + + return yp; +} + + +/*----------------------------------------------------------------------------*/ +/** + @brief Spline interpolation based on Hermite polynomials + @param xp x-value to interpolate + @param t Table containing the columns to interpolate + @param column_x Column of x-values + @param column_y Column of y-values + @param istart (input/output) initial row (set to 0 to search all row) + + @return The interpolated value. +*/ +/*----------------------------------------------------------------------------*/ + +double +sinfo_spline_hermite_table( double xp, const cpl_table *t, const char *column_x, + const char *column_y, int *istart ) +{ + double result = 0; + int n; + + const double *x, *y; + + check( x = cpl_table_get_data_double_const(t, column_x), + "Error reading column '%s'", column_x); + check( y = cpl_table_get_data_double_const(t, column_y), + "Error reading column '%s'", column_y); + + n = cpl_table_get_nrow(t); + + result = sinfo_spline_hermite(xp, x, y, n, istart); + + cleanup: + return result; +} + + +/** + * @brief Concatenate an arbitrary number of strings. + * + * @param s First string + * @param ... Other strings (at least 1 more) + * + * @return Pointer to concatenated string or NULL if error + + * @note The resulting string must be deallocated using @c cpl_free() + * @note THE LAST STRING MUST BE a NULL ptr or AN EMPTY STRING (""). + * However, one should not just use the plain NULL macro in the parameter + * list, since this can lead to undefined behaviour. On some platforms the + * NULL macro might not expant to a pointer type, i.e. sizeof(NULL) might + * not equal sizeof(void*). + * Instead one should use code like the following: + * @code + * y = sinfo_stringcat_any(x, (void*)NULL) + * @endcode + * + */ +char * +sinfo_stringcat_any (const char *s, ...) +{ + char *result = NULL; + int size = 2; + va_list av; + + va_start (av, s); + result = cpl_malloc (2); + assure (result != NULL, CPL_ERROR_ILLEGAL_OUTPUT, + "Memory allocation failed"); + result[0] = '\0'; + for (;;) { + size += strlen (s) + 2; + result = cpl_realloc (result, size); + assure (result != NULL, CPL_ERROR_ILLEGAL_OUTPUT, + "Memory allocation failed"); + strcat (result, s); + s = va_arg (av, char *); + if (s == NULL || *s == '\0') + break; + } + +cleanup: + if (cpl_error_get_code () != CPL_ERROR_NONE) { + cpl_free (result); + result = NULL; + } + + va_end (av); + return result; +} + + +void sinfo_ima2table(char** argv) { + + cpl_vector* vec; + cpl_table* tab; + const char* fname1; + const char* fname2; + cpl_propertylist* plist; + cpl_propertylist* head; + + fname1=argv[1]; + fname2=argv[2]; + sinfo_msg_warning("fname=%s",fname1); + vec=cpl_vector_load(fname1,0); + plist=cpl_propertylist_load(fname1,0); + head=cpl_propertylist_load(fname2,0); + + sinfo_msg_warning("nk1"); + double crpix1=cpl_propertylist_get_double(plist,"CRPIX1"); + + sinfo_msg_warning("nk2"); + double crval1=cpl_propertylist_get_double(plist,"CRVAL1"); + + sinfo_msg_warning("nk3"); + double cdelt1=cpl_propertylist_get_double(plist,"CDELT1"); + + sinfo_msg_warning("nk4 wstep=%g",cdelt1); + int nrow=cpl_vector_get_size(vec); + tab=cpl_table_new(nrow); + cpl_table_wrap_double(tab,cpl_vector_get_data(vec),"counts_d"); + cpl_table_duplicate_column(tab,"wave_d",tab,"counts_d"); + double* pwav=cpl_table_get_data_double(tab,"wave_d"); + double x; + for (int i=0; i +#include + +#define SINFO_SPECTRUM_DATA_BPP CPL_BPP_IEEE_FLOAT +#define SINFO_SPECTRUM_ERRS_BPP CPL_BPP_IEEE_FLOAT +#define SINFO_SPECTRUM_QUAL_BPP CPL_BPP_32_SIGNED +#define SINFO_BUNIT "BUNIT" +#define SINFO_BUNIT_FLUX_ABS_C "erg/s/cm2/Angstrom" + +#define SINFO_BUNIT_NONE_C "" + +#define SINFO_CRPIX1 "CRPIX1" +#define SINFO_CRVAL1 "CRVAL1" + +#define SINFO_CDELT1 "CDELT1" +#define SINFO_CTYPE1 "CTYPE1" +#define SINFO_CUNIT1 "CUNIT1" +#define SINFO_CUNIT1_C "Wavelength units" +#define SINFO_NAXIS1 "NAXIS1" +#define SINFO_NAXIS "NAXIS" + +#define SINFO_EXTNAME "EXTNAME" +#define SINFO_PCATG "ESO PRO CATG" + +#define SINFO_ATMOS_EXT_LIST_COLNAME_K "EXTINCTION" +#define SINFO_WIN_BINX "ESO DET WIN1 BINX" +#define SINFO_WIN_BINY "ESO DET WIN1 BINY" +#define SINFO_ATMOS_EXT_LIST_COLNAME_K "EXTINCTION" +#define SINFO_ATMOS_EXT_LIST_COLNAME_OLD "LA_SILLA" + + +#define SINFO_MERGE_EXT1D "MERGE_EXT1D" +#define SINFO_MERGE_OXT1D "MERGE_OXT1D" +#define SINFO_MERGE1D "MERGE1D" +#define SINFO_MERGE2D "MERGE2D" + +#define SINFO_ORDER1D "ORDER1D" +#define SINFO_ORDER_EXT1D "ORDER_EXT1D" +#define SINFO_ORDER_OXT1D "ORDER_OXT1D" + +#define SINFO_NORM_OXT1D "NORM_OXT1D" +#define SINFO_NORM_ORDER1D "NORM_ORDER1D" +#define SINFO_NORM_ORDER2D "NORM_ORDER2D" +#define SINFO_NORM_MERGE1D "NORM_MERGE1D" +#define SINFO_NORM_MERGE2D "NORM_MERGE2D" + +#define SINFO_FLUX_OXT1D "FLUX_OXT1D" +#define SINFO_FLUX_ORDER2D "FLUX_ORDER2D" +#define SINFO_FLUX_MERGE1D "FLUX_MERGE1D" + +#define SINFO_FLUX_ORDER1D "FLUX_ORDER1D" +#define SINFO_FLUX_ORDER1D "FLUX_ORDER1D" +#define SINFO_FLUX_MOXT1D "FLUX_MOXT1D" + +#define SINFO_COMBINED_OFFSET_2D_SLIT "COMBINED_OFFSET_2D_SLIT_" + +#define SINFO_FLUX_ORDER2D "FLUX_ORDER2D" +#define SINFO_FLUX_MERGE1D "FLUX_MERGE1D" +#define SINFO_ORDER_EXT1D "ORDER_EXT1D" +#define SINFO_ORDER_OXT1D "ORDER_OXT1D" +#define SINFO_ORDER2D "ORDER2D" + +#define SINFO_CRPIX1 "CRPIX1" +#define SINFO_CRPIX2 "CRPIX2" +#define SINFO_CRPIX3 "CRPIX3" + + +#define SINFO_CDELT1 "CDELT1" +#define SINFO_CDELT2 "CDELT2" +#define SINFO_CDELT3 "CDELT3" + +#define SINFO_CRVAL1 "CRVAL1" +#define SINFO_CRVAL2 "CRVAL2" +#define SINFO_CRVAL3 "CRVAL3" + + +#define SINFO_CTYPE1 "CTYPE1" +#define SINFO_CTYPE2 "CTYPE2" +#define SINFO_CTYPE3 "CTYPE3" + +#define SINFO_CD11 "CD1_1" +#define SINFO_CD12 "CD1_2" +#define SINFO_CD21 "CD2_1" +#define SINFO_CD22 "CD2_2" +#define SINFO_EXPTIME "EXPTIME" + +#define SINFO_RECTIFY_BIN_SPACE "ESO PRO RECT BIN SPACE" +#define SINFO_RECTIFY_SPACE_MIN "ESO PRO RECT SPACE MIN" +#define SINFO_RECTIFY_SPACE_MAX "ESO PRO RECT SPACE MAX" +#define SINFO_RECTIFY_LAMBDA_MIN "ESO PRO RECT LAMBDA MIN" +#define SINFO_RECTIFY_LAMBDA_MAX "ESO PRO RECT LAMBDA MAX" +#define SINFO_RECTIFY_BIN_LAMBDA "ESO PRO RECT BIN LAMBDA" + +#define SINFO_REC_TABLE_COLNAME_FLUX1 "FLUX1" +#define SINFO_REC_TABLE_COLNAME_ERRS1 "ERRS1" +#define SINFO_REC_TABLE_COLNAME_QUAL1 "QUAL1" +#define SINFO_REC_TABLE_COLNAME_LAMBDA "LAMBDA" +#define SINFO_REC_TABLE_COLNAME_SLIT "SLIT" +#define SINFO_REC_TABLE_COLNAME_NSLIT "NSLIT" +#define SINFO_REC_TABLE_COLNAME_NLAMBDA "NLAMBDA" +#define SINFO_REC_TABLE_COLNAME_ORDER "ORDER" +#define SINFO_COMBINED_OFFSET_2D_IFU "COMBINED_OFFSET_2D_IFU_" +#define SINFO_QC_EFF_FCLIP "ESO QC FCLIP" + + +#define SINFO_QC_EFF_NCLIP "ESO QC NCLIP" +#define SINFO_DET_WIN1_DIT1 "ESO DET WIN1 DIT1" +#define SINFO_CONAD "ESO DET OUT1 CONAD" +#define SINFO_GET_TAG_FROM_SLITLET( TAG, slitlet, instr)\ + ( (sinfo_instrument_get_arm(instr)) == SINFO_ARM_UVB && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_SLIT)) ? TAG##_UVB : \ + ( (sinfo_instrument_get_arm(instr)) == SINFO_ARM_VIS && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_SLIT)) ? TAG##_VIS : \ + ( (sinfo_instrument_get_arm(instr)) == SINFO_ARM_NIR && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_SLIT)) ? TAG##_NIR : \ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_UVB) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == LOWER_IFU_SLITLET)) ? TAG##_DOWN_IFU_UVB :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_UVB) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == CENTER_IFU_SLITLET)) ? TAG##_CEN_IFU_UVB :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_UVB) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == UPPER_IFU_SLITLET)) ? TAG##_UP_IFU_UVB :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_VIS) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == LOWER_IFU_SLITLET)) ? TAG##_DOWN_IFU_VIS :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_VIS) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == CENTER_IFU_SLITLET)) ? TAG##_CEN_IFU_VIS :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_VIS) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == UPPER_IFU_SLITLET)) ? TAG##_UP_IFU_VIS :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_NIR) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == LOWER_IFU_SLITLET)) ? TAG##_DOWN_IFU_NIR :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_NIR) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == CENTER_IFU_SLITLET)) ? TAG##_CEN_IFU_NIR :\ + ( (sinfo_instrument_get_arm(instr) == SINFO_ARM_NIR) && \ + (sinfo_instrument_get_mode(instr) == SINFO_MODE_IFU) && \ + (slitlet == UPPER_IFU_SLITLET)) ? TAG##_UP_IFU_NIR : "??TAG??" + + +#define SINFO_ASSURE_NOT_NULL(pointer) \ + assure(pointer != NULL, CPL_ERROR_NULL_INPUT,\ + "You have null pointer in input: " #pointer) + +#define SINFO_ASSURE_NOT_NULL_MSG(pointer,msg) \ + assure(pointer != NULL, CPL_ERROR_NULL_INPUT,\ + "You have null pointer in input: " #pointer "\n" msg) + +#define SINFO_ASSURE_NOT_ILLEGAL(cond) \ + assure(cond, CPL_ERROR_ILLEGAL_INPUT,\ + "condition failed: " #cond ) + +#define SINFO_ASSURE_NOT_ILLEGAL_MSG(cond, msg) \ + assure(cond, CPL_ERROR_ILLEGAL_INPUT,\ + "condition failed: " #cond "\n" msg) + +#define SINFO_ASSURE_NOT_MISMATCH(cond) \ + assure(cond, CPL_ERROR_TYPE_MISMATCH,\ + "condition failed: "#cond ) + +#define SINFO_CALLOC( POINTER, TYPE, SIZE) \ + assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\ + "Try to allocate non NULL pointer");\ + POINTER = (TYPE*)(cpl_calloc(SIZE,sizeof(TYPE)));\ + assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\ + "Memory allocation failed!") +#define SINFO_PFITS_GET(RET, LIST, KW, TYPE) \ + check( sinfo_get_property_value( LIST, KW, TYPE, &RET),\ + "Error reading keyword '%s'", KW) + +#define SINFO_FREE(POINTER)\ + if(POINTER!=NULL) cpl_free(POINTER);\ + POINTER = NULL + +#define SINFO_NEW_PROPERTYLIST( POINTER) \ + assure(POINTER == NULL, CPL_ERROR_ILLEGAL_OUTPUT,\ + "Try to allocate non NULL pointer");\ + POINTER = cpl_propertylist_new();\ + assure (POINTER != NULL, CPL_ERROR_ILLEGAL_OUTPUT,\ + "Memory allocation for propertylist failed!") + + + +enum { + CENTER_SLIT, + LOWER_IFU_SLITLET, CENTER_IFU_SLITLET, UPPER_IFU_SLITLET +} ; + +typedef struct { + double lambda_min ; + double lambda_max ; +} HIGH_ABS_REGION ; + +typedef enum _INSTRUMENT_BAND_ { + INSTRUMENT_BAND_UVB, + INSTRUMENT_BAND_VIS, + INSTRUMENT_BAND_NIR, + INSTRUMENT_BAND_ALL, + INSTRUMENT_BAND_J, + INSTRUMENT_BAND_JS, + INSTRUMENT_BAND_JBLOCK, + INSTRUMENT_BAND_H, + INSTRUMENT_BAND_K, + INSTRUMENT_BAND_HK, + INSTRUMENT_BAND_KS, + INSTRUMENT_BAND_L, + INSTRUMENT_BAND_M, + INSTRUMENT_BAND_LP, + INSTRUMENT_BAND_MP, + INSTRUMENT_BAND_Z, + INSTRUMENT_BAND_SZ, + INSTRUMENT_BAND_SH, + INSTRUMENT_BAND_SK, + INSTRUMENT_BAND_SL, + INSTRUMENT_BAND_UNKNOWN +} new_sinfo_band ; + +typedef enum { + SINFO_GD71, + SINFO_Feige110, + SINFO_GD153, + SINFO_LTT3218, + SINFO_LTT7987, + SINFO_BD17, + SINFO_EG274, + SINFO_SINTH +} sinfo_std_star_id; + +typedef struct{ + /* size of the order */ + int size; + /* Minimal spectrum lambda */ + double lambda_min; + /* Maximal spectrum lambda */ + double lambda_max; + /* step in lambda */ + double lambda_step; + /* Minimal slit position */ + double slit_min; + /* Maximal slit position */ + double slit_max; + /* step in slit */ + double slit_step; + /* size in lambda */ + int size_lambda; + /* size in slit */ + int size_slit; + /* flux data */ + cpl_propertylist* flux_header; + cpl_image *flux; + /* errs */ + cpl_propertylist* errs_header; + cpl_image *errs; + /* qual */ + cpl_propertylist* qual_header; + cpl_image *qual; +}sinfo_spectrum; + + +typedef struct{ + int order ; + int nlambda; + int nslit ; + float * slit ; + double * lambda ; + float * data1 ; + float * data2 ; + float * data3 ; + float * errs1 ; + /* FOR IFU mode */ + float * errs2 ; + float * errs3 ; + int * qual1 ; + int * qual2 ; + int * qual3 ; +} sinfo_rec ; + +typedef struct{ + int size; + double slit_min; + double slit_max; + int nslit; + //int max_nlambda ; + //int max_nslit ; + sinfo_rec * list; + new_sinfo_band band; + cpl_propertylist * header; +} sinfo_rec_list; + + +//#define SINFO_CONCAT(A,B) A ## B +#define SINFO_TABLE_GET_ARRAY( TYPE) \ + void sinfo_table_get_array_##TYPE( cpl_table* table, const char* colname, \ + TYPE* pointer, int nb)\ + {\ + const cpl_array* array = NULL;\ + int array_size = 0, k=0;\ + const TYPE* data = NULL;\ + SINFO_ASSURE_NOT_NULL( pointer);\ + check_nomsg( array = cpl_table_get_array( table, colname, 0));\ + check_nomsg( array_size = cpl_array_get_size( array));\ + SINFO_ASSURE_NOT_ILLEGAL( nb == array_size);\ + check_nomsg( data = cpl_array_get_data_##TYPE##_const( array));\ + for( k=0; k< array_size; k++){\ + pointer[k] = data[k];\ + }\ + cleanup:\ + return;\ + } + + + + +HIGH_ABS_REGION * +sinfo_fill_high_abs_regions( + new_sinfo_band band, + cpl_frame* high_abs_frame); + + +struct _star_index_ +{ + cpl_table* index_table; + char* fits_file_name; + int index_size; + cpl_table** cache; + int cache_size; + int* cache_index; +}; + +typedef struct _star_index_ star_index; + +/* Loading the index from the fits file + * */ +star_index* star_index_load(const char* fits_file); + +/*Save the index to the fits file + * */ +star_index* star_index_create(void); +/* Add a new start to the index. To save the changed index to the file star_index_save() should be called + * */ +int star_index_add(star_index* pindex, double RA, double DEC, const char* star_name, cpl_table* ptable); +int star_index_remove_by_name(star_index* pindex, const char* starname); +int start_index_get_size(star_index* pindex); +int star_index_save(star_index* pindex, const char* fits_file_name); +cpl_table* star_index_get(star_index* pindex, double RA, double DEC, double RA_EPS, double DEC_EPS, const char** pstar_name); +void star_index_delete(star_index* pindex); +void star_index_dump(star_index* pindex, FILE* pfile); + + + +cpl_error_code +sinfo_get_property_value(const cpl_propertylist * plist, + const char *keyword, + cpl_type keywordtype, + void *result); +cpl_frame* +sinfo_frame_product(const char* fname, const char* tag, cpl_frame_type type, + cpl_frame_group group,cpl_frame_level level); +cpl_error_code +sinfo_pfits_set_wcs1(cpl_propertylist* header, + const double crpix1, + const double crval1, + const double cdelt1); +int sinfo_pfits_get_binx(const cpl_propertylist * plist); +int sinfo_pfits_get_biny(const cpl_propertylist * plist); +void sinfo_pfits_set_bunit(cpl_propertylist * plist, const char* value); +void sinfo_pfits_set_cunit1(cpl_propertylist * plist, const char* value); +void sinfo_pfits_set_pcatg (cpl_propertylist * plist, const char *value); +void sinfo_pfits_set_ctype1(cpl_propertylist * plist, const char* value); +void sinfo_pfits_set_extname (cpl_propertylist * plist, const char *value); + +int sinfo_pfits_get_naxis (const cpl_propertylist * plist); +const char *sinfo_pfits_get_bunit (const cpl_propertylist * plist); + +double sinfo_pfits_get_rectify_bin_lambda(cpl_propertylist * plist); +const char * sinfo_pfits_get_extname (const cpl_propertylist * plist); +double sinfo_pfits_get_rectify_bin_space(cpl_propertylist * plist); +double sinfo_pfits_get_rectify_space_max(cpl_propertylist * plist); +double sinfo_pfits_get_rectify_space_min(cpl_propertylist * plist); +double sinfo_pfits_get_rectify_lambda_max(cpl_propertylist * plist); +double sinfo_pfits_get_conad(const cpl_propertylist * plist); + +double sinfo_pfits_get_win1_dit1 (const cpl_propertylist * plist); +void sinfo_pfits_set_qc_eff_nclip( cpl_propertylist * plist,int value ); +void sinfo_pfits_set_qc_eff_fclip( cpl_propertylist * plist,double value ); +static int +sinfo_column_to_double(cpl_table* ptable, const char* column); +static double* +sinfo_create_column_double(cpl_table* tbl, const char* col_name, int nrow); +void +sinfo_frame_sci_get_ra_dec_airmass(cpl_frame* frm_sci,double* ra, double* dec, double* airmass); +cpl_error_code sinfo_set_cd_matrix2d(cpl_propertylist* plist); +cpl_error_code +sinfo_pfits_set_wcs2(cpl_propertylist* header, + const double crpix2, + const double crval2, + const double cdelt2); + +double +sinfo_table_interpolate(cpl_table* tbl, + double wav, + const char* colx, + const char* coly); + +double +sinfo_data_interpolate( + double wav, + int nrow, + double* pw, + double* pe + ); + +cpl_table* +sinfo_utils_efficiency_internal( + cpl_table* tbl_obj_spectrum, + cpl_table* tbl_atmext, + cpl_table* tbl_ref, + double exptime, + double airmass, + double aimprim, + double gain, + int biny, + double src2ref_wave_sampling, + const char* col_name_atm_wave, + const char* col_name_atm_abs, + const char* col_name_ref_wave, + const char* col_name_ref_flux, + const char* col_name_ref_bin, + const char* col_name_obj_wave, + const char* col_name_obj_flux, + int* ntot, int* nclip + ); +const char * sinfo_tostring_cpl_frame_type (cpl_frame_type ft); +const char* sinfo_band_tostring(new_sinfo_band band); +cpl_vector * sinfo_image_to_vector( cpl_image * spectrum ); +cpl_image* sinfo_vector_to_image(const cpl_vector* vector,cpl_type type); +double +sinfo_spline_hermite_table( double xp, const cpl_table *t, const char *column_x, + const char *column_y, int *istart ); +double sinfo_pfits_get_rectify_lambda_min(cpl_propertylist * plist); +const char * sinfo_pfits_get_pcatg (const cpl_propertylist * plist); +double sinfo_pfits_getexptime (const cpl_propertylist * plist); + +long sinfo_round_double(double x); +void sinfo_spectrum_free( sinfo_spectrum** list); +cpl_frame* sinfo_spectrum_save( sinfo_spectrum* s, const char* filename, + const char* tag); +void sinfo_rec_list_free(sinfo_rec_list** list); + +float* sinfo_rec_list_get_data1( sinfo_rec_list * list, int idx); + +float * sinfo_rec_list_get_errs1( sinfo_rec_list * list, int idx); + +int * sinfo_rec_list_get_qual1( sinfo_rec_list * list, int idx); +int sinfo_rec_list_get_nslit( sinfo_rec_list * list, int idx); + +int sinfo_rec_list_get_nlambda( sinfo_rec_list * list, int idx); +double* sinfo_rec_list_get_lambda( sinfo_rec_list* list, int idx ); +cpl_error_code +sinfo_pfits_set_wcs(cpl_propertylist* header, const double crpix1, + const double crval1, const double cdelt1, const double crpix2, + const double crval2, const double cdelt2); +double sinfo_rec_list_get_lambda_min( sinfo_rec_list* list); +cpl_frame * +sinfo_normalize_spectrum_ord(const cpl_frame *obj_frame, + const cpl_frame *atm_ext_frame, + cpl_boolean correct_binning, + new_sinfo_band band, + const char* tag); + +void sinfo_merge_point( double flux_a, double weight_a, + double flux_b, double weight_b, double *flux_res, + double *err_res); +char *sinfo_stringcat_any( const char *s, ...) ; +cpl_error_code +sinfo_normalize_spectrum_image_slice(const char* name_s, + const char* tag_o, + const int ext, + const int bin_size, + const double gain, + const double exptime, + const double airmass, + const cpl_table* tbl_atm_ext); +cpl_error_code sinfo_get_table_value (const cpl_table* table, + const char *colname, cpl_type coltype, int i, void* result); +void sinfo_table_get_array_float( cpl_table* table, const char* colname, + float* pointer, int nb); +void sinfo_table_get_array_double( cpl_table* table, const char* colname, + double* pointer, int nb); + +void sinfo_table_get_array_int( cpl_table* table, const char* colname, + int* pointer, int nb); + +cpl_error_code sinfo_parse_catalog_std_stars(cpl_frame* cat, double dRA, + double dDEC, double EPSILON, cpl_table** pptable,sinfo_std_star_id* std_star_id); + + +int sinfo_spectrum_get_size_lambda( sinfo_spectrum* s); +int sinfo_spectrum_get_size_slit( sinfo_spectrum* s); +int* sinfo_spectrum_get_qual( sinfo_spectrum* s); +double* sinfo_spectrum_get_errs( sinfo_spectrum* s); +double* sinfo_spectrum_get_flux( sinfo_spectrum* s); +sinfo_rec_list* sinfo_rec_list_load_eso(cpl_frame* frame, new_sinfo_band band); +sinfo_rec_list* sinfo_rec_list_load_eso_1d(cpl_frame* frame, new_sinfo_band band); +sinfo_rec_list* sinfo_rec_list_load(cpl_frame* frame, new_sinfo_band band); + + +sinfo_spectrum* sinfo_spectrum_1D_create( double lambda_min, double lambda_max, + double lambda_step); +sinfo_spectrum* sinfo_spectrum_2D_create( double lambda_min, double lambda_max, + double lambda_step, double slit_min, double slit_max, double slit_step); + + +int sinfo_print_rec_status(const int val); +void sinfo_ima2table(char** argv); +#endif diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_find_lines_test.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_find_lines_test.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_find_lines_test.c 2016-02-04 11:05:15.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_find_lines_test.c 2017-09-04 19:02:04.000000000 +0000 @@ -83,7 +83,7 @@ double stdev =0; ima_arc=cpl_image_load(file_arc,CPL_TYPE_FLOAT,0,0); - sinfo_msg_warning("ima size: %d %d", + sinfo_msg_warning("ima size: %lld %lld", cpl_image_get_size_x(ima_arc), cpl_image_get_size_y(ima_arc)); diff -Nru cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_response_test.c cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_response_test.c --- cpl-plugin-sinfo-3.0.0+dfsg/sinfoni/tests/sinfo_response_test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-plugin-sinfo-3.1.0+dfsg/sinfoni/tests/sinfo_response_test.c 2017-09-21 09:48:42.000000000 +0000 @@ -0,0 +1,5821 @@ +/* + * This file is part of the ESO SINFONI Pipeline + * Copyright (C) 2004-2009 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, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA + */ +/* + * $Author: amodigli $ + * $Date: 2012-09-18 06:53:36 $ + * $Revision: 1.5 $ + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define MODULE_ID "SINFO_RESPONSE" + + + + + +#define SINFO_CRPIX2 "CRPIX2" +#define SINFO_CRVAL2 "CRVAL2" + +#define SINFO_CDELT2 "CDELT2" +#define SINFO_CTYPE2 "CTYPE2" +#define SINFO_CUNIT2 "CUNIT1" +#define SINFO_CUNIT2_C "Wavelength units" + +#define SINFO_CD11 "CD1_1" +#define SINFO_CD12 "CD1_2" +#define SINFO_CD21 "CD2_1" +#define SINFO_CD22 "CD2_2" + + + +#define SINFO_QC_TELLCORR_OPTEXTID "ESO QC TELLCORR OPTEXTID" +#define SINFO_QC_TELLCORR_RATAVG "ESO QC TELLCORR RATAVG" +#define SINFO_EXPTIME "EXPTIME" + +#define SINFO_QC_TELLCORR_RATAVG "ESO QC TELLCORR RATAVG" +#define SINFO_QC_TELLCORR_RATRMS "ESO QC TELLCORR RATRMS" +#define SINFO_ATMOS_EXT "ATMOS_EXT" + +#define SINFO_ATMOS_EXT_LIST_COLNAME_WAVELENGTH "LAMBDA" + + + +#define SINFO_TABLE_LOAD( TABLE, NAME) \ + check( TABLE = cpl_table_load( NAME, 1, 0),\ + "Can't load %s FITS table", NAME) +typedef struct { + double wguess ; /* Reference line wavelength position */ + double range_wmin; /* minimum of wavelength box for line fit */ + double range_wmax; /* maximum of wavelength box for line fit */ + double ipol_wmin_max; /* maximum lower sub-range wavelength value used to fit line slope */ + double ipol_wmax_min; /* minimum upper sub-range wavelength value used to fit line slope */ + double ipol_hbox; /* half box where polynomial fit is performed */ + +} sinfo_rv_ref_wave_param ; + + +/* + Structure to return gaussian fit results +*/ +typedef struct { + double peakpos, + sigma, + area, + offset, + mse ; +} SINFO_GAUSSIAN_FIT ; + + + +typedef struct { + int size ; + cpl_propertylist * header ; + double * lambda ; + double * K ; +} sinfo_atmos_ext_list ; + + + + +HIGH_ABS_REGION UvbTellFitRegions[] = { + {0., 0.} + } ; +HIGH_ABS_REGION VisTellFitRegions[] = { + {535.4, 536.2}, // 535.8 +/- 0.4 + {551.9, 552.7}, // 552.3 + {555.8, 556.6}, // 556.2 + {563.6, 564.4}, // 564.0 + {603.6, 604.4}, // 604.0 + {616.6, 617.4}, // 617.0 + {638.6, 639.4}, // 639.0 + {682.9, 683.7}, // 683.3 + {707.3, 708.1}, // 707.7 + {747.1, 747.9}, // 747.5 + {753.9, 754.7}, // 754.3 + {777.7, 778.3}, // 777.9 + {781.1, 781.9}, // 781.5 + {789.2, 790.0}, // 789.6 + {799.3, 800.1}, // 799.7 + {809.6, 810.4}, // 810.0 + {841.0, 841.8}, // 841.4 + {850.1, 850.9}, // 850.5 + {864.6, 865.4}, // 865.0 + {874.6, 875.4}, // 875.0 + {887.9, 888.7}, // 888.3 + {923.4, 924.2}, // 923.8 + {971.2, 972.0}, // 971.6 + {979.4, 980.2}, // 979.8 + {995.2, 996.0}, // 995.6 + {1006.1, 1006.9}, // 1006.5 + {1017.6, 1018.4}, // 1018.0 + {0., 0.} + } ; + + +HIGH_ABS_REGION NirTellFitRegions[] = { + {1039.0, 1041.0}, // 1040.0 nm + {1059.0, 1061.0}, // 1060.0 nm + {1190.0, 1192.0}, // 1191.0 nm + {1228.0, 1230.0}, // 1229.0 nm + {1243.0, 1245.0}, // 1244.0 nm + {1552.0, 1554.0}, // 1553.0 nm + {1589.0, 1591.0}, // 1590.0 nm + {1619.0, 1621.0}, // 1620.0 nm + {1658.0, 1660.0}, // 1659.0 nm + {1691.0, 1693.0}, // 1692.0 nm + {1702.0, 1704.0}, // 1703.0 nm + {1709.0, 1711.0}, // 1710.0 nm + {1717.0, 1719.0}, // 1718.0 nm + {1990.0, 1992.0}, // 1991.0 nm + {2036.0, 2038.0}, // 2037.0 nm + {2102.0, 2103.0}, // 2102.0 nm + {2112.0, 2114.0}, // 2113.0 nm + {2125.0, 2127.0}, // 2126.0 nm + {2132.0, 2134.0}, // 2133.0 nm + {2137.0, 2139.0}, // 2138.0 nm + {2141.0, 2143.0}, // 2142.0 nm + {2144.0, 2146.0}, // 2145.0 nm + {2156.0, 2158.0}, // 2157.0 nm + {2163.0, 2165.0}, // 2164.0 nm + {2186.0, 2188.0}, // 2187.0 nm + {2209.0, 2211.0}, // 2210.0 nm + {2239.0, 2241.0}, // 2240.0 nm + {2259.0, 2261.0}, // 2260.0 nm + {2279.0, 2281.0}, // 2280.0 nm + {2306.0, 2308.0}, // 2307.0 nm + {2324.0, 2326.0}, // 2325.0 nm + {2342.0, 2344.0}, // 2343.0 nm + {2379.0, 2381.0}, // 2380.0 nm + {2429.0, 2431.0}, // 2430.0 nm + {2475.0, 2477.0}, // 2476.0 nm + {0., 0.} +} ; + + +HIGH_ABS_REGION AllTellFitRegions[] = { + {535.4, 536.2}, // 535.8 +/- 0.4 + {551.9, 552.7}, // 552.3 + {555.8, 556.6}, // 556.2 + {563.6, 564.4}, // 564.0 + {603.6, 604.4}, // 604.0 + {616.6, 617.4}, // 617.0 + {638.6, 639.4}, // 639.0 + {682.9, 683.7}, // 683.3 + {707.3, 708.1}, // 707.7 + {747.1, 747.9}, // 747.5 + {753.9, 754.7}, // 754.3 + {777.7, 778.3}, // 777.9 + {781.1, 781.9}, // 781.5 + {789.2, 790.0}, // 789.6 + {799.3, 800.1}, // 799.7 + {809.6, 810.4}, // 810.0 + {841.0, 841.8}, // 841.4 + {850.1, 850.9}, // 850.5 + {864.6, 865.4}, // 865.0 + {874.6, 875.4}, // 875.0 + {887.9, 888.7}, // 888.3 + {923.4, 924.2}, // 923.8 + {971.2, 972.0}, // 971.6 + {979.4, 980.2}, // 979.8 + {995.2, 996.0}, // 995.6 + {1006.1, 1006.9}, // 1006.5 + {1017.6, 1018.4}, // 1018.0 + {1039.0, 1041.0}, // 1040.0 nm + {1059.0, 1061.0}, // 1060.0 nm + {1190.0, 1192.0}, // 1191.0 nm + {1228.0, 1230.0}, // 1229.0 nm + {1243.0, 1245.0}, // 1244.0 nm + {1552.0, 1554.0}, // 1553.0 nm + {1589.0, 1591.0}, // 1590.0 nm + {1619.0, 1621.0}, // 1620.0 nm + {1658.0, 1660.0}, // 1659.0 nm + {1691.0, 1693.0}, // 1692.0 nm + {1702.0, 1704.0}, // 1703.0 nm + {1709.0, 1711.0}, // 1710.0 nm + {1717.0, 1719.0}, // 1718.0 nm + {1990.0, 1992.0}, // 1991.0 nm + {2036.0, 2038.0}, // 2037.0 nm + {2102.0, 2103.0}, // 2102.0 nm + {2112.0, 2114.0}, // 2113.0 nm + {2125.0, 2127.0}, // 2126.0 nm + {2132.0, 2134.0}, // 2133.0 nm + {2137.0, 2139.0}, // 2138.0 nm + {2141.0, 2143.0}, // 2142.0 nm + {2144.0, 2146.0}, // 2145.0 nm + {2156.0, 2158.0}, // 2157.0 nm + {2163.0, 2165.0}, // 2164.0 nm + {2186.0, 2188.0}, // 2187.0 nm + {0., 0.} +} ; + +HIGH_ABS_REGION NirJTellFitRegions[] = { + //{1096.0, 1097.0}, // 1040.0 nm + //{1101.0, 1103.0}, // 1060.0 nm + {1104.0, 1106.0}, // 1060.0 nm + {1108.0, 1110.0}, // 1060.0 nm + {1142.0, 1143.0}, // 1060.0 nm + {1160.0, 1162.0}, // 1060.0 nm + {1180.0, 1182.0}, // 1060.0 nm + {1190.0, 1192.0}, // 1191.0 nm + {1210.0, 1212.0}, // 1229.0 nm + {1220.0, 1222.0}, // 1229.0 nm + {1228.0, 1230.0}, // 1229.0 nm + {1230.0, 1232.0}, // 1229.0 nm + {1243.0, 1245.0}, // 1244.0 nm + {1300.0, 1302.0}, // 1244.0 nm + {1310.0, 1312.0}, // 1244.0 nm + {1315.0, 1325.0}, // 1244.0 nm + {1330.0, 1335.0}, // 1244.0 nm +// {1340.0, 1343.0}, // 1244.0 nm +// {1394.0, 1398.0}, // 1244.0 nm + {0., 0.} +} ; + + +HIGH_ABS_REGION NirHTellFitRegions[] = { +// {1039.0, 1041.0}, // 1040.0 nm +// {1059.0, 1061.0}, // 1060.0 nm +// {1190.0, 1192.0}, // 1191.0 nm +// {1228.0, 1230.0}, // 1229.0 nm +// {1243.0, 1245.0}, // 1244.0 nm + {1552.0, 1554.0}, // 1553.0 nm + {1589.0, 1591.0}, // 1590.0 nm + {1619.0, 1621.0}, // 1620.0 nm + {1658.0, 1660.0}, // 1659.0 nm + {1691.0, 1693.0}, // 1692.0 nm + {1702.0, 1704.0}, // 1703.0 nm + {1709.0, 1711.0}, // 1710.0 nm + {1717.0, 1719.0}, // 1718.0 nm +// {1990.0, 1992.0}, // 1991.0 nm + {0., 0.} +} ; + +HIGH_ABS_REGION NirKTellFitRegions[] = { + {1990.0, 1992.0}, // 1991.0 nm + {2036.0, 2038.0}, // 2037.0 nm + {2102.0, 2103.0}, // 2102.0 nm + {2112.0, 2114.0}, // 2113.0 nm + {2125.0, 2127.0}, // 2126.0 nm + {2132.0, 2134.0}, // 2133.0 nm + {2137.0, 2139.0}, // 2138.0 nm + {2141.0, 2143.0}, // 2142.0 nm + {2144.0, 2146.0}, // 2145.0 nm + {2156.0, 2158.0}, // 2157.0 nm + {2163.0, 2165.0}, // 2164.0 nm + {2186.0, 2188.0}, // 2187.0 nm + {2209.0, 2211.0}, // 2210.0 nm + {2239.0, 2241.0}, // 2240.0 nm + {2259.0, 2261.0}, // 2260.0 nm + {2279.0, 2281.0}, // 2280.0 nm + {2306.0, 2308.0}, // 2307.0 nm + {2324.0, 2326.0}, // 2325.0 nm + {2342.0, 2344.0}, // 2343.0 nm + {2379.0, 2381.0}, // 2380.0 nm + {2429.0, 2431.0}, // 2430.0 nm +// {2475.0, 2477.0}, // 2476.0 nm + {0., 0.} +} ; + +HIGH_ABS_REGION NirHKTellFitRegions[] = { +// {1039.0, 1041.0}, // 1040.0 nm +// {1059.0, 1061.0}, // 1060.0 nm +// {1190.0, 1192.0}, // 1191.0 nm +// {1228.0, 1230.0}, // 1229.0 nm +// {1243.0, 1245.0}, // 1244.0 nm + {1552.0, 1554.0}, // 1553.0 nm + {1589.0, 1591.0}, // 1590.0 nm + {1619.0, 1621.0}, // 1620.0 nm + {1658.0, 1660.0}, // 1659.0 nm + {1691.0, 1693.0}, // 1692.0 nm + {1702.0, 1704.0}, // 1703.0 nm + {1709.0, 1711.0}, // 1710.0 nm + {1717.0, 1719.0}, // 1718.0 nm + {1990.0, 1992.0}, // 1991.0 nm + {2036.0, 2038.0}, // 2037.0 nm + {2102.0, 2103.0}, // 2102.0 nm + {2112.0, 2114.0}, // 2113.0 nm + {2125.0, 2127.0}, // 2126.0 nm + {2132.0, 2134.0}, // 2133.0 nm + {2137.0, 2139.0}, // 2138.0 nm + {2141.0, 2143.0}, // 2142.0 nm + {2144.0, 2146.0}, // 2145.0 nm + {2156.0, 2158.0}, // 2157.0 nm + {2163.0, 2165.0}, // 2164.0 nm + {2186.0, 2188.0}, // 2187.0 nm + {2209.0, 2211.0}, // 2210.0 nm + {2239.0, 2241.0}, // 2240.0 nm + {2259.0, 2261.0}, // 2260.0 nm + {2279.0, 2281.0}, // 2280.0 nm + {2306.0, 2308.0}, // 2307.0 nm + {2324.0, 2326.0}, // 2325.0 nm + {2342.0, 2344.0}, // 2343.0 nm + {2379.0, 2381.0}, // 2380.0 nm + {2429.0, 2431.0}, // 2430.0 nm + {2475.0, 2477.0}, // 2476.0 nm + {0., 0.} +} ; + + +HIGH_ABS_REGION UvbTellComputeResidRegions[] = { + {0., 0.} + } ; + +HIGH_ABS_REGION VisTellComputeResidRegions[] = { + {691., 695.}, + {715., 734.}, + {766., 770.}, + {893., 904.}, + {943., 983.}, + {0., 0.} + } ; + +HIGH_ABS_REGION NirTellComputeResidRegions[] = { + {1105.0, 1266.0}, + {1300.0, 1343.0}, + {1468.0, 1780.0}, + {1940.0, 1994.0}, + {2030.0, 2046.0}, + {2080.0, 2100.0}, + {0., 0.} +} ; + + + +HIGH_ABS_REGION AllTellComputeResidRegions[] = { + {691., 695.}, + {715., 734.}, + {766., 770.}, + {893., 904.}, + {943., 983.}, + {1105.0, 1266.0}, + {1300.0, 1343.0}, + {1468.0, 1780.0}, + {1940.0, 1994.0}, + {2030.0, 2046.0}, + {2080.0, 2100.0}, + {0., 0.} +} ; + +HIGH_ABS_REGION NirJTellComputeResidRegions[] = { + {1105.0, 1266.0}, + {1300.0, 1343.0}, + {1468.0, 1780.0}, + {0., 0.} +} ; + +HIGH_ABS_REGION NirHTellComputeResidRegions[] = { + {1105.0, 1266.0}, + {1300.0, 1343.0}, + {1468.0, 1780.0}, + {1940.0, 1994.0}, + {0., 0.} +} ; + +HIGH_ABS_REGION NirKTellComputeResidRegions[] = { + {1940.0, 1994.0}, + {2030.0, 2046.0}, + {2080.0, 2100.0}, + {0., 0.} +} ; + +HIGH_ABS_REGION NirHKTellComputeResidRegions[] = { + {1105.0, 1266.0}, + {1300.0, 1343.0}, + {1468.0, 1780.0}, + {1940.0, 1994.0}, + {2030.0, 2046.0}, + {2080.0, 2100.0}, + {0., 0.} +} ; + +/* +static double +sinfo_std_star_spectra_correlate(hdrl_spectrum1D * obs_s, sinfo_rv_ref_wave_param* w) + +{ + cpl_vector* vec_wave_obs = NULL; + cpl_vector* vec_flux_obs = NULL; + cpl_vector* vec_slope_obs=NULL; + cpl_vector* correl=NULL; + + const double wmin=w->range_wmin; + const double wmax=w->range_wmax; + + sinfo_std_star_spectra_to_vector_range(obs_std_star_list,wmin,wmax,&vec_wave_obs,&vec_flux_obs); + + double wmin_max=w->ipol_wmin_max; + double wmax_min=w->ipol_wmax_min; + + vec_slope_obs=sinfo_vector_fit_slope(vec_wave_obs,vec_flux_obs,wmin_max,wmax_min,2); + + cpl_vector_divide(vec_flux_obs,vec_slope_obs); + cpl_vector_delete(vec_slope_obs); + + cpl_vector_add_scalar(vec_flux_obs,2); + + double wave_range=w->ipol_hbox; + cpl_vector* xfit_obs=NULL; + cpl_vector* yfit_obs=NULL; + + double* pxfit=NULL; + double* pyfit=NULL; + + sinfo_select_line_core(vec_wave_obs,vec_flux_obs,w->wguess,wave_range,&xfit_obs,&yfit_obs); + + cpl_polynomial* poly_fit_obs=NULL; + + double mse=0; + double* pindex=NULL; + poly_fit_obs=sinfo_polynomial_fit_1d_create(xfit_obs,yfit_obs,4,&mse); + + cpl_vector* yfit_pol_obs=NULL; + cpl_vector* yfit_index=NULL; + cpl_size size_x_obs=cpl_vector_get_size(xfit_obs); + yfit_pol_obs=cpl_vector_new(size_x_obs); + yfit_index=cpl_vector_new(size_x_obs); + check_nomsg(pyfit=cpl_vector_get_data(yfit_pol_obs)); + check_nomsg(pxfit=cpl_vector_get_data(xfit_obs)); + check_nomsg(pindex=cpl_vector_get_data(yfit_index)); + + for(cpl_size i=0;iwguess; + + + const double wave_shift=peakpos_obs-peakpos_ref; + + cleanup: + + cpl_vector_delete(yfit_pol_obs); + cpl_vector_delete(xfit_obs); + cpl_vector_delete(yfit_obs); + cpl_vector_delete(vec_wave_obs); + cpl_vector_delete(vec_flux_obs); + cpl_vector_delete(correl); + + return wave_shift; +} +*/ + +#define SINFO_STAR_FLUX_LIST_COLNAME_FLUX "FLUX" +#define SINFO_STAR_FLUX_LIST_COLNAME_WAVELENGTH "LAMBDA" + +typedef struct { + int size ; + cpl_propertylist * header ; + double * lambda ; + double * flux ; +} sinfo_star_flux_list ; + + + + +typedef enum {false,true} bool; + + + + +#define SYNTAX "Test response computation algorithml\n"\ + "usage : \n"\ + "./sinfo_response_test STD_STAR_SPECTRA REF_STD_STAR_CATALOG EXT_TAB RESP_FIT_POINTS TELL_MOD\n"\ + "STD_STAR_SPECTRA => File product with extracted std star spectrum\n"\ + "REF_STD_STAR_CATALOG => Table with std star FITS spectra\n"\ + "EXT_TAB => Table with atm extinction coeffs\n"\ + "RESP_FIT_POINTS => Table with response fit points\n"\ + "TELL_MOD => Table with telluric model\n" + +/* Get the value of a keyword */ + + +#define SINFO_SEEING_START "ESO TEL AMBI FWHM START" +#define SINFO_SEEING_END "ESO TEL AMBI FWHM END" + + + + + + + + + + +static const double STAR_MATCH_DEPSILON=0.0166667; /*60 arcsecs */ + +static cpl_error_code +sinfo_table_save(cpl_table* t, cpl_propertylist* ph, cpl_propertylist* xh, + const char* fname, const int ext) { + + if (ext==0) { + cpl_table_save(t,ph,xh,fname,CPL_IO_DEFAULT); + } else { + cpl_table_save(t,ph,xh,fname,CPL_IO_EXTEND); + } + + return cpl_error_get_code(); + +} +static void sinfo_rv_ref_wave_param_destroy(sinfo_rv_ref_wave_param * p){ + + cpl_free(p); + + return ; +} + + + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get size of spectrum + * + * @param[in] s spectrum structure + * + * @return the size of flux data in spectrum + */ +/*---------------------------------------------------------------------------*/ +static int sinfo_spectrum_get_size( sinfo_spectrum* s) +{ + int res=0; + + SINFO_ASSURE_NOT_NULL( s); + + res = s->size; + + cleanup: + return res; +} + + +/** + * @brief Get minimum lambda of spectrum + * + * @param[in] s spectrum structure + * + * @return minimum lambda spectrum + */ +/*---------------------------------------------------------------------------*/ +static double sinfo_spectrum_get_lambda_min( sinfo_spectrum* s) +{ + double res=0.0; + + SINFO_ASSURE_NOT_NULL( s); + + res = s->lambda_min; + + cleanup: + return res; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get maximum lambda of spectrum + * + * @param[in] s spectrum structure + * + * @return maximum lambda of spectrum + */ +/*---------------------------------------------------------------------------*/ +static double sinfo_spectrum_get_lambda_max( sinfo_spectrum* s) +{ + double res=0.0; + + SINFO_ASSURE_NOT_NULL( s); + + res = s->lambda_max; + + cleanup: + return res; +} + + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Get bin in lambda of spectrum + * + * @param[in] s spectrum structure + * + * @return bin in lambda of spectrum + */ +/*---------------------------------------------------------------------------*/ +static double sinfo_spectrum_get_lambda_step( sinfo_spectrum* s) +{ + double res=0.0; + + SINFO_ASSURE_NOT_NULL( s); + + res = s->lambda_step; + + cleanup: + return res; +} + + + + +static void sinfo_star_flux_list_free( sinfo_star_flux_list ** list ) +{ + if ( list != NULL && *list != NULL ) { + sinfo_free_propertylist(&(*list)->header); + cpl_free( (*list)->lambda ) ; + cpl_free( (*list)->flux ) ; + //cpl_free( (*list)->header ) ; + cpl_free( *list ) ; + *list = NULL ; + } + + + return ; +} + + +static cpl_frame * sinfo_star_flux_list_save( sinfo_star_flux_list * list, + const char * filename, const char * tag ) +{ + cpl_table * table = NULL ; + cpl_frame * result = NULL ; + int size, i ; + double * plambda, * pflux ; + + SINFO_ASSURE_NOT_NULL(list); + SINFO_ASSURE_NOT_NULL(filename); + + /* create a table */ + table = cpl_table_new( 2 ); + + /* create column names */ + cpl_table_new_column(table, SINFO_STAR_FLUX_LIST_COLNAME_WAVELENGTH, + CPL_TYPE_FLOAT); + cpl_table_new_column(table, SINFO_STAR_FLUX_LIST_COLNAME_FLUX, + CPL_TYPE_FLOAT); + + size = list->size ; + plambda = list->lambda ; + pflux = list->flux ; + + cpl_table_set_size(table, size); + + /* insert data */ + for( i = 0 ; iheader, NULL, filename, CPL_IO_DEFAULT); + //xsh_add_temporary_file( filename ); + + /* Create the frame */ + result=sinfo_frame_product( filename, tag, + CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_TEMPORARY); + + sinfo_msg( "Star Flux Frame Saved" ) ; + cleanup: + sinfo_free_table( &table); + return result ; +} +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD1_1 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd11(cpl_propertylist * plist, double value) +{ + check (cpl_propertylist_update_double (plist, SINFO_CD11, value), + "Error writing keyword '%s'", SINFO_CD11); + cleanup: + return; +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD1_2 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd12(cpl_propertylist * plist, double value) +{ + check (cpl_propertylist_update_double (plist, SINFO_CD12, value), + "Error writing keyword '%s'", SINFO_CD12); + cleanup: + return; +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD2_1 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd21(cpl_propertylist * plist, double value) +{ + check (cpl_propertylist_update_double (plist, SINFO_CD21, value), + "Error writing keyword '%s'", SINFO_CD21); + cleanup: + return; +} + +/*--------------------------------------------------------------------------- */ +/** + * @brief Write the CD2_2 value + * @param plist Property list to write to + * @param value The value to write + */ +/*--------------------------------------------------------------------------- */ +static void sinfo_pfits_set_cd22(cpl_propertylist * plist, double value) +{ + check (cpl_propertylist_update_double (plist, SINFO_CD22, value), + "Error writing keyword '%s'", SINFO_CD22); + cleanup: + return; +} + +static cpl_error_code +sinfo_pfits_set_cd_matrix(cpl_propertylist* header, + const double cdelt1, + const double cdelt2) { + + sinfo_pfits_set_cd11(header, cdelt1); + sinfo_pfits_set_cd12(header, 0); + sinfo_pfits_set_cd21(header, 0); + sinfo_pfits_set_cd22(header, cdelt2); + + return cpl_error_get_code(); +} + + +/** +@brief set hdu keys +@param plist input propertylist +@param hduclas1 hdu classification1 value +@param hduclas2 hdu classification2 value +@param hduclas3 hdu classification3 value +@return updated propertylist +*/ +static cpl_error_code +sinfo_plist_set_extra_common_keys(cpl_propertylist* plist) +{ + + cpl_propertylist_append_string(plist,"HDUCLASS", "ESO") ; + cpl_propertylist_set_comment(plist,"HDUCLASS","hdu classification") ; + + cpl_propertylist_append_string(plist,"HDUDOC", "DICD") ; + cpl_propertylist_set_comment(plist,"HDUDOC","hdu reference document") ; + + cpl_propertylist_append_string(plist,"HDUVERS", "DICD V6.0") ; + cpl_propertylist_set_comment(plist,"HDUVERS","hdu reference document version") ; + + return cpl_error_get_code(); +} + + +/** +@brief set hdu keys +@param plist input propertylist +@param hduclas1 hdu classification1 value +@param hduclas2 hdu classification2 value +@param hduclas3 hdu classification3 value +@param scidata name of data extension +@param errdata name of errs extension +@param qualdata name of qual extension +@param type type of extension: 0 data, 1 errs, 2 qual +@return updated propertylist +*/ +cpl_error_code +sinfo_plist_set_extra_keys(cpl_propertylist* plist, + const char* hduclas1, + const char* hduclas2, + const char* hduclas3, + const char* scidata, + const char* errdata, + const char* qualdata, + const int type) +{ + + //SINFO_ASSURE_NOT_ILLEGAL_MSG(type<3,"type < 3"); + SINFO_ASSURE_NOT_ILLEGAL_MSG(type>=0,"type > 0"); + + sinfo_plist_set_extra_common_keys(plist); + + cpl_propertylist_append_string(plist,"HDUCLAS1",hduclas1) ; + cpl_propertylist_set_comment(plist,"HDUCLAS1","hdu format classification") ; + + cpl_propertylist_append_string(plist,"HDUCLAS2",hduclas2) ; + cpl_propertylist_set_comment(plist,"HDUCLAS2","hdu type classification") ; + + if(type == 0) { + if(!cpl_propertylist_has(plist,"EXTNAME")) { + cpl_propertylist_append_string(plist,"EXTNAME",scidata) ; + cpl_propertylist_set_comment(plist,"EXTNAME","name of data extension") ; + } + } + + if(type!=0) { + if(!cpl_propertylist_has(plist,"HDUCLAS3")) { + cpl_propertylist_append_string(plist,"HDUCLAS3",hduclas3) ; + cpl_propertylist_set_comment(plist,"HDUCLAS3","hdu info classification") ; + } + if(!cpl_propertylist_has(plist,"SCIDATA")) { + cpl_propertylist_append_string(plist,"SCIDATA",scidata) ; + cpl_propertylist_set_comment(plist,"SCIDATA","name of data extension") ; + } + } + + if(type!=1) { + if(!cpl_propertylist_has(plist,"ERRDATA")) { + cpl_propertylist_append_string(plist,"ERRDATA",errdata) ; + cpl_propertylist_set_comment(plist,"ERRDATA","name of errs extension") ; + } + } + + if(type!=2) { + if(!cpl_propertylist_has(plist,"QUALDATA")) { + cpl_propertylist_append_string(plist,"QUALDATA",qualdata) ; + cpl_propertylist_set_comment(plist,"QUALDATA","name of qual extension") ; + } + } + cleanup: + return cpl_error_get_code(); +} + + + +static sinfo_atmos_ext_list * sinfo_atmos_ext_list_create( int size ) +{ + sinfo_atmos_ext_list * result = NULL ; + + /* Create the list */ + SINFO_CALLOC( result, sinfo_atmos_ext_list, 1 ) ; + result->size = size ; + SINFO_CALLOC( result->lambda, double, size ) ; + SINFO_CALLOC( result->K, double, size ) ; + + cleanup: + return result ; +} + + +static double sinfo_pfits_get_seeing_start (const cpl_propertylist * plist) +{ + double ret = 0; + + sinfo_get_property_value( plist, SINFO_SEEING_START, CPL_TYPE_DOUBLE,&ret); +cleanup: + return ret; +} + + + +/*---------------------------------------------------------------------------*/ +/** + * @brief Load a 1D spectrum structure + * + * @param[in] s1d_frame the 1D spectrum frame + * @return the spectrum structure + */ +/*---------------------------------------------------------------------------*/ +static sinfo_spectrum* sinfo_spectrum_load( cpl_frame* s1d_frame) +{ + sinfo_spectrum* result = NULL; + const char *s1dname = NULL; + int naxis; + sinfo_msg_warning("pk1 s1d_frame=%p",s1d_frame); + SINFO_ASSURE_NOT_NULL( s1d_frame); + sinfo_msg_warning("pk2 fname=%s",cpl_frame_get_filename(s1d_frame)); + sinfo_msg_warning("pk2 dim=%lld",cpl_frame_get_nextensions(s1d_frame)); + SINFO_ASSURE_NOT_ILLEGAL(cpl_frame_get_nextensions(s1d_frame) == 2); + + check_nomsg( s1dname = cpl_frame_get_filename( s1d_frame)); + sinfo_msg_warning("pk2"); + SINFO_CALLOC(result, sinfo_spectrum,1); + + check_nomsg( result->flux_header = cpl_propertylist_load( s1dname,0)); + check_nomsg( result->errs_header = cpl_propertylist_load( s1dname,1)); + check_nomsg( result->qual_header = cpl_propertylist_load( s1dname,2)); + sinfo_msg_warning("pk3"); + check_nomsg( result->lambda_min = sinfo_pfits_get_crval1( result->flux_header)); + sinfo_msg_warning("pk3"); + check_nomsg( result->lambda_step = sinfo_pfits_get_cdelt1( result->flux_header)); + sinfo_msg_warning("pk3"); + check_nomsg( result->size = sinfo_pfits_get_naxis1( result->flux_header)); + sinfo_msg_warning("pk3"); + check_nomsg( result->size_lambda = sinfo_pfits_get_naxis1( result->flux_header)); + sinfo_msg_warning("pk3"); + result->lambda_max = result->lambda_min+ + result->lambda_step*(result->size-1); + sinfo_msg_warning("pk3"); + check_nomsg( naxis = sinfo_pfits_get_naxis( result->flux_header)); + sinfo_msg_warning("pk4"); + if (naxis > 1){ + check_nomsg( result->slit_min = sinfo_pfits_get_crval2( result->flux_header)); + check_nomsg( result->slit_step = sinfo_pfits_get_cdelt2( result->flux_header)); + check_nomsg( result->size_slit = sinfo_pfits_get_naxis2( result->flux_header)); + result->slit_max = result->slit_min+ + result->slit_step*(result->size_slit-1); + + check_nomsg( result->flux = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0, 0)); + check_nomsg( result->errs = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0, 1)); + check_nomsg( result->qual = cpl_image_load( s1dname, CPL_TYPE_INT, 0, 2)); + } + else{ + double *flux_data = NULL; + double *errs_data = NULL; + int *qual_data = NULL; + int i; + cpl_vector *flux = NULL; + cpl_vector *errs = NULL; + cpl_vector *qual = NULL; + int size = 0; + + check_nomsg( flux = cpl_vector_load( s1dname, 0)); + check_nomsg( size = cpl_vector_get_size( flux)); + check_nomsg( errs = cpl_vector_load( s1dname, 1)); + check_nomsg( qual = cpl_vector_load( s1dname, 2)); + check_nomsg( flux_data = cpl_vector_get_data( flux)); + check_nomsg( result->flux = cpl_image_wrap_double( size, 1 , flux_data)); + cpl_vector_unwrap( flux); + + check_nomsg( errs_data = cpl_vector_get_data( errs)); + check_nomsg( result->errs = cpl_image_wrap_double( size, 1, errs_data)); + + check_nomsg( result->qual = cpl_image_new ( size, 1, CPL_TYPE_INT)); + check_nomsg( qual_data = cpl_image_get_data_int( result->qual)); + for(i=0; i< size; i++){ + check_nomsg( qual_data[i] = (int)cpl_vector_get(qual,i)); + } + cpl_vector_unwrap( errs); + cpl_vector_delete( qual); + } + sinfo_msg_warning("pk5"); + cleanup: + if (cpl_error_get_code() != CPL_ERROR_NONE) { + sinfo_spectrum_free(&result); + } + return result; +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Load a 1D spectrum structure + * + * @param[in] s1d_frame the 1D spectrum frame + * @return the spectrum structure + */ +/*---------------------------------------------------------------------------*/ +static sinfo_spectrum* +sinfo_spectrum_load_from_table( cpl_frame* s1d_frame, const char* wname, + const char* fname) +{ + sinfo_spectrum* result = NULL; + const char *s1dname = NULL; + cpl_table* tab=NULL; + + int status; + + SINFO_ASSURE_NOT_NULL( s1d_frame); + check_nomsg( s1dname = cpl_frame_get_filename( s1d_frame)); + tab = cpl_table_load(s1dname, 1, 0); + sinfo_msg_warning("loading file %s",s1dname); + SINFO_CALLOC(result, sinfo_spectrum,1); + check_nomsg( result->flux_header = cpl_propertylist_load( s1dname,0)); + check_nomsg( result->errs_header = cpl_propertylist_load( s1dname,0)); + check_nomsg( result->qual_header = cpl_propertylist_load( s1dname,0)); + + check_nomsg( result->lambda_min = cpl_table_get_column_min(tab,wname)); + + float* pspec; + //check_nomsg( result->lambda_step = sinfo_pfits_get_cdelt1( result->flux_header)); + + //check_nomsg(result->lambda_step=cpl_table_get_float(tab,wname,1,&status)-result->lambda_min); + pspec=cpl_table_get_data_float(tab, fname); + + check_nomsg(result->size = cpl_table_get_nrow(tab)); + check_nomsg(result->size_lambda = cpl_table_get_nrow(tab)); + + result->lambda_max = cpl_table_get_column_max(tab,wname); + result->lambda_step=(result->lambda_max-result->lambda_min)/(result->size-1); + pspec=cpl_table_get_data_float(tab, fname); + + check_nomsg( result->flux = cpl_image_new( result->size, 1 , CPL_TYPE_DOUBLE)); + check_nomsg( result->errs = cpl_image_new( result->size, 1 , CPL_TYPE_DOUBLE)); + check_nomsg( result->qual = cpl_image_new( result->size, 1 , CPL_TYPE_INT)); + + + double* pflux=cpl_image_get_data_double(result->flux); + double* perrs=cpl_image_get_data_double(result->errs); + int* pqual=cpl_image_get_data_int(result->qual); + + for(int i=0;isize_lambda;i++) { + pflux[i]=pspec[i]; + perrs[i]=sqrt(fabs(pflux[i])); + pqual[i]=0; + } + sinfo_msg_warning("spectrum size %d", result->size); + cleanup: + sinfo_free_table(&tab); + if (cpl_error_get_code() != CPL_ERROR_NONE) { + sinfo_print_rec_status(9); + sinfo_spectrum_free(&result); + } + return result; +} + +static star_index* star_index_construct(const char* fits_file) +{ + star_index* pret = cpl_malloc(sizeof(star_index)); + pret->index_size = 0; + pret->index_table = 0; + pret->cache_size = 0; + pret->cache = 0; + pret->cache_index = 0; + if (fits_file) + { + size_t bt = strlen(fits_file) * sizeof(*fits_file)+1; + pret->fits_file_name = cpl_malloc(bt); + strcpy(pret->fits_file_name, fits_file); + } + else + { + pret->fits_file_name = 0; + } + return pret; +} + + +static void star_index_destruct(star_index* pindex) +{ + if(pindex) + { + if (pindex->cache) + { + int i = 0; + for ( i = 0; i < pindex->cache_size; i++) + { + cpl_table_delete(pindex->cache[i]); + } + cpl_free(pindex->cache); + pindex->cache = 0; + pindex->cache_size = 0; + } + cpl_table_delete(pindex->index_table); + if(pindex->fits_file_name) + { + cpl_free(pindex->fits_file_name); + } + cpl_free(pindex->cache_index); + cpl_free(pindex); + } + +} + + + +static double +sinfo_iterpol_linear(double* data_x,double* data_y,int ndata,double x, +int* i_inf,int* i_sup) +{ + int i=0; + double y=0; + //int i_min=0; + //int i_max=0; + double x1=data_x[*i_inf]; + double x2=data_x[*i_sup]; + double y1=data_y[*i_inf]; + double y2=data_y[*i_sup]; + //x1=x2=y1=y2=0; + //i_min=((*i_inf)>0) ? (*i_inf):0; + //i_max=((*i_sup)x) { + y1=data_y[i-1]; + y2=data_y[i]; + x1=data_x[i-1]; + x2=data_x[i]; + *i_inf=i-1; + *i_sup=i+1; + break; + } + } + //sinfo_msg("i_inf=%d i_sup=%d",*i_inf,*i_sup); + y=(y2-y1)/(x2-x1)*(x-x1)+y1; + //sinfo_msg("x1=%g x2=%g y1=%g y2=%g x=%g y=%g",x1,x2,y1,y2,x,y); + + return y; +} + +static sinfo_star_flux_list * sinfo_star_flux_list_create( int size ) +{ + sinfo_star_flux_list * result = NULL ; + + /* Create the list */ + SINFO_CALLOC( result, sinfo_star_flux_list, 1 ) ; + result->header = NULL ; + result->size = size ; + SINFO_CALLOC( result->lambda, double, size ) ; + SINFO_CALLOC( result->flux, double, size ) ; + + cleanup: + return result ; +} + + +static sinfo_star_flux_list * sinfo_star_flux_list_load( cpl_frame * star_frame) +{ + cpl_table *table = NULL ; + const char * tablename = NULL ; + sinfo_star_flux_list * result = NULL ; + int nentries, i ; + double * plambda, * pflux ; + + /* verify input */ + SINFO_ASSURE_NOT_NULL( star_frame); + + /* get table filename */ + check_nomsg(tablename = cpl_frame_get_filename( star_frame )); + + /* Load the table */ + table=cpl_table_load(tablename,1,0); + //SINFO_TABLE_LOAD( table, tablename ) ; + + /* + cpl_table_and_selected_double(table,SINFO_STAR_FLUX_LIST_COLNAME_WAVELENGTH,CPL_LESS_THAN,SINFO_STAR_FLUX_UVB_WAV_MIN); + cpl_table_erase_selected(table); + */ + + check_nomsg( nentries = cpl_table_get_nrow( table ) ) ; + + /* Create the list */ + check_nomsg( result = sinfo_star_flux_list_create( nentries ) ) ; + + plambda = result->lambda ; + pflux = result->flux ; + + check_nomsg(result->header = cpl_propertylist_load(tablename, 0)); + + check_nomsg(cpl_table_cast_column(table,SINFO_STAR_FLUX_LIST_COLNAME_WAVELENGTH,"F_WAVELENGTH",CPL_TYPE_FLOAT)); + check_nomsg(cpl_table_cast_column(table,SINFO_STAR_FLUX_LIST_COLNAME_FLUX,"F_FLUX",CPL_TYPE_FLOAT)) +; + + /* Fill the list */ + int status=0; + for( i = 0 ; i< nentries ; i++, plambda++, pflux++ ) { + float value ; + + check_nomsg( value=cpl_table_get_float( table, "F_WAVELENGTH",i, &status ) ) ; + *plambda = value ; + check_nomsg( value=cpl_table_get_float( table, "F_FLUX", i, &status ) ) ; + *pflux = value ; + } + + cleanup: + if (cpl_error_get_code () != CPL_ERROR_NONE) { + sinfo_msg("Error: can't load frame %s",cpl_frame_get_filename(star_frame)); + sinfo_star_flux_list_free(&result); + } + sinfo_free_table(&table); + return result ; +} + + +/** +@brief spectra interpolation +@param table_frame table frame containing the spectrum +@param wstep wave step +@param wmin wave min +@param wmax wave max + */ +static cpl_frame* +sinfo_spectrum_interpolate_linear(cpl_frame* table_frame, + const double wstep, + const double wmin, + const double wmax) +{ + + cpl_frame* result=NULL; + cpl_table* table_i=NULL; + cpl_table* table_o=NULL; + const char* name_i=NULL; + const char* tag_i=NULL; + + char* name_o=NULL; + char* tag_o=NULL; + + cpl_propertylist* plist=NULL; + int nrows_i=0; + int nrows_o=0; + int row=0; + + double* pwave_i=NULL; + double* pflux_i=NULL; + double* pwave_o=NULL; + double* pflux_o=NULL; + int i_inf=0; + int i_sup=0; + + //int istart = 0; + + SINFO_ASSURE_NOT_NULL_MSG(table_frame,"Null input table frame"); + SINFO_ASSURE_NOT_ILLEGAL_MSG(wmax>wmin,"wmax < wmin"); + SINFO_ASSURE_NOT_ILLEGAL_MSG(wstep>0,"wstep <= 0"); + + name_i=cpl_frame_get_filename(table_frame); + tag_i=cpl_frame_get_tag(table_frame); + //sinfo_msg("name_i=%s",name_i); + check_nomsg(table_i=cpl_table_load(name_i,1,0)); + nrows_i=cpl_table_get_nrow(table_i); + plist=cpl_propertylist_load(name_i,0); + nrows_o=(int)((wmax-wmin)/wstep+0.5); + table_o=cpl_table_new(nrows_o); + cpl_table_new_column(table_o,"LAMBDA",CPL_TYPE_DOUBLE); + cpl_table_new_column(table_o,"FLUX",CPL_TYPE_DOUBLE); + check_nomsg(cpl_table_fill_column_window_double(table_o,"LAMBDA",0,nrows_o,0.)); + check_nomsg(cpl_table_fill_column_window_double(table_o,"FLUX",0,nrows_o,0.)); + check_nomsg(pwave_i=cpl_table_get_data_double(table_i,"LAMBDA")); + check_nomsg(pflux_i=cpl_table_get_data_double(table_i,"FLUX")); + check_nomsg(pwave_o=cpl_table_get_data_double(table_o,"LAMBDA")); + check_nomsg(pflux_o=cpl_table_get_data_double(table_o,"FLUX")); + i_inf=0; + i_sup=nrows_o; + + for (row = 0; row < nrows_o; row++) + { + + pwave_o[row]= wmin + row * wstep; + pflux_o[row]= sinfo_iterpol_linear(pwave_i,pflux_i,nrows_i,pwave_o[row], + &i_inf,&i_sup); + + //sinfo_msg("interpolated flux[%g]=%g",pwave_o[row],pflux_o[row]); + } + tag_o=cpl_sprintf("INTERPOL_%s",tag_i); + name_o=cpl_sprintf("INTERPOL_%s.fits",tag_i); + sinfo_pfits_set_pcatg(plist,tag_o); + check_nomsg(cpl_table_save(table_o,plist,NULL,name_o,CPL_IO_DEFAULT)); + check_nomsg(result=sinfo_frame_product(name_o,tag_o,CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL)); + + cleanup: + + + sinfo_free_table(&table_i); + sinfo_free_table(&table_o); + sinfo_free_propertylist(&plist); + cpl_free(name_o); + cpl_free(tag_o); + + return result; + +} +static double * +sinfo_bspline_interpolate_data_at_pos(double* w_data, double* f_data, + const int n_data, + double* w_pos, const int n_pos) +{ + double * result=NULL; + + int i_min = 0; + int i_max = n_pos; + gsl_interp_accel *acc = gsl_interp_accel_alloc (); + int i=0; + sinfo_msg("w_pos[0]=%g w_data[0]=%g",w_pos[0],w_data[0]); + sinfo_msg("w_pos[n_pos-1]=%g w_data[n_data-1]=%g",w_pos[n_pos-1],w_data[n_data-1]); + cpl_ensure(w_pos[0] >= w_data[0], CPL_ERROR_ILLEGAL_INPUT,NULL); + cpl_ensure(w_pos[n_pos-1] <= w_data[n_data-1], CPL_ERROR_ILLEGAL_INPUT,NULL); + + gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, n_data); + + gsl_spline_init (spline, w_data, f_data, n_data); + + + result=cpl_calloc(n_pos, sizeof(double)); + + if(w_pos[0] == w_data[0]) { + result[0] = f_data[0]; + i_min = 1; + } + + if(w_pos[n_pos-1] == w_data[n_data-1]) { + result[n_pos-1] = f_data[n_data-1]; + i_max = n_pos-1; + } + + for (i = i_min; i < i_max; i ++) { + double xi = w_pos[i]; + double yi = gsl_spline_eval (spline, xi, acc); + //printf ("%g %g\n", xi, yi); + result[i]=yi; + } + + gsl_spline_free (spline); + gsl_interp_accel_free (acc); + + return result; +} + + + +static cpl_frame* sinfo_spectrum_save2( sinfo_spectrum* s, const char* filename, + const char* tag) +{ + cpl_frame *product_frame = NULL; + + SINFO_ASSURE_NOT_NULL(s); + SINFO_ASSURE_NOT_NULL(filename); + + check_nomsg( sinfo_pfits_set_extname(s->flux_header , "FLUX")); + check_nomsg(sinfo_plist_set_extra_keys(s->flux_header,"IMAGE","DATA","RMSE", + "FLUX","ERRS","QUAL",0)); + + check_nomsg( sinfo_pfits_set_extname(s->errs_header , "ERRS")); + check_nomsg(sinfo_plist_set_extra_keys(s->errs_header,"IMAGE","DATA","RMSE", + "FLUX","ERRS","QUAL",1)); + + check_nomsg( sinfo_pfits_set_extname(s->qual_header , "QUAL")); + check_nomsg(sinfo_plist_set_extra_keys(s->qual_header,"IMAGE","DATA","RMSE", + "FLUX","ERRS","QUAL",2)); + + /* Save the file */ + if ( s->size_slit > 1){ + + double crval1=0; + double crpix1=0; + double cdelt1=0; + + double crval2=0; + double crpix2=0; + double cdelt2=0; + + crval1=sinfo_pfits_get_crval1(s->flux_header); + crpix1=sinfo_pfits_get_crpix1(s->flux_header); + cdelt1=sinfo_pfits_get_cdelt1(s->flux_header); + + crval2=sinfo_pfits_get_crval2(s->flux_header); + crpix2=sinfo_pfits_get_crpix2(s->flux_header); + cdelt2=sinfo_pfits_get_cdelt2(s->flux_header); + + sinfo_pfits_set_wcs(s->errs_header,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2); + sinfo_pfits_set_wcs(s->qual_header,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2); + + check_nomsg( sinfo_pfits_set_pcatg( s->flux_header, tag)); + check(cpl_image_save ( s->flux, filename, CPL_BPP_IEEE_FLOAT, + s->flux_header, CPL_IO_DEFAULT), + "Could not save data to %s extension 0", filename); + check(cpl_image_save ( s->errs, filename, CPL_BPP_IEEE_FLOAT, + s->errs_header, CPL_IO_EXTEND), + "Could not save errs to %s extension 1", filename); + check(cpl_image_save ( s->qual, filename, CPL_BPP_32_SIGNED, + s->qual_header, CPL_IO_EXTEND), + "Could not save qual to %s extension 2", filename); + } + else{ + cpl_vector *flux1D = NULL; + cpl_vector *err1D = NULL; + cpl_vector *qual1D = NULL; + + double crval1=0; + double crpix1=0; + double cdelt1=0; + + crval1=sinfo_pfits_get_crval1(s->flux_header); + crpix1=sinfo_pfits_get_crpix1(s->flux_header); + cdelt1=sinfo_pfits_get_cdelt1(s->flux_header); + + + + sinfo_pfits_set_ctype1(s->flux_header,"LINEAR"); + sinfo_pfits_set_cunit1(s->flux_header,"nm"); + cpl_propertylist_erase_regexp(s->flux_header, "^CTYPE2", 0); + + + + //check_nomsg(sinfo_pfits_set_wcs1(s->errs_header, crpix1, crval1, cdelt1)); + sinfo_pfits_set_cunit1(s->errs_header,"nm"); + + //check_nomsg(sinfo_pfits_set_wcs1(s->qual_header, crpix1, crval1, cdelt1)); + sinfo_pfits_set_cunit1(s->qual_header,"nm"); + sinfo_pfits_set_bunit(s->qual_header,SINFO_BUNIT_NONE_C); + + check_nomsg( flux1D = cpl_vector_new_from_image_row( s->flux, 1)); + check_nomsg( err1D = cpl_vector_new_from_image_row( s->errs, 1)); + check_nomsg( qual1D = cpl_vector_new_from_image_row( s->qual, 1)); + check_nomsg( cpl_vector_save( flux1D, filename, CPL_BPP_IEEE_FLOAT, + s->flux_header, CPL_IO_DEFAULT)); + check_nomsg( cpl_vector_save( err1D, filename, CPL_BPP_IEEE_FLOAT, + s->errs_header, CPL_IO_EXTEND)); + check_nomsg( cpl_vector_save( qual1D, filename, CPL_BPP_32_SIGNED, + s->qual_header, CPL_IO_EXTEND)); + cpl_vector_delete( flux1D); + cpl_vector_delete( err1D); + cpl_vector_delete( qual1D); + } + + + check_nomsg( product_frame = cpl_frame_new() ) ; + check_nomsg( cpl_frame_set_filename( product_frame,filename )); + check_nomsg( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ; + check_nomsg( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ; + check_nomsg( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT )); + + cleanup: + if (cpl_error_get_code () != CPL_ERROR_NONE) { + sinfo_free_frame(&product_frame); + product_frame = NULL; + } + return product_frame; +} + +static cpl_table* +sinfo_spectrum_to_table(sinfo_spectrum* s) +{ + + cpl_table* table_s=NULL; + int size=0; + int i=0; + + double wmin=0; + double wstp=0; + + double* pwave=NULL; + + double* perrs=NULL; + double* pflux=NULL; + int* pqual=NULL; + + double* errs=NULL; + double* flux=NULL; + int* qual=NULL; + + size=sinfo_spectrum_get_size_lambda(s); + wmin= sinfo_spectrum_get_lambda_min(s); + wstp= sinfo_spectrum_get_lambda_step(s); + //sinfo_msg("wmin=%g[nm] wstp=%g[nm]",wmin,wstp); + + //sinfo_msg("Lambda size spectrum=%d",size); + table_s=cpl_table_new(size); + cpl_table_new_column(table_s,"wavelength",CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(table_s,"wavelength",0,size,0); + pwave=cpl_table_get_data_double(table_s,"wavelength"); + + cpl_table_new_column(table_s,"flux",CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(table_s,"flux",0,size,0); + pflux=cpl_table_get_data_double(table_s,"flux"); + + cpl_table_new_column(table_s,"errs",CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(table_s,"errs",0,size,0); + perrs=cpl_table_get_data_double(table_s,"errs"); + + cpl_table_new_column(table_s,"qual",CPL_TYPE_INT); + cpl_table_fill_column_window_int(table_s,"qual",0,size,0); + pqual=cpl_table_get_data_int(table_s,"qual"); + + + flux=sinfo_spectrum_get_flux(s); + errs=sinfo_spectrum_get_errs(s); + qual=sinfo_spectrum_get_qual(s); + + for(i=0;iflux_header); + * and is replaced by: + */ + sinfo_msg_warning("pk1"); + nentries=spectrum->size; + + //PIPPO + + /* Create the list */ + check_nomsg( result = sinfo_star_flux_list_create( nentries ) ) ; + result->header = cpl_propertylist_duplicate(spectrum->flux_header); + + sinfo_msg_warning("pk2"); + cpl_propertylist_append_int(result->header,"NAXIS1",spectrum->size); + sinfo_msg_warning("pk3"); + cpl_propertylist_append_double(result->header,"CRVAL1",spectrum->lambda_min); + sinfo_msg_warning("pk4"); + cpl_propertylist_append_double(result->header,"CDELT1",spectrum->lambda_step); + sinfo_msg_warning("pk5"); + plambda = result->lambda ; + pflux = result->flux ; + + double* pima=cpl_image_get_data_double(spectrum->flux); + double wmin=spectrum->lambda_min; + double wstep=spectrum->lambda_step; + + double wmax; + + /* Fill the list */ + sinfo_msg_warning("nentries=%d",nentries); + + for( i = 0 ; i< nentries ; i++, plambda++, pflux++ ) { + double x=i; + *plambda = (float) (wmin+x*wstep) ; + *pflux = (float) pima[i]; + wmax=*plambda; + + } + sinfo_msg_warning("Test wmin=%g wmax=%g wstep=%g",wmin,wmax,wstep); + cleanup: + + if (cpl_error_get_code () != CPL_ERROR_NONE) { + sinfo_msg_error("can't load frame %s",cpl_frame_get_filename(star_frame)); + sinfo_print_rec_status(0); + sinfo_star_flux_list_free(&result); + } + sinfo_spectrum_free(&spectrum); + return result; +} + + + +static HIGH_ABS_REGION * +sinfo_fill_tell_fit_regions( + new_sinfo_band band, + cpl_frame* high_abs_frame) +{ + HIGH_ABS_REGION * phigh=NULL; + int nrow=0; + double* pwmin=0; + double* pwmax=0; + int i=0; + cpl_table* high_abs_tab=NULL; + + + if(high_abs_frame !=NULL) { + high_abs_tab=cpl_table_load(cpl_frame_get_filename(high_abs_frame),1,0); + } + //the_arm=xsh_instrument_get_arm(instrument); + + + + if(high_abs_tab!=NULL) { + nrow=cpl_table_get_nrow(high_abs_tab); + check_nomsg(pwmin=cpl_table_get_data_double(high_abs_tab,"LAMBDA_MIN")); + check_nomsg(pwmax=cpl_table_get_data_double(high_abs_tab,"LAMBDA_MAX")); + + phigh = (HIGH_ABS_REGION *) cpl_calloc(nrow + 1, sizeof(HIGH_ABS_REGION)); + for(i=0;isize); + + + cpl_ensure_code(list->size == size, CPL_ERROR_ILLEGAL_INPUT); + + /* copy flux from list to specrum */ + pflux = cpl_table_get_data_float(s, "counts_bkg"); + + + if(pflux) + cpl_msg_warning("", "OK ptr"); + else + cpl_msg_warning("", "bad ptr"); + + for(i=0;iflux[i]; + } + + cpl_msg_warning("", "OK p2222tr"); + + + plist = cpl_propertylist_load(name, 0); + cpl_table_save(s, plist, NULL, name, CPL_IO_CREATE); + + cleanup: + cpl_frame_delete(frm); + cpl_table_delete(s); + cpl_propertylist_delete(plist); + + cpl_msg_warning("", "END SAVE"); + + return cpl_error_get_code() ; +} + + +/** + @name xsh_xcorrelate + @memo Cross-correlation of two 1d signals. + @param line_i The reference signal. + @param width_i Number of samples in reference signal. + @param line_t Candidate signal to compare. + @param width_t Number of samples in candidate signal. + @param half_search Half-size of the search domain. + @param delta Output sinfo_correlation offset. + @return Maximum cross-correlation value as a double. + @doc + + Two signals are expected in input of this function: a reference + signal (line_i) and a candidate signal (line_t) . + They are expected to be roughly the same signal up to an offset (delta) + + A cross-correlation is computed on 2*half_search+1 values. The + maximum of likelihood is the maximum cross-correlation value between + signals. The offset 'delta' corresponding to this position is returned. + + Returns -100.0 in case of error. Normally, the cross-sinfo_correlation + coefficient is normalized so it should stay between -1 and +1. + */ + +static double* +sinfo_function1d_xcorrelate2( + double * line_i, + int width_i, + double * line_t, + int width_t, + int half_search, + int normalise, + double * xcorr_max, + double * delta +) +{ + double * xcorr ; + double mean_i, mean_t ; + double rms_i, rms_t ; + double sum, sqsum ; + double norm ; + int maxpos ; + int nsteps ; + int i ; + int step ; + + int STEP_MIN=-half_search; + int STEP_MAX=half_search; + + /* Compute normalization factors */ + sum = sqsum = 0.00 ; + /* + sinfo_msg_warning("width_i=%d width_t=%d half_search=%d normalise=%d", + width_i,width_t,half_search,normalise); + */ + for (i=0 ; i= 0) && + (i+step < width_i)) { + if( !isnan(line_i[i+step]) && !isnan(line_t[i]) ) { + xcorr[step-STEP_MIN] += (line_t[i] - mean_t) * + (line_i[i+step] - mean_i) * + norm ; + } + /* + sinfo_msg_warning("xcorr=%g f1=%g f2=%g norm=%g", + xcorr[step-STEP_MIN], + (line_t[i] - mean_t), + (line_i[i+step] - mean_i),norm); + */ + nval++ ; + } + } + xcorr[step-STEP_MIN] /= (double) nval ; + } + + *xcorr_max = xcorr[0] ; + //sinfo_msg_warning("xcorr_max=%g",*xcorr_max); + maxpos = 0 ; + for (i=0 ; i(*xcorr_max)) { + maxpos = i ; + *xcorr_max = xcorr[i]; + } + } + double fraction = 0; + //sinfo_msg_warning("maxpos=%d",maxpos); + + cpl_vector* vcor=cpl_vector_wrap(nsteps,xcorr); + double a=xcorr[maxpos-1]; + double b=xcorr[maxpos+1]; + double c=xcorr[maxpos]; + fraction=(a-b)/(2.*a+2.*b-4.*c); + //cpl_vector_save(vcor,"vcor_correlate.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + cpl_vector_unwrap(vcor); + + //sinfo_msg_warning("STEP_MIN=%d maxpos=%d",STEP_MIN,maxpos); + //sinfo_msg_warning("fraction=%g a=%g b=%g c=%g delta=%g",fraction,a,b,c,0.5*(b-a)); + + (*delta) = (double)STEP_MIN + (double)maxpos; + *delta-=fraction; + //sinfo_msg("fraction=%g a=%g b=%g c=%g diff=%g delta=%g",fraction,a,b,c,0.5*(b-a),*delta); + return xcorr; +} +static cpl_error_code +sinfo_function1d_xcorrelate(cpl_vector* wcorr, cpl_vector* fcorr,SINFO_GAUSSIAN_FIT* gfit,const double range,const int ext) +{ + int size_x; + cpl_table* tab = NULL; + cpl_table* ext_tab; + char fname[256]; + cpl_vector* wave=NULL; + cpl_vector* flux=NULL; + + size_x=cpl_vector_get_size(wcorr); + tab = cpl_table_new(size_x); + cpl_table_wrap_double(tab, cpl_vector_get_data(wcorr), "logwave"); + cpl_table_wrap_double(tab, cpl_vector_get_data(fcorr), "flux"); + + //sprintf(fname, "fcorr_org.fits"); + //sinfo_table_save(tab,NULL,NULL,fname,ext); + cpl_table_and_selected_double(tab, "logwave", CPL_GREATER_THAN, + (*gfit).peakpos - range); + cpl_table_and_selected_double(tab, "logwave", CPL_LESS_THAN, + (*gfit).peakpos + range); + + ext_tab = cpl_table_extract_selected(tab); + cpl_table_unwrap(tab,"logwave"); + cpl_table_unwrap(tab,"flux"); + sinfo_free_table(&tab); + //sprintf(fname, "fcorr_ext.fits"); + //sinfo_table_save(ext_tab,NULL,NULL,fname,ext); + int next = 0; + next = cpl_table_get_nrow(ext_tab); + //sprintf(fname, "fcorr_tab.fits"); + //sinfo_table_save(ext_tab,NULL,NULL,fname,ext); + double peakpos=0; + double sigma=0; + double area=0; + double offset=0; + double mse=0; + + wave = cpl_vector_wrap(next, cpl_table_get_data_double(ext_tab, "logwave")); + flux = cpl_vector_wrap(next, cpl_table_get_data_double(ext_tab, "flux")); + //sinfo_msg("gauss before fit: peak=%g sigma=%g",(*gfit).peakpos,(*gfit).sigma); + + cpl_vector_fit_gaussian( wave, NULL, flux,NULL, CPL_FIT_ALL, + &peakpos, &sigma,&area, &offset, &mse,NULL,NULL); + //sinfo_msg("gauss check fit: peak=%g sigma=%g",peakpos,sigma); + cpl_vector_fit_gaussian( wave, NULL, flux,NULL, CPL_FIT_ALL, + &gfit->peakpos, &gfit->sigma,&gfit->area, &gfit->offset, &gfit->mse,NULL,NULL); + //double fwhm = CPL_MATH_FWHM_SIG * gfit.sigma; + //sinfo_msg("gauss after fit: peak=%g sigma=%g",(*gfit).peakpos,(*gfit).sigma); + + //cleanup: + cpl_vector_unwrap(wave); + cpl_vector_unwrap(flux); + sinfo_free_table(&ext_tab); + return cpl_error_get_code(); +} + + + + +/* perform correlation of spectrum and model over a given range. Correlation peak determination is refined by Gauss fit + * result is the shift to be applied and the FWHM of the correlation function (useful to make 2nd iteration of correlation + * near peak pos) + */ +static cpl_error_code +sinfo_correl_spectra(double* flux_s, double* flux_m, const int size, + const int hsearch, const double wlogstp,const int norm_xcorr, + const double range, const int ext,SINFO_GAUSSIAN_FIT* gfit, int is_refine, cpl_vector ** pfcorr) +{ + double* pwcorr = NULL; + double corr = 0; + double delta=0; + char fname[256]; + int i=0; + double size_corr = 2 * hsearch + 1; + cpl_vector* f1=NULL; + cpl_vector* f2=NULL; + cpl_vector* correl=NULL; + double shift=0; + cpl_vector* wcorr = NULL; + + double * xcorr = NULL; + + check_nomsg(xcorr = sinfo_function1d_xcorrelate2(flux_s, size, flux_m, size, hsearch, + norm_xcorr,&corr, &delta)); + + check_nomsg(f1=cpl_vector_wrap(size, flux_s)); + f2=cpl_vector_wrap(size, flux_m); + //cpl_vector_save(f1,"f1.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + //cpl_vector_save(f2,"f2.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + //sinfo_msg("size=%d",size); + correl=cpl_vector_new(size_corr); + check_nomsg(shift=cpl_vector_correlate(correl,f1,f2)); + + + + + cpl_vector_save(correl,"correl.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + sinfo_msg("shift=%g",shift); + //sinfo_msg("correlation value=%g measured shift[sample units]=%g measured shift[lognm]=%g", corr, delta,delta*); + //sinfo_msg("hsearch=%d delta=%g sampling step=%g",hsearch,delta,wlogstp); + + gfit->peakpos = (hsearch + delta)*wlogstp; + gfit->sigma = wlogstp*10; + gfit->area = 1.; + + sinfo_msg("gauss guess: peak: %12.8g sigma %g", gfit->peakpos, gfit->sigma); + cpl_vector * fcorr = NULL; + check_nomsg(fcorr = cpl_vector_wrap(size_corr, xcorr)); + *pfcorr = fcorr; + /* AMO changed: to remove a leak (next we override values and + * later we do cpl_vector_unwrap + */ + pwcorr= (double*) cpl_calloc(size_corr, sizeof(double)); + for (i = 0; i < size_corr; i++) { + pwcorr[i] = i*wlogstp; + } + + + + check_nomsg(wcorr = cpl_vector_wrap(size_corr, pwcorr)); + //sprintf(fname,"fcorr.fits"); + //xsh_vector_save(fcorr,NULL,fname,ext); + //sprintf(fname,"wcorr.fits"); + //check_nomsg(xsh_vector_save(wcorr,NULL,fname,ext)); + + /* 4) fit Gaussian to +/-0.001 in log_lam_nm around cross correlation peak */ + check_nomsg(sinfo_function1d_xcorrelate(wcorr,fcorr,gfit,range,ext)); + + sinfo_msg("gauss fit: peak[lognm]: %12.8g sigma[lognm] %g peak[sampl_units]: %12.8g sigma[sampl_units] %g", + gfit->peakpos, gfit->sigma,gfit->peakpos/wlogstp, gfit->sigma/wlogstp); + + + cleanup: + cpl_vector_unwrap(f1); + cpl_vector_unwrap(f2); + cpl_vector_unwrap(wcorr); + cpl_vector_delete(correl); + cpl_free(pwcorr); + return cpl_error_get_code(); + +} + +static cpl_error_code +sinfo_star_flux_list_divide( sinfo_star_flux_list * result, + sinfo_star_flux_list * factor) +{ + + SINFO_ASSURE_NOT_NULL( result ) ; + SINFO_ASSURE_NOT_NULL( factor ) ; + /* Create the list */ + + SINFO_ASSURE_NOT_ILLEGAL_MSG(result->size==factor->size,"List of different sizes"); + int size=result->size; + //SINFO_ASSURE_NOT_ILLEGAL_MSG(result->lambda[0]==factor->lambda[0],"List of different wave start"); + //SINFO_ASSURE_NOT_ILLEGAL_MSG(result->lambda[size-1]==factor->lambda[size-1],"List of different wave end"); + + int i=0; + for(i=0;iflux[i] /= factor->flux[i]; + } + + cleanup: + return cpl_error_get_code(); +} + +static double +sinfo_resample_double(double wout,double* pw1,double* pf1,double wmin,double wmax,int size_obs) +{ + + double m=0; + double w1=0; + double w2=0; + double f1=0; + double f2=0; + double fout=0; + + int i=0; + + /* are we in case of extrapolation ? */ + if( wout < wmin ) { + /* w < wmin */ + m=(pf1[1]-pf1[0])/(pw1[1]-pw1[0]); + fout=m*(wout-wmin)+pf1[0]; + } else if ( wout > wmax ) { + /* w > wmax */ + m=(pf1[size_obs-1]-pf1[size_obs-2])/(pw1[size_obs-1]-pw1[size_obs-2]); + fout=m*(wout-wmax)+pf1[size_obs-1]; + + } else { + /* else, interpolate */ + for(i=0;i + */ + cpl_table_add_scalar(*table_mm, "logwave", (gfit.peakpos-hsearch*wlogstp)); + sinfo_msg("computed shift[lognm]=%g",(gfit.peakpos-hsearch*wlogstp)); + + //sinfo_table_save(*table_mm,NULL,NULL,"model_shift.fits",ext); + + /* + 6) create Gaussian with measured FWHM (corrected by FWHM of model spectrum, + but that effect is small since the model spectra have a resolution of 60000, + so the FWHM of the cross-correlation peak is dominated by the observation) + + 7) convolve model with Gaussain in log_lam_nm space (X-shooter has contant lambda/dlambda) + + We apply this operations to the model sub-range corresponding to the spectrum + */ + + /* NB: + * the only eventually allowed filer in cpl_vector_filter_lowpass_create is CPL_LOWPASS_LINEAR + * as CPL_LOWPASS_GAUSSIAN uses a fixed FWHM. Checking result we later preferred to use + * cpl_wlcalib_xc_convolve_create_kernel that is deprecated but gives better results. + * There the FWHM parameter is actually the sigma: FWHM/CPL_MATH_FWHM_SIG + */ + + double* pvlowpass_fluxm = NULL; + double* pflux_c = NULL; + double fwhm = CPL_MATH_FWHM_SIG * gfit.sigma; + double fwhm_nm = pow(CPL_MATH_E, fwhm); + //cpl_vector * spec_clean=NULL; + //int fwhm_pix=(int)(fwhm_nm+0.50000); + int fwhm_pix = (int) (fwhm / wlogstp + 0.5); + + cpl_table_new_column(*table_mm, "flux_c", CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(*table_mm, "flux_c", 0, size_mm, 0); + sinfo_msg("fwhm_nm=%12.10g fwhm_pix=%d",fwhm_nm,fwhm_pix); + + vfluxm = cpl_vector_wrap(size_mm,cpl_table_get_data_double(*table_mm, "flux")); + sinfo_msg_warning("pk5"); + sinfo_print_rec_status(5); + /* we use CPL deprecated function but it works properly */ + conv_kernel = cpl_wlcalib_xc_convolve_create_kernel(fwhm_pix/CPL_MATH_FWHM_SIG,fwhm_pix/CPL_MATH_FWHM_SIG); + vlowpass_fluxm=cpl_vector_duplicate(vfluxm); + cpl_wlcalib_xc_convolve(vlowpass_fluxm, conv_kernel); + sinfo_msg_warning("pk6"); + sinfo_print_rec_status(6); + //vlowpass_fluxm = cpl_vector_filter_lowpass_create(vfluxm, filter_type,fwhm_pix); + + pvlowpass_fluxm = cpl_vector_get_data(vlowpass_fluxm); + cpl_vector_unwrap(vfluxm); + + pflux_c = cpl_table_get_data_double(*table_mm, "flux_c"); + for (i = 0; i < size_mm; i++) { + pflux_c[i] = pvlowpass_fluxm[i]; + } + sprintf(fname, "model_convolved.fits"); + sinfo_table_save(*table_mm,NULL,NULL,fname,ext); + + cleanup: + sinfo_msg_warning("pk7"); + sinfo_print_rec_status(7); + cpl_vector_delete(conv_kernel); + cpl_vector_delete(vlowpass_fluxm); + sinfo_free_table(&table_rs); + sinfo_free_table(&table_rm); + return cpl_error_get_code(); + +} +static HIGH_ABS_REGION * +sinfo_fill_tell_compute_resid_regions( + new_sinfo_band band, + cpl_frame* high_abs_frame) +{ + HIGH_ABS_REGION * phigh=NULL; + int nrow=0; + double* pwmin=0; + double* pwmax=0; + int i=0; + cpl_table* high_abs_tab=NULL; + //XSH_ARM the_arm; + + if(high_abs_frame !=NULL) { + high_abs_tab=cpl_table_load(cpl_frame_get_filename(high_abs_frame),1,0); + } + //the_arm=xsh_instrument_get_arm(instrument); + + + + if(high_abs_tab!=NULL) { + nrow=cpl_table_get_nrow(high_abs_tab); + check_nomsg(pwmin=cpl_table_get_data_double(high_abs_tab,"LAMBDA_MIN")); + check_nomsg(pwmax=cpl_table_get_data_double(high_abs_tab,"LAMBDA_MAX")); + + phigh = (HIGH_ABS_REGION *) cpl_calloc(nrow + 1, sizeof(HIGH_ABS_REGION)); + for(i=0;ilambda_min != 0.; phigh++) { + //sinfo_msg("Flag [%g,%g]",phigh->lambda_min,phigh->lambda_max); + int nrow = cpl_table_and_selected_double(corr, "wave", CPL_NOT_LESS_THAN, + phigh->lambda_min); + //sinfo_msg("Select min=%d",nrow); + nrow = cpl_table_and_selected_double(corr, "wave", CPL_LESS_THAN, + phigh->lambda_max); + //sinfo_msg("Select max=%d",nrow); + tab_tmp = cpl_table_extract_selected(corr); + cpl_table_select_all(corr); + if (counter == 0) { + //sinfo_msg("create stack table nraws=%d",cpl_table_get_nrow(tab_corr)); + tab_stack = cpl_table_duplicate(tab_tmp); + counter++; + } else { + nrow = cpl_table_get_nrow(tab_stack); + //sinfo_msg("append to stack table size=%d",nrow); + cpl_table_insert(tab_stack, tab_tmp, nrow); + } + sinfo_free_table(&tab_tmp); + nsamples++; + } + + } + sprintf(fname, "tab_corr_sampl.fits"); + sinfo_table_save(tab_stack, NULL, NULL, fname, ext); + + *mean = fabs( ( cpl_table_get_column_mean(tab_stack, "correction") - 1. ) ); + *rms = cpl_table_get_column_stdev(tab_stack, "correction"); + + //sinfo_msg("mean=%g rms=%g", *mean, *rms); + sinfo_free_table(&tab_tmp); + sinfo_free_table(&tab_stack); + return cpl_error_get_code(); + +} + + +static cpl_error_code +sinfo_extract_points_to_fit(cpl_table* table,const char* cwav,const char* cratio, + const int nsamples, new_sinfo_band band, + cpl_vector** vec_wave,cpl_vector** vec_flux) +{ + + + double* pvec_wave = NULL; + double* pvec_flux = NULL; + int kh=0; + HIGH_ABS_REGION * phigh = NULL; + cpl_table* tab_tmp=NULL; + double wmin=0; + double wmax=0; + double wstp=1.; + /* + double wmin_fit_region=9999; + double wmax_fit_region=-9999; + */ + + wmin=cpl_table_get_column_min(table,cwav); + wmax=cpl_table_get_column_max(table,cwav); + + *vec_wave = cpl_vector_new(nsamples+2); + *vec_flux = cpl_vector_new(nsamples+2); + + /* + phigh=sinfo_fill_tell_fit_regions(band,NULL); + for (kh = 0; phigh->lambda_min != 0.; phigh++) { + if( wmin_fit_region> phigh->lambda_min) wmin_fit_region=phigh->lambda_min; + if( wmax_fit_region< phigh->lambda_max) wmax_fit_region=phigh->lambda_max; + } + + if(wmax_fit_region>wmax) { + *vec_wave = cpl_vector_new(nsamples+2); + *vec_flux = cpl_vector_new(nsamples+2); + } else { + *vec_wave = cpl_vector_new(nsamples+1); + *vec_flux = cpl_vector_new(nsamples+1); + } + */ + pvec_wave = cpl_vector_get_data(*vec_wave); + pvec_flux = cpl_vector_get_data(*vec_flux); + //sinfo_msg("sk1 nsamples=%d",nsamples); + + // add one point at the start of the wave range + cpl_table_and_selected_double(table, cwav, CPL_LESS_THAN,wmin+wstp); + tab_tmp = cpl_table_extract_selected(table); + pvec_wave[0] = wmin; + //sinfo_msg_warning("wmin=%g",wmin); + pvec_flux[0] = cpl_table_get_column_median(tab_tmp, cratio); + cpl_table_select_all(table); + sinfo_free_table(&tab_tmp); + + phigh=sinfo_fill_tell_fit_regions(band,NULL); + + + if (phigh != NULL) { + //int nrow = 0; + //sinfo_msg("Fill median ratio values" ); + for (kh = 0; phigh->lambda_min != 0.; phigh++) { + sinfo_msg("Process line %d Flag [%g,%g]",kh,phigh->lambda_min,phigh->lambda_max); + cpl_table_and_selected_double(table, cwav, + CPL_NOT_LESS_THAN, phigh->lambda_min); + //sinfo_msg("Select min=%d",nrow); + int nrow=cpl_table_and_selected_double(table, cwav, CPL_LESS_THAN, + phigh->lambda_max); + //sinfo_msg("Select max=%d",nrow); + tab_tmp = cpl_table_extract_selected(table); + cpl_table_select_all(table); + //TODO SINFONI requires this extra check + if(nrow>0) { + + pvec_wave[kh+1] = 0.5 * (phigh->lambda_max + phigh->lambda_min); + pvec_flux[kh+1] = cpl_table_get_column_median(tab_tmp, cratio); + //sinfo_msg_warning("wave=%g",pvec_wave[kh+1]); + //sinfo_msg_warning("flux=%g",pvec_flux[kh+1]); + } else { + sinfo_msg_warning("No data point at wave=%g",phigh->lambda_max); + } + kh++; + sinfo_free_table(&tab_tmp); + } + } + + /* + if(wmax_fit_region>wmax) { + cpl_table_select_all(table); + + cpl_table_and_selected_double(table, cwav, CPL_NOT_LESS_THAN,wmax-wstp); + tab_tmp = cpl_table_extract_selected(table); + + pvec_wave[kh+1] = wmax; + sinfo_msg("wave=%g",pvec_wave[kh+1]); + check_nomsg(pvec_flux[kh+1] = cpl_table_get_column_median(tab_tmp, cratio)); + cpl_table_delete(tab_tmp); + } + */ + + + cpl_table_select_all(table); + + cpl_table_and_selected_double(table, cwav, CPL_NOT_LESS_THAN,wmax-wstp); + tab_tmp = cpl_table_extract_selected(table); + + pvec_wave[kh+1] = wmax; + pvec_flux[kh+1] = cpl_table_get_column_median(tab_tmp, cratio); + //sinfo_msg_warning("wmax=%g",wmax); + //cpl_table_save(tab_tmp,NULL,NULL,"tab_tmp.fits",CPL_IO_DEFAULT); + //cpl_vector_dump(vec_wave,stdout); + //cpl_vector_save(*vec_wave,"vec_wave.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + //cpl_vector_save(*vec_flux,"vec_flux.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + sinfo_free_table(&tab_tmp); + + + //cleanup: + + return cpl_error_get_code(); +} + + + +static cpl_table* +sinfo_extract_ranges_to_fit(cpl_table* table_in,const char* cwav,new_sinfo_band band) { + + cpl_table* stack = NULL; + HIGH_ABS_REGION * phigh = NULL; + + phigh = sinfo_fill_tell_compute_resid_regions(band, NULL); + + cpl_table* tab_tmp = NULL; + int nsamples = 0; + /* + cpl_table_dump(table_in,0,2,stdout); + sinfo_msg("wmin=%g wmax=%g", + cpl_table_get_column_min(table_in,cwav), + cpl_table_get_column_max(table_in,cwav)); + */ + /* we remove from table points that should not be sampled */ + if (phigh != NULL) { + int counter = 0; + //int kh = 0; + int nrow = 0; + //sinfo_msg("Extract from ratio only regions to be sampled" ); + for (; phigh->lambda_min != 0.; phigh++) { + //sinfo_msg("Flag [%g,%g]",phigh->lambda_min,phigh->lambda_max); + check_nomsg(nrow = cpl_table_and_selected_double(table_in, cwav, CPL_NOT_LESS_THAN, + phigh->lambda_min)); + //sinfo_msg("Select min=%d",nrow); + check_nomsg(nrow = cpl_table_and_selected_double(table_in,cwav, CPL_LESS_THAN, + phigh->lambda_max)); + //sinfo_msg("Select max=%d",nrow); + check_nomsg(tab_tmp = cpl_table_extract_selected(table_in)); + cpl_table_select_all(table_in); + if (counter == 0) { + //sinfo_msg("create stack table"); + stack = cpl_table_duplicate(tab_tmp); + counter++; + } else { + nrow=cpl_table_get_nrow(stack); + //sinfo_msg("append to stack table size=%d",nrow); + cpl_table_insert(stack, tab_tmp, nrow); + } + sinfo_free_table(&tab_tmp); + nsamples++; + } + } + sinfo_free_table(&tab_tmp); + + cleanup: + return stack; +} + +static cpl_table* +sinfo_table_resample_table(cpl_table* tinp,const char* cwinp, const char* cfinp, + cpl_table* tref,const char* cwref, const char* cfref) +{ + + cpl_table* tres=NULL; + double* pwinp=NULL; + double* pwref=NULL; + double* pfinp=NULL; + double* pfres=NULL; + int size_inp=0; + int size_ref=0; + double wmin=0; + double wmax=0; + int i=0; + + check_nomsg(size_inp=cpl_table_get_nrow(tinp)); + check_nomsg(size_ref=cpl_table_get_nrow(tref)); + //sinfo_msg("cwinp=%s",cwinp); + check_nomsg(wmin=cpl_table_get_column_min(tinp,cwinp)); + check_nomsg(wmax=cpl_table_get_column_max(tinp,cwinp)); + //sinfo_msg("wmin=% vag wmax=%g",wmin,wmax); + + /* we first duplicate ref to resampled table to have the same wavelength + sampling and then we take care of computing the flux */ + tres=cpl_table_duplicate(tref); + check_nomsg(pwinp=cpl_table_get_data_double(tinp,cwinp)); + check_nomsg(pwref=cpl_table_get_data_double(tref,cwref)); + + check_nomsg(pfinp=cpl_table_get_data_double(tinp,cfinp)); + check_nomsg(pfres=cpl_table_get_data_double(tres,cfref)); + + for(i=0;ilambda_min != 0.; phigh++) { + nsamples++; + } + + check_nomsg(name_model=cpl_frame_get_filename(frame_m)); + //sinfo_msg_warning("name_model=%s",name_model); + //cpl_frame_set_type(frame_m,CPL_FRAME_TYPE_TABLE); + check_nomsg(next=cpl_frame_get_nextensions(frame_m)); + check_nomsg(tab_res=cpl_table_new(next)); + cpl_table_new_column(tab_res,"id",CPL_TYPE_INT); + cpl_table_new_column(tab_res,"mean",CPL_TYPE_DOUBLE); + cpl_table_new_column(tab_res,"rms",CPL_TYPE_DOUBLE); + + + + cpl_table_fill_column_window_int(tab_res, "id", 0, next, 0); + cpl_table_fill_column_window_double(tab_res, "mean", 0, next, 0); + cpl_table_fill_column_window_double(tab_res, "rms", 0, next, 0); + pext=cpl_table_get_data_int(tab_res,"id"); + pmean=cpl_table_get_data_double(tab_res,"mean"); + prms=cpl_table_get_data_double(tab_res,"rms"); + + //sinfo_msg("name_model %s",name_model); + for (ext = 0; ext < next; ext++) { + + + /* load input model spectrum from appropriate extension */ + check_nomsg(table_m = cpl_table_load(name_model, ext+1, 1)); + sprintf(fname,"tell_model_org.fits"); + check_nomsg(sinfo_table_save(table_m,NULL,NULL,fname,ext)); + + /* the model wavelength are in um units, we need to convert to nm */ + cpl_table_multiply_scalar(table_m, "lam", um2nm); + cpl_table_duplicate_column(table_m, "logwave", table_m, "lam"); + cpl_table_logarithm_column(table_m, "logwave", CPL_MATH_E); + sprintf(fname,"tell_model_res_nm.fits"); + check_nomsg(sinfo_table_save(table_m,NULL,NULL,fname,ext)); + + /* we restrict model to range covered by observation */ + sinfo_msg_warning("restrict wavelength to %g %g",wmin,wmax); + //if(band == INSTRUMENT_BAND_J) { + table_mm=sinfo_table_select_range(table_m,"lam",wmin, wmax); + //} else { + // table_mm=cpl_table_duplicate(table_m); + //} + sinfo_free_table(&table_m); + //size_mm = cpl_table_get_nrow(table_mm); + sprintf(fname,"tell_model_range_arm.fits"); + check_nomsg(sinfo_table_save(table_mm,NULL,NULL,fname,ext)); + + /* Step 2: extract the proper ranges for cross correlation */ + /* Apply this to the model */ + sinfo_msg_warning("select log wave to lmin=%g lmax=%g",lmin,lmax); + //if(band == INSTRUMENT_BAND_J) { + table_me=sinfo_table_select_range(table_mm,"logwave",lmin, lmax); + //} else { + // table_me=cpl_table_duplicate(table_mm); + //} + + /* make a test to verify that exponential of log comes back the same + as original wave column value + check_nomsg(cpl_table_duplicate_column(table_me,"wav",table_me,"logwave")); + check_nomsg(cpl_table_exponential_column(table_me,"wav",CPL_MATH_E)); + */ + sprintf(fname,"tell_model_selected_wrange_log.fits"); + check_nomsg(sinfo_table_save(table_me,NULL,NULL,fname,ext)); + + check_nomsg(sinfo_table_save(table_s,NULL,NULL,"table_s.fits",ext)); + + /* Apply this to the spectrum */ + /* + sinfo_msg_warning("monitor wmin=%g wmax=%g", + cpl_table_get_column_min(table_s,"logwave"), + cpl_table_get_column_min(table_s,"logwave")); + */ + + //if(band == INSTRUMENT_BAND_J) { + table_se=sinfo_table_select_range(table_s,"logwave",lmin, lmax); + //} else { + // table_se=cpl_table_duplicate(table_s); + //} + cpl_table_duplicate_column(table_se, "wav", table_se, "logwave"); + cpl_table_exponential_column(table_se, "wav", CPL_MATH_E); + sprintf(fname,"spectrum_selected_wrange_log.fits"); + check_nomsg(sinfo_table_save(table_se,NULL,NULL,fname,ext)); + + /* Step 3: now we need to do the cross-correlation: + Before doing this we need to be sure that each spectrum is sampled + to the same point. We use the model as reference and re-sample (linearly) + the observed spectrum so that we can then compute the cross-correlation + + Step 4: fit Gaussian to +/-0.001 in log_lam_nm around cross correlation peak + + Step 5: adjust model wavelength scale: + :log_lam_nm_0 = :log_lam_nm+ + + + 6) create Gaussian with measured FWHM (corrected by FWHM of model spectrum, + but that effect is small since the model spectra have a resolution of 60000, + so the FWHM of the cross-correlation peak is dominated by the observation) + + 7) convolve model with Gaussain in log_lam_nm space (X-shooter has contant lambda/dlambda) + + We apply this operations to the model sub-range corresponding to the spectrum + */ + //sinfo_msg("size of model tab=%d",(int)cpl_table_get_nrow(table_me)); + //sinfo_msg("size of spectrum tab=%d",(int)cpl_table_get_nrow(table_se)); + //check_nomsg(sinfo_table_save(table_me,NULL,NULL,"table_me.fits",ext)); + check_nomsg(sinfo_table_save(table_se,NULL,NULL,"table_se.fits",ext)); + if( (band == INSTRUMENT_BAND_J) || + (band == INSTRUMENT_BAND_H) || + (band == INSTRUMENT_BAND_K) || + (band == INSTRUMENT_BAND_HK) || + (band == INSTRUMENT_BAND_UVB) || + (band == INSTRUMENT_BAND_VIS) || + (band == INSTRUMENT_BAND_NIR) || + (band == INSTRUMENT_BAND_ALL)) { + check_nomsg(sinfo_align_model_to_spectrum(table_me,table_se,wlogstp,norm_xcorr,ext,&table_mm)); + } else { + cpl_table_duplicate_column(table_mm,"flux_c",table_mm,"flux"); + } + + sinfo_free_table(&table_me); + sinfo_free_table(&table_se); + + check_nomsg(sinfo_table_save(table_mm,NULL,NULL,"model_shift.fits",ext)); + + /* + 8) convert convolved and shifted model to lam_nm space + */ + + check_nomsg(cpl_table_duplicate_column(table_mm,"wave",table_mm,"logwave")); + check_nomsg(cpl_table_exponential_column(table_mm,"wave",CPL_MATH_E)); + sprintf(fname,"model_aligned_to_obs.fits"); + + //check_nomsg(sinfo_table_save(table_mm,NULL,NULL,fname,ext)); + + /* + 9) divide observed spectrum by convolved and shifted model + Here we get a telluric-corrected observed spectrum + */ + sinfo_free_table(&table_rs); + + sinfo_free_table(&table_rm); + /* In order to divide spectrum by model we need to put them on same sampling steps: + * If we re-sample the model to the coarser spectrum step we introduce artifacts in the re-sampled model spectrum + * Better is to up-sample the observed spectrum to the model. This simply artificially refine the observed spectrum + */ + + /* NOTE THAT WE NEED table_rpfitm at the very end of this function when we downsample table_rs */ + + //TODO: this part seems weird, we need to clarify it, why are we sampling + //table_mm to follow table_s but then we sample table_s to follow table_mm? + + check_nomsg(sinfo_table_save(table_mm,NULL,NULL,"table_mm_before_res.fits",ext)); + + check_nomsg(table_rm = sinfo_table_resample_table(table_mm,"wave","flux",table_s,"wavelength","flux")); + sprintf(fname,"table_rm.fits"); + check_nomsg(sinfo_table_save(table_rm,NULL,NULL,fname,ext)); + + check_nomsg(sinfo_table_save(table_rm,NULL,NULL,"table_rm_after_res.fits",ext)); + + check_nomsg(table_rs=sinfo_table_resample_table(table_s,"wavelength","flux",table_mm,"wave","flux")); + + //PIPPO + sprintf(fname,"spectrum_resampled_to_model.fits"); + check_nomsg(sinfo_table_save(table_rs,NULL,NULL,fname,ext)); + + cpl_table_duplicate_column(table_rs, "flux_model_convolved", table_mm, "flux_c"); + cpl_table_duplicate_column(table_rs, "ratio", table_rs, "flux"); + sinfo_free_table(&table_mm); + check_nomsg(cpl_table_divide_columns(table_rs,"ratio","flux_model_convolved")); + /* NB: the ratio spectrum corresponding to the model that minimizes + the resisiduals is actually the final product we need to use for + the final response computation */ + + sprintf(fname,"spectrum_observed_divided_by_model_convolved.fits"); + check_nomsg(sinfo_table_save(table_rs,NULL,NULL,fname,ext)); + + sprintf(fname,"spectrum_observed_divided_by_model_convolved_ALL.fits"); + check_nomsg(sinfo_table_save(table_rs,NULL,NULL,fname,ext)); + + table_rs_div_mc=cpl_table_duplicate(table_rs); + /* + 10) use predefined continuum points (avoiding regions of strong + telluric absorption as well as known stellar lines) and fit spline + without smoothing + + (points.list, email from Sabine). + Take around each of them +/- 1nm. + take the median in the range [-1nm+wc,wc+1nm] + and then fit a spline (order 3: cubic) + No smoothing + This gives the continuum fit + */ + + check_nomsg(tab_stack=sinfo_extract_ranges_to_fit(table_rs,"wave",band)); + sprintf(fname,"tab_stack.fits"); + + //check_nomsg(sinfo_table_save(tab_stack,NULL,NULL,fname,ext)); + + /* here we make the spline fit of median flux computed in each range + * (to rule out that oscillations in each range creates problems) + * */ + + cpl_vector* vec_wave = NULL; + cpl_vector* vec_flux = NULL; + //double* pwav=NULL; + + check_nomsg(sinfo_table_save(table_rs,NULL,NULL,"table_rs.fits",ext)); + check_nomsg(sinfo_extract_points_to_fit(table_rs,"wave","ratio",nsamples,band,&vec_wave,&vec_flux)); + + //pwav = cpl_table_get_data_double(table_rm, "wave"); + double* sfit=NULL; + double* pfit=NULL; + //double* pwave=NULL; + //cpl_vector_dump(vec_wave,stdout); + //cpl_vector_dump(vec_flux,stdout); + + /* + + double* pflux=NULL; + + sprintf(fname,"ratio_sel.fits"); + check_nomsg(sinfo_table_save(tab_stack,NULL,NULL,fname,ext)); + */ + int nsel = 0; + + check_nomsg(nsel=cpl_table_get_nrow(tab_stack)); + cpl_table_new_column(tab_stack, "fit", CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(tab_stack, "fit", 0, nsel, 0); + pfit = cpl_table_get_data_double(tab_stack, "fit"); + //pwave = cpl_table_get_data_double(tab_stack, "wave"); + + /* + + + pwav = cpl_table_get_data_double(tab_stack, "wave"); + pflux = cpl_table_get_data_double(tab_stack, "ratio"); + vflux=cpl_vector_wrap(size_mm,pflux); + vflux_med=cpl_vector_filter_median_create(vflux,15); + sinfo_msg("size_mm=%d",size_mm); + sprintf(fname,"flux_med.fits"); + cpl_vector_save(vflux_med,fname,CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + mflux=cpl_vector_get_data(vflux_med); + + */ + + /* here we perform the actual fit: we pass now the median points via: + * vec_wave,pvec_flux,nsamples params + * + * To fit each point in each fit window region we would instead pass + * pwav,pflux,nsel params + * + */ + + double* pvec_wave=NULL; + double* pvec_flux=NULL; + pvec_wave=cpl_vector_get_data(vec_wave); + pvec_flux=cpl_vector_get_data(vec_flux); + if(ext == 64){ + cpl_vector_save(vec_wave,"papero.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + cpl_vector_save(vec_flux,"FluxSelected.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + } + //sinfo_msg("Max wave=%g",cpl_vector_get_max(vec_wave)); + + //sfit = xsh_bspline_fit_data2(pvec_wave, pvec_flux, nsamples, phigh,instrument, 1); + + //TODO: we need to clarify this, why this interpolation and then a similar + //one below? + check_nomsg(sfit = sinfo_bspline_interpolate_data_at_pos(pvec_wave, pvec_flux, nsamples+2, + pvec_wave,nsamples+2)); + + //sinfo_msg("Max wave=%g",cpl_vector_get_max(vec_wave)); + + //cpl_vector_delete(vflux_med); + //cpl_vector_unwrap(vflux); + int i=0; + /* this instruction is to fill the fit column in table tab_stack with result of the fit + for(i=0;iwguess = 486.1322; + w->range_wmin=450; + w->range_wmax=550; + w->ipol_wmin_max=470; + w->ipol_wmax_min=500; + w->ipol_hbox=0.5; + + break; + case INSTRUMENT_BAND_VIS: + w->wguess= 656.2793; + w->range_wmin=640; + w->range_wmax=670; + w->ipol_wmin_max=653; + w->ipol_wmax_min=661; + w->ipol_hbox=1.5; + + break; + case INSTRUMENT_BAND_NIR: + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + cpl_msg_warning("", "NIIIIR"); + break; + case INSTRUMENT_BAND_ALL: + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + cpl_msg_warning("", "SYNTHETIC"); + break; + case INSTRUMENT_BAND_J: + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + cpl_msg_warning("", "JJJJJJ"); + break; + + case INSTRUMENT_BAND_H: + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + break; + + case INSTRUMENT_BAND_K: + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + break; + + case INSTRUMENT_BAND_HK: + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + break; + + default : + w->wguess= 1094.12; + w->range_wmin=1000; + w->range_wmax=1200; + w->ipol_wmin_max=1090; + w->ipol_wmax_min=1100; + w->ipol_hbox=1.5; + break; + } + + return cpl_error_get_code(); +} + +static sinfo_rv_ref_wave_param * sinfo_rv_ref_wave_param_create(void){ + + sinfo_rv_ref_wave_param * self = cpl_malloc(sizeof(sinfo_rv_ref_wave_param)); + self->wguess=999.; /* Reference line wavelength position */ + self->range_wmin=999.; /* minimum of wavelength box for line fit */ + self->range_wmax=999.; /* maximum of wavelength box for line fit */ + self->ipol_wmin_max=999.; /* maximum lower sub-range wavelength value used to fit line slope */ + self->ipol_wmax_min=999.; /* minimum upper sub-range wavelength value used to fit line slope */ + + return self; +} + +static cpl_error_code +sinfo_std_star_spectra_to_vector_range(sinfo_star_flux_list * obs_std_star_list, + const double wmin, + const double wmax, + cpl_vector** vec_wave, + cpl_vector** vec_flux) +{ + double* pwave_in=NULL; + double* pflux_in=NULL; + + double* pwave_ou=NULL; + double* pflux_ou=NULL; + + int size=0; + int i=0; + int k=0; + + pwave_in=obs_std_star_list->lambda; + pflux_in=obs_std_star_list->flux; + size=obs_std_star_list->size; + + *vec_wave=cpl_vector_new(size); + *vec_flux=cpl_vector_new(size); + pwave_ou=cpl_vector_get_data(*vec_wave); + pflux_ou=cpl_vector_get_data(*vec_flux); + /* + sinfo_msg_warning("ek3 wmin=%g wmax=%g pwave: min=%g max=%g", + wmin,wmax,pwave_in[0],pwave_in[size-1]); + */ + + for(i=0;i=wmin && pwave_in[i]<= wmax) { + pwave_ou[k]=pwave_in[i]; + pflux_ou[k]=pflux_in[i]; + k++; + } + } + cpl_vector_set_size(*vec_wave,k); + cpl_vector_set_size(*vec_flux,k); + + return cpl_error_get_code(); +} + + +static cpl_polynomial * +sinfo_polynomial_fit_1d_create( + const cpl_vector * x_pos, + const cpl_vector * values, + int degree, + double * mse + ) +{ + cpl_polynomial * fit1d = cpl_polynomial_new(1); +// cpl_vector* x_copy = cpl_vector_duplicate(x_pos); +// cpl_vector* values_copy = cpl_vector_duplicate(values); + int x_size = cpl_vector_get_size(x_pos); + double rechisq = 0; + cpl_size loc_deg=(cpl_size)degree; + cpl_matrix * samppos = cpl_matrix_wrap(1, x_size, + (double*)cpl_vector_get_data_const(x_pos)); + cpl_vector * fitresidual = cpl_vector_new(x_size); + + cpl_polynomial_fit(fit1d, samppos, NULL, values, NULL, + CPL_FALSE, NULL, &loc_deg); + cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL); + + if ( x_size > (degree + 1) ) { + cpl_vector_fill_polynomial_fit_residual(fitresidual, values, NULL, fit1d, + samppos, &rechisq); + cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), NULL); + } + if (mse) + { + *mse = cpl_vector_product(fitresidual, fitresidual) + / cpl_vector_get_size(fitresidual); + } + cpl_matrix_unwrap(samppos); + cpl_vector_delete(fitresidual); + return fit1d; +} + + + +/* + @brief generates a vector of values defined at each input wave pos that is a linear fit of values in range + (wave[0],wmin_max)---(wmax_min,wave[max]) + @param vec_wave wave data + @param vec_flux flux data + @param wmin_max max value of start wave range up to which use data for fit of continuum + @param wmax_min min value of final wave range from which use data for fit of continuum + @return fit of continuum data vector + * */ +static cpl_vector* +sinfo_vector_fit_slope(cpl_vector* vec_wave,cpl_vector* vec_flux, + const double wmin_max,const double wmax_min, + const int degree) +{ + cpl_vector* vec_slope=NULL; + int i=0; + int size=0; + int k=0; + double* pwave=NULL; + double* pflux=NULL; + double* pslope=NULL; + double* pvec_x=NULL; + double* pvec_y=NULL; + double mse=0; + cpl_polynomial* pfit=NULL; + + cpl_vector* vec_x=NULL; + cpl_vector* vec_y=NULL; + + /* input parameters consistency checks */ + cpl_ensure(vec_wave,CPL_ERROR_NULL_INPUT,NULL); + cpl_ensure(vec_flux,CPL_ERROR_NULL_INPUT,NULL); + cpl_ensure(wmin_max0 && degree < 3,CPL_ERROR_INCOMPATIBLE_INPUT,NULL); + + /* extract from vector values that are supposed to follow linear relation */ + size=cpl_vector_get_size(vec_flux); + vec_x=cpl_vector_new(size); + vec_y=cpl_vector_new(size); + pwave=cpl_vector_get_data(vec_wave); + pflux=cpl_vector_get_data(vec_flux); + pvec_x=cpl_vector_get_data(vec_x); + pvec_y=cpl_vector_get_data(vec_y); + + for(i=0;i= wmax_min ) { + pvec_x[k]=pwave[i]; + pvec_y[k]=pflux[i]; + k++; + } + } + + cpl_vector_set_size(vec_x,k); + cpl_vector_set_size(vec_y,k); + + cpl_msg_warning("", "SELECTION: %f %f", wmin_max, wmax_min); + + /* makes linear fit */ + pfit=sinfo_polynomial_fit_1d_create(vec_x,vec_y,degree,&mse); + + /* define results */ + vec_slope=cpl_vector_new(size); + pslope=cpl_vector_get_data(vec_slope); + for(i=0;i=(wguess-wrange) && + pwave[i]<=(wguess+wrange) ) { + + pxfit[k]=pwave[i]; + pyfit[k]=pflux[i]; + k++; + } + } + check_nomsg(cpl_vector_set_size(*xfit,k)); + check_nomsg(cpl_vector_set_size(*yfit,k)); + + cleanup: + return cpl_error_get_code(); +} + +/*---------------------------------------------------------------------------*/ +/** + * @brief Sort an array @a u1 of doubles, and permute an array @a u2 + * in the same way as @a u1 is permuted. + * @param[in,out] u1 Pointer to the first array. + * @param[in,out] u2 Pointer to the second array. + * @param n The common length of both arrays. + * + * @return @c CPL_ERROR_NONE or the appropriate error code. + * + */ +/*---------------------------------------------------------------------------*/ +static cpl_error_code sinfo_sort_double_pairs(double *u1, double *u2, cpl_size n) +{ + cpl_vector * biu1=NULL; + cpl_vector * biu2=NULL; + cpl_bivector * bi_all=NULL; + + if (n < 1) + return cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(u1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(u2 != NULL, CPL_ERROR_NULL_INPUT); + + + biu1=cpl_vector_wrap(n,u1); + biu2=cpl_vector_wrap(n,u2); + + bi_all=cpl_bivector_wrap_vectors(biu1, biu2); + cpl_bivector_sort(bi_all,bi_all, CPL_SORT_ASCENDING,CPL_SORT_BY_X); + + + /* cleaning up */ + + cpl_bivector_unwrap_vectors(bi_all); + cpl_vector_unwrap(biu1); + cpl_vector_unwrap(biu2); + + return CPL_ERROR_NONE; +} + +static double +sinfo_std_star_spectra_correlate(sinfo_star_flux_list * obs_std_star_list, + sinfo_star_flux_list * ref_std_star_list,sinfo_rv_ref_wave_param* w) + +{ + + double wave_shift = 0; + int naxis1 = 0; + double wstep = 0; + double wmin = 0; + double wmax = 0; + + /* + double* prw = 0; + double* prf = 0; + double* pow = 0; + double* pof = 0; + double* pvrf = 0; + double* pvof = 0; + */ + //double* pvrw = 0; + + //double* pvow = 0; + + double hbox_wave=0.5; + int hbox = (int)(hbox_wave/wstep+0.5); + //int hbox = 500; + + + int i=0; + /* + int k=0; + int box=2*hbox+1; + int size=0; + */ + //UFFA + + sinfo_msg_warning("ck0 obs_std_star_list=%p",obs_std_star_list); + sinfo_msg_warning("ck0 obs_std_star_list header=%p",obs_std_star_list->header); + //cpl_propertylist_dump(obs_std_star_list->header,stdout); + sinfo_print_rec_status(0); + naxis1 = sinfo_pfits_get_naxis1(obs_std_star_list->header); + wstep = sinfo_pfits_get_cdelt1(obs_std_star_list->header); + //wmin = sinfo_pfits_get_crval1(obs_std_star_list->header); + + //wmax = wmin + naxis1 * wstep; + //wmin=w->wguess-hbox*wstep; + //wmax=w->wguess+(hbox+1)*wstep; + + //sinfo_msg("hbox=%d",hbox); + /* wrap the observed std star spectrum into a vector */ + cpl_vector* vec_wave_obs = NULL; + cpl_vector* vec_flux_obs = NULL; + cpl_vector* vec_slope_obs=NULL; + cpl_vector* correl=NULL; + + /* we first extract the relevant wavelength range used for cross correlation, covering just one line */ + wmin=w->range_wmin; + wmax=w->range_wmax; + //sinfo_msg("wmin=%g wmax=%g",wmin,wmax); + + sinfo_std_star_spectra_to_vector_range(obs_std_star_list,wmin,wmax,&vec_wave_obs,&vec_flux_obs); + + /* + check_nomsg(cpl_vector_save(vec_flux_obs,"vec_flux_obs.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + check_nomsg(cpl_vector_save(vec_flux_ref,"vec_flux_ref.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + */ + + /* we fit a slope (or parabola) on the flat region of the spectrum */ + double wmin_max=w->ipol_wmin_max; + double wmax_min=w->ipol_wmax_min; + //sinfo_msg("wmin_max=%g wmax_min=%g",wmin_max,wmax_min); + vec_slope_obs=sinfo_vector_fit_slope(vec_wave_obs,vec_flux_obs,wmin_max,wmax_min,2); + + + check_nomsg(cpl_vector_save(vec_flux_obs,"vec_flux_obs.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + check_nomsg(cpl_vector_save(vec_slope_obs,"vec_slope_obs.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + + + /* we divide the spectrum by the slope */ + cpl_vector_divide(vec_flux_obs,vec_slope_obs); + + cpl_vector_delete(vec_slope_obs); + + cpl_vector_add_scalar(vec_flux_obs,2); + + check_nomsg(cpl_vector_save(vec_flux_obs,"vec_slope_obs_divided.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + + /* + check_nomsg(cpl_vector_save(vec_flux_obs,"vec_flux_obs_corr.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + check_nomsg(cpl_vector_save(vec_flux_ref,"vec_flux_ref_corr.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + check_nomsg(cpl_vector_save(vec_wave_obs,"vec_wave_obs.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + check_nomsg(cpl_vector_save(vec_wave_ref,"vec_wave_ref.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + + */ + + /* at this points both line spectra (on ref std star and on observed std) have same ranges and a "continuum" */ + + /* we now restrict to the line core to limit the effects introduced by the wide line wings */ + + double wave_range=w->ipol_hbox; + cpl_vector* xfit_obs=NULL; + cpl_vector* yfit_obs=NULL; + //cpl_vector* xfit_ref=NULL; + //cpl_vector* yfit_ref=NULL; + double* pxfit=NULL; + double* pyfit=NULL; + /* + double* pwave=NULL; + double* pflux=NULL; + */ + + sinfo_select_line_core(vec_wave_obs,vec_flux_obs,w->wguess,wave_range,&xfit_obs,&yfit_obs); + + + check_nomsg(cpl_vector_save(yfit_obs,"vec_slope_obs_divided_selected.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + + + /* + cpl_vector_save(xfit_obs,"xfit_obs.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + cpl_vector_save(yfit_obs,"yfit_obs.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + */ + // sinfo_select_line_core(vec_wave_ref,vec_flux_ref,w->wguess,wave_range,&xfit_ref,&yfit_ref); + + /* + cpl_vector_save(xfit_ref,"xfit_ref.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + cpl_vector_save(yfit_ref,"yfit_ref.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + */ + /* + cpl_vector_delete(vec_flux_obs); + cpl_vector_delete(vec_wave_obs); + */ + + /* + double ymax_obs=0; + double ymax_ref=0; + k=cpl_vector_get_size(yfit_obs); + pflux=cpl_vector_get_data(yfit_obs); + ymax_obs=(pflux[0] <= pflux[k-1]) ? pflux[0] : pflux[k-1]; + + k=cpl_vector_get_size(yfit_ref); + pflux=cpl_vector_get_data(yfit_ref); + ymax_ref=(pflux[0] <= pflux[k-1]) ? pflux[0] : pflux[k-1]; + */ + /* + int size_x=k; + int size_x_ref=0; + */ + int size_x_obs=0; + /* we now make sure to have a symmetric distribution (because later we get the fit-centroid) + sinfo_line_balance(&xfit_ref,&yfit_ref,ymax_ref); + pwave=cpl_vector_get_data(xfit_ref); + pflux=cpl_vector_get_data(yfit_ref); + + k=0; + for(i=0;i>>k=%d ymax_obs=%g",k,ymax_obs); + check_nomsg(cpl_vector_set_size(xfit_obs,k)); + check_nomsg(cpl_vector_set_size(yfit_obs,k)); + + size_x_obs=k; + */ + + + /* here we try to do median smoothing to have better fit */ + //cpl_vector* yfit_obs_med=cpl_vector_filter_median_create(yfit_obs,3); + //check_nomsg(cpl_vector_save(yfit_obs_med,"yfit_obs_med.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + + /* because lines cross correlation is not very accurate, here we try to make a poly (parabola)lation + * fit to have more robust min determination */ + cpl_polynomial* poly_fit_obs=NULL; + + double mse=0; + double* pindex=NULL; + poly_fit_obs=sinfo_polynomial_fit_1d_create(xfit_obs,yfit_obs,4,&mse); + //sinfo_msg("mse=%g",mse); + cpl_vector* yfit_pol_obs=NULL; + cpl_vector* yfit_index=NULL; + size_x_obs=cpl_vector_get_size(xfit_obs); + yfit_pol_obs=cpl_vector_new(size_x_obs); + yfit_index=cpl_vector_new(size_x_obs); + check_nomsg(pyfit=cpl_vector_get_data(yfit_pol_obs)); + check_nomsg(pxfit=cpl_vector_get_data(xfit_obs)); + check_nomsg(pindex=cpl_vector_get_data(yfit_index)); + + for(i=0;iwguess; + cpl_msg_warning("", "POSSSS guess: %g obs: %10.8g Pos ref: %10.8g diff=%10.8g", + w->wguess,peakpos_obs,peakpos_ref,peakpos_obs-peakpos_ref); + + sinfo_msg("Now compute shift by spectra correlation"); + + //PIPPO + /* WE DECIDED NOT TO FIT THE MODEL FOR RV COMPUTATION, ONLY THE OBJECT AND TO MAKE A POLY FIT + * BECAUSE THE FOLLOWING WAS NOT VERY ACCURATE: IN ANY CASE ONE WOULD HAVE TO FIT A GAUUSS TO + * THE CORRELATION MAX + * + + cpl_vector* flux_obs_fine=NULL; + cpl_vector* flux_ref_fine=NULL; + + flux_obs_fine=xsh_vector_upsample(vec_flux_obs,10); + flux_ref_fine=xsh_vector_upsample(vec_flux_ref,10); + cpl_vector_save(flux_obs_fine,"flux_obs_fine.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + cpl_vector_save(flux_ref_fine,"flux_ref_fine.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + + cpl_size shift=0; + hbox=5000; + hbox=cpl_vector_get_size(vec_flux_ref); + correl=cpl_vector_new(2*hbox+1); + + check_nomsg(shift=cpl_vector_correlate(correl,vec_flux_obs,vec_flux_ref)); + //UFFA + cpl_vector_save(correl,"correl.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + + double* flux_o =cpl_vector_get_data(flux_obs_fine); + double* flux_r =cpl_vector_get_data(flux_ref_fine); + int width_i=2*hbox+1; + int width_t=2*hbox+1; + int half_search=(int)(0.5*hbox+1); + double delta=0; + double corr=0; + double* xcorr=NULL; + + + XSH_GAUSSIAN_FIT gfit; + int size_o=0; + size_o = cpl_vector_get_size(flux_obs_fine); + double step=(wmax-wmin)/size_o; + + check_nomsg(sinfo_correl_spectra(flux_o,flux_r,size_o,hbox,step,0.1,0,&gfit)); + + sinfo_msg("sigma=%g",gfit.sigma); + sinfo_msg("computed shift[lognm]=%g",(gfit.peakpos-hbox*step)); + + hbox=(int)3.*CPL_MATH_FWHM_SIG * gfit.sigma/step; + sinfo_msg("hsearch=%d",hbox); + check_nomsg(xsh_correl_spectra(flux_o,flux_r,size_o,hbox,step,0.1,0,&gfit)); + + + + + //check_nomsg(xcorr=xsh_function1d_xcorrelate(line_i,width_i,line_t,width_t,half_search,0,&corr,&delta)); + //cpl_vector_save(xcorr,"xcorr.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT); + sinfo_msg("RV corr=%g delta=%g shift=%g",corr,delta,delta*wstep); + + xsh_free(xcorr); + */ + /* + check_nomsg(correl_max=cpl_vector_get_max(correl)); + sinfo_msg("correl_max=%g",correl_max); + check_nomsg(correl_pos=cpl_vector_find(correl,correl_max)); + sinfo_msg("correl: shift=%d max=%g val(shift)=%g pos=%d", + (int)shift,correl_max,cpl_vector_get(correl,shift+1),(int)correl_pos); + wave_shift=delta*wstep; + */ + wave_shift=peakpos_obs-peakpos_ref; + //check_nomsg(cpl_vector_save(correl,"correl.fits",CPL_BPP_IEEE_FLOAT,NULL,CPL_IO_DEFAULT)); + + cleanup: + + cpl_vector_delete(yfit_pol_obs); + cpl_vector_delete(xfit_obs); + cpl_vector_delete(yfit_obs); + //cpl_vector_delete(xfit_ref); + //cpl_vector_delete(yfit_ref); + cpl_vector_delete(vec_wave_obs); + cpl_vector_delete(vec_flux_obs); + cpl_vector_delete(correl); + + return wave_shift; +} + +static cpl_table* +sinfo_table_shift_rv(cpl_table* orig, const char* col_wave,const double offset) { + cpl_table* shifted = NULL; + double* pwav = NULL; + int nrows=0; + int i=0; + SINFO_ASSURE_NOT_NULL_MSG(orig, "Null input table"); + + shifted=cpl_table_duplicate(orig); + pwav = cpl_table_get_data_double(shifted, col_wave); + nrows=cpl_table_get_nrow(shifted); + for(i=0;ilambda ) ) ; + check_nomsg( cpl_free( (*list)->K ) ) ; + check_nomsg( cpl_free( *list ) ) ; + *list = NULL ; + } + + cleanup: + return ; +} + +/** + * This function corrects a spectrum for contributes due to atmospheric extinction, airmass,exptime,gain + * + * @param star_list Table of ref star flux + * @param spectrum Table of observed star flux + * @param atmos_K atmospheric extinction curve + * @param the_arm observing arm + * @param airmass airmass value + * @param exptime exptime (dit*ndit) value + * @param gain gain value + * @param obj_list Table of observed star flux corrected by atmospheric extinction, airmass,exptime,gain + * + * @return cpl error code + */ + +static void +save_spectrum_debug(const cpl_image * img, const char * fname){ + + cpl_size sz = cpl_image_get_size_x(img); + cpl_vector * v = cpl_vector_new(sz); + for(cpl_size i = 0; i < sz; ++i){ + int rej = 0; + double d = cpl_image_get(img, i + 1, 1, &rej); + cpl_vector_set(v, i, d); + } + + cpl_vector_save(v, fname, CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE); + cpl_vector_delete(v); +} + +static void +save_double_debug(double * d, cpl_size sz, const char * fname){ + cpl_vector * v = cpl_vector_wrap(sz, d); + cpl_vector_save(v, fname, CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE); + cpl_vector_unwrap(v); +} + +static cpl_error_code +sinfo_spectrum_correct( + sinfo_star_flux_list * star_list, + sinfo_spectrum * spectrum, + double * atmos_K, + new_sinfo_band band, + double airmass, + double exptime, + double gain, + sinfo_star_flux_list ** obj_list) +{ + + cpl_msg_warning("", "COO++++RECT: %f %f %f", airmass, exptime, gain); + + save_spectrum_debug(spectrum->flux, "sinfo_spectrum_correct_spectrum.fits"); + save_double_debug(atmos_K, star_list->size, "atmos_K.fits"); + save_double_debug(star_list->flux, star_list->size, "star_list.fits"); + + double lambda=0; + double kvalue=0; + + + double * flux_added = NULL ; + double * lambda_star = NULL; + double * flux_star = NULL ; + + double * lambda_spectrum = NULL; + double * plambda=NULL ; + double * flux_spectrum = NULL ; + //int * qual_spectrum = NULL ; + + int i=0; + int size=0; + int nlambda_spectrum=0; + double lambda_spectrum_min=0; + double lambda_spectrum_max=0; + double lambda_star_min=0; + double lambda_star_max=0; + double step_spectrum=0 ; + double step_star=0 ; + int npix_in_interval=0 ; + int bin_size=1; + int binx=1; + int biny=1; + cpl_frame* obj_integrated=NULL; + + check_nomsg( nlambda_spectrum = sinfo_spectrum_get_size( spectrum ) ) ; + check_nomsg( flux_spectrum = sinfo_spectrum_get_flux( spectrum ) ) ; + //check_nomsg( qual_spectrum = sinfo_spectrum_get_qual( spectrum ) ) ; + check_nomsg( lambda_spectrum_min = sinfo_spectrum_get_lambda_min( spectrum ) ) ; + check_nomsg( lambda_spectrum_max = sinfo_spectrum_get_lambda_max( spectrum ) ) ; + check_nomsg( step_spectrum = sinfo_spectrum_get_lambda_step( spectrum ) ) ; + + /* In NIR, no binning ==> set 1x1 */ + /* TODO : for non-NIR cases we need the binning */ + //if ( the_arm != XSH_ARM_NIR ) { + /* we correct for bin size: + * bin along wave direction* bin along spatial direction + */ + //TODO: to be changed to support UVB,VIS + //check_nomsg(binx = sinfo_pfits_get_binx( spectrum->flux_header )) ; + //check_nomsg(biny = sinfo_pfits_get_biny( spectrum->flux_header )) ; + bin_size=binx*biny; + //} + + + flux_star = star_list->flux ; + size = star_list->size ; + lambda_star = star_list->lambda ; + + + lambda_star_min = *lambda_star ; + lambda_star_max = *(lambda_star+size-1) ; + step_star = (lambda_star_max-lambda_star_min)/(size-1) ; + + sinfo_msg( "Spectrum - size %d Nlambda: %d, Min: %lf, Max: %lf, Step: %lf", + size,nlambda_spectrum, lambda_spectrum_min, lambda_spectrum_max, + step_spectrum ) ; + sinfo_msg( " - BinX: %d, BinY: %d", binx, biny ) ; + + + SINFO_CALLOC( flux_added, double, size ) ; + /* For each lambda in star_list + if there is such a lambda in rec_list Then + integrate (add) the flux from (lambda-delta/2) to (lambda+delta/2) + calculate ratio rec_add_flux/star_flux + endif + EndFor + */ + /* First create lambda_spectrum array */ + SINFO_CALLOC( lambda_spectrum, double, nlambda_spectrum ) ; + + for( lambda = lambda_spectrum_min, plambda = lambda_spectrum, i = 0 ; + iflux[i] = flux_spectrum[i]/cor_fct ; + (*obj_list)->lambda[i] = lambda_star[i] ; + + pwav[i]=lambda_star[i]; + pflux_corr[i]=(*obj_list)->flux[i]; + pflux_obs[i]=flux_spectrum[i]; + pflux_ref[i]=flux_star[i]; + + /* Correct for atmos ext*/ + if ( atmos_K != NULL ) { + kvalue = pow(10., -airmass*atmos_K[i]*0.4 ) ; + (*obj_list)->flux[i] /= kvalue ; + pobj_atm_corr[i]=(*obj_list)->flux[i]; + pkavalue[i]=kvalue; + //sinfo_msg("resp: %g kvalue %g k %g",(*obj_list)->flux[i],kvalue,atmos_K[i]); + } + + /* Multiply by ratio star_binning/spectrum_binning */ + (*obj_list)->flux[i] *= step_star/step_spectrum ; + pobj_bin_cor[i]=(*obj_list)->flux[i]; + + } + + check_nomsg(cpl_table_duplicate_column(debug,"response",debug,"flux_ref")); + + check_nomsg(cpl_table_divide_columns(debug,"response","flux_obs_cor_obs2ref_bin_size")); + //check_nomsg(cpl_table_save(debug,NULL,NULL,"debug.fits",CPL_IO_DEFAULT)); + sinfo_free_table(&debug); + + check_nomsg(obj_integrated=sinfo_star_flux_list_save(*obj_list,"obj_list_corrected.fits","TEST")) ; + + + cleanup: + + cpl_free( lambda_spectrum ) ; + cpl_free( flux_added ) ; + sinfo_free_frame(&obj_integrated); + sinfo_free_table(&debug); + + save_double_debug((*obj_list)->flux, (*obj_list)->size, "obj_list.fits"); + + + return cpl_error_get_code(); + +} + + + + +static sinfo_atmos_ext_list * sinfo_atmos_ext_list_load( cpl_frame * ext_frame ) +{ + cpl_table *table = NULL ; + const char * tablename = NULL ; + sinfo_atmos_ext_list * result = NULL ; + int nentries, i ; + double * plambda, * pK ; + + /* verify input */ + SINFO_ASSURE_NOT_NULL( ext_frame); + + /* get table filename */ + check_nomsg(tablename = cpl_frame_get_filename( ext_frame )); + + /* Load the table */ + SINFO_TABLE_LOAD( table, tablename ) ; + check_nomsg( nentries = cpl_table_get_nrow( table ) ) ; + + /* Create the list */ + check_nomsg( result = sinfo_atmos_ext_list_create( nentries ) ) ; + + plambda = result->lambda ; + pK = result->K ; + if(!cpl_table_has_column(table,SINFO_ATMOS_EXT_LIST_COLNAME_K)){ + sinfo_msg_warning("You are using an obsolete atm extinction line table"); + cpl_table_duplicate_column(table,SINFO_ATMOS_EXT_LIST_COLNAME_K, + table,SINFO_ATMOS_EXT_LIST_COLNAME_OLD); + } + /* Fill the list */ + for( i = 0 ; i< nentries ; i++, plambda++, pK++ ) { + float value ; + + check_nomsg( sinfo_get_table_value( table, SINFO_ATMOS_EXT_LIST_COLNAME_WAVELENGTH, + CPL_TYPE_FLOAT, i, &value ) ) ; + *plambda = value ; + check_nomsg( sinfo_get_table_value( table, SINFO_ATMOS_EXT_LIST_COLNAME_K, + CPL_TYPE_FLOAT, i, &value ) ) ; + *pK = value ; + } + + cleanup: + if (cpl_error_get_code () != CPL_ERROR_NONE) { + sinfo_msg_error("can't load frame %s",cpl_frame_get_filename(ext_frame)); + sinfo_atmos_ext_list_free(&result); + } + cpl_table_delete( table); + return result ; +} +/** + * Interpolate atms extinction at same sampling step as ref std star + * + * @param star_list Table of ref star flux + * @param[in] atmos_ext_tab atmospheric extinction table + * @param[in] instrument instrument arm and lamp setting + * @param[out] atmos_lambda interpolated wave array + * @param[out] atmos_K interpolated atmospheric extinction K + * @return cpl error code + */ + +static cpl_error_code +sinfo_interpolate_atm_ext(sinfo_star_flux_list * star_list, + cpl_table*atmos_ext_tab, + new_sinfo_band band, + double** atmos_lambda, + double** atmos_K) +{ + + int nrow=0; + double* pk=0; + double* pw=0; + int j=0 ; + int nlambda_star=0 ; + double * lambda_star = NULL; + + SINFO_ASSURE_NOT_NULL_MSG (star_list,"null input ref std flux table!"); + SINFO_ASSURE_NOT_NULL_MSG (atmos_ext_tab,"null input atm ext table!"); + + nlambda_star = star_list->size ; + lambda_star = star_list->lambda ; + + /* Fill the atmos_lambda and K with only the subset of lambdas available + in star list (the std star) */ + SINFO_CALLOC( *atmos_lambda, double, nlambda_star ) ; + SINFO_CALLOC( *atmos_K, double, nlambda_star ) ; + if(!cpl_table_has_column(atmos_ext_tab,SINFO_ATMOS_EXT_LIST_COLNAME_K)){ + sinfo_msg_warning("You are using an obsolete atm extinction line table"); + cpl_table_duplicate_column(atmos_ext_tab,SINFO_ATMOS_EXT_LIST_COLNAME_K, + atmos_ext_tab,SINFO_ATMOS_EXT_LIST_COLNAME_OLD); + } + cpl_table_cast_column(atmos_ext_tab,SINFO_ATMOS_EXT_LIST_COLNAME_K,"K",CPL_TYPE_DOUBLE); + cpl_table_cast_column(atmos_ext_tab,"LAMBDA","WAVE",CPL_TYPE_DOUBLE); + + nrow=cpl_table_get_nrow(atmos_ext_tab); + pw=cpl_table_get_data_double(atmos_ext_tab,"WAVE"); + pk=cpl_table_get_data_double(atmos_ext_tab,"K"); + //PAPERO + /* X-shooter specific (UVB-VIS) */ + if(band == INSTRUMENT_BAND_UVB || + band == INSTRUMENT_BAND_VIS || + band == INSTRUMENT_BAND_ALL) { + for( j = 0 ; jsize; + /* Create the list */ + result = sinfo_star_flux_list_create(size); + + //check_nomsg(result->header = cpl_propertylist_duplicate(list->header)); + + + memcpy(result->lambda,list->lambda,size * sizeof(double)); + memcpy(result->flux,list->flux,size * sizeof(double)); + + cleanup: + return result; +} + + +static cpl_vector * +get_windowed(cpl_size start, cpl_size stop, double * v, cpl_size sz){ + + cpl_size true_size = 0; + double * v_data = cpl_calloc(stop - start + 1, sizeof(double)); + for(cpl_size i = start; i <= stop; ++i){ + if(i < 0 || i >= sz) continue; + if(isnan(v[i]) || isinf(v[i])) continue; + v_data[true_size] = v[i]; + true_size++; + } + + if(true_size == 0){ + cpl_free(v_data); + return NULL; + } + + return cpl_vector_wrap(true_size, v_data); +} + +static cpl_error_code +sinfo_star_flux_list_filter_median(sinfo_star_flux_list * result, + int hsize ) +{ + SINFO_ASSURE_NOT_NULL_MSG(result, "Null input flux list table frame"); + SINFO_ASSURE_NOT_ILLEGAL_MSG(result->size > 2*hsize,"size < 2*hsize. You set a too large half window size."); + + cpl_vector* v_out = cpl_vector_new(result->size); + + + for(cpl_size i = 0; i < result->size; i++){ + + cpl_size start = i - hsize; + cpl_size stop = i + hsize; + + + cpl_vector * windowed = get_windowed(start, stop, result->flux, result->size); + if(windowed == NULL){ + cpl_vector_set(v_out, i, NAN); + continue; + } + + cpl_vector_set(v_out, i, cpl_vector_get_median(windowed)); + cpl_vector_delete(windowed); + } + + for(cpl_size i = 0 ; i < result->size; ++i){ + result->flux[i] = cpl_vector_get(v_out, i); + } + +cleanup: + + cpl_vector_delete(v_out); + return cpl_error_get_code(); +} + +static double * sinfo_star_flux_list_get_lambda( sinfo_star_flux_list * list ) +{ + SINFO_ASSURE_NOT_NULL( list ) ; + + cleanup: + return list->lambda ; +} + +static double * sinfo_star_flux_list_get_flux( sinfo_star_flux_list * list ) +{ + SINFO_ASSURE_NOT_NULL( list ) ; + + cleanup: + return list->flux ; +} + + +static double * +sinfo_star_flux_list_duplicate_flux( sinfo_star_flux_list * list ) +{ + SINFO_ASSURE_NOT_NULL( list ) ; + double* to_ret = NULL; + + SINFO_CALLOC( to_ret, double, list->size) ; + + memcpy(to_ret, sinfo_star_flux_list_get_flux(list), sizeof(double) * list->size); + + cleanup: + + return to_ret; +} + +static double * +sinfo_star_flux_list_duplicate_lambda( sinfo_star_flux_list * list ) +{ + SINFO_ASSURE_NOT_NULL( list ) ; + double* to_ret = NULL; + + SINFO_CALLOC( to_ret, double, list->size) ; + + memcpy(to_ret, sinfo_star_flux_list_get_lambda(list), sizeof(double) * list->size); + + cleanup: + + return to_ret; +} + +static sinfo_star_flux_list * +sinfo_bspline_fit_interpol(sinfo_star_flux_list * ref_std_star_list, + cpl_table* resp_fit_points,HIGH_ABS_REGION * phigh, + new_sinfo_band band) +{ + sinfo_star_flux_list * res=NULL; + cpl_table* tab=NULL; + cpl_table* ext_data=NULL; + cpl_table* ext_fit=NULL; + /* + const char* fname=NULL; + double* lambda=NULL; + double wstp_fit=0; + */ + double* wave=NULL; + double* plambda=NULL; + double* flux=NULL; + double* xfit=NULL; + double* yfit=NULL; + double wrange=0; + double wmin_data=0; + double wmax_data=0; + double wmin_fit=0; + double wmax_fit=0; + + + int i=0; + int size_data=0; + int size_fit=0; + double med=0; + int imin=0; + int imax=0; + int nsel=0; + double * pflux=NULL; + + double flux_save=0; + + cpl_error_ensure(ref_std_star_list != NULL, CPL_ERROR_NULL_INPUT,return res,"NULL input reference std star list"); + cpl_error_ensure(resp_fit_points != NULL, CPL_ERROR_NULL_INPUT,return res,"NULL input table with response fit points"); + //cpl_error_ensure(inst != NULL, CPL_ERROR_NULL_INPUT,return res,"NULL input instrument"); + + //fname=cpl_frame_get_filename(resp_fit_points); + //fit_points=cpl_table_load(fname,1,0); + + + /* defines a band dependent size range over which to evaluate the median */ + /* TODO support other bands */ + if (band == INSTRUMENT_BAND_UVB) { + wrange=0.4; + } else if (band == INSTRUMENT_BAND_VIS) { + wrange=1.0; + } else if (band == INSTRUMENT_BAND_ALL || + band == INSTRUMENT_BAND_NIR || + band == INSTRUMENT_BAND_J || + band == INSTRUMENT_BAND_H || + band == INSTRUMENT_BAND_K || + band == INSTRUMENT_BAND_HK || + band == INSTRUMENT_BAND_L) { + wrange=4.0; + } + + + + size_data = ref_std_star_list->size ; + wave = sinfo_star_flux_list_duplicate_lambda(ref_std_star_list) ; + flux = sinfo_star_flux_list_duplicate_flux(ref_std_star_list) ; + res=sinfo_star_flux_list_duplicate(ref_std_star_list); + + tab=cpl_table_new(size_data); + cpl_table_wrap_double(tab,wave,"wave"); + cpl_table_wrap_double(tab,flux,"response"); + cpl_table_save(tab,NULL,NULL,"response_smoothed_modigli.fits",CPL_IO_DEFAULT); + + check_nomsg(wmin_data=cpl_table_get_column_min(tab,"wave")); + check_nomsg(wmax_data=cpl_table_get_column_max(tab,"wave")); + sinfo_msg("wmin_data=%g wmax_data=%g",wmin_data,wmax_data); + size_fit=cpl_table_get_nrow(resp_fit_points); + cpl_table_save(resp_fit_points,NULL,NULL,"resp_fit_points.fits",CPL_IO_DEFAULT); + //cpl_table_save(resp_fit_points,NULL,NULL,"pippo.fits",CPL_IO_DEFAULT); + cpl_table_save(tab,NULL,NULL,"pippo1.fits",CPL_IO_DEFAULT); + pflux=cpl_table_get_data_double(tab,"response"); + /* remove points that have either value NAN or INF */ + for(i=0;ilambda_min != 0.; phigh++) { + cpl_msg_warning("", "Flag [%g,%g]",phigh->lambda_min,phigh->lambda_max); + for (i = 0; i < size_data; i++) { + if ( (wave[i] >= phigh->lambda_min && wave[i] <= phigh->lambda_max) && + (wave[i] >= wmin_data && wave[i] <= wmax_data) ){ + cpl_table_set_invalid(tab,"response", i); + } + } + } + + } + cpl_table_erase_invalid(tab); + cpl_table_save(tab,NULL,NULL,"pippo3.fits",CPL_IO_DEFAULT); + + + + double wmin_good=cpl_table_get_column_min(tab,"wave"); + double wmax_good=cpl_table_get_column_max(tab,"wave"); + + /* limit the points where the raw response is sampled to the region actually + * covered by the data + */ + check_nomsg(wmin_fit=cpl_table_get_column_min(resp_fit_points,"LAMBDA")); + check_nomsg(wmax_fit=cpl_table_get_column_max(resp_fit_points,"LAMBDA")); + + cpl_table_and_selected_double(resp_fit_points,"LAMBDA",CPL_NOT_LESS_THAN,wmin_data); + cpl_table_and_selected_double(resp_fit_points,"LAMBDA",CPL_NOT_GREATER_THAN,wmax_data); + ext_fit=cpl_table_extract_selected(resp_fit_points); + cpl_table_save(ext_fit,NULL,NULL,"resp_fit.fits",CPL_IO_DEFAULT); + cpl_table_save(tab,NULL,NULL,"resp_data.fits",CPL_IO_DEFAULT); + check_nomsg(wmin_fit=cpl_table_get_column_min(ext_fit,"LAMBDA")); + check_nomsg(wmax_fit=cpl_table_get_column_max(ext_fit,"LAMBDA")); + cpl_msg_warning("", "AA: wmin_fit=%g wmax_fit=%g",wmin_fit,wmax_fit); + cpl_msg_warning("", "BB: wmin_data=%g wmax_data=%g",wmin_data,wmax_data); + cpl_msg_warning("", "CC: wmin_good=%g wmax_good=%g",wmin_good,wmax_good); + cpl_table_save(tab,NULL,NULL,"pippo4.fits",CPL_IO_DEFAULT); + + size_fit=cpl_table_get_nrow(ext_fit); + cpl_size size_fit_ori=cpl_table_get_nrow(ext_fit); + + //sinfo_msg_warning("size_fit=%d wstp_fit=%g",size_fit,wstp_fit); + imin=0; + if( (wmin_fit>wmin_data) && (wmin_fit > wmin_good) ) { + //sinfo_msg("wmin_fit>wmin_data"); + size_fit+=1; + imin=1; + } + imax=size_fit-1; + if( (wmax_fit wmin_good ) { + cpl_msg_warning("", "wmin_fit>wmin_good"); + + sinfo_msg("selecting range [%g,%g]",wmin_good,wmin_good+wrange); + nsel=cpl_table_and_selected_double(tab,"wave",CPL_NOT_GREATER_THAN,wmin_good+wrange); + if(nsel==0) { + sinfo_msg_warning("Problem to get spline fit sampling points"); + sinfo_msg_warning("Possibly XSH_HIGH_ABS_WIN table wave ranges incompatible with RESP_FIT_POINTS_CAT table"); + } + ext_data=cpl_table_extract_selected(tab); + cpl_table_select_all(tab); + cpl_table_save(ext_data, NULL, NULL, "ext_data_1.fits", CPL_IO_CREATE); + if(nsel > 0 ) { + check_nomsg(med=cpl_table_get_column_median(ext_data,"response")); + yfit[0]=med; + xfit[0]=wmin_data; + sinfo_msg("xfit[%d]=%g yfit=%g",0,xfit[0],yfit[0]); + } + + + sinfo_msg("xfit=%g yfit=%g",wmin_good,med); + sinfo_free_table(&ext_data); + + } + + + /* + sinfo_msg("wmin_data=%g",wmin_data); + sinfo_msg("wmin_fit=%g",wmin_fit); + sinfo_msg("wmax_data=%g",wmax_data); + sinfo_msg("wmax_fit=%g",wmax_fit); + sinfo_msg("imin=%d imax=%d",imin,imax); + */ + /* determine the other fit points in a robust way */ + plambda=cpl_table_get_data_double(ext_fit,"LAMBDA"); + for(i=0;i< size_fit_ori;i++) { + cpl_msg_warning("", ":::<><>plambda [%g]",plambda[i]); + cpl_table_and_selected_double(tab,"wave",CPL_NOT_LESS_THAN,plambda[i]-wrange); + nsel=cpl_table_and_selected_double(tab,"wave",CPL_NOT_GREATER_THAN,plambda[i]+wrange); + + + sinfo_msg_warning("selecting range [%g,%g] with %i",plambda[i]-wrange,plambda[i]+wrange, nsel); + + if(nsel>0) { + check_nomsg(ext_data=cpl_table_extract_selected(tab)); + //sinfo_msg("wmin=%g wmax=%g",plambda[i]-wrange,plambda[i]+wrange); + check_nomsg(med=cpl_table_get_column_median(ext_data,"response")); + xfit[i + imin]=plambda[i]; + yfit[i + imin]=med; + flux_save=med; + sinfo_msg("xfit[%d]=%g yfit=%g",i,xfit[i],yfit[i]); + sinfo_free_table(&ext_data); + } else { + yfit[i + imin]=flux_save; + } + cpl_table_select_all(tab); + } + cpl_table_select_all(tab); + sinfo_msg_warning("fk7"); + sinfo_print_rec_status(7); + /* determine the last fit points in a robust way */ + + if( wmax_fit0) { + check_nomsg(med=cpl_table_get_column_median(ext_data,"response")); + yfit[size_fit-1]=med; + xfit[size_fit-1]=wmax_data; + } + + sinfo_msg("xfit[%d]=%g yfit=%g",size_fit-1,wmax_good,med); + sinfo_free_table(&ext_data); + } + + sinfo_msg_warning("fk8"); + sinfo_print_rec_status(8); + + cpl_table_save(tab,NULL,NULL,"resp_data_selected.fits",CPL_IO_DEFAULT); + + sinfo_free_table(&tab); + tab=cpl_table_new(size_fit); + cpl_table_wrap_double(tab,xfit,"xfit"); + check_nomsg(cpl_table_wrap_double(tab,yfit,"yfit")); + cpl_table_save(tab,NULL,NULL,"resp_data_fit.fits",CPL_IO_DEFAULT); + + //sinfo_msg("size_fit=%d size_data=%d",size_fit,size_data); + /* as xsh_bspline_interpolate_data_at_pos allocates memory for flux vector + * and we store it in an already allocated structure we need to deallocate + * the corresponding memory first: better would be to replace the res->flux + * values by the newly computed ones + */ + cpl_free(res->flux); + sinfo_msg_warning("xfit[0]=%g xfit[size_fit-1]=%g",xfit[0],xfit[size_fit-1]); + sinfo_msg_warning("xfit[size_fit-3]=%g xfit[size_fit-2]=%g",xfit[size_fit-3],xfit[size_fit-2]); + check_nomsg(res->flux=sinfo_bspline_interpolate_data_at_pos(xfit,yfit,size_fit,res->lambda,size_data)); + //sinfo_star_flux_list_save(res,"fit_response.fits", "TEST" ) ; + sinfo_msg_warning("fk9"); + sinfo_print_rec_status(9); + //exit(0); + cleanup: + + sinfo_msg_warning("fk10"); + sinfo_print_rec_status(10); + cpl_free(xfit); + cpl_free(yfit); + sinfo_free_table(&ext_fit); + cpl_table_unwrap(tab,"xfit"); + cpl_table_unwrap(tab,"yfit"); + cpl_free(tab); + sinfo_msg_warning("fk11"); + sinfo_print_rec_status(11); + return res; +} + + + +static sinfo_star_flux_list * +sinfo_bspline_fit_smooth(sinfo_star_flux_list * ref_std_star_list,HIGH_ABS_REGION * phigh,new_sinfo_band band) +{ + sinfo_star_flux_list * result=NULL; + size_t n = 0; + size_t order = 4; + size_t ncoeffs = 0; + size_t nbreak = 0; + + size_t i, j; + gsl_bspline_workspace *bw; + gsl_vector *B; + + gsl_rng *r; + gsl_vector *c, *w; + gsl_vector * x, *y; + gsl_matrix *X, *cov; + gsl_multifit_linear_workspace *mw; + double chisq=0, Rsq=0, dof=0; + //double tss; + //double wmin=0; + //double wmax=0; + //double wstep=0; + double* wave = NULL; + double* response = NULL; + double* pwav = NULL; + double* pfit = NULL; + //int kh = 0; + double dump_factor = 1.e10; + //cpl_table* tab_response = NULL; + cpl_table* tab_resp_fit = NULL; + //const char* fname = NULL; + + /* set optimal number of coeffs for each arm */ + if (band == INSTRUMENT_BAND_UVB) { + ncoeffs = 21; + } else if (band == INSTRUMENT_BAND_VIS) { + ncoeffs = 16; + } else if ( (band == INSTRUMENT_BAND_ALL ) || + (band == INSTRUMENT_BAND_NIR ) || + (band == INSTRUMENT_BAND_J ) || + (band == INSTRUMENT_BAND_H ) || + (band == INSTRUMENT_BAND_K ) || + (band == INSTRUMENT_BAND_HK ) || + (band == INSTRUMENT_BAND_L ) ) { + ncoeffs = 6; + } + + nbreak = ncoeffs + 2 - order; + + n = ref_std_star_list->size ; + wave = ref_std_star_list->lambda ; + response = ref_std_star_list->flux ; + //wmin = *wave ; + //wmax = *(wave+n-1) ; + //wstep = (wmax-wmin)/(n-1) ; + + gsl_rng_env_setup(); + r = gsl_rng_alloc(gsl_rng_default); + + /* allocate a cubic bspline workspace (ORDER = order) */ + bw = gsl_bspline_alloc(order, nbreak); + B = gsl_vector_alloc(ncoeffs); + + x = gsl_vector_alloc(n); + y = gsl_vector_alloc(n); + X = gsl_matrix_alloc(n, ncoeffs); + c = gsl_vector_alloc(ncoeffs); + w = gsl_vector_alloc(n); + cov = gsl_matrix_alloc(ncoeffs, ncoeffs); + mw = gsl_multifit_linear_alloc(n, ncoeffs); + + //printf("#m=0,S=0\n"); + /* this is the data to be fitted */ + for (i = 0; i < n; ++i) { + double sigma; + double xi = (double) wave[i]; + double yi = (double) response[i]; + + sigma = 0.001 * yi; + double dy = gsl_ran_gaussian(r, sigma); + yi += dy; + + gsl_vector_set(x, i, xi); + + if(isnan(yi) || isinf(yi)) { + gsl_vector_set(y, i, 0); + gsl_vector_set(w, i, 1.0 / dump_factor); + //sinfo_msg("wave=%g y=%g w=%g",xi,yi,gsl_vector_get(w, i)); + } else { + gsl_vector_set(y, i, yi); + gsl_vector_set(w, i, 1.0 / (sigma * sigma)); + //sinfo_msg("wave=%g y=%g w=%g",xi,yi,gsl_vector_get(w, i)); + } + //printf("%f %g\n", xi, yi); + } + + if (phigh != NULL) { + + sinfo_msg("Flag High Absorption Regions" ); + for (; phigh->lambda_min != 0.; phigh++) { + sinfo_msg("Flag [%g,%g]",phigh->lambda_min,phigh->lambda_max); + for (i = 0; i < n; i++) { + if (wave[i] >= phigh->lambda_min && wave[i] <= phigh->lambda_max) { + //gsl_vector_set(w, i, gsl_vector_get(w, i) / dump_factor); + gsl_vector_set(w, i, 1.0 / dump_factor); + //sinfo_msg("w=%g",gsl_vector_get(w, i)); + } + } + } + } + + /* use uniform breakpoints on [0, 15] */ + gsl_bspline_knots_uniform(wave[0], wave[n - 1], bw); + + /* construct the fit matrix X */ + for (i = 0; i < n; ++i) { + double xi = gsl_vector_get(x, i); + + /* compute B_j(xi) for all j */ + gsl_bspline_eval(xi, B, bw); + + /* fill in row i of X */ + for (j = 0; j < ncoeffs; ++j) { + double Bj = gsl_vector_get(B, j); + gsl_matrix_set(X, i, j, Bj); + } + } + + /* do the fit */ + gsl_multifit_wlinear(X, w, y, c, cov, &chisq, mw); + + dof = n - ncoeffs; + /* + tss = gsl_stats_wtss(w->data, 1, y->data, 1, y->size); + Rsq = 1.0 - chisq / tss; + */ + printf("chisq/dof = %e, Rsq = %f\n", chisq / dof, Rsq); + + tab_resp_fit = cpl_table_new(n); + cpl_table_new_column(tab_resp_fit, "wave", CPL_TYPE_DOUBLE); + cpl_table_new_column(tab_resp_fit, "fit", CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(tab_resp_fit, "wave", 0, n, 0); + cpl_table_fill_column_window_double(tab_resp_fit, "fit", 0, n, 0); + pwav = cpl_table_get_data_double(tab_resp_fit, "wave"); + pfit = cpl_table_get_data_double(tab_resp_fit, "fit"); + result=sinfo_star_flux_list_create(n); + /* output the smoothed curve */ + { + double yi, yerr; + //printf("#m=1,S=0\n"); + for (i = 0; i < n; i++) { + double xi = (double) wave[i]; + gsl_bspline_eval(xi, B, bw); + gsl_multifit_linear_est(B, c, cov, &yi, &yerr); + //printf("%f %g\n", xi, yi); + pwav[i] = xi; + pfit[i] = yi; + result->lambda[i]=xi; + result->flux[i]=yi; + } + } + //cpl_table_save(tab_resp_fit, NULL, NULL, "resp_fit.fits", CPL_IO_DEFAULT); + + + //cleanup: + gsl_rng_free(r); + gsl_bspline_free(bw); + gsl_vector_free(B); + gsl_vector_free(x); + gsl_vector_free(y); + gsl_matrix_free(X); + gsl_vector_free(c); + gsl_vector_free(w); + gsl_matrix_free(cov); + gsl_multifit_linear_free(mw); + sinfo_free_table(&tab_resp_fit); + + return result; +} + +cpl_error_code +sinfo_response_merge_obj_std_info(cpl_frame* result, + sinfo_star_flux_list * star_list, + sinfo_star_flux_list * obj_list) +{ + + cpl_table* table=NULL; + const char* name=NULL; + cpl_propertylist* plist=NULL; + int nrow=0; + int i=0; + + double* pobj=NULL; + double* pref=NULL; + double* pdiv=NULL; + + name=cpl_frame_get_filename(result); + plist=cpl_propertylist_load(name,0); + table=cpl_table_load(name,1,0); + nrow=cpl_table_get_nrow(table); + + check_nomsg(cpl_table_name_column(table,"FLUX", "RESPONSE")); + cpl_table_new_column(table,"OBS",CPL_TYPE_DOUBLE); + cpl_table_new_column(table,"REF",CPL_TYPE_DOUBLE); + cpl_table_new_column(table,"REF_DIV_OBS",CPL_TYPE_DOUBLE); + cpl_table_fill_column_window_double(table,"OBS",0,nrow,0); + cpl_table_fill_column_window_double(table,"REF",0,nrow,0); + cpl_table_fill_column_window_double(table,"REF_DIV_OBS",0,nrow,0); + + pobj=cpl_table_get_data_double(table,"OBS"); + pref=cpl_table_get_data_double(table,"REF"); + pdiv=cpl_table_get_data_double(table,"REF_DIV_OBS"); + + for(i=0;iflux[i]; + pref[i]=star_list->flux[i]; + pdiv[i]=pref[i]/pobj[i]; + } + + cpl_table_save(table,plist,NULL,name,CPL_IO_DEFAULT); + + cleanup: + sinfo_free_table(&table); + sinfo_free_propertylist(&plist); + + return cpl_error_get_code(); +} +static void +sinfo_star_flux_list_extrapolate_wave_end( sinfo_star_flux_list * list , + const double wmax) +{ + SINFO_ASSURE_NOT_NULL( list ) ; + int size=list->size; + int i=0; + int k=0; + int off=10; + double f1=0; + double f2=0; + double w1=0; + double w2=0; + double x1=0; + double x2=0; + double m=0; + double x=0; + double w=0; + int computed=0; + + + /* Rayleigh-Jeans extrapolation of null flux values: + * we can linearize the formula to have a quick fit + * flux=A/lambda^4+B. X=1/lambda^4, Y=f==> + * Y=A*X+B==> we can linearize */ + for (i = 0; i < size; i++) { + if (list->lambda[i]flux[k]; + f1 = list->flux[k - off]; + w2 = 1./list->lambda[k]; + x2 = w2*w2*w2*w2; + w1 = 1./list->lambda[k - off]; + x1 = w1*w1*w1*w1; + m = (f2 - f1) / (x2 - x1); + computed=1; + + } else { + w=1./list->lambda[i]; + x=w*w*w*w; + + list->flux[i]=f1+m*(x-x1); + + } + } + } + + cleanup: + return; +} +static void +sinfo_frame_spectrum_save(cpl_frame* frm,const char* name_o) +{ + sinfo_spectrum* s=NULL; + //const char* name=NULL; + const char* tag=NULL; + cpl_frame* loc_frm=NULL; + //name=cpl_frame_get_filename(frm); + sinfo_msg_warning("frm=%p",frm); + sinfo_print_rec_status(20); + //cpl_ensure(frm != NULL, CPL_ERROR_NULL_INPUT, NULL); + sinfo_print_rec_status(21); + s=sinfo_spectrum_load(frm); + sinfo_print_rec_status(22); + loc_frm=sinfo_spectrum_save(s,name_o,tag); + sinfo_print_rec_status(23); + cpl_frame_set_filename(frm,name_o); + sinfo_print_rec_status(24); + sinfo_spectrum_free(&s); + sinfo_free_frame(&loc_frm); + return; +} +static char * sinfo_get_basename(const char *filename) +{ + char *p ; + p = strrchr (filename, '/'); + return p ? p + 1 : (char *) filename; +} + + +static cpl_frame * +sinfo_compute_response(cpl_frame * obs_std_star, + cpl_frame * flux_std_star_cat, + cpl_frame * atmos_ext, + cpl_frame* high_abs, + cpl_frame* resp_fit_points, + cpl_frame* tell_mod_cat, + new_sinfo_band band, + double exptime, + const int tell_corr ) +{ + + /* TODO: exptime should not appear in this function interface as it can be + * retrieved from input frame */ + cpl_frame* result = NULL; + cpl_ensure(obs_std_star != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(flux_std_star_cat != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(atmos_ext != NULL, CPL_ERROR_NULL_INPUT, NULL); + //cpl_ensure(high_abs != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(resp_fit_points != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(tell_mod_cat != NULL, CPL_ERROR_NULL_INPUT, NULL); + + double dRA = 0; + double dDEC = 0; + double airmass = 0; + + double wmin = 0; + double wmax = 0; + double wstep = 0; + int naxis1 = 0; + double cdelt1 = 0; + const char* filename = NULL; + cpl_propertylist* plist = NULL; + int is_complete=0; + cpl_frame* ipol_ref_std_star_frame=NULL; + cpl_frame* frm_tmp=NULL; + + cpl_table* tbl_shift_std_spectrum=NULL; + cpl_frame* shift_std_star_frame=NULL; + const char* tbl_shift_std_fname="shift_flux_std_star.fits"; + char resp_obs_std_star_fname[256]; + cpl_frame* obs_std_star_resp=NULL; + cpl_table* resp_fit_points_tbl=NULL; + cpl_table* tbl_ref_std_spectrum = NULL; + const double um2nm=1000; + cpl_frame* ipol_shift_std_star_frame=NULL; + + + sinfo_star_flux_list * shift_std_star_list = NULL; + sinfo_star_flux_list * corr_obs_std_star_list = NULL; + sinfo_star_flux_list * response =NULL; + sinfo_star_flux_list * response_fit =NULL; + + + sinfo_star_flux_list * obs_std_star_list = NULL; + /* X-shooter specific */ + sinfo_rv_ref_wave_param* rv_ref_wave=NULL; + + sinfo_spectrum* obs_spectrum=NULL; + + HIGH_ABS_REGION * phigh = NULL; + + sinfo_star_flux_list * ref_std_star_list = NULL; + + + + filename = cpl_frame_get_filename(obs_std_star); + const char* obs_name = filename + strlen(filename); + while(*obs_name != '/') obs_name--; + obs_name++; + + char fname_obs[256]; + sprintf(fname_obs, "%s", obs_name); + sinfo_msg_warning("filename=%s",filename); + cpl_table* tab_obs_std_star=cpl_table_load(filename,1,0); + plist = cpl_propertylist_load(filename, 0); + + //naxis1 = sinfo_pfits_get_naxis1(plist); + int status; + naxis1 = cpl_table_get_nrow(tab_obs_std_star); + /* TODO: adjust SINFONI scale from um to nm */ + if( band == INSTRUMENT_BAND_J || + band == INSTRUMENT_BAND_H || + band == INSTRUMENT_BAND_K || + band == INSTRUMENT_BAND_HK || + band == INSTRUMENT_BAND_L ) { + sinfo_msg_warning("correct wave scale from um to nm"); + cpl_table_multiply_scalar(tab_obs_std_star,"wavelength",um2nm); + } + cpl_table_save(tab_obs_std_star, plist, NULL, "tmp_obs_std_star_ORI.fits", CPL_IO_CREATE); + cpl_table_save(tab_obs_std_star, plist, NULL, "tmp_obs_std_star.fits", CPL_IO_CREATE); + cpl_frame_set_filename(obs_std_star,"tmp_obs_std_star.fits"); + wmin=cpl_table_get_column_min(tab_obs_std_star,"wavelength"); + wmax=cpl_table_get_column_max(tab_obs_std_star,"wavelength"); + int nrow=0; + nrow=cpl_table_get_nrow(tab_obs_std_star); + wstep=(wmax-wmin)/(nrow-1); + sinfo_msg_warning("rk1 wmin=%g wmax=%g wstep=%g cdelt1=%g naxis1=%d", + wmin,wmax,wstep,cdelt1,naxis1); + /* inaccurate + if(cpl_table_get_column_type(tab_obs_std_star, "wavelength") == CPL_TYPE_DOUBLE) { + wstep=cpl_table_get_double(tab_obs_std_star,"wavelength",1,&status)-wmin; + } else { + wstep=cpl_table_get_float(tab_obs_std_star,"wavelength",1,&status)-wmin; + } + */ + + + + /* + * cdelt1 = sinfo_pfits_get_cdelt1(plist); + wstep=cdelt1; + wmin = sinfo_pfits_get_crval1(plist); + */ + + //wmax = wmin + cdelt1 * naxis1; + obs_std_star_resp=cpl_frame_duplicate(obs_std_star); + + obs_std_star_list = sinfo_star_flux_list_load_spectrum(obs_std_star_resp) ; + cpl_frame* frm=sinfo_star_flux_list_save( obs_std_star_list,"obs_std_star_list.fits", "TEST" ) ; + sinfo_star_flux_list_free(&obs_std_star_list); + sinfo_free_frame(&frm); + //exit(0); + + sinfo_frame_sci_get_ra_dec_airmass(obs_std_star_resp,&dRA,&dDEC,&airmass); + sinfo_msg_warning("rk1 wmin=%g wmax=%g wstep=%g cdelt1=%g naxis1=%d", + wmin,wmax,wstep,cdelt1,naxis1); + sinfo_print_rec_status(1); + sinfo_std_star_id std_star_id=0; + sinfo_parse_catalog_std_stars(flux_std_star_cat, dRA, dDEC, + STAR_MATCH_DEPSILON, &tbl_ref_std_spectrum,&std_star_id); + + + sinfo_msg_warning("dRA=%g dDEC=%g airmass=%g",dRA,dDEC,airmass); + + /* for QC we save the ref STD spectrum in a FITS file to be used for comparison */ + cpl_frame* ref_std_star_frame=NULL; + const char* tbl_ref_std_fname="ref_flux_std_star.fits"; + /* TODO: the following table in a NULL pointer" */ + sinfo_msg_warning("tbl_ref_std_spectrum1=%p",tbl_ref_std_spectrum); + cpl_table_save(tbl_ref_std_spectrum,NULL,NULL,tbl_ref_std_fname, + CPL_IO_DEFAULT); + + + ref_std_star_frame=sinfo_frame_product(tbl_ref_std_fname,"FLUX_STD_STAR", + CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_INTERMEDIATE); + + + /* re-sample reference STD spectrum on the same sampling pixel base of the observed STD spectrum. + * over the allowed wave ranges. This operation need to conserve flux.QC: verify that after + * re-sampling the re-sampled spectrum overlaps the original one. The re-sampling should be given by a + * (Hermite) spline fit of large enough degree + * */ + + sinfo_msg_warning("rk2 wstep=%g wmin=%g wmax=%g",wstep,wmin,wmax); + sinfo_print_rec_status(2); + check_nomsg(ipol_ref_std_star_frame=sinfo_spectrum_interpolate_linear(ref_std_star_frame,wstep,wmin,wmax)); + + sinfo_msg_warning("rk3"); + sinfo_print_rec_status(3); + check_nomsg(ref_std_star_list = sinfo_star_flux_list_load( ipol_ref_std_star_frame )) ; + sinfo_free_frame(&ipol_ref_std_star_frame); + sinfo_free_frame(&ref_std_star_frame); + + //TODO: next line can be commented out + //sinfo_star_flux_list_save( ref_std_star_list,"ref_std_star_list.fits", "TEST" ) ; + /* Does not apply for SINFONI */ + if( band == INSTRUMENT_BAND_UVB && is_complete !=0){ + sinfo_star_flux_list_extrapolate_wave_end(ref_std_star_list,545.); + frm_tmp=sinfo_star_flux_list_save( ref_std_star_list,"extrapol_ref_std_star_list.fits", "TEST" ) ; + sinfo_free_frame(&frm_tmp); + } + + + + //PIPPO: we moved here telluric correction. + sinfo_msg_warning("tell_corr=%d tell_mod_cal=%p",tell_corr,tell_mod_cat); + sinfo_msg_warning("rk4"); + sinfo_print_rec_status(4); + + + if(band != INSTRUMENT_BAND_UVB && tell_corr == 1 && tell_mod_cat!= NULL) { + sinfo_msg_warning("Telluric correction"); + cpl_table* tab_res=NULL; + //int next=0; + + cpl_size model_idx=0; + obs_std_star_list = sinfo_star_flux_list_load_spectrum(obs_std_star_resp) ; + + cpl_frame* frm=sinfo_star_flux_list_save( obs_std_star_list,"obs_std_star_list.fits", "TEST" ) ; + sinfo_free_frame(&frm); + //exit(0); + obs_spectrum = sinfo_spectrum_load_from_table( obs_std_star_resp, + "wavelength","counts_bkg"); + sinfo_print_rec_status(3); + sinfo_msg_warning("ok3"); + + check_nomsg(tab_res=sinfo_telluric_model_eval(tell_mod_cat,obs_spectrum,band, + &model_idx)); + + cpl_table_save(tab_res, NULL, NULL, "corrected_obs_modigli.fits", CPL_IO_CREATE); + + + //exit(0); + sinfo_print_rec_status(4); + sinfo_msg_warning("ok4"); + + sinfo_spectrum_free(&obs_spectrum); + + /* + sinfo_msg("response size %d table size %d", + response->size,cpl_table_get_nrow(tab_obs_tell_cor)); + sinfo_msg("wstep=%g",wstep); + tab_res=sinfo_table_resample_uniform(tab_obs_tell_cor,"wave","ratio",wstep); + sinfo_msg("response size %d table size %d", + response->size,cpl_table_get_nrow(tab_res)); + */ + double* pwav=NULL; + double* pflx=NULL; + int i=0; + //cpl_table_dump(tab_res,1,2,stdout); + pwav = cpl_table_get_data_double(tab_res, "wavelength"); + + pflx = cpl_table_get_data_double(tab_res, "ratio"); + + sinfo_msg_warning("ok1 size_obs=%d size_mod_corr=%d", + obs_std_star_list->size,(int)cpl_table_get_nrow(tab_res)); + sinfo_print_rec_status(5); + sinfo_msg_warning("ok5"); + for(i=0;isize;i++) { + + obs_std_star_list->lambda[i] = pwav[i]; + + obs_std_star_list->flux[i] = pflx[i]; + + } + sinfo_print_rec_status(6); + sinfo_msg_warning("ok6"); + sinfo_free_table(&tab_res); + frm_tmp=sinfo_star_flux_list_save( obs_std_star_list,"obs_std_star_list_tell.fits", "TEST" ) ; + sinfo_print_rec_status(1); + + sinfo_free_frame(&frm_tmp); + sinfo_star_flux_list_to_frame(obs_std_star_list,obs_std_star_resp); + sinfo_print_rec_status(7); + sinfo_msg_warning("ok7"); + } else { + check_nomsg(obs_std_star_list = sinfo_star_flux_list_load_spectrum(obs_std_star_resp)) ; + //frm_tmp=sinfo_star_flux_list_save( obs_std_star_list,"obs_std_star_list.fits", "TEST" ) ; + //sinfo_free_frame(&frm_tmp); + + } + sinfo_print_rec_status(8); + sinfo_msg_warning("ok8"); + + + //CONTINUE + /* TODO: here we need to have the image converted in table + check_nomsg(ipol_obs_std_star_frame=xsh_spectrum_interpolate_linear(obs_std_star_resp,wstep/10,wmin,wmax)); + */ + + + /* TODO: shift the ref STD star spectrum by a value corresponding to the its radial velocity */ + rv_ref_wave=sinfo_rv_ref_wave_param_create(); + + /* get reference lambda from given ref std star */ + sinfo_rv_ref_wave_init(std_star_id ,band,rv_ref_wave); + //sinfo_msg("guess=%12.8g",rv_ref_wave->wguess); + + + /* get corresponding lambda from observed std star */ + /* this method is not very robust to get the shift between spectra as: + * 1) the observed spectrum is noisy + * 2) the lines are in absorbtion and do not have a Gaussian shape + * 3) some line have an inversion (a small max in the minimum area of the line) + * Thus it is better to make a cross correlation between lines that allows to solve all problems + */ + /* + double wave_obs=0; + wave_obs=xsh_get_obs_std_star_wave_ref(obs_std_star_resp,wave_guess,wmin,wstep); + double wave_shift=0; + double wave_ref=0; + wave_ref=xsh_get_ref_std_star_wave_ref(tbl_ref_std_spectrum,wave_guess,wstep); + sinfo_msg("wave: guess %g ref %g shift %g",wave_guess,wave_ref,wave_guess-wave_ref); + */ + //sinfo_star_flux_list_save( obs_std_star_list,"obs_std_star_list.fits", "TEST" ) ; + frm_tmp=sinfo_star_flux_list_save( ref_std_star_list,"ref_flux_std_star.fits", "TEST" ) ; + sinfo_free_frame(&frm_tmp); + double wave_shift=0; + sinfo_print_rec_status(9); + sinfo_msg_warning("ok9"); + if(band == INSTRUMENT_BAND_ALL || + band == INSTRUMENT_BAND_J || + band == INSTRUMENT_BAND_NIR || + band == INSTRUMENT_BAND_VIS || + band == INSTRUMENT_BAND_UVB) { + cpl_msg_warning("", "COOOOOOOOORRRRELATE!!!!!!!!"); + wave_shift=sinfo_std_star_spectra_correlate(obs_std_star_list,ref_std_star_list,rv_ref_wave); + } + else{ + cpl_msg_warning("", "||!!poejiwfibweifiwNOOOOOCOOOOOOOOORRRRELATE!!!!!!!!"); + } + //double offset=(wave_obs-wave_guess)/wave_guess; + double offset=(wave_shift)/rv_ref_wave->wguess; + cpl_msg_warning("","wave: guess[nm] %g RV shift[nm] %g offset[unitless]=%g",rv_ref_wave->wguess,wave_shift,offset); + cpl_msg_warning("", "offset::::: %e", offset); + tbl_shift_std_spectrum=sinfo_table_shift_rv(tbl_ref_std_spectrum,"LAMBDA",offset); + + sinfo_free_table(&tbl_ref_std_spectrum); + + check_nomsg(cpl_table_save(tbl_shift_std_spectrum,NULL,NULL,tbl_shift_std_fname, + CPL_IO_DEFAULT)); + sinfo_print_rec_status(10); + sinfo_msg_warning("ok10"); + + cpl_table_save(tbl_shift_std_spectrum, NULL, NULL, "tbl_shift_std_spectrum.fits", CPL_IO_CREATE); + + //TODO: This tmp product has been left for SABINE to check the RV shift + sinfo_free_table(& tbl_shift_std_spectrum); + check_nomsg(shift_std_star_frame=sinfo_frame_product(tbl_shift_std_fname,"FLUX_STD_STAR", + CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_INTERMEDIATE)); + + + /* Define (possibly STD star dependent) arm dependent windows where the (either reference and observed) + * STD star spectrum should not be sampled (these are usually narrow regions around line cores) + * */ + + sinfo_print_rec_status(11); + sinfo_msg_warning("ok11"); + + check_nomsg(phigh=sinfo_fill_high_abs_regions(band,high_abs)); + + check_nomsg(ipol_shift_std_star_frame=sinfo_spectrum_interpolate_linear(shift_std_star_frame,wstep,wmin,wmax)); + + check_nomsg( shift_std_star_list = sinfo_star_flux_list_load( ipol_shift_std_star_frame ) ) ; + + sinfo_free_frame(&ipol_shift_std_star_frame); + sinfo_free_frame(&shift_std_star_frame); + + sinfo_print_rec_status(12); + sinfo_msg_warning("ok12"); + frm_tmp=sinfo_star_flux_list_save( shift_std_star_list,"shift_std_star_list.fits", "TEST" ) ; + sinfo_free_frame(&frm_tmp); + sinfo_msg_warning("ok13"); + //exit(0); + /* median-average over few pix (half-box of 2 pix radii, ie the number of pixels 'around' + * the central pixel which define the neighbourhood of that pixel=> filter size is 2*radii+1) + * the observed STD spectrum to remove residual CRH/BP. + * DONE WITHIN xsh_obs_std_correct + */ + + /* + * FOR VIS,NIR that are affected by telluric lines: + * Then filter-max over half-box of 20 pix (to remove isolated telluric lines) + * Then filter smooth over 50 pix, for smoothing. */ + /* TODO: for the moment not implemented also to be able to check how much bad pixels affects result */ + //sinfo_star_flux_list * obs_std_star_list = NULL; + + /* correct observed spectrum for atmospheric absorbtion and airmass dimming effects, wavelength direction + * bin size, gain, exptime */ + sinfo_print_rec_status(13); + check_nomsg( corr_obs_std_star_list = sinfo_obs_std_correct(obs_std_star_resp, shift_std_star_list, atmos_ext,band ) ) ; + sinfo_print_rec_status(14); + sinfo_free_frame(&obs_std_star_resp); + sinfo_msg_warning("ok14"); + //check_nomsg(sinfo_star_flux_list_save(corr_obs_std_star_list,"corr_obs_std_star_list.fits", "TEST" )) ; + + /* divide observed (corrected) spectrum by reference one at the allowed sampling pixels + * QC: verify that the resulting spectrum is smooth */ + + sinfo_print_rec_status(15); + sinfo_msg_warning("ok15"); + check_nomsg(response=sinfo_star_flux_list_duplicate(shift_std_star_list)); + //check_nomsg(sinfo_star_flux_list_fill_null_end(response)); + //check_nomsg(sinfo_star_flux_list_save(response,"dup_obs_std_star_list.fits", "TEST" )) ; + + check_nomsg(frm_tmp=sinfo_star_flux_list_save( response,"response_before_division.fits", "TEST" )) ; + sinfo_free_frame(&frm_tmp); + check_nomsg(frm_tmp=sinfo_star_flux_list_save( corr_obs_std_star_list,"corr_obs_std_star_list_before_division.fits", "TEST" )) ; + sinfo_free_frame(&frm_tmp); + + //sinfo_star_flux_list_filter_median(response,2); + check_nomsg(sinfo_star_flux_list_divide(response,corr_obs_std_star_list)); + //check_nomsg(sinfo_star_flux_list_save(response,"std_div_obs_star.fits", "TEST" )) ; + + /* smooth over a pixel radii window equivalent to 5nm the resulting ration to get the response + * QC: verify the resulting spectrum is smooth + */ + + check_nomsg(frm_tmp=sinfo_star_flux_list_save( response,"response_before_smooth.fits", "TEST" )) ; + sinfo_free_frame(&frm_tmp); + + + + check_nomsg(sinfo_star_flux_list_filter_median(response, 11 )); + //check_nomsg(sinfo_star_flux_list_save(response,"med_response.fits", "TEST" )) ; + //int hsize=(int)(0.25/wstep+0.5); + /* + int hsize=(int)(1./wstep+0.5); + + check_nomsg(sinfo_star_flux_list_filter_lowpass(response,CPL_LOWPASS_LINEAR, hsize )); + */ + check_nomsg(frm_tmp=sinfo_star_flux_list_save( response,"response_after_smooth.fits", "TEST" )) ; + sinfo_free_frame(&frm_tmp); + + /* interpolate response over pre-defined windows */ + //check_nomsg(xsh_interpolate_high_abs_regions2(ref_std_star_list,response,phigh)); + //check_nomsg(sinfo_star_flux_list_save( response,"response_window.fits", "TEST" )) ; + + /* B-spline- fit response over flagging out pre-defined windows */ + sinfo_print_rec_status(16); + sinfo_msg_warning("ok16"); + //PAPERO: here was set telluric correction. + + if(resp_fit_points == NULL) cpl_msg_warning("", "resp_fit_points == NULL"); + else cpl_msg_warning("", "resp_fit_points <> NULL"); + + if(resp_fit_points!=NULL) { + cpl_msg_warning("", "EXTRACTING FROM %s", cpl_frame_get_filename(resp_fit_points)); + if (CPL_ERROR_NONE + != sinfo_parse_catalog_std_stars(resp_fit_points, dRA, + dDEC, STAR_MATCH_DEPSILON, + &resp_fit_points_tbl, &std_star_id)) { + sinfo_msg_warning( + "Problem parsing input STD catalog. For robustness recipe goes on."); + sinfo_msg_warning("%s", cpl_error_get_message()); + cpl_error_reset(); + sinfo_free_table(&resp_fit_points_tbl); + return NULL ; + } + sinfo_msg_warning("rk18"); + sinfo_print_rec_status(18); + sinfo_msg_warning("Determine response by cubic spline fit interpolation of points defined in input RESP_FIT_POINTS_CAT_%s", + sinfo_band_tostring(band)); + cpl_table_save(resp_fit_points_tbl,NULL, NULL, "resp_fit_points_tbl.fits", CPL_IO_CREATE); + + //cpl_table_dump(resp_fit_points_tbl,0,cpl_table_get_nrow(resp_fit_points_tbl),stdout); + check_nomsg(response_fit=sinfo_bspline_fit_interpol(response,resp_fit_points_tbl,phigh,band)); + sinfo_msg_warning("rk19"); + sinfo_print_rec_status(19); + + } else { + sinfo_msg_warning("rk20"); + sinfo_print_rec_status(20); + sinfo_msg("Determine response by cubic spline smooth interpolation of pipeline defined regions"); + response_fit=sinfo_bspline_fit_smooth(response,phigh,band); + sinfo_msg_warning("rk21"); + sinfo_print_rec_status(21); + } + sinfo_msg_warning("rk22"); + sinfo_print_rec_status(22); + //response_fit=xsh_bspline_interpol(response,phigh,instrument); + //abort(); + /* + double* spline_fit=NULL; + int i=0; + spline_fit=sinfo_bspline_fit_smooth_data(response->lambda,response->flux, + response->size,phigh,instrument,0); + + for(i=0;isize;i++) { + ref_std_star_list->flux[i]=spline_fit[i]; + } + */ + /* Final step: frame creation, merging info from star and object list */ + char tag[256]; + char fname[256]; + + sprintf(tag,"RESPONSE_MERGE1D_%s",sinfo_band_tostring(band)); + sprintf(fname,"RESPONSE_MERGE1D_%s",fname_obs); + + check_nomsg( result = sinfo_star_flux_list_save( response_fit, fname, tag ) ) ; + + check_nomsg(sinfo_response_merge_obj_std_info(result,shift_std_star_list, corr_obs_std_star_list)); + sinfo_msg_warning("rk23"); + sinfo_print_rec_status(23); + + cleanup: + sinfo_rv_ref_wave_param_destroy(rv_ref_wave); + sinfo_star_flux_list_free(&response); + sinfo_star_flux_list_free(&shift_std_star_list); + sinfo_star_flux_list_free(&ref_std_star_list); + sinfo_star_flux_list_free(&response_fit); + sinfo_star_flux_list_free(&corr_obs_std_star_list); + sinfo_star_flux_list_free(&obs_std_star_list); + sinfo_msg_warning("rk24"); + sinfo_print_rec_status(24); + sinfo_free_propertylist(&plist); + sinfo_free_table(&tab_obs_std_star); + sinfo_free_table(&resp_fit_points_tbl); + + sinfo_free_frame(&obs_std_star_resp); + sinfo_free_table(&tbl_ref_std_spectrum); + return result; + +} + +const char* SINFO_RESPONSE_BUG_REPORT = "amodigli@eso.org"; +static void sinfo_response_test(const char* spc_name, const char* cat_name, + const char* atm_ext_name, const char* high_abs_name, + const char* resp_fit_points_name, const char* tell_mod_cat_name) +{ + + cpl_test(CPL_ERROR_NONE == CPL_ERROR_NONE); + cpl_frame * obs_std_star = NULL; + cpl_frame * flux_std_star_cat = NULL; + cpl_frame * atmos_ext = NULL; + cpl_frame* high_abs = NULL; + cpl_frame* resp_fit_points = NULL; + cpl_frame* tell_mod_cat = NULL; + new_sinfo_band band = INSTRUMENT_BAND_K; + double exptime=600; + const int tell_corr=1; + + obs_std_star=sinfo_frame_product(spc_name, "STD_STAR_SPECTRA", CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL); + sinfo_msg_warning("cat_name=%s",cat_name); + flux_std_star_cat=sinfo_frame_product(cat_name, "FLUX_STD_CATALOG_NIR", CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL); + + atmos_ext=sinfo_frame_product(atm_ext_name, "ATMOS_EXT_NIR", CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL); + + /* + high_abs=sinfo_frame_product(high_abs_name, "ATMOS_EXT_NIR", CPL_FRAME_TYPE_TABLE, + CPL_FRAME_GROUP_PRODUCT,CPL_FRAME_LEVEL_FINAL); + */ + + resp_fit_points=sinfo_frame_product(resp_fit_points_name, "RESP_FIT_POINTS_CAT_NIR", + CPL_FRAME_TYPE_TABLE,CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL); + + tell_mod_cat=sinfo_frame_product(tell_mod_cat_name, "TELL_MOD_CAT_NIR", + CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT, + CPL_FRAME_LEVEL_FINAL); + sinfo_msg_warning("ok5 %s",spc_name); + cpl_propertylist* plist = cpl_propertylist_load(spc_name,0); + char test_band[10]; + char instrume[10]; + strcpy(instrume, cpl_propertylist_get_string(plist, "INSTRUME")); + sinfo_msg_warning("INSTRUME=%s",instrume); + if (!strcmp(instrume, "SINFONI")) { + strcpy(test_band, cpl_propertylist_get_string(plist, KEY_NAME_FILT_NAME)); + if (!strcmp(test_band, "J")) { + band=INSTRUMENT_BAND_J ; + } else if (!strcmp(test_band, "H")) { + band=INSTRUMENT_BAND_H ; + } else if (!strcmp(test_band, "K")) { + band=INSTRUMENT_BAND_K ; + } else if (!strcmp(test_band, "HK") || !strcmp(test_band, "H+K")) { + band=INSTRUMENT_BAND_HK ; + } else { + band=INSTRUMENT_BAND_L ; + } + } else if (!strcmp(instrume, "XSHOOTER")) { + strcpy(test_band, cpl_propertylist_get_string(plist, "ESO SEQ ARM")); + if (!strcmp(test_band, "UVB")) { + band=INSTRUMENT_BAND_UVB ; + } else if (!strcmp(test_band, "VIS")) { + band=INSTRUMENT_BAND_VIS ; + } else if (!strcmp(test_band, "NIR")) { + band=INSTRUMENT_BAND_NIR ; + } + } else if (!strcmp(instrume, "SYNTHETIC")) { + band=INSTRUMENT_BAND_ALL ; + sinfo_msg_warning("SYNTHETIC"); + } + + sinfo_free_propertylist(&plist); + cpl_frame* resp=NULL; + + resp=sinfo_compute_response(obs_std_star,flux_std_star_cat, + atmos_ext,high_abs,resp_fit_points, + tell_mod_cat,band, + exptime,tell_corr ); + + sinfo_free_frame(&obs_std_star); + sinfo_free_frame(&flux_std_star_cat); + sinfo_free_frame(&atmos_ext); + //sinfo_free_frame(&high_abs); + sinfo_free_frame(&resp_fit_points); + sinfo_free_frame(&tell_mod_cat); + sinfo_free_frame(&resp); + +} +static int test_small(void){ + + +cpl_image* input_image = cpl_image_new(5,5,CPL_TYPE_FLOAT); + cpl_image_add_scalar(input_image,5000.); + cpl_image_dump_structure(input_image,stdout); + cpl_image_save(input_image, "pippo.fits", CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); +} + + +int main( int argc, char** argv) +{ + cpl_test_init(SINFO_RESPONSE_BUG_REPORT, CPL_MSG_WARNING); + //test_small(); + + + const char * obs_spc_std_name = NULL; + const char * ref_std_cat_name = NULL; + const char * atm_ext_name = NULL; + const char * high_abs_name = NULL; + const char * resp_fit_points_name = NULL; + const char * tell_mod_cat_name = NULL; + + /* Analyse parameters */ + sinfo_msg("argc=%d",argc); + if ( argc == 3) { + sinfo_ima2table(argv); + } else if ( argc > 5) { + obs_spc_std_name = argv[1]; + ref_std_cat_name = argv[2]; + atm_ext_name = argv[3]; + //high_abs_name = argv[4]; + resp_fit_points_name = argv[4]; + tell_mod_cat_name = argv[5]; + sinfo_msg_warning("obs_spc_std_name=%s ref_std_cat_name=%s",obs_spc_std_name,ref_std_cat_name); + sinfo_response_test(obs_spc_std_name,ref_std_cat_name,atm_ext_name,high_abs_name, + resp_fit_points_name,tell_mod_cat_name); + } + else{ + printf(SYNTAX); + return cpl_test_end(0); + + } + + + return cpl_test_end(0); +}